From 34020d9344dbce334486ea9c3f5babdc6fbcbe10 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 13 Nov 2009 15:13:01 -0800 Subject: 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. --- ChangeLog | 22 ++++++++++++++++++++++ Makefile | 7 ++++++- txr.1 | 12 ++++++------ txr.c | 3 +++ 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d31eba4..bb277664 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2009-11-13 Kaz Kylheku + + 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 Previous commit broke UTF-8 lexing, by changing the get_char 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 - " - <