item->u.call(item, value, data);
break;
}
+ case OPT_CL_BREAK:
+ oc->stop_parsing = 2;
+ break;
default:
ASSERT(0);
}
opt_prepare_items(oc, options);
int force_positional = 0;
- int i;
+ int i, start_i = 0;
for (i=0; argv[i] && !oc->stop_parsing; i++) {
+ start_i = i;
char *arg = argv[i];
opt_invoke_hooks(oc, OPT_HOOK_BEFORE_ARG, NULL, NULL);
if (arg[0] != '-' || force_positional)
opt_check_required(oc);
opt_invoke_hooks(oc, OPT_HOOK_FINAL, NULL, NULL);
- return i;
+ return (oc->stop_parsing < 2 ? i : start_i);
}
* contents of another list of options.
* - `OPT_CL_HELP`: no option, just print a help text.
* - `OPT_CL_HOOK`: no option, but a definition of a <<hooks,hook>>.
+ * - `OPT_CL_BREAK`: when a given option occurs, stop parsing and keep
+ * the option in the argument list.
***/
enum opt_class {
OPT_CL_SECTION,
OPT_CL_HELP,
OPT_CL_HOOK,
+ OPT_CL_BREAK,
};
/***
/** Incrementing option. @target should be a variable of type `int`. **/
#define OPT_INC(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, int *), .flags = fl, .help = desc, .cls = OPT_CL_INC, .type = CT_INT }
+/** Breakpoint option. When this option occurs, parsing is terminated and the option is kept in the argument array. **/
+#define OPT_BREAK(shortopt, longopt, fl) { .letter = shortopt, .name = longopt, .flags = fl, .cls = OPT_CL_BREAK }
+
/* FIXME: Backwards compatibility only, should not be used anymore. */
#define OPT_UNS OPT_UINT
#define OPT_UNS_MULTIPLE OPT_UINT_MULTIPLE