split jim_jtag_command into multiple handlers
[openocd.git] / src / helper / configuration.c
1 /***************************************************************************
2 * Copyright (C) 2004, 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
4 * *
5 * Copyright (C) 2007,2008 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "configuration.h"
28 #include "log.h"
29
30
31 static size_t num_config_files;
32 static char** config_file_names;
33
34 static size_t num_script_dirs;
35 static char** script_search_dirs;
36
37 void add_script_search_dir (const char *dir)
38 {
39 num_script_dirs++;
40 script_search_dirs = (char **)realloc(script_search_dirs, (num_script_dirs + 1) * sizeof (char *));
41
42 script_search_dirs[num_script_dirs-1] = strdup(dir);
43 script_search_dirs[num_script_dirs] = NULL;
44
45 LOG_DEBUG("adding %s", dir);
46 }
47
48 void add_config_command (const char *cfg)
49 {
50 num_config_files++;
51 config_file_names = (char **)realloc(config_file_names, (num_config_files + 1) * sizeof (char *));
52
53 config_file_names[num_config_files-1] = strdup(cfg);
54 config_file_names[num_config_files] = NULL;
55 }
56
57 /* return full path or NULL according to search rules */
58 char *find_file(const char *file)
59 {
60 FILE *fp = NULL;
61 char **search_dirs = script_search_dirs;
62 char *dir;
63 char const *mode="r";
64 char *full_path;
65
66 /* Check absolute and relative to current working dir first.
67 * This keeps full_path reporting belowing working. */
68 full_path = alloc_printf("%s", file);
69 fp = fopen(full_path, mode);
70
71 while (!fp)
72 {
73 free(full_path);
74 full_path = NULL;
75 dir = *search_dirs++;
76
77 if (!dir)
78 break;
79
80 full_path = alloc_printf("%s/%s", dir, file);
81 fp = fopen(full_path, mode);
82 }
83
84 if (fp)
85 {
86 fclose(fp);
87 LOG_DEBUG("found %s", full_path);
88 return full_path;
89 }
90
91 free(full_path);
92
93 return NULL;
94 }
95
96 FILE *open_file_from_path(const char *file, const char *mode)
97 {
98 if (mode[0]!='r')
99 {
100 return fopen(file, mode);
101 } else
102 {
103 char *full_path = find_file(file);
104 if (full_path == NULL)
105 return NULL;
106 FILE *fp = NULL;
107 fp = fopen(full_path, mode);
108 free(full_path);
109 return fp;
110 }
111 }
112
113 int parse_config_file(struct command_context *cmd_ctx)
114 {
115 int retval;
116 char **cfg;
117
118 if (!config_file_names)
119 add_config_command ("script openocd.cfg");
120
121 cfg = config_file_names;
122
123 while (*cfg)
124 {
125 retval = command_run_line(cmd_ctx, *cfg);
126 if (retval != ERROR_OK)
127 return retval;
128 cfg++;
129 }
130
131 return ERROR_OK;
132 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)