+/***
+ * [[flags]]
+ * Option flags
+ * ------------
+ *
+ * Each option can specify a combination of the following flags.
+ ***/
+
+#define OPT_REQUIRED 0x1 /** The option must be always present. **/
+#define OPT_REQUIRED_VALUE 0x2 /** The option must have a value. **/
+#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. **/
+#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_INTERNAL 0x4000 // Used internally to ask for passing of struct opt_context to OPT_CALL
+
+/**
+ * If none of these flags are specified, a default is chosen automatically
+ * according to option class:
+ *
+ * - `OPT_MAYBE_VALUE` for `OPT_CL_STATIC`
+ * - `OPT_REQUIRED_VALUE` for `OPT_CL_MULTIPLE`
+ * - `OPT_NO_VALUE` for `OPT_CL_BOOL`, `OPT_CL_SWITCH` and `OPT_CL_INC`
+ * - An error is reported in all other cases.
+ **/
+#define OPT_VALUE_FLAGS (OPT_REQUIRED_VALUE | OPT_NO_VALUE | OPT_MAYBE_VALUE)
+
+/***
+ * [[macros]]
+ * Macros for declaration of options
+ * ---------------------------------
+ *
+ * In most cases, option definitions are built using these macros.
+ ***/
+
+/** Used inside `struct opt_section` to start a list of items. **/
+#define OPT_ITEMS .opt = ( struct opt_item[] )
+
+/** No option, just a piece of help text. **/
+#define OPT_HELP(line) { .help = line, .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")
+
+/** Boolean option. @target should be a variable of type `int`. **/
+#define OPT_BOOL(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, int *), .help = desc, .flags = fl, .cls = OPT_CL_BOOL, .type = CT_INT }
+
+/** String option. @target should be a variable of type `char *`. **/
+#define OPT_STRING(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, char **), .help = desc, .flags = fl, .cls = OPT_CL_STATIC, .type = CT_STRING }
+
+/** 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 }
+
+/** 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 }
+
+/** Floating-point option. @target should be a variable of type `double`. **/
+#define OPT_DOUBLE(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, double *), .help = desc, .flags = fl, .cls = OPT_CL_STATIC, .type = CT_DOUBLE }
+
+/** 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 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 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 }
+
+/** Multi-valued floating-point option. @target should be a growing array of `double`s. **/
+#define OPT_DOUBLE_MULTIPLE(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, double **), .help = desc, .flags = fl, .cls = OPT_CL_MULTIPLE, .type = CT_DOUBLE }
+
+/** Multi-valued IPv4 address option. @target should be a growing array of `u32`s. **/
+#define OPT_IP_MULTIPLE(shortopt, longopt, target, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, u32 **), .help = desc, .flags = fl, .cls = OPT_CL_MULTIPLE, .type = CT_IP }
+
+/** Switch option. @target should be a variable of type `int` and it will be set to the value @val. **/
+#define OPT_SWITCH(shortopt, longopt, target, val, fl, desc) { .letter = shortopt, .name = longopt, .ptr = CHECK_PTR_TYPE(&target, int *), .help = desc, .flags = fl, .cls = OPT_CL_SWITCH, .type = CT_LOOKUP, .u.value = val }
+
+/** 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 }
+
+/**
+ * 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,
+ * @value contains the current argument of the option (NULL if there is none),
+ * and @data is specified here.
+ **/
+#define OPT_CALL(shortopt, longopt, fn, data, fl, desc) { .letter = shortopt, .name = longopt, .ptr = data, .help = desc, .u.call = fn, .flags = fl, .cls = OPT_CL_CALL, .type = CT_USER }
+
+/**
+ * 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. If the @OPT_REQUIRED_VALUE
+ * flag is not set, the parser must be able to parse a NULL value.
+ **/
+#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 }
+
+/** 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 }