summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-11-29 23:02:04 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-11-29 23:02:04 -0800
commitba858aeab76824d84eca2a0f183ca865eae8b4d6 (patch)
treedd13e6dfb59e291687cbc0249d62dd7f2934ce7c /share
parent14611800d14b9d0a95a1c2110e704ecf3718b2a4 (diff)
downloadtxr-ba858aeab76824d84eca2a0f183ca865eae8b4d6.tar.gz
txr-ba858aeab76824d84eca2a0f183ca865eae8b4d6.tar.bz2
txr-ba858aeab76824d84eca2a0f183ca865eae8b4d6.zip
bugfix: awk must consume *args*.
This problem happens when awk is issued from the command line followed by one or more arguments as exemplified by the usage txr -e '(awk ...) arg ... . In this case, after awk processes the args as input sources and completes, TXR resumes processing the command line arguments and wants to open arg as a script file! To address this problem, when awk defaults on using *args* as input sources, it consumes *args* by clearing the variable to nil. TXR's command line processing already reacts to changes in *args* by evaluated forms. Code that wants *args* to be left alone by awk can explicitly pass them in using (awk (:inputs *args*) ...). * share/txr/stdlib/awk.tl (sys:awk-state): Move default initialization of inputs into :postinit. If there are no inputs by :postinit time, then take *args* or *stdin*. If *args* is used in this default manner, then consume *args*. * txr.1: Documented.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/awk.tl3
1 files changed, 2 insertions, 1 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl
index 23db2403..a2fa0785 100644
--- a/share/txr/stdlib/awk.tl
+++ b/share/txr/stdlib/awk.tl
@@ -31,7 +31,7 @@
fs ft kfs
(ofs " ")
(ors "\n")
- (inputs (or *args* (list *stdin*)))
+ (inputs)
(output *stdout*)
(file-num 0)
(file-rec-num 0)
@@ -44,6 +44,7 @@
(dohash (k v self.streams)
(close-stream v)))
(:postinit (self)
+ (set self.inputs (or self.inputs (zap *args*) (list *stdin*)))
(if (plusp self.rng-n)
(set self.rng-vec (vector self.rng-n)))
(unless (streamp self.output)