From d613cde8a2579f8e40248dc3839c39c89de4009e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 20 Nov 2016 21:31:51 -0800 Subject: Revive -b option for binding Lisp variables. * txr.c (txr_main): Implement -b option that takes an argument. Ensure that -b produces an error if clumped with other options. * txr.1: Documented -b var=val. --- txr.1 | 30 ++++++++++++++++++++++++------ txr.c | 24 +++++++++++++++++++++--- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/txr.1 b/txr.1 index 8e1d2dca..c7d408e1 100644 --- a/txr.1 +++ b/txr.1 @@ -482,12 +482,30 @@ of this function. Verbose operation. Detailed logging is enabled. .coIP -b -This is a deprecated option, which is silently ignored. In \*(TX versions -prior to 90, the printing of variable bindings (see -.code -B -option) was -implicit behavior which was automatically suppressed in certain situations. -The -b option suppressed it unconditionally. +This option binds a Lisp global lexical variable (as if by the +.code defparml +function) to an object described by Lisp syntax. It requires an argument +of the form +.meta sym=value +where +.code sym +must be, syntactically, a token denoting a bindable symbol, and +.meta value +is arbitrary \*(TL syntax. The +.meta sym +syntax is converted to the symbol it denotes, which is bound as a global +lexical variable, if it is not already a variable. +The +.meta value +syntax is parsed to the Lisp object it denotes. This object is not subject +to evaluation; the object itself is stored into the variable binding denoted +by +.metn sym . +Note that if +.meta sym +already exists as a global variable, then it is simply overwritten. If +.meta sym +is marked special, then it stays special. .coIP -B If the query is successful, print the variable bindings as a sequence diff --git a/txr.c b/txr.c index c31c7fa2..9bc3d5fe 100644 --- a/txr.c +++ b/txr.c @@ -728,7 +728,7 @@ int txr_main(int argc, char **argv) } /* Single letter options with args: non-clumping. */ - if (length(arg) == two && find(ref(arg, one), lit("acfepPtC"), nil, nil)) + if (length(arg) == two && find(ref(arg, one), lit("abcfepPtC"), nil, nil)) { val opt = chr_str(arg, one); @@ -749,6 +749,25 @@ int txr_main(int argc, char **argv) if (!do_fixnum_opt(compat, opt, arg)) return EXIT_FAILURE; break; + 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)) { + format(std_error, + lit("~a: ~s isn't a bindable symbol\n"), + prog_string, sym, nao); + return EXIT_FAILURE; + } + + reg_var(sym, obj); + } + break; case 'c': if (txr_lisp_p) { format(std_error, @@ -827,8 +846,6 @@ int txr_main(int argc, char **argv) case 'q': match_loglevel = 0; break; - case 'b': /* deprecated */ - break; case 'B': opt_print_bindings = 1; break; @@ -861,6 +878,7 @@ int txr_main(int argc, char **argv) stream_set_prop(std_input, real_time_k, nil); break; case 'a': + case 'b': case 'c': case 'e': case 'p': -- cgit v1.2.3