summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--share/txr/stdlib/awk.tl3
-rw-r--r--txr.132
2 files changed, 34 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)
diff --git a/txr.1 b/txr.1
index 507d3f0a..94bc81c7 100644
--- a/txr.1
+++ b/txr.1
@@ -41383,6 +41383,38 @@ is taken as the input sources. Otherwise, the
.code *stdin*
stream is taken as the one and only input source.
+If the
+.code awk
+macro uses
+.code *args*
+via the above defaulting behavior, it copies
+.code *args*
+and sets that variable to
+.codn nil .
+This is done in order that if
+.code awk
+is used from the \*(TX command line, for example using the
+.code -e
+command line option, after
+.code awk
+terminates, \*(TX will not try to open the next argument
+as a script file or treat it as an option.
+Note: programs which want
+.code awk
+not to modify
+.code *args*
+can explicitly specify
+.code *args*
+as the argument to the
+.code :inputs
+keyword, rather than allow
+.code *args*
+to be used through the defaulting behavior. Only the
+defaulting behavior consumes the arguments by overwriting
+.code *args*
+with
+.codn nil .
+
It is an error to specify more than one
.code :inputs
clause.