diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-01-28 06:25:08 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-01-28 06:25:08 -0800 |
commit | b839a3fb4b337f2d48a05f580550698f3eeef9f5 (patch) | |
tree | 8b772043f168522d0b13c59ef7630c0c4e39aea3 | |
parent | 249f3b085eed719f03d60258ef40e501dd783f2f (diff) | |
download | txr-b839a3fb4b337f2d48a05f580550698f3eeef9f5.tar.gz txr-b839a3fb4b337f2d48a05f580550698f3eeef9f5.tar.bz2 txr-b839a3fb4b337f2d48a05f580550698f3eeef9f5.zip |
command line: better diagnosis for --args and --eargs
* txr.c (txr_main): Diagnose accurately when --args
or --eargs is specified without any of the required trailing
syntax, instead of complaining about --args or --eargs being an
unknown option. Also, fix the error message about --eargs not having
an argument, such that it doesn't insinuate that there exists
an --eargs=value syntax.
-rw-r--r-- | txr.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -575,8 +575,14 @@ int txr_main(int argc, char **argv) /* Odd case 1: --args is followed by an arbitrary delimiting * character, not necessarily = */ - if (match_str(arg, lit("--args"), zero) && ge(length(arg), num(7))) { + if (match_str(arg, lit("--args"), zero)) { val sep = sub_str(arg, num(6), num(7)); + if (empty(sep)) { + format(std_error, + lit("~a: --args requires argument material\n"), + prog_string, nao); + return EXIT_FAILURE; + } arg = sub_str(arg, num(7), nil); arg_list = append2(split_str(arg, sep), arg_list); set(eff_arg_tail, butlastn(one, deref(eff_arg_tail))); @@ -585,12 +591,18 @@ int txr_main(int argc, char **argv) /* Odd case 2: --eargs is followed by an arbitrary delimiting * character, not necessarily = */ - if (match_str(arg, lit("--eargs"), zero) && ge(length(arg), num(8))) { + if (match_str(arg, lit("--eargs"), zero)) { val sep = sub_str(arg, num(7), num(8)); val arg2; + if (empty(sep)) { + format(std_error, + lit("~a: --eargs requires argument material\n"), + prog_string, nao); + return EXIT_FAILURE; + } if (!arg_list) { format(std_error, - lit("~a: --eargs=[...] must be followed by an argument\n"), + lit("~a: --eargs must be followed by an argument\n"), prog_string, nao); return EXIT_FAILURE; } |