]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/opt.h
tableprinter: code cleanup
[libucw.git] / ucw / opt.h
index e37fb68c1f42d7284ca6f9b221bfa0bf2fe34a03..557cadb16491255fcd62bf31ad120a87e9f001c9 100644 (file)
--- a/ucw/opt.h
+++ b/ucw/opt.h
@@ -3,6 +3,7 @@
  *
  *     (c) 2013 Jan Moskyto Matejka <mq@ucw.cz>
  *     (c) 2014 Martin Mares <mj@ucw.cz>
+ *     (c) 2014 Pavel Charvat <pchar@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -99,12 +100,12 @@ struct opt_item {
   const char * name;                   // long name (NULL if none)
   int letter;                          // short name (0 if none)
   void * ptr;                          // variable to store the value to
-  const char * help;                   // description in --help
+  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
     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
+    void (* hook)(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)
@@ -125,7 +126,6 @@ struct opt_item {
 #define OPT_NO_VALUE       0x4         /** The option must have no value. **/
 #define OPT_MAYBE_VALUE            0x8         /** The option may have a value. **/
 #define OPT_NEGATIVE       0x10        /** Reversing the effect of OPT_INC or saving @false into OPT_BOOL. **/
-#define OPT_NO_HELP        0x20        /** Exclude this option from the help. **/
 #define OPT_LAST_ARG       0x40        /** Stop processing arguments after this line. **/
 #define OPT_SINGLE         0x100       /** The option must appear at most once. **/
 #define OPT_MULTIPLE       0x200       /** The option may appear multiple times; will save all the values into a simple list. **/
@@ -170,6 +170,9 @@ struct opt_item {
 /** Ordinary integer option. @target should be a variable of type `int`. **/
 #define OPT_INT(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, int *), .help = desc, .flags = fl, .cls = OPT_CL_STATIC, .type = CT_INT }
 
+/** Unsigned integer option. @target should be a variable of type `uint`. **/
+#define OPT_UINT(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, uint *), .help = desc, .flags = fl, .cls = OPT_CL_STATIC, .type = CT_INT }
+
 /** 64-bit integer option. @target should be a variable of type `u64`. **/
 #define OPT_U64(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, u64 *), .help = desc, .flags = fl, .cls = OPT_CL_STATIC, .type = CT_U64 }
 
@@ -179,12 +182,15 @@ struct opt_item {
 /** IP address option, currently IPv4 only. @target should be a variable of type `u32`. **/
 #define OPT_IP(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, u32 *), .help = desc, .flags = fl, .cls = OPT_CL_STATIC, .type = CT_IP }
 
-/** Multi-valued string option. @target should be a growing array of `int`s. **/
-#define OPT_BOOL_MULTIPLE(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, char ***), .help = desc, .flags = fl, .cls = OPT_CL_MULTIPLE, .type = CT_STRING }
+/** Multi-valued string option. @target should be a growing array of `char *`s. **/
+#define OPT_STRING_MULTIPLE(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, char ***), .help = desc, .flags = fl, .cls = OPT_CL_MULTIPLE, .type = CT_STRING }
 
 /** Multi-valued integer option. @target should be a growing array of `int`s. **/
 #define OPT_INT_MULTIPLE(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, int **), .help = desc, .flags = fl, .cls = OPT_CL_MULTIPLE, .type = CT_INT }
 
+/** Multi-valued unsigned integer option. @target should be a growing array of `uint`s. **/
+#define OPT_UINT_MULTIPLE(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, uint **), .help = desc, .flags = fl, .cls = OPT_CL_MULTIPLE, .type = CT_INT }
+
 /** Multi-valued 64-bit integer option. @target should be a growing array of `u64`s. **/
 #define OPT_U64_MULTIPLE(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, u64 **), .help = desc, .flags = fl, .cls = OPT_CL_MULTIPLE, .type = CT_U64 }
 
@@ -200,6 +206,11 @@ struct opt_item {
 /** Incrementing option. @target should be a variable of type `int`. **/
 #define OPT_INC(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, int *), .flags = fl, .help = desc, .cls = OPT_CL_INC, .type = CT_INT }
 
+/* FIXME: Backwards compatibility only, should not be used anymore. */
+#define OPT_UNS OPT_UINT
+#define OPT_UNS_MULTIPLE OPT_UINT_MULTIPLE
+
+
 /**
  * When this option appears, call the function @fn with parameters @item, @value, @data,
  * where @item points to the <<struct_opt_item,`struct opt_item`>> of this option,
@@ -339,7 +350,7 @@ void opt_handle_help(struct opt_item * opt, const char * value, void * data);
 void opt_handle_config(struct opt_item * opt, const char * value, void * data);
 void opt_handle_set(struct opt_item * opt, const char * value, void * data);
 void opt_handle_dumpconfig(struct opt_item * opt, const char * value, void * data);
-void opt_conf_hook_internal(struct opt_item * opt, uns event, const char * value, void * data);
+void opt_conf_hook_internal(struct opt_item * opt, uint event, const char * value, void * data);
 
 // XXX: This is duplicated with <ucw/getopt.h>, but that one will hopefully go away one day.
 /**
@@ -372,7 +383,7 @@ extern char *cf_env_file;
 #define OPT_HOOK_BEFORE_ARG    0x1     /** Call before option parsing **/
 #define OPT_HOOK_BEFORE_VALUE  0x2     /** Call before value parsing **/
 #define OPT_HOOK_AFTER_VALUE   0x4     /** Call after value parsing **/
-#define OPT_HOOK_FINAL         0x8     /** Call just before opt_parse() returns **/
+#define OPT_HOOK_FINAL         0x8     /** Call just before @opt_parse() returns **/
 #define OPT_HOOK_INTERNAL       0x4000 // Used internally to ask for passing of struct opt_context
 
 #endif