]> granicus.if.org Git - yasm/commitdiff
Allow -longopt as well as --longopt.
authorPeter Johnson <peter@tortall.net>
Sun, 5 Oct 2014 17:31:26 +0000 (10:31 -0700)
committerPeter Johnson <peter@tortall.net>
Sun, 5 Oct 2014 17:31:26 +0000 (10:31 -0700)
This is more consistent with other tools.

frontends/yasm/yasm-options.c

index eff6ba9a00e71043cd942f6d674e925c76c9e3cf..1545c41ae62a44ab92754c353b5756f6564d2498 100644 (file)
@@ -112,6 +112,7 @@ parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts,
                     errors++;
             } else {            /* sopt */
                 for (i = 0; i < nopts; i++) {
+                    size_t optlen;
                     if (argv[0][1] == options[i].sopt) {
                         char *cmd = &argv[0][1];
                         char *param;
@@ -137,6 +138,36 @@ parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts,
                             got_it = 1;
                         break;
                     }
+                    /* also allow longopt with single dash */
+                    if (options[i].lopt &&
+                        strncmp(&argv[0][1], options[i].lopt,
+                                (optlen = strlen(options[i].lopt))) == 0) {
+                        char *param;
+                        char c = argv[0][1 + optlen];
+
+                        if (c != '\0' && c != '=' && !isspace(c))
+                            continue;
+
+                        if (options[i].takes_param) {
+                            param = strchr(&argv[0][1], '=');
+                            if (!param) {
+                                print_error(
+                                    _("option `-%s' needs an argument!"),
+                                    options[i].lopt);
+                                errors++;
+                                goto fail;
+                            } else {
+                                *param = '\0';
+                                param++;
+                            }
+                        } else
+                            param = NULL;
+
+                        if (!options[i].
+                            handler(&argv[0][1], param, options[i].extra))
+                            got_it = 1;
+                        break;
+                    }
                 }
                 if (!got_it && !other_option_handler(argv[0]))
                     got_it = 1;