]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/opt.h
Tests: xtypes-test sets an explicit timezone
[libucw.git] / ucw / opt.h
index 20df7fd7b340d5277c4e34ed175d2b39988c8b36..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
@@ -239,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 }