From ce6020f1f8248050bb17699cc229205e8cdbdf4e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 17 Feb 2012 23:35:57 -0800 Subject: Reimplementation of how TXR decides whether to dump bindings or not. This is now done right inside the standard output stream. * match.c (output_produced): Variable removed. (complex_open): Assignment to output_produced removed. * stream.c (output_produced): New global variable. (stdio_put_string, stdio_put_char): Set output_produced to t if the target of the output is stdout. * stream.h (output_produced): Declared. * txr.h (output_produced): Declaration removed. --- ChangeLog | 16 ++++++++++++++++ match.c | 2 -- stream.c | 6 ++++++ stream.h | 1 + txr.h | 1 - 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index eda56c02..7a63e83d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2012-02-17 Kaz Kylheku + + Reimplementation of how TXR decides whether to dump bindings + or not. This is now done right inside the standard output stream. + + * match.c (output_produced): Variable removed. + (complex_open): Assignment to output_produced removed. + + * stream.c (output_produced): New global variable. + (stdio_put_string, stdio_put_char): Set output_produced + to t if the target of the output is stdout. + + * stream.h (output_produced): Declared. + + * txr.h (output_produced): Declaration removed. + 2012-02-17 Kaz Kylheku * eval.c (dwim_loc): 2012-02-13 fix didn't do it. diff --git a/match.c b/match.c index b5e489dd..d921757e 100644 --- a/match.c +++ b/match.c @@ -47,7 +47,6 @@ #include "eval.h" #include "match.h" -int output_produced; int opt_nobindings = 0; int opt_lisp_bindings = 0; int opt_arraydims = 1; @@ -1459,7 +1458,6 @@ static fpip_t complex_open(val name, val output, val append) if (!wcscmp(namestr, L"-")) { ret.close = fpip_fclose; ret.f = output ? stdout : stdin; - output_produced = output ? 1 : 0; } else if (namestr[0] == '!') { ret.close = fpip_pclose; ret.f = w_popen(namestr+1, output ? L"w" : L"r"); diff --git a/stream.c b/stream.c index 023e8390..64380b87 100644 --- a/stream.c +++ b/stream.c @@ -45,6 +45,7 @@ #include "utf8.h" val std_input, std_output, std_error; +val output_produced; struct strm_ops { struct cobj_ops cobj_ops; @@ -124,6 +125,9 @@ static val stdio_put_string(val stream, val str) { struct stdio_handle *h = (struct stdio_handle *) stream->co.handle; + if (h->f == stdout) + output_produced = t; + if (h->f != 0) { const wchar_t *s = c_str(str); while (*s) { @@ -138,6 +142,8 @@ static val stdio_put_string(val stream, val str) static val stdio_put_char(val stream, val ch) { struct stdio_handle *h = (struct stdio_handle *) stream->co.handle; + if (h->f == stdout) + output_produced = t; return h->f != 0 && utf8_encode(c_chr(ch), stdio_put_char_callback, (mem_t *) h->f) ? t : stdio_maybe_write_error(stream); } diff --git a/stream.h b/stream.h index 14208f7a..4cb7f923 100644 --- a/stream.h +++ b/stream.h @@ -25,6 +25,7 @@ */ extern val std_input, std_output, std_error; +extern val output_produced; val make_stdio_stream(FILE *, val descr, val input, val output); val make_pipe_stream(FILE *, val descr, val input, val output); diff --git a/txr.h b/txr.h index 23afc823..293840a1 100644 --- a/txr.h +++ b/txr.h @@ -35,4 +35,3 @@ extern int opt_vg_debug; extern int opt_derivative_regex; extern const wchli_t *version; extern const wchar_t *progname; -extern int output_produced; -- cgit v1.2.3