GetOpt - how to. Example (short and incomplete): \code struct jim_getopt_info goi; jim_getopt_setup(&goi, interp, argc, argv); 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; } } } \endcode Setup GETOPT \code struct jim_getopt_info goi; Jim_GetOptSetup(&goi, interp, argc, argv); \endcode
Create an appropriate error message for an NVP. 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: \code 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] } } \endcode