summaryrefslogtreecommitdiffstats
path: root/txr.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-07-01 22:44:45 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-07-01 22:44:45 -0700
commit0f26cfaba854a5c13dee193680f7e516185662f5 (patch)
tree2dc44d02d1dd052cc001cc42866d39d81ba09dba /txr.c
parentdd3ff4c38db7c9daa72d5074c986a1462ab3bb8e (diff)
downloadtxr-0f26cfaba854a5c13dee193680f7e516185662f5.tar.gz
txr-0f26cfaba854a5c13dee193680f7e516185662f5.tar.bz2
txr-0f26cfaba854a5c13dee193680f7e516185662f5.zip
main: maintain -b option.
* txr.c (help): Remove -b help text which pertains to an ancient -b option that was deprecated in 2014. Add correct help text for -b. (txr_main): Use split_str for the argument of -b. If it fails to produce a two-element list, it means the equal sign is missing; issue an error message and exit. Thereby we avoid passing nil as the input source argument of lisp_parse.
Diffstat (limited to 'txr.c')
-rw-r--r--txr.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/txr.c b/txr.c
index 81d946bc..67029e28 100644
--- a/txr.c
+++ b/txr.c
@@ -105,8 +105,6 @@ static void help(void)
"-Dvar Predefine variable var, with empty string value.\n"
"-q Quiet: don't report errors during query matching.\n"
"-v Verbose: extra logging from matcher.\n"
-"-b Don't dump list of bindings, or 'false'\n"
-" on unsuccessful termination.\n"
"-B Force list of bindings to be dumped, or false\n"
" if termination is unsuccessful.\n"
"-l If dumping bindings, use TXR Lisp format.\n"
@@ -134,6 +132,9 @@ static void help(void)
" using the prinl function.\n"
"-P expression Like -p, but prints using pprinl.\n"
"-t expression Like -p, but prints using tprint.\n"
+"-b var=value Bind a Lisp global variable as if by defparml.\n"
+" var and value are parsed as Lisp syntax.\n"
+" value is not evaluated.\n"
"-C N Request backward-compatible behavior to the\n"
" specified version of TXR.\n"
"--help Reproduce this help text.\n"
@@ -843,20 +844,27 @@ int txr_main(int argc, char **argv)
case 'b':
drop_privilege();
{
- val pair = partition_star(arg, pos(chr('='), arg, nil, nil));
- val sym = lisp_parse(pop(&pair), std_error,
- colon_k, lit("cmdline-expr"), colon_k);
- val obj = lisp_parse(pop(&pair), std_error,
- colon_k, lit("cmdline-expr"), colon_k);
-
- if (!bindable(sym)) {
+ val pair = split_str(arg, chr('='));
+ if (cdr(pair)) {
+ val sym = lisp_parse(pop(&pair), std_error,
+ colon_k, lit("cmdline-expr"), colon_k);
+ val obj = lisp_parse(pop(&pair), std_error,
+ colon_k, lit("cmdline-expr"), colon_k);
+
+ if (!bindable(sym)) {
+ format(std_error,
+ lit("~a: ~s isn't a bindable symbol\n"),
+ prog_string, sym, nao);
+ return EXIT_FAILURE;
+ }
+
+ reg_var(sym, obj);
+ } else {
format(std_error,
- lit("~a: ~s isn't a bindable symbol\n"),
- prog_string, sym, nao);
+ lit("~a: -b argument must be var=val syntax\n"),
+ prog_string, nao);
return EXIT_FAILURE;
}
-
- reg_var(sym, obj);
}
break;
case 'c':