diff options
-rw-r--r-- | share/txr/stdlib/awk.tl | 5 | ||||
-rw-r--r-- | txr.1 | 24 |
2 files changed, 29 insertions, 0 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl index 9732ea24..05567956 100644 --- a/share/txr/stdlib/awk.tl +++ b/share/txr/stdlib/awk.tl @@ -35,6 +35,7 @@ (inputs) (output *stdout*) (file-num 0) + file-name (file-rec-num 0) (rec-num 0) rec orig-rec fields nf @@ -119,6 +120,9 @@ (whilet ((in (pop aws.inputs))) (block :awk-file (inc aws.file-num) + (set aws.file-name (if (streamp in) + (stream-get-prop in :name) + in)) (when beg-file-func [beg-file-func aws]) (let* ((*stdin* (if (streamp in) in (open-file in))) @@ -268,6 +272,7 @@ (nr (qref ,aws-sym rec-num)) (fnr (qref ,aws-sym file-rec-num)) (arg (qref ,aws-sym file-num)) + (fname (qref ,aws-sym file-name)) (rs (qref ,aws-sym rs)) (krs (qref ,aws-sym krs)) (fs (qref ,aws-sym fs)) @@ -43122,6 +43122,30 @@ Thereafter, it is incremented whenever .code awk switches to a new input source. +.coNP Variable @ fname +.desc +The awk variable +.code fname +provides access to a character string which, if the current input is +a file stream, is the name of the underlying file. Assigning to this +variable changes its value, but has no effect on the input stream. +Whenever a new input source is used by +.code awk +it sets this variable either from the file name on which it is opening +a stream.. When using an existing stream rather than opening a file, +.code awk +sets this variable from the +.code :name +property of the stream. + +Note that the redirection macros +.code <- +and +.code <! +have no effect on this variable. Within their scope, +.code fname +retains its value. + .coNP Variable @ rs .desc The awk variable |