diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-11-20 21:31:51 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-11-20 21:31:51 -0800 |
commit | d613cde8a2579f8e40248dc3839c39c89de4009e (patch) | |
tree | 4b1e25ae19d7ea812aaa0cef465d9a332ee9a30b | |
parent | 2c679f9bd0abcd8412b9162c74a58ba1eace3ed5 (diff) | |
download | txr-d613cde8a2579f8e40248dc3839c39c89de4009e.tar.gz txr-d613cde8a2579f8e40248dc3839c39c89de4009e.tar.bz2 txr-d613cde8a2579f8e40248dc3839c39c89de4009e.zip |
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.
-rw-r--r-- | txr.1 | 30 | ||||
-rw-r--r-- | txr.c | 24 |
2 files changed, 45 insertions, 9 deletions
@@ -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 @@ -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': |