4 int Jim_GetNvp(Jim_Interp
*interp
,
5 Jim_Obj
*objPtr
, const Jim_Nvp
* nvp_table
, const Jim_Nvp
** result
)
10 e
= Jim_Nvp_name2value_obj(interp
, nvp_table
, objPtr
, &n
);
18 *result
= (Jim_Nvp
*) n
;
26 Jim_Nvp
*Jim_Nvp_name2value_simple(const Jim_Nvp
* p
, const char *name
)
29 if (0 == strcmp(name
, p
->name
)) {
34 return ((Jim_Nvp
*) (p
));
37 Jim_Nvp
*Jim_Nvp_name2value_nocase_simple(const Jim_Nvp
* p
, const char *name
)
40 if (0 == strcasecmp(name
, p
->name
)) {
45 return ((Jim_Nvp
*) (p
));
48 int Jim_Nvp_name2value_obj(Jim_Interp
*interp
, const Jim_Nvp
* p
, Jim_Obj
*o
, Jim_Nvp
** result
)
50 return Jim_Nvp_name2value(interp
, p
, Jim_String(o
), result
);
54 int Jim_Nvp_name2value(Jim_Interp
*interp
, const Jim_Nvp
* _p
, const char *name
, Jim_Nvp
** result
)
58 p
= Jim_Nvp_name2value_simple(_p
, name
);
62 *result
= (Jim_Nvp
*) (p
);
75 Jim_Nvp_name2value_obj_nocase(Jim_Interp
*interp
, const Jim_Nvp
* p
, Jim_Obj
*o
, Jim_Nvp
** puthere
)
77 return Jim_Nvp_name2value_nocase(interp
, p
, Jim_String(o
), puthere
);
81 Jim_Nvp_name2value_nocase(Jim_Interp
*interp
, const Jim_Nvp
* _p
, const char *name
,
86 p
= Jim_Nvp_name2value_nocase_simple(_p
, name
);
89 *puthere
= (Jim_Nvp
*) (p
);
101 int Jim_Nvp_value2name_obj(Jim_Interp
*interp
, const Jim_Nvp
* p
, Jim_Obj
*o
, Jim_Nvp
** result
)
106 e
= Jim_GetWide(interp
, o
, &w
);
111 return Jim_Nvp_value2name(interp
, p
, w
, result
);
114 Jim_Nvp
*Jim_Nvp_value2name_simple(const Jim_Nvp
* p
, int value
)
117 if (value
== p
->value
) {
122 return ((Jim_Nvp
*) (p
));
126 int Jim_Nvp_value2name(Jim_Interp
*interp
, const Jim_Nvp
* _p
, int value
, Jim_Nvp
** result
)
130 p
= Jim_Nvp_value2name_simple(_p
, value
);
133 *result
= (Jim_Nvp
*) (p
);
145 int Jim_GetOpt_Setup(Jim_GetOptInfo
* p
, Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
147 memset(p
, 0, sizeof(*p
));
155 void Jim_GetOpt_Debug(Jim_GetOptInfo
* p
)
159 fprintf(stderr
, "---args---\n");
160 for (x
= 0; x
< p
->argc
; x
++) {
161 fprintf(stderr
, "%2d) %s\n", x
, Jim_String(p
->argv
[x
]));
163 fprintf(stderr
, "-------\n");
167 int Jim_GetOpt_Obj(Jim_GetOptInfo
* goi
, Jim_Obj
**puthere
)
189 int Jim_GetOpt_String(Jim_GetOptInfo
* goi
, char **puthere
, int *len
)
196 r
= Jim_GetOpt_Obj(goi
, &o
);
198 cp
= Jim_GetString(o
, len
);
201 *puthere
= (char *)(cp
);
207 int Jim_GetOpt_Double(Jim_GetOptInfo
* goi
, double *puthere
)
213 if (puthere
== NULL
) {
217 r
= Jim_GetOpt_Obj(goi
, &o
);
219 r
= Jim_GetDouble(goi
->interp
, o
, puthere
);
221 Jim_SetResultFormatted(goi
->interp
, "not a number: %#s", o
);
227 int Jim_GetOpt_Wide(Jim_GetOptInfo
* goi
, jim_wide
* puthere
)
233 if (puthere
== NULL
) {
237 r
= Jim_GetOpt_Obj(goi
, &o
);
239 r
= Jim_GetWide(goi
->interp
, o
, puthere
);
244 int Jim_GetOpt_Nvp(Jim_GetOptInfo
* goi
, const Jim_Nvp
* nvp
, Jim_Nvp
** puthere
)
250 if (puthere
== NULL
) {
254 e
= Jim_GetOpt_Obj(goi
, &o
);
256 e
= Jim_Nvp_name2value_obj(goi
->interp
, nvp
, o
, puthere
);
262 void Jim_GetOpt_NvpUnknown(Jim_GetOptInfo
* goi
, const Jim_Nvp
* nvptable
, int hadprefix
)
265 Jim_SetResult_NvpUnknown(goi
->interp
, goi
->argv
[-2], goi
->argv
[-1], nvptable
);
268 Jim_SetResult_NvpUnknown(goi
->interp
, NULL
, goi
->argv
[-1], nvptable
);
273 int Jim_GetOpt_Enum(Jim_GetOptInfo
* goi
, const char *const *lookup
, int *puthere
)
279 if (puthere
== NULL
) {
282 e
= Jim_GetOpt_Obj(goi
, &o
);
284 e
= Jim_GetEnum(goi
->interp
, o
, lookup
, puthere
, "option", JIM_ERRMSG
);
290 Jim_SetResult_NvpUnknown(Jim_Interp
*interp
,
291 Jim_Obj
*param_name
, Jim_Obj
*param_value
, const Jim_Nvp
* nvp
)
294 Jim_SetResultFormatted(interp
, "%#s: Unknown: %#s, try one of: ", param_name
, param_value
);
297 Jim_SetResultFormatted(interp
, "Unknown param: %#s, try one of: ", param_value
);
303 if ((nvp
+ 1)->name
) {
311 Jim_AppendStrings(interp
, Jim_GetResult(interp
), a
, b
, NULL
);
316 const char *Jim_Debug_ArgvString(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
318 static Jim_Obj
*debug_string_obj
;
322 if (debug_string_obj
) {
323 Jim_FreeObj(interp
, debug_string_obj
);
326 debug_string_obj
= Jim_NewEmptyStringObj(interp
);
327 for (x
= 0; x
< argc
; x
++) {
328 Jim_AppendStrings(interp
, debug_string_obj
, Jim_String(argv
[x
]), " ", NULL
);
331 return Jim_String(debug_string_obj
);
334 int Jim_nvpInit(Jim_Interp
*interp
)
336 /* This is really a helper library, not an extension, but this is the easy way */