OpenOCD
jim-nvp.h File Reference
Include dependency graph for jim-nvp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  jim_getopt_info
 A TCL -ish GetOpt like code. More...
 
struct  jim_nvp
 Name Value Pairs, aka: NVP. More...
 

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 *goi)
 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 *lookup, struct jim_nvp **puthere)
 Remove argv[0] as NVP. More...
 
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. 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 *goi, 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 *nvp_table, const char *name, struct jim_nvp **result)
 
int jim_nvp_name2value_nocase (Jim_Interp *interp, const struct jim_nvp *nvp_table, const char *name, struct jim_nvp **result)
 
struct jim_nvpjim_nvp_name2value_nocase_simple (const struct jim_nvp *nvp_table, const char *name)
 
int jim_nvp_name2value_obj (Jim_Interp *interp, const struct jim_nvp *nvp_table, Jim_Obj *name_obj, struct jim_nvp **result)
 
int jim_nvp_name2value_obj_nocase (Jim_Interp *interp, const struct jim_nvp *nvp_table, Jim_Obj *name_obj, struct jim_nvp **result)
 
struct jim_nvpjim_nvp_name2value_simple (const struct jim_nvp *nvp_table, const char *name)
 
int jim_nvp_value2name (Jim_Interp *interp, const struct jim_nvp *nvp_table, int value, struct jim_nvp **result)
 
int jim_nvp_value2name_obj (Jim_Interp *interp, const struct jim_nvp *nvp_table, Jim_Obj *value_obj, struct jim_nvp **result)
 
struct jim_nvpjim_nvp_value2name_simple (const struct jim_nvp *nvp_table, int v)
 
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' 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);

Definition at line 300 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 26 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 158 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 203 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 260 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 
)

◆ 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:236
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:252

Definition at line 252 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_aice_newtap_cmd(), jim_arc_add_reg(), jim_arc_add_reg_type_flags(), jim_arc_add_reg_type_struct(), jim_hl_newtap_cmd(), jim_newtap_cmd(), jim_target_invoke_event(), jim_target_reset(), jim_target_wait_state(), jtag_tap_configure_cmd(), jtag_tap_configure_event(), and target_configure().

◆ jim_getopt_obj()

◆ 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:221
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:148
int jim_getopt_string(struct jim_getopt_info *goi, const char **puthere, int *len)
Remove argv[0] as string.
Definition: jim-nvp.c:187
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 148 of file jim-nvp.c.

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

Referenced by jim_adapter_name(), jim_aice_arp_init_reset(), jim_aice_newtap(), jim_arc_add_reg(), jim_arc_add_reg_type_flags(), jim_arc_add_reg_type_struct(), jim_arc_get_aux_reg(), jim_arc_get_core_reg(), jim_arc_get_reg_field(), jim_arc_set_aux_reg(), jim_arm_tpiu_swo_configure(), jim_arm_tpiu_swo_create(), jim_cti_create(), jim_dap_create(), jim_hl_newtap(), jim_jtag_arp_init(), jim_jtag_arp_init_reset(), jim_jtag_configure(), jim_jtag_names(), jim_jtag_newtap(), jim_jtag_tap_enabler(), jim_nds32_bulk_read(), jim_nds32_bulk_write(), jim_nds32_multi_write(), jim_nds32_read_edm_sr(), jim_nds32_write_edm_sr(), jim_target_configure(), jim_target_create(), jim_target_examine(), jim_target_invoke_event(), jim_target_reset(), and jim_target_wait_state().

◆ jim_getopt_string()

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

◆ jim_getopt_wide()

◆ jim_nvp_name2value()

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

Definition at line 70 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 nvp_table,
const char *  name,
struct jim_nvp **  result 
)

Definition at line 95 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 nvp_table,
const char *  name 
)

Definition at line 55 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 nvp_table,
Jim_Obj *  name_obj,
struct jim_nvp **  result 
)

◆ jim_nvp_name2value_obj_nocase()

int jim_nvp_name2value_obj_nocase ( Jim_Interp *  interp,
const struct jim_nvp nvp_table,
Jim_Obj *  name_obj,
struct jim_nvp **  result 
)

Definition at line 87 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 nvp_table,
const char *  name 
)

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

References jim_nvp::name, and name.

Referenced by COMMAND_HANDLER(), and jim_nvp_name2value().

◆ jim_nvp_value2name()

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

◆ jim_nvp_value2name_obj()

int jim_nvp_value2name_obj ( Jim_Interp *  interp,
const struct jim_nvp nvp_table,
Jim_Obj *  value_obj,
struct jim_nvp **  result 
)

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

References jim_nvp_value2name().

◆ jim_nvp_value2name_simple()

◆ 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_table 
)

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

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

References jim_nvp::name, name, and NULL.

Referenced by jim_getopt_nvp_unknown().