summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog22
-rw-r--r--Makefile7
-rw-r--r--txr.112
-rw-r--r--txr.c3
4 files changed, 37 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 2d31eba4..bb277664 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,27 @@
2009-11-13 Kaz Kylheku <kkylheku@gmail.com>
+ Allow -c scripts to not have a trailing newline.
+ Test suite exercises -c now.
+
+ txr.c (txr_main): If the script specified with -c is not terminated
+ by a newline, just add a newline. On the shell command line, it's a
+ nuisance to have to add the extra line before closing the quote.
+ It's also awkward in scripting, because the shell (or at
+ least Bash 3.0) does not produce a final terminating newline in command
+ substitution syntax like -c "$(cat file)". The last newline in
+ the file is trimmed, and has to be explicitly added in the script
+ itself, which is wrong in the case when the file is empty.
+
+ Makefile (TXR_SCRIPT_ON_CMDLINE): New target-specific variable,
+ arbitarily set for test 002.
+ (%.ok: %.txr): Rule updated to honor TXR_SCRIPT_ON_CMDLINE
+ variable, passing the script body to txr using -c rather than
+ as a file argument.
+
+ txr.1: Document -c change.
+
+2009-11-13 Kaz Kylheku <kkylheku@gmail.com>
+
Previous commit broke UTF-8 lexing, by changing the get_char
semantics on the input stream to wide character input.
Also, reading a query the command line (-c) must
diff --git a/Makefile b/Makefile
index a3389518..878ca04f 100644
--- a/Makefile
+++ b/Makefile
@@ -68,9 +68,14 @@ tests/001/%: TXR_ARGS := $(top_srcdir)/tests/001/data
tests/002/%: TXR_OPTS := -DTESTDIR=$(top_srcdir)/tests/002
tests/004/%: TXR_ARGS := -a 123 -b -c
+tests/002/%: TXR_SCRIPT_ON_CMDLINE := y
+
%.ok: %.txr
mkdir -p $(dir $@)
- $(PROG) $(TXR_DBG_OPTS) $(TXR_OPTS) $^ $(TXR_ARGS) > $(@:.ok=.out)
+ $(if $(TXR_SCRIPT_ON_CMDLINE),\
+ $(PROG) $(TXR_DBG_OPTS) $(TXR_OPTS) -c "$$(cat $^)" \
+ $(TXR_ARGS) > $(@:.ok=.out),\
+ $(PROG) $(TXR_DBG_OPTS) $(TXR_OPTS) $^ $(TXR_ARGS) > $(@:.ok=.out))
diff $(^:.txr=.expected) $(@:.ok=.out)
%.expected: %.txr
diff --git a/txr.1 b/txr.1
index e62b30e1..5b2b4fbc 100644
--- a/txr.1
+++ b/txr.1
@@ -141,8 +141,10 @@ the dimension order is: NAME_m_m+1_..._n[1][2]...[m-1].
Specifies the query in the form of a command line argument. If this option is
used, the query-file argument is omitted. The first non-option argument,
if there is one, now specifies the first input source rather than a query.
-Queries specified as arguments must properly end in a newline, as if they
-were read from a text file, thus -c "@a" is not a properly formed query.
+Unlike queries read from a file, (non-empty) queries specified as arguments
+using -c do not have to properly end in a newline. Internally, txr
+adds the missing newline before parsing the query. Thus -c "@a"
+is a valid query which matches a line.
Example:
@@ -152,8 +154,7 @@ Example:
# comes from shell "here document" redirection.
txr -c "@a
- @b
- " - <<!
+ @b" - <<!
1
2
!
@@ -166,8 +167,7 @@ The @# comment syntax can be used for better formatting:
txr -c "@#
@a
- @b
- "
+ @b"
.IP -f query-file
Specifies the file from which the query is to be read, instead of the
diff --git a/txr.c b/txr.c
index 58bfffb3..dcf316ad 100644
--- a/txr.c
+++ b/txr.c
@@ -307,6 +307,9 @@ static int txr_main(int argc, char **argv)
if (specstring) {
spec_file = L"cmdline";
spec_file_str = string(spec_file);
+ if (gt(length_str(specstring), zero) &&
+ chr_str(specstring, minus(length_str(specstring), one)) != chr('\n'))
+ specstring = cat_str(list(specstring, string(L"\n"), nao), nil);
yyin_stream = make_string_byte_input_stream(specstring);
} else if (spec_file_str) {
if (wcscmp(c_str(spec_file_str), L"-") != 0) {