OpenOCD
jim-nvp.c File Reference
Include dependency graph for jim-nvp.c:

Go to the source code of this file.

Functions

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. More...
 
int jim_get_nvp (Jim_Interp *interp, Jim_Obj *objptr, const struct jim_nvp *nvp_table, const struct jim_nvp **result)
 
void jim_getopt_debug (struct jim_getopt_info *p)
 Debug - Dump parameters to stderr. More...
 
int jim_getopt_double (struct jim_getopt_info *goi, double *puthere)
 Remove argv[0] as double. More...
 
int jim_getopt_enum (struct jim_getopt_info *goi, const char *const *lookup, int *puthere)
 Remove argv[0] as Enum. More...
 
int jim_getopt_nvp (struct jim_getopt_info *goi, const struct jim_nvp *nvp, struct jim_nvp **puthere)
 Remove argv[0] as NVP. More...
 
void jim_getopt_nvp_unknown (struct jim_getopt_info *goi, const struct jim_nvp *nvptable, int hadprefix)
 Create an appropriate error message for an NVP. More...
 
int jim_getopt_obj (struct jim_getopt_info *goi, Jim_Obj **puthere)
 Remove argv[0] from the list. More...
 
int jim_getopt_setup (struct jim_getopt_info *p, Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 GetOpt - how to. More...
 
int jim_getopt_string (struct jim_getopt_info *goi, const char **puthere, int *len)
 Remove argv[0] as string. More...
 
int jim_getopt_wide (struct jim_getopt_info *goi, jim_wide *puthere)
 Remove argv[0] as wide. More...
 
int jim_nvp_name2value (Jim_Interp *interp, const struct jim_nvp *_p, const char *name, struct jim_nvp **result)
 
int jim_nvp_name2value_nocase (Jim_Interp *interp, const struct jim_nvp *_p, const char *name, struct jim_nvp **puthere)
 
struct jim_nvpjim_nvp_name2value_nocase_simple (const struct jim_nvp *p, const char *name)
 
int jim_nvp_name2value_obj (Jim_Interp *interp, const struct jim_nvp *p, Jim_Obj *o, struct jim_nvp **result)
 
int jim_nvp_name2value_obj_nocase (Jim_Interp *interp, const struct jim_nvp *p, Jim_Obj *o, struct jim_nvp **puthere)
 
struct jim_nvpjim_nvp_name2value_simple (const struct jim_nvp *p, const char *name)
 
int jim_nvp_value2name (Jim_Interp *interp, const struct jim_nvp *_p, int value, struct jim_nvp **result)
 
int jim_nvp_value2name_obj (Jim_Interp *interp, const struct jim_nvp *p, Jim_Obj *o, struct jim_nvp **result)
 
struct jim_nvpjim_nvp_value2name_simple (const struct jim_nvp *p, int value)
 
void jim_set_result_nvp_unknown (Jim_Interp *interp, Jim_Obj *param_name, Jim_Obj *param_value, const struct jim_nvp *nvp)
 prints a nice 'unknown' parameter error message to the 'result' More...
 

Function Documentation

◆ jim_debug_argv_string()

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.

Parameters
interp- the interpreter
argc- arg count
argv- the objects
Returns
string pointer holding the text.

Note, next call to this function will free the old (last) string.

For example might want do this:

fp = fopen("some.file.log", "a");
fprintf(fp, "PARAMS are: %s\n", Jim_DebugArgvString(interp, argc, argv));
fclose(fp);
#define fp
Definition: mips32.c:223

Definition at line 301 of file jim-nvp.c.

References NULL.

◆ jim_get_nvp()

int jim_get_nvp ( Jim_Interp *  interp,
Jim_Obj *  objptr,
const struct jim_nvp nvp_table,
const struct jim_nvp **  result 
)

Definition at line 27 of file jim-nvp.c.

References jim_nvp_name2value_obj(), and jim_nvp::name.

◆ jim_getopt_debug()

void jim_getopt_debug ( struct jim_getopt_info goi)

Debug - Dump parameters to stderr.

Parameters
goi- current parameters

Definition at line 159 of file jim-nvp.c.

References jim_getopt_info::argc, and jim_getopt_info::argv.

◆ jim_getopt_double()

int jim_getopt_double ( struct jim_getopt_info goi,
double *  puthere 
)

Remove argv[0] as double.

Parameters
goi- get opt info
puthere- where param is put.

Definition at line 204 of file jim-nvp.c.

References jim_getopt_info::interp, and jim_getopt_obj().

◆ jim_getopt_enum()

int jim_getopt_enum ( struct jim_getopt_info goi,
const char *const *  lookup,
int *  puthere 
)

Remove argv[0] as Enum.

Parameters
goi- get opt info
lookup- lookup table.
puthere- where param is put.

Definition at line 261 of file jim-nvp.c.

References jim_getopt_info::interp, and jim_getopt_obj().

◆ jim_getopt_nvp()

int jim_getopt_nvp ( struct jim_getopt_info goi,
const struct jim_nvp lookup,
struct jim_nvp **  puthere 
)

Remove argv[0] as NVP.

Parameters
goi- get opt info
lookup- nvp lookup table
puthere- where param is put.

Definition at line 237 of file jim-nvp.c.

References jim_getopt_info::interp, jim_getopt_obj(), and jim_nvp_name2value_obj().

Referenced by arm_tpiu_swo_configure(), dap_configure(), jim_target_invoke_event(), and target_configure().

◆ jim_getopt_nvp_unknown()

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.

Parameters
goi- options info
lookup- the NVP table that was used.
hadprefix- 0 or 1 if the option had a prefix.

This function will set the "interp->result" to a human readable error message listing the available options.

This function assumes the previous option argv[-1] is the unknown string.

If this option had some prefix, then pass "hadprefix = 1" else pass "hadprefix = 0"

Example:

while (goi.argc) {
// Get the next option
e = jim_getopt_nvp(&goi, cmd_options, &n);
if (e != JIM_OK) {
// option was not recognized
// pass 'hadprefix = 0' because there is no prefix
jim_getopt_nvp_unknown(&goi, cmd_options, 0);
return e;
}
switch (n->value) {
case OPT_SEX:
// handle: --sex male | female | lots | needmore
e = jim_getopt_nvp(&goi, &nvp_sex, &n);
if (e != JIM_OK) {
jim_getopt_nvp_unknown(&ogi, nvp_sex, 1);
return e;
}
printf("Code: (%d) is %s\n", n->value, n->name);
break;
case ...:
[snip]
}
}
int jim_getopt_nvp(struct jim_getopt_info *goi, const struct jim_nvp *nvp, struct jim_nvp **puthere)
Remove argv[0] as NVP.
Definition: jim-nvp.c:237
void jim_getopt_nvp_unknown(struct jim_getopt_info *goi, const struct jim_nvp *nvptable, int hadprefix)
Create an appropriate error message for an NVP.
Definition: jim-nvp.c:253

Definition at line 253 of file jim-nvp.c.

References jim_getopt_info::argv, jim_getopt_info::interp, jim_set_result_nvp_unknown(), and NULL.

Referenced by arm_tpiu_swo_configure(), dap_configure(), jim_target_invoke_event(), and target_configure().

◆ jim_getopt_obj()

int jim_getopt_obj ( struct jim_getopt_info goi,
Jim_Obj **  puthere 
)

◆ jim_getopt_setup()

int jim_getopt_setup ( struct jim_getopt_info goi,
Jim_Interp *  interp,
int  argc,
Jim_Obj *const *  argv 
)

GetOpt - how to.

Example (short and incomplete):

struct jim_getopt_info goi;
while (goi.argc) {
e = jim_getopt_nvp(&goi, nvp_options, &n);
if (e != JIM_OK) {
jim_getopt_nvp_unknown(&goi, nvp_options, 0);
return e;
}
switch (n->value) {
case ALIVE:
printf("Option ALIVE specified\n");
break;
case FIRST:
if (goi.argc < 1) {
.. not enough args error ..
}
jim_getopt_string(&goi, &cp, NULL);
printf("FIRSTNAME: %s\n", cp);
case AGE:
jim_getopt_wide(&goi, &w);
printf("AGE: %d\n", (int)(w));
break;
case POLITICS:
e = jim_getopt_nvp(&goi, nvp_politics, &n);
if (e != JIM_OK) {
jim_getopt_nvp_unknown(&goi, nvp_politics, 1);
return e;
}
}
}
int jim_getopt_wide(struct jim_getopt_info *goi, jim_wide *puthere)
Remove argv[0] as wide.
Definition: jim-nvp.c:222
int jim_getopt_setup(struct jim_getopt_info *p, Jim_Interp *interp, int argc, Jim_Obj *const *argv)
GetOpt - how to.
Definition: jim-nvp.c:149
int jim_getopt_string(struct jim_getopt_info *goi, const char **puthere, int *len)
Remove argv[0] as string.
Definition: jim-nvp.c:188
A TCL -ish GetOpt like code.
Definition: jim-nvp.h:135
Jim_Interp * interp
Definition: jim-nvp.h:136
Jim_Obj *const * argv
Definition: jim-nvp.h:138
#define NULL
Definition: usb.h:16

Setup GETOPT

Parameters
goi- get opt info to be initialized
interp- jim interp
argc- argc count.
argv- argv (will be copied)
struct jim_getopt_info goi;
Jim_GetOptSetup(&goi, interp, argc, argv);

Definition at line 149 of file jim-nvp.c.

References jim_getopt_info::argc, jim_getopt_info::argv, and jim_getopt_info::interp.

Referenced by jim_arm_tpiu_swo_configure(), jim_arm_tpiu_swo_create(), jim_cti_create(), jim_dap_create(), jim_target_configure(), jim_target_create(), and jim_target_invoke_event().

◆ jim_getopt_string()

int jim_getopt_string ( struct jim_getopt_info goi,
const char **  puthere,
int *  len 
)

Remove argv[0] as string.

Parameters
goi- get opt info
puthere- where param is put
len- return its length

Definition at line 188 of file jim-nvp.c.

References jim_getopt_obj().

Referenced by arm_tpiu_swo_configure(), rtos_create(), stm8_jim_configure(), target_configure(), and target_create().

◆ jim_getopt_wide()

int jim_getopt_wide ( struct jim_getopt_info goi,
jim_wide *  puthere 
)

Remove argv[0] as wide.

Parameters
goi- get opt info
puthere- where param is put.

Definition at line 222 of file jim-nvp.c.

References jim_getopt_info::interp, and jim_getopt_obj().

Referenced by adiv5_jim_spot_configure(), arm_tpiu_swo_configure(), dap_configure(), stm8_jim_configure(), and target_configure().

◆ jim_nvp_name2value()

int jim_nvp_name2value ( Jim_Interp *  interp,
const struct jim_nvp _p,
const char *  name,
struct jim_nvp **  result 
)

Definition at line 71 of file jim-nvp.c.

References jim_nvp_name2value_simple(), jim_nvp::name, and name.

Referenced by jim_nvp_name2value_obj().

◆ jim_nvp_name2value_nocase()

int jim_nvp_name2value_nocase ( Jim_Interp *  interp,
const struct jim_nvp _p,
const char *  name,
struct jim_nvp **  puthere 
)

Definition at line 96 of file jim-nvp.c.

References jim_nvp_name2value_nocase_simple(), jim_nvp::name, and name.

Referenced by jim_nvp_name2value_obj_nocase().

◆ jim_nvp_name2value_nocase_simple()

struct jim_nvp* jim_nvp_name2value_nocase_simple ( const struct jim_nvp p,
const char *  name 
)

Definition at line 56 of file jim-nvp.c.

References jim_nvp::name, and name.

Referenced by jim_nvp_name2value_nocase().

◆ jim_nvp_name2value_obj()

int jim_nvp_name2value_obj ( Jim_Interp *  interp,
const struct jim_nvp p,
Jim_Obj *  o,
struct jim_nvp **  result 
)

◆ jim_nvp_name2value_obj_nocase()

int jim_nvp_name2value_obj_nocase ( Jim_Interp *  interp,
const struct jim_nvp p,
Jim_Obj *  o,
struct jim_nvp **  puthere 
)

Definition at line 88 of file jim-nvp.c.

References jim_nvp_name2value_nocase().

◆ jim_nvp_name2value_simple()

struct jim_nvp* jim_nvp_name2value_simple ( const struct jim_nvp p,
const char *  name 
)

Definition at line 46 of file jim-nvp.c.

References jim_nvp::name, and name.

Referenced by jim_nvp_name2value().

◆ jim_nvp_value2name()

int jim_nvp_value2name ( Jim_Interp *  interp,
const struct jim_nvp _p,
int  value,
struct jim_nvp **  result 
)

◆ jim_nvp_value2name_obj()

int jim_nvp_value2name_obj ( Jim_Interp *  interp,
const struct jim_nvp p,
Jim_Obj *  o,
struct jim_nvp **  result 
)

Definition at line 112 of file jim-nvp.c.

References jim_nvp_value2name().

◆ jim_nvp_value2name_simple()

struct jim_nvp* jim_nvp_value2name_simple ( const struct jim_nvp p,
int  value 
)

◆ jim_set_result_nvp_unknown()

void jim_set_result_nvp_unknown ( Jim_Interp *  interp,
Jim_Obj *  param_name,
Jim_Obj *  param_value,
const struct jim_nvp nvp 
)

prints a nice 'unknown' parameter error message to the 'result'

Definition at line 275 of file jim-nvp.c.

References nvp::name, name, and NULL.

Referenced by jim_getopt_nvp_unknown().