summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-06-09 07:13:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-06-09 07:13:59 -0700
commit26e61191b5b5eb346be5f6c245b98d8e1c0fe718 (patch)
treee8f7f1b3cec4cbe9c6df2f03f507232866cb5deb
parentc27a97c95c628ff1e49339f82537bbf3719ab75a (diff)
downloadtxr-26e61191b5b5eb346be5f6c245b98d8e1c0fe718.tar.gz
txr-26e61191b5b5eb346be5f6c245b98d8e1c0fe718.tar.bz2
txr-26e61191b5b5eb346be5f6c245b98d8e1c0fe718.zip
The dumping of bindings and printing of false must now
be explicitly requested by the -B option. * match.c (opt_nobindings): Variable removed. (opt_print_bindings): New variable. (extract): Print bindings or "false" if opt_print_bindings is true. * stream.c (output_produced): Variable removed. (stdio_put_string, stdio_put_char, stdio_put_byte): Remove update of output_produced. * stream.h (output_produced): Declaration removed. * txr.1: Documentation updated. * txr.c (txr_main): Option 'b' does nothing. 'B', 'l', 'a', and '--lisp-bindings' set opt_print_bindings to 1. * txr.h (opt_nobindings): Declaration removed. (opt_print_bindings): Declared. * unwind.c (uw_throw): When exiting due to a query error or file error, print false when opt_print_bindings is true.
-rw-r--r--ChangeLog26
-rw-r--r--match.c4
-rw-r--r--stream.c11
-rw-r--r--stream.h2
-rw-r--r--txr.171
-rw-r--r--txr.c8
-rw-r--r--txr.h2
-rw-r--r--unwind.c2
8 files changed, 48 insertions, 78 deletions
diff --git a/ChangeLog b/ChangeLog
index 1087931d..828d16e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2014-06-09 Kaz Kylheku <kaz@kylheku.com>
+
+ The dumping of bindings and printing of false must now
+ be explicitly requested by the -B option.
+
+ * match.c (opt_nobindings): Variable removed.
+ (opt_print_bindings): New variable.
+ (extract): Print bindings or "false" if opt_print_bindings is true.
+
+ * stream.c (output_produced): Variable removed.
+ (stdio_put_string, stdio_put_char, stdio_put_byte): Remove
+ update of output_produced.
+
+ * stream.h (output_produced): Declaration removed.
+
+ * txr.1: Documentation updated.
+
+ * txr.c (txr_main): Option 'b' does nothing. 'B', 'l', 'a',
+ and '--lisp-bindings' set opt_print_bindings to 1.
+
+ * txr.h (opt_nobindings): Declaration removed.
+ (opt_print_bindings): Declared.
+
+ * unwind.c (uw_throw): When exiting due to a query error or
+ file error, print false when opt_print_bindings is true.
+
2014-06-06 Kaz Kylheku <kaz@kylheku.com>
Fixing issue with list-like iteration over generic sequences,
diff --git a/match.c b/match.c
index acd82b1d..c2f72cf6 100644
--- a/match.c
+++ b/match.c
@@ -49,7 +49,7 @@
#include "eval.h"
#include "match.h"
-int opt_nobindings = 0;
+int opt_print_bindings = 0;
int opt_lisp_bindings = 0;
int opt_arraydims = 1;
@@ -3939,7 +3939,7 @@ int extract(val spec, val files, val predefined_bindings)
predefined_bindings,
t, nil, nil)));
- if ((!output_produced && opt_nobindings <= 0) || opt_nobindings < 0) {
+ if (opt_print_bindings) {
if (bindings) {
bindings = nreverse(bindings);
dump_bindings(bindings);
diff --git a/stream.c b/stream.c
index 75b51c97..b12d06e0 100644
--- a/stream.c
+++ b/stream.c
@@ -62,8 +62,6 @@
#include "utf8.h"
#include "eval.h"
-val output_produced;
-
val stdin_s, stdout_s, stddebug_s, stderr_s, stdnull_s;
val dev_k, ino_k, mode_k, nlink_k, uid_k;
@@ -219,9 +217,6 @@ static val stdio_put_string(val stream, val str)
{
struct stdio_handle *h = (struct stdio_handle *) stream->co.handle;
- if (stream != std_debug && stream != std_error)
- output_produced = t;
-
if (h->f != 0) {
const wchar_t *s = c_str(str);
@@ -238,9 +233,6 @@ static val stdio_put_char(val stream, val ch)
{
struct stdio_handle *h = (struct stdio_handle *) stream->co.handle;
- if (stream != std_debug && stream != std_error)
- output_produced = t;
-
return h->f != 0 && utf8_encode(c_chr(ch), stdio_put_char_callback, (mem_t *) h->f)
? t : stdio_maybe_error(stream, lit("writing"));
}
@@ -249,9 +241,6 @@ static val stdio_put_byte(val stream, int b)
{
struct stdio_handle *h = (struct stdio_handle *) stream->co.handle;
- if (stream != std_debug && stream != std_error)
- output_produced = t;
-
return h->f != 0 && se_putc(b, (FILE *) h->f) != EOF
? t : stdio_maybe_error(stream, lit("writing"));
}
diff --git a/stream.h b/stream.h
index 7a5911e6..30b06a85 100644
--- a/stream.h
+++ b/stream.h
@@ -54,8 +54,6 @@ struct strm_ops {
#define std_null (deref(lookup_var_l(nil, stdnull_s)))
loc lookup_var_l(val env, val sym);
-extern val output_produced;
-
extern val dev_k, ino_k, mode_k, nlink_k, uid_k;
extern val gid_k, rdev_k, size_k, blksize_k, blocks_k;
extern val atime_k, mtime_k, ctime_k;
diff --git a/txr.1 b/txr.1
index 66698a38..887f6d1e 100644
--- a/txr.1
+++ b/txr.1
@@ -106,26 +106,25 @@ Invoke the interactive txr debugger. See the DEBUGGER section.
Verbose operation. Detailed logging is enabled.
.IP -b
-Suppresses the printing of variable bindings for a successful query, and the
-word .
-IR false
-for a failed query. The program still sets an appropriate
-termination status. Bindings are implicitly suppressed if the TXR query
-performs an output operation on any file stream other than *stddebug*.
-(Internal streams like string streams do not count as output.)
+This is a deprecated option, which is silently ignored. In TXR versions
+prior to 90, the printing of variable bindings (see -B option) was
+implicit behavior which was automatically suppressed in certain situations.
+The -b option suppressed it unconditionally.
.IP -B
-Force the printing of variable bindings for a successful query, and the
-word .
-IR false
-for a failed query, even if the program produced output.
+If the query is successful, print the variable bindings as a sequence
+of assignmnents in shell syntax can be evaled by a POSIX shell.
+If the query failes, print the word "false". Evaluation of this word
+by the shell has the effect of producing an unsuccessful termination
+status from the eval command.
.IP "-l or --lisp-bindings"
-Print the variable bindings in Lisp syntax instead of shell syntax.
+This option implies -B. Print the variable bindings in Lisp syntax instead of
+shell syntax.
.IP "-a num"
-The decimal integer argument specifies the maximum number of array dimensions
-to use for variables arising out of collect. The default is 1. Additional
+This option implies -B. The decimal integer argument specifies the maximum number of array dimensions
+to use for list-valued variable bindings. The default is 1. Additional
dimensions are expressed using numeric suffixes in the generated variable
names.
For instance, consider the three-dimensional list arising out of a triply
@@ -246,15 +245,6 @@ syntax, or fails to match,
.B TXR
issues an error diagnostic and terminates with a failed status.
-If the query is accepted, but fails to execute, either due to a
-semantic error or due to a mismatch against the data,
-.B TXR
-terminates with a failed status, it also prints the word
-.IR false
-on standard output. (See NOTES ON FALSE below). Printing of false
-is suppressed if the query executed one or more @(output) directive
-directed to standard output.
-
If the query is well-formed, and matches, then
.B TXR
issues no diagnostics on standard error (except in the case of verbose
@@ -14905,38 +14895,3 @@ trailing context is deeply involved in its logic. For single-character
trailing contexts, it may be a good idea to use a complemented character class
instead. That is to say, rather than (.%a)bc, consider [^a]*bc. The set of
strings which don't contain the character a is adequately expressed by [^a]*.
-
-.SH APPENDIX B: NOTES ON FALSE
-
-The reason for printing the word
-.IR false
-on standard output when
-a query doesn't match, in addition to returning a failed termination
-status, is that the output of
-.B TXR
-may be collected by a shell script, by the application of eval to command
-substitution syntax. Printing
-.IR false
-will cause eval to evaluate the
-.IR false
-command, and thus failed status will propagate from the eval
-itself. The eval command conceals the termination status of a
-program run via command substitution. That is to say, if a program
-fails, without producing output, its output is substituted into the eval
-command which then succeeds, masking the failure of the program. For example:
-
- eval "$(false)"
-
-appears successful: the false utility indicates a failed status, but
-produces no output. Eval evaluates an empty script and reports success;
-the failed status of the false program is forgotten.
-Note the difference between the above and this:
-
- eval "$(echo false)"
-
-This command has a failed status. The echo prints the word false and succeeds;
-this false word is then evaluated as a script, and thus interpreted as the
-false command which fails. This failure
-.B is
-propagated as the result of the eval
-command.
diff --git a/txr.c b/txr.c
index 570a0aa6..9b84aabb 100644
--- a/txr.c
+++ b/txr.c
@@ -262,6 +262,7 @@ int txr_main(int argc, char **argv)
}
opt_arraydims = c_num(optval);
+ opt_print_bindings = 1;
}
break;
case 'c':
@@ -303,6 +304,7 @@ int txr_main(int argc, char **argv)
continue;
} else if (equal(arg, lit("--lisp-bindings"))) {
opt_lisp_bindings = 1;
+ opt_print_bindings = 1;
continue;
} else if (equal(arg, lit("--debugger"))) {
#if CONFIG_DEBUG_SUPPORT
@@ -330,14 +332,14 @@ int txr_main(int argc, char **argv)
case 'q':
match_loglevel = 0;
break;
- case 'b':
- opt_nobindings = 1;
+ case 'b': /* deprecated */
break;
case 'B':
- opt_nobindings = -1;
+ opt_print_bindings = 1;
break;
case 'l':
opt_lisp_bindings = 1;
+ opt_print_bindings = 1;
break;
case 'd':
#if CONFIG_DEBUG_SUPPORT
diff --git a/txr.h b/txr.h
index 7ff260d5..de458560 100644
--- a/txr.h
+++ b/txr.h
@@ -25,7 +25,7 @@
*/
extern int opt_loglevel;
-extern int opt_nobindings;
+extern int opt_print_bindings;
extern int opt_lisp_bindings;
extern int opt_arraydims;
extern int opt_gc_debug;
diff --git a/unwind.c b/unwind.c
index 3b4f674e..c76c4b0b 100644
--- a/unwind.c
+++ b/unwind.c
@@ -292,7 +292,7 @@ val uw_throw(val sym, val exception)
}
if (uw_exception_subtype_p(sym, query_error_s) ||
uw_exception_subtype_p(sym, file_error_s)) {
- if (!output_produced)
+ if (opt_print_bindings)
put_line(lit("false"), std_output);
exit(EXIT_FAILURE);
}