summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-09-25 07:06:41 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-09-25 07:06:41 -0700
commit0ad39c713f1d0239abda6cece563c0964a1ea5e0 (patch)
tree75fb44f71fb1cd79f17be1743633175ddcfeed04 /share
parent0720e906157d8e51ada26b2bc81ce26a262c8964 (diff)
downloadtxr-0ad39c713f1d0239abda6cece563c0964a1ea5e0.tar.gz
txr-0ad39c713f1d0239abda6cece563c0964a1ea5e0.tar.bz2
txr-0ad39c713f1d0239abda6cece563c0964a1ea5e0.zip
awk macro: handle dynamic changes in rs variable.
* awk.tl (sys:awk-state loop): The loop now notices when rs or krs changes and switches to a new record-adapter or to the raw stream as necessary. * txr.1: Notes added about changes to rs and krs.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/awk.tl48
1 files changed, 28 insertions, 20 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl
index eb07cdcc..404c3aab 100644
--- a/share/txr/stdlib/awk.tl
+++ b/share/txr/stdlib/awk.tl
@@ -82,26 +82,34 @@
(inc aws.file-num)
(when beg-file-func
[beg-file-func aws])
- (unwind-protect
- (let* ((stin (if (streamp in) in (open-file in)))
- (recin (if (and (equal aws.rs "\n")
- (not aws.krs))
- stin
- (record-adapter (if (regexp aws.rs)
- aws.rs
- (regex-compile aws.rs))
- stin
- aws.krs))))
- (set aws.file-rec-num 0)
- (whilet ((rec (get-line recin)))
- (set aws.rec rec aws.orig-rec rec)
- (inc aws.rec-num)
- (inc aws.file-rec-num)
- aws.(rec-to-f)
- (block :awk-rec
- [func aws])))
- (when end-file-func
- [end-file-func aws])))))
+ (flet ((get-stream (stin)
+ (if (and (equal aws.rs "\n")
+ (not aws.krs))
+ stin
+ (record-adapter (if (regexp aws.rs)
+ aws.rs
+ (regex-compile aws.rs))
+ stin
+ aws.krs))))
+ (unwind-protect
+ (let* ((stin (if (streamp in) in (open-file in)))
+ (recin (get-stream stin))
+ (noted-rs aws.rs)
+ (noted-krs aws.krs))
+ (set aws.file-rec-num 0)
+ (whilet ((rec (get-line recin)))
+ (set aws.rec rec aws.orig-rec rec)
+ (inc aws.rec-num)
+ (inc aws.file-rec-num)
+ aws.(rec-to-f)
+ (block :awk-rec
+ [func aws])
+ (unless (and (equal noted-rs aws.rs)
+ (eq noted-krs aws.krs))
+ (set recin (get-stream stin))
+ (set noted-rs aws.rs noted-krs aws.krs))))
+ (when end-file-func
+ [end-file-func aws]))))))
(defmeth sys:awk-state prn (self . args)
(cond