3ffc6736e86ea6ececbbb2b1e42c897a6c58b056
[openocd.git] / src / helper / options.c
1 /***************************************************************************
2 * Copyright (C) 2004, 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
4 * *
5 * Copyright (C) 2007,2008 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "configuration.h"
28 #include "log.h"
29 // @todo the inclusion of server.h here is a layering violation
30 #include "server.h"
31
32 #include <getopt.h>
33
34 static int help_flag, version_flag;
35
36 static struct option long_options[] =
37 {
38 {"help", no_argument, &help_flag, 1},
39 {"version", no_argument, &version_flag, 1},
40 {"debug", optional_argument, 0, 'd'},
41 {"file", required_argument, 0, 'f'},
42 {"search", required_argument, 0, 's'},
43 {"log_output", required_argument, 0, 'l'},
44 {"command", required_argument, 0, 'c'},
45 {"pipe", no_argument, 0, 'p'},
46 {0, 0, 0, 0}
47 };
48
49 int configuration_output_handler(struct command_context *context, const char* line)
50 {
51 LOG_USER_N("%s", line);
52
53 return ERROR_OK;
54 }
55
56 static void add_default_dirs(void)
57 {
58 #ifdef _WIN32
59 /* Add the parent of the directory where openocd.exe resides to the
60 * config script search path.
61 * Directory layout:
62 * bin\openocd.exe
63 * lib\openocd
64 * event\at91eb40a_reset.cfg
65 * target\at91eb40a.cfg
66 */
67 {
68 char strExePath [MAX_PATH];
69 GetModuleFileName (NULL, strExePath, MAX_PATH);
70 /* Either this code will *always* work or it will SEGFAULT giving
71 * excellent information on the culprit.
72 */
73 *strrchr(strExePath, '\\') = 0;
74 strcat(strExePath, "\\..");
75 add_script_search_dir(strExePath);
76 }
77 /*
78 * Add support for the default (as of 20080121) layout when
79 * using autotools and cygwin to build native MinGW binary.
80 * Path separator is converted to UNIX style so that MinGW is
81 * pleased.
82 *
83 * bin/openocd.exe
84 * lib/openocd/event/at91eb40a_reset.cfg
85 * lib/openocd/target/at91eb40a.cfg
86 */
87 {
88 char strExePath [MAX_PATH];
89 char *p;
90 GetModuleFileName (NULL, strExePath, MAX_PATH);
91 *strrchr(strExePath, '\\') = 0;
92 strcat(strExePath, "/../lib/"PACKAGE);
93 for (p = strExePath; *p; p++) {
94 if (*p == '\\')
95 *p = '/';
96 }
97 add_script_search_dir(strExePath);
98 }
99 #else
100 /*
101 * The directory containing OpenOCD-supplied scripts should be
102 * listed last in the built-in search order, so the user can
103 * override these scripts with site-specific customizations.
104 */
105 /// @todo Implement @c add_script_search_dir("${HOME}/.openocd").
106 add_script_search_dir(PKGDATADIR "/site");
107 add_script_search_dir(PKGDATADIR "/scripts");
108 #endif
109 }
110
111 int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[])
112 {
113 int c;
114 char command_buffer[128];
115
116 while (1)
117 {
118 /* getopt_long stores the option index here. */
119 int option_index = 0;
120
121 c = getopt_long(argc, argv, "hvd::l:f:s:c:p", long_options, &option_index);
122
123 /* Detect the end of the options. */
124 if (c == -1)
125 break;
126
127 switch (c)
128 {
129 case 0:
130 break;
131 case 'h': /* --help | -h */
132 help_flag = 1;
133 break;
134 case 'v': /* --version | -v */
135 version_flag = 1;
136 break;
137 case 'f': /* --file | -f */
138 {
139 snprintf(command_buffer, 128, "script {%s}", optarg);
140 add_config_command(command_buffer);
141 break;
142 }
143 case 's': /* --search | -s */
144 add_script_search_dir(optarg);
145 break;
146 case 'd': /* --debug | -d */
147 if (optarg)
148 snprintf(command_buffer, 128, "debug_level %s", optarg);
149 else
150 snprintf(command_buffer, 128, "debug_level 3");
151 command_run_line(cmd_ctx, command_buffer);
152 break;
153 case 'l': /* --log_output | -l */
154 if (optarg)
155 {
156 snprintf(command_buffer, 128, "log_output %s", optarg);
157 command_run_line(cmd_ctx, command_buffer);
158 }
159 break;
160 case 'c': /* --command | -c */
161 if (optarg)
162 {
163 add_config_command(optarg);
164 }
165 break;
166 case 'p': /* --pipe | -p */
167 #if BUILD_ECOSBOARD == 1
168 /* pipes unsupported on hosted platforms */
169 LOG_WARNING("pipes not supported on this platform");
170 #else
171 server_use_pipes = 1;
172 #endif
173 break;
174 }
175 }
176
177 if (help_flag)
178 {
179 LOG_OUTPUT("Open On-Chip Debugger\n(c) 2005-2008 by Dominic Rath\n\n");
180 LOG_OUTPUT("--help | -h\tdisplay this help\n");
181 LOG_OUTPUT("--version | -v\tdisplay OpenOCD version\n");
182 LOG_OUTPUT("--file | -f\tuse configuration file <name>\n");
183 LOG_OUTPUT("--search | -s\tdir to search for config files and scripts\n");
184 LOG_OUTPUT("--debug | -d\tset debug level <0-3>\n");
185 LOG_OUTPUT("--log_output | -l\tredirect log output to file <name>\n");
186 LOG_OUTPUT("--command | -c\trun <command>\n");
187 LOG_OUTPUT("--pipe | -p\tuse pipes for gdb communication\n");
188 exit(-1);
189 }
190
191 if (version_flag)
192 {
193 /* Nothing to do, version gets printed automatically. */
194 // It is not an error to request the VERSION number.
195 exit(0);
196 }
197
198 /* paths specified on the command line take precedence over these
199 * built-in paths
200 */
201 add_default_dirs();
202
203 return ERROR_OK;
204 }

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)