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 /txr.c | |
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.
Diffstat (limited to 'txr.c')
-rw-r--r-- | txr.c | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -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) { |