From 73584c632d9a61c679cea57ba09f5d1843bf1435 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 7 Sep 2015 14:26:56 -0700 Subject: TXR 105 regression: real-time stream not used on tty. When the -n option was introduced, on Mar 29, 2015, the change didn't take into account that the hacky complex_open function takes the C stdin stream directly, and not the std_input Lisp stream. After that change, only the std_input is automaticaly marked for real-time input if standard input is a tty, and not any stream later opened from stdin. * match.c (enum fpip_close): New enum member, fpip_close_stream. (struct fpip): New member s, for smuggling through a stream. (complex_open): If name is "-", then plant std_input or std_output as the s member of fpip_t, rather than planting stdin or stdout as the f member. (complex_open_failed): Check for nil stream also. (complex_snarf, complex_stream): Handle stream case. --- match.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/match.c b/match.c index b4a2fd56..5eb8662c 100644 --- a/match.c +++ b/match.c @@ -1576,17 +1576,18 @@ static val txeval_allow_ub(val spec, val form, val bindings) return do_txeval(spec, form, bindings, t); } -enum fpip_close { fpip_fclose, fpip_pclose, fpip_closedir }; +enum fpip_close { fpip_fclose, fpip_pclose, fpip_closedir, fpip_close_stream }; typedef struct fpip { FILE *f; DIR *d; + val s; enum fpip_close close; } fpip_t; static fpip_t complex_open(val name, val output, val append) { - fpip_t ret = { 0, 0 }; + fpip_t ret = { 0, 0, nil, 0 }; const wchar_t *namestr = c_str(name); cnum len = c_num(length_str(name)); @@ -1594,8 +1595,8 @@ static fpip_t complex_open(val name, val output, val append) return ret; if (!wcscmp(namestr, L"-")) { - ret.close = fpip_fclose; - ret.f = output ? stdout : stdin; + ret.close = fpip_close_stream; + ret.s = output ? std_output : std_input; } else if (namestr[0] == '!') { ret.close = fpip_pclose; ret.f = w_popen(namestr+1, output ? L"w" : L"r"); @@ -1617,7 +1618,7 @@ static fpip_t complex_open(val name, val output, val append) static int complex_open_failed(fpip_t fp) { - return fp.f == 0 && fp.d == 0; + return fp.f == 0 && fp.d == 0 && fp.s == nil; } static val complex_snarf(fpip_t fp, val name) @@ -1629,6 +1630,8 @@ static val complex_snarf(fpip_t fp, val name) return lazy_stream_cons(make_pipe_stream(fp.f, name)); case fpip_closedir: return lazy_stream_cons(make_dir_stream(fp.d)); + case fpip_close_stream: + return lazy_stream_cons(fp.s); } internal_error("bad input source type"); @@ -1643,9 +1646,11 @@ static val complex_stream(fpip_t fp, val name) return make_pipe_stream(fp.f, name); case fpip_closedir: uw_throwf(query_error_s, lit("cannot output to directory: ~a"), name, nao); + case fpip_close_stream: + return fp.s; } - internal_error("bad input source type"); + internal_error("bad output destination type"); } static val robust_length(val obj) -- cgit v1.2.3