summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog17
-rw-r--r--debug.c30
-rw-r--r--eval.c1
-rw-r--r--stream.c14
-rw-r--r--stream.h2
-rw-r--r--txr.12
6 files changed, 44 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index b4bbe9b8..8eea6f22 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
2012-02-26 Kaz Kylheku <kaz@kylheku.com>
+ Fix the issue properly, once and for all, of how to determine
+ that output has taken place and suppress the printing of bindings.
+
+ * debug.c (debug): std_output replaced with std_debug.
+
+ * eval.c (eval_init): Registered new *stddebug* variable.
+
+ * stream.c (std_debug): New variable.
+ (stdio_put_string): Check that stream is other than
+ std_debug, to determine that output has taken place.
+
+ * stream.h (std_debug): Declared.
+
+ * txr.1: Added *stddebug* to documentation stub heading.
+
+2012-02-26 Kaz Kylheku <kaz@kylheku.com>
+
Fixing long-time (pre-GIT) bug. The object (nil) was stupidly used to
represent empty optional output clauses, distinguishing them from
missing clauses. This creates an ambiguity, so that an @(output)
diff --git a/debug.c b/debug.c
index 0eed79d1..16076a94 100644
--- a/debug.c
+++ b/debug.c
@@ -102,9 +102,9 @@ val debug(val form, val bindings, val data, val line, val pos, val base)
val input, command;
if (print_form) {
- format(std_output, lit("stopped at ~a\n"), source_loc_str(form), nao);
- format(std_output, lit("form: ~s\n"), form, nao);
- format(std_output, lit("depth: ~s\n"), num(debug_depth), nao);
+ format(std_debug, lit("stopped at ~a\n"), source_loc_str(form), nao);
+ format(std_debug, lit("form: ~s\n"), form, nao);
+ format(std_debug, lit("depth: ~s\n"), num(debug_depth), nao);
print_form = nil;
}
@@ -122,16 +122,16 @@ val debug(val form, val bindings, val data, val line, val pos, val base)
suffix = sub_str(data, pos, plus(pos, half));
}
- format(std_output, lit("data (~s:~s):\n~s . ~s\n"),
+ format(std_debug, lit("data (~s:~s):\n~s . ~s\n"),
line, plus(pos, base), prefix, suffix, nao);
} else {
- format(std_output, lit("data (~s):\n~s\n"), line, data, nao);
+ format(std_debug, lit("data (~s):\n~s\n"), line, data, nao);
}
print_data = nil;
}
- format(std_output, lit("txr> "), nao);
- flush_stream(std_output);
+ format(std_debug, lit("txr> "), nao);
+ flush_stream(std_debug);
input = split_str_set(or2(get_line(std_input), lit("q")), lit("\t "));
command = if3(equal(first(input), null_string),
@@ -139,7 +139,7 @@ val debug(val form, val bindings, val data, val line, val pos, val base)
last_command = command;
if (equal(command, lit("?")) || equal(command, lit("h"))) {
- help(std_output);
+ help(std_debug);
continue;
} else if (equal(command, null_string)) {
continue;
@@ -159,14 +159,14 @@ val debug(val form, val bindings, val data, val line, val pos, val base)
next_depth = debug_depth - 1;
return nil;
} else if (equal(command, lit("v"))) {
- show_bindings(bindings, std_output);
+ show_bindings(bindings, std_debug);
} else if (equal(command, lit("s"))) {
print_form = t;
} else if (equal(command, lit("i"))) {
print_data = t;
} else if (equal(command, lit("b")) || equal(command, lit("d"))) {
if (!rest(input)) {
- format(std_output, lit("b needs argument\n"), nao);
+ format(std_debug, lit("b needs argument\n"), nao);
continue;
} else {
long n = wcstol(c_str(second(input)), NULL, 10);
@@ -174,19 +174,19 @@ val debug(val form, val bindings, val data, val line, val pos, val base)
push(num(n), &breakpoints);
}
} else if (equal(command, lit("l"))) {
- format(std_output, lit("breakpoints: ~s\n"), breakpoints, nao);
+ format(std_debug, lit("breakpoints: ~s\n"), breakpoints, nao);
} else if (equal(command, lit("w"))) {
- format(std_output, lit("backtrace:\n"), nao);
+ format(std_debug, lit("backtrace:\n"), nao);
{
uw_frame_t *iter;
for (iter = uw_current_frame(); iter != 0; iter = iter->uw.up) {
if (iter->uw.type == UW_DBG) {
if (iter->db.ub_p_a_pairs)
- format(std_output, lit("(~s ~s ~s)\n"), iter->db.func,
+ format(std_debug, lit("(~s ~s ~s)\n"), iter->db.func,
iter->db.args, iter->db.ub_p_a_pairs, nao);
else
- format(std_output, lit("(~s ~s)\n"), iter->db.func,
+ format(std_debug, lit("(~s ~s)\n"), iter->db.func,
iter->db.args, nao);
}
}
@@ -194,7 +194,7 @@ val debug(val form, val bindings, val data, val line, val pos, val base)
} else if (equal(command, lit("q"))) {
uw_throwf(query_error_s, lit("terminated via debugger"), nao);
} else {
- format(std_output, lit("unrecognized command: ~a\n"), command, nao);
+ format(std_debug, lit("unrecognized command: ~a\n"), command, nao);
}
}
diff --git a/eval.c b/eval.c
index c0a38ed5..532b63f0 100644
--- a/eval.c
+++ b/eval.c
@@ -2181,6 +2181,7 @@ void eval_init(void)
reg_fun(intern(lit("eval"), user_package), func_n2o(eval_intrinsic, 1));
reg_var(intern(lit("*stdout*"), user_package), &std_output);
+ reg_var(intern(lit("*stddebug*"), user_package), &std_debug);
reg_var(intern(lit("*stdin*"), user_package), &std_input);
reg_var(intern(lit("*stderr*"), user_package), &std_error);
reg_fun(intern(lit("format"), user_package), func_n2v(formatv));
diff --git a/stream.c b/stream.c
index 80f12c29..62cd85ae 100644
--- a/stream.c
+++ b/stream.c
@@ -44,7 +44,7 @@
#include "stream.h"
#include "utf8.h"
-val std_input, std_output, std_error;
+val std_input, std_output, std_debug, std_error;
val output_produced;
struct strm_ops {
@@ -126,11 +126,12 @@ static val stdio_put_string(val stream, val str)
{
struct stdio_handle *h = (struct stdio_handle *) stream->co.handle;
- if (h->f == stdout)
+ if (stream != std_debug)
output_produced = t;
if (h->f != 0) {
const wchar_t *s = c_str(str);
+
while (*s) {
if (!utf8_encode(*s++, stdio_put_char_callback, (mem_t *) h->f))
return stdio_maybe_write_error(stream);
@@ -143,8 +144,10 @@ 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)
+
+ if (stream != std_debug)
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);
}
@@ -154,7 +157,7 @@ static val stdio_put_byte(val stream, val byte)
cnum b = c_num(byte);
struct stdio_handle *h = (struct stdio_handle *) stream->co.handle;
- if (h->f == stdout)
+ if (stream != std_debug)
output_produced = t;
if (b < 0 || b > 255)
@@ -1306,9 +1309,10 @@ val open_pipe(val path, val mode_str)
void stream_init(void)
{
- protect(&std_input, &std_output, &std_error, (val *) 0);
+ protect(&std_input, &std_output, &std_debug, &std_error, (val *) 0);
std_input = make_stdio_stream(stdin, string(L"stdin"), t, nil);
std_output = make_stdio_stream(stdout, string(L"stdout"), nil, t);
+ std_debug = make_stdio_stream(stdout, string(L"debug"), nil, t);
std_error = make_stdio_stream(stderr, string(L"stderr"), nil, t);
detect_format_string();
}
diff --git a/stream.h b/stream.h
index ba6ef58e..cae9bf98 100644
--- a/stream.h
+++ b/stream.h
@@ -24,7 +24,7 @@
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-extern val std_input, std_output, std_error;
+extern val std_input, std_output, std_debug, std_error;
extern val output_produced;
val make_stdio_stream(FILE *, val descr, val input, val output);
diff --git a/txr.1 b/txr.1
index 34f34bcd..2307d2f1 100644
--- a/txr.1
+++ b/txr.1
@@ -6511,7 +6511,7 @@ Certain object types have a custom equal function.
.SS Function eval
-.SS Variables *stdout*, *stdin* and *stderr*
+.SS Variables *stdout*, *stddebug*, *stdin* and *stderr*
.SS Function format