- fprintf(stderr, "%s %s\n", spaces + strlen(item->help), item->u.help2);
- } else if (item->cls == OPT_CL_SECTION) {
- opt_help_noexit_internal(item->u.section);
- } else if (item->letter) {
- sprintf(buf, "-%c, --%s%s", item->letter, item->name, VAL(item));
- fprintf(stderr, "%s%s %s\n", buf, spaces + strlen(buf), item->help);
- } else {
- sprintf(buf, "--%s%s", item->name, VAL(item));
- fprintf(stderr, "%s%s %s\n", buf, spaces + strlen(buf), item->help);
+ opt_failure("Boolean argument for %s has a strange value. Supported (case insensitive): 1/0, y/n, yes/no, true/false.", THIS_OPT);
+ break;
+ case OPT_CL_STATIC:
+ case OPT_CL_MULTIPLE:
+ {
+ char * e = NULL;
+ void * ptr;
+ if (item->cls == OPT_CL_STATIC)
+ ptr = item->ptr;
+ else
+ ptr = GARY_PUSH_GENERIC(*(void **)item->ptr);
+#define OPT_PTR(type) ((type *) ptr)
+ switch (item->type) {
+ case CT_INT:
+ if (!value)
+ *OPT_PTR(int) = 0;
+ else
+ e = cf_parse_int(value, OPT_PTR(int));
+ if (e)
+ opt_failure("Integer value parsing failed for %s: %s", THIS_OPT, e);
+ break;
+ case CT_U64:
+ if (!value)
+ *OPT_PTR(u64) = 0;
+ else
+ e = cf_parse_u64(value, OPT_PTR(u64));
+ if (e)
+ opt_failure("Unsigned 64-bit value parsing failed for %s: %s", THIS_OPT, e);
+ break;
+ case CT_DOUBLE:
+ if (!value)
+ *OPT_PTR(double) = NAN;
+ else
+ e = cf_parse_double(value, OPT_PTR(double));
+ if (e)
+ opt_failure("Floating-point value parsing failed for %s: %s", THIS_OPT, e);
+ break;
+ case CT_IP:
+ if (!value)
+ *OPT_PTR(u32) = 0;
+ else
+ e = cf_parse_ip(value, OPT_PTR(u32));
+ if (e)
+ opt_failure("IP address parsing failed for %s: %s", THIS_OPT, e);
+ break;
+ case CT_STRING:
+ if (!value)
+ *OPT_PTR(const char *) = NULL;
+ else
+ *OPT_PTR(const char *) = xstrdup(value);
+ break;
+ case CT_USER:
+ {
+ char * e = item->u.utype->parser(value, ptr);
+ if (e)
+ opt_failure("Cannot parse the value of %s: %s", THIS_OPT, e);
+ break;
+ }
+ default:
+ ASSERT(0);
+ }
+#undef OPT_PTR
+ break;
+ }
+ case OPT_CL_SWITCH:
+ if ((opt->flags & OPT_SINGLE) && *((int *)item->ptr) != -1)
+ opt_failure("Multiple switches: %s", THIS_OPT);
+ else
+ *((int *)item->ptr) = item->u.value;
+ break;
+ case OPT_CL_INC:
+ if (opt->flags & OPT_NEGATIVE)
+ (*((int *)item->ptr))--;
+ else
+ (*((int *)item->ptr))++;
+ break;
+ case OPT_CL_CALL:
+ {
+ void *data = (opt->flags & OPT_INTERNAL) ? oc : item->ptr;
+ item->u.call(item, value, data);
+ break;
+ }
+ default:
+ ASSERT(0);
+ }
+
+ opt_invoke_hooks(oc, OPT_HOOK_AFTER_VALUE, item, value);
+}
+
+static int opt_longopt(struct opt_context * oc, char ** argv, int index) {
+ int eaten = 0;
+ char * name_in = argv[index] + 2; // skipping the -- on the beginning
+ uint pos = strchrnul(name_in, '=') - name_in;
+ struct opt_precomputed * opt = opt_find_item_longopt(oc, strndupa(name_in, pos));
+ char * value = NULL;
+
+ opt->flags |= OPT_SEEN_AS_LONG;
+
+ if (opt->item->cls == OPT_CL_BOOL &&
+ ((opt->flags & OPT_NEGATIVE)
+ ? (!strncmp(opt->item->name, "no-", 3) && !strncmp(name_in, opt->item->name + 3, pos-3))
+ : (!strncmp(name_in, "no-", 3) && !strncmp(name_in+3, opt->item->name, pos-3)))) {
+ if (name_in[pos])
+ opt_failure("Option --%s must not have any value.", name_in);
+ value = "n";
+ } else if (opt->flags & OPT_REQUIRED_VALUE) {
+ if (name_in[pos])
+ value = name_in + pos + 1;
+ else {
+ value = argv[index+1];
+ if (!value)
+ opt_failure("Option %s must have a value, but nothing supplied.", THIS_OPT);
+ eaten++;