1 /* SPDX-License-Identifier: BSD-2-Clause-Views */
3 /* Jim - A small embeddable Tcl interpreter
5 * Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
6 * Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
7 * Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
8 * Copyright 2008 oharboe - Øyvind Harboe - oyvind.harboe@zylin.com
9 * Copyright 2008 Andrew Lunn <andrew@lunn.ch>
10 * Copyright 2008 Duane Ellis <openocd@duaneellis.com>
11 * Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
12 * Copyright 2008 Steve Bennett <steveb@workware.net.au>
13 * Copyright 2009 Nico Coesel <ncoesel@dealogic.nl>
14 * Copyright 2009 Zachary T Welch zw@superlucidity.net
15 * Copyright 2009 David Brownell
16 * Copyright (c) 2005-2011 Jim Tcl Project. All rights reserved.
19 #ifndef OPENOCD_HELPER_JIM_NVP_H
20 #define OPENOCD_HELPER_JIM_NVP_H
24 /** Name Value Pairs, aka: NVP
25 * - Given a string - return the associated int.
26 * - Given a number - return the associated string.
29 * Very useful when the number is not a simple index into an array of
30 * known string, or there may be multiple strings (aliases) that mean then same
33 * An NVP Table is terminated with ".name = NULL".
35 * During the 'name2value' operation, if no matching string is found
36 * the pointer to the terminal element (with p->name == NULL) is returned.
40 * const struct jim_nvp yn[] = {
48 * struct jim_nvp *result
49 * e = jim_nvp_name2value(interp, yn, "y", &result);
51 * e = jim_nvp_name2value(interp, yn, "n", &result);
53 * e = jim_nvp_name2value(interp, yn, "Blah", &result);
57 * During the number2name operation, the first matching value is returned.
64 int jim_get_nvp(Jim_Interp
*interp
,
66 const struct jim_nvp
*nvp_table
,
67 const struct jim_nvp
**result
);
69 /* Name Value Pairs Operations */
70 struct jim_nvp
*jim_nvp_name2value_simple(const struct jim_nvp
*nvp_table
, const char *name
);
71 struct jim_nvp
*jim_nvp_name2value_nocase_simple(const struct jim_nvp
*nvp_table
, const char *name
);
72 struct jim_nvp
*jim_nvp_value2name_simple(const struct jim_nvp
*nvp_table
, int v
);
74 int jim_nvp_name2value(Jim_Interp
*interp
,
75 const struct jim_nvp
*nvp_table
,
77 struct jim_nvp
**result
);
78 int jim_nvp_name2value_nocase(Jim_Interp
*interp
,
79 const struct jim_nvp
*nvp_table
,
81 struct jim_nvp
**result
);
82 int jim_nvp_value2name(Jim_Interp
*interp
, const struct jim_nvp
*nvp_table
, int value
, struct jim_nvp
**result
);
84 int jim_nvp_name2value_obj(Jim_Interp
*interp
,
85 const struct jim_nvp
*nvp_table
,
87 struct jim_nvp
**result
);
88 int jim_nvp_name2value_obj_nocase(Jim_Interp
*interp
,
89 const struct jim_nvp
*nvp_table
,
91 struct jim_nvp
**result
);
92 int jim_nvp_value2name_obj(Jim_Interp
*interp
,
93 const struct jim_nvp
*nvp_table
,
95 struct jim_nvp
**result
);
97 /** prints a nice 'unknown' parameter error message to the 'result' */
98 void jim_set_result_nvp_unknown(Jim_Interp
*interp
,
100 Jim_Obj
*param_value
,
101 const struct jim_nvp
*nvp_table
);
103 /** Debug: convert argc/argv into a printable string for printf() debug
105 * \param interp - the interpreter
106 * \param argc - arg count
107 * \param argv - the objects
109 * \returns string pointer holding the text.
111 * Note, next call to this function will free the old (last) string.
113 * For example might want do this:
115 * fp = fopen("some.file.log", "a");
116 * fprintf(fp, "PARAMS are: %s\n", Jim_DebugArgvString(interp, argc, argv));
120 const char *jim_debug_argv_string(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
);
123 /** A TCL -ish GetOpt like code.
125 * Some TCL objects have various "configuration" values.
126 * For example - in Tcl/Tk the "buttons" have many options.
128 * Useful when dealing with command options.
129 * that may come in any order...
131 * Does not support "-foo = 123" type options.
132 * Only supports tcl type options, like "-foo 123"
135 struct jim_getopt_info
{
138 Jim_Obj
*const *argv
;
139 int isconfigure
; /* non-zero if configure */
144 * Example (short and incomplete):
146 * struct jim_getopt_info goi;
148 * jim_getopt_setup(&goi, interp, argc, argv);
151 * e = jim_getopt_nvp(&goi, nvp_options, &n);
153 * jim_getopt_nvp_unknown(&goi, nvp_options, 0);
157 * switch (n->value) {
159 * printf("Option ALIVE specified\n");
162 * if (goi.argc < 1) {
163 * .. not enough args error ..
165 * jim_getopt_string(&goi, &cp, NULL);
166 * printf("FIRSTNAME: %s\n", cp);
168 * jim_getopt_wide(&goi, &w);
169 * printf("AGE: %d\n", (int)(w));
172 * e = jim_getopt_nvp(&goi, nvp_politics, &n);
174 * jim_getopt_nvp_unknown(&goi, nvp_politics, 1);
186 * \param goi - get opt info to be initialized
187 * \param interp - jim interp
188 * \param argc - argc count.
189 * \param argv - argv (will be copied)
192 * struct jim_getopt_info goi;
194 * Jim_GetOptSetup(&goi, interp, argc, argv);
198 int jim_getopt_setup(struct jim_getopt_info
*goi
,
201 Jim_Obj
*const *argv
);
204 /** Debug - Dump parameters to stderr
205 * \param goi - current parameters
207 void jim_getopt_debug(struct jim_getopt_info
*goi
);
209 /** Remove argv[0] from the list.
211 * \param goi - get opt info
212 * \param puthere - where param is put
215 int jim_getopt_obj(struct jim_getopt_info
*goi
, Jim_Obj
**puthere
);
217 /** Remove argv[0] as string.
219 * \param goi - get opt info
220 * \param puthere - where param is put
221 * \param len - return its length
223 int jim_getopt_string(struct jim_getopt_info
*goi
, const char **puthere
, int *len
);
225 /** Remove argv[0] as double.
227 * \param goi - get opt info
228 * \param puthere - where param is put.
231 int jim_getopt_double(struct jim_getopt_info
*goi
, double *puthere
);
233 /** Remove argv[0] as wide.
235 * \param goi - get opt info
236 * \param puthere - where param is put.
238 int jim_getopt_wide(struct jim_getopt_info
*goi
, jim_wide
*puthere
);
240 /** Remove argv[0] as NVP.
242 * \param goi - get opt info
243 * \param lookup - nvp lookup table
244 * \param puthere - where param is put.
247 int jim_getopt_nvp(struct jim_getopt_info
*goi
, const struct jim_nvp
*lookup
, struct jim_nvp
**puthere
);
249 /** Create an appropriate error message for an NVP.
251 * \param goi - options info
252 * \param lookup - the NVP table that was used.
253 * \param hadprefix - 0 or 1 if the option had a prefix.
255 * This function will set the "interp->result" to a human readable
256 * error message listing the available options.
258 * This function assumes the previous option argv[-1] is the unknown string.
260 * If this option had some prefix, then pass "hadprefix = 1" else pass "hadprefix = 0"
266 * // Get the next option
267 * e = jim_getopt_nvp(&goi, cmd_options, &n);
269 * // option was not recognized
270 * // pass 'hadprefix = 0' because there is no prefix
271 * jim_getopt_nvp_unknown(&goi, cmd_options, 0);
275 * switch (n->value) {
277 * // handle: --sex male | female | lots | needmore
278 * e = jim_getopt_nvp(&goi, &nvp_sex, &n);
280 * jim_getopt_nvp_unknown(&ogi, nvp_sex, 1);
283 * printf("Code: (%d) is %s\n", n->value, n->name);
292 void jim_getopt_nvp_unknown(struct jim_getopt_info
*goi
, const struct jim_nvp
*lookup
, int hadprefix
);
295 /** Remove argv[0] as Enum
297 * \param goi - get opt info
298 * \param lookup - lookup table.
299 * \param puthere - where param is put.
302 int jim_getopt_enum(struct jim_getopt_info
*goi
, const char *const *lookup
, int *puthere
);
306 * Do not use these API anymore, as they do not comply with OpenOCD coding style
307 * They are listed here to avoid breaking build after merge of patches already queued in gerrit
310 static inline __attribute__ ((deprecated
))
311 const char *Jim_Debug_ArgvString(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
313 return jim_debug_argv_string(interp
, argc
, argv
);
316 static inline __attribute__ ((deprecated
))
317 int Jim_GetNvp(Jim_Interp
*interp
, Jim_Obj
*objptr
, const struct jim_nvp
*nvp_table
, const struct jim_nvp
**result
)
319 return jim_get_nvp(interp
, objptr
, nvp_table
, result
);
322 static inline __attribute__ ((deprecated
))
323 void Jim_GetOpt_Debug(struct jim_getopt_info
*goi
)
325 jim_getopt_debug(goi
);
328 static inline __attribute__ ((deprecated
))
329 int Jim_GetOpt_Double(struct jim_getopt_info
*goi
, double *puthere
)
331 return jim_getopt_double(goi
, puthere
);
334 static inline __attribute__ ((deprecated
))
335 int Jim_GetOpt_Enum(struct jim_getopt_info
*goi
, const char *const *lookup
, int *puthere
)
337 return jim_getopt_enum(goi
, lookup
, puthere
);
340 static inline __attribute__ ((deprecated
))
341 int Jim_GetOpt_Nvp(struct jim_getopt_info
*goi
, const struct jim_nvp
*lookup
, struct jim_nvp
**puthere
)
343 return jim_getopt_nvp(goi
, lookup
, puthere
);
346 static inline __attribute__ ((deprecated
))
347 void Jim_GetOpt_NvpUnknown(struct jim_getopt_info
*goi
, const struct jim_nvp
*lookup
, int hadprefix
)
349 jim_getopt_nvp_unknown(goi
, lookup
, hadprefix
);
352 static inline __attribute__ ((deprecated
))
353 int Jim_GetOpt_Obj(struct jim_getopt_info
*goi
, Jim_Obj
**puthere
)
355 return jim_getopt_obj(goi
, puthere
);
358 static inline __attribute__ ((deprecated
))
359 int Jim_GetOpt_Setup(struct jim_getopt_info
*goi
, Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
361 return jim_getopt_setup(goi
, interp
, argc
, argv
);
364 static inline __attribute__ ((deprecated
))
365 int Jim_GetOpt_String(struct jim_getopt_info
*goi
, const char **puthere
, int *len
)
367 return jim_getopt_string(goi
, puthere
, len
);
370 static inline __attribute__ ((deprecated
))
371 int Jim_GetOpt_Wide(struct jim_getopt_info
*goi
, jim_wide
*puthere
)
373 return jim_getopt_wide(goi
, puthere
);
376 static inline __attribute__ ((deprecated
))
377 int Jim_Nvp_name2value(Jim_Interp
*interp
, const struct jim_nvp
*nvp_table
, const char *name
, struct jim_nvp
**result
)
379 return jim_nvp_name2value(interp
, nvp_table
, name
, result
);
382 static inline __attribute__ ((deprecated
))
383 int Jim_Nvp_name2value_nocase(Jim_Interp
*interp
, const struct jim_nvp
*nvp_table
, const char *name
,
384 struct jim_nvp
**result
)
386 return jim_nvp_name2value_nocase(interp
, nvp_table
, name
, result
);
389 static inline __attribute__ ((deprecated
))
390 struct jim_nvp
*Jim_Nvp_name2value_nocase_simple(const struct jim_nvp
*nvp_table
, const char *name
)
392 return jim_nvp_name2value_nocase_simple(nvp_table
, name
);
395 static inline __attribute__ ((deprecated
))
396 int Jim_Nvp_name2value_obj(Jim_Interp
*interp
, const struct jim_nvp
*nvp_table
, Jim_Obj
*name_obj
,
397 struct jim_nvp
**result
)
399 return jim_nvp_name2value_obj(interp
, nvp_table
, name_obj
, result
);
402 static inline __attribute__ ((deprecated
))
403 int Jim_Nvp_name2value_obj_nocase(Jim_Interp
*interp
, const struct jim_nvp
*nvp_table
, Jim_Obj
*name_obj
,
404 struct jim_nvp
**result
)
406 return jim_nvp_name2value_obj_nocase(interp
, nvp_table
, name_obj
, result
);
409 static inline __attribute__ ((deprecated
))
410 struct jim_nvp
*Jim_Nvp_name2value_simple(const struct jim_nvp
*nvp_table
, const char *name
)
412 return jim_nvp_name2value_simple(nvp_table
, name
);
415 static inline __attribute__ ((deprecated
))
416 int Jim_Nvp_value2name(Jim_Interp
*interp
, const struct jim_nvp
*nvp_table
, int value
, struct jim_nvp
**result
)
418 return jim_nvp_value2name(interp
, nvp_table
, value
, result
);
421 static inline __attribute__ ((deprecated
))
422 int Jim_Nvp_value2name_obj(Jim_Interp
*interp
, const struct jim_nvp
*nvp_table
, Jim_Obj
*value_obj
,
423 struct jim_nvp
**result
)
425 return jim_nvp_value2name_obj(interp
, nvp_table
, value_obj
, result
);
428 static inline __attribute__ ((deprecated
))
429 struct jim_nvp
*Jim_Nvp_value2name_simple(const struct jim_nvp
*nvp_table
, int v
)
431 return jim_nvp_value2name_simple(nvp_table
, v
);
434 static inline __attribute__ ((deprecated
))
435 void Jim_SetResult_NvpUnknown(Jim_Interp
*interp
, Jim_Obj
*param_name
, Jim_Obj
*param_value
,
436 const struct jim_nvp
*nvp_table
)
438 jim_set_result_nvp_unknown(interp
, param_name
, param_value
, nvp_table
);
441 typedef struct jim_getopt_info Jim_GetOptInfo
__attribute__ ((deprecated
));
442 typedef struct jim_nvp Jim_Nvp
__attribute__ ((deprecated
));
444 #endif /* OPENOCD_HELPER_JIM_NVP_H */
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)