diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-09-08 22:42:02 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-09-08 22:42:02 -0700 |
commit | 4e918815564c2b4753c6e165daee050030d734c3 (patch) | |
tree | 5e04e045f283bce7b56490037b5869579dee0e03 | |
parent | f6946d73027e1f3213336a6fd721f4ab85036664 (diff) | |
download | txr-4e918815564c2b4753c6e165daee050030d734c3.tar.gz txr-4e918815564c2b4753c6e165daee050030d734c3.tar.bz2 txr-4e918815564c2b4753c6e165daee050030d734c3.zip |
awk macro: support ors (output record separator).
* share/txr/stdlib/awk.tl (sys:awk-state): New slot, ors.
(sys:awk-state prn): Use put-string to output the record
rather than put-line, and stick the ors at the end.
(sys:awk-let): Provide ors local symbol macro.
-rw-r--r-- | share/txr/stdlib/awk.tl | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl index f625fa53..0a08ee18 100644 --- a/share/txr/stdlib/awk.tl +++ b/share/txr/stdlib/awk.tl @@ -27,6 +27,7 @@ (rs "\n") (fs #/[ \t\n]+/) (ofs " ") + (ors "\n") (inputs (or *args* (list *stdin*))) (output *stdout*) (file-num 0) @@ -77,7 +78,7 @@ [func aws]))))))) (defmeth sys:awk-state prn (self . args) - (put-line `@{(if args args self.rec) self.ofs}`)) + (put-string `@{(if args args self.rec) self.ofs}@{self.ors}`)) (defun sys:awk-expander (clauses) (let (inputs output name lets begin-actions end-actions pattern-actions) @@ -129,7 +130,8 @@ (arg (qref ,aws-sym file-num)) (rs (qref ,aws-sym rs)) (fs (qref ,aws-sym fs)) - (ofs (qref ,aws-sym ofs))) + (ofs (qref ,aws-sym ofs)) + (ors (qref ,aws-sym ors))) (macrolet ((next () '(return-from :awk-rec)) (next-file () '(return-from :awk-file)) (prn (. args) ^(qref ,',aws-sym (prn ,*args))) |