1 /***************************************************************************
2 * Copyright (C) 2004, 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * Copyright (C) 2007,2008 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
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. *
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. *
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 ***************************************************************************/
27 #include "configuration.h"
29 // @todo the inclusion of server.h here is a layering violation
34 static int help_flag, version_flag;
36 static struct option long_options[] =
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'},
49 int configuration_output_handler(struct command_context_s *context, const char* line)
51 LOG_USER_N("%s", line);
56 int add_default_dirs(void)
59 /* Add the parent of the directory where openocd.exe resides to the
60 * config script search path.
64 * event\at91eb40a_reset.cfg
65 * target\at91eb40a.cfg
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.
73 *strrchr(strExePath, '\\')=0;
74 strcat(strExePath, "\\..");
75 add_script_search_dir(strExePath);
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
84 * lib/openocd/event/at91eb40a_reset.cfg
85 * lib/openocd/target/at91eb40a.cfg
88 char strExePath [MAX_PATH];
90 GetModuleFileName (NULL, strExePath, MAX_PATH);
91 *strrchr(strExePath, '\\')=0;
92 strcat(strExePath, "/../lib/"PACKAGE);
93 for(p=strExePath; *p; p++) {
97 add_script_search_dir(strExePath);
100 /* Add dir for openocd supplied scripts last so that user can over
101 ride those scripts if desired. */
102 add_script_search_dir(PKGDATADIR);
103 add_script_search_dir(PKGLIBDIR);
108 int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char *argv[])
111 char command_buffer[128];
115 /* getopt_long stores the option index here. */
116 int option_index = 0;
118 c = getopt_long(argc, argv, "hvd::l:f:s:c:p", long_options, &option_index);
120 /* Detect the end of the options. */
128 case 'h': /* --help | -h */
131 case 'v': /* --version | -v */
134 case 'f': /* --file | -f */
136 snprintf(command_buffer, 128, "script {%s}", optarg);
137 add_config_command(command_buffer);
140 case 's': /* --search | -s */
141 add_script_search_dir(optarg);
143 case 'd': /* --debug | -d */
145 snprintf(command_buffer, 128, "debug_level %s", optarg);
147 snprintf(command_buffer, 128, "debug_level 3");
148 command_run_line(cmd_ctx, command_buffer);
150 case 'l': /* --log_output | -l */
153 snprintf(command_buffer, 128, "log_output %s", optarg);
154 command_run_line(cmd_ctx, command_buffer);
157 case 'c': /* --command | -c */
160 add_config_command(optarg);
163 case 'p': /* --pipe | -p */
164 #if BUILD_ECOSBOARD == 1
165 /* pipes unsupported on hosted platforms */
166 LOG_WARNING("pipes not supported on this platform");
168 server_use_pipes = 1;
176 LOG_OUTPUT("Open On-Chip Debugger\n(c) 2005-2008 by Dominic Rath\n\n");
177 LOG_OUTPUT("--help | -h\tdisplay this help\n");
178 LOG_OUTPUT("--version | -v\tdisplay OpenOCD version\n");
179 LOG_OUTPUT("--file | -f\tuse configuration file <name>\n");
180 LOG_OUTPUT("--search | -s\tdir to search for config files and scripts\n");
181 LOG_OUTPUT("--debug | -d\tset debug level <0-3>\n");
182 LOG_OUTPUT("--log_output | -l\tredirect log output to file <name>\n");
183 LOG_OUTPUT("--command | -c\trun <command>\n");
184 LOG_OUTPUT("--pipe | -p\tuse pipes for gdb communication\n");
190 /* Nothing to do, version gets printed automatically. */
191 // It is not an error to request the VERSION number.