diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2009-11-13 15:13:01 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2009-11-13 15:13:01 -0800 |
commit | 34020d9344dbce334486ea9c3f5babdc6fbcbe10 (patch) | |
tree | f63ccd35ab0f8b3303bd65f3eb22f9655aabdb49 | |
parent | 95e59dd555a038fd6eb70bc38e4e921d811b1f49 (diff) | |
download | txr-34020d9344dbce334486ea9c3f5babdc6fbcbe10.tar.gz txr-34020d9344dbce334486ea9c3f5babdc6fbcbe10.tar.bz2 txr-34020d9344dbce334486ea9c3f5babdc6fbcbe10.zip |
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.
-rw-r--r-- | ChangeLog | 22 | ||||
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | txr.1 | 12 | ||||
-rw-r--r-- | txr.c | 3 |
4 files changed, 37 insertions, 7 deletions
@@ -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 @@ -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 @@ -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 @@ -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) { |