OpenOCD
jim-nvp.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-2-Clause-Views */
2 
3 /* Jim - A small embeddable Tcl interpreter
4  *
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.
17  */
18 
19 #ifndef OPENOCD_HELPER_JIM_NVP_H
20 #define OPENOCD_HELPER_JIM_NVP_H
21 
22 #include <stdbool.h>
23 #include <jim.h>
24 
60 struct jim_nvp {
61  const char *name;
62  int value;
63 };
64 
65 int jim_get_nvp(Jim_Interp *interp,
66  Jim_Obj *objptr,
67  const struct jim_nvp *nvp_table,
68  const struct jim_nvp **result);
69 
70 /* Name Value Pairs Operations */
71 struct jim_nvp *jim_nvp_name2value_simple(const struct jim_nvp *nvp_table, const char *name);
72 struct jim_nvp *jim_nvp_name2value_nocase_simple(const struct jim_nvp *nvp_table, const char *name);
73 struct jim_nvp *jim_nvp_value2name_simple(const struct jim_nvp *nvp_table, int v);
74 
75 int jim_nvp_name2value(Jim_Interp *interp,
76  const struct jim_nvp *nvp_table,
77  const char *name,
78  struct jim_nvp **result);
79 int jim_nvp_name2value_nocase(Jim_Interp *interp,
80  const struct jim_nvp *nvp_table,
81  const char *name,
82  struct jim_nvp **result);
83 int jim_nvp_value2name(Jim_Interp *interp, const struct jim_nvp *nvp_table, int value, struct jim_nvp **result);
84 
85 int jim_nvp_name2value_obj(Jim_Interp *interp,
86  const struct jim_nvp *nvp_table,
87  Jim_Obj *name_obj,
88  struct jim_nvp **result);
89 int jim_nvp_name2value_obj_nocase(Jim_Interp *interp,
90  const struct jim_nvp *nvp_table,
91  Jim_Obj *name_obj,
92  struct jim_nvp **result);
93 int jim_nvp_value2name_obj(Jim_Interp *interp,
94  const struct jim_nvp *nvp_table,
95  Jim_Obj *value_obj,
96  struct jim_nvp **result);
97 
99 void jim_set_result_nvp_unknown(Jim_Interp *interp,
100  Jim_Obj *param_name,
101  Jim_Obj *param_value,
102  const struct jim_nvp *nvp_table);
103 
121 const char *jim_debug_argv_string(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
122 
123 
137  Jim_Interp *interp;
138  int argc;
139  Jim_Obj *const *argv;
141 };
142 
199 int jim_getopt_setup(struct jim_getopt_info *goi,
200  Jim_Interp *interp,
201  int argc,
202  Jim_Obj *const *argv);
203 
204 
208 void jim_getopt_debug(struct jim_getopt_info *goi);
209 
216 int jim_getopt_obj(struct jim_getopt_info *goi, Jim_Obj **puthere);
217 
224 int jim_getopt_string(struct jim_getopt_info *goi, const char **puthere, int *len);
225 
232 int jim_getopt_double(struct jim_getopt_info *goi, double *puthere);
233 
239 int jim_getopt_wide(struct jim_getopt_info *goi, jim_wide *puthere);
240 
248 int jim_getopt_nvp(struct jim_getopt_info *goi, const struct jim_nvp *lookup, struct jim_nvp **puthere);
249 
293 void jim_getopt_nvp_unknown(struct jim_getopt_info *goi, const struct jim_nvp *lookup, int hadprefix);
294 
295 
303 int jim_getopt_enum(struct jim_getopt_info *goi, const char *const *lookup, int *puthere);
304 
305 #endif /* OPENOCD_HELPER_JIM_NVP_H */
const char * name
Definition: armv4_5.c:76
int jim_nvp_value2name(Jim_Interp *interp, const struct jim_nvp *nvp_table, int value, struct jim_nvp **result)
Definition: jim-nvp.c:134
void jim_getopt_nvp_unknown(struct jim_getopt_info *goi, const struct jim_nvp *lookup, int hadprefix)
Create an appropriate error message for an NVP.
Definition: jim-nvp.c:253
int jim_nvp_value2name_obj(Jim_Interp *interp, const struct jim_nvp *nvp_table, Jim_Obj *value_obj, struct jim_nvp **result)
Definition: jim-nvp.c:112
int jim_nvp_name2value_obj_nocase(Jim_Interp *interp, const struct jim_nvp *nvp_table, Jim_Obj *name_obj, struct jim_nvp **result)
Definition: jim-nvp.c:88
void jim_set_result_nvp_unknown(Jim_Interp *interp, Jim_Obj *param_name, Jim_Obj *param_value, const struct jim_nvp *nvp_table)
prints a nice 'unknown' parameter error message to the 'result'
Definition: jim-nvp.c:275
struct jim_nvp * jim_nvp_name2value_simple(const struct jim_nvp *nvp_table, const char *name)
Definition: jim-nvp.c:46
int jim_getopt_wide(struct jim_getopt_info *goi, jim_wide *puthere)
Remove argv[0] as wide.
Definition: jim-nvp.c:222
void jim_getopt_debug(struct jim_getopt_info *goi)
Debug - Dump parameters to stderr.
Definition: jim-nvp.c:159
int jim_get_nvp(Jim_Interp *interp, Jim_Obj *objptr, const struct jim_nvp *nvp_table, const struct jim_nvp **result)
Definition: jim-nvp.c:27
int jim_getopt_string(struct jim_getopt_info *goi, const char **puthere, int *len)
Remove argv[0] as string.
Definition: jim-nvp.c:188
int jim_getopt_enum(struct jim_getopt_info *goi, const char *const *lookup, int *puthere)
Remove argv[0] as Enum.
Definition: jim-nvp.c:261
int jim_getopt_setup(struct jim_getopt_info *goi, Jim_Interp *interp, int argc, Jim_Obj *const *argv)
GetOpt - how to.
Definition: jim-nvp.c:149
int jim_nvp_name2value(Jim_Interp *interp, const struct jim_nvp *nvp_table, const char *name, struct jim_nvp **result)
Definition: jim-nvp.c:71
int jim_getopt_nvp(struct jim_getopt_info *goi, const struct jim_nvp *lookup, struct jim_nvp **puthere)
Remove argv[0] as NVP.
Definition: jim-nvp.c:237
int jim_getopt_obj(struct jim_getopt_info *goi, Jim_Obj **puthere)
Remove argv[0] from the list.
Definition: jim-nvp.c:169
const char * jim_debug_argv_string(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Debug: convert argc/argv into a printable string for printf() debug.
Definition: jim-nvp.c:301
int jim_nvp_name2value_obj(Jim_Interp *interp, const struct jim_nvp *nvp_table, Jim_Obj *name_obj, struct jim_nvp **result)
Definition: jim-nvp.c:66
int jim_nvp_name2value_nocase(Jim_Interp *interp, const struct jim_nvp *nvp_table, const char *name, struct jim_nvp **result)
Definition: jim-nvp.c:96
struct jim_nvp * jim_nvp_name2value_nocase_simple(const struct jim_nvp *nvp_table, const char *name)
Definition: jim-nvp.c:56
int jim_getopt_double(struct jim_getopt_info *goi, double *puthere)
Remove argv[0] as double.
Definition: jim-nvp.c:204
struct jim_nvp * jim_nvp_value2name_simple(const struct jim_nvp *nvp_table, int v)
Definition: jim-nvp.c:124
A TCL -ish GetOpt like code.
Definition: jim-nvp.h:136
Jim_Interp * interp
Definition: jim-nvp.h:137
bool is_configure
Definition: jim-nvp.h:140
Jim_Obj *const * argv
Definition: jim-nvp.h:139
Name Value Pairs, aka: NVP.
Definition: jim-nvp.h:60
const char * name
Definition: jim-nvp.h:61
int value
Definition: jim-nvp.h:62