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 static size_t num_config_files;
34 static char** config_file_names;
36 static size_t num_script_dirs;
37 static char** script_search_dirs;
39 void add_script_search_dir (const char *dir)
42 script_search_dirs = (char **)realloc(script_search_dirs, (num_script_dirs+1) * sizeof (char *));
44 script_search_dirs[num_script_dirs-1] = strdup(dir);
45 script_search_dirs[num_script_dirs] = NULL;
48 void add_config_file_name (const char *cfg)
51 config_file_names = (char **)realloc(config_file_names, (num_config_files+1) * sizeof (char *));
53 config_file_names[num_config_files-1] = strdup(cfg);
54 config_file_names[num_config_files] = NULL;
57 FILE *open_file_from_path (char *file, char *mode)
61 return fopen(file, mode);
66 char **search_dirs = script_search_dirs;
70 /* Check absolute and relative to current working dir first.
71 * This keeps full_path reporting belowing working. */
72 snprintf(full_path, 1024, "%s", file);
73 fp = fopen(full_path, mode);
82 snprintf(full_path, 1024, "%s/%s", dir, file);
83 fp = fopen(full_path, mode);
87 LOG_DEBUG("opened %s", full_path);
93 int parse_config_file(struct command_context_s *cmd_ctx)
97 if (!config_file_names)
98 add_config_file_name ("script openocd.cfg");
100 cfg = config_file_names;
104 command_run_line(cmd_ctx, *cfg);