From 82a698d3339cfd92912d02484e1d67e792212ecf Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 7 Mar 2014 00:03:48 -0800 Subject: * lib.c (upop): New function. * lib.h (upop): Declared. * txr.c (txr_main): Two bugfixes. One is that the argument - was being pushed back twice resulting in *args* being ("-" "-"). This is because the option processing loop checked for "-" and pushed it back into args, and then some logic after the loop pushed arg back into args again. But, these pushes were wrong because they push back a different cons cell; we would like to be able to do (ldiff *full-args* *args*). This is solved by upop, which provides one element of undo. After upop, we can restore the prior list from the undo save location. --- ChangeLog | 16 ++++++++++++++++ lib.c | 6 ++++++ lib.h | 1 + txr.c | 16 ++++++++-------- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index e6df860d..d9d74336 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2014-03-06 Kaz Kylheku + + * lib.c (upop): New function. + + * lib.h (upop): Declared. + + * txr.c (txr_main): Two bugfixes. One is that the argument - + was being pushed back twice resulting in *args* being ("-" "-"). + This is because the option processing loop checked for "-" and pushed + it back into args, and then some logic after the loop pushed arg back + into args again. But, these pushes were wrong because they push + back a different cons cell; we would like to be able to + do (ldiff *full-args* *args*). This is solved by upop, which provides + one element of undo. After upop, we can restore the prior list + from the undo save location. + 2014-03-06 Kaz Kylheku * lib.c (assert_s): New global variable. diff --git a/lib.c b/lib.c index 4365c4b8..2b5bd031 100644 --- a/lib.c +++ b/lib.c @@ -426,6 +426,12 @@ val pop(val *plist) return ret; } +val upop(val *plist, val *pundo) +{ + *pundo = *plist; + return pop(plist); +} + val push(val value, val *plist) { /* Unsafe for mutating object fields: use mpush macro. */ diff --git a/lib.h b/lib.h index ab519088..c1524891 100644 --- a/lib.h +++ b/lib.h @@ -385,6 +385,7 @@ val *tail(val cons); val *lastcons(val list); val *ltail(val *cons); val pop(val *plist); +val upop(val *plist, val *pundo); val push(val v, val *plist); val copy_list(val list); val make_like(val list, val thatobj); diff --git a/txr.c b/txr.c index 2e3b6ac5..9dbb0ebd 100644 --- a/txr.c +++ b/txr.c @@ -178,7 +178,7 @@ int txr_main(int argc, char **argv) val bindings = nil; val evaled = nil; int match_loglevel = opt_loglevel; - val arg; + val arg_undo = nil, arg; list_collect_decl(arg_list, arg_tail); prot1(&spec_file_str); @@ -199,15 +199,15 @@ int txr_main(int argc, char **argv) arg_list = cdr(arg_list); - for (arg = pop(&arg_list); arg && car(arg) == chr('-'); arg = pop(&arg_list)) + for (arg = upop(&arg_list, &arg_undo); + arg && car(arg) == chr('-'); + arg = upop(&arg_list, &arg_undo)) { if (equal(arg, lit("--"))) break; - if (equal(arg, lit("-"))) { - push(arg, &arg_list); + if (equal(arg, lit("-"))) break; - } if (equal(sub(arg, zero, two), lit("-D"))) { val dopt_arg = sub(arg, two, t); @@ -247,7 +247,7 @@ int txr_main(int argc, char **argv) return EXIT_FAILURE; } - arg = pop(&arg_list); + arg = upop(&arg_list, &arg_undo); switch (c_chr(opt)) { case 'a': @@ -383,7 +383,7 @@ int txr_main(int argc, char **argv) specstring = cat_str(list(specstring, string(L"\n"), nao), nil); yyin_stream = make_string_byte_input_stream(specstring); if (arg) - push(arg, &arg_list); + arg_list = arg_undo; } else if (spec_file) { if (wcscmp(c_str(spec_file), L"-") != 0) { FILE *in = w_fopen(c_str(spec_file), L"r"); @@ -395,7 +395,7 @@ int txr_main(int argc, char **argv) spec_file_str = lit("stdin"); } if (arg) - push(arg, &arg_list); + arg_list = arg_undo; } else { if (!arg) { if (evaled) -- cgit v1.2.3