summaryrefslogtreecommitdiffstats
path: root/txr.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2009-11-13 15:13:01 -0800
committerKaz Kylheku <kaz@kylheku.com>2009-11-13 15:13:01 -0800
commit34020d9344dbce334486ea9c3f5babdc6fbcbe10 (patch)
treef63ccd35ab0f8b3303bd65f3eb22f9655aabdb49 /txr.c
parent95e59dd555a038fd6eb70bc38e4e921d811b1f49 (diff)
downloadtxr-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.c3
1 files changed, 3 insertions, 0 deletions
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) {