diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-06-19 19:07:31 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-06-19 19:07:31 -0700 |
commit | 3e00170c1ca93f6677c1cc9f68b120bdc3f9da1f (patch) | |
tree | b283b7480eca99a03165e107f7fb3cfd3df79364 /share | |
parent | 92d273995c487edcffde501bf05a2905aef2e99c (diff) | |
download | txr-3e00170c1ca93f6677c1cc9f68b120bdc3f9da1f.tar.gz txr-3e00170c1ca93f6677c1cc9f68b120bdc3f9da1f.tar.bz2 txr-3e00170c1ca93f6677c1cc9f68b120bdc3f9da1f.zip |
awk macro: bugfix: :output file stream not closed.
In the case when the :output clause of the awk macro opens a
stream, it isn't closing it. Why don't we treat such a stream
uniformly with redirections.
* share/txr/stdlib/awk.tl (sys:awk-state :postinit):
If a file is opened for output, then don't just install
this file as self.output. Also place it into the self.streams
hash, identified by using the key (:outf <name>), just
like a (-> "name") redirection. This ensures that it will
be closed when the awk macro terminates. It's also potentially
useful in that output redirections referring to the name will
use the same stream.
* txr.1: Documented that streams opened by :output are
closed, and that they are treated uniformly with redirections.
Diffstat (limited to 'share')
-rw-r--r-- | share/txr/stdlib/awk.tl | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl index 7c4033e6..aab6a4eb 100644 --- a/share/txr/stdlib/awk.tl +++ b/share/txr/stdlib/awk.tl @@ -50,7 +50,9 @@ (if (plusp self.rng-n) (set self.rng-vec (vector self.rng-n))) (unless (streamp self.output) - (set self.output (open-file self.output "w"))))) + (let ((stream (open-file self.output "w"))) + (set [self.streams ^(:outf ,self.output)] stream + self.output stream))))) (defstruct sys:awk-compile-time () inputs output name lets |