1 /***************************************************************************
2 * Copyright (C) 2004, 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
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. *
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. *
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 ***************************************************************************/
26 #include "configuration.h"
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'},
48 int configuration_output_handler(struct command_context_s *context, const char* line)
55 int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char *argv[])
58 char command_buffer[128];
62 /* getopt_long stores the option index here. */
65 c = getopt_long(argc, argv, "hvd::l:f:s:c:", long_options, &option_index);
67 /* Detect the end of the options. */
75 case 'h': /* --help | -h */
78 case 'v': /* --version | -v */
81 case 'f': /* --file | -f */
83 char *t=strrchr(optarg, '.');
84 if (strcmp(t, ".tcl")==0)
86 /* Files ending in .tcl are executed as Tcl files */
87 snprintf(command_buffer, 128, "source [find {%s}]", optarg);
90 snprintf(command_buffer, 128, "script %s", optarg);
92 add_config_command(command_buffer);
95 case 's': /* --search | -s */
96 add_script_search_dir(optarg);
98 case 'd': /* --debug | -d */
100 snprintf(command_buffer, 128, "debug_level %s", optarg);
102 snprintf(command_buffer, 128, "debug_level 3");
103 command_run_line(cmd_ctx, command_buffer);
105 case 'l': /* --log_output | -l */
108 snprintf(command_buffer, 128, "log_output %s", optarg);
109 command_run_line(cmd_ctx, command_buffer);
112 case 'c': /* --command | -c */
115 add_config_command(optarg);
124 LOG_OUTPUT("Open On-Chip Debugger\n(c) 2005-2008 by Dominic Rath\n\n");
125 LOG_OUTPUT("--help | -h\tdisplay this help\n");
126 LOG_OUTPUT("--version | -v\tdisplay OpenOCD version\n");
127 LOG_OUTPUT("--file | -f\tuse configuration file <name>\n");
128 LOG_OUTPUT("--search | -s\tdir to search for config files and scripts\n");
129 LOG_OUTPUT("--debug | -d\tset debug level <0-3>\n");
130 LOG_OUTPUT("--log_output | -l\tredirect log output to file <name>\n");
131 LOG_OUTPUT("--command | -c\trun <command>\n");
137 /* Nothing to do, version gets printed automatically. */
142 /* Add the parent of the directory where openocd.exe resides to the
143 * config script search path.
147 * event\at91eb40a_reset.cfg
148 * target\at91eb40a.cfg
151 char strExePath [MAX_PATH];
152 GetModuleFileName (NULL, strExePath, MAX_PATH);
153 /* Either this code will *always* work or it will SEGFAULT giving
154 * excellent information on the culprit.
156 *strrchr(strExePath, '\\')=0;
157 strcat(strExePath, "\\..");
158 add_script_search_dir(strExePath);
161 /* Add dir for openocd supplied scripts last so that user can over
162 ride those scripts if desired. */
163 add_script_search_dir(PKGDATADIR);
164 add_script_search_dir(PKGLIBDIR);