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"
33 char* config_file_name;
37 static struct option long_options[] =
39 {"help", no_argument, &help_flag, 1},
41 {"debug", optional_argument, 0, 'd'},
42 {"file", required_argument, 0, 'f'},
43 {"log_output", required_argument, 0, 'l'},
48 int configuration_output_handler(struct command_context_s *context, 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, "hd::l:f:", long_options, &option_index);
67 /* Detect the end of the options. */
75 case 'h': /* --help | -h */
78 case 'f': /* --file | -f */
79 config_file_name = optarg;
81 case 'd': /* --debug | -d */
83 snprintf(command_buffer, 128, "debug_level %s", optarg);
85 snprintf(command_buffer, 128, "debug_level 3");
86 command_run_line(cmd_ctx, command_buffer);
88 case 'l': /* --log_output | -l */
91 snprintf(command_buffer, 128, "log_output %s", optarg);
92 command_run_line(cmd_ctx, command_buffer);
100 printf("Open On-Chip Debugger\n(c) 2005 by Dominic Rath\n\n");
101 printf("--help | -h\tdisplay this help\n");
102 printf("--file | -f\tuse configuration file <name>\n");
103 printf("--debug | -d\tset debug level <0-3>\n");
104 printf("--log_output | -l\tredirect log output to file <name>\n");
111 int parse_config_file(struct command_context_s *cmd_ctx)
115 if (!config_file_name)
116 config_file_name = "openocd.cfg";
118 config_file = fopen(config_file_name, "r");
121 ERROR("couldn't open config file");
122 return ERROR_NO_CONFIG_FILE;
125 command_run_file(cmd_ctx, config_file, COMMAND_CONFIG);