#include <ucw/lib.h>
#include <ucw/conf.h>
+#include <ucw/xtypes.h>
#include <stdlib.h>
#include <stdio.h>
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
+ const struct xtype * xtype; // specification of the extended type for CT_XTYPE
} u;
u16 flags; // as defined below (for hooks, event mask is stored instead)
byte cls; // enum opt_class
#define OPT_MULTIPLE 0x200 /** The option may appear multiple times; will save all the values into a simple list. **/
#define OPT_SEEN_AS_LONG 0x400 // Used internally to signal that we currently process the long form of the option
#define OPT_BEFORE_CONFIG 0x800 /** The option may appear before a config file is loaded. **/
+#define OPT_HELP_COL 0x1000 /** Used for OPT_CL_HELP to signal that tabs switch columns. **/
#define OPT_INTERNAL 0x4000 // Used internally to ask for passing of struct opt_context to OPT_CALL
/**
/** No option, just a piece of help text. **/
#define OPT_HELP(line) { .help = line, .cls = OPT_CL_HELP }
+/** Like OPT_HELP, but the help text uses tab characters to switch columns like help text for ordinary options does. **/
+#define OPT_HELP_COLUMNS(line) { .help = line, .flags = OPT_HELP_COL, .cls = OPT_CL_HELP }
+
/** Standard `--help` option. **/
#define OPT_HELP_OPTION OPT_CALL(0, "help", opt_handle_help, NULL, OPT_BEFORE_CONFIG | OPT_INTERNAL | OPT_NO_VALUE, "\tShow this help")
/** Multi-valued option of user-defined type. @target should be a growing array of the right kind of items. **/
#define OPT_USER_MULTIPLE(shortopt, longopt, target, ttype, fl, desc) { .letter = shortopt, .name = longopt, .ptr = &target, .u.utype = &ttype, .flags = fl, .help = desc, .cls = OPT_CL_MULTIPLE, .type = CT_USER }
+/**
+ * An option with user-defined syntax. @xtype is a <<xtypes:struct_xtype,`xtype`>>
+ * describing the syntax, @target is a variable of the corresponding type. If the @OPT_REQUIRED_VALUE
+ * flag is not set, the parser must be able to parse a NULL value.
+ **/
+#define OPT_XTYPE(shortopt, longopt, target, ttype, fl, desc) { .letter = shortopt, .name = longopt, .ptr = &target, .u.xtype = &ttype, .flags = fl, .help = desc, .cls = OPT_CL_STATIC, .type = CT_XTYPE }
+
+/** Multi-valued option of extended type. @target should be a growing array of the right kind of items. **/
+#define OPT_XTYPE_MULTIPLE(shortopt, longopt, target, ttype, fl, desc) { .letter = shortopt, .name = longopt, .ptr = &target, .u.xtype = &ttype, .flags = fl, .help = desc, .cls = OPT_CL_MULTIPLE, .type = CT_XTYPE }
+
/** A sub-section. **/
#define OPT_SECTION(sec) { .cls = OPT_CL_SECTION, .u.section = &sec }