target/arm: do not expose 'arm reg', 'arm mcr/mrc' commands on Cortex-M
[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, see <http://www.gnu.org/licenses/>. *
20 ***************************************************************************/
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "configuration.h"
27 #include "log.h"
28 #include "replacements.h"
29
30 static size_t num_config_files;
31 static char **config_file_names;
32
33 static size_t num_script_dirs;
34 static char **script_search_dirs;
35
36 void add_script_search_dir(const char *dir)
37 {
38 num_script_dirs++;
39 script_search_dirs = realloc(script_search_dirs, (num_script_dirs + 1) * sizeof(char *));
40
41 script_search_dirs[num_script_dirs-1] = strdup(dir);
42 script_search_dirs[num_script_dirs] = NULL;
43
44 LOG_DEBUG("adding %s", dir);
45 }
46
47 void add_config_command(const char *cfg)
48 {
49 num_config_files++;
50 config_file_names = realloc(config_file_names, (num_config_files + 1) * sizeof(char *));
51
52 config_file_names[num_config_files-1] = strdup(cfg);
53 config_file_names[num_config_files] = NULL;
54 }
55
56 void free_config(void)
57 {
58 while (num_config_files)
59 free(config_file_names[--num_config_files]);
60
61 free(config_file_names);
62 config_file_names = NULL;
63
64 while (num_script_dirs)
65 free(script_search_dirs[--num_script_dirs]);
66
67 free(script_search_dirs);
68 script_search_dirs = NULL;
69 }
70
71 /* return full path or NULL according to search rules */
72 char *find_file(const char *file)
73 {
74 FILE *fp = NULL;
75 char **search_dirs = script_search_dirs;
76 char *dir;
77 char const *mode = "r";
78 char *full_path;
79
80 /* Check absolute and relative to current working dir first.
81 * This keeps full_path reporting belowing working. */
82 full_path = alloc_printf("%s", file);
83 fp = fopen(full_path, mode);
84
85 while (!fp) {
86 free(full_path);
87 full_path = NULL;
88 dir = *search_dirs++;
89
90 if (!dir)
91 break;
92
93 full_path = alloc_printf("%s/%s", dir, file);
94 fp = fopen(full_path, mode);
95 }
96
97 if (fp) {
98 fclose(fp);
99 LOG_DEBUG("found %s", full_path);
100 return full_path;
101 }
102
103 free(full_path);
104
105 return NULL;
106 }
107
108 FILE *open_file_from_path(const char *file, const char *mode)
109 {
110 if (mode[0] != 'r')
111 return fopen(file, mode);
112 else {
113 char *full_path = find_file(file);
114 if (!full_path)
115 return NULL;
116 FILE *fp = NULL;
117 fp = fopen(full_path, mode);
118 free(full_path);
119 return fp;
120 }
121 }
122
123 int parse_config_file(struct command_context *cmd_ctx)
124 {
125 int retval;
126 char **cfg;
127
128 if (!config_file_names) {
129 command_run_line(cmd_ctx, "script openocd.cfg");
130 return ERROR_OK;
131 }
132
133 cfg = config_file_names;
134
135 while (*cfg) {
136 retval = command_run_line(cmd_ctx, *cfg);
137 if (retval != ERROR_OK)
138 return retval;
139 cfg++;
140 }
141
142 return ERROR_OK;
143 }
144
145 #ifndef _WIN32
146 #include <pwd.h>
147 #endif
148
149 char *get_home_dir(const char *append_path)
150 {
151 #ifdef _WIN32
152 char homepath[MAX_PATH];
153 #endif
154
155 char *home = getenv("HOME");
156
157 if (!home) {
158
159 #ifdef _WIN32
160 home = getenv("USERPROFILE");
161
162 if (!home) {
163 char *drive = getenv("HOMEDRIVE");
164 char *path = getenv("HOMEPATH");
165 if (drive && path) {
166 snprintf(homepath, MAX_PATH, "%s/%s", drive, path);
167 home = homepath;
168 }
169 }
170 #else
171 struct passwd *pwd = getpwuid(getuid());
172 if (pwd)
173 home = pwd->pw_dir;
174
175 #endif
176 }
177
178 if (!home)
179 return home;
180
181 char *home_path;
182
183 if (append_path)
184 home_path = alloc_printf("%s/%s", home, append_path);
185 else
186 home_path = alloc_printf("%s", home);
187
188 return home_path;
189 }

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)