diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-06-19 21:20:03 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-06-19 21:20:03 -0700 |
commit | 9dbcde8882a8a917b6d0329e06ea2232e62b1c8c (patch) | |
tree | 77c9955719208c90501086a9eaf954c882de4063 /share | |
parent | 3e00170c1ca93f6677c1cc9f68b120bdc3f9da1f (diff) | |
download | txr-9dbcde8882a8a917b6d0329e06ea2232e62b1c8c.tar.gz txr-9dbcde8882a8a917b6d0329e06ea2232e62b1c8c.tar.bz2 txr-9dbcde8882a8a917b6d0329e06ea2232e62b1c8c.zip |
awk macro: bugfix: non-use of redirection mode strings.
The problem here is that ensure-stream ignores the mode
argument and decides between "r" and "w". That is incorrect;
the mode could be "a" for append.
The second problem is that the ignored mode strings are
also wrong. For an input pipe, "w" is specified rather than
"r".
* share/txr/stdlib/awk.tl (sys:awk-state ensure-stream): Use
the mode argument. The cases consolidate, because all that
need be distinguished here is file versus pipe.
(sys:awk-mac-let): for the <! redirection (input from pipe),
the mode must be "r", not "w".
Diffstat (limited to 'share')
-rw-r--r-- | share/txr/stdlib/awk.tl | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl index aab6a4eb..6b2f6ee2 100644 --- a/share/txr/stdlib/awk.tl +++ b/share/txr/stdlib/awk.tl @@ -191,10 +191,8 @@ (hash-update-1 self.streams ^(,kind ,path) (do or @1 (caseq kind - (:inf (open-file path "r")) - (:outf (open-file path "w")) - (:inp (open-command path "r")) - (:outp (open-command path "w")))) + ((:inf :outf) (open-file path mode)) + ((:inp :outp) (open-command path mode)))) nil)) (defmeth sys:awk-state close-or-flush (self stream kind path val) @@ -383,7 +381,7 @@ (!> (path . body) ^(sys:awk-redir ,',aws-sym *stdout* :outp "w" ,path ,body)) (<! (path . body) - ^(sys:awk-redir ,',aws-sym *stdin* :inp "w" ,path ,body))) + ^(sys:awk-redir ,',aws-sym *stdin* :inp "r" ,path ,body))) ,*body))) (defmacro sys:awk-fun-let (aws-sym . body) |