f62ab16b2b6f9922538048b6d90876515ab8fbfb
[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 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 {0, 0, 0, 0}
46 };
47
48 int configuration_output_handler(struct command_context_s *context, const char* line)
49 {
50 LOG_INFO_N(line);
51
52 return ERROR_OK;
53 }
54
55 int add_default_dirs(void)
56 {
57 #ifdef _WIN32
58 /* Add the parent of the directory where openocd.exe resides to the
59 * config script search path.
60 * Directory layout:
61 * bin\openocd.exe
62 * lib\openocd
63 * event\at91eb40a_reset.cfg
64 * target\at91eb40a.cfg
65 */
66 {
67 char strExePath [MAX_PATH];
68 GetModuleFileName (NULL, strExePath, MAX_PATH);
69 /* Either this code will *always* work or it will SEGFAULT giving
70 * excellent information on the culprit.
71 */
72 *strrchr(strExePath, '\\')=0;
73 strcat(strExePath, "\\..");
74 add_script_search_dir(strExePath);
75 }
76 #else
77 /* Add dir for openocd supplied scripts last so that user can over
78 ride those scripts if desired. */
79 add_script_search_dir(PKGDATADIR);
80 add_script_search_dir(PKGLIBDIR);
81 #endif
82 return ERROR_OK;
83 }
84
85 int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char *argv[])
86 {
87 int c;
88 char command_buffer[128];
89
90 while (1)
91 {
92 /* getopt_long stores the option index here. */
93 int option_index = 0;
94
95 c = getopt_long(argc, argv, "hvd::l:f:s:c:", long_options, &option_index);
96
97 /* Detect the end of the options. */
98 if (c == -1)
99 break;
100
101 switch (c)
102 {
103 case 0:
104 break;
105 case 'h': /* --help | -h */
106 help_flag = 1;
107 break;
108 case 'v': /* --version | -v */
109 version_flag = 1;
110 break;
111 case 'f': /* --file | -f */
112 {
113 char *t=strrchr(optarg, '.');
114 if (strcmp(t, ".tcl")==0)
115 {
116 /* Files ending in .tcl are executed as Tcl files */
117 snprintf(command_buffer, 128, "source [find {%s}]", optarg);
118 } else
119 {
120 snprintf(command_buffer, 128, "script %s", optarg);
121 }
122 add_config_command(command_buffer);
123 break;
124 }
125 case 's': /* --search | -s */
126 add_script_search_dir(optarg);
127 break;
128 case 'd': /* --debug | -d */
129 if (optarg)
130 snprintf(command_buffer, 128, "debug_level %s", optarg);
131 else
132 snprintf(command_buffer, 128, "debug_level 3");
133 command_run_line(cmd_ctx, command_buffer);
134 break;
135 case 'l': /* --log_output | -l */
136 if (optarg)
137 {
138 snprintf(command_buffer, 128, "log_output %s", optarg);
139 command_run_line(cmd_ctx, command_buffer);
140 }
141 break;
142 case 'c': /* --command | -c */
143 if (optarg)
144 {
145 add_config_command(optarg);
146 }
147 break;
148
149 }
150 }
151
152 if (help_flag)
153 {
154 LOG_OUTPUT("Open On-Chip Debugger\n(c) 2005-2008 by Dominic Rath\n\n");
155 LOG_OUTPUT("--help | -h\tdisplay this help\n");
156 LOG_OUTPUT("--version | -v\tdisplay OpenOCD version\n");
157 LOG_OUTPUT("--file | -f\tuse configuration file <name>\n");
158 LOG_OUTPUT("--search | -s\tdir to search for config files and scripts\n");
159 LOG_OUTPUT("--debug | -d\tset debug level <0-3>\n");
160 LOG_OUTPUT("--log_output | -l\tredirect log output to file <name>\n");
161 LOG_OUTPUT("--command | -c\trun <command>\n");
162 exit(-1);
163 }
164
165 if (version_flag)
166 {
167 /* Nothing to do, version gets printed automatically. */
168 exit(-1);
169 }
170
171
172 return ERROR_OK;
173 }

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)