move options handling to separate file to better support embedded implementations...
[openocd.git] / src / helper / options.c
1 /***************************************************************************
2 * Copyright (C) 2004, 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "types.h"
25 #include "command.h"
26 #include "configuration.h"
27 #include "log.h"
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <getopt.h>
32 #include <string.h>
33
34
35 static int help_flag;
36
37 static struct option long_options[] =
38 {
39 {"help", no_argument, &help_flag, 1},
40
41 {"debug", optional_argument, 0, 'd'},
42 {"file", required_argument, 0, 'f'},
43 {"search", required_argument, 0, 's'},
44 {"log_output", required_argument, 0, 'l'},
45 {"command", required_argument, 0, 'c'},
46
47 {0, 0, 0, 0}
48 };
49
50
51 int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char *argv[])
52 {
53 int c;
54 char command_buffer[128];
55
56 while (1)
57 {
58 /* getopt_long stores the option index here. */
59 int option_index = 0;
60
61 c = getopt_long(argc, argv, "hd::l:f:s:c:", long_options, &option_index);
62
63 /* Detect the end of the options. */
64 if (c == -1)
65 break;
66
67 switch (c)
68 {
69 case 0:
70 break;
71 case 'h': /* --help | -h */
72 help_flag = 1;
73 break;
74 case 'f': /* --file | -f */
75 snprintf(command_buffer, 128, "script %s", optarg);
76 add_config_file_name(command_buffer);
77 break;
78 case 's': /* --search | -s */
79 add_script_search_dir(optarg);
80 break;
81 case 'd': /* --debug | -d */
82 if (optarg)
83 snprintf(command_buffer, 128, "debug_level %s", optarg);
84 else
85 snprintf(command_buffer, 128, "debug_level 3");
86 command_run_line(cmd_ctx, command_buffer);
87 break;
88 case 'l': /* --log_output | -l */
89 if (optarg)
90 {
91 snprintf(command_buffer, 128, "log_output %s", optarg);
92 command_run_line(cmd_ctx, command_buffer);
93 }
94 break;
95 case 'c': /* --command | -c */
96 if (optarg)
97 {
98 add_config_file_name(optarg);
99 }
100 break;
101
102 }
103 }
104
105 if (help_flag)
106 {
107 printf("Open On-Chip Debugger\n(c) 2005 by Dominic Rath\n\n");
108 printf("--help | -h\tdisplay this help\n");
109 printf("--file | -f\tuse configuration file <name>\n");
110 printf("--search | -s\tdir to search for config files and scripts.\n");
111 printf("--debug | -d\tset debug level <0-3>\n");
112 printf("--log_output | -l\tredirect log output to file <name>\n");
113 printf("--command | -c\trun <command>\n");
114 exit(-1);
115 }
116
117 /* Add dir for openocd supplied scripts last so that user can over
118 ride those scripts if desired. */
119 add_script_search_dir(PKGDATADIR);
120 add_script_search_dir(PKGLIBDIR);
121
122 return ERROR_OK;
123 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)