Ticket #8666: longoptions.patch

File longoptions.patch, 1.1 KB (added by jvprat, 17 years ago)
  • base/commandLine.cpp

     
    245245                } \
    246246                const char *option = s; \
    247247                if (*s == '\0' && !isLongCmd) { option = s2; i++; } \
    248                 if (!option) option = defaultVal; \
     248                if (!option || *option == '\0') option = defaultVal; \
    249249                if (option) settings[longCmd] = option;
    250250
    251251// Use this for options which have a required (string) value
    252252#define DO_OPTION(shortCmd, longCmd) \
    253253        DO_OPTION_OPT(shortCmd, longCmd, 0) \
    254         if (!option) usage("Option '%s' requires an argument", argv[i-1]);
     254        if (!option) usage("Option '%s' requires an argument", argv[isLongCmd ? i : i-1]);
    255255
    256256// Use this for options which have a required integer value
    257257#define DO_OPTION_INT(shortCmd, longCmd) \
    258         DO_OPTION_OPT(shortCmd, longCmd, 0) \
    259         if (!option) usage("Option '%s' requires an argument", argv[i-1]); \
     258        DO_OPTION(shortCmd, longCmd) \
    260259        char *endptr = 0; \
    261260        int intValue; intValue = (int)strtol(option, &endptr, 0); \
    262261        if (endptr == NULL || *endptr != 0) usage("--%s: Invalid number '%s'", longCmd, option);