]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/opt.h
Tests: xtypes-test sets an explicit timezone
[libucw.git] / ucw / opt.h
index 3f1be8127511327eeb8b9ba0c5b36ffdf1f1b3cd..c8c683c03cb70775137fd20185f3c00a604e5f4f 100644 (file)
--- a/ucw/opt.h
+++ b/ucw/opt.h
@@ -14,6 +14,7 @@
 
 #include <ucw/lib.h>
 #include <ucw/conf.h>
+#include <ucw/xtypes.h>
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -110,6 +111,7 @@ struct opt_item {
     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
@@ -134,6 +136,7 @@ struct opt_item {
 #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
 
 /**
@@ -161,6 +164,9 @@ struct opt_item {
 /** 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")
 
@@ -235,6 +241,16 @@ struct opt_item {
 /** 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 }