1 /***************************************************************************
\r
2 * Copyright (C) 2004, 2005 by Dominic Rath *
\r
3 * Dominic.Rath@gmx.de *
\r
5 * This program is free software; you can redistribute it and/or modify *
\r
6 * it under the terms of the GNU General Public License as published by *
\r
7 * the Free Software Foundation; either version 2 of the License, or *
\r
8 * (at your option) any later version. *
\r
10 * This program is distributed in the hope that it will be useful, *
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
\r
13 * GNU General Public License for more details. *
\r
15 * You should have received a copy of the GNU General Public License *
\r
16 * along with this program; if not, write to the *
\r
17 * Free Software Foundation, Inc., *
\r
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
\r
19 ***************************************************************************/
\r
20 #ifdef HAVE_CONFIG_H
\r
25 #include "command.h"
\r
26 #include "configuration.h"
\r
35 static int help_flag;
\r
37 static struct option long_options[] =
\r
39 {"help", no_argument, &help_flag, 1},
\r
41 {"debug", optional_argument, 0, 'd'},
\r
42 {"file", required_argument, 0, 'f'},
\r
43 {"search", required_argument, 0, 's'},
\r
44 {"log_output", required_argument, 0, 'l'},
\r
45 {"command", required_argument, 0, 'c'},
\r
51 int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char *argv[])
\r
54 char command_buffer[128];
\r
58 /* getopt_long stores the option index here. */
\r
59 int option_index = 0;
\r
61 c = getopt_long(argc, argv, "hd::l:f:s:c:", long_options, &option_index);
\r
63 /* Detect the end of the options. */
\r
71 case 'h': /* --help | -h */
\r
74 case 'f': /* --file | -f */
\r
75 snprintf(command_buffer, 128, "script %s", optarg);
\r
76 add_config_file_name(command_buffer);
\r
78 case 's': /* --search | -s */
\r
79 add_script_search_dir(optarg);
\r
81 case 'd': /* --debug | -d */
\r
83 snprintf(command_buffer, 128, "debug_level %s", optarg);
\r
85 snprintf(command_buffer, 128, "debug_level 3");
\r
86 command_run_line(cmd_ctx, command_buffer);
\r
88 case 'l': /* --log_output | -l */
\r
91 snprintf(command_buffer, 128, "log_output %s", optarg);
\r
92 command_run_line(cmd_ctx, command_buffer);
\r
95 case 'c': /* --command | -c */
\r
98 add_config_file_name(optarg);
\r
107 printf("Open On-Chip Debugger\n(c) 2005 by Dominic Rath\n\n");
\r
108 printf("--help | -h\tdisplay this help\n");
\r
109 printf("--file | -f\tuse configuration file <name>\n");
\r
110 printf("--search | -s\tdir to search for config files and scripts.\n");
\r
111 printf("--debug | -d\tset debug level <0-3>\n");
\r
112 printf("--log_output | -l\tredirect log output to file <name>\n");
\r
113 printf("--command | -c\trun <command>\n");
\r
117 /* Add dir for openocd supplied scripts last so that user can over
\r
118 ride those scripts if desired. */
\r
119 add_script_search_dir(PKGDATADIR);
\r
120 add_script_search_dir(PKGLIBDIR);
\r