From c91af9a17b0533c6df846ff712e7ade306c7b38a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 30 May 2017 23:04:31 -0700 Subject: command line: --eargs semantics change. The --eargs mechanism won't perform a blind substring replacement of {} with the following argument. Only arguments which match {} exactly are replaced. * eval.c (retf): Static function becomes extern. * eval.h (retf): Declared. * txr.c (txr_main): Replace the filtering logic on the split eargs argument list to just look for items equal to the string "{}" and replace with the following argument. * txr.1: Updated --eargs documentation. --- eval.c | 2 +- eval.h | 1 + txr.1 | 36 ++++++++++++++++++++++++++---------- txr.c | 5 ++--- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/eval.c b/eval.c index 4e6766d0..220355b3 100644 --- a/eval.c +++ b/eval.c @@ -5246,7 +5246,7 @@ static val do_retf(val ret, struct args *args) return ret; } -static val retf(val ret) +val retf(val ret) { return func_f0v(ret, do_retf); } diff --git a/eval.h b/eval.h index 69391879..75cf2c75 100644 --- a/eval.h +++ b/eval.h @@ -80,6 +80,7 @@ val mapcarv(val fun, struct args *lists); val mapcarl(val fun, val list_of_lists); val lazy_mapcar(val fun, val list); val generate(val while_pred, val gen_fun); +val retf(val ret); val prinl(val obj, val stream); val pprinl(val obj, val stream); val tprint(val obj, val out); diff --git a/txr.1 b/txr.1 index 09b1b172..26a66dbb 100644 --- a/txr.1 +++ b/txr.1 @@ -769,10 +769,10 @@ option (extended .codn --args ) is like .code --args -but must be followed by an argument. The argument is substituted -in place of occurrences of +but must be followed by an argument. The argument is removed from +the argument list and substituted in place of occurrences of .code {} -in the +among the arguments expanded from the .code --eargs syntax. @@ -1136,11 +1136,17 @@ The mechanism allows an additional flexibility. An .code --eargs argument must be followed by one more argument. -Occurrences of the two-character sequence + +After +.code --eargs +performs the argument splitting in the same manner as +.codn --args , +any of the arguments which it produces which are the +two-character sequence .code {} -in the encoded argument string are replaced with that -following argument. This replacement occurs after -the argument splitting. +are replaced with that following argument. Whether +or not the replacement occurs, that following argument +is then removed. Example: @@ -1172,9 +1178,11 @@ processing takes place, firstly the argument sequence -B {} --foo 42 .cble -is produced. Then, all occurrences of +is produced by splitting into four fields using the +.code : +character as the separator. Then, within these four fields, all occurrences of .code {} -are replaced with +are replaced with the following argument .codn script.txr , resulting in: @@ -1182,7 +1190,15 @@ resulting in: -B script.txr --foo 42 .cble -The resulting \*(TX invocation is +Furthermore, that +.code script.txr +argument is removed from the remaining argument list. + +The four arguments are then substituted in place of the original +.code --eargs:-B:{}:--foo:42 +syntax. + +The resulting \*(TX invocation is, therefore: .cblk /usr/bin/txr -B script.txr --foo 42 a b c diff --git a/txr.c b/txr.c index 3fdb18c0..ca80c2ca 100644 --- a/txr.c +++ b/txr.c @@ -573,9 +573,8 @@ int txr_main(int argc, char **argv) } arg = sub_str(arg, num(8), nil); arg2 = upop(&arg_list, &arg_undo); - arg_list = append2(mapcar(curry_123_3(func_n3(regsub), - regex_compile(lit("{}"), nil), - arg2), + arg_list = append2(mapcar(iffi(curry_12_2(equal_f, lit("{}")), + retf(arg2), nil), split_str(arg, sep)), arg_list); set(eff_arg_tail, butlastn(one, deref(eff_arg_tail))); -- cgit v1.2.3