Alternatively, the short name can refer to a <<positional,positional argument>>.
- Long name: an arbitrary string. Set to NULL if the option has no long form.
- Variable, where the value of the option shall be stored, together with
- its <<conf:enum_cf_type,data type>>.
+ its <<conf:enum_cf_type,data type>>. The type is either one of the conventional
+ types (`int`, `uns`, etc.), or a user-defined type providing its own parser
+ function via <<conf:struct_cf_user_type,`cf_user_type`>>.
- <<flags,Flags>> further specifying behavior of the option (whether it is mandatory,
whether it carries a value, whether it can be set repeatedly, etc.).
- Help text, from which the help displayed to the user is constructed.
[OPT_CL_SWITCH] = OPT_NO_VALUE,
[OPT_CL_INC] = OPT_NO_VALUE,
[OPT_CL_CALL] = 0,
- [OPT_CL_USER] = 0,
[OPT_CL_SECTION] = 0,
[OPT_CL_HELP] = 0
};
flags |= OPT_REQUIRED_VALUE;
}
if (!(flags & OPT_VALUE_FLAGS)) {
- ASSERT(item->cls != OPT_CL_CALL && item->cls != OPT_CL_USER);
+ ASSERT(item->cls != OPT_CL_CALL);
flags |= opt_default_value_flags[item->cls];
}
else
*OPT_PTR(const char *) = xstrdup(value);
break;
+ case CT_USER:
+ {
+ char * e = item->u.utype->parser(value, item->ptr);
+ if (e)
+ opt_failure("Cannot parse the value of %s: %s", THIS_OPT, e);
+ break;
+ }
default:
ASSERT(0);
}
item->u.call(item, value, data);
break;
}
- case OPT_CL_USER:
- {
- char * e = NULL;
- e = item->u.utype->parser(value, OPT_PTR(void*));
- if (e)
- opt_failure("Cannot parse the value of %s: %s", THIS_OPT, e);
- break;
- }
default:
ASSERT(0);
}
* `OPT_NEGATIVE` flag is set).
* - `OPT_CL_CALL`: instead of setting a variable, call a function
* and pass the value of the option to it.
- * - `OPT_CL_USER`: like `OPT_CL_STATIC`, but with user-defined value
- * syntax, specified as <<conf:struct_cf_user_type,`cf_user_type`>>.
* - `OPT_CL_SECTION`: not a real option, but an instruction to insert
* contents of another list of options.
* - `OPT_CL_HELP`: no option, just print a help text.
OPT_CL_SWITCH,
OPT_CL_INC,
OPT_CL_CALL,
- OPT_CL_USER,
OPT_CL_SECTION,
OPT_CL_HELP,
OPT_CL_HOOK,
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, uns 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 OPT_CL_USER
+ 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)
byte cls; // enum opt_class
* An option with user-defined syntax. @ttype is a <<conf:struct_cf_user_type,`cf_user_type`>>
* describing the syntax, @target is a variable of the corresponding type.
**/
-#define OPT_USER(shortopt, longopt, target, ttype, fl, desc) { .letter = shortopt, .name = longopt, .ptr = &target, .u.utype = &ttype, .flags = fl, .help = desc, .cls = OPT_CL_USER, .type = CT_USER }
+#define OPT_USER(shortopt, longopt, target, ttype, fl, desc) { .letter = shortopt, .name = longopt, .ptr = &target, .u.utype = &ttype, .flags = fl, .help = desc, .cls = OPT_CL_STATIC, .type = CT_USER }
/** A sub-section. **/
#define OPT_SECTION(sec) { .cls = OPT_CL_SECTION, .u.section = &sec }