diff options
author | Peter Johnson <peter@tortall.net> | 2014-10-05 10:31:26 -0700 |
---|---|---|
committer | Peter Johnson <peter@tortall.net> | 2014-10-05 10:31:26 -0700 |
commit | 1962750ea6c9f33c3530783c02e66f0e493bd046 (patch) | |
tree | 6d6eb97c8c1f5f9860b9abc41d7d58fa50d1058d | |
parent | 85b88de12d227a3e014f3217b845876174579609 (diff) | |
download | yasm-1962750ea6c9f33c3530783c02e66f0e493bd046.tar.gz |
Allow -longopt as well as --longopt.
This is more consistent with other tools.
-rw-r--r-- | frontends/yasm/yasm-options.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/frontends/yasm/yasm-options.c b/frontends/yasm/yasm-options.c index eff6ba9a..1545c41a 100644 --- a/frontends/yasm/yasm-options.c +++ b/frontends/yasm/yasm-options.c @@ -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; |