aboutsummaryrefslogtreecommitdiffstats
path: root/doc/gawk.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/gawk.texi')
-rw-r--r--doc/gawk.texi29
1 files changed, 22 insertions, 7 deletions
diff --git a/doc/gawk.texi b/doc/gawk.texi
index b6685951..9a3c75fd 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -21081,7 +21081,7 @@ using indirect function calls:
@ignore
@c file eg/prog/indirectcall.awk
#
-# Arnold Robbins, arnold@skeeve.com, Public Domain
+# Arnold Robbins, arnold@@skeeve.com, Public Domain
# January 2009
@c endfile
@end ignore
@@ -26728,7 +26728,7 @@ line. That line is then printed to the output file:
@}
if ($3 != curfile) @{
if (curfile != "")
- close(curfile)
+ filelist[curfile]++ # save to close later
curfile = $3
@}
@@ -26772,6 +26772,26 @@ sample source file (as has been done here!) without any hassle. The file is
only closed when a new @value{DF} name is encountered or at the end of the
input file.
+When a new @value{FN} is encountered, instead of closing the file,
+the program saves the name of the current file in @code{filelist}.
+This makes it possible to interleave the code for more than one file in
+the Texinfo input file. (Previous versions of this program @emph{did}
+close the file. But because of the @samp{>} redirection, a file whose
+parts were not all one after the other ended up getting clobbered.)
+An @code{END} rule then closes all the open files when processing
+is finished:
+
+@example
+@c file eg/prog/extract.awk
+@group
+END @{
+ for (f in filelist)
+ close(filelist[f])
+@}
+@end group
+@c endfile
+@end example
+
Finally, the function @code{@w{unexpected_eof()}} prints an appropriate
error message and then exits.
The @code{END} rule handles the final cleanup, closing the open file:
@@ -26786,11 +26806,6 @@ function unexpected_eof()
exit 1
@}
@end group
-
-END @{
- if (curfile)
- close(curfile)
-@}
@c endfile
@end example