static void opt_help_scan_item(struct help *h, struct opt_precomputed *opt)
{
- struct opt_item *item = opt->item;
+ const struct opt_item *item = opt->item;
if (!item->help)
return;
static void opt_help_scan(struct help *h, const struct opt_section *sec)
{
- for (struct opt_item * item = sec->opt; item->cls != OPT_CL_END; item++) {
+ for (const struct opt_item * item = sec->opt; item->cls != OPT_CL_END; item++) {
if (item->cls == OPT_CL_SECTION)
opt_help_scan(h, item->u.section);
else if (item->cls == OPT_CL_HOOK)
const struct opt_section * options;
struct opt_precomputed * opts;
struct opt_precomputed ** shortopt;
- struct opt_item ** hooks;
+ const struct opt_item ** hooks;
int opt_count;
int hook_count;
int positional_max;
};
struct opt_precomputed {
- struct opt_item * item;
+ const struct opt_item * item;
const char * name;
short flags;
short count;
};
-void opt_precompute(struct opt_precomputed *opt, struct opt_item *item);
+void opt_precompute(struct opt_precomputed *opt, const struct opt_item *item);
#endif
static char *opt_name(struct opt_context *oc, struct opt_precomputed *opt)
{
- struct opt_item *item = opt->item;
+ const struct opt_item *item = opt->item;
char *res;
if (item->letter >= OPT_POSITIONAL_TAIL)
res = stk_printf("positional argument #%d", oc->positional_count);
#define THIS_OPT opt_name(oc, opt)
-void opt_precompute(struct opt_precomputed *opt, struct opt_item *item)
+void opt_precompute(struct opt_precomputed *opt, const struct opt_item *item)
{
opt->item = item;
opt->count = 0;
opt->flags = flags;
}
-static void opt_invoke_hooks(struct opt_context *oc, uint event, struct opt_item *item, char *value)
+static void opt_invoke_hooks(struct opt_context *oc, uint event, const struct opt_item *item, char *value)
{
for (int i = 0; i < oc->hook_count; i++) {
- struct opt_item *hook = oc->hooks[i];
+ const struct opt_item *hook = oc->hooks[i];
if (hook->flags & event) {
void *data = (hook->flags & OPT_HOOK_INTERNAL) ? oc : hook->ptr;
hook->u.hook(item, event, value, data);
}
static void opt_parse_value(struct opt_context * oc, struct opt_precomputed * opt, char * value) {
- struct opt_item * item = opt->item;
+ const struct opt_item * item = opt->item;
if (opt->count++ && (opt->flags & OPT_SINGLE))
opt_failure("Option %s must be specified at most once.", THIS_OPT);
static void opt_prepare_items(struct opt_context *oc, const struct opt_section *sec)
{
- for (struct opt_item *item = sec->opt; item->cls != OPT_CL_END; item++) {
+ for (const struct opt_item *item = sec->opt; item->cls != OPT_CL_END; item++) {
if (item->cls == OPT_CL_SECTION)
opt_prepare_items(oc, item->u.section);
else if (item->cls == OPT_CL_HOOK)
for (int i = 0; i < oc->opt_count; i++) {
struct opt_precomputed *opt = &oc->opts[i];
if (!opt->count && (opt->flags & OPT_REQUIRED)) {
- struct opt_item *item = opt->item;
+ const struct opt_item *item = opt->item;
if (item->letter > OPT_POSITIONAL_TAIL)
opt_failure("Required positional argument #%d not found.", item->letter - OPT_POSITIONAL_TAIL);
else if (item->letter == OPT_POSITIONAL_TAIL)
/** A section of option list. **/
struct opt_section {
- struct opt_item * opt;
+ const struct opt_item * opt;
};
/** A definition of a single option item. **/
void * ptr; // variable to store the value to
const char * help; // description in --help (NULL to omit the option from the help)
union opt_union {
- struct opt_section * section; // subsection for OPT_CL_SECTION
+ const struct opt_section * section; // subsection for OPT_CL_SECTION
int value; // value for OPT_CL_SWITCH
- void (* call)(struct opt_item * opt, const char * value, void * data); // function to call for OPT_CL_CALL
- void (* hook)(struct opt_item * opt, uint event, const char * value, void * data); // function to call for OPT_CL_HOOK
+ void (* call)(const struct opt_item * opt, const char * value, void * data); // function to call for OPT_CL_CALL
+ void (* hook)(const struct opt_item * opt, uint event, const char * value, void * data); // function to call for OPT_CL_HOOK
struct cf_user_type * utype; // specification of the user-defined type for CT_USER
} u;
u16 flags; // as defined below (for hooks, event mask is stored instead)