summaryrefslogtreecommitdiffstats
path: root/txr.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-02-06 22:47:47 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-02-06 22:47:47 -0800
commit76c9b4092e6b90c64273b567b8c42aee762c8615 (patch)
treec5c261b8d70a32214ba1cd10e59836ddc3a18a27 /txr.c
parenta634be3b976d91cf18ac130a0fb145e6176a1e53 (diff)
downloadtxr-76c9b4092e6b90c64273b567b8c42aee762c8615.tar.gz
txr-76c9b4092e6b90c64273b567b8c42aee762c8615.tar.bz2
txr-76c9b4092e6b90c64273b567b8c42aee762c8615.zip
txr: -D bugfixes.
* txr.c (txr_main): Don't use split_str to break -Dvar=val syntax, because that splits on all occurrences of the = character. Secondly, diagnose -Da,b,c shape: list commas occur with no = sign.
Diffstat (limited to 'txr.c')
-rw-r--r--txr.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/txr.c b/txr.c
index e94be080..df3f9b14 100644
--- a/txr.c
+++ b/txr.c
@@ -659,18 +659,31 @@ int txr_main(int argc, char **argv)
/* Odd case 3: -Dfoo=bar syntax. */
if (equal(sub(arg, zero, two), lit("-D"))) {
val dopt_arg = sub(arg, two, t);
- cons_bind(var, def, split_str(dopt_arg, lit("=")));
- val deflist = if2(def, split_str(car(def), lit(",")));
- val sym = intern(var, cur_package);
-
- if (rest(deflist))
- bindings = cons(cons(sym, deflist), bindings);
- else if (deflist)
- bindings = cons(cons(sym, car(deflist)), bindings);
- else
- bindings = cons(cons(sym, null_string), bindings);
-
- match_reg_var(sym);
+ val eq_pos = search_str(dopt_arg, lit("="), nil, nil);
+
+ if (eq_pos) {
+ val var = sub_str(dopt_arg, zero, eq_pos);
+ val def = sub_str(dopt_arg, succ(eq_pos), t);
+ val deflist = split_str(def, lit(","));
+ val sym = intern(var, cur_package);
+
+ if (rest(deflist))
+ bindings = cons(cons(sym, deflist), bindings);
+ else
+ bindings = cons(cons(sym, car(deflist)), bindings);
+
+ match_reg_var(sym);
+ } else {
+ if (search_str(dopt_arg, lit(","), nil, nil)) {
+ format(std_error,
+ lit("~a: bad -D syntax: ~a\n"), prog_string, arg, nao);
+ return EXIT_FAILURE;
+ } else {
+ val sym = intern(dopt_arg, cur_package);
+ bindings = cons(cons(sym, null_string), bindings);
+ match_reg_var(sym);
+ }
+ }
continue;
}