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
52 int configuration_output_handler(struct command_context_s *context, char* line)
\r
60 int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char *argv[])
\r
63 char command_buffer[128];
\r
67 /* getopt_long stores the option index here. */
\r
68 int option_index = 0;
\r
70 c = getopt_long(argc, argv, "hd::l:f:s:c:", long_options, &option_index);
\r
72 /* Detect the end of the options. */
\r
80 case 'h': /* --help | -h */
\r
83 case 'f': /* --file | -f */
\r
84 snprintf(command_buffer, 128, "script %s", optarg);
\r
85 add_config_file_name(command_buffer);
\r
87 case 's': /* --search | -s */
\r
88 add_script_search_dir(optarg);
\r
90 case 'd': /* --debug | -d */
\r
92 snprintf(command_buffer, 128, "debug_level %s", optarg);
\r
94 snprintf(command_buffer, 128, "debug_level 3");
\r
95 command_run_line(cmd_ctx, command_buffer);
\r
97 case 'l': /* --log_output | -l */
\r
100 snprintf(command_buffer, 128, "log_output %s", optarg);
\r
101 command_run_line(cmd_ctx, command_buffer);
\r
104 case 'c': /* --command | -c */
\r
107 add_config_file_name(optarg);
\r
116 printf("Open On-Chip Debugger\n(c) 2005 by Dominic Rath\n\n");
\r
117 printf("--help | -h\tdisplay this help\n");
\r
118 printf("--file | -f\tuse configuration file <name>\n");
\r
119 printf("--search | -s\tdir to search for config files and scripts.\n");
\r
120 printf("--debug | -d\tset debug level <0-3>\n");
\r
121 printf("--log_output | -l\tredirect log output to file <name>\n");
\r
122 printf("--command | -c\trun <command>\n");
\r
126 /* Add dir for openocd supplied scripts last so that user can over
\r
127 ride those scripts if desired. */
\r
128 add_script_search_dir(PKGDATADIR);
\r
129 add_script_search_dir(PKGLIBDIR);
\r