summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2010-07-16 12:18:27 +0300
committerArnold D. Robbins <arnold@skeeve.com>2010-07-16 12:18:27 +0300
commite1ef22d366abd1f9ec95eb495c727d55181c8584 (patch)
treecc0fee624202820eb928e60b6a096362c85ff807
parentcae8bc6ced84c12590e3554a06a952283735363a (diff)
downloadgawk-e1ef22d366abd1f9ec95eb495c727d55181c8584.tar.gz
Move to 2.15.gawk-2.15
-rw-r--r--FUTURES127
-rw-r--r--Makefile.bsd44 (renamed from Makefile.bsd44alpha)0
-rw-r--r--Makefile.in56
-rw-r--r--NEWS84
-rw-r--r--PORTS13
-rw-r--r--PROBLEMS2
-rw-r--r--README6
-rw-r--r--README.amiga89
-rw-r--r--README.dos24
-rw-r--r--README.hpux8x4
-rw-r--r--README.ibmrt-aos (renamed from config/sunos41-gnulibc)0
-rw-r--r--README.linux3
-rw-r--r--array.c17
-rw-r--r--atari/textrd.c30
-rw-r--r--awk.h42
-rw-r--r--awk.y102
-rw-r--r--awktab.c3948
-rw-r--r--builtin.c84
-rw-r--r--config/bsd44 (renamed from config/bsd44alpha)0
-rw-r--r--config/hpux7.08
-rw-r--r--config/hpux8x3
-rw-r--r--config/ibmrt-aos0
-rw-r--r--config/linux3
-rw-r--r--config/linux.h295
-rw-r--r--config/riscos4527
-rw-r--r--config/sequent1
-rw-r--r--config/sgi4054
-rw-r--r--config/sgi405.cc6
-rw-r--r--config/sunos41-glibc0
-rw-r--r--config/ultrix311
-rw-r--r--dfa.c43
-rw-r--r--dfa.h4
-rw-r--r--eval.c11
-rw-r--r--field.c129
-rw-r--r--gawk.1270
-rw-r--r--gawk.info204
-rw-r--r--gawk.info-11069
-rw-r--r--gawk.info-21236
-rw-r--r--gawk.info-31288
-rw-r--r--gawk.info-41305
-rw-r--r--gawk.info-51256
-rw-r--r--gawk.info-61234
-rw-r--r--gawk.info-71265
-rw-r--r--gawk.info-81173
-rw-r--r--gawk.info-9359
-rw-r--r--gawk.texi586
-rw-r--r--getopt1.c160
-rw-r--r--io.c387
-rw-r--r--iop.c38
-rw-r--r--main.c320
-rw-r--r--missing.c14
-rw-r--r--missing/strchr.c10
-rw-r--r--missing/strftime.324
-rw-r--r--missing/strftime.c157
-rw-r--r--missing/strncasecmp.c (renamed from missing/strcase.c)0
-rw-r--r--missing/system.c2
-rw-r--r--node.c11
-rw-r--r--protos.h1
-rw-r--r--re.c68
-rw-r--r--regex.h2
-rw-r--r--test/Makefile27
-rw-r--r--test/fieldwdth.good (renamed from test/fieldwidths.good)0
-rw-r--r--test/ignrcase.good (renamed from test/ignorecase.good)0
-rwxr-xr-xtest/pound-bang3
-rw-r--r--test/pound-bang.good1
-rwxr-xr-xtest/poundbang3
-rw-r--r--test/poundbang.good1
-rw-r--r--version.c5
-rw-r--r--vms/vms_misc.c16
69 files changed, 14693 insertions, 2948 deletions
diff --git a/FUTURES b/FUTURES
index d119b6d0..da714318 100644
--- a/FUTURES
+++ b/FUTURES
@@ -3,116 +3,109 @@ in roughly the order they will be done for a given release. This file is
mainly for use by the developers to help keep themselves on track, please
don't bug us too much about schedules or what all this really means.
-Still to go in 2.13
-===================
+For 2.16
+========
+David:
+ Move to autoconf-based configure system.
-4/18/91: MOSTLY DONE: Make printf fully compatible with the ANSI C spec.
+ Allow RS to be a regexp.
-4/18/91: DONE: Supply a warning for: /foo/ ~ exp, /foo/ !~ exp
+ RT variable to hold text of record terminator
-4/19/91: DONE: Fix CONVFMT and OFMT interaction
+ RECLEN variable for fixed length records
-3/19/91: DONE: move -C, -V, -c options to -W ala posix
+ Feedback alloca.s changes to FSF
-3/19/91: DONE: -W posix option, throw out \x
+ Extensible hashing in memory of awk arrays
-3/19/91: DONE: clean up ifdef stuff, go to config.h
+ Split() with null string as third arg to split up strings
-3/19/91: DONE: -W lint option
+ Analogously, setting FS="" would split the input record into individual
+ characters.
-4/5/91: DONE: change from time and ctime to sysclock and strftime
+Arnold:
+ Generalize IGNORECASE
+ any value makes it work, not just numeric non-zero
+ make it apply to *all* string comparisons
-4/21/91: DONE: make /dev/fd checking happen at run time
+ Fix FILENAME to have an initial value of "", not "-"
-4/14/91: DONE: man page fix up
+ Clean up code by isolating system-specific functions in separate files.
-4/17/91: DONE: Table driven built-in subroutine argument count checking
+ Undertake significant directory reorganization.
-6/1/92: DONE: Update regex.h flags for AWK and feed back to FSF
+ Extensive manual cleanup:
+ Use of texinfo 2.0 features
+ Lots more examples
+ Document all of the above.
-Feedback alloca.s changes to FSF
+In 2.17
+=======
+David:
-10/28/91: DONE: Brief manual clean up
+ Incorporate newer dfa.c and regex.c (go to POSIX regexps)
-4/18/91: DONE: Provide a list of systems
- a) where gawk has been ported
- b) where it has run the test suite
+ Make regex + dfa less dependant on gawk header file includes
-For 2.14
-========
+ General sub functions:
+ edit(line, pat, sub) and gedit(line, pat, sub)
+ that return the substituted strings and allow \1 etc. in the sub string.
-6/18/92: DONE: "next file" keyword sequence
+Arnold:
+ DBM storage of awk arrays. Try to allow multiple dbm packages
-10/28/91: DONE: Warn or fatal if identifier used as both variable and array
+ ? Have strftime() pay attention to the value of ENVIRON["TZ"]
-12/22/91: DONE: Variables string or numeric or both
+ Additional manual features:
+ Document posix regexps
+ Document use of dbm arrays
+ ? Add an error messages section to the manual
+ ? A section on where gawk is bounded
+ regex
+ i/o
+ sun fp conversions
-In 2.15 or later
-================
+For 2.18
+========
-more lint: check for use of builtin vars. only in new awk.
+Arnold:
+ Add chdir and stat built-in functions.
-Extensible hashing and on-disk storage of awk arrays
+ Add function pointers as valid variable types.
-"restart" keyword
+ Add an `ftw' built-in function that takes a function pointer.
-Add |&
+David:
-Split() with null string as third arg to split up strings
+ Do an optimization pass over parse tree?
-Analogously, setting FS="" would split the input record into individual
-characters.
+For 2.19 or later:
+==================
+Add lint checking everywhere, including check for use of builtin vars.
+only in new awk.
-Allow RS to be a regexp.
+"restart" keyword
-RECLEN variable for fixed length records
+Add |&
Make awk '/foo/' files... run at egrep speeds
-Extensive manual cleanup:
-
- Use of texinfo 2.0 features
-
- Lots more examples
-
- Add an error messages section to the manual
-
- A section on where gawk is bounded
- regex
- i/o
- sun fp conversions
-
Do a reference card
-? Have strftime() pay attention to the value of ENVIRON["TZ"]
-
-A way to mix library files and command line strings for source code (-s?)
-
Allow OFMT to be other than a floating point format.
-? SFIO based printf and other i/o
-
Allow redefining of builtin functions?
-Incorporate newer dfa.c and regex.c
-
-Make regex + dfa less dependant on gawk header file includes
-
-General sub functions edit(line, pat, sub) and gedit(line, pat, sub) that
- return the substituted strings and allow \1 etc. in the sub string.
-
-Add lint checking everywhere
-
Make it faster and smaller.
-Create a gawk-to-C translator? (or C++??)
+For 3.x:
+========
Create a gawk compiler?
-Do an optimization pass over parse tree?
+Create a gawk-to-C translator? (or C++??)
Provide awk profiling and debugging.
-Clean up code by isolating system-specific functions in separate files.
-Move to autoconf-based configure system.
+
diff --git a/Makefile.bsd44alpha b/Makefile.bsd44
index 269f14b8..269f14b8 100644
--- a/Makefile.bsd44alpha
+++ b/Makefile.bsd44
diff --git a/Makefile.in b/Makefile.in
index 58eb9394..f4792dc3 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -51,9 +51,9 @@ LINKSTATIC= #-Bstatic
WARN= #-W -Wunused -Wimplicit -Wreturn-type -Wcomment # for gcc only
# Parser to use on grammar - any one of the following will work
-PARSER = yacc
+PARSER = bison -y
+#PARSER = yacc
#PARSER = byacc
-#PARSER = bison -y
# Set LIBS to any libraries that are machine specific
LIBS =
@@ -76,7 +76,6 @@ LIBS =
##MAKE_ALLOCA_S## ALLOCA= alloca.o
FLAGS=
-##MAKE_RS6000## FLAGS = -qchars=signed
# VMS POSIX, VAXC V3.2
##MAKE_VMS-Posix## FLAGS = -UVMS -D__STDC__=0
@@ -85,6 +84,9 @@ FLAGS=
##MAKE_Apollo## FLAGS = -U__STDC__ -A run,sys5.3
##MAKE_Apollo## LIBS = -A sys,any
+# SGI IRIX 4.0.5 cc flags
+##MAKE_SGI## FLAGS = -cckr
+
# Use -s -Xlinker -object flags when you are satisfied that
# that the program compiles correctly
##MAKE_NeXT## FLAGS = -DGFMT_WORKAROUND #-s -Xlinker -object
@@ -93,7 +95,7 @@ CFLAGS= -DGAWK $(FLAGS) $(DEBUG) $(LINKSTATIC) $(PROFILE) $(OPTIMIZE) $(WARN)
# object files
AWKOBJS = main.o eval.o builtin.o msg.o iop.o io.o field.o array.o \
- node.o version.o missing.o re.o getopt.o
+ node.o version.o missing.o re.o getopt.o getopt1.o
ALLOBJS = $(AWKOBJS) awktab.o
@@ -103,7 +105,7 @@ GNUOBJS= regex.o dfa.o $(ALLOCA)
# source and documentation files
SRC = main.c eval.c builtin.c msg.c version.c \
- iop.c io.c field.c array.c node.c missing.c re.c getopt.c
+ iop.c io.c field.c array.c node.c missing.c re.c getopt.c getopt1.c
ALLSRC= $(SRC) awktab.c
@@ -113,7 +115,7 @@ GNUSRC = alloca.c alloca.s dfa.c dfa.h regex.c regex.h
COPIES = missing/system.c missing/tzset.c \
missing/memcmp.c missing/memcpy.c missing/memset.c \
- missing/random.c missing/strcase.c missing/strchr.c \
+ missing/random.c missing/strncasecmp.c missing/strchr.c \
missing/strerror.c missing/strtod.c \
missing/strftime.c missing/strftime.3
@@ -136,7 +138,7 @@ ALLFILES= $(AWKSRC) $(GNUSRC) $(COPIES) $(MISC) $(DOCS) $(ALLDOC) $(OTHERS) \
$(SUPPORT)
# Release of gawk. There can be no leading or trailing white space here!
-REL=2.14
+REL=2.15
# rules to build gawk
gawk: $(ALLOBJS) $(GNUOBJS) $(REOBJS)
@@ -146,6 +148,8 @@ $(AWKOBJS) regex.o dfa.o: awk.h dfa.h regex.h
getopt.o: getopt.h
+getopt1.o: getopt.h
+
main.o: patchlevel.h
awktab.c: awk.y
@@ -161,8 +165,8 @@ config.h: config.in
@echo or copy config.in to config.h and edit it.; exit 1
install: gawk
- install -s gawk $(DESTDIR)$(BINDIR)
- install -c gawk.1 $(DESTDIR)$(MANDIR)/gawk.$(MANEXT)
+ cp gawk $(DESTDIR)$(BINDIR)
+ cp gawk.1 $(DESTDIR)$(MANDIR)/gawk.$(MANEXT)
# ALLOCA: uncomment this if your system (notably System V boxen)
# does not have alloca in /lib/libc.a or /lib/libPW.a
@@ -193,7 +197,7 @@ clean:
*.orig *.rej */*.orig */*.rej
cleaner: clean
- rm -f gawk awktab.c
+ rm -f gawk awktab.c Makefile
clobber: clean
rm -f $(ALLDOC) gawk.log
@@ -206,14 +210,14 @@ gawk.dvi: gawk.texi
gawk.info: gawk.texi
makeinfo gawk.texi
-gawk-test-$(REL).tar.Z::
- -rm -f gawk-test-$(REL).tar.Z
- tar -cf - test | compress >gawk-test-$(REL).tar.Z
+gawk-test-$(REL).tar.z::
+ -rm -f gawk-test-$(REL).tar.z
+ tar -cf - test | gzip >gawk-test-$(REL).tar.z
dist: $(AWKSRC) $(GNUSRC) $(DOCS) $(MISC) $(COPIES) $(SUPPORT) clean
./configure msdos
mv config.h pc
- -rm -rf gawk-$(REL) gawk-$(REL).*.tar.Z
+ -rm -rf gawk-$(REL) gawk-$(REL).*.tar.z
-mkdir gawk-$(REL)
cp -p $(AWKSRC) $(GNUSRC) $(DOCS) $(MISC) gawk-$(REL)
-mkdir gawk-$(REL)/missing
@@ -228,25 +232,29 @@ dist: $(AWKSRC) $(GNUSRC) $(DOCS) $(MISC) $(COPIES) $(SUPPORT) clean
cp -p config/* gawk-$(REL)/config
-mkdir gawk-$(REL)/support
cp -p support/* gawk-$(REL)/support
- tar -cf - test | (cd gawk-$(REL); tar xpf - )
- tar -cf - gawk-$(REL) | compress > gawk-$(REL).`gawk '{print $$3}' patchlevel.h`.tar.Z
+ mv test gawk-$(REL)
+ tar -cf - gawk-$(REL) | gzip > gawk-$(REL).`gawk '{print $$3}' patchlevel.h`.tar.z
+ mv gawk-$(REL)/test .
-gawk-doc-$(REL).tar.Z: gawk.info gawk.dvi gawk.1
- -rm -rf gawk-doc-$(REL) gawk-doc-$(REL).tar.Z
+gawk-doc-$(REL).tar.z: gawk.info gawk.dvi gawk.1
+ -rm -rf gawk-doc-$(REL) gawk-doc-$(REL).tar.z
-mkdir gawk-doc-$(REL)
cp -p $(INFOFILES) gawk.dvi gawk-doc-$(REL)
nroff -man gawk.1 > gawk-doc-$(REL)/gawk.1.pr
- tar -cf - gawk-doc-$(REL) | compress > gawk-doc-$(REL).tar.Z
+ tar -cf - gawk-doc-$(REL) | gzip > gawk-doc-$(REL).tar.z
-gawk-ps-$(REL).tar.Z: gawk.dvi gawk.1
- -rm -rf gawk-ps-$(REL) gawk-ps-$(REL).tar.Z
+gawk-ps-$(REL).tar.z: gawk.dvi gawk.1
+ -rm -rf gawk-ps-$(REL) gawk-ps-$(REL).tar.z
-mkdir gawk-ps-$(REL)
dvips -o !cat gawk.dvi > gawk-ps-$(REL)/gawk.postscript
pstroff -man gawk.1 > gawk-ps-$(REL)/gawk.1.ps
- tar -cf - gawk-ps-$(REL) | compress > gawk-ps-$(REL).tar.Z
+ tar -cf - gawk-ps-$(REL) | gzip > gawk-ps-$(REL).tar.z
-release: gawk-src-$(REL).tar.Z gawk-doc-$(REL).tar.Z gawk-ps-$(REL).tar.Z \
- gawk-test-$(REL).tar.Z
+release: gawk-src-$(REL).tar.z gawk-doc-$(REL).tar.z gawk-ps-$(REL).tar.z \
+ gawk-test-$(REL).tar.z
test: gawk
cd test; make -k
+
+check: test
+
diff --git a/NEWS b/NEWS
index 191de0bf..94d9b11b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,87 @@
+Changes from 2.14 to 2.15
+---------------------------
+
+Command-line source can now be mixed with library functions.
+
+ARGIND variable tracks index in ARGV of FILENAME.
+
+GNU style long options in addition to short options.
+
+Plan 9 style special files interpreted by gawk:
+ /dev/pid
+ /dev/ppid
+ /dev/pgrpid
+ /dev/user
+ $1 = getuid
+ $2 = geteuid
+ $3 = getgid
+ $4 = getegid
+ $5 ... $NF = getgroups if supported
+
+ERRNO variable contains error string if getline or close fails.
+
+Very old options -a and -e have gone away.
+
+Inftest has been removed from the default target in test/Makefile -- the
+ results were too machine specific and resulted in too many false alarms.
+
+A README.amiga has been added.
+
+The "too many arguments supplied for format string" warning message is only
+ in effect under the lint option.
+
+Code improvements in dfa.c.
+
+Fixed all reported bugs:
+
+ Writes are checked for failure (such as full filesystem).
+
+ Stopped (at least some) runaway error messages.
+
+ gsub(/^/, "x") does the right thing for $0 of 0, 1, or more length.
+
+ close() on a command being piped to a getline now works properly.
+
+ The input record will no longer be freed upon an explicit close()
+ of the input file.
+
+ A NUL character in FS now works.
+
+ In a substitute, \\& now means a literal backslash followed by what
+ was matched.
+
+ Integer overflow of substring length in substr() is caught.
+
+ An input record without a newline termination is handled properly.
+
+ In io.c, check is against only EMFILE so that system file table
+ is not filled.
+
+ Renamed all files with names longer than 14 characters.
+
+ Escaped characters in regular expressions were being lost when
+ IGNORECASE was used.
+
+ Long source lines were not being handled properly.
+
+ Sourcefiles that ended in a tab but no newline were bombing.
+
+ Patterns that could match zero characters in split() were not working
+ properly.
+
+ The parsedebug option was not working.
+
+ The grammar was being a bit too lenient, allowing some very dubious
+ programs to pass.
+
+ Compilation with DEBUG defined now works.
+
+ A variable read in with getline was not being treated as a potential
+ number.
+
+ Array subscripts were not always of string type.
+
+
Changes from 2.13.2 to 2.14
---------------------------
diff --git a/PORTS b/PORTS
index bd2678dd..95e133f9 100644
--- a/PORTS
+++ b/PORTS
@@ -17,3 +17,16 @@ VMS POSIX V1.0, V1.1
OpenVMS AXP V1.0
MSDOS - Microsoft C 5.1, compiles and runs very simple testing
BSD 4.4alpha
+
+From: ghazi@caip.rutgers.edu (Kaveh R. Ghazi):
+
+arch configured as:
+---- --------------
+Hpux 9.0 hpux8x
+NeXTStep 2.0 next20
+Sgi Irix 4.0.5 (/bin/cc) sgi405.cc (new file)
+Stardent Titan 1500 OSv2.5 sysv3
+Stardent Vistra (i860) SVR4 sysv4
+SunOS 4.1.2 sunos41
+Tektronix XD88 (UTekV 3.2e) sysv3
+Ultrix 4.2 ultrix41
diff --git a/PROBLEMS b/PROBLEMS
index 0f9a620d..3b7c5148 100644
--- a/PROBLEMS
+++ b/PROBLEMS
@@ -1,4 +1,4 @@
-This is a list of known problems in gawk 2.14.
+This is a list of known problems in gawk 2.15.
Hopefully they will all be fixed in the next major release of gawk.
Please keep in mind that the code is still undergoing significant evolution.
diff --git a/README b/README
index 5161a00a..f4bd3df8 100644
--- a/README
+++ b/README
@@ -1,10 +1,10 @@
README:
-This is GNU Awk 2.14. It should be upwardly compatible with the
+This is GNU Awk 2.15. It should be upwardly compatible with the
System V Release 4 awk. It is almost completely compliant with draft 11.3
of POSIX 1003.2.
-This release is essentially a bug fix release.
+This release adds new features -- see NEWS for details.
See the installation instructions, below.
@@ -63,7 +63,7 @@ After successful compilation, do 'make test' to run a small test
suite. There should be no output from the 'cmp' invocations except in
the cases where there are small differences in floating point values.
If there are other differences, please investigate and report the
-problem. More extensive testing can be invoked with 'make bigtest'.
+problem.
PRINTING THE MANUAL
diff --git a/README.amiga b/README.amiga
new file mode 100644
index 00000000..bb5d267f
--- /dev/null
+++ b/README.amiga
@@ -0,0 +1,89 @@
+From: "Lars Hecking" <ST000002@hrz1.hrz.th-darmstadt.de>
+Date: Thu, 3 Dec 1992 17:56:24 -0400
+Subject: Gawk-2.14 -- Amiga-Port, the 2nd
+
+Gawk on the Amiga has been compiled and tested using the Amiga port
+of gcc by Markus Wild (wild@nessie.cs.id.ethz.ch). I recommend the use
+of this compiler (at least v2.2.2) because the provided environment
+(includes, libs, binutils) allows straight-forward porting of BSD/UNIX
+programs. Gcc compiled programs access/emulate UNIX syscalls via a
+shared library (ixemul.library); thus, only minimal changes to the
+source are necessary. That release also provides a `sh'- command. If
+no `sh'-command is available or another compiler is being used,
+`config.h' and `Makefile' are to be created by hand. Since I'm afraid
+that none of the Amiga-specific make-commands handles UNIX-style
+makefiles correctly I suggest the use of Dennis Vadura's`dmake',
+which is available on the Amiga (v3.6). I'm currently using dmake v3.8
+(a hack) or GNU make v3.62 (another hack :), which even allows
+to start multiple make jobs! Thanx to Markus!).
+
+Machine Configuration (obsoleted by gawk 2.16)
+---------------------
+Only copy the following into config/amiga:
+
+Amiga under AmigaOS with gcc
+DOPRNT_MISSING 1
+ENVSEP ','
+DEFPATH ".,/usr/local/lib"
+HAVE_UNDERSCORE_SETJMP 1
+SRANDOM_PROTO 1
+STDC_HEADERS 1
+
+The gcc compiler and the compiled executables are working under
+AmigaOS 1.2/1.3 as well as AmigaOS 2.x. However, some very special
+functions of ixemul.library currently require AmigaOS 2.x to work
+properly.
+
+
+How to compile (obsoleted by gawk 2.16)
+--------------
+Compiling and installing on the Amiga rather clones the UNIX-
+installation:
+
+After you have extracted the `gawk' distribution, `cd' to `gawk-
+2.14'. Look in the `config' subdirectory for a file that matches your
+machine (in this case: `amiga', if the gawk maintainers put it there
+:).
+
+ If you find such a file, run the command:
+
+ sh configure amiga
+
+ This produces a `Makefile' and `config.h' tailored to your system.
+ You may wish to edit the `Makefile' to use a different C compiler,
+ such as `gcc', the GNU C compiler (recommended), if you have it.
+ You may also wish to change the `CFLAGS' variable, which controls
+ the command line options that are passed to the C compiler (such as
+ optimization levels, or producing `resident'-able code)
+
+ After you have configured `Makefile' and `config.h', type:
+
+ make
+
+and shortly thereafter (a little bit longer on a 7MHz machine >:->,
+you should have an executable version of `gawk'. That's all there is
+to it!
+
+
+Testing ( %-/
+-------
+Testing gawk with the included shell-scripts and .awk-files is not
+possible. As far as I found out this is a Shell problem (shell-
+metas), not a gawk problem. Using gawk from the commandline requires
+modifications, too. To perform at least some of the tests I'd
+suggest:
+
+ make >amitest -n bigtest
+
+then modifying 'amitest' to work with your shell and
+
+ execute amitest
+
+All tests that are depending on UNIX-shell specifics will fail (eg.
+redirection of stderr: stderr and stdout are identical on the Amiga).
+If I really have the time (currently I'm finishing my studies) I'll
+write an amiga-script for the tests ...
+
+Despite testing is not a thankful task, `gawk' works and I found it
+very useful for tasks where both shell scripts and C-programs are
+inadequate.
diff --git a/README.dos b/README.dos
index 0d81261f..110fed7e 100644
--- a/README.dos
+++ b/README.dos
@@ -1,9 +1,19 @@
-Gawk has been compiled and (very) minimally tested under MS-DOS using
-MSC 5.1. To compile under DOS, move the stuff in the pc directory to
-the directory with the rest of the gawk sources, and run make.bat.
-The Makefile.pc file is obsolete and should probably go away.
+ Gawk has been compiled and tested under MS-DOS using MSC 5.1. To compile
+under DOS, move the stuff in the pc directory to the directory with the rest
+of the gawk sources, and run make.bat.
-You will have to put CRs at the end of each line in make.bat.
+ If you have Ndmake (or some other unix-like make utility), you can use
+the Makefile.pc file.
-You will have to copy the Microsoft library routine setargv.obj to
-the gawk directory for the link to work
+ You will have to put CRs at the end of each line in the make.bat or
+Makefile.pc file.
+
+ You will also have to copy the Microsoft library routine setargv.obj to
+the gawk directory for the link to work.
+
+ Please note: Gawk is very sensitive to compiler optimization; using -Oa
+or -Ox WILL cause errors. It is recommended to only use the default
+optimization. Also, you should get warning messages, but you can ignore them.
+
+ If you have any problems with the DOS version of Gawk, please send them to
+Scott Deifik, scottd@amgen.com.
diff --git a/README.hpux8x b/README.hpux8x
new file mode 100644
index 00000000..7b005bb7
--- /dev/null
+++ b/README.hpux8x
@@ -0,0 +1,4 @@
+When compiling on HPPA machines running HP-UX 8.0x you should add the
+option: "+Obb1000". The file awktab.c fails to compile without this
+option. The option sets the maximum number of basic blocks allowed
+in a function to 1000.
diff --git a/config/sunos41-gnulibc b/README.ibmrt-aos
index e69de29b..e69de29b 100644
--- a/config/sunos41-gnulibc
+++ b/README.ibmrt-aos
diff --git a/README.linux b/README.linux
deleted file mode 100644
index 813fc623..00000000
--- a/README.linux
+++ /dev/null
@@ -1,3 +0,0 @@
-A proper config file was not submitted for linux, so just copy
-config/linux.h to config.h and make the small changes noted in
-the comment at the top of that file.
diff --git a/array.c b/array.c
index a5f5c754..59be340c 100644
--- a/array.c
+++ b/array.c
@@ -203,11 +203,24 @@ NODE *symbol, *subs;
/* It's not there, install it. */
if (do_lint && subs->stlen == 0)
- warning("subscript of array is null string");
+ warning("subscript of array `%s' is null string",
+ symbol->vname);
getnode(bucket);
bucket->type = Node_ahash;
- bucket->ahname = dupnode(subs);
+ if (subs->flags & TEMP)
+ bucket->ahname = dupnode(subs);
+ else {
+ unsigned int saveflags = subs->flags;
+
+ subs->flags &= ~MALLOC;
+ bucket->ahname = dupnode(subs);
+ subs->flags = saveflags;
+ }
free_temp(subs);
+
+ /* array subscripts are strings */
+ bucket->ahname->flags &= ~NUMBER;
+ bucket->ahname->flags |= STRING;
bucket->ahvalue = Nnull_string;
bucket->ahnext = symbol->var_array[hash1];
symbol->var_array[hash1] = bucket;
diff --git a/atari/textrd.c b/atari/textrd.c
deleted file mode 100644
index 07ed0905..00000000
--- a/atari/textrd.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * From gnulib Atari ST sources - with a fix for a bug causing
- * a premature EOF when only characters read are CR's.
- * Written by Eric R. Smith and placed in the public domain.
- * Fix - Michal Jaegermann, June 1991.
- */
-#include <stdio.h>
-#include <unistd.h>
-int
-_text_read(fd, buf, nbytes)
- int fd;
- char *buf;
- int nbytes;
-{
- char *to, *from;
- int r;
- do {
- r = read(fd, buf, nbytes);
- if (r <= 0) /* if EOF or read error - return */
- return r;
- to = from = buf;
- do {
- if (*from == '\r')
- from++;
- else
- *to++ = *from++;
- } while (--r);
- } while (buf == to); /* only '\r's? - try to read next nbytes */
- return (to - buf);
-}
diff --git a/awk.h b/awk.h
index 5fcf7c2f..ca3997f1 100644
--- a/awk.h
+++ b/awk.h
@@ -35,8 +35,10 @@
extern int errno;
#endif
#ifdef __GNU_LIBRARY__
+#ifndef linux
#include <signum.h>
#endif
+#endif
/* ----------------- System dependencies (with more includes) -----------*/
@@ -388,6 +390,7 @@ typedef struct exp_node {
# define MAYBE_NUM 128 /* user input: if NUMERIC then
* a NUMBER
*/
+ char *vname; /* variable's name */
} NODE;
#define lnode sub.nodep.l.lptr
@@ -454,6 +457,8 @@ typedef struct iobuf {
long secsiz;
int flag;
# define IOP_IS_TTY 1
+# define IOP_IS_INTERNAL 2
+# define IOP_NO_FREE 4
} IOBUF;
typedef void (*Func_ptr)();
@@ -480,6 +485,12 @@ struct redirect {
struct redirect *next;
};
+/* structure for our source, either a command line string or a source file */
+struct src {
+ enum srctype { CMDLINE = 1, SOURCEFILE } stype;
+ char *val;
+};
+
/* longjmp return codes, must be nonzero */
/* Continue means either for loop/while continue, or next input record */
#define TAG_CONTINUE 1
@@ -496,7 +507,6 @@ extern int NF;
extern int NR;
extern int FNR;
extern int IGNORECASE;
-extern char *FS;
extern char *RS;
extern char *OFS;
extern int OFSlen;
@@ -526,7 +536,7 @@ extern const char *myname;
extern NODE *nextfree;
extern int field0_valid;
-extern int strict;
+extern int do_unix;
extern int do_posix;
extern int do_lint;
extern int in_begin_rule;
@@ -649,30 +659,6 @@ extern NODE *do_srand P((NODE *tree));
extern NODE *do_match P((NODE *tree));
extern NODE *do_gsub P((NODE *tree));
extern NODE *do_sub P((NODE *tree));
-/* debug.c */
-extern int ptree P((NODE *n));
-extern NODE *pt P((void));
-extern int print_parse_tree P((NODE *ptr));
-extern int dump_vars P((void));
-extern int dump_fields P((void));
-extern int print_debug P((char *str, void * n));
-extern int print_a_node P((NODE *ptr));
-extern int print_maybe_semi P((NODE *ptr));
-extern int deal_with_curls P((NODE *ptr));
-extern NODE *do_prvars P((void));
-extern NODE *do_bp P((void));
-extern void do_free P((char *s));
-/* dfa.c */
-extern void regsyntax P((long bits, int fold));
-extern void regparse P((const char *s, size_t len, struct regexp *r));
-extern void reganalyze P((struct regexp *r, int searchflag));
-extern void regstate P((int s, struct regexp *r, int trans[]));
-extern char *regexecute P((struct regexp *r, char *begin,
- char *end, int newline, int *count, int *backref));
-extern void reginit P((struct regexp *r));
-extern void regcompile P((const char *s, size_t len,
- struct regexp *r, int searchflag));
-extern void reg_free P((struct regexp *r));
/* eval.c */
extern int interpret P((NODE *volatile tree));
extern NODE *r_tree_eval P((NODE *tree));
@@ -708,7 +694,7 @@ extern void do_nextfile P((void));
/* iop.c */
extern int optimal_bufsize P((int fd));
extern IOBUF *iop_alloc P((int fd));
-extern int get_a_record P((char **out, IOBUF *iop, int rs));
+extern int get_a_record P((char **out, IOBUF *iop, int rs, int *errcode));
/* main.c */
extern int main P((int argc, char **argv));
extern Regexp *mk_re_parse P((char *s, int ignorecase));
@@ -741,7 +727,7 @@ extern void freenode P((NODE *it));
extern void unref P((NODE *tmp));
extern int parse_escape P((char **string_ptr));
/* re.c */
-extern Regexp *make_regexp P((NODE *s, int ignorecase, int dfa));
+extern Regexp *make_regexp P((char *s, int len, int ignorecase, int dfa));
extern int research P((Regexp *rp, char *str, int start, int len, int need_start));
extern void refree P((Regexp *rp));
extern void reg_error P((const char *s));
diff --git a/awk.y b/awk.y
index ee3e60e5..e737e7fe 100644
--- a/awk.y
+++ b/awk.y
@@ -66,8 +66,8 @@ NODE *variables[HASHSIZE];
extern char *source;
extern int sourceline;
-extern char *cmdline_src;
-extern char **srcfiles;
+extern struct src *srcfiles;
+extern int numfiles;
extern int errcount;
extern NODE *begin_block;
extern NODE *end_block;
@@ -84,7 +84,7 @@ extern NODE *end_block;
%type <nodeval> function_prologue function_body
%type <nodeval> rexp exp start program rule simp_exp
-%type <nodeval> non_post_simp_exp post_inc_dec_exp
+%type <nodeval> non_post_simp_exp
%type <nodeval> pattern
%type <nodeval> action variable param_list
%type <nodeval> rexpression_list opt_rexpression_list
@@ -293,11 +293,13 @@ regexp
REGEXP '/'
{
NODE *n;
+ int len;
getnode(n);
n->type = Node_regex;
- n->re_exp = make_string($3, strlen($3));
- n->re_reg = mk_re_parse($3, 0);
+ len = strlen($3);
+ n->re_exp = make_string($3, len);
+ n->re_reg = make_regexp($3, len, 0, 1);
n->re_text = NULL;
n->re_flags = CONST;
n->re_cnt = 1;
@@ -383,14 +385,19 @@ statement
| LEX_NEXT opt_exp statement_term
{ NODETYPE type;
- if (! io_allowed) yyerror("next used in BEGIN or END action");
if ($2 && $2 == lookup("file")) {
if (do_lint)
warning("`next file' is a gawk extension");
- else if (strict || do_posix)
+ else if (do_unix || do_posix)
yyerror("`next file' is a gawk extension");
+ else if (! io_allowed)
+ yyerror("`next file' used in BEGIN or END action");
type = Node_K_nextfile;
- } else type = Node_K_next;
+ } else {
+ if (! io_allowed)
+ yyerror("next used in BEGIN or END action");
+ type = Node_K_next;
+ }
$$ = node ((NODE *)NULL, type, (NODE *)NULL);
}
| LEX_EXIT opt_exp statement_term
@@ -591,7 +598,7 @@ exp : variable ASSIGNOP
{ $$ = node($1, Node_cond_exp, node($3, Node_if_branches, $5));}
| simp_exp
{ $$ = $1; }
- | exp exp %prec CONCAT_OP
+ | exp simp_exp %prec CONCAT_OP
{ $$ = node ($1, Node_concat, $2); }
;
@@ -624,13 +631,12 @@ rexp
{ $$ = node($1, Node_cond_exp, node($3, Node_if_branches, $5));}
| simp_exp
{ $$ = $1; }
- | rexp rexp %prec CONCAT_OP
+ | rexp simp_exp %prec CONCAT_OP
{ $$ = node ($1, Node_concat, $2); }
;
simp_exp
: non_post_simp_exp
- | post_inc_dec_exp
/* Binary operators in order of decreasing precedence. */
| simp_exp '^' simp_exp
{ $$ = node ($1, Node_exp, $3); }
@@ -644,6 +650,10 @@ simp_exp
{ $$ = node ($1, Node_plus, $3); }
| simp_exp '-' simp_exp
{ $$ = node ($1, Node_minus, $3); }
+ | variable INCREMENT
+ { $$ = node ($1, Node_postincrement, (NODE *)NULL); }
+ | variable DECREMENT
+ { $$ = node ($1, Node_postdecrement, (NODE *)NULL); }
;
non_post_simp_exp
@@ -652,12 +662,8 @@ non_post_simp_exp
| '(' exp r_paren
{ $$ = $2; }
| LEX_BUILTIN
- {
- if (! io_allowed && strcmp(tokstart, "nextfile") == 0)
- yyerror("nextfile() is illegal in BEGIN and END");
- }
'(' opt_expression_list r_paren
- { $$ = snode ($4, Node_builtin, (int) $1); }
+ { $$ = snode ($3, Node_builtin, (int) $1); }
| LEX_LENGTH '(' opt_expression_list r_paren
{ $$ = snode ($3, Node_builtin, (int) $1); }
| LEX_LENGTH
@@ -672,6 +678,7 @@ non_post_simp_exp
{
$$ = node ($3, Node_func_call, make_string($1, strlen($1)));
}
+ | variable
| INCREMENT variable
{ $$ = node ($2, Node_preincrement, (NODE *)NULL); }
| DECREMENT variable
@@ -692,14 +699,6 @@ non_post_simp_exp
{ $$ = $2; }
;
-post_inc_dec_exp
- : variable INCREMENT
- { $$ = node ($1, Node_postincrement, (NODE *)NULL); }
- | variable DECREMENT
- { $$ = node ($1, Node_postdecrement, (NODE *)NULL); }
- | variable
- ;
-
opt_variable
: /* empty */
{ $$ = NULL; }
@@ -720,8 +719,6 @@ variable
}
| '$' non_post_simp_exp
{ $$ = node ($2, Node_field_spec, (NODE *)NULL); }
- | '$' variable
- { $$ = node ($2, Node_field_spec, (NODE *)NULL); }
;
l_brace
@@ -825,7 +822,7 @@ yyerror(va_alist)
va_dcl
{
va_list args;
- char *mesg;
+ char *mesg = NULL;
register char *bp, *cp;
char *scan;
char buf[120];
@@ -834,7 +831,12 @@ va_dcl
/* Find the current line in the input file */
if (lexptr) {
if (!thisline) {
- for (cp=lexeme; cp != lexptr_begin && *cp != '\n'; --cp)
+ cp = lexeme;
+ if (*cp == '\n') {
+ cp--;
+ mesg = "unexpected newline";
+ }
+ for ( ; cp != lexptr_begin && *cp != '\n'; --cp)
;
if (*cp == '\n')
cp++;
@@ -862,7 +864,8 @@ va_dcl
*bp++ = ' ';
}
va_start(args);
- mesg = va_arg(args, char *);
+ if (mesg == NULL)
+ mesg = va_arg(args, char *);
strcpy(bp, mesg);
err("", buf, args);
va_end(args);
@@ -882,13 +885,14 @@ get_src_buf()
static int did_newline = 0;
# define SLOP 128 /* enough space to hold most source lines */
- if (cmdline_src) {
+ if (nextfile > numfiles)
+ return NULL;
+
+ if (srcfiles[nextfile].stype == CMDLINE) {
if (len == 0) {
- len = strlen(cmdline_src);
- if (len == 0)
- cmdline_src = NULL;
+ len = strlen(srcfiles[nextfile].val);
sourceline = 1;
- lexptr = lexptr_begin = cmdline_src;
+ lexptr = lexptr_begin = srcfiles[nextfile].val;
lexend = lexptr + len;
} else if (!did_newline && *(lexptr-1) != '\n') {
/*
@@ -914,15 +918,22 @@ get_src_buf()
lexeme = lexptr - offset;
lexptr_begin = buf;
lexend = lexptr + 1;
- } else
+ } else {
+ len = 0;
lexeme = lexptr = lexptr_begin = NULL;
+ }
+ if (lexptr == NULL && ++nextfile <= numfiles)
+ return get_src_buf();
return lexptr;
}
if (!samefile) {
- source = srcfiles[nextfile];
+ source = srcfiles[nextfile].val;
if (source == NULL) {
- if (buf)
+ if (buf) {
free(buf);
+ buf = NULL;
+ }
+ len = 0;
return lexeme = lexptr = lexptr_begin = NULL;
}
fd = pathopen(source);
@@ -952,7 +963,7 @@ get_src_buf()
}
linelen = lexptr - scan;
if (linelen > SLOP)
- len = SLOP;
+ linelen = SLOP;
thisline = buf + SLOP - linelen;
memcpy(thisline, scan, linelen);
lexeme = buf + SLOP - offset;
@@ -965,6 +976,7 @@ get_src_buf()
if (n == 0) {
samefile = 0;
nextfile++;
+ len = 0;
return get_src_buf();
}
lexptr = buf + SLOP;
@@ -991,14 +1003,15 @@ tokexpand()
return token;
}
-#ifdef DEBUG
+#if DEBUG
char
nextc() {
if (lexptr && lexptr < lexend)
return *lexptr++;
- if (get_src_buf())
+ else if (get_src_buf())
return *lexptr++;
- return '\0';
+ else
+ return '\0';
}
#else
#define nextc() ((lexptr && lexptr < lexend) ? \
@@ -1071,7 +1084,7 @@ retry:
while ((c = nextc()) == ' ' || c == '\t')
;
- lexeme = lexptr-1;
+ lexeme = lexptr ? lexptr - 1 : lexptr;
thisline = NULL;
token = tokstart;
yylval.nodetypeval = Node_illegal;
@@ -1094,7 +1107,7 @@ retry:
case '\\':
#ifdef RELAXED_CONTINUATION
- if (!strict) { /* strip trailing white-space and/or comment */
+ if (!do_unix) { /* strip trailing white-space and/or comment */
while ((c = nextc()) == ' ' || c == '\t') continue;
if (c == '#')
while ((c = nextc()) != '\n') if (!c) break;
@@ -1458,7 +1471,7 @@ retry:
warning("%s is not supported in old awk",
tokentab[mid].operator);
}
- if ((strict && (tokentab[mid].flags & GAWKX))
+ if ((do_unix && (tokentab[mid].flags & GAWKX))
|| (do_posix && (tokentab[mid].flags & NOT_POSIX)))
break;
if (tokentab[mid].class == LEX_BUILTIN
@@ -1639,6 +1652,7 @@ NODE *value;
hp->hlength = len;
hp->hvalue = value;
hp->hname = name;
+ hp->hvalue->vname = name;
return hp->hvalue;
}
diff --git a/awktab.c b/awktab.c
index 0eb809a1..74b46822 100644
--- a/awktab.c
+++ b/awktab.c
@@ -1,5 +1,48 @@
-# line 27 "awk.y"
+/* A Bison parser, made from awk.y */
+
+#define YYBISON 1 /* Identify Bison output. */
+
+#define FUNC_CALL 258
+#define NAME 259
+#define REGEXP 260
+#define ERROR 261
+#define YNUMBER 262
+#define YSTRING 263
+#define RELOP 264
+#define APPEND_OP 265
+#define ASSIGNOP 266
+#define MATCHOP 267
+#define NEWLINE 268
+#define CONCAT_OP 269
+#define LEX_BEGIN 270
+#define LEX_END 271
+#define LEX_IF 272
+#define LEX_ELSE 273
+#define LEX_RETURN 274
+#define LEX_DELETE 275
+#define LEX_WHILE 276
+#define LEX_DO 277
+#define LEX_FOR 278
+#define LEX_BREAK 279
+#define LEX_CONTINUE 280
+#define LEX_PRINT 281
+#define LEX_PRINTF 282
+#define LEX_NEXT 283
+#define LEX_EXIT 284
+#define LEX_FUNCTION 285
+#define LEX_GETLINE 286
+#define LEX_IN 287
+#define LEX_AND 288
+#define LEX_OR 289
+#define INCREMENT 290
+#define DECREMENT 291
+#define LEX_BUILTIN 292
+#define LEX_LENGTH 293
+#define UNARY 294
+
+#line 26 "awk.y"
+
#ifdef DEBUG
#define YYDEBUG 12
#endif
@@ -42,14 +85,14 @@ NODE *variables[HASHSIZE];
extern char *source;
extern int sourceline;
-extern char *cmdline_src;
-extern char **srcfiles;
+extern struct src *srcfiles;
+extern int numfiles;
extern int errcount;
extern NODE *begin_block;
extern NODE *end_block;
-# line 76 "awk.y"
-typedef union {
+#line 73 "awk.y"
+typedef union {
long lval;
AWKNUM fval;
NODE *nodeval;
@@ -57,54 +100,2089 @@ typedef union {
char *sval;
NODE *(*ptrval)();
} YYSTYPE;
-# define FUNC_CALL 257
-# define NAME 258
-# define REGEXP 259
-# define ERROR 260
-# define YNUMBER 261
-# define YSTRING 262
-# define RELOP 263
-# define APPEND_OP 264
-# define ASSIGNOP 265
-# define MATCHOP 266
-# define NEWLINE 267
-# define CONCAT_OP 268
-# define LEX_BEGIN 269
-# define LEX_END 270
-# define LEX_IF 271
-# define LEX_ELSE 272
-# define LEX_RETURN 273
-# define LEX_DELETE 274
-# define LEX_WHILE 275
-# define LEX_DO 276
-# define LEX_FOR 277
-# define LEX_BREAK 278
-# define LEX_CONTINUE 279
-# define LEX_PRINT 280
-# define LEX_PRINTF 281
-# define LEX_NEXT 282
-# define LEX_EXIT 283
-# define LEX_FUNCTION 284
-# define LEX_GETLINE 285
-# define LEX_IN 286
-# define LEX_AND 287
-# define LEX_OR 288
-# define INCREMENT 289
-# define DECREMENT 290
-# define LEX_BUILTIN 291
-# define LEX_LENGTH 292
-# define UNARY 293
-#define yyclearin yychar = -1
-#define yyerrok yyerrflag = 0
-extern int yychar;
-extern int yyerrflag;
+
+#ifndef YYLTYPE
+typedef
+ struct yyltype
+ {
+ int timestamp;
+ int first_line;
+ int first_column;
+ int last_line;
+ int last_column;
+ char *text;
+ }
+ yyltype;
+
+#define YYLTYPE yyltype
+#endif
+
+#include <stdio.h>
+
+#ifndef __STDC__
+#define const
+#endif
+
+
+
+#define YYFINAL 306
+#define YYFLAG -32768
+#define YYNTBASE 61
+
+#define YYTRANSLATE(x) ((unsigned)(x) <= 294 ? yytranslate[x] : 106)
+
+static const char yytranslate[] = { 0,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 49, 2, 2, 52, 48, 2, 2, 53,
+ 54, 46, 44, 60, 45, 2, 47, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 40, 59, 41,
+ 2, 42, 39, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 55, 2, 56, 51, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 57, 43, 58, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
+ 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 50
+};
+
+#if YYDEBUG != 0
+static const short yyprhs[] = { 0,
+ 0, 4, 6, 9, 11, 14, 15, 19, 20, 24,
+ 27, 30, 33, 35, 38, 41, 43, 45, 47, 49,
+ 51, 52, 60, 65, 67, 71, 72, 77, 83, 88,
+ 90, 93, 95, 98, 100, 103, 106, 109, 113, 115,
+ 122, 131, 140, 151, 161, 164, 167, 174, 179, 183,
+ 187, 188, 193, 200, 203, 205, 207, 214, 224, 226,
+ 229, 230, 232, 233, 236, 237, 240, 243, 246, 247,
+ 249, 251, 255, 257, 260, 264, 265, 267, 268, 270,
+ 272, 276, 278, 281, 285, 289, 290, 292, 294, 298,
+ 300, 303, 307, 311, 312, 317, 323, 328, 332, 336,
+ 340, 344, 346, 349, 353, 357, 361, 365, 371, 373,
+ 376, 377, 382, 386, 390, 394, 396, 399, 403, 407,
+ 411, 417, 419, 422, 424, 428, 432, 436, 440, 444,
+ 448, 451, 454, 457, 461, 466, 471, 473, 478, 480,
+ 483, 486, 488, 490, 493, 496, 497, 499, 501, 506,
+ 509, 512, 515, 517, 518, 520, 522
+};
+
+#endif
+
+static const short yyrhs[] = { 82,
+ 62, 82, 0, 63, 0, 62, 63, 0, 1, 0,
+ 62, 1, 0, 0, 15, 64, 74, 0, 0, 16,
+ 65, 74, 0, 15, 76, 0, 16, 76, 0, 71,
+ 74, 0, 74, 0, 71, 76, 0, 68, 70, 0,
+ 4, 0, 3, 0, 67, 0, 37, 0, 38, 0,
+ 0, 30, 69, 66, 53, 85, 102, 82, 0, 100,
+ 75, 101, 103, 0, 92, 0, 92, 105, 92, 0,
+ 0, 47, 73, 5, 47, 0, 100, 75, 101, 103,
+ 82, 0, 100, 101, 103, 82, 0, 77, 0, 75,
+ 77, 0, 1, 0, 75, 1, 0, 81, 0, 104,
+ 82, 0, 104, 82, 0, 100, 101, 0, 100, 75,
+ 101, 0, 80, 0, 21, 53, 92, 102, 82, 77,
+ 0, 22, 82, 77, 21, 53, 92, 102, 82, 0,
+ 23, 53, 4, 32, 4, 102, 82, 77, 0, 23,
+ 53, 87, 104, 92, 104, 87, 102, 82, 77, 0,
+ 23, 53, 87, 104, 104, 87, 102, 82, 77, 0,
+ 24, 76, 0, 25, 76, 0, 79, 53, 91, 102,
+ 84, 76, 0, 79, 88, 84, 76, 0, 28, 87,
+ 76, 0, 29, 87, 76, 0, 0, 19, 78, 87,
+ 76, 0, 20, 4, 55, 91, 56, 76, 0, 92,
+ 76, 0, 26, 0, 27, 0, 17, 53, 92, 102,
+ 82, 77, 0, 17, 53, 92, 102, 82, 77, 18,
+ 82, 77, 0, 13, 0, 81, 13, 0, 0, 81,
+ 0, 0, 41, 96, 0, 0, 42, 92, 0, 10,
+ 92, 0, 43, 92, 0, 0, 86, 0, 4, 0,
+ 86, 105, 4, 0, 1, 0, 86, 1, 0, 86,
+ 105, 1, 0, 0, 92, 0, 0, 89, 0, 94,
+ 0, 89, 105, 94, 0, 1, 0, 89, 1, 0,
+ 89, 1, 94, 0, 89, 105, 1, 0, 0, 91,
+ 0, 92, 0, 91, 105, 92, 0, 1, 0, 91,
+ 1, 0, 91, 1, 92, 0, 91, 105, 1, 0,
+ 0, 99, 11, 93, 92, 0, 53, 91, 102, 32,
+ 4, 0, 92, 43, 31, 98, 0, 31, 98, 83,
+ 0, 92, 33, 92, 0, 92, 34, 92, 0, 92,
+ 12, 92, 0, 72, 0, 49, 72, 0, 92, 32,
+ 4, 0, 92, 9, 92, 0, 92, 41, 92, 0,
+ 92, 42, 92, 0, 92, 39, 92, 40, 92, 0,
+ 96, 0, 92, 96, 0, 0, 99, 11, 95, 94,
+ 0, 94, 33, 94, 0, 94, 34, 94, 0, 31,
+ 98, 83, 0, 72, 0, 49, 72, 0, 94, 12,
+ 94, 0, 94, 32, 4, 0, 94, 9, 94, 0,
+ 94, 39, 94, 40, 94, 0, 96, 0, 94, 96,
+ 0, 97, 0, 96, 51, 96, 0, 96, 46, 96,
+ 0, 96, 47, 96, 0, 96, 48, 96, 0, 96,
+ 44, 96, 0, 96, 45, 96, 0, 99, 35, 0,
+ 99, 36, 0, 49, 96, 0, 53, 92, 102, 0,
+ 37, 53, 90, 102, 0, 38, 53, 90, 102, 0,
+ 38, 0, 3, 53, 90, 102, 0, 99, 0, 35,
+ 99, 0, 36, 99, 0, 7, 0, 8, 0, 45,
+ 96, 0, 44, 96, 0, 0, 99, 0, 4, 0,
+ 4, 55, 91, 56, 0, 52, 97, 0, 57, 82,
+ 0, 58, 82, 0, 54, 0, 0, 104, 0, 59,
+ 0, 60, 82, 0
+};
+
+#if YYDEBUG != 0
+static const short yyrline[] = { 0,
+ 133, 138, 146, 162, 163, 167, 169, 183, 185, 199,
+ 205, 211, 213, 215, 228, 237, 239, 241, 251, 252,
+ 256, 260, 268, 277, 279, 288, 290, 308, 310, 315,
+ 317, 325, 327, 332, 333, 337, 339, 341, 343, 345,
+ 347, 349, 354, 358, 363, 366, 369, 371, 382, 400,
+ 402, 404, 406, 408, 413, 415, 420, 425, 432, 434,
+ 438, 439, 443, 445, 450, 452, 454, 456, 461, 463,
+ 468, 470, 472, 474, 476, 482, 484, 489, 491, 496,
+ 498, 504, 506, 508, 510, 515, 517, 522, 524, 530,
+ 532, 534, 536, 541, 544, 549, 551, 556, 562, 564,
+ 566, 572, 574, 582, 584, 590, 592, 594, 596, 598,
+ 603, 606, 607, 609, 611, 617, 619, 621, 623, 625,
+ 627, 629, 631, 636, 638, 640, 642, 644, 646, 648,
+ 650, 652, 657, 659, 661, 664, 666, 674, 678, 679,
+ 681, 683, 685, 688, 695, 700, 702, 707, 709, 717,
+ 722, 726, 730, 734, 735, 739, 742
+};
+
+static const char * const yytname[] = { "$","error","$illegal.","FUNC_CALL",
+"NAME","REGEXP","ERROR","YNUMBER","YSTRING","RELOP","APPEND_OP","ASSIGNOP","MATCHOP",
+"NEWLINE","CONCAT_OP","LEX_BEGIN","LEX_END","LEX_IF","LEX_ELSE","LEX_RETURN",
+"LEX_DELETE","LEX_WHILE","LEX_DO","LEX_FOR","LEX_BREAK","LEX_CONTINUE","LEX_PRINT",
+"LEX_PRINTF","LEX_NEXT","LEX_EXIT","LEX_FUNCTION","LEX_GETLINE","LEX_IN","LEX_AND",
+"LEX_OR","INCREMENT","DECREMENT","LEX_BUILTIN","LEX_LENGTH","'?'","':'","'<'",
+"'>'","'|'","'+'","'-'","'*'","'/'","'%'","'!'","UNARY","'^'","'$'","'('","')'",
+"'['","']'","'{'","'}'","';'","','","start","program","rule","@1","@2","func_name",
+"lex_builtin","function_prologue","@3","function_body","pattern","regexp","@4",
+"action","statements","statement_term","statement","@5","print","if_statement",
+"nls","opt_nls","input_redir","output_redir","opt_param_list","param_list","opt_exp",
+"opt_rexpression_list","rexpression_list","opt_expression_list","expression_list",
+"exp","@6","rexp","@7","simp_exp","non_post_simp_exp","opt_variable","variable",
+"l_brace","r_brace","r_paren","opt_semi","semi","comma",""
+};
+#endif
+
+static const short yyr1[] = { 0,
+ 61, 62, 62, 62, 62, 64, 63, 65, 63, 63,
+ 63, 63, 63, 63, 63, 66, 66, 66, 67, 67,
+ 69, 68, 70, 71, 71, 73, 72, 74, 74, 75,
+ 75, 75, 75, 76, 76, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 78, 77, 77, 77, 79, 79, 80, 80, 81, 81,
+ 82, 82, 83, 83, 84, 84, 84, 84, 85, 85,
+ 86, 86, 86, 86, 86, 87, 87, 88, 88, 89,
+ 89, 89, 89, 89, 89, 90, 90, 91, 91, 91,
+ 91, 91, 91, 93, 92, 92, 92, 92, 92, 92,
+ 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
+ 95, 94, 94, 94, 94, 94, 94, 94, 94, 94,
+ 94, 94, 94, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 97, 97, 97, 97, 97, 97, 97, 97,
+ 97, 97, 97, 97, 97, 98, 98, 99, 99, 99,
+ 100, 101, 102, 103, 103, 104, 105
+};
+
+static const short yyr2[] = { 0,
+ 3, 1, 2, 1, 2, 0, 3, 0, 3, 2,
+ 2, 2, 1, 2, 2, 1, 1, 1, 1, 1,
+ 0, 7, 4, 1, 3, 0, 4, 5, 4, 1,
+ 2, 1, 2, 1, 2, 2, 2, 3, 1, 6,
+ 8, 8, 10, 9, 2, 2, 6, 4, 3, 3,
+ 0, 4, 6, 2, 1, 1, 6, 9, 1, 2,
+ 0, 1, 0, 2, 0, 2, 2, 2, 0, 1,
+ 1, 3, 1, 2, 3, 0, 1, 0, 1, 1,
+ 3, 1, 2, 3, 3, 0, 1, 1, 3, 1,
+ 2, 3, 3, 0, 4, 5, 4, 3, 3, 3,
+ 3, 1, 2, 3, 3, 3, 3, 5, 1, 2,
+ 0, 4, 3, 3, 3, 1, 2, 3, 3, 3,
+ 5, 1, 2, 1, 3, 3, 3, 3, 3, 3,
+ 2, 2, 2, 3, 4, 4, 1, 4, 1, 2,
+ 2, 1, 1, 2, 2, 0, 1, 1, 4, 2,
+ 2, 2, 1, 0, 1, 1, 2
+};
+
+static const short yydefact[] = { 61,
+ 59, 62, 0, 60, 4, 0, 148, 142, 143, 6,
+ 8, 21, 146, 0, 0, 0, 137, 0, 0, 26,
+ 0, 0, 0, 61, 0, 2, 0, 0, 102, 13,
+ 24, 109, 124, 139, 0, 0, 0, 156, 0, 10,
+ 34, 61, 0, 11, 0, 63, 147, 140, 141, 0,
+ 0, 0, 0, 145, 139, 144, 0, 103, 133, 150,
+ 139, 90, 0, 88, 151, 5, 3, 1, 15, 0,
+ 12, 14, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 61, 110, 0, 0, 0, 0, 0, 0, 0,
+ 94, 131, 132, 32, 0, 51, 0, 0, 61, 0,
+ 0, 0, 55, 56, 76, 76, 61, 0, 30, 0,
+ 39, 0, 0, 154, 61, 0, 0, 88, 0, 7,
+ 35, 9, 17, 16, 19, 20, 0, 18, 0, 98,
+ 0, 0, 0, 0, 91, 153, 0, 0, 134, 0,
+ 105, 101, 104, 99, 100, 0, 106, 107, 146, 157,
+ 25, 129, 130, 126, 127, 128, 125, 0, 0, 76,
+ 0, 0, 0, 76, 45, 46, 0, 77, 0, 152,
+ 33, 31, 154, 82, 146, 0, 0, 116, 65, 0,
+ 80, 122, 139, 54, 0, 37, 61, 155, 36, 138,
+ 149, 0, 64, 135, 136, 27, 92, 0, 93, 89,
+ 154, 0, 97, 95, 0, 0, 0, 0, 0, 148,
+ 0, 49, 50, 61, 63, 117, 0, 0, 0, 0,
+ 0, 83, 0, 0, 0, 0, 0, 0, 0, 123,
+ 111, 38, 29, 73, 71, 0, 0, 96, 23, 108,
+ 61, 52, 0, 61, 0, 0, 0, 28, 115, 65,
+ 67, 66, 68, 48, 84, 85, 81, 120, 118, 119,
+ 113, 114, 0, 0, 61, 74, 0, 0, 0, 0,
+ 0, 0, 0, 76, 0, 0, 112, 22, 75, 72,
+ 57, 53, 40, 0, 61, 76, 0, 47, 121, 61,
+ 61, 0, 0, 61, 0, 41, 42, 61, 0, 58,
+ 0, 44, 43, 0, 0, 0
+};
+
+static const short yydefgoto[] = { 304,
+ 25, 26, 39, 43, 127, 128, 27, 45, 69, 28,
+ 29, 57, 30, 108, 40, 109, 160, 110, 111, 2,
+ 3, 130, 221, 236, 237, 167, 179, 180, 116, 117,
+ 112, 158, 181, 264, 32, 33, 46, 34, 113, 114,
+ 139, 187, 115, 138
+};
+
+static const short yypact[] = { -6,
+-32768, 8, 1094,-32768,-32768, -26, -11,-32768,-32768, -1,
+ -1,-32768, 1, 1, 1, 16, 31, 1738, 1738,-32768,
+ 1691, 1738, 1186, -6, 890,-32768, -5, -2,-32768,-32768,
+ 836, 69,-32768, 83, 612, 1166, 1186,-32768, -5,-32768,
+ 8, -6, -5,-32768, 101, 20,-32768,-32768,-32768, 1166,
+ 1166, 1738, 1606, 36, 2, 36, 62,-32768, 36,-32768,
+-32768,-32768, 5, 1299,-32768,-32768,-32768,-32768,-32768, 726,
+-32768,-32768, 1606, 1606, 93, 1606, 1606, 1606, 1606, 1606,
+ 70, -6, 69, 1606, 1738, 1738, 1738, 1738, 1738, 1738,
+-32768,-32768,-32768,-32768, 54,-32768, 105, 58, -6, 68,
+ -1, -1,-32768,-32768, 1606, 1606, -6, 679,-32768, 783,
+-32768, 994, 612, 78, -6, 86, 18, 1398, 23,-32768,
+-32768,-32768,-32768,-32768,-32768,-32768, 90,-32768, 1738,-32768,
+ 86, 86, 1299, 97, 1606,-32768, 104, 1233,-32768, 679,
+ 1373, 1753,-32768, 1506, 1445, 1351, 1373, 1373, 1,-32768,
+ 1398, 130, 130, 36, 36, 36, 36, 1606, 1606, 1606,
+ 92, 1606, 937, 1625,-32768,-32768, -1, 1398, -1,-32768,
+-32768,-32768, 78,-32768, 1, 1691, 1186,-32768, 0, 3,
+ 1528, 69, 89,-32768, 679,-32768, -6,-32768,-32768,-32768,
+-32768, 14, 69,-32768,-32768,-32768, 1398, 144,-32768, 1398,
+ 78, 1606,-32768, 1398, 1299, -1, 1186, 1299, 131, -15,
+ 78,-32768,-32768, -6, 20,-32768, 5, 1606, 1606, 1606,
+ -1, 1672, 1252, 1672, 1672, 147, 1672, 1672, 1672, 69,
+-32768,-32768,-32768,-32768,-32768, 86, 28,-32768,-32768, 1398,
+ -6,-32768, 29, -6, 100, 150, 1119,-32768,-32768, 0,
+ 1398, 1398, 1398,-32768, 1528,-32768, 1528, 802, 1013,-32768,
+ 1586, 1567, 1467, 1672, -6,-32768, 35, 937, -1, 937,
+ 1606, 86, 1047, 1606, -1, 1672, 1528,-32768,-32768,-32768,
+ 140,-32768,-32768, 1299, -6, 1606, 86,-32768, 1528, -6,
+ -6, 937, 86, -6, 937,-32768,-32768, -6, 937,-32768,
+ 937,-32768,-32768, 160, 172,-32768
+};
+
+static const short yypgoto[] = {-32768,
+-32768, 148,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
+ 91,-32768, 106, -47, 82, -99,-32768,-32768,-32768, 21,
+ 155, -40, -65,-32768,-32768, -104,-32768,-32768, 76, -9,
+ -3,-32768, 11,-32768, 325, 164, -124, 77, 103, -105,
+ 247, -147, 406, -30
+};
+
+
+#define YYLAST 1806
+
+
+static const short yytable[] = { 31,
+ 84, 169, 173, 222, 7, 135, 1, 186, 172, 218,
+ 1, 1, -79, 63, 234, -79, 246, 235, 135, 64,
+ 4, 31, 140, 135, 203, 214, 36, 119, 266, 135,
+ 41, 41, 118, 118, 201, 279, 92, 93, 280, 37,
+ 172, 219, 220, 37, -79, -79, 118, 118, 41, 133,
+ 215, 24, 22, 239, 24, 206, 38, 38, 136, 211,
+ 129, -79, 82, 209, 82, 185, 134, -69, 50, 141,
+ 142, -87, 144, 145, 146, 147, 148, 82, 191, 232,
+ 151, -70, 82, 51, 269, 172, 90, 82, 82, 47,
+ 48, 49, 44, 91, 55, 55, 143, 55, 61, 231,
+ 149, 168, 168, 123, 124, 35, 159, 55, 161, 72,
+ 162, 58, 85, 86, 87, 88, 89, 92, 93, 90,
+ 164, 41, 41, 92, 93, 131, 132, 35, 55, 70,
+ 35, 197, 41, 71, 200, 198, 38, 125, 126, 136,
+ 55, 35, 192, 196, 120, 35, 207, 238, 122, 223,
+ 260, 245, 271, 272, 204, 205, 168, 290, 208, 305,
+ 168, 55, 55, 55, 55, 55, 55, 217, 281, 287,
+ 283, 306, 67, 64, 249, 87, 88, 89, 65, 68,
+ 90, 293, 165, 166, 275, 60, 183, 41, 55, 41,
+ 0, 0, 297, 184, 55, 300, 121, 243, 240, 302,
+ 178, 303, 0, 118, 0, 55, 267, 0, 0, 55,
+ 0, 0, 0, 0, 251, 252, 253, 55, 55, 0,
+ 55, 55, 55, 55, 55, 47, 41, 55, 0, 0,
+ 0, 0, 255, 257, 258, 259, 150, 261, 262, 263,
+ 0, 41, 0, 273, 55, 0, 0, 0, 212, 0,
+ 213, 47, 55, 163, 0, 0, 0, 55, 0, 0,
+ 0, 170, 0, 0, 0, 0, 216, 284, 0, 189,
+ 168, 0, 0, 55, 277, 0, 55, 0, 0, 0,
+ 55, 55, 168, 0, 55, 0, 289, 242, 0, 41,
+ 0, 0, 0, 0, 0, 41, 0, 0, 183, 183,
+ 183, 183, 254, 183, 183, 183, 0, 0, 0, 137,
+ 0, 0, 178, 178, 178, 178, 55, 178, 178, 178,
+ 0, 0, 0, 0, 0, 0, 0, 55, 55, 55,
+ 0, 55, 0, 55, 55, 55, 0, 55, 55, 55,
+ 183, 233, 54, 56, 0, 59, 0, 0, 0, 55,
+ 282, 0, 183, 55, 178, 83, 288, 0, 0, 0,
+ 55, 0, 190, 0, 0, 55, 178, 0, 248, 0,
+ 0, 0, 0, 0, 0, 0, 59, 194, 195, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 83, 0,
+ 0, 0, 0, 0, 0, 268, 0, 0, 270, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 152,
+ 153, 154, 155, 156, 157, 42, 42, 0, 0, 278,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 42, 182, 0, 83, 0, 0, 292,
+ 0, 0, 83, 0, 295, 296, 0, 0, 299, 0,
+ 0, 241, 301, 193, 244, 0, 0, 83, 0, 0,
+ 0, 0, 0, 250, 0, 83, 83, 0, 83, 83,
+ 83, 83, 83, 0, 0, 83, 0, 0, 0, 0,
+ 0, 0, 265, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 83, 0, 0, 0, 0, 0, 0, 0,
+ 59, 0, 0, 0, 0, 230, 42, 42, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 42, 285, 188,
+ 0, 83, 0, 0, 83, 0, 0, 0, 83, 83,
+ 291, 0, 83, 294, 0, 0, 0, 0, 0, 298,
+ 0, 0, 0, 0, 0, 0, 182, 182, 182, 182,
+ 0, 182, 182, 182, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 83, 0, 0, 0, 0, 0,
+ 0, 0, 42, 0, 42, 83, 83, 83, 188, 230,
+ 0, 230, 230, 230, 0, 230, 230, 230, 182, 0,
+ 0, 0, 0, 0, 0, 0, 0, 83, 0, 0,
+ 182, 230, 0, 0, 0, 0, 188, 0, 83, 0,
+ 0, 42, 94, 230, 6, 7, 247, 0, 8, 9,
+ 0, 0, 0, 0, 0, 0, 42, 0, 95, 0,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
+ 106, 0, 13, 0, 0, 0, 14, 15, 16, 17,
+ 0, 0, 274, 0, 0, 18, 19, 0, 20, 0,
+ 21, 0, 0, 22, 23, 0, 0, 0, 24, 107,
+ 38, 0, 0, 0, 42, 0, 0, 0, 286, 171,
+ 42, 6, 7, 0, 0, 8, 9, 0, 0, 0,
+ 0, 0, 0, 0, 0, 95, 0, 96, 97, 98,
+ 99, 100, 101, 102, 103, 104, 105, 106, 0, 13,
+ 0, 0, 0, 14, 15, 16, 17, 0, 0, 0,
+ 0, 0, 18, 19, 0, 20, 94, 21, 6, 7,
+ 22, 23, 8, 9, 0, 24, 107, 38, 0, 0,
+ 0, 0, 95, 0, 96, 97, 98, 99, 100, 101,
+ 102, 103, 104, 105, 106, 0, 13, 0, 0, 0,
+ 14, 15, 16, 17, 0, 0, 0, 0, 0, 18,
+ 19, 0, 20, 0, 21, 0, 0, 22, 23, 0,
+ 0, 0, 24, 174, 38, 6, 7, 0, 0, 8,
+ 9, 0, -78, 0, 0, -78, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 7, 0, 0, 8, 9,
+-32768, 0, 0, 175, 0, 0, 0, 14, 15, 16,
+ 17, 0, 0, 0, -78, -78, 18, 19, 0, 20,
+ 0, 176, 0, 0, 22, 177, 14, 15, 6, 7,
+ 0, -78, 8, 9, 73, 18, 19, 74, 0, 0,
+ 52, 0, 0, 22, 53, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 75, 76, 77,
+ 14, 15, 16, 17, 78, 0, 79, 80, 81, 18,
+ 19, 0, 0, 0, 52, 0, 0, 22, 53, -61,
+ 66, 0, 6, 7, 0, 82, 8, 9, 0, 0,
+ 0, 0, 1, 0, 10, 11, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 12,
+ 13, 0, 0, 0, 14, 15, 16, 17, 0, 0,
+ 0, 0, 0, 18, 19, 0, 20, 0, 21, 6,
+ 7, 22, 23, 8, 9, 0, 24, 0, 0, 0,
+ 0, 0, 0, 95, 0, 96, 97, 98, 99, 100,
+ 101, 102, 103, 104, 105, 106, 0, 13, 0, 0,
+ 0, 14, 15, 16, 17, 0, 0, 0, 0, 0,
+ 18, 19, 0, 20, 0, 21, 0, 0, 22, 23,
+ 0, 0, 0, 24, 0, 38, 6, 7, 0, 0,
+ 8, 9, 73, 0, 0, 74, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 7, 0, 0, 8,
+ 9, 224, 0, 0,-32768, 75, 76, 77, 14, 15,
+ 16, 17, 78, 0, 79, 80, 81, 18, 19, 0,
+ 0, 0, 52, 0, 0, 22, 53, 14, 15, 6,
+ 7, 0, 38, 8, 9, 73, 18, 19, 74, 0,
+ 0, 52, 0, 0, 22, 53, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 75, 76,
+ 77, 14, 15, 16, 17, 78, 0, 79, 80, 81,
+ 18, 19, 0, 0, 5, 52, 6, 7, 22, 53,
+ 8, 9, 0, 0, 0, 38, 0, 0, 10, 11,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 6, 7, 12, 13, 8, 9, 0, 14, 15,
+ 16, 17, 0, 0, 0, 0, 0, 18, 19, 0,
+ 20, 0, 21, 0, 0, 22, 23, 0, 0, 13,
+ 24, 0, 0, 14, 15, 16, 17, 0, 0, 0,
+ 0, 0, 18, 19, 0, 20, 62, 21, 6, 7,
+ 22, 23, 8, 9, 0, 0, 0, 38, 0, 0,
+ 0, 0, 0, 0, 0, 0, 62, 0, 6, 7,
+ 0, 0, 8, 9, 0, 0, 13, 0, 0, 0,
+ 14, 15, 16, 17, 0, 0, 0, 0, 0, 18,
+ 19, 0, 20, 0, 21, 0, 13, 22, 23, -86,
+ 14, 15, 16, 17, 0, 0, 0, 0, 0, 18,
+ 19, 0, 20, 199, 21, 6, 7, 22, 23, 8,
+ 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 256, 0, 6, 7, 0, 0, 8, 9,
+ 0, 0, 0, 13, 0, 0, 0, 14, 15, 16,
+ 17, 0, 0, 0, 0, 0, 18, 19, 0, 20,
+ 0, 21, 175, 0, 22, 23, 14, 15, 16, 17,
+ 0, 0, 0, 0, 0, 18, 19, 0, 20, 0,
+ 176, 6, 7, 22, 53, 8, 9, 73, 0, 0,
+ 74, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 75, 76, 77, 14, 15, 16, 17, 78, 0, 79,
+ 80, 81, 18, 19, 0, 0, 0, 52, 0, 0,
+ 22, 53, 136, 6, 7, 0, 0, 8, 9, 73,
+ 0, 0, 74, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 7, 0, 0, 8,
+ 9,-32768, 75, 76, 77, 14, 15, 16, 17, 78,
+ 202, 79, 80, 81, 18, 19, 0, 0, 0, 52,
+ 6, 7, 22, 53, 8, 9, 73, 14, 15, 74,
+ 0, 0, 0,-32768,-32768,-32768, 18, 19, 0, 0,
+ 0, 52, 0, 0, 22, 53, 0, 0, 0, 75,
+ 76, 77, 14, 15, 16, 17, 78, 0, 79, 80,
+ 81, 18, 19, 0, 0, 0, 52, 6, 7, 22,
+ 53, 8, 9, 73, 0, 0, 74, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 6,
+ 7, 0, 0, 8, 9, 224, 75, 76, 225, 14,
+ 15, 16, 17, 0, 0, 79, 80, 81, 18, 19,
+ 0, 0, 0, 52, 0, 0, 22, 53, 226, 227,
+ 228, 14, 15, 16, 17, 229, 276, 0, 6, 7,
+ 18, 19, 8, 9, 73, 52, 0, 74, 22, 53,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 6, 7, 0, 0, 8, 9, 224, 75, 0, 225,
+ 14, 15, 16, 17, 0, 0, 79, 80, 81, 18,
+ 19, 0, 0, 0, 52, 0, 0, 22, 53, 226,
+ 227, 228, 14, 15, 16, 17, 229, 0, 0, 6,
+ 7, 18, 19, 8, 9, 224, 52, 0, 225, 22,
+ 53, 0, 0, 0, 0, 0, 0, 0, 6, 7,
+ 0, 0, 8, 9, 224, 0, 0, 225, 226, 227,
+ 0, 14, 15, 16, 17, 0, 0, 0, 6, 7,
+ 18, 19, 8, 9, 0, 52, 0, 226, 22, 53,
+ 14, 15, 16, 17, 0, 0, 0, 6, 210, 18,
+ 19, 8, 9, 0, 52, 0, 13, 22, 53, 0,
+ 14, 15, 16, 17, 0, 0, 0, 0, 0, 18,
+ 19, 0, 20, 0, 21, 13, 0, 22, 23, 14,
+ 15, 16, 17, 0, 0, 0, 0, 0, 18, 19,
+ 0, 20, 0, 21, 6, 7, 22, 23, 8, 9,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 6, 7, 0, 0, 8, 9, 0,
+ 0, 0, 175, 0, 0, 0, 14, 15, 16, 17,
+ 0, 0, 0, 0, 0, 18, 19, 0, 20, 0,
+ 176, 0, 0, 22, 53, 14, 15, 16, 17, 0,
+ 0, 0, 0, 0, 18, 19, 0, 20, 0, 52,
+ 6, 7, 22, 53, 8, 9, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 7, 0, 0, 8,
+ 9, 73, 0, 0,-32768, 0, 0, 0, 0, 0,
+ 0, 0, 14, 15, 16, 17, 0, 0, 0, 0,
+ 0, 18, 19, 0, 0, 0, 52, 14, 15, 22,
+ 53, 0, 0, 79, 80, 81, 18, 19, 0, 0,
+ 0, 52, 0, 0, 22, 53
+};
+
+static const short yycheck[] = { 3,
+ 31, 106, 108, 1, 4, 1, 13, 113, 108, 10,
+ 13, 13, 10, 23, 1, 13, 32, 4, 1, 23,
+ 13, 25, 70, 1, 149, 173, 53, 37, 1, 1,
+ 10, 11, 36, 37, 140, 1, 35, 36, 4, 55,
+ 140, 42, 43, 55, 42, 43, 50, 51, 28, 53,
+ 175, 57, 52, 201, 57, 160, 59, 59, 54, 164,
+ 41, 59, 60, 163, 60, 113, 5, 54, 53, 73,
+ 74, 54, 76, 77, 78, 79, 80, 60, 56, 185,
+ 84, 54, 60, 53, 56, 185, 51, 60, 60, 13,
+ 14, 15, 11, 11, 18, 19, 4, 21, 22, 11,
+ 31, 105, 106, 3, 4, 3, 53, 31, 4, 28,
+ 53, 21, 44, 45, 46, 47, 48, 35, 36, 51,
+ 53, 101, 102, 35, 36, 50, 51, 25, 52, 27,
+ 28, 135, 112, 28, 138, 32, 59, 37, 38, 54,
+ 64, 39, 53, 47, 39, 43, 55, 4, 43, 180,
+ 4, 21, 53, 4, 158, 159, 160, 18, 162, 0,
+ 164, 85, 86, 87, 88, 89, 90, 177, 268, 274,
+ 270, 0, 25, 177, 215, 46, 47, 48, 24, 25,
+ 51, 286, 101, 102, 250, 22, 110, 167, 112, 169,
+ -1, -1, 292, 112, 118, 295, 42, 207, 202, 299,
+ 110, 301, -1, 207, -1, 129, 237, -1, -1, 133,
+ -1, -1, -1, -1, 218, 219, 220, 141, 142, -1,
+ 144, 145, 146, 147, 148, 149, 206, 151, -1, -1,
+ -1, -1, 222, 223, 224, 225, 82, 227, 228, 229,
+ -1, 221, -1, 247, 168, -1, -1, -1, 167, -1,
+ 169, 175, 176, 99, -1, -1, -1, 181, -1, -1,
+ -1, 107, -1, -1, -1, -1, 176, 271, -1, 115,
+ 274, -1, -1, 197, 264, -1, 200, -1, -1, -1,
+ 204, 205, 286, -1, 208, -1, 276, 206, -1, 269,
+ -1, -1, -1, -1, -1, 275, -1, -1, 222, 223,
+ 224, 225, 221, 227, 228, 229, -1, -1, -1, 63,
+ -1, -1, 222, 223, 224, 225, 240, 227, 228, 229,
+ -1, -1, -1, -1, -1, -1, -1, 251, 252, 253,
+ -1, 255, -1, 257, 258, 259, -1, 261, 262, 263,
+ 264, 187, 18, 19, -1, 21, -1, -1, -1, 273,
+ 269, -1, 276, 277, 264, 31, 275, -1, -1, -1,
+ 284, -1, 116, -1, -1, 289, 276, -1, 214, -1,
+ -1, -1, -1, -1, -1, -1, 52, 131, 132, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 64, -1,
+ -1, -1, -1, -1, -1, 241, -1, -1, 244, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, 85,
+ 86, 87, 88, 89, 90, 10, 11, -1, -1, 265,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 28, 110, -1, 112, -1, -1, 285,
+ -1, -1, 118, -1, 290, 291, -1, -1, 294, -1,
+ -1, 205, 298, 129, 208, -1, -1, 133, -1, -1,
+ -1, -1, -1, 217, -1, 141, 142, -1, 144, 145,
+ 146, 147, 148, -1, -1, 151, -1, -1, -1, -1,
+ -1, -1, 236, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, 168, -1, -1, -1, -1, -1, -1, -1,
+ 176, -1, -1, -1, -1, 181, 101, 102, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, 112, 272, 114,
+ -1, 197, -1, -1, 200, -1, -1, -1, 204, 205,
+ 284, -1, 208, 287, -1, -1, -1, -1, -1, 293,
+ -1, -1, -1, -1, -1, -1, 222, 223, 224, 225,
+ -1, 227, 228, 229, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, 240, -1, -1, -1, -1, -1,
+ -1, -1, 167, -1, 169, 251, 252, 253, 173, 255,
+ -1, 257, 258, 259, -1, 261, 262, 263, 264, -1,
+ -1, -1, -1, -1, -1, -1, -1, 273, -1, -1,
+ 276, 277, -1, -1, -1, -1, 201, -1, 284, -1,
+ -1, 206, 1, 289, 3, 4, 211, -1, 7, 8,
+ -1, -1, -1, -1, -1, -1, 221, -1, 17, -1,
+ 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
+ 29, -1, 31, -1, -1, -1, 35, 36, 37, 38,
+ -1, -1, 247, -1, -1, 44, 45, -1, 47, -1,
+ 49, -1, -1, 52, 53, -1, -1, -1, 57, 58,
+ 59, -1, -1, -1, 269, -1, -1, -1, 273, 1,
+ 275, 3, 4, -1, -1, 7, 8, -1, -1, -1,
+ -1, -1, -1, -1, -1, 17, -1, 19, 20, 21,
+ 22, 23, 24, 25, 26, 27, 28, 29, -1, 31,
+ -1, -1, -1, 35, 36, 37, 38, -1, -1, -1,
+ -1, -1, 44, 45, -1, 47, 1, 49, 3, 4,
+ 52, 53, 7, 8, -1, 57, 58, 59, -1, -1,
+ -1, -1, 17, -1, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, -1, 31, -1, -1, -1,
+ 35, 36, 37, 38, -1, -1, -1, -1, -1, 44,
+ 45, -1, 47, -1, 49, -1, -1, 52, 53, -1,
+ -1, -1, 57, 1, 59, 3, 4, -1, -1, 7,
+ 8, -1, 10, -1, -1, 13, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 4, -1, -1, 7, 8,
+ 9, -1, -1, 31, -1, -1, -1, 35, 36, 37,
+ 38, -1, -1, -1, 42, 43, 44, 45, -1, 47,
+ -1, 49, -1, -1, 52, 53, 35, 36, 3, 4,
+ -1, 59, 7, 8, 9, 44, 45, 12, -1, -1,
+ 49, -1, -1, 52, 53, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, 32, 33, 34,
+ 35, 36, 37, 38, 39, -1, 41, 42, 43, 44,
+ 45, -1, -1, -1, 49, -1, -1, 52, 53, 0,
+ 1, -1, 3, 4, -1, 60, 7, 8, -1, -1,
+ -1, -1, 13, -1, 15, 16, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, 30,
+ 31, -1, -1, -1, 35, 36, 37, 38, -1, -1,
+ -1, -1, -1, 44, 45, -1, 47, -1, 49, 3,
+ 4, 52, 53, 7, 8, -1, 57, -1, -1, -1,
+ -1, -1, -1, 17, -1, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, -1, 31, -1, -1,
+ -1, 35, 36, 37, 38, -1, -1, -1, -1, -1,
+ 44, 45, -1, 47, -1, 49, -1, -1, 52, 53,
+ -1, -1, -1, 57, -1, 59, 3, 4, -1, -1,
+ 7, 8, 9, -1, -1, 12, 13, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, 4, -1, -1, 7,
+ 8, 9, -1, -1, 12, 32, 33, 34, 35, 36,
+ 37, 38, 39, -1, 41, 42, 43, 44, 45, -1,
+ -1, -1, 49, -1, -1, 52, 53, 35, 36, 3,
+ 4, -1, 59, 7, 8, 9, 44, 45, 12, -1,
+ -1, 49, -1, -1, 52, 53, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 32, 33,
+ 34, 35, 36, 37, 38, 39, -1, 41, 42, 43,
+ 44, 45, -1, -1, 1, 49, 3, 4, 52, 53,
+ 7, 8, -1, -1, -1, 59, -1, -1, 15, 16,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 3, 4, 30, 31, 7, 8, -1, 35, 36,
+ 37, 38, -1, -1, -1, -1, -1, 44, 45, -1,
+ 47, -1, 49, -1, -1, 52, 53, -1, -1, 31,
+ 57, -1, -1, 35, 36, 37, 38, -1, -1, -1,
+ -1, -1, 44, 45, -1, 47, 1, 49, 3, 4,
+ 52, 53, 7, 8, -1, -1, -1, 59, -1, -1,
+ -1, -1, -1, -1, -1, -1, 1, -1, 3, 4,
+ -1, -1, 7, 8, -1, -1, 31, -1, -1, -1,
+ 35, 36, 37, 38, -1, -1, -1, -1, -1, 44,
+ 45, -1, 47, -1, 49, -1, 31, 52, 53, 54,
+ 35, 36, 37, 38, -1, -1, -1, -1, -1, 44,
+ 45, -1, 47, 1, 49, 3, 4, 52, 53, 7,
+ 8, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, 1, -1, 3, 4, -1, -1, 7, 8,
+ -1, -1, -1, 31, -1, -1, -1, 35, 36, 37,
+ 38, -1, -1, -1, -1, -1, 44, 45, -1, 47,
+ -1, 49, 31, -1, 52, 53, 35, 36, 37, 38,
+ -1, -1, -1, -1, -1, 44, 45, -1, 47, -1,
+ 49, 3, 4, 52, 53, 7, 8, 9, -1, -1,
+ 12, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 32, 33, 34, 35, 36, 37, 38, 39, -1, 41,
+ 42, 43, 44, 45, -1, -1, -1, 49, -1, -1,
+ 52, 53, 54, 3, 4, -1, -1, 7, 8, 9,
+ -1, -1, 12, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, 4, -1, -1, 7,
+ 8, 9, 32, 33, 34, 35, 36, 37, 38, 39,
+ 40, 41, 42, 43, 44, 45, -1, -1, -1, 49,
+ 3, 4, 52, 53, 7, 8, 9, 35, 36, 12,
+ -1, -1, -1, 41, 42, 43, 44, 45, -1, -1,
+ -1, 49, -1, -1, 52, 53, -1, -1, -1, 32,
+ 33, 34, 35, 36, 37, 38, 39, -1, 41, 42,
+ 43, 44, 45, -1, -1, -1, 49, 3, 4, 52,
+ 53, 7, 8, 9, -1, -1, 12, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, 3,
+ 4, -1, -1, 7, 8, 9, 32, 33, 12, 35,
+ 36, 37, 38, -1, -1, 41, 42, 43, 44, 45,
+ -1, -1, -1, 49, -1, -1, 52, 53, 32, 33,
+ 34, 35, 36, 37, 38, 39, 40, -1, 3, 4,
+ 44, 45, 7, 8, 9, 49, -1, 12, 52, 53,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 3, 4, -1, -1, 7, 8, 9, 32, -1, 12,
+ 35, 36, 37, 38, -1, -1, 41, 42, 43, 44,
+ 45, -1, -1, -1, 49, -1, -1, 52, 53, 32,
+ 33, 34, 35, 36, 37, 38, 39, -1, -1, 3,
+ 4, 44, 45, 7, 8, 9, 49, -1, 12, 52,
+ 53, -1, -1, -1, -1, -1, -1, -1, 3, 4,
+ -1, -1, 7, 8, 9, -1, -1, 12, 32, 33,
+ -1, 35, 36, 37, 38, -1, -1, -1, 3, 4,
+ 44, 45, 7, 8, -1, 49, -1, 32, 52, 53,
+ 35, 36, 37, 38, -1, -1, -1, 3, 4, 44,
+ 45, 7, 8, -1, 49, -1, 31, 52, 53, -1,
+ 35, 36, 37, 38, -1, -1, -1, -1, -1, 44,
+ 45, -1, 47, -1, 49, 31, -1, 52, 53, 35,
+ 36, 37, 38, -1, -1, -1, -1, -1, 44, 45,
+ -1, 47, -1, 49, 3, 4, 52, 53, 7, 8,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 3, 4, -1, -1, 7, 8, -1,
+ -1, -1, 31, -1, -1, -1, 35, 36, 37, 38,
+ -1, -1, -1, -1, -1, 44, 45, -1, 47, -1,
+ 49, -1, -1, 52, 53, 35, 36, 37, 38, -1,
+ -1, -1, -1, -1, 44, 45, -1, 47, -1, 49,
+ 3, 4, 52, 53, 7, 8, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, 4, -1, -1, 7,
+ 8, 9, -1, -1, 12, -1, -1, -1, -1, -1,
+ -1, -1, 35, 36, 37, 38, -1, -1, -1, -1,
+ -1, 44, 45, -1, -1, -1, 49, 35, 36, 52,
+ 53, -1, -1, 41, 42, 43, 44, 45, -1, -1,
+ -1, 49, -1, -1, 52, 53
+};
+/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
+#line 3 "/local/lib/bison.simple"
+
+/* Skeleton output parser for bison,
+ Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 1, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+
+#ifndef alloca
+#ifdef __GNUC__
+#define alloca __builtin_alloca
+#else /* not GNU C. */
+#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc)
+#include <alloca.h>
+#else /* not sparc */
+#if defined (MSDOS) && !defined (__TURBOC__)
+#include <malloc.h>
+#else /* not MSDOS, or __TURBOC__ */
+#if defined(_AIX)
+#include <malloc.h>
+ #pragma alloca
+#endif /* not _AIX */
+#endif /* not MSDOS, or __TURBOC__ */
+#endif /* not sparc. */
+#endif /* not GNU C. */
+#endif /* alloca not defined. */
+
+/* This is the parser code that is written into each bison parser
+ when the %semantic_parser declaration is not specified in the grammar.
+ It was written by Richard Stallman by simplifying the hairy parser
+ used when %semantic_parser is specified. */
+
+/* Note: there must be only one dollar sign in this file.
+ It is replaced by the list of actions, each action
+ as one case of the switch. */
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY -2
+#define YYEOF 0
+#define YYACCEPT return(0)
+#define YYABORT return(1)
+#define YYERROR goto yyerrlab1
+/* Like YYERROR except do call yyerror.
+ This remains here temporarily to ease the
+ transition to the new meaning of YYERROR, for GCC.
+ Once GCC version 2 has supplanted version 1, this can go. */
+#define YYFAIL goto yyerrlab
+#define YYRECOVERING() (!!yyerrstatus)
+#define YYBACKUP(token, value) \
+do \
+ if (yychar == YYEMPTY && yylen == 1) \
+ { yychar = (token), yylval = (value); \
+ yychar1 = YYTRANSLATE (yychar); \
+ YYPOPSTACK; \
+ goto yybackup; \
+ } \
+ else \
+ { yyerror ("syntax error: cannot back up"); YYERROR; } \
+while (0)
+
+#define YYTERROR 1
+#define YYERRCODE 256
+
+#ifndef YYPURE
+#define YYLEX yylex()
+#endif
+
+#ifdef YYPURE
+#ifdef YYLSP_NEEDED
+#define YYLEX yylex(&yylval, &yylloc)
+#else
+#define YYLEX yylex(&yylval)
+#endif
+#endif
+
+/* If nonreentrant, generate the variables here */
+
+#ifndef YYPURE
+
+int yychar; /* the lookahead symbol */
+YYSTYPE yylval; /* the semantic value of the */
+ /* lookahead symbol */
+
+#ifdef YYLSP_NEEDED
+YYLTYPE yylloc; /* location data for the lookahead */
+ /* symbol */
+#endif
+
+int yynerrs; /* number of parse errors so far */
+#endif /* not YYPURE */
+
+#if YYDEBUG != 0
+int yydebug; /* nonzero means print parse trace */
+/* Since this is uninitialized, it does not stop multiple parsers
+ from coexisting. */
+#endif
+
+/* YYINITDEPTH indicates the initial size of the parser's stacks */
+
+#ifndef YYINITDEPTH
+#define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH is the maximum size the stacks can grow to
+ (effective only if the built-in stack extension method is used). */
+
+#if YYMAXDEPTH == 0
+#undef YYMAXDEPTH
+#endif
+
#ifndef YYMAXDEPTH
-#define YYMAXDEPTH 150
+#define YYMAXDEPTH 10000
+#endif
+
+#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
+#define __yy_bcopy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)
+#else /* not GNU C or C++ */
+#ifndef __cplusplus
+
+/* This is the most reliable way to avoid incompatibilities
+ in available built-in functions on various systems. */
+static void
+__yy_bcopy (from, to, count)
+ char *from;
+ char *to;
+ int count;
+{
+ register char *f = from;
+ register char *t = to;
+ register int i = count;
+
+ while (i-- > 0)
+ *t++ = *f++;
+}
+
+#else /* __cplusplus */
+
+/* This is the most reliable way to avoid incompatibilities
+ in available built-in functions on various systems. */
+static void
+__yy_bcopy (char *from, char *to, int count)
+{
+ register char *f = from;
+ register char *t = to;
+ register int i = count;
+
+ while (i-- > 0)
+ *t++ = *f++;
+}
+
+#endif
+#endif
+
+#line 169 "/local/lib/bison.simple"
+int
+yyparse()
+{
+ register int yystate;
+ register int yyn;
+ register short *yyssp;
+ register YYSTYPE *yyvsp;
+ int yyerrstatus; /* number of tokens to shift before error messages enabled */
+ int yychar1; /* lookahead token as an internal (translated) token number */
+
+ short yyssa[YYINITDEPTH]; /* the state stack */
+ YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
+
+ short *yyss = yyssa; /* refer to the stacks thru separate pointers */
+ YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
+
+#ifdef YYLSP_NEEDED
+ YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
+ YYLTYPE *yyls = yylsa;
+ YYLTYPE *yylsp;
+
+#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
+#else
+#define YYPOPSTACK (yyvsp--, yyssp--)
+#endif
+
+ int yystacksize = YYINITDEPTH;
+
+#ifdef YYPURE
+ int yychar;
+ YYSTYPE yylval;
+ int yynerrs;
+#ifdef YYLSP_NEEDED
+ YYLTYPE yylloc;
+#endif
+#endif
+
+ YYSTYPE yyval; /* the variable used to return */
+ /* semantic values from the action */
+ /* routines */
+
+ int yylen;
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Starting parse\n");
+#endif
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
+
+ yyssp = yyss - 1;
+ yyvsp = yyvs;
+#ifdef YYLSP_NEEDED
+ yylsp = yyls;
+#endif
+
+/* Push a new state, which is found in yystate . */
+/* In all cases, when you get here, the value and location stacks
+ have just been pushed. so pushing a state here evens the stacks. */
+yynewstate:
+
+ *++yyssp = yystate;
+
+ if (yyssp >= yyss + yystacksize - 1)
+ {
+ /* Give user a chance to reallocate the stack */
+ /* Use copies of these so that the &'s don't force the real ones into memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ short *yyss1 = yyss;
+#ifdef YYLSP_NEEDED
+ YYLTYPE *yyls1 = yyls;
+#endif
+
+ /* Get the current used size of the three stacks, in elements. */
+ int size = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ /* Each stack pointer address is followed by the size of
+ the data in use in that stack, in bytes. */
+ yyoverflow("parser stack overflow",
+ &yyss1, size * sizeof (*yyssp),
+ &yyvs1, size * sizeof (*yyvsp),
+#ifdef YYLSP_NEEDED
+ &yyls1, size * sizeof (*yylsp),
+#endif
+ &yystacksize);
+
+ yyss = yyss1; yyvs = yyvs1;
+#ifdef YYLSP_NEEDED
+ yyls = yyls1;
+#endif
+#else /* no yyoverflow */
+ /* Extend the stack our own way. */
+ if (yystacksize >= YYMAXDEPTH)
+ {
+ yyerror("parser stack overflow");
+ return 2;
+ }
+ yystacksize *= 2;
+ if (yystacksize > YYMAXDEPTH)
+ yystacksize = YYMAXDEPTH;
+ yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
+ __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
+ yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
+ __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
+#ifdef YYLSP_NEEDED
+ yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
+ __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
+#endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + size - 1;
+ yyvsp = yyvs + size - 1;
+#ifdef YYLSP_NEEDED
+ yylsp = yyls + size - 1;
+#endif
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Stack size increased to %d\n", yystacksize);
+#endif
+
+ if (yyssp >= yyss + yystacksize - 1)
+ YYABORT;
+ }
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Entering state %d\n", yystate);
+#endif
+
+ goto yybackup;
+ yybackup:
+
+/* Do appropriate processing given the current state. */
+/* Read a lookahead token if we need one and don't already have one. */
+/* yyresume: */
+
+ /* First try to decide what to do without reference to lookahead token. */
+
+ yyn = yypact[yystate];
+ if (yyn == YYFLAG)
+ goto yydefault;
+
+ /* Not known => get a lookahead token if don't already have one. */
+
+ /* yychar is either YYEMPTY or YYEOF
+ or a valid token in external form. */
+
+ if (yychar == YYEMPTY)
+ {
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Reading a token: ");
+#endif
+ yychar = YYLEX;
+ }
+
+ /* Convert token to internal form (in yychar1) for indexing tables with */
+
+ if (yychar <= 0) /* This means end of input. */
+ {
+ yychar1 = 0;
+ yychar = YYEOF; /* Don't call YYLEX any more */
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Now at end of input.\n");
+#endif
+ }
+ else
+ {
+ yychar1 = YYTRANSLATE(yychar);
+
+#if YYDEBUG != 0
+ if (yydebug)
+ {
+ fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
+ /* Give the individual parser a way to print the precise meaning
+ of a token, for further debugging info. */
+#ifdef YYPRINT
+ YYPRINT (stderr, yychar, yylval);
+#endif
+ fprintf (stderr, ")\n");
+ }
+#endif
+ }
+
+ yyn += yychar1;
+ if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
+ goto yydefault;
+
+ yyn = yytable[yyn];
+
+ /* yyn is what to do for this token type in this state.
+ Negative => reduce, -yyn is rule number.
+ Positive => shift, yyn is new state.
+ New state is final state => don't bother to shift,
+ just return success.
+ 0, or most negative number => error. */
+
+ if (yyn < 0)
+ {
+ if (yyn == YYFLAG)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+ else if (yyn == 0)
+ goto yyerrlab;
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Shift the lookahead token. */
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
+#endif
+
+ /* Discard the token being shifted unless it is eof. */
+ if (yychar != YYEOF)
+ yychar = YYEMPTY;
+
+ *++yyvsp = yylval;
+#ifdef YYLSP_NEEDED
+ *++yylsp = yylloc;
+#endif
+
+ /* count tokens shifted since error; after three, turn off error status. */
+ if (yyerrstatus) yyerrstatus--;
+
+ yystate = yyn;
+ goto yynewstate;
+
+/* Do the default action for the current state. */
+yydefault:
+
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+
+/* Do a reduction. yyn is the number of a rule to reduce with. */
+yyreduce:
+ yylen = yyr2[yyn];
+ yyval = yyvsp[1-yylen]; /* implement default value of the action */
+
+#if YYDEBUG != 0
+ if (yydebug)
+ {
+ int i;
+
+ fprintf (stderr, "Reducing via rule %d (line %d), ",
+ yyn, yyrline[yyn]);
+
+ /* Print the symbols being reduced, and their result. */
+ for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
+ fprintf (stderr, "%s ", yytname[yyrhs[i]]);
+ fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
+ }
+#endif
+
+
+ switch (yyn) {
+
+case 1:
+#line 134 "awk.y"
+{ expression_value = yyvsp[-1].nodeval; ;
+ break;}
+case 2:
+#line 139 "awk.y"
+{
+ if (yyvsp[0].nodeval != NULL)
+ yyval.nodeval = yyvsp[0].nodeval;
+ else
+ yyval.nodeval = NULL;
+ yyerrok;
+ ;
+ break;}
+case 3:
+#line 148 "awk.y"
+{
+ if (yyvsp[0].nodeval == NULL)
+ yyval.nodeval = yyvsp[-1].nodeval;
+ else if (yyvsp[-1].nodeval == NULL)
+ yyval.nodeval = yyvsp[0].nodeval;
+ else {
+ if (yyvsp[-1].nodeval->type != Node_rule_list)
+ yyvsp[-1].nodeval = node(yyvsp[-1].nodeval, Node_rule_list,
+ (NODE*)NULL);
+ yyval.nodeval = append_right (yyvsp[-1].nodeval,
+ node(yyvsp[0].nodeval, Node_rule_list,(NODE *) NULL));
+ }
+ yyerrok;
+ ;
+ break;}
+case 4:
+#line 162 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 5:
+#line 163 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 6:
+#line 167 "awk.y"
+{ io_allowed = 0; ;
+ break;}
+case 7:
+#line 169 "awk.y"
+{
+ if (begin_block) {
+ if (begin_block->type != Node_rule_list)
+ begin_block = node(begin_block, Node_rule_list,
+ (NODE *)NULL);
+ (void) append_right (begin_block, node(
+ node((NODE *)NULL, Node_rule_node, yyvsp[0].nodeval),
+ Node_rule_list, (NODE *)NULL) );
+ } else
+ begin_block = node((NODE *)NULL, Node_rule_node, yyvsp[0].nodeval);
+ yyval.nodeval = NULL;
+ io_allowed = 1;
+ yyerrok;
+ ;
+ break;}
+case 8:
+#line 183 "awk.y"
+{ io_allowed = 0; ;
+ break;}
+case 9:
+#line 185 "awk.y"
+{
+ if (end_block) {
+ if (end_block->type != Node_rule_list)
+ end_block = node(end_block, Node_rule_list,
+ (NODE *)NULL);
+ (void) append_right (end_block, node(
+ node((NODE *)NULL, Node_rule_node, yyvsp[0].nodeval),
+ Node_rule_list, (NODE *)NULL));
+ } else
+ end_block = node((NODE *)NULL, Node_rule_node, yyvsp[0].nodeval);
+ yyval.nodeval = NULL;
+ io_allowed = 1;
+ yyerrok;
+ ;
+ break;}
+case 10:
+#line 200 "awk.y"
+{
+ warning("BEGIN blocks must have an action part");
+ errcount++;
+ yyerrok;
+ ;
+ break;}
+case 11:
+#line 206 "awk.y"
+{
+ warning("END blocks must have an action part");
+ errcount++;
+ yyerrok;
+ ;
+ break;}
+case 12:
+#line 212 "awk.y"
+{ yyval.nodeval = node (yyvsp[-1].nodeval, Node_rule_node, yyvsp[0].nodeval); yyerrok; ;
+ break;}
+case 13:
+#line 214 "awk.y"
+{ yyval.nodeval = node ((NODE *)NULL, Node_rule_node, yyvsp[0].nodeval); yyerrok; ;
+ break;}
+case 14:
+#line 216 "awk.y"
+{
+ yyval.nodeval = node (yyvsp[-1].nodeval,
+ Node_rule_node,
+ node(node(node(make_number(0.0),
+ Node_field_spec,
+ (NODE *) NULL),
+ Node_expression_list,
+ (NODE *) NULL),
+ Node_K_print,
+ (NODE *) NULL));
+ yyerrok;
+ ;
+ break;}
+case 15:
+#line 229 "awk.y"
+{
+ func_install(yyvsp[-1].nodeval, yyvsp[0].nodeval);
+ yyval.nodeval = NULL;
+ yyerrok;
+ ;
+ break;}
+case 16:
+#line 238 "awk.y"
+{ yyval.sval = yyvsp[0].sval; ;
+ break;}
+case 17:
+#line 240 "awk.y"
+{ yyval.sval = yyvsp[0].sval; ;
+ break;}
+case 18:
+#line 242 "awk.y"
+{
+ yyerror("%s() is a built-in function, it cannot be redefined",
+ tokstart);
+ errcount++;
+ /* yyerrok; */
+ ;
+ break;}
+case 21:
+#line 257 "awk.y"
+{
+ param_counter = 0;
+ ;
+ break;}
+case 22:
+#line 261 "awk.y"
+{
+ yyval.nodeval = append_right(make_param(yyvsp[-4].sval), yyvsp[-2].nodeval);
+ can_return = 1;
+ ;
+ break;}
+case 23:
+#line 269 "awk.y"
+{
+ yyval.nodeval = yyvsp[-2].nodeval;
+ can_return = 0;
+ ;
+ break;}
+case 24:
+#line 278 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 25:
+#line 280 "awk.y"
+{ yyval.nodeval = mkrangenode ( node(yyvsp[-2].nodeval, Node_cond_pair, yyvsp[0].nodeval) ); ;
+ break;}
+case 26:
+#line 289 "awk.y"
+{ ++want_regexp; ;
+ break;}
+case 27:
+#line 291 "awk.y"
+{
+ NODE *n;
+ int len;
+
+ getnode(n);
+ n->type = Node_regex;
+ len = strlen(yyvsp[-1].sval);
+ n->re_exp = make_string(yyvsp[-1].sval, len);
+ n->re_reg = make_regexp(yyvsp[-1].sval, len, 0, 1);
+ n->re_text = NULL;
+ n->re_flags = CONST;
+ n->re_cnt = 1;
+ yyval.nodeval = n;
+ ;
+ break;}
+case 28:
+#line 309 "awk.y"
+{ yyval.nodeval = yyvsp[-3].nodeval ; ;
+ break;}
+case 29:
+#line 311 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 30:
+#line 316 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 31:
+#line 318 "awk.y"
+{
+ if (yyvsp[-1].nodeval == NULL || yyvsp[-1].nodeval->type != Node_statement_list)
+ yyvsp[-1].nodeval = node(yyvsp[-1].nodeval, Node_statement_list,(NODE *)NULL);
+ yyval.nodeval = append_right(yyvsp[-1].nodeval,
+ node( yyvsp[0].nodeval, Node_statement_list, (NODE *)NULL));
+ yyerrok;
+ ;
+ break;}
+case 32:
+#line 326 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 33:
+#line 328 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 36:
+#line 338 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 37:
+#line 340 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 38:
+#line 342 "awk.y"
+{ yyval.nodeval = yyvsp[-1].nodeval; ;
+ break;}
+case 39:
+#line 344 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 40:
+#line 346 "awk.y"
+{ yyval.nodeval = node (yyvsp[-3].nodeval, Node_K_while, yyvsp[0].nodeval); ;
+ break;}
+case 41:
+#line 348 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_K_do, yyvsp[-5].nodeval); ;
+ break;}
+case 42:
+#line 350 "awk.y"
+{
+ yyval.nodeval = node (yyvsp[0].nodeval, Node_K_arrayfor, make_for_loop(variable(yyvsp[-5].sval,1),
+ (NODE *)NULL, variable(yyvsp[-3].sval,1)));
+ ;
+ break;}
+case 43:
+#line 355 "awk.y"
+{
+ yyval.nodeval = node(yyvsp[0].nodeval, Node_K_for, (NODE *)make_for_loop(yyvsp[-7].nodeval, yyvsp[-5].nodeval, yyvsp[-3].nodeval));
+ ;
+ break;}
+case 44:
+#line 359 "awk.y"
+{
+ yyval.nodeval = node (yyvsp[0].nodeval, Node_K_for,
+ (NODE *)make_for_loop(yyvsp[-6].nodeval, (NODE *)NULL, yyvsp[-3].nodeval));
+ ;
+ break;}
+case 45:
+#line 365 "awk.y"
+{ yyval.nodeval = node ((NODE *)NULL, Node_K_break, (NODE *)NULL); ;
+ break;}
+case 46:
+#line 368 "awk.y"
+{ yyval.nodeval = node ((NODE *)NULL, Node_K_continue, (NODE *)NULL); ;
+ break;}
+case 47:
+#line 370 "awk.y"
+{ yyval.nodeval = node (yyvsp[-3].nodeval, yyvsp[-5].nodetypeval, yyvsp[-1].nodeval); ;
+ break;}
+case 48:
+#line 372 "awk.y"
+{
+ if (yyvsp[-3].nodetypeval == Node_K_print && yyvsp[-2].nodeval == NULL)
+ yyvsp[-2].nodeval = node(node(make_number(0.0),
+ Node_field_spec,
+ (NODE *) NULL),
+ Node_expression_list,
+ (NODE *) NULL);
+
+ yyval.nodeval = node (yyvsp[-2].nodeval, yyvsp[-3].nodetypeval, yyvsp[-1].nodeval);
+ ;
+ break;}
+case 49:
+#line 383 "awk.y"
+{ NODETYPE type;
+
+ if (yyvsp[-1].nodeval && yyvsp[-1].nodeval == lookup("file")) {
+ if (do_lint)
+ warning("`next file' is a gawk extension");
+ else if (do_unix || do_posix)
+ yyerror("`next file' is a gawk extension");
+ else if (! io_allowed)
+ yyerror("`next file' used in BEGIN or END action");
+ type = Node_K_nextfile;
+ } else {
+ if (! io_allowed)
+ yyerror("next used in BEGIN or END action");
+ type = Node_K_next;
+ }
+ yyval.nodeval = node ((NODE *)NULL, type, (NODE *)NULL);
+ ;
+ break;}
+case 50:
+#line 401 "awk.y"
+{ yyval.nodeval = node (yyvsp[-1].nodeval, Node_K_exit, (NODE *)NULL); ;
+ break;}
+case 51:
+#line 403 "awk.y"
+{ if (! can_return) yyerror("return used outside function context"); ;
+ break;}
+case 52:
+#line 405 "awk.y"
+{ yyval.nodeval = node (yyvsp[-1].nodeval, Node_K_return, (NODE *)NULL); ;
+ break;}
+case 53:
+#line 407 "awk.y"
+{ yyval.nodeval = node (variable(yyvsp[-4].sval,1), Node_K_delete, yyvsp[-2].nodeval); ;
+ break;}
+case 54:
+#line 409 "awk.y"
+{ yyval.nodeval = yyvsp[-1].nodeval; ;
+ break;}
+case 55:
+#line 414 "awk.y"
+{ yyval.nodetypeval = yyvsp[0].nodetypeval; ;
+ break;}
+case 56:
+#line 416 "awk.y"
+{ yyval.nodetypeval = yyvsp[0].nodetypeval; ;
+ break;}
+case 57:
+#line 421 "awk.y"
+{
+ yyval.nodeval = node(yyvsp[-3].nodeval, Node_K_if,
+ node(yyvsp[0].nodeval, Node_if_branches, (NODE *)NULL));
+ ;
+ break;}
+case 58:
+#line 427 "awk.y"
+{ yyval.nodeval = node (yyvsp[-6].nodeval, Node_K_if,
+ node (yyvsp[-3].nodeval, Node_if_branches, yyvsp[0].nodeval)); ;
+ break;}
+case 59:
+#line 433 "awk.y"
+{ want_assign = 0; ;
+ break;}
+case 63:
+#line 444 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 64:
+#line 446 "awk.y"
+{ yyval.nodeval = node (yyvsp[0].nodeval, Node_redirect_input, (NODE *)NULL); ;
+ break;}
+case 65:
+#line 451 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 66:
+#line 453 "awk.y"
+{ yyval.nodeval = node (yyvsp[0].nodeval, Node_redirect_output, (NODE *)NULL); ;
+ break;}
+case 67:
+#line 455 "awk.y"
+{ yyval.nodeval = node (yyvsp[0].nodeval, Node_redirect_append, (NODE *)NULL); ;
+ break;}
+case 68:
+#line 457 "awk.y"
+{ yyval.nodeval = node (yyvsp[0].nodeval, Node_redirect_pipe, (NODE *)NULL); ;
+ break;}
+case 69:
+#line 462 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 70:
+#line 464 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 71:
+#line 469 "awk.y"
+{ yyval.nodeval = make_param(yyvsp[0].sval); ;
+ break;}
+case 72:
+#line 471 "awk.y"
+{ yyval.nodeval = append_right(yyvsp[-2].nodeval, make_param(yyvsp[0].sval)); yyerrok; ;
+ break;}
+case 73:
+#line 473 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 74:
+#line 475 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 75:
+#line 477 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 76:
+#line 483 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 77:
+#line 485 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 78:
+#line 490 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 79:
+#line 492 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 80:
+#line 497 "awk.y"
+{ yyval.nodeval = node (yyvsp[0].nodeval, Node_expression_list, (NODE *)NULL); ;
+ break;}
+case 81:
+#line 499 "awk.y"
+{
+ yyval.nodeval = append_right(yyvsp[-2].nodeval,
+ node( yyvsp[0].nodeval, Node_expression_list, (NODE *)NULL));
+ yyerrok;
+ ;
+ break;}
+case 82:
+#line 505 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 83:
+#line 507 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 84:
+#line 509 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 85:
+#line 511 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 86:
+#line 516 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 87:
+#line 518 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 88:
+#line 523 "awk.y"
+{ yyval.nodeval = node (yyvsp[0].nodeval, Node_expression_list, (NODE *)NULL); ;
+ break;}
+case 89:
+#line 525 "awk.y"
+{
+ yyval.nodeval = append_right(yyvsp[-2].nodeval,
+ node( yyvsp[0].nodeval, Node_expression_list, (NODE *)NULL));
+ yyerrok;
+ ;
+ break;}
+case 90:
+#line 531 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 91:
+#line 533 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 92:
+#line 535 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 93:
+#line 537 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 94:
+#line 542 "awk.y"
+{ want_assign = 0; ;
+ break;}
+case 95:
+#line 544 "awk.y"
+{
+ if (do_lint && yyvsp[0].nodeval->type == Node_regex)
+ warning("Regular expression on left of assignment.");
+ yyval.nodeval = node (yyvsp[-3].nodeval, yyvsp[-2].nodetypeval, yyvsp[0].nodeval);
+ ;
+ break;}
+case 96:
+#line 550 "awk.y"
+{ yyval.nodeval = node (variable(yyvsp[0].sval,1), Node_in_array, yyvsp[-3].nodeval); ;
+ break;}
+case 97:
+#line 552 "awk.y"
+{
+ yyval.nodeval = node (yyvsp[0].nodeval, Node_K_getline,
+ node (yyvsp[-3].nodeval, Node_redirect_pipein, (NODE *)NULL));
+ ;
+ break;}
+case 98:
+#line 557 "awk.y"
+{
+ if (do_lint && ! io_allowed && yyvsp[0].nodeval == NULL)
+ warning("non-redirected getline undefined inside BEGIN or END action");
+ yyval.nodeval = node (yyvsp[-1].nodeval, Node_K_getline, yyvsp[0].nodeval);
+ ;
+ break;}
+case 99:
+#line 563 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_and, yyvsp[0].nodeval); ;
+ break;}
+case 100:
+#line 565 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_or, yyvsp[0].nodeval); ;
+ break;}
+case 101:
+#line 567 "awk.y"
+{
+ if (yyvsp[-2].nodeval->type == Node_regex)
+ warning("Regular expression on left of MATCH operator.");
+ yyval.nodeval = node (yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, mk_rexp(yyvsp[0].nodeval));
+ ;
+ break;}
+case 102:
+#line 573 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 103:
+#line 575 "awk.y"
+{
+ yyval.nodeval = node(node(make_number(0.0),
+ Node_field_spec,
+ (NODE *) NULL),
+ Node_nomatch,
+ yyvsp[0].nodeval);
+ ;
+ break;}
+case 104:
+#line 583 "awk.y"
+{ yyval.nodeval = node (variable(yyvsp[0].sval,1), Node_in_array, yyvsp[-2].nodeval); ;
+ break;}
+case 105:
+#line 585 "awk.y"
+{
+ if (do_lint && yyvsp[0].nodeval->type == Node_regex)
+ warning("Regular expression on left of comparison.");
+ yyval.nodeval = node (yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, yyvsp[0].nodeval);
+ ;
+ break;}
+case 106:
+#line 591 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_less, yyvsp[0].nodeval); ;
+ break;}
+case 107:
+#line 593 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_greater, yyvsp[0].nodeval); ;
+ break;}
+case 108:
+#line 595 "awk.y"
+{ yyval.nodeval = node(yyvsp[-4].nodeval, Node_cond_exp, node(yyvsp[-2].nodeval, Node_if_branches, yyvsp[0].nodeval));;
+ break;}
+case 109:
+#line 597 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 110:
+#line 599 "awk.y"
+{ yyval.nodeval = node (yyvsp[-1].nodeval, Node_concat, yyvsp[0].nodeval); ;
+ break;}
+case 111:
+#line 604 "awk.y"
+{ want_assign = 0; ;
+ break;}
+case 112:
+#line 606 "awk.y"
+{ yyval.nodeval = node (yyvsp[-3].nodeval, yyvsp[-2].nodetypeval, yyvsp[0].nodeval); ;
+ break;}
+case 113:
+#line 608 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_and, yyvsp[0].nodeval); ;
+ break;}
+case 114:
+#line 610 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_or, yyvsp[0].nodeval); ;
+ break;}
+case 115:
+#line 612 "awk.y"
+{
+ if (do_lint && ! io_allowed && yyvsp[0].nodeval == NULL)
+ warning("non-redirected getline undefined inside BEGIN or END action");
+ yyval.nodeval = node (yyvsp[-1].nodeval, Node_K_getline, yyvsp[0].nodeval);
+ ;
+ break;}
+case 116:
+#line 618 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 117:
+#line 620 "awk.y"
+{ yyval.nodeval = node((NODE *) NULL, Node_nomatch, yyvsp[0].nodeval); ;
+ break;}
+case 118:
+#line 622 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, mk_rexp(yyvsp[0].nodeval)); ;
+ break;}
+case 119:
+#line 624 "awk.y"
+{ yyval.nodeval = node (variable(yyvsp[0].sval,1), Node_in_array, yyvsp[-2].nodeval); ;
+ break;}
+case 120:
+#line 626 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, yyvsp[-1].nodetypeval, yyvsp[0].nodeval); ;
+ break;}
+case 121:
+#line 628 "awk.y"
+{ yyval.nodeval = node(yyvsp[-4].nodeval, Node_cond_exp, node(yyvsp[-2].nodeval, Node_if_branches, yyvsp[0].nodeval));;
+ break;}
+case 122:
+#line 630 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 123:
+#line 632 "awk.y"
+{ yyval.nodeval = node (yyvsp[-1].nodeval, Node_concat, yyvsp[0].nodeval); ;
+ break;}
+case 125:
+#line 639 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_exp, yyvsp[0].nodeval); ;
+ break;}
+case 126:
+#line 641 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_times, yyvsp[0].nodeval); ;
+ break;}
+case 127:
+#line 643 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_quotient, yyvsp[0].nodeval); ;
+ break;}
+case 128:
+#line 645 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_mod, yyvsp[0].nodeval); ;
+ break;}
+case 129:
+#line 647 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_plus, yyvsp[0].nodeval); ;
+ break;}
+case 130:
+#line 649 "awk.y"
+{ yyval.nodeval = node (yyvsp[-2].nodeval, Node_minus, yyvsp[0].nodeval); ;
+ break;}
+case 131:
+#line 651 "awk.y"
+{ yyval.nodeval = node (yyvsp[-1].nodeval, Node_postincrement, (NODE *)NULL); ;
+ break;}
+case 132:
+#line 653 "awk.y"
+{ yyval.nodeval = node (yyvsp[-1].nodeval, Node_postdecrement, (NODE *)NULL); ;
+ break;}
+case 133:
+#line 658 "awk.y"
+{ yyval.nodeval = node (yyvsp[0].nodeval, Node_not,(NODE *) NULL); ;
+ break;}
+case 134:
+#line 660 "awk.y"
+{ yyval.nodeval = yyvsp[-1].nodeval; ;
+ break;}
+case 135:
+#line 663 "awk.y"
+{ yyval.nodeval = snode (yyvsp[-1].nodeval, Node_builtin, (int) yyvsp[-3].lval); ;
+ break;}
+case 136:
+#line 665 "awk.y"
+{ yyval.nodeval = snode (yyvsp[-1].nodeval, Node_builtin, (int) yyvsp[-3].lval); ;
+ break;}
+case 137:
+#line 667 "awk.y"
+{
+ if (do_lint)
+ warning("call of `length' without parentheses is not portable");
+ yyval.nodeval = snode ((NODE *)NULL, Node_builtin, (int) yyvsp[0].lval);
+ if (do_posix)
+ warning( "call of `length' without parentheses is deprecated by POSIX");
+ ;
+ break;}
+case 138:
+#line 675 "awk.y"
+{
+ yyval.nodeval = node (yyvsp[-1].nodeval, Node_func_call, make_string(yyvsp[-3].sval, strlen(yyvsp[-3].sval)));
+ ;
+ break;}
+case 140:
+#line 680 "awk.y"
+{ yyval.nodeval = node (yyvsp[0].nodeval, Node_preincrement, (NODE *)NULL); ;
+ break;}
+case 141:
+#line 682 "awk.y"
+{ yyval.nodeval = node (yyvsp[0].nodeval, Node_predecrement, (NODE *)NULL); ;
+ break;}
+case 142:
+#line 684 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 143:
+#line 686 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 144:
+#line 689 "awk.y"
+{ if (yyvsp[0].nodeval->type == Node_val) {
+ yyvsp[0].nodeval->numbr = -(force_number(yyvsp[0].nodeval));
+ yyval.nodeval = yyvsp[0].nodeval;
+ } else
+ yyval.nodeval = node (yyvsp[0].nodeval, Node_unary_minus, (NODE *)NULL);
+ ;
+ break;}
+case 145:
+#line 696 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 146:
+#line 701 "awk.y"
+{ yyval.nodeval = NULL; ;
+ break;}
+case 147:
+#line 703 "awk.y"
+{ yyval.nodeval = yyvsp[0].nodeval; ;
+ break;}
+case 148:
+#line 708 "awk.y"
+{ yyval.nodeval = variable(yyvsp[0].sval,1); ;
+ break;}
+case 149:
+#line 710 "awk.y"
+{
+ if (yyvsp[-1].nodeval->rnode == NULL) {
+ yyval.nodeval = node (variable(yyvsp[-3].sval,1), Node_subscript, yyvsp[-1].nodeval->lnode);
+ freenode(yyvsp[-1].nodeval);
+ } else
+ yyval.nodeval = node (variable(yyvsp[-3].sval,1), Node_subscript, yyvsp[-1].nodeval);
+ ;
+ break;}
+case 150:
+#line 718 "awk.y"
+{ yyval.nodeval = node (yyvsp[0].nodeval, Node_field_spec, (NODE *)NULL); ;
+ break;}
+case 152:
+#line 726 "awk.y"
+{ yyerrok; ;
+ break;}
+case 153:
+#line 730 "awk.y"
+{ yyerrok; ;
+ break;}
+case 156:
+#line 739 "awk.y"
+{ yyerrok; want_assign = 0; ;
+ break;}
+case 157:
+#line 742 "awk.y"
+{ yyerrok; ;
+ break;}
+}
+ /* the action file gets copied in in place of this dollarsign */
+#line 442 "/local/lib/bison.simple"
+
+ yyvsp -= yylen;
+ yyssp -= yylen;
+#ifdef YYLSP_NEEDED
+ yylsp -= yylen;
+#endif
+
+#if YYDEBUG != 0
+ if (yydebug)
+ {
+ short *ssp1 = yyss - 1;
+ fprintf (stderr, "state stack now");
+ while (ssp1 != yyssp)
+ fprintf (stderr, " %d", *++ssp1);
+ fprintf (stderr, "\n");
+ }
#endif
-YYSTYPE yylval, yyval;
-# define YYERRCODE 256
-# line 751 "awk.y"
+ *++yyvsp = yyval;
+
+#ifdef YYLSP_NEEDED
+ yylsp++;
+ if (yylen == 0)
+ {
+ yylsp->first_line = yylloc.first_line;
+ yylsp->first_column = yylloc.first_column;
+ yylsp->last_line = (yylsp-1)->last_line;
+ yylsp->last_column = (yylsp-1)->last_column;
+ yylsp->text = 0;
+ }
+ else
+ {
+ yylsp->last_line = (yylsp+yylen-1)->last_line;
+ yylsp->last_column = (yylsp+yylen-1)->last_column;
+ }
+#endif
+
+ /* Now "shift" the result of the reduction.
+ Determine what state that goes to,
+ based on the state we popped back to
+ and the rule number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
+ if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTBASE];
+
+ goto yynewstate;
+
+yyerrlab: /* here on detecting error */
+
+ if (! yyerrstatus)
+ /* If not already recovering from an error, report this error. */
+ {
+ ++yynerrs;
+
+#ifdef YYERROR_VERBOSE
+ yyn = yypact[yystate];
+
+ if (yyn > YYFLAG && yyn < YYLAST)
+ {
+ int size = 0;
+ char *msg;
+ int x, count;
+
+ count = 0;
+ for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
+ if (yycheck[x + yyn] == x)
+ size += strlen(yytname[x]) + 15, count++;
+ msg = (char *) malloc(size + 15);
+ if (msg != 0)
+ {
+ strcpy(msg, "parse error");
+
+ if (count < 5)
+ {
+ count = 0;
+ for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
+ if (yycheck[x + yyn] == x)
+ {
+ strcat(msg, count == 0 ? ", expecting `" : " or `");
+ strcat(msg, yytname[x]);
+ strcat(msg, "'");
+ count++;
+ }
+ }
+ yyerror(msg);
+ free(msg);
+ }
+ else
+ yyerror ("parse error; also virtual memory exceeded");
+ }
+ else
+#endif /* YYERROR_VERBOSE */
+ yyerror("parse error");
+ }
+
+ goto yyerrlab1;
+yyerrlab1: /* here on error raised explicitly by an action */
+
+ if (yyerrstatus == 3)
+ {
+ /* if just tried and failed to reuse lookahead token after an error, discard it. */
+
+ /* return failure if at end of input */
+ if (yychar == YYEOF)
+ YYABORT;
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
+#endif
+
+ yychar = YYEMPTY;
+ }
+
+ /* Else will try to reuse lookahead token
+ after shifting the error token. */
+
+ yyerrstatus = 3; /* Each real token shifted decrements this */
+
+ goto yyerrhandle;
+
+yyerrdefault: /* current state does not do anything special for the error token. */
+
+#if 0
+ /* This is wrong; only states that explicitly want error tokens
+ should shift them. */
+ yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
+ if (yyn) goto yydefault;
+#endif
+
+yyerrpop: /* pop the current state because it cannot handle the error token */
+
+ if (yyssp == yyss) YYABORT;
+ yyvsp--;
+ yystate = *--yyssp;
+#ifdef YYLSP_NEEDED
+ yylsp--;
+#endif
+
+#if YYDEBUG != 0
+ if (yydebug)
+ {
+ short *ssp1 = yyss - 1;
+ fprintf (stderr, "Error: state stack now");
+ while (ssp1 != yyssp)
+ fprintf (stderr, " %d", *++ssp1);
+ fprintf (stderr, "\n");
+ }
+#endif
+
+yyerrhandle:
+
+ yyn = yypact[yystate];
+ if (yyn == YYFLAG)
+ goto yyerrdefault;
+
+ yyn += YYTERROR;
+ if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
+ goto yyerrdefault;
+
+ yyn = yytable[yyn];
+ if (yyn < 0)
+ {
+ if (yyn == YYFLAG)
+ goto yyerrpop;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+ else if (yyn == 0)
+ goto yyerrpop;
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+#if YYDEBUG != 0
+ if (yydebug)
+ fprintf(stderr, "Shifting error token, ");
+#endif
+
+ *++yyvsp = yylval;
+#ifdef YYLSP_NEEDED
+ *++yylsp = yylloc;
+#endif
+
+ yystate = yyn;
+ goto yynewstate;
+}
+#line 745 "awk.y"
struct token {
@@ -182,7 +2260,7 @@ yyerror(va_alist)
va_dcl
{
va_list args;
- char *mesg;
+ char *mesg = NULL;
register char *bp, *cp;
char *scan;
char buf[120];
@@ -191,7 +2269,12 @@ va_dcl
/* Find the current line in the input file */
if (lexptr) {
if (!thisline) {
- for (cp=lexeme; cp != lexptr_begin && *cp != '\n'; --cp)
+ cp = lexeme;
+ if (*cp == '\n') {
+ cp--;
+ mesg = "unexpected newline";
+ }
+ for ( ; cp != lexptr_begin && *cp != '\n'; --cp)
;
if (*cp == '\n')
cp++;
@@ -219,7 +2302,8 @@ va_dcl
*bp++ = ' ';
}
va_start(args);
- mesg = va_arg(args, char *);
+ if (mesg == NULL)
+ mesg = va_arg(args, char *);
strcpy(bp, mesg);
err("", buf, args);
va_end(args);
@@ -239,13 +2323,14 @@ get_src_buf()
static int did_newline = 0;
# define SLOP 128 /* enough space to hold most source lines */
- if (cmdline_src) {
+ if (nextfile > numfiles)
+ return NULL;
+
+ if (srcfiles[nextfile].stype == CMDLINE) {
if (len == 0) {
- len = strlen(cmdline_src);
- if (len == 0)
- cmdline_src = NULL;
+ len = strlen(srcfiles[nextfile].val);
sourceline = 1;
- lexptr = lexptr_begin = cmdline_src;
+ lexptr = lexptr_begin = srcfiles[nextfile].val;
lexend = lexptr + len;
} else if (!did_newline && *(lexptr-1) != '\n') {
/*
@@ -271,15 +2356,22 @@ get_src_buf()
lexeme = lexptr - offset;
lexptr_begin = buf;
lexend = lexptr + 1;
- } else
+ } else {
+ len = 0;
lexeme = lexptr = lexptr_begin = NULL;
+ }
+ if (lexptr == NULL && ++nextfile <= numfiles)
+ return get_src_buf();
return lexptr;
}
if (!samefile) {
- source = srcfiles[nextfile];
+ source = srcfiles[nextfile].val;
if (source == NULL) {
- if (buf)
+ if (buf) {
free(buf);
+ buf = NULL;
+ }
+ len = 0;
return lexeme = lexptr = lexptr_begin = NULL;
}
fd = pathopen(source);
@@ -309,7 +2401,7 @@ get_src_buf()
}
linelen = lexptr - scan;
if (linelen > SLOP)
- len = SLOP;
+ linelen = SLOP;
thisline = buf + SLOP - linelen;
memcpy(thisline, scan, linelen);
lexeme = buf + SLOP - offset;
@@ -322,6 +2414,7 @@ get_src_buf()
if (n == 0) {
samefile = 0;
nextfile++;
+ len = 0;
return get_src_buf();
}
lexptr = buf + SLOP;
@@ -348,14 +2441,15 @@ tokexpand()
return token;
}
-#ifdef DEBUG
+#if DEBUG
char
nextc() {
if (lexptr && lexptr < lexend)
return *lexptr++;
- if (get_src_buf())
+ else if (get_src_buf())
return *lexptr++;
- return '\0';
+ else
+ return '\0';
}
#else
#define nextc() ((lexptr && lexptr < lexend) ? \
@@ -428,7 +2522,7 @@ retry:
while ((c = nextc()) == ' ' || c == '\t')
;
- lexeme = lexptr-1;
+ lexeme = lexptr ? lexptr - 1 : lexptr;
thisline = NULL;
token = tokstart;
yylval.nodetypeval = Node_illegal;
@@ -451,7 +2545,7 @@ retry:
case '\\':
#ifdef RELAXED_CONTINUATION
- if (!strict) { /* strip trailing white-space and/or comment */
+ if (!do_unix) { /* strip trailing white-space and/or comment */
while ((c = nextc()) == ' ' || c == '\t') continue;
if (c == '#')
while ((c = nextc()) != '\n') if (!c) break;
@@ -815,7 +2909,7 @@ retry:
warning("%s is not supported in old awk",
tokentab[mid].operator);
}
- if ((strict && (tokentab[mid].flags & GAWKX))
+ if ((do_unix && (tokentab[mid].flags & GAWKX))
|| (do_posix && (tokentab[mid].flags & NOT_POSIX)))
break;
if (tokentab[mid].class == LEX_BUILTIN
@@ -996,6 +3090,7 @@ NODE *value;
hp->hlength = len;
hp->hvalue = value;
hp->hname = name;
+ hp->hvalue->vname = name;
return hp->hvalue;
}
@@ -1148,1720 +3243,3 @@ NODE *exp;
return n;
}
}
-int yyexca[] ={
--1, 1,
- 0, -1,
- -2, 0,
--1, 5,
- 0, 61,
- -2, 0,
--1, 77,
- 264, 78,
- 267, 78,
- 62, 78,
- 124, 78,
- 59, 78,
- -2, 0,
--1, 112,
- 41, 86,
- -2, 0,
--1, 113,
- 41, 86,
- -2, 0,
--1, 126,
- 266, 0,
- -2, 101,
--1, 128,
- 263, 0,
- 60, 0,
- 62, 0,
- 124, 0,
- -2, 105,
--1, 129,
- 263, 0,
- 60, 0,
- 62, 0,
- 124, 0,
- -2, 106,
--1, 130,
- 263, 0,
- 60, 0,
- 62, 0,
- 124, 0,
- -2, 107,
--1, 149,
- 264, 79,
- 267, 79,
- 62, 79,
- 124, 79,
- 59, 79,
- -2, 0,
--1, 188,
- 41, 86,
- -2, 0,
--1, 190,
- 41, 87,
- -2, 0,
--1, 224,
- 41, 69,
- -2, 0,
--1, 253,
- 266, 0,
- -2, 118,
--1, 255,
- 263, 0,
- -2, 120,
--1, 263,
- 41, 70,
- -2, 0,
- };
-# define YYNPROD 161
-# define YYLAST 1998
-int yyact[]={
-
- 62, 216, 107, 13, 87, 229, 13, 88, 89, 166,
- 165, 123, 240, 297, 4, 82, 45, 37, 91, 45,
- 292, 265, 291, 264, 204, 88, 89, 187, 88, 89,
- 270, 24, 171, 266, 254, 155, 63, 161, 24, 127,
- 176, 65, 98, 168, 169, 36, 52, 35, 157, 25,
- 63, 174, 82, 122, 63, 124, 125, 126, 22, 128,
- 129, 130, 131, 93, 136, 82, 189, 203, 66, 63,
- 100, 82, 103, 222, 107, 64, 177, 101, 63, 158,
- 158, 45, 102, 22, 103, 276, 206, 63, 232, 101,
- 104, 174, 105, 269, 102, 224, 188, 163, 16, 178,
- 144, 142, 113, 112, 6, 11, 133, 26, 186, 111,
- 39, 257, 140, 186, 186, 170, 48, 94, 231, 99,
- 160, 110, 82, 109, 86, 46, 41, 121, 159, 100,
- 114, 115, 108, 134, 99, 99, 167, 164, 77, 262,
- 71, 100, 82, 198, 82, 158, 141, 118, 91, 148,
- 149, 263, 120, 10, 27, 20, 5, 1, 24, 50,
- 12, 158, 17, 192, 223, 36, 0, 35, 0, 25,
- 0, 225, 226, 228, 0, 0, 152, 0, 0, 0,
- 191, 45, 207, 197, 0, 0, 0, 193, 0, 186,
- 134, 0, 0, 201, 0, 237, 99, 241, 195, 99,
- 99, 99, 99, 99, 99, 245, 246, 247, 0, 221,
- 134, 0, 199, 0, 0, 0, 190, 217, 0, 0,
- 0, 0, 94, 186, 4, 20, 205, 4, 24, 0,
- 0, 0, 17, 0, 90, 36, 0, 35, 0, 25,
- 0, 0, 0, 271, 0, 22, 0, 68, 172, 152,
- 0, 45, 94, 23, 99, 233, 0, 236, 258, 30,
- 23, 0, 280, 33, 34, 213, 172, 0, 211, 82,
- 282, 0, 20, 158, 0, 24, 99, 0, 82, 17,
- 0, 172, 36, 0, 35, 158, 25, 153, 212, 209,
- 172, 31, 32, 28, 29, 82, 279, 0, 45, 208,
- 0, 0, 82, 82, 82, 0, 152, 152, 152, 152,
- 152, 273, 152, 152, 152, 22, 20, 68, 0, 24,
- 0, 285, 155, 17, 185, 24, 36, 0, 35, 98,
- 25, 0, 36, 295, 35, 0, 25, 281, 0, 0,
- 0, 0, 45, 0, 0, 0, 289, 152, 0, 152,
- 152, 152, 152, 0, 152, 152, 152, 0, 0, 0,
- 0, 0, 22, 299, 202, 0, 0, 0, 0, 0,
- 304, 305, 306, 152, 152, 0, 0, 0, 135, 30,
- 23, 0, 0, 33, 34, 0, 152, 0, 0, 0,
- 0, 0, 0, 83, 0, 80, 81, 72, 73, 74,
- 75, 76, 84, 85, 78, 79, 22, 18, 0, 0,
- 0, 31, 32, 28, 29, 20, 0, 0, 24, 0,
- 215, 0, 17, 0, 0, 36, 0, 35, 0, 25,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 260,
- 0, 45, 59, 0, 60, 61, 0, 0, 67, 30,
- 23, 0, 0, 33, 34, 0, 0, 0, 0, 0,
- 0, 0, 0, 83, 0, 80, 81, 72, 73, 74,
- 75, 76, 84, 85, 78, 79, 0, 18, 0, 0,
- 0, 31, 32, 28, 29, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 67, 30, 23, 150, 0,
- 33, 34, 21, 0, 0, 0, 53, 0, 0, 0,
- 83, 0, 80, 81, 72, 73, 74, 75, 76, 84,
- 85, 78, 79, 96, 18, 0, 0, 0, 31, 32,
- 28, 29, 0, 0, 0, 0, 0, 0, 116, 117,
- 30, 23, 0, 0, 33, 34, 2, 23, 0, 0,
- 33, 34, 38, 0, 83, 0, 80, 81, 72, 73,
- 74, 75, 76, 84, 85, 78, 79, 0, 18, 106,
- 0, 0, 31, 32, 28, 29, 0, 0, 31, 32,
- 156, 0, 0, 0, 0, 20, 0, 0, 24, 0,
- 0, 119, 17, 0, 0, 36, 0, 35, 0, 25,
- 96, 0, 0, 179, 180, 181, 182, 183, 184, 0,
- 132, 0, 59, 0, 60, 138, 139, 0, 0, 0,
- 143, 0, 0, 0, 0, 0, 0, 0, 248, 250,
- 251, 252, 253, 0, 255, 256, 0, 0, 0, 30,
- 23, 0, 0, 33, 34, 58, 0, 0, 56, 4,
- 0, 0, 20, 156, 0, 24, 0, 0, 96, 17,
- 174, 0, 36, 0, 35, 0, 25, 18, 57, 54,
- 55, 31, 32, 28, 29, 0, 53, 0, 275, 59,
- 230, 60, 61, 196, 0, 0, 70, 0, 0, 14,
- 0, 0, 14, 20, 0, 287, 24, 14, 0, 51,
- 17, 0, 0, 36, 0, 35, 0, 25, 0, 0,
- 156, 156, 156, 156, 156, 0, 156, 156, 156, 45,
- 59, 0, 60, 61, 0, 0, 0, 0, 14, 0,
- 0, 0, 0, 14, 0, 0, 0, 0, 20, 0,
- 0, 24, 238, 53, 0, 17, 0, 0, 36, 0,
- 35, 156, 25, 156, 156, 156, 156, 0, 156, 156,
- 156, 0, 0, 194, 0, 59, 0, 60, 61, 0,
- 0, 0, 0, 0, 0, 0, 0, 156, 156, 0,
- 0, 0, 20, 0, 53, 24, 268, 0, 0, 17,
- 156, 0, 36, 63, 35, 0, 25, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 277, 59,
- 23, 60, 61, 33, 34, 58, 0, 0, 0, 0,
- 0, 20, 0, 0, 24, 290, 0, 0, 17, 53,
- 294, 36, 0, 35, 0, 25, 0, 0, 0, 0,
- 298, 31, 32, 301, 302, 0, 0, 303, 59, 0,
- 60, 61, 0, 0, 0, 0, 0, 0, 155, 0,
- 0, 24, 0, 0, 0, 98, 0, 0, 36, 0,
- 35, 0, 25, 53, 0, 0, 30, 23, 0, 0,
- 33, 34, 58, 274, 0, 56, 0, 0, 214, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 18, 57, 54, 55, 31, 32,
- 28, 29, 53, 0, 0, 0, 0, 30, 23, 0,
- 0, 33, 34, 58, 0, 0, 56, 20, 0, 0,
- 24, 0, 0, 0, 17, 0, 0, 36, 0, 35,
- 0, 25, 0, 0, 0, 18, 57, 54, 55, 31,
- 32, 28, 29, 0, 59, 0, 60, 0, 0, 0,
- 0, 0, 30, 23, 0, 0, 33, 34, 58, 155,
- 0, 56, 24, 0, 0, 155, 98, 0, 24, 36,
- 0, 35, 98, 25, 0, 36, 0, 35, 0, 25,
- 18, 57, 54, 55, 31, 32, 28, 29, 0, 214,
- 0, 0, 0, 19, 0, 0, 30, 23, 0, 0,
- 33, 34, 58, 20, 0, 56, 24, 0, 53, 0,
- 17, 0, 0, 36, 95, 35, 0, 25, 0, 0,
- 0, 0, 0, 0, 18, 57, 54, 55, 31, 32,
- 28, 29, 0, 0, 0, 30, 23, 0, 0, 33,
- 34, 58, 20, 0, 56, 24, 0, 0, 0, 17,
- 0, 0, 36, 0, 35, 0, 25, 0, 0, 0,
- 0, 0, 0, 18, 57, 54, 55, 31, 32, 28,
- 29, 154, 30, 23, 0, 0, 33, 34, 213, 0,
- 0, 211, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 22, 0, 0, 0, 0, 0, 0,
- 153, 212, 209, 210, 31, 32, 28, 29, 20, 0,
- 0, 24, 0, 0, 0, 17, 0, 0, 36, 0,
- 35, 0, 25, 0, 155, 0, 0, 24, 0, 0,
- 0, 98, 22, 0, 36, 59, 35, 60, 25, 0,
- 0, 30, 23, 0, 154, 33, 34, 58, 0, 218,
- 56, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 18,
- 57, 54, 0, 31, 32, 28, 29, 0, 0, 0,
- 0, 0, 0, 30, 23, 0, 0, 33, 34, 213,
- 23, 0, 211, 33, 34, 213, 0, 0, 0, 53,
- 0, 154, 154, 154, 154, 154, 0, 154, 154, 154,
- 0, 153, 212, 209, 210, 31, 32, 28, 29, 0,
- 0, 31, 32, 0, 0, 0, 40, 30, 23, 0,
- 0, 33, 34, 0, 0, 0, 0, 4, 0, 8,
- 9, 0, 154, 0, 154, 154, 154, 154, 0, 154,
- 154, 154, 0, 0, 15, 18, 0, 0, 0, 31,
- 32, 28, 29, 0, 0, 7, 30, 23, 154, 154,
- 33, 34, 0, 0, 0, 0, 0, 20, 8, 9,
- 24, 154, 0, 0, 17, 0, 0, 36, 0, 35,
- 0, 25, 0, 15, 18, 0, 0, 0, 31, 32,
- 28, 29, 20, 45, 0, 24, 0, 0, 0, 17,
- 0, 0, 36, 0, 35, 155, 25, 0, 24, 0,
- 0, 0, 98, 0, 0, 36, 0, 35, 0, 25,
- 0, 0, 30, 23, 0, 0, 33, 34, 58, 0,
- 0, 56, 0, 0, 0, 0, 0, 0, 30, 23,
- 0, 0, 33, 34, 213, 0, 0, 211, 0, 0,
- 18, 57, 0, 0, 31, 32, 28, 29, 0, 0,
- 0, 0, 0, 0, 0, 0, 153, 212, 0, 0,
- 31, 32, 28, 29, 20, 0, 0, 24, 0, 0,
- 175, 17, 155, 0, 36, 24, 35, 0, 25, 147,
- 0, 0, 36, 0, 35, 0, 25, 0, 0, 0,
- 20, 0, 0, 24, 0, 0, 0, 17, 0, 0,
- 36, 0, 35, 0, 25, 0, 0, 0, 0, 0,
- 0, 155, 0, 0, 24, 0, 0, 0, 98, 0,
- 0, 36, 0, 35, 0, 25, 20, 0, 0, 24,
- 0, 0, 0, 17, 0, 0, 36, 0, 35, 0,
- 25, 0, 0, 0, 0, 0, 0, 0, 97, 0,
- 0, 24, 0, 0, 0, 98, 0, 0, 36, 0,
- 35, 173, 25, 97, 0, 0, 24, 0, 0, 0,
- 98, 0, 0, 36, 0, 35, 0, 0, 0, 0,
- 0, 30, 23, 0, 20, 33, 34, 24, 0, 0,
- 0, 17, 0, 0, 36, 0, 35, 0, 25, 0,
- 0, 0, 0, 0, 0, 92, 30, 23, 0, 18,
- 33, 34, 0, 31, 32, 28, 29, 0, 249, 30,
- 23, 0, 0, 33, 34, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 18, 0, 0, 0, 31, 32,
- 28, 29, 0, 0, 0, 0, 0, 153, 0, 0,
- 0, 31, 32, 28, 29, 0, 0, 0, 0, 0,
- 234, 0, 235, 0, 0, 0, 0, 0, 0, 239,
- 0, 0, 0, 243, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 227, 30, 23,
- 0, 0, 33, 34, 261, 151, 30, 23, 69, 0,
- 33, 34, 0, 0, 267, 0, 0, 44, 44, 44,
- 0, 0, 0, 0, 30, 23, 18, 0, 33, 34,
- 31, 32, 28, 29, 153, 0, 0, 0, 31, 32,
- 28, 29, 0, 278, 3, 30, 23, 0, 0, 33,
- 34, 283, 18, 43, 43, 43, 31, 32, 28, 29,
- 30, 200, 0, 293, 33, 34, 296, 0, 0, 0,
- 0, 0, 0, 153, 137, 0, 300, 31, 32, 28,
- 29, 0, 30, 23, 44, 44, 33, 34, 18, 0,
- 0, 44, 31, 32, 28, 29, 0, 30, 23, 0,
- 42, 33, 34, 0, 0, 0, 0, 0, 0, 0,
- 47, 49, 0, 0, 31, 32, 28, 29, 0, 23,
- 43, 43, 33, 34, 0, 0, 0, 43, 0, 31,
- 32, 28, 29, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 137, 0, 0, 0, 0, 0, 0, 0,
- 31, 32, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 44, 0, 44, 0,
- 0, 0, 0, 0, 0, 0, 145, 146, 0, 0,
- 0, 0, 0, 162, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 137, 43, 0, 43, 0, 0, 0, 0, 0,
- 242, 0, 44, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 44, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 43, 0,
- 0, 272, 0, 0, 0, 0, 0, 0, 219, 0,
- 220, 0, 0, 0, 0, 0, 43, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 284, 0, 44, 0, 0, 44, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 244, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 43, 0,
- 0, 43, 259, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 286, 0, 0, 288 };
-int yypact[]={
-
- -253, -1000, 1019, -250, -1000, 980, -1000, -1000, -43, -43,
- -40, -1000, -65, 749, 192, -1000, -261, 1279, -5, -1000,
- 1445, 47, -253, -17, 1460, -1000, -1000, -1000, -1000, 63,
- 62, -5, -5, -1000, -1000, 1460, 1460, -1000, -1000, -1000,
- -1000, -65, -1000, -250, -253, -1000, -65, -1000, -1000, -1000,
- -1000, 239, 1387, -274, 1387, 1387, 1387, -219, 1387, 1387,
- 1387, 1387, 1481, -253, 122, 22, -1000, -1000, -253, -253,
- 192, -1000, 61, -253, 60, -43, -43, 1369, 1387, 1387,
- -1000, -221, 382, 57, -1000, -1000, -248, -1000, -1000, -1000,
- 10, 619, -1000, 16, -1000, -1000, -24, 1460, 1387, -282,
- 1460, 1460, 1460, 1460, 1460, 1460, -1000, 1279, -1000, -1000,
- -232, 56, 1279, 1279, -1000, -1000, -24, -24, -1000, -1000,
- -1000, 122, 788, -5, 1085, 894, 552, -1000, 1481, 1481,
- 1481, 705, -1000, 22, -1000, -1000, -253, -1000, -1000, -1000,
- -1000, 122, 1387, 283, 1423, -1000, -1000, 1279, -38, 43,
- 936, -1000, -264, -5, -1000, 1445, 47, -43, 788, -43,
- 1387, -18, -1000, 1387, 55, -1000, -1000, -1000, -1000, -1000,
- 1387, 1361, 1387, -281, -1000, -1000, -1000, 1460, 619, -24,
- -24, -24, -24, 35, 35, 25, 788, 41, 1279, 50,
- 34, 50, 22, -1000, 1387, -253, -1000, -1000, 619, -263,
- -89, 22, 10, -43, 1387, 1387, 1387, 1292, 1408, 1408,
- 1408, 1408, -224, 1408, 1408, 289, -1000, 16, -1000, -1000,
- -1000, -43, 1279, 619, -235, 788, 788, -1000, 788, -225,
- 47, -1000, -1000, 50, -1000, -1000, -1000, 788, -1000, -253,
- 53, -228, 1254, -38, -1000, 788, 788, 788, 936, -1000,
- 936, 1101, 2, 942, -1000, 289, 825, 1408, -1000, -1000,
- -8, -253, 50, 6, -1000, -1000, -1000, -1000, 283, 1387,
- 50, 660, 1387, -43, 1408, 936, -43, 283, -253, -236,
- -1000, -1000, 619, -253, 1387, 50, -1000, 936, -1000, -259,
- -1000, -1000, -1000, -253, 283, 50, -253, -253, -1000, -1000,
- -253, 283, 283, 283, -1000, -1000, -1000 };
-int yypgo[]={
-
- 0, 160, 159, 420, 0, 157, 156, 104, 502, 107,
- 154, 153, 105, 98, 151, 150, 149, 216, 66, 75,
- 68, 140, 139, 48, 63, 1003, 40, 67, 138, 137,
- 136, 546, 126, 125, 1720, 124, 1400, 686, 41, 64,
- 32, 121, 1664, 1628, 120, 115, 111, 109 };
-int yyr1[]={
-
- 0, 5, 6, 6, 6, 6, 32, 7, 33, 7,
- 7, 7, 7, 7, 7, 7, 29, 29, 29, 30,
- 30, 35, 1, 2, 11, 11, 41, 25, 12, 12,
- 19, 19, 19, 19, 34, 34, 20, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 20, 44, 20, 20, 20, 28, 28, 21, 21, 42,
- 42, 31, 31, 26, 26, 27, 27, 27, 27, 22,
- 22, 14, 14, 14, 14, 14, 23, 23, 16, 16,
- 15, 15, 15, 15, 15, 15, 18, 18, 17, 17,
- 17, 17, 17, 17, 45, 4, 4, 4, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 46, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 8, 8, 8, 8, 8, 8,
- 8, 8, 9, 9, 47, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 10, 10, 10, 24, 24,
- 13, 13, 13, 13, 37, 38, 36, 39, 39, 43,
- 40 };
-int yyr2[]={
-
- 0, 7, 3, 5, 3, 5, 1, 7, 1, 7,
- 5, 5, 5, 3, 5, 5, 3, 3, 3, 2,
- 2, 1, 15, 9, 3, 7, 1, 9, 11, 9,
- 3, 5, 3, 5, 2, 4, 5, 5, 7, 3,
- 13, 17, 17, 21, 19, 5, 5, 13, 9, 7,
- 7, 1, 9, 13, 5, 3, 3, 13, 19, 3,
- 4, 0, 2, 1, 5, 1, 5, 5, 5, 1,
- 3, 3, 7, 3, 5, 7, 1, 3, 1, 3,
- 3, 7, 3, 5, 7, 7, 1, 3, 3, 7,
- 3, 5, 7, 7, 1, 9, 11, 9, 7, 7,
- 7, 7, 3, 5, 7, 7, 7, 7, 11, 3,
- 5, 1, 9, 7, 7, 7, 3, 5, 7, 7,
- 7, 11, 3, 5, 2, 2, 7, 7, 7, 7,
- 7, 7, 5, 7, 1, 11, 9, 3, 9, 5,
- 5, 3, 3, 5, 5, 5, 5, 2, 1, 3,
- 3, 9, 5, 5, 4, 5, 3, 0, 2, 3,
- 5 };
-int yychk[]={
-
- -1000, -5, -31, -42, 267, -6, -7, 256, 269, 270,
- -11, -12, -1, -4, -37, 284, -13, 40, 285, -25,
- 33, -8, 123, 258, 36, 47, -9, -10, 291, 292,
- 257, 289, 290, 261, 262, 45, 43, 267, -31, -7,
- 256, -32, -34, -42, -43, 59, -33, -34, -12, -34,
- -2, -37, -40, 124, 287, 288, 266, 286, 263, 60,
- 62, 63, -4, 44, -19, -38, -20, 256, 125, -43,
- -37, -21, 275, 276, 277, 278, 279, -28, 282, 283,
- 273, 274, -4, 271, 280, 281, -35, 265, 289, 290,
- -17, -4, 256, -24, -13, -25, -8, 33, 40, -13,
- 94, 42, 47, 37, 43, 45, -31, 91, -9, -13,
- -41, -47, 40, 40, -13, -13, -8, -8, -12, -31,
- -12, -19, -4, 285, -4, -4, -4, 258, -4, -4,
- -4, -4, -31, -38, -20, 256, -39, -43, -31, -31,
- -38, -19, 40, -31, 40, -34, -34, 40, -16, -15,
- -3, 256, -13, 285, -25, 33, -8, -23, -4, -23,
- -44, 258, -34, 40, -29, 258, 257, -30, 291, 292,
- -45, -40, 256, -36, 41, -36, -26, 60, -4, -8,
- -8, -8, -8, -8, -8, -17, -4, 259, 40, -18,
- -17, -18, -38, -24, 58, -39, -31, -38, -4, -20,
- 258, -23, -17, -27, 62, 264, 124, -40, 256, 287,
- 288, 266, 286, 263, 63, -3, 265, -24, -25, -34,
- -34, -23, 91, -4, 40, -4, -4, 256, -4, 286,
- -8, 93, 47, -18, -36, -36, -39, -4, -31, -36,
- 275, 286, -43, -36, -34, -4, -4, -4, -3, 256,
- -3, -3, -3, -3, 258, -3, -3, -46, -26, -34,
- -17, -36, -22, -14, 258, 256, 258, -36, -31, 40,
- 258, -4, -43, -27, 58, -3, 93, -31, -36, -40,
- 256, -20, -4, -36, -43, -23, -34, -3, -34, -20,
- -31, 258, 256, -36, -31, -23, -36, 272, -31, -20,
- -36, -31, -31, -31, -20, -20, -20 };
-int yydef[]={
-
- 61, -2, 0, 62, 59, -2, 2, 4, 6, 8,
- 0, 13, 0, 24, 0, 21, 147, 0, 148, 102,
- 0, 109, 61, 150, 0, 26, 124, 125, 134, 137,
- 0, 0, 0, 141, 142, 0, 0, 60, 1, 3,
- 5, 0, 10, 34, 61, 159, 0, 11, 12, 14,
- 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 110, 61, 0, 157, 30, 32, 61, 61,
- 0, 39, 0, 61, 0, 0, 0, -2, 76, 76,
- 51, 0, 0, 0, 55, 56, 0, 94, 145, 146,
- 0, 88, 90, 63, 149, 103, 132, 0, 0, 147,
- 0, 0, 0, 0, 0, 0, 154, 0, 152, 153,
- 0, 0, -2, -2, 139, 140, 143, 144, 7, 35,
- 9, 0, 25, 148, 99, 100, -2, 104, -2, -2,
- -2, 0, 160, 157, 31, 33, 61, 158, 155, 36,
- 37, 0, 0, 0, 76, 45, 46, 0, 65, -2,
- 80, 82, 147, 148, 116, 0, 122, 0, 77, 0,
- 76, 0, 54, 0, 0, 16, 17, 18, 19, 20,
- 0, 0, 91, 0, 156, 133, 98, 0, 0, 126,
- 127, 128, 129, 130, 131, 0, 88, 0, -2, 0,
- -2, 0, 157, 97, 0, 61, 29, 38, 0, 0,
- 150, 0, 0, 0, 0, 0, 0, 0, 83, 0,
- 0, 0, 0, 0, 0, 123, 111, 63, 117, 49,
- 50, 0, 0, 0, -2, 95, 89, 93, 92, 0,
- 64, 151, 27, 0, 136, 138, 23, 108, 28, 61,
- 0, 0, 0, 65, 48, 66, 67, 68, 81, 85,
- 84, 113, 114, -2, 119, -2, 0, 0, 115, 52,
- 0, 61, 0, -2, 71, 73, 96, 135, 0, 0,
- 0, 0, 76, 0, 0, 112, 0, 0, 61, 0,
- 74, 40, 0, 61, 76, 0, 47, 121, 53, 57,
- 22, 72, 75, 61, 0, 0, 61, 61, 41, 42,
- 61, 0, 0, 0, 44, 58, 43 };
-typedef struct { char *t_name; int t_val; } yytoktype;
-#ifndef YYDEBUG
-# define YYDEBUG 0 /* don't allow debugging */
-#endif
-
-#if YYDEBUG
-
-yytoktype yytoks[] =
-{
- "FUNC_CALL", 257,
- "NAME", 258,
- "REGEXP", 259,
- "ERROR", 260,
- "YNUMBER", 261,
- "YSTRING", 262,
- "RELOP", 263,
- "APPEND_OP", 264,
- "ASSIGNOP", 265,
- "MATCHOP", 266,
- "NEWLINE", 267,
- "CONCAT_OP", 268,
- "LEX_BEGIN", 269,
- "LEX_END", 270,
- "LEX_IF", 271,
- "LEX_ELSE", 272,
- "LEX_RETURN", 273,
- "LEX_DELETE", 274,
- "LEX_WHILE", 275,
- "LEX_DO", 276,
- "LEX_FOR", 277,
- "LEX_BREAK", 278,
- "LEX_CONTINUE", 279,
- "LEX_PRINT", 280,
- "LEX_PRINTF", 281,
- "LEX_NEXT", 282,
- "LEX_EXIT", 283,
- "LEX_FUNCTION", 284,
- "LEX_GETLINE", 285,
- "LEX_IN", 286,
- "LEX_AND", 287,
- "LEX_OR", 288,
- "INCREMENT", 289,
- "DECREMENT", 290,
- "LEX_BUILTIN", 291,
- "LEX_LENGTH", 292,
- "?", 63,
- ":", 58,
- "<", 60,
- ">", 62,
- "|", 124,
- "+", 43,
- "-", 45,
- "*", 42,
- "/", 47,
- "%", 37,
- "!", 33,
- "UNARY", 293,
- "^", 94,
- "$", 36,
- "(", 40,
- ")", 41,
- "-unknown-", -1 /* ends search */
-};
-
-char * yyreds[] =
-{
- "-no such reduction-",
- "start : opt_nls program opt_nls",
- "program : rule",
- "program : program rule",
- "program : error",
- "program : program error",
- "rule : LEX_BEGIN",
- "rule : LEX_BEGIN action",
- "rule : LEX_END",
- "rule : LEX_END action",
- "rule : LEX_BEGIN statement_term",
- "rule : LEX_END statement_term",
- "rule : pattern action",
- "rule : action",
- "rule : pattern statement_term",
- "rule : function_prologue function_body",
- "func_name : NAME",
- "func_name : FUNC_CALL",
- "func_name : lex_builtin",
- "lex_builtin : LEX_BUILTIN",
- "lex_builtin : LEX_LENGTH",
- "function_prologue : LEX_FUNCTION",
- "function_prologue : LEX_FUNCTION func_name '(' opt_param_list r_paren opt_nls",
- "function_body : l_brace statements r_brace opt_semi",
- "pattern : exp",
- "pattern : exp comma exp",
- "regexp : '/'",
- "regexp : '/' REGEXP '/'",
- "action : l_brace statements r_brace opt_semi opt_nls",
- "action : l_brace r_brace opt_semi opt_nls",
- "statements : statement",
- "statements : statements statement",
- "statements : error",
- "statements : statements error",
- "statement_term : nls",
- "statement_term : semi opt_nls",
- "statement : semi opt_nls",
- "statement : l_brace r_brace",
- "statement : l_brace statements r_brace",
- "statement : if_statement",
- "statement : LEX_WHILE '(' exp r_paren opt_nls statement",
- "statement : LEX_DO opt_nls statement LEX_WHILE '(' exp r_paren opt_nls",
- "statement : LEX_FOR '(' NAME LEX_IN NAME r_paren opt_nls statement",
- "statement : LEX_FOR '(' opt_exp semi exp semi opt_exp r_paren opt_nls statement",
- "statement : LEX_FOR '(' opt_exp semi semi opt_exp r_paren opt_nls statement",
- "statement : LEX_BREAK statement_term",
- "statement : LEX_CONTINUE statement_term",
- "statement : print '(' expression_list r_paren output_redir statement_term",
- "statement : print opt_rexpression_list output_redir statement_term",
- "statement : LEX_NEXT opt_exp statement_term",
- "statement : LEX_EXIT opt_exp statement_term",
- "statement : LEX_RETURN",
- "statement : LEX_RETURN opt_exp statement_term",
- "statement : LEX_DELETE NAME '[' expression_list ']' statement_term",
- "statement : exp statement_term",
- "print : LEX_PRINT",
- "print : LEX_PRINTF",
- "if_statement : LEX_IF '(' exp r_paren opt_nls statement",
- "if_statement : LEX_IF '(' exp r_paren opt_nls statement LEX_ELSE opt_nls statement",
- "nls : NEWLINE",
- "nls : nls NEWLINE",
- "opt_nls : /* empty */",
- "opt_nls : nls",
- "input_redir : /* empty */",
- "input_redir : '<' simp_exp",
- "output_redir : /* empty */",
- "output_redir : '>' exp",
- "output_redir : APPEND_OP exp",
- "output_redir : '|' exp",
- "opt_param_list : /* empty */",
- "opt_param_list : param_list",
- "param_list : NAME",
- "param_list : param_list comma NAME",
- "param_list : error",
- "param_list : param_list error",
- "param_list : param_list comma error",
- "opt_exp : /* empty */",
- "opt_exp : exp",
- "opt_rexpression_list : /* empty */",
- "opt_rexpression_list : rexpression_list",
- "rexpression_list : rexp",
- "rexpression_list : rexpression_list comma rexp",
- "rexpression_list : error",
- "rexpression_list : rexpression_list error",
- "rexpression_list : rexpression_list error rexp",
- "rexpression_list : rexpression_list comma error",
- "opt_expression_list : /* empty */",
- "opt_expression_list : expression_list",
- "expression_list : exp",
- "expression_list : expression_list comma exp",
- "expression_list : error",
- "expression_list : expression_list error",
- "expression_list : expression_list error exp",
- "expression_list : expression_list comma error",
- "exp : variable ASSIGNOP",
- "exp : variable ASSIGNOP exp",
- "exp : '(' expression_list r_paren LEX_IN NAME",
- "exp : exp '|' LEX_GETLINE opt_variable",
- "exp : LEX_GETLINE opt_variable input_redir",
- "exp : exp LEX_AND exp",
- "exp : exp LEX_OR exp",
- "exp : exp MATCHOP exp",
- "exp : regexp",
- "exp : '!' regexp",
- "exp : exp LEX_IN NAME",
- "exp : exp RELOP exp",
- "exp : exp '<' exp",
- "exp : exp '>' exp",
- "exp : exp '?' exp ':' exp",
- "exp : simp_exp",
- "exp : exp exp",
- "rexp : variable ASSIGNOP",
- "rexp : variable ASSIGNOP rexp",
- "rexp : rexp LEX_AND rexp",
- "rexp : rexp LEX_OR rexp",
- "rexp : LEX_GETLINE opt_variable input_redir",
- "rexp : regexp",
- "rexp : '!' regexp",
- "rexp : rexp MATCHOP rexp",
- "rexp : rexp LEX_IN NAME",
- "rexp : rexp RELOP rexp",
- "rexp : rexp '?' rexp ':' rexp",
- "rexp : simp_exp",
- "rexp : rexp rexp",
- "simp_exp : non_post_simp_exp",
- "simp_exp : post_inc_dec_exp",
- "simp_exp : simp_exp '^' simp_exp",
- "simp_exp : simp_exp '*' simp_exp",
- "simp_exp : simp_exp '/' simp_exp",
- "simp_exp : simp_exp '%' simp_exp",
- "simp_exp : simp_exp '+' simp_exp",
- "simp_exp : simp_exp '-' simp_exp",
- "non_post_simp_exp : '!' simp_exp",
- "non_post_simp_exp : '(' exp r_paren",
- "non_post_simp_exp : LEX_BUILTIN",
- "non_post_simp_exp : LEX_BUILTIN '(' opt_expression_list r_paren",
- "non_post_simp_exp : LEX_LENGTH '(' opt_expression_list r_paren",
- "non_post_simp_exp : LEX_LENGTH",
- "non_post_simp_exp : FUNC_CALL '(' opt_expression_list r_paren",
- "non_post_simp_exp : INCREMENT variable",
- "non_post_simp_exp : DECREMENT variable",
- "non_post_simp_exp : YNUMBER",
- "non_post_simp_exp : YSTRING",
- "non_post_simp_exp : '-' simp_exp",
- "non_post_simp_exp : '+' simp_exp",
- "post_inc_dec_exp : variable INCREMENT",
- "post_inc_dec_exp : variable DECREMENT",
- "post_inc_dec_exp : variable",
- "opt_variable : /* empty */",
- "opt_variable : variable",
- "variable : NAME",
- "variable : NAME '[' expression_list ']'",
- "variable : '$' non_post_simp_exp",
- "variable : '$' variable",
- "l_brace : '{' opt_nls",
- "r_brace : '}' opt_nls",
- "r_paren : ')'",
- "opt_semi : /* empty */",
- "opt_semi : semi",
- "semi : ';'",
- "comma : ',' opt_nls",
-};
-#endif /* YYDEBUG */
-#line 1 "/usr/lib/yaccpar"
-/* @(#)yaccpar 1.10 89/04/04 SMI; from S5R3 1.10 */
-
-/*
-** Skeleton parser driver for yacc output
-*/
-
-/*
-** yacc user known macros and defines
-*/
-#define YYERROR goto yyerrlab
-#define YYACCEPT { free(yys); free(yyv); return(0); }
-#define YYABORT { free(yys); free(yyv); return(1); }
-#define YYBACKUP( newtoken, newvalue )\
-{\
- if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
- {\
- yyerror( "syntax error - cannot backup" );\
- goto yyerrlab;\
- }\
- yychar = newtoken;\
- yystate = *yyps;\
- yylval = newvalue;\
- goto yynewstate;\
-}
-#define YYRECOVERING() (!!yyerrflag)
-#ifndef YYDEBUG
-# define YYDEBUG 1 /* make debugging available */
-#endif
-
-/*
-** user known globals
-*/
-int yydebug; /* set to 1 to get debugging */
-
-/*
-** driver internal defines
-*/
-#define YYFLAG (-1000)
-
-/*
-** static variables used by the parser
-*/
-static YYSTYPE *yyv; /* value stack */
-static int *yys; /* state stack */
-
-static YYSTYPE *yypv; /* top of value stack */
-static int *yyps; /* top of state stack */
-
-static int yystate; /* current state */
-static int yytmp; /* extra var (lasts between blocks) */
-
-int yynerrs; /* number of errors */
-
-int yyerrflag; /* error recovery flag */
-int yychar; /* current input token number */
-
-
-/*
-** yyparse - return 0 if worked, 1 if syntax error not recovered from
-*/
-int
-yyparse()
-{
- register YYSTYPE *yypvt; /* top of value stack for $vars */
- unsigned yymaxdepth = YYMAXDEPTH;
-
- /*
- ** Initialize externals - yyparse may be called more than once
- */
- yyv = (YYSTYPE*)malloc(yymaxdepth*sizeof(YYSTYPE));
- yys = (int*)malloc(yymaxdepth*sizeof(int));
- if (!yyv || !yys)
- {
- yyerror( "out of memory" );
- return(1);
- }
- yypv = &yyv[-1];
- yyps = &yys[-1];
- yystate = 0;
- yytmp = 0;
- yynerrs = 0;
- yyerrflag = 0;
- yychar = -1;
-
- goto yystack;
- {
- register YYSTYPE *yy_pv; /* top of value stack */
- register int *yy_ps; /* top of state stack */
- register int yy_state; /* current state */
- register int yy_n; /* internal state number info */
-
- /*
- ** get globals into registers.
- ** branch to here only if YYBACKUP was called.
- */
- yynewstate:
- yy_pv = yypv;
- yy_ps = yyps;
- yy_state = yystate;
- goto yy_newstate;
-
- /*
- ** get globals into registers.
- ** either we just started, or we just finished a reduction
- */
- yystack:
- yy_pv = yypv;
- yy_ps = yyps;
- yy_state = yystate;
-
- /*
- ** top of for (;;) loop while no reductions done
- */
- yy_stack:
- /*
- ** put a state and value onto the stacks
- */
-#if YYDEBUG
- /*
- ** if debugging, look up token value in list of value vs.
- ** name pairs. 0 and negative (-1) are special values.
- ** Note: linear search is used since time is not a real
- ** consideration while debugging.
- */
- if ( yydebug )
- {
- register int yy_i;
-
- (void)printf( "State %d, token ", yy_state );
- if ( yychar == 0 )
- (void)printf( "end-of-file\n" );
- else if ( yychar < 0 )
- (void)printf( "-none-\n" );
- else
- {
- for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
- yy_i++ )
- {
- if ( yytoks[yy_i].t_val == yychar )
- break;
- }
- (void)printf( "%s\n", yytoks[yy_i].t_name );
- }
- }
-#endif /* YYDEBUG */
- if ( ++yy_ps >= &yys[ yymaxdepth ] ) /* room on stack? */
- {
- /*
- ** reallocate and recover. Note that pointers
- ** have to be reset, or bad things will happen
- */
- int yyps_index = (yy_ps - yys);
- int yypv_index = (yy_pv - yyv);
- int yypvt_index = (yypvt - yyv);
- yymaxdepth += YYMAXDEPTH;
- yyv = (YYSTYPE*)realloc((char*)yyv,
- yymaxdepth * sizeof(YYSTYPE));
- yys = (int*)realloc((char*)yys,
- yymaxdepth * sizeof(int));
- if (!yyv || !yys)
- {
- yyerror( "yacc stack overflow" );
- return(1);
- }
- yy_ps = yys + yyps_index;
- yy_pv = yyv + yypv_index;
- yypvt = yyv + yypvt_index;
- }
- *yy_ps = yy_state;
- *++yy_pv = yyval;
-
- /*
- ** we have a new state - find out what to do
- */
- yy_newstate:
- if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG )
- goto yydefault; /* simple state */
-#if YYDEBUG
- /*
- ** if debugging, need to mark whether new token grabbed
- */
- yytmp = yychar < 0;
-#endif
- if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
- yychar = 0; /* reached EOF */
-#if YYDEBUG
- if ( yydebug && yytmp )
- {
- register int yy_i;
-
- (void)printf( "Received token " );
- if ( yychar == 0 )
- (void)printf( "end-of-file\n" );
- else if ( yychar < 0 )
- (void)printf( "-none-\n" );
- else
- {
- for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
- yy_i++ )
- {
- if ( yytoks[yy_i].t_val == yychar )
- break;
- }
- (void)printf( "%s\n", yytoks[yy_i].t_name );
- }
- }
-#endif /* YYDEBUG */
- if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) )
- goto yydefault;
- if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar ) /*valid shift*/
- {
- yychar = -1;
- yyval = yylval;
- yy_state = yy_n;
- if ( yyerrflag > 0 )
- yyerrflag--;
- goto yy_stack;
- }
-
- yydefault:
- if ( ( yy_n = yydef[ yy_state ] ) == -2 )
- {
-#if YYDEBUG
- yytmp = yychar < 0;
-#endif
- if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
- yychar = 0; /* reached EOF */
-#if YYDEBUG
- if ( yydebug && yytmp )
- {
- register int yy_i;
-
- (void)printf( "Received token " );
- if ( yychar == 0 )
- (void)printf( "end-of-file\n" );
- else if ( yychar < 0 )
- (void)printf( "-none-\n" );
- else
- {
- for ( yy_i = 0;
- yytoks[yy_i].t_val >= 0;
- yy_i++ )
- {
- if ( yytoks[yy_i].t_val
- == yychar )
- {
- break;
- }
- }
- (void)printf( "%s\n", yytoks[yy_i].t_name );
- }
- }
-#endif /* YYDEBUG */
- /*
- ** look through exception table
- */
- {
- register int *yyxi = yyexca;
-
- while ( ( *yyxi != -1 ) ||
- ( yyxi[1] != yy_state ) )
- {
- yyxi += 2;
- }
- while ( ( *(yyxi += 2) >= 0 ) &&
- ( *yyxi != yychar ) )
- ;
- if ( ( yy_n = yyxi[1] ) < 0 )
- YYACCEPT;
- }
- }
-
- /*
- ** check for syntax error
- */
- if ( yy_n == 0 ) /* have an error */
- {
- /* no worry about speed here! */
- switch ( yyerrflag )
- {
- case 0: /* new error */
- yyerror( "syntax error" );
- goto skip_init;
- yyerrlab:
- /*
- ** get globals into registers.
- ** we have a user generated syntax type error
- */
- yy_pv = yypv;
- yy_ps = yyps;
- yy_state = yystate;
- yynerrs++;
- skip_init:
- case 1:
- case 2: /* incompletely recovered error */
- /* try again... */
- yyerrflag = 3;
- /*
- ** find state where "error" is a legal
- ** shift action
- */
- while ( yy_ps >= yys )
- {
- yy_n = yypact[ *yy_ps ] + YYERRCODE;
- if ( yy_n >= 0 && yy_n < YYLAST &&
- yychk[yyact[yy_n]] == YYERRCODE) {
- /*
- ** simulate shift of "error"
- */
- yy_state = yyact[ yy_n ];
- goto yy_stack;
- }
- /*
- ** current state has no shift on
- ** "error", pop stack
- */
-#if YYDEBUG
-# define _POP_ "Error recovery pops state %d, uncovers state %d\n"
- if ( yydebug )
- (void)printf( _POP_, *yy_ps,
- yy_ps[-1] );
-# undef _POP_
-#endif
- yy_ps--;
- yy_pv--;
- }
- /*
- ** there is no state on stack with "error" as
- ** a valid shift. give up.
- */
- YYABORT;
- case 3: /* no shift yet; eat a token */
-#if YYDEBUG
- /*
- ** if debugging, look up token in list of
- ** pairs. 0 and negative shouldn't occur,
- ** but since timing doesn't matter when
- ** debugging, it doesn't hurt to leave the
- ** tests here.
- */
- if ( yydebug )
- {
- register int yy_i;
-
- (void)printf( "Error recovery discards " );
- if ( yychar == 0 )
- (void)printf( "token end-of-file\n" );
- else if ( yychar < 0 )
- (void)printf( "token -none-\n" );
- else
- {
- for ( yy_i = 0;
- yytoks[yy_i].t_val >= 0;
- yy_i++ )
- {
- if ( yytoks[yy_i].t_val
- == yychar )
- {
- break;
- }
- }
- (void)printf( "token %s\n",
- yytoks[yy_i].t_name );
- }
- }
-#endif /* YYDEBUG */
- if ( yychar == 0 ) /* reached EOF. quit */
- YYABORT;
- yychar = -1;
- goto yy_newstate;
- }
- }/* end if ( yy_n == 0 ) */
- /*
- ** reduction by production yy_n
- ** put stack tops, etc. so things right after switch
- */
-#if YYDEBUG
- /*
- ** if debugging, print the string that is the user's
- ** specification of the reduction which is just about
- ** to be done.
- */
- if ( yydebug )
- (void)printf( "Reduce by (%d) \"%s\"\n",
- yy_n, yyreds[ yy_n ] );
-#endif
- yytmp = yy_n; /* value to switch over */
- yypvt = yy_pv; /* $vars top of value stack */
- /*
- ** Look in goto table for next state
- ** Sorry about using yy_state here as temporary
- ** register variable, but why not, if it works...
- ** If yyr2[ yy_n ] doesn't have the low order bit
- ** set, then there is no action to be done for
- ** this reduction. So, no saving & unsaving of
- ** registers done. The only difference between the
- ** code just after the if and the body of the if is
- ** the goto yy_stack in the body. This way the test
- ** can be made before the choice of what to do is needed.
- */
- {
- /* length of production doubled with extra bit */
- register int yy_len = yyr2[ yy_n ];
-
- if ( !( yy_len & 01 ) )
- {
- yy_len >>= 1;
- yyval = ( yy_pv -= yy_len )[1]; /* $$ = $1 */
- yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
- *( yy_ps -= yy_len ) + 1;
- if ( yy_state >= YYLAST ||
- yychk[ yy_state =
- yyact[ yy_state ] ] != -yy_n )
- {
- yy_state = yyact[ yypgo[ yy_n ] ];
- }
- goto yy_stack;
- }
- yy_len >>= 1;
- yyval = ( yy_pv -= yy_len )[1]; /* $$ = $1 */
- yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
- *( yy_ps -= yy_len ) + 1;
- if ( yy_state >= YYLAST ||
- yychk[ yy_state = yyact[ yy_state ] ] != -yy_n )
- {
- yy_state = yyact[ yypgo[ yy_n ] ];
- }
- }
- /* save until reenter driver code */
- yystate = yy_state;
- yyps = yy_ps;
- yypv = yy_pv;
- }
- /*
- ** code supplied by user is placed in this switch
- */
- switch( yytmp )
- {
-
-case 1:
-# line 137 "awk.y"
-{ expression_value = yypvt[-1].nodeval; } break;
-case 2:
-# line 142 "awk.y"
-{
- if (yypvt[-0].nodeval != NULL)
- yyval.nodeval = yypvt[-0].nodeval;
- else
- yyval.nodeval = NULL;
- yyerrok;
- } break;
-case 3:
-# line 151 "awk.y"
-{
- if (yypvt[-0].nodeval == NULL)
- yyval.nodeval = yypvt[-1].nodeval;
- else if (yypvt[-1].nodeval == NULL)
- yyval.nodeval = yypvt[-0].nodeval;
- else {
- if (yypvt[-1].nodeval->type != Node_rule_list)
- yypvt[-1].nodeval = node(yypvt[-1].nodeval, Node_rule_list,
- (NODE*)NULL);
- yyval.nodeval = append_right (yypvt[-1].nodeval,
- node(yypvt[-0].nodeval, Node_rule_list,(NODE *) NULL));
- }
- yyerrok;
- } break;
-case 4:
-# line 165 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 5:
-# line 166 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 6:
-# line 170 "awk.y"
-{ io_allowed = 0; } break;
-case 7:
-# line 172 "awk.y"
-{
- if (begin_block) {
- if (begin_block->type != Node_rule_list)
- begin_block = node(begin_block, Node_rule_list,
- (NODE *)NULL);
- (void) append_right (begin_block, node(
- node((NODE *)NULL, Node_rule_node, yypvt[-0].nodeval),
- Node_rule_list, (NODE *)NULL) );
- } else
- begin_block = node((NODE *)NULL, Node_rule_node, yypvt[-0].nodeval);
- yyval.nodeval = NULL;
- io_allowed = 1;
- yyerrok;
- } break;
-case 8:
-# line 186 "awk.y"
-{ io_allowed = 0; } break;
-case 9:
-# line 188 "awk.y"
-{
- if (end_block) {
- if (end_block->type != Node_rule_list)
- end_block = node(end_block, Node_rule_list,
- (NODE *)NULL);
- (void) append_right (end_block, node(
- node((NODE *)NULL, Node_rule_node, yypvt[-0].nodeval),
- Node_rule_list, (NODE *)NULL));
- } else
- end_block = node((NODE *)NULL, Node_rule_node, yypvt[-0].nodeval);
- yyval.nodeval = NULL;
- io_allowed = 1;
- yyerrok;
- } break;
-case 10:
-# line 203 "awk.y"
-{
- warning("BEGIN blocks must have an action part");
- errcount++;
- yyerrok;
- } break;
-case 11:
-# line 209 "awk.y"
-{
- warning("END blocks must have an action part");
- errcount++;
- yyerrok;
- } break;
-case 12:
-# line 215 "awk.y"
-{ yyval.nodeval = node (yypvt[-1].nodeval, Node_rule_node, yypvt[-0].nodeval); yyerrok; } break;
-case 13:
-# line 217 "awk.y"
-{ yyval.nodeval = node ((NODE *)NULL, Node_rule_node, yypvt[-0].nodeval); yyerrok; } break;
-case 14:
-# line 219 "awk.y"
-{
- yyval.nodeval = node (yypvt[-1].nodeval,
- Node_rule_node,
- node(node(node(make_number(0.0),
- Node_field_spec,
- (NODE *) NULL),
- Node_expression_list,
- (NODE *) NULL),
- Node_K_print,
- (NODE *) NULL));
- yyerrok;
- } break;
-case 15:
-# line 232 "awk.y"
-{
- func_install(yypvt[-1].nodeval, yypvt[-0].nodeval);
- yyval.nodeval = NULL;
- yyerrok;
- } break;
-case 16:
-# line 241 "awk.y"
-{ yyval.sval = yypvt[-0].sval; } break;
-case 17:
-# line 243 "awk.y"
-{ yyval.sval = yypvt[-0].sval; } break;
-case 18:
-# line 245 "awk.y"
-{
- yyerror("%s() is a built-in function, it cannot be redefined",
- tokstart);
- errcount++;
- /* yyerrok; */
- } break;
-case 21:
-# line 260 "awk.y"
-{
- param_counter = 0;
- } break;
-case 22:
-# line 264 "awk.y"
-{
- yyval.nodeval = append_right(make_param(yypvt[-4].sval), yypvt[-2].nodeval);
- can_return = 1;
- } break;
-case 23:
-# line 272 "awk.y"
-{
- yyval.nodeval = yypvt[-2].nodeval;
- can_return = 0;
- } break;
-case 24:
-# line 281 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 25:
-# line 283 "awk.y"
-{ yyval.nodeval = mkrangenode ( node(yypvt[-2].nodeval, Node_cond_pair, yypvt[-0].nodeval) ); } break;
-case 26:
-# line 292 "awk.y"
-{ ++want_regexp; } break;
-case 27:
-# line 294 "awk.y"
-{
- NODE *n;
-
- getnode(n);
- n->type = Node_regex;
- n->re_exp = make_string(yypvt[-1].sval, strlen(yypvt[-1].sval));
- n->re_reg = mk_re_parse(yypvt[-1].sval, 0);
- n->re_text = NULL;
- n->re_flags = CONST;
- n->re_cnt = 1;
- yyval.nodeval = n;
- } break;
-case 28:
-# line 310 "awk.y"
-{ yyval.nodeval = yypvt[-3].nodeval ; } break;
-case 29:
-# line 312 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 30:
-# line 317 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 31:
-# line 319 "awk.y"
-{
- if (yypvt[-1].nodeval == NULL || yypvt[-1].nodeval->type != Node_statement_list)
- yypvt[-1].nodeval = node(yypvt[-1].nodeval, Node_statement_list,(NODE *)NULL);
- yyval.nodeval = append_right(yypvt[-1].nodeval,
- node( yypvt[-0].nodeval, Node_statement_list, (NODE *)NULL));
- yyerrok;
- } break;
-case 32:
-# line 327 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 33:
-# line 329 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 36:
-# line 339 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 37:
-# line 341 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 38:
-# line 343 "awk.y"
-{ yyval.nodeval = yypvt[-1].nodeval; } break;
-case 39:
-# line 345 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 40:
-# line 347 "awk.y"
-{ yyval.nodeval = node (yypvt[-3].nodeval, Node_K_while, yypvt[-0].nodeval); } break;
-case 41:
-# line 349 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_K_do, yypvt[-5].nodeval); } break;
-case 42:
-# line 351 "awk.y"
-{
- yyval.nodeval = node (yypvt[-0].nodeval, Node_K_arrayfor, make_for_loop(variable(yypvt[-5].sval,1),
- (NODE *)NULL, variable(yypvt[-3].sval,1)));
- } break;
-case 43:
-# line 356 "awk.y"
-{
- yyval.nodeval = node(yypvt[-0].nodeval, Node_K_for, (NODE *)make_for_loop(yypvt[-7].nodeval, yypvt[-5].nodeval, yypvt[-3].nodeval));
- } break;
-case 44:
-# line 360 "awk.y"
-{
- yyval.nodeval = node (yypvt[-0].nodeval, Node_K_for,
- (NODE *)make_for_loop(yypvt[-6].nodeval, (NODE *)NULL, yypvt[-3].nodeval));
- } break;
-case 45:
-# line 366 "awk.y"
-{ yyval.nodeval = node ((NODE *)NULL, Node_K_break, (NODE *)NULL); } break;
-case 46:
-# line 369 "awk.y"
-{ yyval.nodeval = node ((NODE *)NULL, Node_K_continue, (NODE *)NULL); } break;
-case 47:
-# line 371 "awk.y"
-{ yyval.nodeval = node (yypvt[-3].nodeval, yypvt[-5].nodetypeval, yypvt[-1].nodeval); } break;
-case 48:
-# line 373 "awk.y"
-{
- if (yypvt[-3].nodetypeval == Node_K_print && yypvt[-2].nodeval == NULL)
- yypvt[-2].nodeval = node(node(make_number(0.0),
- Node_field_spec,
- (NODE *) NULL),
- Node_expression_list,
- (NODE *) NULL);
-
- yyval.nodeval = node (yypvt[-2].nodeval, yypvt[-3].nodetypeval, yypvt[-1].nodeval);
- } break;
-case 49:
-# line 384 "awk.y"
-{ NODETYPE type;
-
- if (! io_allowed) yyerror("next used in BEGIN or END action");
- if (yypvt[-1].nodeval && yypvt[-1].nodeval == lookup("file")) {
- if (do_lint)
- warning("`next file' is a gawk extension");
- else if (strict || do_posix)
- yyerror("`next file' is a gawk extension");
- type = Node_K_nextfile;
- } else type = Node_K_next;
- yyval.nodeval = node ((NODE *)NULL, type, (NODE *)NULL);
- } break;
-case 50:
-# line 397 "awk.y"
-{ yyval.nodeval = node (yypvt[-1].nodeval, Node_K_exit, (NODE *)NULL); } break;
-case 51:
-# line 399 "awk.y"
-{ if (! can_return) yyerror("return used outside function context"); } break;
-case 52:
-# line 401 "awk.y"
-{ yyval.nodeval = node (yypvt[-1].nodeval, Node_K_return, (NODE *)NULL); } break;
-case 53:
-# line 403 "awk.y"
-{ yyval.nodeval = node (variable(yypvt[-4].sval,1), Node_K_delete, yypvt[-2].nodeval); } break;
-case 54:
-# line 405 "awk.y"
-{ yyval.nodeval = yypvt[-1].nodeval; } break;
-case 55:
-# line 410 "awk.y"
-{ yyval.nodetypeval = yypvt[-0].nodetypeval; } break;
-case 56:
-# line 412 "awk.y"
-{ yyval.nodetypeval = yypvt[-0].nodetypeval; } break;
-case 57:
-# line 417 "awk.y"
-{
- yyval.nodeval = node(yypvt[-3].nodeval, Node_K_if,
- node(yypvt[-0].nodeval, Node_if_branches, (NODE *)NULL));
- } break;
-case 58:
-# line 423 "awk.y"
-{ yyval.nodeval = node (yypvt[-6].nodeval, Node_K_if,
- node (yypvt[-3].nodeval, Node_if_branches, yypvt[-0].nodeval)); } break;
-case 59:
-# line 429 "awk.y"
-{ want_assign = 0; } break;
-case 63:
-# line 440 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 64:
-# line 442 "awk.y"
-{ yyval.nodeval = node (yypvt[-0].nodeval, Node_redirect_input, (NODE *)NULL); } break;
-case 65:
-# line 447 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 66:
-# line 449 "awk.y"
-{ yyval.nodeval = node (yypvt[-0].nodeval, Node_redirect_output, (NODE *)NULL); } break;
-case 67:
-# line 451 "awk.y"
-{ yyval.nodeval = node (yypvt[-0].nodeval, Node_redirect_append, (NODE *)NULL); } break;
-case 68:
-# line 453 "awk.y"
-{ yyval.nodeval = node (yypvt[-0].nodeval, Node_redirect_pipe, (NODE *)NULL); } break;
-case 69:
-# line 458 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 70:
-# line 460 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 71:
-# line 465 "awk.y"
-{ yyval.nodeval = make_param(yypvt[-0].sval); } break;
-case 72:
-# line 467 "awk.y"
-{ yyval.nodeval = append_right(yypvt[-2].nodeval, make_param(yypvt[-0].sval)); yyerrok; } break;
-case 73:
-# line 469 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 74:
-# line 471 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 75:
-# line 473 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 76:
-# line 479 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 77:
-# line 481 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 78:
-# line 486 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 79:
-# line 488 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 80:
-# line 493 "awk.y"
-{ yyval.nodeval = node (yypvt[-0].nodeval, Node_expression_list, (NODE *)NULL); } break;
-case 81:
-# line 495 "awk.y"
-{
- yyval.nodeval = append_right(yypvt[-2].nodeval,
- node( yypvt[-0].nodeval, Node_expression_list, (NODE *)NULL));
- yyerrok;
- } break;
-case 82:
-# line 501 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 83:
-# line 503 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 84:
-# line 505 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 85:
-# line 507 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 86:
-# line 512 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 87:
-# line 514 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 88:
-# line 519 "awk.y"
-{ yyval.nodeval = node (yypvt[-0].nodeval, Node_expression_list, (NODE *)NULL); } break;
-case 89:
-# line 521 "awk.y"
-{
- yyval.nodeval = append_right(yypvt[-2].nodeval,
- node( yypvt[-0].nodeval, Node_expression_list, (NODE *)NULL));
- yyerrok;
- } break;
-case 90:
-# line 527 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 91:
-# line 529 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 92:
-# line 531 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 93:
-# line 533 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 94:
-# line 538 "awk.y"
-{ want_assign = 0; } break;
-case 95:
-# line 540 "awk.y"
-{
- if (do_lint && yypvt[-0].nodeval->type == Node_regex)
- warning("Regular expression on left of assignment.");
- yyval.nodeval = node (yypvt[-3].nodeval, yypvt[-2].nodetypeval, yypvt[-0].nodeval);
- } break;
-case 96:
-# line 546 "awk.y"
-{ yyval.nodeval = node (variable(yypvt[-0].sval,1), Node_in_array, yypvt[-3].nodeval); } break;
-case 97:
-# line 548 "awk.y"
-{
- yyval.nodeval = node (yypvt[-0].nodeval, Node_K_getline,
- node (yypvt[-3].nodeval, Node_redirect_pipein, (NODE *)NULL));
- } break;
-case 98:
-# line 553 "awk.y"
-{
- if (do_lint && ! io_allowed && yypvt[-0].nodeval == NULL)
- warning("non-redirected getline undefined inside BEGIN or END action");
- yyval.nodeval = node (yypvt[-1].nodeval, Node_K_getline, yypvt[-0].nodeval);
- } break;
-case 99:
-# line 559 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_and, yypvt[-0].nodeval); } break;
-case 100:
-# line 561 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_or, yypvt[-0].nodeval); } break;
-case 101:
-# line 563 "awk.y"
-{
- if (yypvt[-2].nodeval->type == Node_regex)
- warning("Regular expression on left of MATCH operator.");
- yyval.nodeval = node (yypvt[-2].nodeval, yypvt[-1].nodetypeval, mk_rexp(yypvt[-0].nodeval));
- } break;
-case 102:
-# line 569 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 103:
-# line 571 "awk.y"
-{
- yyval.nodeval = node(node(make_number(0.0),
- Node_field_spec,
- (NODE *) NULL),
- Node_nomatch,
- yypvt[-0].nodeval);
- } break;
-case 104:
-# line 579 "awk.y"
-{ yyval.nodeval = node (variable(yypvt[-0].sval,1), Node_in_array, yypvt[-2].nodeval); } break;
-case 105:
-# line 581 "awk.y"
-{
- if (do_lint && yypvt[-0].nodeval->type == Node_regex)
- warning("Regular expression on left of comparison.");
- yyval.nodeval = node (yypvt[-2].nodeval, yypvt[-1].nodetypeval, yypvt[-0].nodeval);
- } break;
-case 106:
-# line 587 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_less, yypvt[-0].nodeval); } break;
-case 107:
-# line 589 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_greater, yypvt[-0].nodeval); } break;
-case 108:
-# line 591 "awk.y"
-{ yyval.nodeval = node(yypvt[-4].nodeval, Node_cond_exp, node(yypvt[-2].nodeval, Node_if_branches, yypvt[-0].nodeval));} break;
-case 109:
-# line 593 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 110:
-# line 595 "awk.y"
-{ yyval.nodeval = node (yypvt[-1].nodeval, Node_concat, yypvt[-0].nodeval); } break;
-case 111:
-# line 600 "awk.y"
-{ want_assign = 0; } break;
-case 112:
-# line 602 "awk.y"
-{ yyval.nodeval = node (yypvt[-3].nodeval, yypvt[-2].nodetypeval, yypvt[-0].nodeval); } break;
-case 113:
-# line 604 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_and, yypvt[-0].nodeval); } break;
-case 114:
-# line 606 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_or, yypvt[-0].nodeval); } break;
-case 115:
-# line 608 "awk.y"
-{
- if (do_lint && ! io_allowed && yypvt[-0].nodeval == NULL)
- warning("non-redirected getline undefined inside BEGIN or END action");
- yyval.nodeval = node (yypvt[-1].nodeval, Node_K_getline, yypvt[-0].nodeval);
- } break;
-case 116:
-# line 614 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 117:
-# line 616 "awk.y"
-{ yyval.nodeval = node((NODE *) NULL, Node_nomatch, yypvt[-0].nodeval); } break;
-case 118:
-# line 618 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, yypvt[-1].nodetypeval, mk_rexp(yypvt[-0].nodeval)); } break;
-case 119:
-# line 620 "awk.y"
-{ yyval.nodeval = node (variable(yypvt[-0].sval,1), Node_in_array, yypvt[-2].nodeval); } break;
-case 120:
-# line 622 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, yypvt[-1].nodetypeval, yypvt[-0].nodeval); } break;
-case 121:
-# line 624 "awk.y"
-{ yyval.nodeval = node(yypvt[-4].nodeval, Node_cond_exp, node(yypvt[-2].nodeval, Node_if_branches, yypvt[-0].nodeval));} break;
-case 122:
-# line 626 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 123:
-# line 628 "awk.y"
-{ yyval.nodeval = node (yypvt[-1].nodeval, Node_concat, yypvt[-0].nodeval); } break;
-case 126:
-# line 636 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_exp, yypvt[-0].nodeval); } break;
-case 127:
-# line 638 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_times, yypvt[-0].nodeval); } break;
-case 128:
-# line 640 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_quotient, yypvt[-0].nodeval); } break;
-case 129:
-# line 642 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_mod, yypvt[-0].nodeval); } break;
-case 130:
-# line 644 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_plus, yypvt[-0].nodeval); } break;
-case 131:
-# line 646 "awk.y"
-{ yyval.nodeval = node (yypvt[-2].nodeval, Node_minus, yypvt[-0].nodeval); } break;
-case 132:
-# line 651 "awk.y"
-{ yyval.nodeval = node (yypvt[-0].nodeval, Node_not,(NODE *) NULL); } break;
-case 133:
-# line 653 "awk.y"
-{ yyval.nodeval = yypvt[-1].nodeval; } break;
-case 134:
-# line 655 "awk.y"
-{
- if (! io_allowed && strcmp(tokstart, "nextfile") == 0)
- yyerror("nextfile() is illegal in BEGIN and END");
- } break;
-case 135:
-# line 660 "awk.y"
-{ yyval.nodeval = snode (yypvt[-1].nodeval, Node_builtin, (int) yypvt[-4].lval); } break;
-case 136:
-# line 662 "awk.y"
-{ yyval.nodeval = snode (yypvt[-1].nodeval, Node_builtin, (int) yypvt[-3].lval); } break;
-case 137:
-# line 664 "awk.y"
-{
- if (do_lint)
- warning("call of `length' without parentheses is not portable");
- yyval.nodeval = snode ((NODE *)NULL, Node_builtin, (int) yypvt[-0].lval);
- if (do_posix)
- warning( "call of `length' without parentheses is deprecated by POSIX");
- } break;
-case 138:
-# line 672 "awk.y"
-{
- yyval.nodeval = node (yypvt[-1].nodeval, Node_func_call, make_string(yypvt[-3].sval, strlen(yypvt[-3].sval)));
- } break;
-case 139:
-# line 676 "awk.y"
-{ yyval.nodeval = node (yypvt[-0].nodeval, Node_preincrement, (NODE *)NULL); } break;
-case 140:
-# line 678 "awk.y"
-{ yyval.nodeval = node (yypvt[-0].nodeval, Node_predecrement, (NODE *)NULL); } break;
-case 141:
-# line 680 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 142:
-# line 682 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 143:
-# line 685 "awk.y"
-{ if (yypvt[-0].nodeval->type == Node_val) {
- yypvt[-0].nodeval->numbr = -(force_number(yypvt[-0].nodeval));
- yyval.nodeval = yypvt[-0].nodeval;
- } else
- yyval.nodeval = node (yypvt[-0].nodeval, Node_unary_minus, (NODE *)NULL);
- } break;
-case 144:
-# line 692 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 145:
-# line 697 "awk.y"
-{ yyval.nodeval = node (yypvt[-1].nodeval, Node_postincrement, (NODE *)NULL); } break;
-case 146:
-# line 699 "awk.y"
-{ yyval.nodeval = node (yypvt[-1].nodeval, Node_postdecrement, (NODE *)NULL); } break;
-case 148:
-# line 705 "awk.y"
-{ yyval.nodeval = NULL; } break;
-case 149:
-# line 707 "awk.y"
-{ yyval.nodeval = yypvt[-0].nodeval; } break;
-case 150:
-# line 712 "awk.y"
-{ yyval.nodeval = variable(yypvt[-0].sval,1); } break;
-case 151:
-# line 714 "awk.y"
-{
- if (yypvt[-1].nodeval->rnode == NULL) {
- yyval.nodeval = node (variable(yypvt[-3].sval,1), Node_subscript, yypvt[-1].nodeval->lnode);
- freenode(yypvt[-1].nodeval);
- } else
- yyval.nodeval = node (variable(yypvt[-3].sval,1), Node_subscript, yypvt[-1].nodeval);
- } break;
-case 152:
-# line 722 "awk.y"
-{ yyval.nodeval = node (yypvt[-0].nodeval, Node_field_spec, (NODE *)NULL); } break;
-case 153:
-# line 724 "awk.y"
-{ yyval.nodeval = node (yypvt[-0].nodeval, Node_field_spec, (NODE *)NULL); } break;
-case 155:
-# line 732 "awk.y"
-{ yyerrok; } break;
-case 156:
-# line 736 "awk.y"
-{ yyerrok; } break;
-case 159:
-# line 745 "awk.y"
-{ yyerrok; want_assign = 0; } break;
-case 160:
-# line 748 "awk.y"
-{ yyerrok; } break;
- }
- goto yystack; /* reset registers in driver code */
-}
diff --git a/builtin.c b/builtin.c
index 5022ca4c..c65bb902 100644
--- a/builtin.c
+++ b/builtin.c
@@ -30,9 +30,11 @@
#ifndef SRANDOM_PROTO
extern void srandom P((int seed));
#endif
+#ifndef linux
extern char *initstate P((unsigned seed, char *state, int n));
extern char *setstate P((char *state));
extern long random P((void));
+#endif
extern NODE **fields_arr;
extern int output_is_tty;
@@ -61,6 +63,32 @@ double (*Log)() = log;
#define Ceil(n) ceil(n)
#endif
+static void
+efwrite(ptr, size, count, fp, from, rp, flush)
+void *ptr;
+unsigned size, count;
+FILE *fp;
+char *from;
+struct redirect *rp;
+int flush;
+{
+ errno = 0;
+ if (fwrite(ptr, size, count, fp) != count)
+ goto wrerror;
+ if (flush
+ && ((fp == stdout && output_is_tty)
+ || (rp && (rp->flag & RED_NOBUF)))) {
+ fflush(fp);
+ if (ferror(fp))
+ goto wrerror;
+ }
+ return;
+ wrerror:
+ fatal("%s to \"%s\" failed (%s)", from,
+ rp ? rp->value : "standard output",
+ errno ? strerror(errno) : "reason unknown");
+}
+
/* Builtin functions */
NODE *
do_exp(tree)
@@ -568,7 +596,7 @@ retry:
"^ ran out for this one"
);
}
- if (carg != NULL)
+ if (do_lint && carg != NULL)
warning("too many arguments supplied for format string");
bchunk(s0, s1 - s0);
free_temp(sfmt);
@@ -597,14 +625,8 @@ register NODE *tree;
} else
fp = stdout;
tree = do_sprintf(tree->lnode);
- (void) fwrite(tree->stptr, sizeof(char), tree->stlen, fp);
+ efwrite(tree->stptr, sizeof(char), tree->stlen, fp, "printf", rp , 1);
free_temp(tree);
- if ((fp == stdout && output_is_tty) || (rp && (rp->flag & RED_NOBUF)))
- fflush(fp);
- if (ferror(fp)) {
- warning("error writing output: %s", strerror(errno));
- clearerr(fp);
- }
}
NODE *
@@ -629,7 +651,8 @@ NODE *tree;
{
NODE *t1, *t2, *t3;
NODE *r;
- register int indx, length;
+ register int indx;
+ size_t length;
t1 = tree_eval(tree->lnode);
t2 = tree_eval(tree->rnode->lnode);
@@ -637,7 +660,7 @@ NODE *tree;
length = t1->stlen;
else {
t3 = tree_eval(tree->rnode->rnode->lnode);
- length = (int) force_number(t3);
+ length = (size_t) force_number(t3);
free_temp(t3);
}
indx = (int) force_number(t2) - 1;
@@ -649,7 +672,7 @@ NODE *tree;
free_temp(t1);
return Nnull_string;
}
- if (indx + length > t1->stlen)
+ if (indx + length > t1->stlen || LONG_MAX - indx < length)
length = t1->stlen - indx;
r = tmp_string(t1->stptr + indx, length);
free_temp(t1);
@@ -745,35 +768,18 @@ register NODE *tree;
t1 = tmp_string(buf, strlen(buf));
}
}
- (void) fwrite(t1->stptr, sizeof(char), t1->stlen, fp);
+ efwrite(t1->stptr, sizeof(char), t1->stlen, fp, "print", rp, 0);
free_temp(t1);
tree = tree->rnode;
if (tree) {
s = OFS;
-#if (!defined(VMS)) || defined(NO_TTY_FWRITE)
- while (*s)
- putc(*s++, fp);
-#else
if (OFSlen)
- (void) fwrite(s, sizeof(char), OFSlen, fp);
-#endif /* VMS && !NO_TTY_FWRITE */
+ efwrite(s, sizeof(char), OFSlen, fp, "print", rp, 0);
}
}
s = ORS;
-#if (!defined(VMS)) || defined(NO_TTY_FWRITE)
- while (*s)
- putc(*s++, fp);
- if ((fp == stdout && output_is_tty) || (rp && (rp->flag & RED_NOBUF)))
-#else
if (ORSlen)
- (void) fwrite(s, sizeof(char), ORSlen, fp);
- if ((rp && (rp->flag & RED_NOBUF)))
-#endif /* VMS && !NO_TTY_FWRITE */
- fflush(fp);
- if (ferror(fp)) {
- warning("error writing output: %s", strerror(errno));
- clearerr(fp);
- }
+ efwrite(s, sizeof(char), ORSlen, fp, "print", rp, 1);
}
NODE *
@@ -858,8 +864,6 @@ NODE *tree;
static int firstrand = 1;
static char state[256];
-#define MAXLONG 2147483647 /* maximum value for long int */
-
/* ARGSUSED */
NODE *
do_rand(tree)
@@ -870,7 +874,7 @@ NODE *tree;
srandom(1);
firstrand = 0;
}
- return tmp_number((AWKNUM) random() / MAXLONG);
+ return tmp_number((AWKNUM) random() / LONG_MAX);
}
NODE *
@@ -965,7 +969,7 @@ int global;
/* do the search early to avoid work on non-match */
if (research(rp, t->stptr, 0, t->stlen, 1) == -1 ||
- (RESTART(rp, t->stptr) >= t->stlen) && (matches = 1)) {
+ (RESTART(rp, t->stptr) > t->stlen) && (matches = 1)) {
free_temp(t);
return tmp_number((AWKNUM) matches);
}
@@ -1002,8 +1006,10 @@ int global;
if (*scan == '&') {
repllen--;
ampersands++;
- } else if (*scan == '\\' && *(scan+1) == '&')
+ } else if (*scan == '\\' && (*(scan+1) == '&' || *(scan+1) == '\\')) {
repllen--;
+ scan++;
+ }
}
bp = buf;
@@ -1030,13 +1036,13 @@ int global;
if (*scan == '&')
for (cp = matchstart; cp < matchend; cp++)
*bp++ = *cp;
- else if (*scan == '\\' && *(scan+1) == '&') {
+ else if (*scan == '\\' && (*(scan+1) == '&' || *(scan+1) == '\\')) {
scan++;
*bp++ = *scan;
} else
*bp++ = *scan;
- if (global && matchstart == matchend && matchend < text + textlen - 1) {
- *bp++ = *text;
+ if (global && matchstart == matchend && matchend < text + textlen) {
+ *bp++ = *matchend;
matchend++;
}
textlen = text + textlen - matchend;
diff --git a/config/bsd44alpha b/config/bsd44
index 4dfcb79d..4dfcb79d 100644
--- a/config/bsd44alpha
+++ b/config/bsd44
diff --git a/config/hpux7.0 b/config/hpux7.0
new file mode 100644
index 00000000..0e2b3bd1
--- /dev/null
+++ b/config/hpux7.0
@@ -0,0 +1,8 @@
+For HPUX 7.0
+STDC_HEADERS 1
+_POSIX_SOURCE 1
+POSIX 1
+HAVE_UNDERSCORE_SETJMP 1
+STRCASE_MISSING 1
+BSDSTDIO 1
+RANDOM_MISSING 1
diff --git a/config/hpux8x b/config/hpux8x
new file mode 100644
index 00000000..66d347a9
--- /dev/null
+++ b/config/hpux8x
@@ -0,0 +1,3 @@
+HPPA running HP-UX 8.x
+STDC_HEADERS 1
+RANDOM_MISSING 1
diff --git a/config/ibmrt-aos b/config/ibmrt-aos
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/config/ibmrt-aos
diff --git a/config/linux b/config/linux
new file mode 100644
index 00000000..ff825f59
--- /dev/null
+++ b/config/linux
@@ -0,0 +1,3 @@
+Configure file for Linux 0.98.pl4 (with gcc 2.2.2d7)
+DOPRNT_MISSING 1
+SRANDOM_PROTO 1
diff --git a/config/linux.h b/config/linux.h
deleted file mode 100644
index f0b6856d..00000000
--- a/config/linux.h
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * config.h -- configuration definitions for gawk.
- *
- * Linux 0.96a+
- *
- * Linux version 3 Jun 1992, faith@cs.unc.edu (using gcc 2.1)
- * Revised: Thu Jun 4 22:24:01 1992 by root
- *
- * NOTE: Select, in Makefile-dist, the bison option and turn on gcc switches.
- * In builtin.c, place a
- * #ifndef linux
- * #endif
- * wrapper around the externs for srandom(), initstate(), setstate(), and
- * random().
- */
-
-/*
- * Copyright (C) 1991, the Free Software Foundation, Inc.
- *
- * This file is part of GAWK, the GNU implementation of the
- * AWK Progamming Language.
- *
- * GAWK is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 1, or (at your option)
- * any later version.
- *
- * GAWK is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GAWK; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * This file isolates configuration dependencies for gnu awk.
- * You should know something about your system, perhaps by having
- * a manual handy, when you edit this file. You should copy config.h-dist
- * to config.h, and edit config.h. Do not modify config.h-dist, so that
- * it will be easy to apply any patches that may be distributed.
- *
- * The general idea is that systems conforming to the various standards
- * should need to do the least amount of changing. Definining the various
- * items in ths file usually means that your system is missing that
- * particular feature.
- *
- * The order of preference in standard conformance is ANSI C, POSIX,
- * and the SVID.
- *
- * If you have no clue as to what's going on with your system, try
- * compiling gawk without editing this file and see what shows up
- * missing in the link stage. From there, you can probably figure out
- * which defines to turn on.
- */
-
-/**************************/
-/* Miscellanious features */
-/**************************/
-
-/*
- * BLKSIZE_MISSING
- *
- * Check your /usr/include/sys/stat.h file. If the stat structure
- * does not have a member named st_blksize, define this. (This will
- * most likely be the case on most System V systems prior to V.4.)
- */
-#define BLKSIZE_MISSING 1
-
-/*
- * SIGTYPE
- *
- * The return type of the routines passed to the signal function.
- * Modern systems use `void', older systems use `int'.
- * If left undefined, it will default to void.
- */
-/* #define SIGTYPE int */
-
-/*
- * SIZE_T_MISSING
- *
- * If your system has no typedef for size_t, define this to get a default
- */
-/* #define SIZE_T_MISSING 1 */
-
-/*
- * CHAR_UNSIGNED
- *
- * If your machine uses unsigned characters (IBM RT and RS/6000 and others)
- * then define this for use in regex.c
- */
-/* #define CHAR_UNSIGNED 1 */
-
-/*
- * HAVE_UNDERSCORE_SETJMP
- *
- * Check in your /usr/include/setjmp.h file. If there are routines
- * there named _setjmp and _longjmp, then you should define this.
- * Typically only systems derived from Berkeley Unix have this.
- */
-/* #define HAVE_UNDERSCORE_SETJMP 1 */
-
-/***********************************************/
-/* Missing library subroutines or system calls */
-/***********************************************/
-
-/*
- * GETOPT_MISSING
- *
- * Define this if your library does not have the getopt(3) library
- * routine for parsing command line arguments.
- */
-/* #define GETOPT_MISSING 1 */
-
-/*
- * MEMCMP_MISSING
- * MEMCPY_MISSING
- * MEMSET_MISSING
- *
- * These three routines are for manipulating blocks of memory. Most
- * likely they will either all three be present or all three be missing,
- * so they're grouped together.
- */
-/* #define MEMCMP_MISSING 1 */
-/* #define MEMCPY_MISSING 1 */
-/* #define MEMSET_MISSING 1 */
-
-/*
- * RANDOM_MISSING
- *
- * Your system does not have the random(3) suite of random number
- * generating routines. These are different than the old rand(3)
- * routines!
- */
-/* #define RANDOM_MISSING 1 */
-
-/*
- * STRCASE_MISSING
- *
- * Your system does not have the strcasemp() and strncasecmp()
- * routines that originated in Berkeley Unix.
- */
-#define STRCASE_MISSING 1
-
-/*
- * STRCHR_MISSING
- *
- * Your system does not have the strchr() and strrchr() functions.
- */
-/* #define STRCHR_MISSING 1 */
-
-/*
- * STRERROR_MISSING
- *
- * Your system lacks the ANSI C strerror() routine for returning the
- * strings associated with errno values.
- */
-/* #define STRERROR_MISSING 1 */
-
-/*
- * STRTOD_MISSING
- *
- * Your system does not have the strtod() routine for converting
- * strings to double precision floating point values.
- */
-/* #define STRTOD_MISSING 1 */
-
-/*
- * STRTOL_MISSING
- *
- * Your system does not have the strtol() routine for converting
- * strings to long integers.
- */
-/* #define STRTOL_MISSING 1 */
-
-/*
- * STRFTIME_MISSING
- *
- * Your system lacks the ANSI C strftime() routine for formatting
- * broken down time values.
- */
-/* #define STRFTIME_MISSING 1 */
-
-/*
- * TZSET_MISSING
- *
- * If you have a 4.2 BSD vintage system, then the strftime() routine
- * supplied in the missing directory won't be enough, because it relies on the
- * tzset() routine from System V / Posix. Fortunately, there is an
- * emulation for tzset() too that should do the trick. If you don't
- * have tzset(), define this.
- */
-/* #define TZSET_MISSING 1 */
-
-/*
- * TZNAME_MISSING
- *
- * Some systems do not support the external variables tzname and daylight.
- * If this is the case *and* strftime() is missing, define this.
- */
-/* #define TZNAME_MISSING 1 */
-
-/*
- * STDC_HEADERS
- *
- * If your system does have ANSI compliant header files that
- * provide prototypes for library routines, then define this.
- */
-#define STDC_HEADERS 1
-
-/*
- * NO_TOKEN_PASTING
- *
- * If your compiler define's __STDC__ but does not support token
- * pasting (tok##tok), then define this.
- */
-/* #define NO_TOKEN_PASTING 1 */
-
-/*****************************************************************/
-/* Stuff related to the Standard I/O Library. */
-/*****************************************************************/
-/* Much of this is (still, unfortunately) black magic in nature. */
-/* You may have to use some or all of these together to get gawk */
-/* to work correctly. */
-/*****************************************************************/
-
-/*
- * NON_STD_SPRINTF
- *
- * Look in your /usr/include/stdio.h file. If the return type of the
- * sprintf() function is NOT `int', define this.
- */
-/* #define NON_STD_SPRINTF 1 */
-
-/*
- * VPRINTF_MISSING
- *
- * Define this if your system lacks vprintf() and the other routines
- * that go with it.
- */
-/* #define VPRINTF_MISSING 1 */
-
-/*
- * BSDSTDIO
- *
- * Define this if your standard i/o library is internally compatible
- * with the one shipped with Berkeley Unix systems (4.n, n <= 3-reno).
- * If you've defined VPRINTF_MISSING, you probably will need this too.
- */
-/* #define BSDSTDIO 1 */
-
-/*
- * DOPRNT_MISSING
- *
- * Define this if your standard i/o library does not have the _doprnt()
- * routine. This is used in an attempt to simulate the vfprintf()
- * routine.
- */
-#define DOPRNT_MISSING 1
-
-/*
- * Casts from size_t to int and back. These will become unnecessary
- * at some point in the future, but for now are required where the
- * two types are a different representation.
- */
-/* #define SZTC */
-/* #define INTC */
-
-/*
- * SYSTEM_MISSING
- *
- * Define this if your library does not provide a system function
- * or you are not entirely happy with it and would rather use
- * a provided replacement (atari only).
- */
-/* #define SYSTEM_MISSING 1 */
-
-
-/*******************************/
-/* Gawk configuration options. */
-/*******************************/
-
-/*
- * DEFPATH
- *
- * The default search path for the -f option of gawk. It is used
- * if the AWKPATH environment variable is undefined. The default
- * definition is provided here. Most likely you should not change
- * this.
- */
-
-/* #define DEFPATH ".:/usr/lib/awk:/usr/local/lib/awk" */
-/* #define ENVSEP ':' */
diff --git a/config/riscos452 b/config/riscos452
new file mode 100644
index 00000000..be4ad54e
--- /dev/null
+++ b/config/riscos452
@@ -0,0 +1,7 @@
+MIPS RISC/os 4.52
+BLKSIZE_MISSING 1
+RANDOM_MISSING 1
+STRCASE_MISSING 1
+STRERROR_MISSING 1
+STRFTIME_MISSING 1
+CHAR_UNSIGNED 1
diff --git a/config/sequent b/config/sequent
index 48d2821a..0b340110 100644
--- a/config/sequent
+++ b/config/sequent
@@ -14,3 +14,4 @@ NON_STD_SPRINTF 1
VPRINTF_MISSING 1
BSDSTDIO 1
TZSET_MISSING 1
+FMOD_MISSING 1
diff --git a/config/sgi405 b/config/sgi405
new file mode 100644
index 00000000..633f8e53
--- /dev/null
+++ b/config/sgi405
@@ -0,0 +1,4 @@
+SGI Personal Iris (Sys V derived) (this works with gcc)
+BLKSIZE_MISSING 1
+STDC_HEADERS 1
+MAKE_ALLOCA_C
diff --git a/config/sgi405.cc b/config/sgi405.cc
new file mode 100644
index 00000000..980eaa3b
--- /dev/null
+++ b/config/sgi405.cc
@@ -0,0 +1,6 @@
+SGI Personal Iris (Sys V derived) (this works with cc)
+BLKSIZE_MISSING 1
+STDC_HEADERS 1
+CHAR_UNSIGNED 1
+MAKE_CC
+MAKE_SGI
diff --git a/config/sunos41-glibc b/config/sunos41-glibc
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/config/sunos41-glibc
diff --git a/config/ultrix31 b/config/ultrix31
index 912c80cd..4359bdca 100644
--- a/config/ultrix31
+++ b/config/ultrix31
@@ -4,3 +4,4 @@ STRERROR_MISSING 1
STRFTIME_MISSING 1
NON_STD_SPRINTF 1
TZSET_MISSING 1
+FMOD_MISSING 1
diff --git a/dfa.c b/dfa.c
index 7777c66c..5293c755 100644
--- a/dfa.c
+++ b/dfa.c
@@ -1417,12 +1417,8 @@ regstate(s, r, trans)
else
state_letter = state;
for (i = 0; i < _NOTCHAR; ++i)
- if (i == '\n')
- trans[i] = state_newline;
- else if (ISALNUM(i))
- trans[i] = state_letter;
- else
- trans[i] = state;
+ trans[i] = (ISALNUM(i)) ? state_letter : state ;
+ trans['\n'] = state_newline;
}
else
for (i = 0; i < _NOTCHAR; ++i)
@@ -1627,12 +1623,8 @@ regexecute(r, begin, end, newline, count, backref)
sbit_init = 1;
for (i = 0; i < _NOTCHAR; ++i)
- if (i == '\n')
- sbit[i] = 4;
- else if (ISALNUM(i))
- sbit[i] = 2;
- else
- sbit[i] = 1;
+ sbit[i] = (ISALNUM(i)) ? 2 : 1;
+ sbit['\n'] = 4;
}
if (! r->tralloc)
@@ -1645,30 +1637,21 @@ regexecute(r, begin, end, newline, count, backref)
for (;;)
{
- /* The dreaded inner loop. */
- if ((t = trans[s]) != 0)
- do
- {
- s1 = t[*p++];
- if (! (t = trans[s1]))
- goto last_was_s;
- s = t[*p++];
- }
- while ((t = trans[s]) != 0);
- goto last_was_s1;
- last_was_s:
- tmp = s, s = s1, s1 = tmp;
- last_was_s1:
+ while ((t = trans[s]) != 0) { /* hand-optimized loop */
+ s1 = t[*p++];
+ if ((t = trans[s1]) == 0) {
+ tmp = s ; s = s1 ; s1 = tmp ; /* swap */
+ break;
+ }
+ s = t[*p++];
+ }
if (s >= 0 && p <= (unsigned char *) end && r->fails[s])
{
if (r->success[s] & sbit[*p])
{
if (backref)
- if (r->states[s].backref)
- *backref = 1;
- else
- *backref = 0;
+ *backref = (r->states[s].backref != 0);
return (char *) p;
}
diff --git a/dfa.h b/dfa.h
index b4869808..65fc4956 100644
--- a/dfa.h
+++ b/dfa.h
@@ -175,13 +175,17 @@ what you give them. Help stamp out software-hoarding! */
#endif
/* Number of bits in an unsigned char. */
+#ifndef CHARBITS
#define CHARBITS 8
+#endif
/* First integer value that is greater than any character code. */
#define _NOTCHAR (1 << CHARBITS)
/* INTBITS need not be exact, just a lower bound. */
+#ifndef INTBITS
#define INTBITS (CHARBITS * sizeof (int))
+#endif
/* Number of ints required to hold a bit for every character. */
#define _CHARSET_INTS ((_NOTCHAR + INTBITS - 1) / INTBITS)
diff --git a/eval.c b/eval.c
index 09ca96b2..f640f373 100644
--- a/eval.c
+++ b/eval.c
@@ -393,9 +393,12 @@ register NODE *tree;
if (tree->var_value->stref <= 0) cant_happen();
return tree->var_value;
}
- if (tree->type == Node_param_list)
-/* return (stack_ptr[(_t)->param_cnt])->var_value; */
- return (stack_ptr[(tree)->param_cnt])->var_value;
+ if (tree->type == Node_param_list) {
+ if (stack_ptr[tree->param_cnt] == NULL)
+ return Nnull_string;
+ else
+ return stack_ptr[tree->param_cnt]->var_value;
+ }
#endif
switch (tree->type) {
case Node_and:
@@ -1143,7 +1146,7 @@ set_IGNORECASE()
{
static int warned = 0;
- if ((do_lint || strict) && ! warned) {
+ if ((do_lint || do_unix) && ! warned) {
warned = 1;
warning("IGNORECASE not supported in compatibility mode");
}
diff --git a/field.c b/field.c
index d50d793c..d8f9a545 100644
--- a/field.c
+++ b/field.c
@@ -25,16 +25,16 @@
#include "awk.h"
-static int (*parse_field) P((int, char **, int, char *,
+static int (*parse_field) P((int, char **, int, NODE *,
Regexp *, void (*)(), NODE *));
static void rebuild_record P((void));
-static int re_parse_field P((int, char **, int, char *,
+static int re_parse_field P((int, char **, int, NODE *,
Regexp *, void (*)(), NODE *));
-static int def_parse_field P((int, char **, int, char *,
+static int def_parse_field P((int, char **, int, NODE *,
Regexp *, void (*)(), NODE *));
-static int sc_parse_field P((int, char **, int, char *,
+static int sc_parse_field P((int, char **, int, NODE *,
Regexp *, void (*)(), NODE *));
-static int fw_parse_field P((int, char **, int, char *,
+static int fw_parse_field P((int, char **, int, NODE *,
Regexp *, void (*)(), NODE *));
static void set_element P((int, char *, int, NODE *));
static void grow_fields_arr P((int num));
@@ -46,8 +46,7 @@ static char *parse_extent; /* marks where to restart parse of record */
static int parse_high_water=0; /* field number that we have parsed so far */
static int nf_high_water = 0; /* size of fields_arr */
static int resave_fs;
-static NODE *save_FS;
-static char *save_fs; /* save current value of FS when line is read,
+static NODE *save_FS; /* save current value of FS when line is read,
* to be used in deferred parsing
*/
@@ -69,7 +68,6 @@ init_fields()
fields_arr[0] = nodes[0] = n;
parse_extent = fields_arr[0]->stptr;
save_FS = dupnode(FS_node->var_value);
- save_fs = save_FS->stptr;
field0_valid = 1;
}
@@ -183,7 +181,6 @@ int freeold;
resave_fs = 0;
unref(save_FS);
save_FS = dupnode(FS_node->var_value);
- save_fs = save_FS->stptr;
}
nodes[0]->stptr = buf;
nodes[0]->stlen = cnt;
@@ -227,7 +224,7 @@ re_parse_field(up_to, buf, len, fs, rp, set, n)
int up_to; /* parse only up to this field number */
char **buf; /* on input: string to parse; on output: point to start next */
int len;
-register char *fs;
+NODE *fs;
Regexp *rp;
void (*set) (); /* routine to set the value of the parsed field */
NODE *n;
@@ -258,7 +255,7 @@ NODE *n;
}
continue;
}
- (*set)(++nf, field, RESTART(rp, scan), n);
+ (*set)(++nf, field, scan + RESTART(rp, scan) - field, n);
scan += REEND(rp, scan);
field = scan;
if (scan == end) /* FS at end of record */
@@ -282,7 +279,7 @@ def_parse_field(up_to, buf, len, fs, rp, set, n)
int up_to; /* parse only up to this field number */
char **buf; /* on input: string to parse; on output: point to start next */
int len;
-register char *fs;
+NODE *fs;
Regexp *rp;
void (*set) (); /* routine to set the value of the parsed field */
NODE *n;
@@ -336,13 +333,13 @@ sc_parse_field(up_to, buf, len, fs, rp, set, n)
int up_to; /* parse only up to this field number */
char **buf; /* on input: string to parse; on output: point to start next */
int len;
-register char *fs;
+NODE *fs;
Regexp *rp;
void (*set) (); /* routine to set the value of the parsed field */
NODE *n;
{
register char *scan = *buf;
- register char fschar = *fs;
+ register char fschar;
register int nf = parse_high_water;
register char *field;
register char *end = scan + len;
@@ -353,11 +350,16 @@ NODE *n;
if (len == 0)
return nf;
+ if (*RS == 0 && fs->stlen == 0)
+ fschar = '\n';
+ else
+ fschar = fs->stptr[0];
+
/* before doing anything save the char at *end */
sav = *end;
/* because it will be destroyed now: */
-
*end = fschar; /* sentinel character */
+
for (; nf < up_to; scan++) {
field = scan;
while (*scan++ != fschar)
@@ -377,15 +379,14 @@ NODE *n;
/*
* this is called both from get_field() and from do_split()
- * via (*pase_field)(). This variation is for when FS is a single character
- * other than space.
+ * via (*parse_field)(). This variation is for fields are fixed widths.
*/
static int
fw_parse_field(up_to, buf, len, fs, rp, set, n)
int up_to; /* parse only up to this field number */
char **buf; /* on input: string to parse; on output: point to start next */
int len;
-register char *fs;
+NODE *fs;
Regexp *rp;
void (*set) (); /* routine to set the value of the parsed field */
NODE *n;
@@ -427,7 +428,7 @@ Func_ptr *assign; /* this field is on the LHS of an assign */
NF = (*parse_field)(HUGE-1, &parse_extent,
fields_arr[0]->stlen -
(parse_extent - fields_arr[0]->stptr),
- save_fs, FS_regexp, set_field,
+ save_FS, FS_regexp, set_field,
(NODE *)NULL);
parse_high_water = NF;
}
@@ -455,7 +456,7 @@ Func_ptr *assign; /* this field is on the LHS of an assign */
parse_extent = fields_arr[0]->stptr;
parse_high_water = (*parse_field)(requested, &parse_extent,
fields_arr[0]->stlen - (parse_extent-fields_arr[0]->stptr),
- save_fs, FS_regexp, set_field, (NODE *)NULL);
+ save_FS, FS_regexp, set_field, (NODE *)NULL);
/*
* if we reached the end of the record, set NF to the number of
@@ -509,9 +510,9 @@ do_split(tree)
NODE *tree;
{
NODE *t1, *t2, *t3, *tmp;
- register char *splitc = "";
+ NODE *fs;
char *s;
- int (*parseit)P((int, char **, int, char *,
+ int (*parseit)P((int, char **, int, NODE *,
Regexp *, void (*)(), NODE *));
Regexp *rp = NULL;
@@ -529,92 +530,71 @@ NODE *tree;
if (t3->re_flags & FS_DFLT) {
parseit = parse_field;
- splitc = FS;
+ fs = force_string(FS_node->var_value);
rp = FS_regexp;
} else {
tmp = force_string(tree_eval(t3->re_exp));
if (tmp->stlen == 1) {
- if (tmp->stptr[0] == ' ') {
+ if (tmp->stptr[0] == ' ')
parseit = def_parse_field;
- } else {
+ else
parseit = sc_parse_field;
- splitc = tmp->stptr;
- }
} else {
parseit = re_parse_field;
rp = re_update(t3);
}
- free_temp(tmp);
+ fs = tmp;
}
s = t1->stptr;
tmp = tmp_number((AWKNUM) (*parseit)(HUGE, &s, (int)t1->stlen,
- splitc, rp, set_element, t2));
+ fs, rp, set_element, t2));
free_temp(t1);
+ free_temp(t3);
return tmp;
}
void
set_FS()
{
- register NODE *tmp;
- static char buf[10];
+ NODE *tmp = NULL;
+ char buf[10];
+ NODE *fs;
+ buf[0] = '\0';
default_FS = 0;
if (FS_regexp) {
refree(FS_regexp);
FS_regexp = NULL;
}
- parse_field = def_parse_field;
- tmp = force_string(FS_node->var_value);
- FS = tmp->stptr;
- if (*RS == 0) {
+ fs = force_string(FS_node->var_value);
+ if (fs->stlen > 1)
parse_field = re_parse_field;
- FS = buf;
- if (tmp->stlen == 1) {
- if (tmp->stptr[0] == ' ') {
- (void) strcpy(buf, "[ \n]+");
+ else if (*RS == 0) {
+ parse_field = sc_parse_field;
+ if (fs->stlen == 1) {
+ if (fs->stptr[0] == ' ') {
default_FS = 1;
- } else if (tmp->stptr[0] != '\n') {
- if (IGNORECASE == 0)
- sprintf(buf, "[%c\n]", tmp->stptr[0]);
- else {
- char c = tmp->stptr[0];
-
- sprintf(buf, "[%c%c\n]",
- c, islower(c) ? toupper(c) : isupper(c) ? tolower(c) : c );
- }
- } else {
- parse_field = sc_parse_field;
- FS = tmp->stptr;
- }
- } else if (tmp->stlen == 0) {
- buf[0] = '\n';
- buf[1] = '\0';
- parse_field = sc_parse_field;
- } else
- FS = tmp->stptr;
+ strcpy(buf, "[ \t\n]+");
+ } else if (fs->stptr[0] != '\n')
+ sprintf(buf, "[%c\n]", fs->stptr[0]);
+ }
} else {
- if (tmp->stlen > 1)
- parse_field = re_parse_field;
- else if (*FS == ' ' && tmp->stlen == 1)
+ parse_field = def_parse_field;
+ if (fs->stptr[0] == ' ' && fs->stlen == 1)
default_FS = 1;
- else if (*FS != ' ' && tmp->stlen == 1) {
+ else if (fs->stptr[0] != ' ' && fs->stlen == 1) {
if (IGNORECASE == 0)
parse_field = sc_parse_field;
- else {
- char c = *FS;
-
- sprintf(buf, "[%c%c]",
- c, islower(c) ? toupper(c) : isupper(c) ? tolower(c) : c );
- parse_field = re_parse_field;
- }
+ else
+ sprintf(buf, "[%c]", fs->stptr[0]);
}
}
- if (parse_field == re_parse_field) {
- tmp = tmp_string(FS, strlen(FS));
- FS_regexp = make_regexp(tmp, IGNORECASE, 1);
- free_temp(tmp);
+ if (buf[0]) {
+ FS_regexp = make_regexp(buf, strlen(buf), IGNORECASE, 1);
+ parse_field = re_parse_field;
+ } else if (parse_field == re_parse_field) {
+ FS_regexp = make_regexp(fs->stptr, fs->stlen, IGNORECASE, 1);
} else
FS_regexp = NULL;
resave_fs = 1;
@@ -636,12 +616,13 @@ set_FIELDWIDTHS()
register int i;
static int fw_alloc = 1;
static int warned = 0;
+ extern double strtod();
if (do_lint && ! warned) {
warned = 1;
warning("use of FIELDWIDTHS is a gawk extension");
}
- if (strict) /* quick and dirty, does the trick */
+ if (do_unix) /* quick and dirty, does the trick */
return;
parse_field = fw_parse_field;
diff --git a/gawk.1 b/gawk.1
index aefd2320..79f3df81 100644
--- a/gawk.1
+++ b/gawk.1
@@ -1,20 +1,12 @@
.ds PX \s-1POSIX\s+1
.ds UX \s-1UNIX\s+1
.ds AN \s-1ANSI\s+1
-.TH GAWK 1 "Jul 20 1992" "Free Software Foundation" "Utility Commands"
+.TH GAWK 1 "Apr 15 1993" "Free Software Foundation" "Utility Commands"
.SH NAME
gawk \- pattern scanning and processing language
.SH SYNOPSIS
.B gawk
-[
-.B \-W
-.I gawk-options
-] [
-.BI \-F\^ fs
-] [
-.B \-v
-.IR var = val
-]
+[ POSIX or GNU style options ]
.B \-f
.I program-file
[
@@ -22,15 +14,8 @@ gawk \- pattern scanning and processing language
] file .\^.\^.
.br
.B gawk
+[ POSIX or GNU style options ]
[
-.B \-W
-.I gawk-options
-] [
-.BI \-F\^ fs
-] [
-.B \-v
-.IR var = val
-] [
.B \-\^\-
]
.I program-text
@@ -39,8 +24,7 @@ file .\^.\^.
.I Gawk
is the GNU Project's implementation of the AWK programming language.
It conforms to the definition of the language in
-the \*(PX 1003.2 Command Language And Utilities Standard
-(draft 11).
+the \*(PX 1003.2 Command Language And Utilities Standard.
This version in turn is based on the description in
.IR "The AWK Programming Language" ,
by Aho, Kernighan, and Weinberger,
@@ -54,7 +38,9 @@ The command line consists of options to
.I gawk
itself, the AWK program text (if not supplied via the
.B \-f
-option), and values to be made
+or
+.B \-\^\-file
+options), and values to be made
available in the
.B ARGC
and
@@ -63,10 +49,37 @@ pre-defined AWK variables.
.SH OPTIONS
.PP
.I Gawk
-accepts the following options, which should be available on any implementation
-of the AWK language.
+options may be either the traditional \*(PX one letter options,
+or the GNU style long options. \*(PX style options start with a single ``\-'',
+while GNU long options start with ``\-\^\-''.
+GNU style long options are provided for both GNU-specific features and
+for \*(PX mandated features. Other implementations of the AWK language
+are likely to only accept the traditional one letter options.
+.PP
+Following the \*(PX standard,
+.IR gawk -specific
+options are supplied via arguments to the
+.B \-W
+option. Multiple
+.B \-W
+options may be supplied, or multiple arguments may be supplied together
+if they are separated by commas, or enclosed in quotes and separated
+by white space.
+Case is ignored in arguments to the
+.B \-W
+option.
+Each
+.B \-W
+option has a corresponding GNU style long option, as detailed below.
+.PP
+.I Gawk
+accepts the following options.
+.TP
+.PD 0
+.BI \-F " fs"
.TP
-.BI \-F fs
+.PD
+.BI \-\^\-field-separator= fs
Use
.I fs
for the input field separator (the value of the
@@ -74,7 +87,11 @@ for the input field separator (the value of the
predefined
variable).
.TP
-\fB\-v\fI var\fR\^=\^\fIval\fR
+.PD 0
+\fB\-v\fI var\fB\^=\^\fIval\fR
+.TP
+.PD
+\fB\-\^\-assign=\fIvar\fB\^=\^\fIval\fR
Assign the value
.IR val ,
to the variable
@@ -84,38 +101,25 @@ Such variable values are available to the
.B BEGIN
block of an AWK program.
.TP
+.PD 0
.BI \-f " program-file"
+.TP
+.PD
+.BI \-\^\-file= program-file
Read the AWK program source from the file
.IR program-file ,
instead of from the first command line argument.
Multiple
.B \-f
+(or
+.BR \-\^\-file )
options may be used.
+.TP \w'\fB\-\^\-copyright\fR'u+1n
+.PD 0
+.B "\-W compat"
.TP
-.B \-\^\-
-Signal the end of options. This is useful to allow further arguments to the
-AWK program itself to start with a ``\-''.
-This is mainly for consistency with the argument parsing convention used
-by most other \*(PX programs.
-.PP
-Following the \*(PX standard,
-.IR gawk -specific
-options are supplied via arguments to the
-.B \-W
-option. Multiple
-.B \-W
-options may be supplied, or multiple arguments may be supplied together
-if they are separated by commas, or enclosed in quotes and separated
-by white space.
-Case is ignored in arguments to the
-.B \-W
-option.
-.PP
-The
-.B \-W
-option accepts the following arguments:
-.TP \w'\fBcopyright\fR'u+1n
-.B compat
+.PD
+.B \-\^\-compat
Run in
.I compatibility
mode. In compatibility mode,
@@ -128,18 +132,58 @@ See
below, for more information.
.TP
.PD 0
-.B copyleft
+.B "\-W copyleft"
+.TP
+.PD 0
+.B "\-W copyright"
+.TP
+.PD 0
+.B \-\^\-copyleft
.TP
.PD
-.B copyright
+.B \-\^\-copyright
Print the short version of the GNU copyright information message on
the error output.
.TP
-.B lint
+.PD 0
+.B "\-W help"
+.TP
+.PD 0
+.B "\-W usage"
+.TP
+.PD 0
+.B \-\^\-help
+.TP
+.PD
+.B \-\^\-usage
+Print a relatively short summary of the available options on
+the error output.
+.TP
+.PD 0
+.B "\-W lint"
+.TP
+.PD 0
+.B \-\^\-lint
Provide warnings about constructs that are
dubious or non-portable to other AWK implementations.
+.ig
+.\" This option is left undocumented, on purpose.
+.TP
+.PD 0
+.B "\-W nostalgia"
+.TP
+.PD
+.B \-\^\-nostalgia
+Provide a moment of nostalgia for long time
+.I awk
+users.
+..
.TP
-.B posix
+.PD 0
+.B "\-W posix"
+.TP
+.PD
+.B \-\^\-posix
This turns on
.I compatibility
mode, with the following additional restrictions:
@@ -167,7 +211,35 @@ and
.BR ^= .
.RE
.TP
-.B version
+.PD 0
+.BI "\-W source=" program-text
+.TP
+.PD
+.BI \-\^\-source= program-text
+Use
+.I program-text
+as AWK program source code.
+This option allows the easy intermixing of library functions (used via the
+.B \-f
+and
+.B \-\^\-file
+options) with source code entered on the command line.
+It is intended primarily for medium to large size AWK programs used
+in shell scripts.
+.sp .5
+The
+.B "\-W source="
+form of this option uses the rest of the command line argument for
+.IR program-text ;
+no other options to
+.B \-W
+will be recognized in the same argument.
+.TP
+.PD 0
+.B "\-W version"
+.TP
+.PD
+.B \-\^\-version
Print version information for this particular copy of
.I gawk
on the error output.
@@ -176,6 +248,12 @@ This is useful mainly for knowing if the current copy of
on your system
is up to date with respect to whatever the Free Software Foundation
is distributing.
+.TP
+.B \-\^\-
+Signal the end of options. This is useful to allow further arguments to the
+AWK program itself to start with a ``\-''.
+This is mainly for consistency with the argument parsing convention used
+by most other \*(PX programs.
.PP
Any other options are flagged as illegal, but are otherwise ignored.
.SH AWK PROGRAM EXECUTION
@@ -367,6 +445,11 @@ The number of command line arguments (does not include options to
.IR gawk ,
or the program source).
.TP
+.B ARGIND
+The index in
+.B ARGV
+of the current file being processed.
+.TP
.B ARGV
Array of command line arguments. The array is indexed from
0 to
@@ -393,6 +476,18 @@ function.
.IR gawk .)
.\" but don't hold your breath...
.TP
+.B ERRNO
+If a system error occurs either doing a redirection for
+.BR getline ,
+during a read for
+.BR getline ,
+or during a
+.BR close ,
+then
+.B ERRNO
+will contain
+a string describing the error.
+.TP
.B FIELDWIDTHS
A white-space separated list of fieldwidths. When set,
.I gawk
@@ -595,7 +690,7 @@ If one value is numeric and the other has a string value that is a
Otherwise, the numeric value is converted to a string and a string
comparison is performed.
Two strings are compared, of course, as strings.
-According to the \*(PX standard (draft 11), even if two strings are
+According to the \*(PX standard, even if two strings are
numeric strings, a numeric comparison is performed. However, this is
clearly incorrect, and
.I gawk
@@ -1095,8 +1190,47 @@ from a file,
recognizes certain special filenames internally. These filenames
allow access to open file descriptors inherited from
.IR gawk 's
-parent process (usually the shell). The filenames are:
+parent process (usually the shell).
+Other special filenames provide access information about the running
+.B gawk
+process.
+The filenames are:
.TP \w'\fB/dev/stdout\fR'u+1n
+.B /dev/pid
+Reading this file returns the process ID of the current process,
+in decimal, terminated with a newline.
+.TP
+.B /dev/ppid
+Reading this file returns the parent process ID of the current process,
+in decimal, terminated with a newline.
+.TP
+.B /dev/pgrpid
+Reading this file returns the process group ID of the current process,
+in decimal, terminated with a newline.
+.TP
+.B /dev/user
+Reading this file returns a single record terminated with a newline.
+The fields are separated with blanks.
+.B $1
+is the value of the
+.IR getuid (2)
+system call,
+.B $2
+is the value of the
+.IR geteuid (2)
+system call,
+.B $3
+is the value of the
+.IR getgid (2)
+system call, and
+.B $4
+is the value of the
+.IR getegid (2)
+system call.
+If there are any additional fields, they are the group IDs returned by
+.IR getgroups (2).
+(Multiple groups may not be supported on all systems.)
+.TP
.B /dev/stdin
The standard input.
.TP
@@ -1435,7 +1569,7 @@ Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger,
Addison-Wesley, 1988. ISBN 0-201-07981-X.
.PP
.IR "The GAWK Manual" ,
-Edition 0.14, published by the Free Software Foundation, 1992.
+Edition 0.15, published by the Free Software Foundation, 1993.
.SH POSIX COMPATIBILITY
A primary goal for
.I gawk
@@ -1546,6 +1680,13 @@ The special file names available for I/O redirection are not recognized.
.TP
\(bu
The
+.B ARGIND
+and
+.B ERRNO
+variables are not special.
+.TP
+\(bu
+The
.B IGNORECASE
variable and its side-effects are not available.
.TP
@@ -1601,7 +1742,11 @@ If
was compiled for debugging, it will
accept the following additional options:
.TP
-.B "\-W parsedebug"
+.PD 0
+.B \-Wparsedebug
+.TP
+.PD
+.B \-\^\-parsedebug
Turn on
.IR yacc (1)
or
@@ -1666,9 +1811,9 @@ it remains only for backwards compatibility.
.SH VERSION INFORMATION
This man page documents
.IR gawk ,
-version 2.14.
+version 2.15.
.PP
-For the 2.14 version of
+Starting with the 2.15 version of
.IR gawk ,
the
.BR \-c ,
@@ -1680,10 +1825,7 @@ the
.BR \-a ,
and
.B \-e
-options of the 2.11 version are recognized. However,
-.I gawk
-will print a warning message,
-and these options will go away in the 2.15 version.
+options of the 2.11 version are no longer recognized.
.SH AUTHORS
The original version of \*(UX
.I awk
diff --git a/gawk.info b/gawk.info
new file mode 100644
index 00000000..4cd036db
--- /dev/null
+++ b/gawk.info
@@ -0,0 +1,204 @@
+This is Info file gawk.info, produced by Makeinfo-1.54 from the input
+file gawk.texi.
+
+ This file documents `awk', a program that you can use to select
+particular records in a file and perform operations upon them.
+
+ This is Edition 0.15 of `The GAWK Manual',
+for the 2.15 version of the GNU implementation
+of AWK.
+
+ Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that
+the entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Foundation.
+
+
+Indirect:
+gawk.info-1: 1052
+gawk.info-2: 48248
+gawk.info-3: 98077
+gawk.info-4: 146748
+gawk.info-5: 195871
+gawk.info-6: 243594
+gawk.info-7: 291465
+gawk.info-8: 340847
+gawk.info-9: 380680
+
+Tag Table:
+(Indirect)
+Node: Top1052
+Node: Preface3963
+Node: History5556
+Node: Copying7899
+Node: This Manual27051
+Node: Sample Data Files28895
+Node: Getting Started31687
+Node: Very Simple33398
+Node: Two Rules35366
+Node: More Complex37450
+Node: Running gawk40436
+Node: One-shot41385
+Node: Read Terminal42521
+Node: Long43580
+Node: Executable Scripts44922
+Node: Comments47145
+Node: Statements/Lines48248
+Node: When51139
+Node: Reading Files53054
+Node: Records54781
+Node: Fields58015
+Node: Non-Constant Fields60628
+Node: Changing Fields62452
+Node: Field Separators65825
+Node: Constant Size75461
+Node: Multiple Line79009
+Node: Getline81405
+Node: Close Input91149
+Node: Printing92605
+Node: Print93604
+Node: Print Examples95738
+Node: Output Separators98077
+Node: OFMT99815
+Node: Printf100959
+Node: Basic Printf101863
+Node: Control Letters103288
+Node: Format Modifiers105102
+Node: Printf Examples107607
+Node: Redirection110289
+Node: File/Pipe Redirection111025
+Node: Close Output114498
+Node: Special Files117002
+Node: One-liners121936
+Node: Patterns124658
+Node: Kinds of Patterns125636
+Node: Regexp126641
+Node: Regexp Usage127585
+Node: Regexp Operators129614
+Node: Case-sensitivity135092
+Node: Comparison Patterns137402
+Node: Boolean Patterns139563
+Node: Expression Patterns141073
+Node: Ranges142513
+Node: BEGIN/END143923
+Node: Empty146477
+Node: Actions146748
+Node: Expressions149128
+Node: Constants151149
+Node: Variables156714
+Node: Assignment Options158323
+Node: Arithmetic Ops160007
+Node: Concatenation161673
+Node: Comparison Ops163021
+Node: Boolean Ops167446
+Node: Assignment Ops169909
+Node: Increment Ops173983
+Node: Conversion176479
+Node: Values179554
+Node: Conditional Exp182137
+Node: Function Calls183465
+Node: Precedence186229
+Node: Statements189612
+Node: If Statement191295
+Node: While Statement192823
+Node: Do Statement194786
+Node: For Statement195871
+Node: Break Statement199063
+Node: Continue Statement200672
+Node: Next Statement203295
+Node: Next File Statement205239
+Node: Exit Statement208285
+Node: Arrays209900
+Node: Array Intro211102
+Node: Reference to Elements214605
+Node: Assigning Elements216548
+Node: Array Example217050
+Node: Scanning an Array218781
+Node: Delete221081
+Node: Numeric Array Subscripts222061
+Node: Multi-dimensional223941
+Node: Multi-scanning227169
+Node: Built-in228791
+Node: Calling Built-in229748
+Node: Numeric Functions231012
+Node: String Functions234359
+Node: I/O Functions243594
+Node: Time Functions246218
+Node: User-defined254306
+Node: Definition Syntax255024
+Node: Function Example259016
+Node: Function Caveats260091
+Node: Return Statement263134
+Node: Built-in Variables265517
+Node: User-modified266553
+Node: Auto-set270830
+Node: Command Line276569
+Node: Options277494
+Node: Other Arguments284568
+Node: AWKPATH Variable286934
+Node: Obsolete289076
+Node: Undocumented290336
+Node: Language History290524
+Node: V7/S5R3.1291465
+Node: S5R4294169
+Node: POSIX295706
+Node: POSIX/GNU296424
+Node: Installation298055
+Node: Gawk Distribution298921
+Node: Extracting299374
+Node: Distribution contents300969
+Node: Unix Installation303773
+Node: Quick Installation304464
+Node: Configuration Philosophy305633
+Node: New Configurations307959
+Node: VMS Installation310061
+Node: VMS Compilation310620
+Node: VMS Installation Details312235
+Node: VMS Running313872
+Node: VMS POSIX315458
+Node: MS-DOS Installation316846
+Node: Atari Installation317774
+Node: Gawk Summary323536
+Node: Command Line Summary324297
+Node: Language Summary326730
+Node: Variables/Fields328819
+Node: Fields Summary329545
+Node: Built-in Summary331012
+Node: Arrays Summary334217
+Node: Data Type Summary335492
+Node: Rules Summary336965
+Node: Pattern Summary338614
+Node: Regexp Summary340847
+Node: Actions Summary342067
+Node: Operator Summary342982
+Node: Control Flow Summary344343
+Node: I/O Summary344949
+Node: Printf Summary346828
+Node: Special File Summary348654
+Node: Numeric Functions Summary350712
+Node: String Functions Summary351548
+Node: Time Functions Summary353380
+Node: String Constants Summary354144
+Node: Functions Summary355527
+Node: Historical Features356586
+Node: Sample Program357443
+Node: Bugs361697
+Node: Notes364545
+Node: Compatibility Mode365074
+Node: Future Extensions365907
+Node: Improvements368204
+Node: Glossary370239
+Node: Index380680
+
+End Tag Table
diff --git a/gawk.info-1 b/gawk.info-1
new file mode 100644
index 00000000..e6f2e750
--- /dev/null
+++ b/gawk.info-1
@@ -0,0 +1,1069 @@
+This is Info file gawk.info, produced by Makeinfo-1.54 from the input
+file gawk.texi.
+
+ This file documents `awk', a program that you can use to select
+particular records in a file and perform operations upon them.
+
+ This is Edition 0.15 of `The GAWK Manual',
+for the 2.15 version of the GNU implementation
+of AWK.
+
+ Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that
+the entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Foundation.
+
+
+File: gawk.info, Node: Top, Next: Preface, Prev: (dir), Up: (dir)
+
+General Introduction
+********************
+
+ This file documents `awk', a program that you can use to select
+particular records in a file and perform operations upon them.
+
+ This is Edition 0.15 of `The GAWK Manual',
+for the 2.15 version of the GNU implementation
+of AWK.
+
+* Menu:
+
+* Preface:: What you can do with `awk'; brief history
+ and acknowledgements.
+* Copying:: Your right to copy and distribute `gawk'.
+* This Manual:: Using this manual.
+ Includes sample input files that you can use.
+* Getting Started:: A basic introduction to using `awk'.
+ How to run an `awk' program.
+ Command line syntax.
+* Reading Files:: How to read files and manipulate fields.
+* Printing:: How to print using `awk'. Describes the
+ `print' and `printf' statements.
+ Also describes redirection of output.
+* One-liners:: Short, sample `awk' programs.
+* Patterns:: The various types of patterns
+ explained in detail.
+* Actions:: The various types of actions are
+ introduced here. Describes
+ expressions and the various operators in
+ detail. Also describes comparison expressions.
+* Expressions:: Expressions are the basic building
+ blocks of statements.
+* Statements:: The various control statements are
+ described in detail.
+* Arrays:: The description and use of arrays.
+ Also includes array-oriented control
+ statements.
+* Built-in:: The built-in functions are summarized here.
+* User-defined:: User-defined functions are described in detail.
+* Built-in Variables:: Built-in Variables
+* Command Line:: How to run `gawk'.
+* Language History:: The evolution of the `awk' language.
+* Installation:: Installing `gawk' under
+ various operating systems.
+* Gawk Summary:: `gawk' Options and Language Summary.
+* Sample Program:: A sample `awk' program with a
+ complete explanation.
+* Bugs:: Reporting Problems and Bugs.
+* Notes:: Something about the
+ implementation of `gawk'.
+* Glossary:: An explanation of some unfamiliar terms.
+* Index::
+
+
+File: gawk.info, Node: Preface, Next: Copying, Prev: Top, Up: Top
+
+Preface
+*******
+
+ If you are like many computer users, you would frequently like to
+make changes in various text files wherever certain patterns appear, or
+extract data from parts of certain lines while discarding the rest. To
+write a program to do this in a language such as C or Pascal is a
+time-consuming inconvenience that may take many lines of code. The job
+may be easier with `awk'.
+
+ The `awk' utility interprets a special-purpose programming language
+that makes it possible to handle simple data-reformatting jobs easily
+with just a few lines of code.
+
+ The GNU implementation of `awk' is called `gawk'; it is fully upward
+compatible with the System V Release 4 version of `awk'. `gawk' is
+also upward compatible with the POSIX (draft) specification of the
+`awk' language. This means that all properly written `awk' programs
+should work with `gawk'. Thus, we usually don't distinguish between
+`gawk' and other `awk' implementations in this manual.
+
+ This manual teaches you what `awk' does and how you can use `awk'
+effectively. You should already be familiar with basic system commands
+such as `ls'. Using `awk' you can:
+
+ * manage small, personal databases
+
+ * generate reports
+
+ * validate data
+
+ * produce indexes, and perform other document preparation tasks
+
+ * even experiment with algorithms that can be adapted later to other
+ computer languages
+
+* Menu:
+
+* History:: The history of `gawk' and
+ `awk'. Acknowledgements.
+
+
+File: gawk.info, Node: History, Prev: Preface, Up: Preface
+
+History of `awk' and `gawk'
+===========================
+
+ The name `awk' comes from the initials of its designers: Alfred V.
+Aho, Peter J. Weinberger, and Brian W. Kernighan. The original version
+of `awk' was written in 1977. In 1985 a new version made the
+programming language more powerful, introducing user-defined functions,
+multiple input streams, and computed regular expressions. This new
+version became generally available with System V Release 3.1. The
+version in System V Release 4 added some new features and also cleaned
+up the behavior in some of the "dark corners" of the language. The
+specification for `awk' in the POSIX Command Language and Utilities
+standard further clarified the language based on feedback from both the
+`gawk' designers, and the original `awk' designers.
+
+ The GNU implementation, `gawk', was written in 1986 by Paul Rubin
+and Jay Fenlason, with advice from Richard Stallman. John Woods
+contributed parts of the code as well. In 1988 and 1989, David
+Trueman, with help from Arnold Robbins, thoroughly reworked `gawk' for
+compatibility with the newer `awk'. Current development (1992) focuses
+on bug fixes, performance improvements, and standards compliance.
+
+ We need to thank many people for their assistance in producing this
+manual. Jay Fenlason contributed many ideas and sample programs.
+Richard Mlynarik and Robert J. Chassell gave helpful comments on early
+drafts of this manual. The paper `A Supplemental Document for `awk''
+by John W. Pierce of the Chemistry Department at UC San Diego,
+pinpointed several issues relevant both to `awk' implementation and to
+this manual, that would otherwise have escaped us. David Trueman, Pat
+Rankin, and Michal Jaegermann also contributed sections of the manual.
+
+ The following people provided many helpful comments on this edition
+of the manual: Rick Adams, Michael Brennan, Rich Burridge, Diane Close,
+Christopher ("Topher") Eliot, Michael Lijewski, Pat Rankin, Miriam
+Robbins, and Michal Jaegermann. Robert J. Chassell provided much
+valuable advice on the use of Texinfo.
+
+ Finally, we would like to thank Brian Kernighan of Bell Labs for
+invaluable assistance during the testing and debugging of `gawk', and
+for help in clarifying numerous points about the language.
+
+
+File: gawk.info, Node: Copying, Next: This Manual, Prev: Preface, Up: Top
+
+GNU GENERAL PUBLIC LICENSE
+**************************
+
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 675 Mass Ave, Cambridge, MA 02139, USA
+
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+Preamble
+========
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it in
+new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software,
+and (2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 1. This License applies to any program or other work which contains a
+ notice placed by the copyright holder saying it may be distributed
+ under the terms of this General Public License. The "Program",
+ below, refers to any such program or work, and a "work based on
+ the Program" means either the Program or any derivative work under
+ copyright law: that is to say, a work containing the Program or a
+ portion of it, either verbatim or with modifications and/or
+ translated into another language. (Hereinafter, translation is
+ included without limitation in the term "modification".) Each
+ licensee is addressed as "you".
+
+ Activities other than copying, distribution and modification are
+ not covered by this License; they are outside its scope. The act
+ of running the Program is not restricted, and the output from the
+ Program is covered only if its contents constitute a work based on
+ the Program (independent of having been made by running the
+ Program). Whether that is true depends on what the Program does.
+
+ 2. You may copy and distribute verbatim copies of the Program's
+ source code as you receive it, in any medium, provided that you
+ conspicuously and appropriately publish on each copy an appropriate
+ copyright notice and disclaimer of warranty; keep intact all the
+ notices that refer to this License and to the absence of any
+ warranty; and give any other recipients of the Program a copy of
+ this License along with the Program.
+
+ You may charge a fee for the physical act of transferring a copy,
+ and you may at your option offer warranty protection in exchange
+ for a fee.
+
+ 3. You may modify your copy or copies of the Program or any portion
+ of it, thus forming a work based on the Program, and copy and
+ distribute such modifications or work under the terms of Section 1
+ above, provided that you also meet all of these conditions:
+
+ a. You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b. You must cause any work that you distribute or publish, that
+ in whole or in part contains or is derived from the Program
+ or any part thereof, to be licensed as a whole at no charge
+ to all third parties under the terms of this License.
+
+ c. If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display
+ an announcement including an appropriate copyright notice and
+ a notice that there is no warranty (or else, saying that you
+ provide a warranty) and that users may redistribute the
+ program under these conditions, and telling the user how to
+ view a copy of this License. (Exception: if the Program
+ itself is interactive but does not normally print such an
+ announcement, your work based on the Program is not required
+ to print an announcement.)
+
+ These requirements apply to the modified work as a whole. If
+ identifiable sections of that work are not derived from the
+ Program, and can be reasonably considered independent and separate
+ works in themselves, then this License, and its terms, do not
+ apply to those sections when you distribute them as separate
+ works. But when you distribute the same sections as part of a
+ whole which is a work based on the Program, the distribution of
+ the whole must be on the terms of this License, whose permissions
+ for other licensees extend to the entire whole, and thus to each
+ and every part regardless of who wrote it.
+
+ Thus, it is not the intent of this section to claim rights or
+ contest your rights to work written entirely by you; rather, the
+ intent is to exercise the right to control the distribution of
+ derivative or collective works based on the Program.
+
+ In addition, mere aggregation of another work not based on the
+ Program with the Program (or with a work based on the Program) on
+ a volume of a storage or distribution medium does not bring the
+ other work under the scope of this License.
+
+ 4. You may copy and distribute the Program (or a work based on it,
+ under Section 2) in object code or executable form under the terms
+ of Sections 1 and 2 above provided that you also do one of the
+ following:
+
+ a. Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of
+ Sections 1 and 2 above on a medium customarily used for
+ software interchange; or,
+
+ b. Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a
+ medium customarily used for software interchange; or,
+
+ c. Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with
+ such an offer, in accord with Subsection b above.)
+
+ The source code for a work means the preferred form of the work for
+ making modifications to it. For an executable work, complete
+ source code means all the source code for all modules it contains,
+ plus any associated interface definition files, plus the scripts
+ used to control compilation and installation of the executable.
+ However, as a special exception, the source code distributed need
+ not include anything that is normally distributed (in either
+ source or binary form) with the major components (compiler,
+ kernel, and so on) of the operating system on which the executable
+ runs, unless that component itself accompanies the executable.
+
+ If distribution of executable or object code is made by offering
+ access to copy from a designated place, then offering equivalent
+ access to copy the source code from the same place counts as
+ distribution of the source code, even though third parties are not
+ compelled to copy the source along with the object code.
+
+ 5. You may not copy, modify, sublicense, or distribute the Program
+ except as expressly provided under this License. Any attempt
+ otherwise to copy, modify, sublicense or distribute the Program is
+ void, and will automatically terminate your rights under this
+ License. However, parties who have received copies, or rights,
+ from you under this License will not have their licenses
+ terminated so long as such parties remain in full compliance.
+
+ 6. You are not required to accept this License, since you have not
+ signed it. However, nothing else grants you permission to modify
+ or distribute the Program or its derivative works. These actions
+ are prohibited by law if you do not accept this License.
+ Therefore, by modifying or distributing the Program (or any work
+ based on the Program), you indicate your acceptance of this
+ License to do so, and all its terms and conditions for copying,
+ distributing or modifying the Program or works based on it.
+
+ 7. Each time you redistribute the Program (or any work based on the
+ Program), the recipient automatically receives a license from the
+ original licensor to copy, distribute or modify the Program
+ subject to these terms and conditions. You may not impose any
+ further restrictions on the recipients' exercise of the rights
+ granted herein. You are not responsible for enforcing compliance
+ by third parties to this License.
+
+ 8. If, as a consequence of a court judgment or allegation of patent
+ infringement or for any other reason (not limited to patent
+ issues), conditions are imposed on you (whether by court order,
+ agreement or otherwise) that contradict the conditions of this
+ License, they do not excuse you from the conditions of this
+ License. If you cannot distribute so as to satisfy simultaneously
+ your obligations under this License and any other pertinent
+ obligations, then as a consequence you may not distribute the
+ Program at all. For example, if a patent license would not permit
+ royalty-free redistribution of the Program by all those who
+ receive copies directly or indirectly through you, then the only
+ way you could satisfy both it and this License would be to refrain
+ entirely from distribution of the Program.
+
+ If any portion of this section is held invalid or unenforceable
+ under any particular circumstance, the balance of the section is
+ intended to apply and the section as a whole is intended to apply
+ in other circumstances.
+
+ It is not the purpose of this section to induce you to infringe any
+ patents or other property right claims or to contest validity of
+ any such claims; this section has the sole purpose of protecting
+ the integrity of the free software distribution system, which is
+ implemented by public license practices. Many people have made
+ generous contributions to the wide range of software distributed
+ through that system in reliance on consistent application of that
+ system; it is up to the author/donor to decide if he or she is
+ willing to distribute software through any other system and a
+ licensee cannot impose that choice.
+
+ This section is intended to make thoroughly clear what is believed
+ to be a consequence of the rest of this License.
+
+ 9. If the distribution and/or use of the Program is restricted in
+ certain countries either by patents or by copyrighted interfaces,
+ the original copyright holder who places the Program under this
+ License may add an explicit geographical distribution limitation
+ excluding those countries, so that distribution is permitted only
+ in or among countries not thus excluded. In such case, this
+ License incorporates the limitation as if written in the body of
+ this License.
+
+ 10. The Free Software Foundation may publish revised and/or new
+ versions of the General Public License from time to time. Such
+ new versions will be similar in spirit to the present version, but
+ may differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+ Program specifies a version number of this License which applies
+ to it and "any later version", you have the option of following
+ the terms and conditions either of that version or of any later
+ version published by the Free Software Foundation. If the Program
+ does not specify a version number of this License, you may choose
+ any version ever published by the Free Software Foundation.
+
+ 11. If you wish to incorporate parts of the Program into other free
+ programs whose distribution conditions are different, write to the
+ author to ask for permission. For software which is copyrighted
+ by the Free Software Foundation, write to the Free Software
+ Foundation; we sometimes make exceptions for this. Our decision
+ will be guided by the two goals of preserving the free status of
+ all derivatives of our free software and of promoting the sharing
+ and reuse of software generally.
+
+ NO WARRANTY
+
+ 12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
+ WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
+ LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
+ WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
+ NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
+ QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
+ SERVICING, REPAIR OR CORRECTION.
+
+ 13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+ WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
+ MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
+ LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
+ INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
+ INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
+ OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
+ OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+How to Apply These Terms to Your New Programs
+=============================================
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these
+terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES.
+ Copyright (C) 19YY NAME OF AUTHOR
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ Also add information on how to contact you by electronic and paper
+mail.
+
+ If the program is interactive, make it output a short notice like
+this when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
+ type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+ The hypothetical commands `show w' and `show c' should show the
+appropriate parts of the General Public License. Of course, the
+commands you use may be called something other than `show w' and `show
+c'; they could even be mouse-clicks or menu items--whatever suits your
+program.
+
+ You should also get your employer (if you work as a programmer) or
+your school, if any, to sign a "copyright disclaimer" for the program,
+if necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ SIGNATURE OF TY COON, 1 April 1989
+ Ty Coon, President of Vice
+
+ This General Public License does not permit incorporating your
+program into proprietary programs. If your program is a subroutine
+library, you may consider it more useful to permit linking proprietary
+applications with the library. If this is what you want to do, use the
+GNU Library General Public License instead of this License.
+
+
+File: gawk.info, Node: This Manual, Next: Getting Started, Prev: Copying, Up: Top
+
+Using this Manual
+*****************
+
+ The term `awk' refers to a particular program, and to the language
+you use to tell this program what to do. When we need to be careful,
+we call the program "the `awk' utility" and the language "the `awk'
+language." The term `gawk' refers to a version of `awk' developed as
+part the GNU project. The purpose of this manual is to explain both the
+`awk' language and how to run the `awk' utility.
+
+ While concentrating on the features of `gawk', the manual will also
+attempt to describe important differences between `gawk' and other
+`awk' implementations. In particular, any features that are not in the
+POSIX standard for `awk' will be noted.
+
+ The term "`awk' program" refers to a program written by you in the
+`awk' programming language.
+
+ *Note Getting Started with `awk': Getting Started, for the bare
+essentials you need to know to start using `awk'.
+
+ Some useful "one-liners" are included to give you a feel for the
+`awk' language (*note Useful "One-liners": One-liners.).
+
+ A sample `awk' program has been provided for you (*note Sample
+Program::.).
+
+ If you find terms that you aren't familiar with, try looking them up
+in the glossary (*note Glossary::.).
+
+ The entire `awk' language is summarized for quick reference in *Note
+`gawk' Summary: Gawk Summary. Look there if you just need to refresh
+your memory about a particular feature.
+
+ Most of the time complete `awk' programs are used as examples, but in
+some of the more advanced sections, only the part of the `awk' program
+that illustrates the concept being described is shown.
+
+* Menu:
+
+* Sample Data Files:: Sample data files for use in the `awk'
+ programs illustrated in this manual.
+
+
+File: gawk.info, Node: Sample Data Files, Prev: This Manual, Up: This Manual
+
+Data Files for the Examples
+===========================
+
+ Many of the examples in this manual take their input from two sample
+data files. The first, called `BBS-list', represents a list of
+computer bulletin board systems together with information about those
+systems. The second data file, called `inventory-shipped', contains
+information about shipments on a monthly basis. Each line of these
+files is one "record".
+
+ In the file `BBS-list', each record contains the name of a computer
+bulletin board, its phone number, the board's baud rate, and a code for
+the number of hours it is operational. An `A' in the last column means
+the board operates 24 hours a day. A `B' in the last column means the
+board operates evening and weekend hours, only. A `C' means the board
+operates only on weekends.
+
+ aardvark 555-5553 1200/300 B
+ alpo-net 555-3412 2400/1200/300 A
+ barfly 555-7685 1200/300 A
+ bites 555-1675 2400/1200/300 A
+ camelot 555-0542 300 C
+ core 555-2912 1200/300 C
+ fooey 555-1234 2400/1200/300 B
+ foot 555-6699 1200/300 B
+ macfoo 555-6480 1200/300 A
+ sdace 555-3430 2400/1200/300 A
+ sabafoo 555-2127 1200/300 C
+
+ The second data file, called `inventory-shipped', represents
+information about shipments during the year. Each record contains the
+month of the year, the number of green crates shipped, the number of
+red boxes shipped, the number of orange bags shipped, and the number of
+blue packages shipped, respectively. There are 16 entries, covering
+the 12 months of one year and 4 months of the next year.
+
+ Jan 13 25 15 115
+ Feb 15 32 24 226
+ Mar 15 24 34 228
+ Apr 31 52 63 420
+ May 16 34 29 208
+ Jun 31 42 75 492
+ Jul 24 34 67 436
+ Aug 15 34 47 316
+ Sep 13 55 37 277
+ Oct 29 54 68 525
+ Nov 20 87 82 577
+ Dec 17 35 61 401
+
+ Jan 21 36 64 620
+ Feb 26 58 80 652
+ Mar 24 75 70 495
+ Apr 21 70 74 514
+
+ If you are reading this in GNU Emacs using Info, you can copy the
+regions of text showing these sample files into your own test files.
+This way you can try out the examples shown in the remainder of this
+document. You do this by using the command `M-x write-region' to copy
+text from the Info file into a file for use with `awk' (*Note Misc File
+Ops: (emacs)Misc File Ops, for more information). Using this
+information, create your own `BBS-list' and `inventory-shipped' files,
+and practice what you learn in this manual.
+
+
+File: gawk.info, Node: Getting Started, Next: Reading Files, Prev: This Manual, Up: Top
+
+Getting Started with `awk'
+**************************
+
+ The basic function of `awk' is to search files for lines (or other
+units of text) that contain certain patterns. When a line matches one
+of the patterns, `awk' performs specified actions on that line. `awk'
+keeps processing input lines in this way until the end of the input
+file is reached.
+
+ When you run `awk', you specify an `awk' "program" which tells `awk'
+what to do. The program consists of a series of "rules". (It may also
+contain "function definitions", but that is an advanced feature, so we
+will ignore it for now. *Note User-defined Functions: User-defined.)
+Each rule specifies one pattern to search for, and one action to
+perform when that pattern is found.
+
+ Syntactically, a rule consists of a pattern followed by an action.
+The action is enclosed in curly braces to separate it from the pattern.
+Rules are usually separated by newlines. Therefore, an `awk' program
+looks like this:
+
+ PATTERN { ACTION }
+ PATTERN { ACTION }
+ ...
+
+* Menu:
+
+* Very Simple:: A very simple example.
+* Two Rules:: A less simple one-line example with two rules.
+* More Complex:: A more complex example.
+* Running gawk:: How to run `gawk' programs;
+ includes command line syntax.
+* Comments:: Adding documentation to `gawk' programs.
+* Statements/Lines:: Subdividing or combining statements into lines.
+* When:: When to use `gawk' and
+ when to use other things.
+
+
+File: gawk.info, Node: Very Simple, Next: Two Rules, Prev: Getting Started, Up: Getting Started
+
+A Very Simple Example
+=====================
+
+ The following command runs a simple `awk' program that searches the
+input file `BBS-list' for the string of characters: `foo'. (A string
+of characters is usually called, a "string". The term "string" is
+perhaps based on similar usage in English, such as "a string of
+pearls," or, "a string of cars in a train.")
+
+ awk '/foo/ { print $0 }' BBS-list
+
+When lines containing `foo' are found, they are printed, because
+`print $0' means print the current line. (Just `print' by itself means
+the same thing, so we could have written that instead.)
+
+ You will notice that slashes, `/', surround the string `foo' in the
+actual `awk' program. The slashes indicate that `foo' is a pattern to
+search for. This type of pattern is called a "regular expression", and
+is covered in more detail later (*note Regular Expressions as Patterns:
+Regexp.). There are single-quotes around the `awk' program so that the
+shell won't interpret any of it as special shell characters.
+
+ Here is what this program prints:
+
+ fooey 555-1234 2400/1200/300 B
+ foot 555-6699 1200/300 B
+ macfoo 555-6480 1200/300 A
+ sabafoo 555-2127 1200/300 C
+
+ In an `awk' rule, either the pattern or the action can be omitted,
+but not both. If the pattern is omitted, then the action is performed
+for *every* input line. If the action is omitted, the default action
+is to print all lines that match the pattern.
+
+ Thus, we could leave out the action (the `print' statement and the
+curly braces) in the above example, and the result would be the same:
+all lines matching the pattern `foo' would be printed. By comparison,
+omitting the `print' statement but retaining the curly braces makes an
+empty action that does nothing; then no lines would be printed.
+
+
+File: gawk.info, Node: Two Rules, Next: More Complex, Prev: Very Simple, Up: Getting Started
+
+An Example with Two Rules
+=========================
+
+ The `awk' utility reads the input files one line at a time. For
+each line, `awk' tries the patterns of each of the rules. If several
+patterns match then several actions are run, in the order in which they
+appear in the `awk' program. If no patterns match, then no actions are
+run.
+
+ After processing all the rules (perhaps none) that match the line,
+`awk' reads the next line (however, *note The `next' Statement: Next
+Statement.). This continues until the end of the file is reached.
+
+ For example, the `awk' program:
+
+ /12/ { print $0 }
+ /21/ { print $0 }
+
+contains two rules. The first rule has the string `12' as the pattern
+and `print $0' as the action. The second rule has the string `21' as
+the pattern and also has `print $0' as the action. Each rule's action
+is enclosed in its own pair of braces.
+
+ This `awk' program prints every line that contains the string `12'
+*or* the string `21'. If a line contains both strings, it is printed
+twice, once by each rule.
+
+ If we run this program on our two sample data files, `BBS-list' and
+`inventory-shipped', as shown here:
+
+ awk '/12/ { print $0 }
+ /21/ { print $0 }' BBS-list inventory-shipped
+
+we get the following output:
+
+ aardvark 555-5553 1200/300 B
+ alpo-net 555-3412 2400/1200/300 A
+ barfly 555-7685 1200/300 A
+ bites 555-1675 2400/1200/300 A
+ core 555-2912 1200/300 C
+ fooey 555-1234 2400/1200/300 B
+ foot 555-6699 1200/300 B
+ macfoo 555-6480 1200/300 A
+ sdace 555-3430 2400/1200/300 A
+ sabafoo 555-2127 1200/300 C
+ sabafoo 555-2127 1200/300 C
+ Jan 21 36 64 620
+ Apr 21 70 74 514
+
+Note how the line in `BBS-list' beginning with `sabafoo' was printed
+twice, once for each rule.
+
+
+File: gawk.info, Node: More Complex, Next: Running gawk, Prev: Two Rules, Up: Getting Started
+
+A More Complex Example
+======================
+
+ Here is an example to give you an idea of what typical `awk'
+programs do. This example shows how `awk' can be used to summarize,
+select, and rearrange the output of another utility. It uses features
+that haven't been covered yet, so don't worry if you don't understand
+all the details.
+
+ ls -l | awk '$5 == "Nov" { sum += $4 }
+ END { print sum }'
+
+ This command prints the total number of bytes in all the files in the
+current directory that were last modified in November (of any year).
+(In the C shell you would need to type a semicolon and then a backslash
+at the end of the first line; in a POSIX-compliant shell, such as the
+Bourne shell or the Bourne-Again shell, you can type the example as
+shown.)
+
+ The `ls -l' part of this example is a command that gives you a
+listing of the files in a directory, including file size and date. Its
+output looks like this:
+
+ -rw-r--r-- 1 close 1933 Nov 7 13:05 Makefile
+ -rw-r--r-- 1 close 10809 Nov 7 13:03 gawk.h
+ -rw-r--r-- 1 close 983 Apr 13 12:14 gawk.tab.h
+ -rw-r--r-- 1 close 31869 Jun 15 12:20 gawk.y
+ -rw-r--r-- 1 close 22414 Nov 7 13:03 gawk1.c
+ -rw-r--r-- 1 close 37455 Nov 7 13:03 gawk2.c
+ -rw-r--r-- 1 close 27511 Dec 9 13:07 gawk3.c
+ -rw-r--r-- 1 close 7989 Nov 7 13:03 gawk4.c
+
+The first field contains read-write permissions, the second field
+contains the number of links to the file, and the third field
+identifies the owner of the file. The fourth field contains the size
+of the file in bytes. The fifth, sixth, and seventh fields contain the
+month, day, and time, respectively, that the file was last modified.
+Finally, the eighth field contains the name of the file.
+
+ The `$5 == "Nov"' in our `awk' program is an expression that tests
+whether the fifth field of the output from `ls -l' matches the string
+`Nov'. Each time a line has the string `Nov' in its fifth field, the
+action `{ sum += $4 }' is performed. This adds the fourth field (the
+file size) to the variable `sum'. As a result, when `awk' has finished
+reading all the input lines, `sum' is the sum of the sizes of files
+whose lines matched the pattern. (This works because `awk' variables
+are automatically initialized to zero.)
+
+ After the last line of output from `ls' has been processed, the
+`END' rule is executed, and the value of `sum' is printed. In this
+example, the value of `sum' would be 80600.
+
+ These more advanced `awk' techniques are covered in later sections
+(*note Overview of Actions: Actions.). Before you can move on to more
+advanced `awk' programming, you have to know how `awk' interprets your
+input and displays your output. By manipulating fields and using
+`print' statements, you can produce some very useful and spectacular
+looking reports.
+
+
+File: gawk.info, Node: Running gawk, Next: Comments, Prev: More Complex, Up: Getting Started
+
+How to Run `awk' Programs
+=========================
+
+ There are several ways to run an `awk' program. If the program is
+short, it is easiest to include it in the command that runs `awk', like
+this:
+
+ awk 'PROGRAM' INPUT-FILE1 INPUT-FILE2 ...
+
+where PROGRAM consists of a series of patterns and actions, as
+described earlier.
+
+ When the program is long, it is usually more convenient to put it in
+a file and run it with a command like this:
+
+ awk -f PROGRAM-FILE INPUT-FILE1 INPUT-FILE2 ...
+
+* Menu:
+
+* One-shot:: Running a short throw-away `awk' program.
+* Read Terminal:: Using no input files (input from
+ terminal instead).
+* Long:: Putting permanent `awk' programs in files.
+* Executable Scripts:: Making self-contained `awk' programs.
+
+
+File: gawk.info, Node: One-shot, Next: Read Terminal, Prev: Running gawk, Up: Running gawk
+
+One-shot Throw-away `awk' Programs
+----------------------------------
+
+ Once you are familiar with `awk', you will often type simple
+programs at the moment you want to use them. Then you can write the
+program as the first argument of the `awk' command, like this:
+
+ awk 'PROGRAM' INPUT-FILE1 INPUT-FILE2 ...
+
+where PROGRAM consists of a series of PATTERNS and ACTIONS, as
+described earlier.
+
+ This command format instructs the shell to start `awk' and use the
+PROGRAM to process records in the input file(s). There are single
+quotes around PROGRAM so that the shell doesn't interpret any `awk'
+characters as special shell characters. They also cause the shell to
+treat all of PROGRAM as a single argument for `awk' and allow PROGRAM
+to be more than one line long.
+
+ This format is also useful for running short or medium-sized `awk'
+programs from shell scripts, because it avoids the need for a separate
+file for the `awk' program. A self-contained shell script is more
+reliable since there are no other files to misplace.
+
+
+File: gawk.info, Node: Read Terminal, Next: Long, Prev: One-shot, Up: Running gawk
+
+Running `awk' without Input Files
+---------------------------------
+
+ You can also run `awk' without any input files. If you type the
+command line:
+
+ awk 'PROGRAM'
+
+then `awk' applies the PROGRAM to the "standard input", which usually
+means whatever you type on the terminal. This continues until you
+indicate end-of-file by typing `Control-d'.
+
+ For example, if you execute this command:
+
+ awk '/th/'
+
+whatever you type next is taken as data for that `awk' program. If you
+go on to type the following data:
+
+ Kathy
+ Ben
+ Tom
+ Beth
+ Seth
+ Karen
+ Thomas
+ `Control-d'
+
+then `awk' prints this output:
+
+ Kathy
+ Beth
+ Seth
+
+as matching the pattern `th'. Notice that it did not recognize
+`Thomas' as matching the pattern. The `awk' language is "case
+sensitive", and matches patterns exactly. (However, you can override
+this with the variable `IGNORECASE'. *Note Case-sensitivity in
+Matching: Case-sensitivity.)
+
+
+File: gawk.info, Node: Long, Next: Executable Scripts, Prev: Read Terminal, Up: Running gawk
+
+Running Long Programs
+---------------------
+
+ Sometimes your `awk' programs can be very long. In this case it is
+more convenient to put the program into a separate file. To tell `awk'
+to use that file for its program, you type:
+
+ awk -f SOURCE-FILE INPUT-FILE1 INPUT-FILE2 ...
+
+ The `-f' instructs the `awk' utility to get the `awk' program from
+the file SOURCE-FILE. Any file name can be used for SOURCE-FILE. For
+example, you could put the program:
+
+ /th/
+
+into the file `th-prog'. Then this command:
+
+ awk -f th-prog
+
+does the same thing as this one:
+
+ awk '/th/'
+
+which was explained earlier (*note Running `awk' without Input Files:
+Read Terminal.). Note that you don't usually need single quotes around
+the file name that you specify with `-f', because most file names don't
+contain any of the shell's special characters. Notice that in
+`th-prog', the `awk' program did not have single quotes around it. The
+quotes are only needed for programs that are provided on the `awk'
+command line.
+
+ If you want to identify your `awk' program files clearly as such,
+you can add the extension `.awk' to the file name. This doesn't affect
+the execution of the `awk' program, but it does make "housekeeping"
+easier.
+
+
+File: gawk.info, Node: Executable Scripts, Prev: Long, Up: Running gawk
+
+Executable `awk' Programs
+-------------------------
+
+ Once you have learned `awk', you may want to write self-contained
+`awk' scripts, using the `#!' script mechanism. You can do this on
+many Unix systems (1) (and someday on GNU).
+
+ For example, you could create a text file named `hello', containing
+the following (where `BEGIN' is a feature we have not yet discussed):
+
+ #! /bin/awk -f
+
+ # a sample awk program
+ BEGIN { print "hello, world" }
+
+After making this file executable (with the `chmod' command), you can
+simply type:
+
+ hello
+
+at the shell, and the system will arrange to run `awk' (2) as if you
+had typed:
+
+ awk -f hello
+
+Self-contained `awk' scripts are useful when you want to write a
+program which users can invoke without knowing that the program is
+written in `awk'.
+
+ If your system does not support the `#!' mechanism, you can get a
+similar effect using a regular shell script. It would look something
+like this:
+
+ : The colon makes sure this script is executed by the Bourne shell.
+ awk 'PROGRAM' "$@"
+
+ Using this technique, it is *vital* to enclose the PROGRAM in single
+quotes to protect it from interpretation by the shell. If you omit the
+quotes, only a shell wizard can predict the results.
+
+ The `"$@"' causes the shell to forward all the command line
+arguments to the `awk' program, without interpretation. The first
+line, which starts with a colon, is used so that this shell script will
+work even if invoked by a user who uses the C shell.
+
+ ---------- Footnotes ----------
+
+ (1) The `#!' mechanism works on Unix systems derived from Berkeley
+Unix, System V Release 4, and some System V Release 3 systems.
+
+ (2) The line beginning with `#!' lists the full pathname of an
+interpreter to be run, and an optional initial command line argument to
+pass to that interpreter. The operating system then runs the
+interpreter with the given argument and the full argument list of the
+executed program. The first argument in the list is the full pathname
+of the `awk' program. The rest of the argument list will either be
+options to `awk', or data files, or both.
+
+
+File: gawk.info, Node: Comments, Next: Statements/Lines, Prev: Running gawk, Up: Getting Started
+
+Comments in `awk' Programs
+==========================
+
+ A "comment" is some text that is included in a program for the sake
+of human readers, and that is not really part of the program. Comments
+can explain what the program does, and how it works. Nearly all
+programming languages have provisions for comments, because programs are
+typically hard to understand without their extra help.
+
+ In the `awk' language, a comment starts with the sharp sign
+character, `#', and continues to the end of the line. The `awk'
+language ignores the rest of a line following a sharp sign. For
+example, we could have put the following into `th-prog':
+
+ # This program finds records containing the pattern `th'. This is how
+ # you continue comments on additional lines.
+ /th/
+
+ You can put comment lines into keyboard-composed throw-away `awk'
+programs also, but this usually isn't very useful; the purpose of a
+comment is to help you or another person understand the program at a
+later time.
+
diff --git a/gawk.info-2 b/gawk.info-2
new file mode 100644
index 00000000..954b4309
--- /dev/null
+++ b/gawk.info-2
@@ -0,0 +1,1236 @@
+This is Info file gawk.info, produced by Makeinfo-1.54 from the input
+file gawk.texi.
+
+ This file documents `awk', a program that you can use to select
+particular records in a file and perform operations upon them.
+
+ This is Edition 0.15 of `The GAWK Manual',
+for the 2.15 version of the GNU implementation
+of AWK.
+
+ Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that
+the entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Foundation.
+
+
+File: gawk.info, Node: Statements/Lines, Next: When, Prev: Comments, Up: Getting Started
+
+`awk' Statements versus Lines
+=============================
+
+ Most often, each line in an `awk' program is a separate statement or
+separate rule, like this:
+
+ awk '/12/ { print $0 }
+ /21/ { print $0 }' BBS-list inventory-shipped
+
+ But sometimes statements can be more than one line, and lines can
+contain several statements. You can split a statement into multiple
+lines by inserting a newline after any of the following:
+
+ , { ? : || && do else
+
+A newline at any other point is considered the end of the statement.
+(Splitting lines after `?' and `:' is a minor `gawk' extension. The
+`?' and `:' referred to here is the three operand conditional
+expression described in *Note Conditional Expressions: Conditional Exp.)
+
+ If you would like to split a single statement into two lines at a
+point where a newline would terminate it, you can "continue" it by
+ending the first line with a backslash character, `\'. This is allowed
+absolutely anywhere in the statement, even in the middle of a string or
+regular expression. For example:
+
+ awk '/This program is too long, so continue it\
+ on the next line/ { print $1 }'
+
+We have generally not used backslash continuation in the sample
+programs in this manual. Since in `gawk' there is no limit on the
+length of a line, it is never strictly necessary; it just makes
+programs prettier. We have preferred to make them even more pretty by
+keeping the statements short. Backslash continuation is most useful
+when your `awk' program is in a separate source file, instead of typed
+in on the command line. You should also note that many `awk'
+implementations are more picky about where you may use backslash
+continuation. For maximal portability of your `awk' programs, it is
+best not to split your lines in the middle of a regular expression or a
+string.
+
+ *Warning: backslash continuation does not work as described above
+with the C shell.* Continuation with backslash works for `awk'
+programs in files, and also for one-shot programs *provided* you are
+using a POSIX-compliant shell, such as the Bourne shell or the
+Bourne-again shell. But the C shell used on Berkeley Unix behaves
+differently! There, you must use two backslashes in a row, followed by
+a newline.
+
+ When `awk' statements within one rule are short, you might want to
+put more than one of them on a line. You do this by separating the
+statements with a semicolon, `;'. This also applies to the rules
+themselves. Thus, the previous program could have been written:
+
+ /12/ { print $0 } ; /21/ { print $0 }
+
+*Note:* the requirement that rules on the same line must be separated
+with a semicolon is a recent change in the `awk' language; it was done
+for consistency with the treatment of statements within an action.
+
+
+File: gawk.info, Node: When, Prev: Statements/Lines, Up: Getting Started
+
+When to Use `awk'
+=================
+
+ You might wonder how `awk' might be useful for you. Using additional
+utility programs, more advanced patterns, field separators, arithmetic
+statements, and other selection criteria, you can produce much more
+complex output. The `awk' language is very useful for producing
+reports from large amounts of raw data, such as summarizing information
+from the output of other utility programs like `ls'. (*Note A More
+Complex Example: More Complex.)
+
+ Programs written with `awk' are usually much smaller than they would
+be in other languages. This makes `awk' programs easy to compose and
+use. Often `awk' programs can be quickly composed at your terminal,
+used once, and thrown away. Since `awk' programs are interpreted, you
+can avoid the usually lengthy edit-compile-test-debug cycle of software
+development.
+
+ Complex programs have been written in `awk', including a complete
+retargetable assembler for 8-bit microprocessors (*note Glossary::., for
+more information) and a microcode assembler for a special purpose Prolog
+computer. However, `awk''s capabilities are strained by tasks of such
+complexity.
+
+ If you find yourself writing `awk' scripts of more than, say, a few
+hundred lines, you might consider using a different programming
+language. Emacs Lisp is a good choice if you need sophisticated string
+or pattern matching capabilities. The shell is also good at string and
+pattern matching; in addition, it allows powerful use of the system
+utilities. More conventional languages, such as C, C++, and Lisp, offer
+better facilities for system programming and for managing the complexity
+of large programs. Programs in these languages may require more lines
+of source code than the equivalent `awk' programs, but they are easier
+to maintain and usually run more efficiently.
+
+
+File: gawk.info, Node: Reading Files, Next: Printing, Prev: Getting Started, Up: Top
+
+Reading Input Files
+*******************
+
+ In the typical `awk' program, all input is read either from the
+standard input (by default the keyboard, but often a pipe from another
+command) or from files whose names you specify on the `awk' command
+line. If you specify input files, `awk' reads them in order, reading
+all the data from one before going on to the next. The name of the
+current input file can be found in the built-in variable `FILENAME'
+(*note Built-in Variables::.).
+
+ The input is read in units called records, and processed by the
+rules one record at a time. By default, each record is one line. Each
+record is split automatically into fields, to make it more convenient
+for a rule to work on its parts.
+
+ On rare occasions you will need to use the `getline' command, which
+can do explicit input from any number of files (*note Explicit Input
+with `getline': Getline.).
+
+* Menu:
+
+* Records:: Controlling how data is split into records.
+* Fields:: An introduction to fields.
+* Non-Constant Fields:: Non-constant Field Numbers.
+* Changing Fields:: Changing the Contents of a Field.
+* Field Separators:: The field separator and how to change it.
+* Constant Size:: Reading constant width data.
+* Multiple Line:: Reading multi-line records.
+* Getline:: Reading files under explicit program control
+ using the `getline' function.
+* Close Input:: Closing an input file (so you can read from
+ the beginning once more).
+
+
+File: gawk.info, Node: Records, Next: Fields, Prev: Reading Files, Up: Reading Files
+
+How Input is Split into Records
+===============================
+
+ The `awk' language divides its input into records and fields.
+Records are separated by a character called the "record separator". By
+default, the record separator is the newline character, defining a
+record to be a single line of text.
+
+ Sometimes you may want to use a different character to separate your
+records. You can use a different character by changing the built-in
+variable `RS'. The value of `RS' is a string that says how to separate
+records; the default value is `"\n"', the string containing just a
+newline character. This is why records are, by default, single lines.
+
+ `RS' can have any string as its value, but only the first character
+of the string is used as the record separator. The other characters are
+ignored. `RS' is exceptional in this regard; `awk' uses the full value
+of all its other built-in variables.
+
+ You can change the value of `RS' in the `awk' program with the
+assignment operator, `=' (*note Assignment Expressions: Assignment
+Ops.). The new record-separator character should be enclosed in
+quotation marks to make a string constant. Often the right time to do
+this is at the beginning of execution, before any input has been
+processed, so that the very first record will be read with the proper
+separator. To do this, use the special `BEGIN' pattern (*note `BEGIN'
+and `END' Special Patterns: BEGIN/END.). For example:
+
+ awk 'BEGIN { RS = "/" } ; { print $0 }' BBS-list
+
+changes the value of `RS' to `"/"', before reading any input. This is
+a string whose first character is a slash; as a result, records are
+separated by slashes. Then the input file is read, and the second rule
+in the `awk' program (the action with no pattern) prints each record.
+Since each `print' statement adds a newline at the end of its output,
+the effect of this `awk' program is to copy the input with each slash
+changed to a newline.
+
+ Another way to change the record separator is on the command line,
+using the variable-assignment feature (*note Invoking `awk': Command
+Line.).
+
+ awk '{ print $0 }' RS="/" BBS-list
+
+This sets `RS' to `/' before processing `BBS-list'.
+
+ Reaching the end of an input file terminates the current input
+record, even if the last character in the file is not the character in
+`RS'.
+
+ The empty string, `""' (a string of no characters), has a special
+meaning as the value of `RS': it means that records are separated only
+by blank lines. *Note Multiple-Line Records: Multiple Line, for more
+details.
+
+ The `awk' utility keeps track of the number of records that have
+been read so far from the current input file. This value is stored in a
+built-in variable called `FNR'. It is reset to zero when a new file is
+started. Another built-in variable, `NR', is the total number of input
+records read so far from all files. It starts at zero but is never
+automatically reset to zero.
+
+ If you change the value of `RS' in the middle of an `awk' run, the
+new value is used to delimit subsequent records, but the record
+currently being processed (and records already processed) are not
+affected.
+
+
+File: gawk.info, Node: Fields, Next: Non-Constant Fields, Prev: Records, Up: Reading Files
+
+Examining Fields
+================
+
+ When `awk' reads an input record, the record is automatically
+separated or "parsed" by the interpreter into chunks called "fields".
+By default, fields are separated by whitespace, like words in a line.
+Whitespace in `awk' means any string of one or more spaces and/or tabs;
+other characters such as newline, formfeed, and so on, that are
+considered whitespace by other languages are *not* considered
+whitespace by `awk'.
+
+ The purpose of fields is to make it more convenient for you to refer
+to these pieces of the record. You don't have to use them--you can
+operate on the whole record if you wish--but fields are what make
+simple `awk' programs so powerful.
+
+ To refer to a field in an `awk' program, you use a dollar-sign, `$',
+followed by the number of the field you want. Thus, `$1' refers to the
+first field, `$2' to the second, and so on. For example, suppose the
+following is a line of input:
+
+ This seems like a pretty nice example.
+
+Here the first field, or `$1', is `This'; the second field, or `$2', is
+`seems'; and so on. Note that the last field, `$7', is `example.'.
+Because there is no space between the `e' and the `.', the period is
+considered part of the seventh field.
+
+ No matter how many fields there are, the last field in a record can
+be represented by `$NF'. So, in the example above, `$NF' would be the
+same as `$7', which is `example.'. Why this works is explained below
+(*note Non-constant Field Numbers: Non-Constant Fields.). If you try
+to refer to a field beyond the last one, such as `$8' when the record
+has only 7 fields, you get the empty string.
+
+ Plain `NF', with no `$', is a built-in variable whose value is the
+number of fields in the current record.
+
+ `$0', which looks like an attempt to refer to the zeroth field, is a
+special case: it represents the whole input record. This is what you
+would use if you weren't interested in fields.
+
+ Here are some more examples:
+
+ awk '$1 ~ /foo/ { print $0 }' BBS-list
+
+This example prints each record in the file `BBS-list' whose first
+field contains the string `foo'. The operator `~' is called a
+"matching operator" (*note Comparison Expressions: Comparison Ops.); it
+tests whether a string (here, the field `$1') matches a given regular
+expression.
+
+ By contrast, the following example:
+
+ awk '/foo/ { print $1, $NF }' BBS-list
+
+looks for `foo' in *the entire record* and prints the first field and
+the last field for each input record containing a match.
+
+
+File: gawk.info, Node: Non-Constant Fields, Next: Changing Fields, Prev: Fields, Up: Reading Files
+
+Non-constant Field Numbers
+==========================
+
+ The number of a field does not need to be a constant. Any
+expression in the `awk' language can be used after a `$' to refer to a
+field. The value of the expression specifies the field number. If the
+value is a string, rather than a number, it is converted to a number.
+Consider this example:
+
+ awk '{ print $NR }'
+
+Recall that `NR' is the number of records read so far: 1 in the first
+record, 2 in the second, etc. So this example prints the first field
+of the first record, the second field of the second record, and so on.
+For the twentieth record, field number 20 is printed; most likely, the
+record has fewer than 20 fields, so this prints a blank line.
+
+ Here is another example of using expressions as field numbers:
+
+ awk '{ print $(2*2) }' BBS-list
+
+ The `awk' language must evaluate the expression `(2*2)' and use its
+value as the number of the field to print. The `*' sign represents
+multiplication, so the expression `2*2' evaluates to 4. The
+parentheses are used so that the multiplication is done before the `$'
+operation; they are necessary whenever there is a binary operator in
+the field-number expression. This example, then, prints the hours of
+operation (the fourth field) for every line of the file `BBS-list'.
+
+ If the field number you compute is zero, you get the entire record.
+Thus, `$(2-2)' has the same value as `$0'. Negative field numbers are
+not allowed.
+
+ The number of fields in the current record is stored in the built-in
+variable `NF' (*note Built-in Variables::.). The expression `$NF' is
+not a special feature: it is the direct consequence of evaluating `NF'
+and using its value as a field number.
+
+
+File: gawk.info, Node: Changing Fields, Next: Field Separators, Prev: Non-Constant Fields, Up: Reading Files
+
+Changing the Contents of a Field
+================================
+
+ You can change the contents of a field as seen by `awk' within an
+`awk' program; this changes what `awk' perceives as the current input
+record. (The actual input is untouched: `awk' never modifies the input
+file.)
+
+ Consider this example:
+
+ awk '{ $3 = $2 - 10; print $2, $3 }' inventory-shipped
+
+The `-' sign represents subtraction, so this program reassigns field
+three, `$3', to be the value of field two minus ten, `$2 - 10'. (*Note
+Arithmetic Operators: Arithmetic Ops.) Then field two, and the new
+value for field three, are printed.
+
+ In order for this to work, the text in field `$2' must make sense as
+a number; the string of characters must be converted to a number in
+order for the computer to do arithmetic on it. The number resulting
+from the subtraction is converted back to a string of characters which
+then becomes field three. *Note Conversion of Strings and Numbers:
+Conversion.
+
+ When you change the value of a field (as perceived by `awk'), the
+text of the input record is recalculated to contain the new field where
+the old one was. Therefore, `$0' changes to reflect the altered field.
+Thus,
+
+ awk '{ $2 = $2 - 10; print $0 }' inventory-shipped
+
+prints a copy of the input file, with 10 subtracted from the second
+field of each line.
+
+ You can also assign contents to fields that are out of range. For
+example:
+
+ awk '{ $6 = ($5 + $4 + $3 + $2) ; print $6 }' inventory-shipped
+
+We've just created `$6', whose value is the sum of fields `$2', `$3',
+`$4', and `$5'. The `+' sign represents addition. For the file
+`inventory-shipped', `$6' represents the total number of parcels
+shipped for a particular month.
+
+ Creating a new field changes the internal `awk' copy of the current
+input record--the value of `$0'. Thus, if you do `print $0' after
+adding a field, the record printed includes the new field, with the
+appropriate number of field separators between it and the previously
+existing fields.
+
+ This recomputation affects and is affected by several features not
+yet discussed, in particular, the "output field separator", `OFS',
+which is used to separate the fields (*note Output Separators::.), and
+`NF' (the number of fields; *note Examining Fields: Fields.). For
+example, the value of `NF' is set to the number of the highest field
+you create.
+
+ Note, however, that merely *referencing* an out-of-range field does
+*not* change the value of either `$0' or `NF'. Referencing an
+out-of-range field merely produces a null string. For example:
+
+ if ($(NF+1) != "")
+ print "can't happen"
+ else
+ print "everything is normal"
+
+should print `everything is normal', because `NF+1' is certain to be
+out of range. (*Note The `if' Statement: If Statement, for more
+information about `awk''s `if-else' statements.)
+
+ It is important to note that assigning to a field will change the
+value of `$0', but will not change the value of `NF', even when you
+assign the null string to a field. For example:
+
+ echo a b c d | awk '{ OFS = ":"; $2 = "" ; print ; print NF }'
+
+prints
+
+ a::c:d
+ 4
+
+The field is still there, it just has an empty value. You can tell
+because there are two colons in a row.
+
+
+File: gawk.info, Node: Field Separators, Next: Constant Size, Prev: Changing Fields, Up: Reading Files
+
+Specifying how Fields are Separated
+===================================
+
+ (This section is rather long; it describes one of the most
+fundamental operations in `awk'. If you are a novice with `awk', we
+recommend that you re-read this section after you have studied the
+section on regular expressions, *Note Regular Expressions as Patterns:
+Regexp.)
+
+ The way `awk' splits an input record into fields is controlled by
+the "field separator", which is a single character or a regular
+expression. `awk' scans the input record for matches for the
+separator; the fields themselves are the text between the matches. For
+example, if the field separator is `oo', then the following line:
+
+ moo goo gai pan
+
+would be split into three fields: `m', ` g' and ` gai pan'.
+
+ The field separator is represented by the built-in variable `FS'.
+Shell programmers take note! `awk' does not use the name `IFS' which
+is used by the shell.
+
+ You can change the value of `FS' in the `awk' program with the
+assignment operator, `=' (*note Assignment Expressions: Assignment
+Ops.). Often the right time to do this is at the beginning of
+execution, before any input has been processed, so that the very first
+record will be read with the proper separator. To do this, use the
+special `BEGIN' pattern (*note `BEGIN' and `END' Special Patterns:
+BEGIN/END.). For example, here we set the value of `FS' to the string
+`","':
+
+ awk 'BEGIN { FS = "," } ; { print $2 }'
+
+Given the input line,
+
+ John Q. Smith, 29 Oak St., Walamazoo, MI 42139
+
+this `awk' program extracts the string ` 29 Oak St.'.
+
+ Sometimes your input data will contain separator characters that
+don't separate fields the way you thought they would. For instance, the
+person's name in the example we've been using might have a title or
+suffix attached, such as `John Q. Smith, LXIX'. From input containing
+such a name:
+
+ John Q. Smith, LXIX, 29 Oak St., Walamazoo, MI 42139
+
+the previous sample program would extract ` LXIX', instead of ` 29 Oak
+St.'. If you were expecting the program to print the address, you
+would be surprised. So choose your data layout and separator
+characters carefully to prevent such problems.
+
+ As you know, by default, fields are separated by whitespace sequences
+(spaces and tabs), not by single spaces: two spaces in a row do not
+delimit an empty field. The default value of the field separator is a
+string `" "' containing a single space. If this value were interpreted
+in the usual way, each space character would separate fields, so two
+spaces in a row would make an empty field between them. The reason
+this does not happen is that a single space as the value of `FS' is a
+special case: it is taken to specify the default manner of delimiting
+fields.
+
+ If `FS' is any other single character, such as `","', then each
+occurrence of that character separates two fields. Two consecutive
+occurrences delimit an empty field. If the character occurs at the
+beginning or the end of the line, that too delimits an empty field. The
+space character is the only single character which does not follow these
+rules.
+
+ More generally, the value of `FS' may be a string containing any
+regular expression. Then each match in the record for the regular
+expression separates fields. For example, the assignment:
+
+ FS = ", \t"
+
+makes every area of an input line that consists of a comma followed by a
+space and a tab, into a field separator. (`\t' stands for a tab.)
+
+ For a less trivial example of a regular expression, suppose you want
+single spaces to separate fields the way single commas were used above.
+You can set `FS' to `"[ ]"'. This regular expression matches a single
+space and nothing else.
+
+ `FS' can be set on the command line. You use the `-F' argument to
+do so. For example:
+
+ awk -F, 'PROGRAM' INPUT-FILES
+
+sets `FS' to be the `,' character. Notice that the argument uses a
+capital `F'. Contrast this with `-f', which specifies a file
+containing an `awk' program. Case is significant in command options:
+the `-F' and `-f' options have nothing to do with each other. You can
+use both options at the same time to set the `FS' argument *and* get an
+`awk' program from a file.
+
+ The value used for the argument to `-F' is processed in exactly the
+same way as assignments to the built-in variable `FS'. This means that
+if the field separator contains special characters, they must be escaped
+appropriately. For example, to use a `\' as the field separator, you
+would have to type:
+
+ # same as FS = "\\"
+ awk -F\\\\ '...' files ...
+
+Since `\' is used for quoting in the shell, `awk' will see `-F\\'.
+Then `awk' processes the `\\' for escape characters (*note Constant
+Expressions: Constants.), finally yielding a single `\' to be used for
+the field separator.
+
+ As a special case, in compatibility mode (*note Invoking `awk':
+Command Line.), if the argument to `-F' is `t', then `FS' is set to the
+tab character. (This is because if you type `-F\t', without the quotes,
+at the shell, the `\' gets deleted, so `awk' figures that you really
+want your fields to be separated with tabs, and not `t's. Use `-v
+FS="t"' on the command line if you really do want to separate your
+fields with `t's.)
+
+ For example, let's use an `awk' program file called `baud.awk' that
+contains the pattern `/300/', and the action `print $1'. Here is the
+program:
+
+ /300/ { print $1 }
+
+ Let's also set `FS' to be the `-' character, and run the program on
+the file `BBS-list'. The following command prints a list of the names
+of the bulletin boards that operate at 300 baud and the first three
+digits of their phone numbers:
+
+ awk -F- -f baud.awk BBS-list
+
+It produces this output:
+
+ aardvark 555
+ alpo
+ barfly 555
+ bites 555
+ camelot 555
+ core 555
+ fooey 555
+ foot 555
+ macfoo 555
+ sdace 555
+ sabafoo 555
+
+Note the second line of output. If you check the original file, you
+will see that the second line looked like this:
+
+ alpo-net 555-3412 2400/1200/300 A
+
+ The `-' as part of the system's name was used as the field
+separator, instead of the `-' in the phone number that was originally
+intended. This demonstrates why you have to be careful in choosing
+your field and record separators.
+
+ The following program searches the system password file, and prints
+the entries for users who have no password:
+
+ awk -F: '$2 == ""' /etc/passwd
+
+Here we use the `-F' option on the command line to set the field
+separator. Note that fields in `/etc/passwd' are separated by colons.
+The second field represents a user's encrypted password, but if the
+field is empty, that user has no password.
+
+ According to the POSIX standard, `awk' is supposed to behave as if
+each record is split into fields at the time that it is read. In
+particular, this means that you can change the value of `FS' after a
+record is read, but before any of the fields are referenced. The value
+of the fields (i.e. how they were split) should reflect the old value
+of `FS', not the new one.
+
+ However, many implementations of `awk' do not do this. Instead,
+they defer splitting the fields until a field reference actually
+happens, using the *current* value of `FS'! This behavior can be
+difficult to diagnose. The following example illustrates the results of
+the two methods. (The `sed' command prints just the first line of
+`/etc/passwd'.)
+
+ sed 1q /etc/passwd | awk '{ FS = ":" ; print $1 }'
+
+will usually print
+
+ root
+
+on an incorrect implementation of `awk', while `gawk' will print
+something like
+
+ root:nSijPlPhZZwgE:0:0:Root:/:
+
+ There is an important difference between the two cases of `FS = " "'
+(a single blank) and `FS = "[ \t]+"' (which is a regular expression
+matching one or more blanks or tabs). For both values of `FS', fields
+are separated by runs of blanks and/or tabs. However, when the value of
+`FS' is `" "', `awk' will strip leading and trailing whitespace from
+the record, and then decide where the fields are.
+
+ For example, the following expression prints `b':
+
+ echo ' a b c d ' | awk '{ print $2 }'
+
+However, the following prints `a':
+
+ echo ' a b c d ' | awk 'BEGIN { FS = "[ \t]+" } ; { print $2 }'
+
+In this case, the first field is null.
+
+ The stripping of leading and trailing whitespace also comes into
+play whenever `$0' is recomputed. For instance, this pipeline
+
+ echo ' a b c d' | awk '{ print; $2 = $2; print }'
+
+produces this output:
+
+ a b c d
+ a b c d
+
+The first `print' statement prints the record as it was read, with
+leading whitespace intact. The assignment to `$2' rebuilds `$0' by
+concatenating `$1' through `$NF' together, separated by the value of
+`OFS'. Since the leading whitespace was ignored when finding `$1', it
+is not part of the new `$0'. Finally, the last `print' statement
+prints the new `$0'.
+
+ The following table summarizes how fields are split, based on the
+value of `FS'.
+
+`FS == " "'
+ Fields are separated by runs of whitespace. Leading and trailing
+ whitespace are ignored. This is the default.
+
+`FS == ANY SINGLE CHARACTER'
+ Fields are separated by each occurrence of the character. Multiple
+ successive occurrences delimit empty fields, as do leading and
+ trailing occurrences.
+
+`FS == REGEXP'
+ Fields are separated by occurrences of characters that match
+ REGEXP. Leading and trailing matches of REGEXP delimit empty
+ fields.
+
+
+File: gawk.info, Node: Constant Size, Next: Multiple Line, Prev: Field Separators, Up: Reading Files
+
+Reading Fixed-width Data
+========================
+
+ (This section discusses an advanced, experimental feature. If you
+are a novice `awk' user, you may wish to skip it on the first reading.)
+
+ `gawk' 2.13 introduced a new facility for dealing with fixed-width
+fields with no distinctive field separator. Data of this nature arises
+typically in one of at least two ways: the input for old FORTRAN
+programs where numbers are run together, and the output of programs
+that did not anticipate the use of their output as input for other
+programs.
+
+ An example of the latter is a table where all the columns are lined
+up by the use of a variable number of spaces and *empty fields are just
+spaces*. Clearly, `awk''s normal field splitting based on `FS' will
+not work well in this case. (Although a portable `awk' program can use
+a series of `substr' calls on `$0', this is awkward and inefficient for
+a large number of fields.)
+
+ The splitting of an input record into fixed-width fields is
+specified by assigning a string containing space-separated numbers to
+the built-in variable `FIELDWIDTHS'. Each number specifies the width
+of the field *including* columns between fields. If you want to ignore
+the columns between fields, you can specify the width as a separate
+field that is subsequently ignored.
+
+ The following data is the output of the `w' utility. It is useful
+to illustrate the use of `FIELDWIDTHS'.
+
+ 10:06pm up 21 days, 14:04, 23 users
+ User tty login idle JCPU PCPU what
+ hzuo ttyV0 8:58pm 9 5 vi p24.tex
+ hzang ttyV3 6:37pm 50 -csh
+ eklye ttyV5 9:53pm 7 1 em thes.tex
+ dportein ttyV6 8:17pm 1:47 -csh
+ gierd ttyD3 10:00pm 1 elm
+ dave ttyD4 9:47pm 4 4 w
+ brent ttyp0 26Jun91 4:46 26:46 4:41 bash
+ dave ttyq4 26Jun9115days 46 46 wnewmail
+
+ The following program takes the above input, converts the idle time
+to number of seconds and prints out the first two fields and the
+calculated idle time. (This program uses a number of `awk' features
+that haven't been introduced yet.)
+
+ BEGIN { FIELDWIDTHS = "9 6 10 6 7 7 35" }
+ NR > 2 {
+ idle = $4
+ sub(/^ */, "", idle) # strip leading spaces
+ if (idle == "") idle = 0
+ if (idle ~ /:/) { split(idle, t, ":"); idle = t[1] * 60 + t[2] }
+ if (idle ~ /days/) { idle *= 24 * 60 * 60 }
+
+ print $1, $2, idle
+ }
+
+ Here is the result of running the program on the data:
+
+ hzuo ttyV0 0
+ hzang ttyV3 50
+ eklye ttyV5 0
+ dportein ttyV6 107
+ gierd ttyD3 1
+ dave ttyD4 0
+ brent ttyp0 286
+ dave ttyq4 1296000
+
+ Another (possibly more practical) example of fixed-width input data
+would be the input from a deck of balloting cards. In some parts of
+the United States, voters make their choices by punching holes in
+computer cards. These cards are then processed to count the votes for
+any particular candidate or on any particular issue. Since a voter may
+choose not to vote on some issue, any column on the card may be empty.
+An `awk' program for processing such data could use the `FIELDWIDTHS'
+feature to simplify reading the data.
+
+ This feature is still experimental, and will likely evolve over time.
+
+
+File: gawk.info, Node: Multiple Line, Next: Getline, Prev: Constant Size, Up: Reading Files
+
+Multiple-Line Records
+=====================
+
+ In some data bases, a single line cannot conveniently hold all the
+information in one entry. In such cases, you can use multi-line
+records.
+
+ The first step in doing this is to choose your data format: when
+records are not defined as single lines, how do you want to define them?
+What should separate records?
+
+ One technique is to use an unusual character or string to separate
+records. For example, you could use the formfeed character (written
+`\f' in `awk', as in C) to separate them, making each record a page of
+the file. To do this, just set the variable `RS' to `"\f"' (a string
+containing the formfeed character). Any other character could equally
+well be used, as long as it won't be part of the data in a record.
+
+ Another technique is to have blank lines separate records. By a
+special dispensation, a null string as the value of `RS' indicates that
+records are separated by one or more blank lines. If you set `RS' to
+the null string, a record always ends at the first blank line
+encountered. And the next record doesn't start until the first nonblank
+line that follows--no matter how many blank lines appear in a row, they
+are considered one record-separator. (End of file is also considered a
+record separator.)
+
+ The second step is to separate the fields in the record. One way to
+do this is to put each field on a separate line: to do this, just set
+the variable `FS' to the string `"\n"'. (This simple regular
+expression matches a single newline.)
+
+ Another way to separate fields is to divide each of the lines into
+fields in the normal manner. This happens by default as a result of a
+special feature: when `RS' is set to the null string, the newline
+character *always* acts as a field separator. This is in addition to
+whatever field separations result from `FS'.
+
+ The original motivation for this special exception was probably so
+that you get useful behavior in the default case (i.e., `FS == " "').
+This feature can be a problem if you really don't want the newline
+character to separate fields, since there is no way to prevent it.
+However, you can work around this by using the `split' function to
+break up the record manually (*note Built-in Functions for String
+Manipulation: String Functions.).
+
+
+File: gawk.info, Node: Getline, Next: Close Input, Prev: Multiple Line, Up: Reading Files
+
+Explicit Input with `getline'
+=============================
+
+ So far we have been getting our input files from `awk''s main input
+stream--either the standard input (usually your terminal) or the files
+specified on the command line. The `awk' language has a special
+built-in command called `getline' that can be used to read input under
+your explicit control.
+
+ This command is quite complex and should *not* be used by beginners.
+It is covered here because this is the chapter on input. The examples
+that follow the explanation of the `getline' command include material
+that has not been covered yet. Therefore, come back and study the
+`getline' command *after* you have reviewed the rest of this manual and
+have a good knowledge of how `awk' works.
+
+ `getline' returns 1 if it finds a record, and 0 if the end of the
+file is encountered. If there is some error in getting a record, such
+as a file that cannot be opened, then `getline' returns -1. In this
+case, `gawk' sets the variable `ERRNO' to a string describing the error
+that occurred.
+
+ In the following examples, COMMAND stands for a string value that
+represents a shell command.
+
+`getline'
+ The `getline' command can be used without arguments to read input
+ from the current input file. All it does in this case is read the
+ next input record and split it up into fields. This is useful if
+ you've finished processing the current record, but you want to do
+ some special processing *right now* on the next record. Here's an
+ example:
+
+ awk '{
+ if (t = index($0, "/*")) {
+ if (t > 1)
+ tmp = substr($0, 1, t - 1)
+ else
+ tmp = ""
+ u = index(substr($0, t + 2), "*/")
+ while (u == 0) {
+ getline
+ t = -1
+ u = index($0, "*/")
+ }
+ if (u <= length($0) - 2)
+ $0 = tmp substr($0, t + u + 3)
+ else
+ $0 = tmp
+ }
+ print $0
+ }'
+
+ This `awk' program deletes all C-style comments, `/* ... */',
+ from the input. By replacing the `print $0' with other
+ statements, you could perform more complicated processing on the
+ decommented input, like searching for matches of a regular
+ expression. (This program has a subtle problem--can you spot it?)
+
+ This form of the `getline' command sets `NF' (the number of
+ fields; *note Examining Fields: Fields.), `NR' (the number of
+ records read so far; *note How Input is Split into Records:
+ Records.), `FNR' (the number of records read from this input
+ file), and the value of `$0'.
+
+ *Note:* the new value of `$0' is used in testing the patterns of
+ any subsequent rules. The original value of `$0' that triggered
+ the rule which executed `getline' is lost. By contrast, the
+ `next' statement reads a new record but immediately begins
+ processing it normally, starting with the first rule in the
+ program. *Note The `next' Statement: Next Statement.
+
+`getline VAR'
+ This form of `getline' reads a record into the variable VAR. This
+ is useful when you want your program to read the next record from
+ the current input file, but you don't want to subject the record
+ to the normal input processing.
+
+ For example, suppose the next line is a comment, or a special
+ string, and you want to read it, but you must make certain that it
+ won't trigger any rules. This version of `getline' allows you to
+ read that line and store it in a variable so that the main
+ read-a-line-and-check-each-rule loop of `awk' never sees it.
+
+ The following example swaps every two lines of input. For
+ example, given:
+
+ wan
+ tew
+ free
+ phore
+
+ it outputs:
+
+ tew
+ wan
+ phore
+ free
+
+ Here's the program:
+
+ awk '{
+ if ((getline tmp) > 0) {
+ print tmp
+ print $0
+ } else
+ print $0
+ }'
+
+ The `getline' function used in this way sets only the variables
+ `NR' and `FNR' (and of course, VAR). The record is not split into
+ fields, so the values of the fields (including `$0') and the value
+ of `NF' do not change.
+
+`getline < FILE'
+ This form of the `getline' function takes its input from the file
+ FILE. Here FILE is a string-valued expression that specifies the
+ file name. `< FILE' is called a "redirection" since it directs
+ input to come from a different place.
+
+ This form is useful if you want to read your input from a
+ particular file, instead of from the main input stream. For
+ example, the following program reads its input record from the
+ file `foo.input' when it encounters a first field with a value
+ equal to 10 in the current input file.
+
+ awk '{
+ if ($1 == 10) {
+ getline < "foo.input"
+ print
+ } else
+ print
+ }'
+
+ Since the main input stream is not used, the values of `NR' and
+ `FNR' are not changed. But the record read is split into fields in
+ the normal manner, so the values of `$0' and other fields are
+ changed. So is the value of `NF'.
+
+ This does not cause the record to be tested against all the
+ patterns in the `awk' program, in the way that would happen if the
+ record were read normally by the main processing loop of `awk'.
+ However the new record is tested against any subsequent rules,
+ just as when `getline' is used without a redirection.
+
+`getline VAR < FILE'
+ This form of the `getline' function takes its input from the file
+ FILE and puts it in the variable VAR. As above, FILE is a
+ string-valued expression that specifies the file from which to
+ read.
+
+ In this version of `getline', none of the built-in variables are
+ changed, and the record is not split into fields. The only
+ variable changed is VAR.
+
+ For example, the following program copies all the input files to
+ the output, except for records that say `@include FILENAME'. Such
+ a record is replaced by the contents of the file FILENAME.
+
+ awk '{
+ if (NF == 2 && $1 == "@include") {
+ while ((getline line < $2) > 0)
+ print line
+ close($2)
+ } else
+ print
+ }'
+
+ Note here how the name of the extra input file is not built into
+ the program; it is taken from the data, from the second field on
+ the `@include' line.
+
+ The `close' function is called to ensure that if two identical
+ `@include' lines appear in the input, the entire specified file is
+ included twice. *Note Closing Input Files and Pipes: Close Input.
+
+ One deficiency of this program is that it does not process nested
+ `@include' statements the way a true macro preprocessor would.
+
+`COMMAND | getline'
+ You can "pipe" the output of a command into `getline'. A pipe is
+ simply a way to link the output of one program to the input of
+ another. In this case, the string COMMAND is run as a shell
+ command and its output is piped into `awk' to be used as input.
+ This form of `getline' reads one record from the pipe.
+
+ For example, the following program copies input to output, except
+ for lines that begin with `@execute', which are replaced by the
+ output produced by running the rest of the line as a shell command:
+
+ awk '{
+ if ($1 == "@execute") {
+ tmp = substr($0, 10)
+ while ((tmp | getline) > 0)
+ print
+ close(tmp)
+ } else
+ print
+ }'
+
+ The `close' function is called to ensure that if two identical
+ `@execute' lines appear in the input, the command is run for each
+ one. *Note Closing Input Files and Pipes: Close Input.
+
+ Given the input:
+
+ foo
+ bar
+ baz
+ @execute who
+ bletch
+
+ the program might produce:
+
+ foo
+ bar
+ baz
+ hack ttyv0 Jul 13 14:22
+ hack ttyp0 Jul 13 14:23 (gnu:0)
+ hack ttyp1 Jul 13 14:23 (gnu:0)
+ hack ttyp2 Jul 13 14:23 (gnu:0)
+ hack ttyp3 Jul 13 14:23 (gnu:0)
+ bletch
+
+ Notice that this program ran the command `who' and printed the
+ result. (If you try this program yourself, you will get different
+ results, showing you who is logged in on your system.)
+
+ This variation of `getline' splits the record into fields, sets the
+ value of `NF' and recomputes the value of `$0'. The values of
+ `NR' and `FNR' are not changed.
+
+`COMMAND | getline VAR'
+ The output of the command COMMAND is sent through a pipe to
+ `getline' and into the variable VAR. For example, the following
+ program reads the current date and time into the variable
+ `current_time', using the `date' utility, and then prints it.
+
+ awk 'BEGIN {
+ "date" | getline current_time
+ close("date")
+ print "Report printed on " current_time
+ }'
+
+ In this version of `getline', none of the built-in variables are
+ changed, and the record is not split into fields.
+
+
+File: gawk.info, Node: Close Input, Prev: Getline, Up: Reading Files
+
+Closing Input Files and Pipes
+=============================
+
+ If the same file name or the same shell command is used with
+`getline' more than once during the execution of an `awk' program, the
+file is opened (or the command is executed) only the first time. At
+that time, the first record of input is read from that file or command.
+The next time the same file or command is used in `getline', another
+record is read from it, and so on.
+
+ This implies that if you want to start reading the same file again
+from the beginning, or if you want to rerun a shell command (rather than
+reading more output from the command), you must take special steps.
+What you must do is use the `close' function, as follows:
+
+ close(FILENAME)
+
+or
+
+ close(COMMAND)
+
+ The argument FILENAME or COMMAND can be any expression. Its value
+must exactly equal the string that was used to open the file or start
+the command--for example, if you open a pipe with this:
+
+ "sort -r names" | getline foo
+
+then you must close it with this:
+
+ close("sort -r names")
+
+ Once this function call is executed, the next `getline' from that
+file or command will reopen the file or rerun the command.
+
+ `close' returns a value of zero if the close succeeded. Otherwise,
+the value will be non-zero. In this case, `gawk' sets the variable
+`ERRNO' to a string describing the error that occurred.
+
+
+File: gawk.info, Node: Printing, Next: One-liners, Prev: Reading Files, Up: Top
+
+Printing Output
+***************
+
+ One of the most common things that actions do is to output or "print"
+some or all of the input. For simple output, use the `print'
+statement. For fancier formatting use the `printf' statement. Both
+are described in this chapter.
+
+* Menu:
+
+* Print:: The `print' statement.
+* Print Examples:: Simple examples of `print' statements.
+* Output Separators:: The output separators and how to change them.
+* OFMT:: Controlling Numeric Output With `print'.
+* Printf:: The `printf' statement.
+* Redirection:: How to redirect output to multiple
+ files and pipes.
+* Special Files:: File name interpretation in `gawk'.
+ `gawk' allows access to
+ inherited file descriptors.
+
+
+File: gawk.info, Node: Print, Next: Print Examples, Prev: Printing, Up: Printing
+
+The `print' Statement
+=====================
+
+ The `print' statement does output with simple, standardized
+formatting. You specify only the strings or numbers to be printed, in a
+list separated by commas. They are output, separated by single spaces,
+followed by a newline. The statement looks like this:
+
+ print ITEM1, ITEM2, ...
+
+The entire list of items may optionally be enclosed in parentheses. The
+parentheses are necessary if any of the item expressions uses a
+relational operator; otherwise it could be confused with a redirection
+(*note Redirecting Output of `print' and `printf': Redirection.). The
+relational operators are `==', `!=', `<', `>', `>=', `<=', `~' and `!~'
+(*note Comparison Expressions: Comparison Ops.).
+
+ The items printed can be constant strings or numbers, fields of the
+current record (such as `$1'), variables, or any `awk' expressions.
+The `print' statement is completely general for computing *what* values
+to print. With two exceptions, you cannot specify *how* to print
+them--how many columns, whether to use exponential notation or not, and
+so on. (*Note Output Separators::, and *Note Controlling Numeric
+Output with `print': OFMT.) For that, you need the `printf' statement
+(*note Using `printf' Statements for Fancier Printing: Printf.).
+
+ The simple statement `print' with no items is equivalent to `print
+$0': it prints the entire current record. To print a blank line, use
+`print ""', where `""' is the null, or empty, string.
+
+ To print a fixed piece of text, use a string constant such as
+`"Hello there"' as one item. If you forget to use the double-quote
+characters, your text will be taken as an `awk' expression, and you
+will probably get an error. Keep in mind that a space is printed
+between any two items.
+
+ Most often, each `print' statement makes one line of output. But it
+isn't limited to one line. If an item value is a string that contains a
+newline, the newline is output along with the rest of the string. A
+single `print' can make any number of lines this way.
+
+
+File: gawk.info, Node: Print Examples, Next: Output Separators, Prev: Print, Up: Printing
+
+Examples of `print' Statements
+==============================
+
+ Here is an example of printing a string that contains embedded
+newlines:
+
+ awk 'BEGIN { print "line one\nline two\nline three" }'
+
+produces output like this:
+
+ line one
+ line two
+ line three
+
+ Here is an example that prints the first two fields of each input
+record, with a space between them:
+
+ awk '{ print $1, $2 }' inventory-shipped
+
+Its output looks like this:
+
+ Jan 13
+ Feb 15
+ Mar 15
+ ...
+
+ A common mistake in using the `print' statement is to omit the comma
+between two items. This often has the effect of making the items run
+together in the output, with no space. The reason for this is that
+juxtaposing two string expressions in `awk' means to concatenate them.
+For example, without the comma:
+
+ awk '{ print $1 $2 }' inventory-shipped
+
+prints:
+
+ Jan13
+ Feb15
+ Mar15
+ ...
+
+ Neither example's output makes much sense to someone unfamiliar with
+the file `inventory-shipped'. A heading line at the beginning would
+make it clearer. Let's add some headings to our table of months (`$1')
+and green crates shipped (`$2'). We do this using the `BEGIN' pattern
+(*note `BEGIN' and `END' Special Patterns: BEGIN/END.) to force the
+headings to be printed only once:
+
+ awk 'BEGIN { print "Month Crates"
+ print "----- ------" }
+ { print $1, $2 }' inventory-shipped
+
+Did you already guess what happens? This program prints the following:
+
+ Month Crates
+ ----- ------
+ Jan 13
+ Feb 15
+ Mar 15
+ ...
+
+The headings and the table data don't line up! We can fix this by
+printing some spaces between the two fields:
+
+ awk 'BEGIN { print "Month Crates"
+ print "----- ------" }
+ { print $1, " ", $2 }' inventory-shipped
+
+ You can imagine that this way of lining up columns can get pretty
+complicated when you have many columns to fix. Counting spaces for two
+or three columns can be simple, but more than this and you can get
+"lost" quite easily. This is why the `printf' statement was created
+(*note Using `printf' Statements for Fancier Printing: Printf.); one of
+its specialties is lining up columns of data.
+
diff --git a/gawk.info-3 b/gawk.info-3
new file mode 100644
index 00000000..5c87ac3a
--- /dev/null
+++ b/gawk.info-3
@@ -0,0 +1,1288 @@
+This is Info file gawk.info, produced by Makeinfo-1.54 from the input
+file gawk.texi.
+
+ This file documents `awk', a program that you can use to select
+particular records in a file and perform operations upon them.
+
+ This is Edition 0.15 of `The GAWK Manual',
+for the 2.15 version of the GNU implementation
+of AWK.
+
+ Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that
+the entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Foundation.
+
+
+File: gawk.info, Node: Output Separators, Next: OFMT, Prev: Print Examples, Up: Printing
+
+Output Separators
+=================
+
+ As mentioned previously, a `print' statement contains a list of
+items, separated by commas. In the output, the items are normally
+separated by single spaces. But they do not have to be spaces; a
+single space is only the default. You can specify any string of
+characters to use as the "output field separator" by setting the
+built-in variable `OFS'. The initial value of this variable is the
+string `" "', that is, just a single space.
+
+ The output from an entire `print' statement is called an "output
+record". Each `print' statement outputs one output record and then
+outputs a string called the "output record separator". The built-in
+variable `ORS' specifies this string. The initial value of the
+variable is the string `"\n"' containing a newline character; thus,
+normally each `print' statement makes a separate line.
+
+ You can change how output fields and records are separated by
+assigning new values to the variables `OFS' and/or `ORS'. The usual
+place to do this is in the `BEGIN' rule (*note `BEGIN' and `END'
+Special Patterns: BEGIN/END.), so that it happens before any input is
+processed. You may also do this with assignments on the command line,
+before the names of your input files.
+
+ The following example prints the first and second fields of each
+input record separated by a semicolon, with a blank line added after
+each line:
+
+ awk 'BEGIN { OFS = ";"; ORS = "\n\n" }
+ { print $1, $2 }' BBS-list
+
+ If the value of `ORS' does not contain a newline, all your output
+will be run together on a single line, unless you output newlines some
+other way.
+
+
+File: gawk.info, Node: OFMT, Next: Printf, Prev: Output Separators, Up: Printing
+
+Controlling Numeric Output with `print'
+=======================================
+
+ When you use the `print' statement to print numeric values, `awk'
+internally converts the number to a string of characters, and prints
+that string. `awk' uses the `sprintf' function to do this conversion.
+For now, it suffices to say that the `sprintf' function accepts a
+"format specification" that tells it how to format numbers (or
+strings), and that there are a number of different ways that numbers
+can be formatted. The different format specifications are discussed
+more fully in *Note Using `printf' Statements for Fancier Printing:
+Printf.
+
+ The built-in variable `OFMT' contains the default format
+specification that `print' uses with `sprintf' when it wants to convert
+a number to a string for printing. By supplying different format
+specifications as the value of `OFMT', you can change how `print' will
+print your numbers. As a brief example:
+
+ awk 'BEGIN { OFMT = "%d" # print numbers as integers
+ print 17.23 }'
+
+will print `17'.
+
+
+File: gawk.info, Node: Printf, Next: Redirection, Prev: OFMT, Up: Printing
+
+Using `printf' Statements for Fancier Printing
+==============================================
+
+ If you want more precise control over the output format than `print'
+gives you, use `printf'. With `printf' you can specify the width to
+use for each item, and you can specify various stylistic choices for
+numbers (such as what radix to use, whether to print an exponent,
+whether to print a sign, and how many digits to print after the decimal
+point). You do this by specifying a string, called the "format
+string", which controls how and where to print the other arguments.
+
+* Menu:
+
+* Basic Printf:: Syntax of the `printf' statement.
+* Control Letters:: Format-control letters.
+* Format Modifiers:: Format-specification modifiers.
+* Printf Examples:: Several examples.
+
+
+File: gawk.info, Node: Basic Printf, Next: Control Letters, Prev: Printf, Up: Printf
+
+Introduction to the `printf' Statement
+--------------------------------------
+
+ The `printf' statement looks like this:
+
+ printf FORMAT, ITEM1, ITEM2, ...
+
+The entire list of arguments may optionally be enclosed in parentheses.
+The parentheses are necessary if any of the item expressions uses a
+relational operator; otherwise it could be confused with a redirection
+(*note Redirecting Output of `print' and `printf': Redirection.). The
+relational operators are `==', `!=', `<', `>', `>=', `<=', `~' and `!~'
+(*note Comparison Expressions: Comparison Ops.).
+
+ The difference between `printf' and `print' is the argument FORMAT.
+This is an expression whose value is taken as a string; it specifies
+how to output each of the other arguments. It is called the "format
+string".
+
+ The format string is the same as in the ANSI C library function
+`printf'. Most of FORMAT is text to be output verbatim. Scattered
+among this text are "format specifiers", one per item. Each format
+specifier says to output the next item at that place in the format.
+
+ The `printf' statement does not automatically append a newline to its
+output. It outputs only what the format specifies. So if you want a
+newline, you must include one in the format. The output separator
+variables `OFS' and `ORS' have no effect on `printf' statements.
+
+
+File: gawk.info, Node: Control Letters, Next: Format Modifiers, Prev: Basic Printf, Up: Printf
+
+Format-Control Letters
+----------------------
+
+ A format specifier starts with the character `%' and ends with a
+"format-control letter"; it tells the `printf' statement how to output
+one item. (If you actually want to output a `%', write `%%'.) The
+format-control letter specifies what kind of value to print. The rest
+of the format specifier is made up of optional "modifiers" which are
+parameters such as the field width to use.
+
+ Here is a list of the format-control letters:
+
+`c'
+ This prints a number as an ASCII character. Thus, `printf "%c",
+ 65' outputs the letter `A'. The output for a string value is the
+ first character of the string.
+
+`d'
+ This prints a decimal integer.
+
+`i'
+ This also prints a decimal integer.
+
+`e'
+ This prints a number in scientific (exponential) notation. For
+ example,
+
+ printf "%4.3e", 1950
+
+ prints `1.950e+03', with a total of four significant figures of
+ which three follow the decimal point. The `4.3' are "modifiers",
+ discussed below.
+
+`f'
+ This prints a number in floating point notation.
+
+`g'
+ This prints a number in either scientific notation or floating
+ point notation, whichever uses fewer characters.
+
+`o'
+ This prints an unsigned octal integer.
+
+`s'
+ This prints a string.
+
+`x'
+ This prints an unsigned hexadecimal integer.
+
+`X'
+ This prints an unsigned hexadecimal integer. However, for the
+ values 10 through 15, it uses the letters `A' through `F' instead
+ of `a' through `f'.
+
+`%'
+ This isn't really a format-control letter, but it does have a
+ meaning when used after a `%': the sequence `%%' outputs one `%'.
+ It does not consume an argument.
+
+
+File: gawk.info, Node: Format Modifiers, Next: Printf Examples, Prev: Control Letters, Up: Printf
+
+Modifiers for `printf' Formats
+------------------------------
+
+ A format specification can also include "modifiers" that can control
+how much of the item's value is printed and how much space it gets. The
+modifiers come between the `%' and the format-control letter. Here are
+the possible modifiers, in the order in which they may appear:
+
+`-'
+ The minus sign, used before the width modifier, says to
+ left-justify the argument within its specified width. Normally
+ the argument is printed right-justified in the specified width.
+ Thus,
+
+ printf "%-4s", "foo"
+
+ prints `foo '.
+
+`WIDTH'
+ This is a number representing the desired width of a field.
+ Inserting any number between the `%' sign and the format control
+ character forces the field to be expanded to this width. The
+ default way to do this is to pad with spaces on the left. For
+ example,
+
+ printf "%4s", "foo"
+
+ prints ` foo'.
+
+ The value of WIDTH is a minimum width, not a maximum. If the item
+ value requires more than WIDTH characters, it can be as wide as
+ necessary. Thus,
+
+ printf "%4s", "foobar"
+
+ prints `foobar'.
+
+ Preceding the WIDTH with a minus sign causes the output to be
+ padded with spaces on the right, instead of on the left.
+
+`.PREC'
+ This is a number that specifies the precision to use when printing.
+ This specifies the number of digits you want printed to the right
+ of the decimal point. For a string, it specifies the maximum
+ number of characters from the string that should be printed.
+
+ The C library `printf''s dynamic WIDTH and PREC capability (for
+example, `"%*.*s"') is supported. Instead of supplying explicit WIDTH
+and/or PREC values in the format string, you pass them in the argument
+list. For example:
+
+ w = 5
+ p = 3
+ s = "abcdefg"
+ printf "<%*.*s>\n", w, p, s
+
+is exactly equivalent to
+
+ s = "abcdefg"
+ printf "<%5.3s>\n", s
+
+Both programs output `<**abc>'. (We have used the bullet symbol "*" to
+represent a space, to clearly show you that there are two spaces in the
+output.)
+
+ Earlier versions of `awk' did not support this capability. You may
+simulate it by using concatenation to build up the format string, like
+so:
+
+ w = 5
+ p = 3
+ s = "abcdefg"
+ printf "<%" w "." p "s>\n", s
+
+This is not particularly easy to read, however.
+
+
+File: gawk.info, Node: Printf Examples, Prev: Format Modifiers, Up: Printf
+
+Examples of Using `printf'
+--------------------------
+
+ Here is how to use `printf' to make an aligned table:
+
+ awk '{ printf "%-10s %s\n", $1, $2 }' BBS-list
+
+prints the names of bulletin boards (`$1') of the file `BBS-list' as a
+string of 10 characters, left justified. It also prints the phone
+numbers (`$2') afterward on the line. This produces an aligned
+two-column table of names and phone numbers:
+
+ aardvark 555-5553
+ alpo-net 555-3412
+ barfly 555-7685
+ bites 555-1675
+ camelot 555-0542
+ core 555-2912
+ fooey 555-1234
+ foot 555-6699
+ macfoo 555-6480
+ sdace 555-3430
+ sabafoo 555-2127
+
+ Did you notice that we did not specify that the phone numbers be
+printed as numbers? They had to be printed as strings because the
+numbers are separated by a dash. This dash would be interpreted as a
+minus sign if we had tried to print the phone numbers as numbers. This
+would have led to some pretty confusing results.
+
+ We did not specify a width for the phone numbers because they are the
+last things on their lines. We don't need to put spaces after them.
+
+ We could make our table look even nicer by adding headings to the
+tops of the columns. To do this, use the `BEGIN' pattern (*note
+`BEGIN' and `END' Special Patterns: BEGIN/END.) to force the header to
+be printed only once, at the beginning of the `awk' program:
+
+ awk 'BEGIN { print "Name Number"
+ print "---- ------" }
+ { printf "%-10s %s\n", $1, $2 }' BBS-list
+
+ Did you notice that we mixed `print' and `printf' statements in the
+above example? We could have used just `printf' statements to get the
+same results:
+
+ awk 'BEGIN { printf "%-10s %s\n", "Name", "Number"
+ printf "%-10s %s\n", "----", "------" }
+ { printf "%-10s %s\n", $1, $2 }' BBS-list
+
+By outputting each column heading with the same format specification
+used for the elements of the column, we have made sure that the headings
+are aligned just like the columns.
+
+ The fact that the same format specification is used three times can
+be emphasized by storing it in a variable, like this:
+
+ awk 'BEGIN { format = "%-10s %s\n"
+ printf format, "Name", "Number"
+ printf format, "----", "------" }
+ { printf format, $1, $2 }' BBS-list
+
+ See if you can use the `printf' statement to line up the headings and
+table data for our `inventory-shipped' example covered earlier in the
+section on the `print' statement (*note The `print' Statement: Print.).
+
+
+File: gawk.info, Node: Redirection, Next: Special Files, Prev: Printf, Up: Printing
+
+Redirecting Output of `print' and `printf'
+==========================================
+
+ So far we have been dealing only with output that prints to the
+standard output, usually your terminal. Both `print' and `printf' can
+also send their output to other places. This is called "redirection".
+
+ A redirection appears after the `print' or `printf' statement.
+Redirections in `awk' are written just like redirections in shell
+commands, except that they are written inside the `awk' program.
+
+* Menu:
+
+* File/Pipe Redirection:: Redirecting Output to Files and Pipes.
+* Close Output:: How to close output files and pipes.
+
+
+File: gawk.info, Node: File/Pipe Redirection, Next: Close Output, Prev: Redirection, Up: Redirection
+
+Redirecting Output to Files and Pipes
+-------------------------------------
+
+ Here are the three forms of output redirection. They are all shown
+for the `print' statement, but they work identically for `printf' also.
+
+`print ITEMS > OUTPUT-FILE'
+ This type of redirection prints the items onto the output file
+ OUTPUT-FILE. The file name OUTPUT-FILE can be any expression.
+ Its value is changed to a string and then used as a file name
+ (*note Expressions as Action Statements: Expressions.).
+
+ When this type of redirection is used, the OUTPUT-FILE is erased
+ before the first output is written to it. Subsequent writes do not
+ erase OUTPUT-FILE, but append to it. If OUTPUT-FILE does not
+ exist, then it is created.
+
+ For example, here is how one `awk' program can write a list of BBS
+ names to a file `name-list' and a list of phone numbers to a file
+ `phone-list'. Each output file contains one name or number per
+ line.
+
+ awk '{ print $2 > "phone-list"
+ print $1 > "name-list" }' BBS-list
+
+`print ITEMS >> OUTPUT-FILE'
+ This type of redirection prints the items onto the output file
+ OUTPUT-FILE. The difference between this and the single-`>'
+ redirection is that the old contents (if any) of OUTPUT-FILE are
+ not erased. Instead, the `awk' output is appended to the file.
+
+`print ITEMS | COMMAND'
+ It is also possible to send output through a "pipe" instead of
+ into a file. This type of redirection opens a pipe to COMMAND
+ and writes the values of ITEMS through this pipe, to another
+ process created to execute COMMAND.
+
+ The redirection argument COMMAND is actually an `awk' expression.
+ Its value is converted to a string, whose contents give the shell
+ command to be run.
+
+ For example, this produces two files, one unsorted list of BBS
+ names and one list sorted in reverse alphabetical order:
+
+ awk '{ print $1 > "names.unsorted"
+ print $1 | "sort -r > names.sorted" }' BBS-list
+
+ Here the unsorted list is written with an ordinary redirection
+ while the sorted list is written by piping through the `sort'
+ utility.
+
+ Here is an example that uses redirection to mail a message to a
+ mailing list `bug-system'. This might be useful when trouble is
+ encountered in an `awk' script run periodically for system
+ maintenance.
+
+ report = "mail bug-system"
+ print "Awk script failed:", $0 | report
+ print "at record number", FNR, "of", FILENAME | report
+ close(report)
+
+ We call the `close' function here because it's a good idea to close
+ the pipe as soon as all the intended output has been sent to it.
+ *Note Closing Output Files and Pipes: Close Output, for more
+ information on this. This example also illustrates the use of a
+ variable to represent a FILE or COMMAND: it is not necessary to
+ always use a string constant. Using a variable is generally a
+ good idea, since `awk' requires you to spell the string value
+ identically every time.
+
+ Redirecting output using `>', `>>', or `|' asks the system to open a
+file or pipe only if the particular FILE or COMMAND you've specified
+has not already been written to by your program, or if it has been
+closed since it was last written to.
+
+
+File: gawk.info, Node: Close Output, Prev: File/Pipe Redirection, Up: Redirection
+
+Closing Output Files and Pipes
+------------------------------
+
+ When a file or pipe is opened, the file name or command associated
+with it is remembered by `awk' and subsequent writes to the same file or
+command are appended to the previous writes. The file or pipe stays
+open until `awk' exits. This is usually convenient.
+
+ Sometimes there is a reason to close an output file or pipe earlier
+than that. To do this, use the `close' function, as follows:
+
+ close(FILENAME)
+
+or
+
+ close(COMMAND)
+
+ The argument FILENAME or COMMAND can be any expression. Its value
+must exactly equal the string used to open the file or pipe to begin
+with--for example, if you open a pipe with this:
+
+ print $1 | "sort -r > names.sorted"
+
+then you must close it with this:
+
+ close("sort -r > names.sorted")
+
+ Here are some reasons why you might need to close an output file:
+
+ * To write a file and read it back later on in the same `awk'
+ program. Close the file when you are finished writing it; then
+ you can start reading it with `getline' (*note Explicit Input with
+ `getline': Getline.).
+
+ * To write numerous files, successively, in the same `awk' program.
+ If you don't close the files, eventually you may exceed a system
+ limit on the number of open files in one process. So close each
+ one when you are finished writing it.
+
+ * To make a command finish. When you redirect output through a pipe,
+ the command reading the pipe normally continues to try to read
+ input as long as the pipe is open. Often this means the command
+ cannot really do its work until the pipe is closed. For example,
+ if you redirect output to the `mail' program, the message is not
+ actually sent until the pipe is closed.
+
+ * To run the same program a second time, with the same arguments.
+ This is not the same thing as giving more input to the first run!
+
+ For example, suppose you pipe output to the `mail' program. If you
+ output several lines redirected to this pipe without closing it,
+ they make a single message of several lines. By contrast, if you
+ close the pipe after each line of output, then each line makes a
+ separate message.
+
+ `close' returns a value of zero if the close succeeded. Otherwise,
+the value will be non-zero. In this case, `gawk' sets the variable
+`ERRNO' to a string describing the error that occurred.
+
+
+File: gawk.info, Node: Special Files, Prev: Redirection, Up: Printing
+
+Standard I/O Streams
+====================
+
+ Running programs conventionally have three input and output streams
+already available to them for reading and writing. These are known as
+the "standard input", "standard output", and "standard error output".
+These streams are, by default, terminal input and output, but they are
+often redirected with the shell, via the `<', `<<', `>', `>>', `>&' and
+`|' operators. Standard error is used only for writing error messages;
+the reason we have two separate streams, standard output and standard
+error, is so that they can be redirected separately.
+
+ In other implementations of `awk', the only way to write an error
+message to standard error in an `awk' program is as follows:
+
+ print "Serious error detected!\n" | "cat 1>&2"
+
+This works by opening a pipeline to a shell command which can access the
+standard error stream which it inherits from the `awk' process. This
+is far from elegant, and is also inefficient, since it requires a
+separate process. So people writing `awk' programs have often
+neglected to do this. Instead, they have sent the error messages to the
+terminal, like this:
+
+ NF != 4 {
+ printf("line %d skipped: doesn't have 4 fields\n", FNR) > "/dev/tty"
+ }
+
+This has the same effect most of the time, but not always: although the
+standard error stream is usually the terminal, it can be redirected, and
+when that happens, writing to the terminal is not correct. In fact, if
+`awk' is run from a background job, it may not have a terminal at all.
+Then opening `/dev/tty' will fail.
+
+ `gawk' provides special file names for accessing the three standard
+streams. When you redirect input or output in `gawk', if the file name
+matches one of these special names, then `gawk' directly uses the
+stream it stands for.
+
+`/dev/stdin'
+ The standard input (file descriptor 0).
+
+`/dev/stdout'
+ The standard output (file descriptor 1).
+
+`/dev/stderr'
+ The standard error output (file descriptor 2).
+
+`/dev/fd/N'
+ The file associated with file descriptor N. Such a file must have
+ been opened by the program initiating the `awk' execution
+ (typically the shell). Unless you take special pains, only
+ descriptors 0, 1 and 2 are available.
+
+ The file names `/dev/stdin', `/dev/stdout', and `/dev/stderr' are
+aliases for `/dev/fd/0', `/dev/fd/1', and `/dev/fd/2', respectively,
+but they are more self-explanatory.
+
+ The proper way to write an error message in a `gawk' program is to
+use `/dev/stderr', like this:
+
+ NF != 4 {
+ printf("line %d skipped: doesn't have 4 fields\n", FNR) > "/dev/stderr"
+ }
+
+ `gawk' also provides special file names that give access to
+information about the running `gawk' process. Each of these "files"
+provides a single record of information. To read them more than once,
+you must first close them with the `close' function (*note Closing
+Input Files and Pipes: Close Input.). The filenames are:
+
+`/dev/pid'
+ Reading this file returns the process ID of the current process,
+ in decimal, terminated with a newline.
+
+`/dev/ppid'
+ Reading this file returns the parent process ID of the current
+ process, in decimal, terminated with a newline.
+
+`/dev/pgrpid'
+ Reading this file returns the process group ID of the current
+ process, in decimal, terminated with a newline.
+
+`/dev/user'
+ Reading this file returns a single record terminated with a
+ newline. The fields are separated with blanks. The fields
+ represent the following information:
+
+ `$1'
+ The value of the `getuid' system call.
+
+ `$2'
+ The value of the `geteuid' system call.
+
+ `$3'
+ The value of the `getgid' system call.
+
+ `$4'
+ The value of the `getegid' system call.
+
+ If there are any additional fields, they are the group IDs
+ returned by `getgroups' system call. (Multiple groups may not be
+ supported on all systems.)
+
+ These special file names may be used on the command line as data
+files, as well as for I/O redirections within an `awk' program. They
+may not be used as source files with the `-f' option.
+
+ Recognition of these special file names is disabled if `gawk' is in
+compatibility mode (*note Invoking `awk': Command Line.).
+
+ *Caution*: Unless your system actually has a `/dev/fd' directory
+ (or any of the other above listed special files), the
+ interpretation of these file names is done by `gawk' itself. For
+ example, using `/dev/fd/4' for output will actually write on file
+ descriptor 4, and not on a new file descriptor that was `dup''ed
+ from file descriptor 4. Most of the time this does not matter;
+ however, it is important to *not* close any of the files related
+ to file descriptors 0, 1, and 2. If you do close one of these
+ files, unpredictable behavior will result.
+
+
+File: gawk.info, Node: One-liners, Next: Patterns, Prev: Printing, Up: Top
+
+Useful "One-liners"
+*******************
+
+ Useful `awk' programs are often short, just a line or two. Here is a
+collection of useful, short programs to get you started. Some of these
+programs contain constructs that haven't been covered yet. The
+description of the program will give you a good idea of what is going
+on, but please read the rest of the manual to become an `awk' expert!
+
+ Since you are reading this in Info, each line of the example code is
+enclosed in quotes, to represent text that you would type literally.
+The examples themselves represent shell commands that use single quotes
+to keep the shell from interpreting the contents of the program. When
+reading the examples, focus on the text between the open and close
+quotes.
+
+`awk '{ if (NF > max) max = NF }'
+` END { print max }''
+ This program prints the maximum number of fields on any input line.
+
+`awk 'length($0) > 80''
+ This program prints every line longer than 80 characters. The sole
+ rule has a relational expression as its pattern, and has no action
+ (so the default action, printing the record, is used).
+
+`awk 'NF > 0''
+ This program prints every line that has at least one field. This
+ is an easy way to delete blank lines from a file (or rather, to
+ create a new file similar to the old file but from which the blank
+ lines have been deleted).
+
+`awk '{ if (NF > 0) print }''
+ This program also prints every line that has at least one field.
+ Here we allow the rule to match every line, then decide in the
+ action whether to print.
+
+`awk 'BEGIN { for (i = 1; i <= 7; i++)'
+` print int(101 * rand()) }''
+ This program prints 7 random numbers from 0 to 100, inclusive.
+
+`ls -l FILES | awk '{ x += $4 } ; END { print "total bytes: " x }''
+ This program prints the total number of bytes used by FILES.
+
+`expand FILE | awk '{ if (x < length()) x = length() }'
+` END { print "maximum line length is " x }''
+ This program prints the maximum line length of FILE. The input is
+ piped through the `expand' program to change tabs into spaces, so
+ the widths compared are actually the right-margin columns.
+
+`awk 'BEGIN { FS = ":" }'
+` { print $1 | "sort" }' /etc/passwd'
+ This program prints a sorted list of the login names of all users.
+
+`awk '{ nlines++ }'
+` END { print nlines }''
+ This programs counts lines in a file.
+
+`awk 'END { print NR }''
+ This program also counts lines in a file, but lets `awk' do the
+ work.
+
+`awk '{ print NR, $0 }''
+ This program adds line numbers to all its input files, similar to
+ `cat -n'.
+
+
+File: gawk.info, Node: Patterns, Next: Actions, Prev: One-liners, Up: Top
+
+Patterns
+********
+
+ Patterns in `awk' control the execution of rules: a rule is executed
+when its pattern matches the current input record. This chapter tells
+all about how to write patterns.
+
+* Menu:
+
+* Kinds of Patterns:: A list of all kinds of patterns.
+ The following subsections describe
+ them in detail.
+* Regexp:: Regular expressions such as `/foo/'.
+* Comparison Patterns:: Comparison expressions such as `$1 > 10'.
+* Boolean Patterns:: Combining comparison expressions.
+* Expression Patterns:: Any expression can be used as a pattern.
+* Ranges:: Pairs of patterns specify record ranges.
+* BEGIN/END:: Specifying initialization and cleanup rules.
+* Empty:: The empty pattern, which matches every record.
+
+
+File: gawk.info, Node: Kinds of Patterns, Next: Regexp, Prev: Patterns, Up: Patterns
+
+Kinds of Patterns
+=================
+
+ Here is a summary of the types of patterns supported in `awk'.
+
+`/REGULAR EXPRESSION/'
+ A regular expression as a pattern. It matches when the text of the
+ input record fits the regular expression. (*Note Regular
+ Expressions as Patterns: Regexp.)
+
+`EXPRESSION'
+ A single expression. It matches when its value, converted to a
+ number, is nonzero (if a number) or nonnull (if a string). (*Note
+ Expressions as Patterns: Expression Patterns.)
+
+`PAT1, PAT2'
+ A pair of patterns separated by a comma, specifying a range of
+ records. (*Note Specifying Record Ranges with Patterns: Ranges.)
+
+`BEGIN'
+`END'
+ Special patterns to supply start-up or clean-up information to
+ `awk'. (*Note `BEGIN' and `END' Special Patterns: BEGIN/END.)
+
+`NULL'
+ The empty pattern matches every input record. (*Note The Empty
+ Pattern: Empty.)
+
+
+File: gawk.info, Node: Regexp, Next: Comparison Patterns, Prev: Kinds of Patterns, Up: Patterns
+
+Regular Expressions as Patterns
+===============================
+
+ A "regular expression", or "regexp", is a way of describing a class
+of strings. A regular expression enclosed in slashes (`/') is an `awk'
+pattern that matches every input record whose text belongs to that
+class.
+
+ The simplest regular expression is a sequence of letters, numbers, or
+both. Such a regexp matches any string that contains that sequence.
+Thus, the regexp `foo' matches any string containing `foo'. Therefore,
+the pattern `/foo/' matches any input record containing `foo'. Other
+kinds of regexps let you specify more complicated classes of strings.
+
+* Menu:
+
+* Regexp Usage:: How to Use Regular Expressions
+* Regexp Operators:: Regular Expression Operators
+* Case-sensitivity:: How to do case-insensitive matching.
+
+
+File: gawk.info, Node: Regexp Usage, Next: Regexp Operators, Prev: Regexp, Up: Regexp
+
+How to Use Regular Expressions
+------------------------------
+
+ A regular expression can be used as a pattern by enclosing it in
+slashes. Then the regular expression is matched against the entire
+text of each record. (Normally, it only needs to match some part of
+the text in order to succeed.) For example, this prints the second
+field of each record that contains `foo' anywhere:
+
+ awk '/foo/ { print $2 }' BBS-list
+
+ Regular expressions can also be used in comparison expressions. Then
+you can specify the string to match against; it need not be the entire
+current input record. These comparison expressions can be used as
+patterns or in `if', `while', `for', and `do' statements.
+
+`EXP ~ /REGEXP/'
+ This is true if the expression EXP (taken as a character string)
+ is matched by REGEXP. The following example matches, or selects,
+ all input records with the upper-case letter `J' somewhere in the
+ first field:
+
+ awk '$1 ~ /J/' inventory-shipped
+
+ So does this:
+
+ awk '{ if ($1 ~ /J/) print }' inventory-shipped
+
+`EXP !~ /REGEXP/'
+ This is true if the expression EXP (taken as a character string)
+ is *not* matched by REGEXP. The following example matches, or
+ selects, all input records whose first field *does not* contain
+ the upper-case letter `J':
+
+ awk '$1 !~ /J/' inventory-shipped
+
+ The right hand side of a `~' or `!~' operator need not be a constant
+regexp (i.e., a string of characters between slashes). It may be any
+expression. The expression is evaluated, and converted if necessary to
+a string; the contents of the string are used as the regexp. A regexp
+that is computed in this way is called a "dynamic regexp". For example:
+
+ identifier_regexp = "[A-Za-z_][A-Za-z_0-9]+"
+ $0 ~ identifier_regexp
+
+sets `identifier_regexp' to a regexp that describes `awk' variable
+names, and tests if the input record matches this regexp.
+
+
+File: gawk.info, Node: Regexp Operators, Next: Case-sensitivity, Prev: Regexp Usage, Up: Regexp
+
+Regular Expression Operators
+----------------------------
+
+ You can combine regular expressions with the following characters,
+called "regular expression operators", or "metacharacters", to increase
+the power and versatility of regular expressions.
+
+ Here is a table of metacharacters. All characters not listed in the
+table stand for themselves.
+
+`^'
+ This matches the beginning of the string or the beginning of a line
+ within the string. For example:
+
+ ^@chapter
+
+ matches the `@chapter' at the beginning of a string, and can be
+ used to identify chapter beginnings in Texinfo source files.
+
+`$'
+ This is similar to `^', but it matches only at the end of a string
+ or the end of a line within the string. For example:
+
+ p$
+
+ matches a record that ends with a `p'.
+
+`.'
+ This matches any single character except a newline. For example:
+
+ .P
+
+ matches any single character followed by a `P' in a string. Using
+ concatenation we can make regular expressions like `U.A', which
+ matches any three-character sequence that begins with `U' and ends
+ with `A'.
+
+`[...]'
+ This is called a "character set". It matches any one of the
+ characters that are enclosed in the square brackets. For example:
+
+ [MVX]
+
+ matches any one of the characters `M', `V', or `X' in a string.
+
+ Ranges of characters are indicated by using a hyphen between the
+ beginning and ending characters, and enclosing the whole thing in
+ brackets. For example:
+
+ [0-9]
+
+ matches any digit.
+
+ To include the character `\', `]', `-' or `^' in a character set,
+ put a `\' in front of it. For example:
+
+ [d\]]
+
+ matches either `d', or `]'.
+
+ This treatment of `\' is compatible with other `awk'
+ implementations, and is also mandated by the POSIX Command Language
+ and Utilities standard. The regular expressions in `awk' are a
+ superset of the POSIX specification for Extended Regular
+ Expressions (EREs). POSIX EREs are based on the regular
+ expressions accepted by the traditional `egrep' utility.
+
+ In `egrep' syntax, backslash is not syntactically special within
+ square brackets. This means that special tricks have to be used to
+ represent the characters `]', `-' and `^' as members of a
+ character set.
+
+ In `egrep' syntax, to match `-', write it as `---', which is a
+ range containing only `-'. You may also give `-' as the first or
+ last character in the set. To match `^', put it anywhere except
+ as the first character of a set. To match a `]', make it the
+ first character in the set. For example:
+
+ []d^]
+
+ matches either `]', `d' or `^'.
+
+`[^ ...]'
+ This is a "complemented character set". The first character after
+ the `[' *must* be a `^'. It matches any characters *except* those
+ in the square brackets (or newline). For example:
+
+ [^0-9]
+
+ matches any character that is not a digit.
+
+`|'
+ This is the "alternation operator" and it is used to specify
+ alternatives. For example:
+
+ ^P|[0-9]
+
+ matches any string that matches either `^P' or `[0-9]'. This
+ means it matches any string that contains a digit or starts with
+ `P'.
+
+ The alternation applies to the largest possible regexps on either
+ side.
+
+`(...)'
+ Parentheses are used for grouping in regular expressions as in
+ arithmetic. They can be used to concatenate regular expressions
+ containing the alternation operator, `|'.
+
+`*'
+ This symbol means that the preceding regular expression is to be
+ repeated as many times as possible to find a match. For example:
+
+ ph*
+
+ applies the `*' symbol to the preceding `h' and looks for matches
+ to one `p' followed by any number of `h's. This will also match
+ just `p' if no `h's are present.
+
+ The `*' repeats the *smallest* possible preceding expression.
+ (Use parentheses if you wish to repeat a larger expression.) It
+ finds as many repetitions as possible. For example:
+
+ awk '/\(c[ad][ad]*r x\)/ { print }' sample
+
+ prints every record in the input containing a string of the form
+ `(car x)', `(cdr x)', `(cadr x)', and so on.
+
+`+'
+ This symbol is similar to `*', but the preceding expression must be
+ matched at least once. This means that:
+
+ wh+y
+
+ would match `why' and `whhy' but not `wy', whereas `wh*y' would
+ match all three of these strings. This is a simpler way of
+ writing the last `*' example:
+
+ awk '/\(c[ad]+r x\)/ { print }' sample
+
+`?'
+ This symbol is similar to `*', but the preceding expression can be
+ matched once or not at all. For example:
+
+ fe?d
+
+ will match `fed' and `fd', but nothing else.
+
+`\'
+ This is used to suppress the special meaning of a character when
+ matching. For example:
+
+ \$
+
+ matches the character `$'.
+
+ The escape sequences used for string constants (*note Constant
+ Expressions: Constants.) are valid in regular expressions as well;
+ they are also introduced by a `\'.
+
+ In regular expressions, the `*', `+', and `?' operators have the
+highest precedence, followed by concatenation, and finally by `|'. As
+in arithmetic, parentheses can change how operators are grouped.
+
+
+File: gawk.info, Node: Case-sensitivity, Prev: Regexp Operators, Up: Regexp
+
+Case-sensitivity in Matching
+----------------------------
+
+ Case is normally significant in regular expressions, both when
+matching ordinary characters (i.e., not metacharacters), and inside
+character sets. Thus a `w' in a regular expression matches only a
+lower case `w' and not an upper case `W'.
+
+ The simplest way to do a case-independent match is to use a character
+set: `[Ww]'. However, this can be cumbersome if you need to use it
+often; and it can make the regular expressions harder for humans to
+read. There are two other alternatives that you might prefer.
+
+ One way to do a case-insensitive match at a particular point in the
+program is to convert the data to a single case, using the `tolower' or
+`toupper' built-in string functions (which we haven't discussed yet;
+*note Built-in Functions for String Manipulation: String Functions.).
+For example:
+
+ tolower($1) ~ /foo/ { ... }
+
+converts the first field to lower case before matching against it.
+
+ Another method is to set the variable `IGNORECASE' to a nonzero
+value (*note Built-in Variables::.). When `IGNORECASE' is not zero,
+*all* regexp operations ignore case. Changing the value of
+`IGNORECASE' dynamically controls the case sensitivity of your program
+as it runs. Case is significant by default because `IGNORECASE' (like
+most variables) is initialized to zero.
+
+ x = "aB"
+ if (x ~ /ab/) ... # this test will fail
+
+ IGNORECASE = 1
+ if (x ~ /ab/) ... # now it will succeed
+
+ In general, you cannot use `IGNORECASE' to make certain rules
+case-insensitive and other rules case-sensitive, because there is no way
+to set `IGNORECASE' just for the pattern of a particular rule. To do
+this, you must use character sets or `tolower'. However, one thing you
+can do only with `IGNORECASE' is turn case-sensitivity on or off
+dynamically for all the rules at once.
+
+ `IGNORECASE' can be set on the command line, or in a `BEGIN' rule.
+Setting `IGNORECASE' from the command line is a way to make a program
+case-insensitive without having to edit it.
+
+ The value of `IGNORECASE' has no effect if `gawk' is in
+compatibility mode (*note Invoking `awk': Command Line.). Case is
+always significant in compatibility mode.
+
+
+File: gawk.info, Node: Comparison Patterns, Next: Boolean Patterns, Prev: Regexp, Up: Patterns
+
+Comparison Expressions as Patterns
+==================================
+
+ "Comparison patterns" test relationships such as equality between
+two strings or numbers. They are a special case of expression patterns
+(*note Expressions as Patterns: Expression Patterns.). They are written
+with "relational operators", which are a superset of those in C. Here
+is a table of them:
+
+`X < Y'
+ True if X is less than Y.
+
+`X <= Y'
+ True if X is less than or equal to Y.
+
+`X > Y'
+ True if X is greater than Y.
+
+`X >= Y'
+ True if X is greater than or equal to Y.
+
+`X == Y'
+ True if X is equal to Y.
+
+`X != Y'
+ True if X is not equal to Y.
+
+`X ~ Y'
+ True if X matches the regular expression described by Y.
+
+`X !~ Y'
+ True if X does not match the regular expression described by Y.
+
+ The operands of a relational operator are compared as numbers if they
+are both numbers. Otherwise they are converted to, and compared as,
+strings (*note Conversion of Strings and Numbers: Conversion., for the
+detailed rules). Strings are compared by comparing the first character
+of each, then the second character of each, and so on, until there is a
+difference. If the two strings are equal until the shorter one runs
+out, the shorter one is considered to be less than the longer one.
+Thus, `"10"' is less than `"9"', and `"abc"' is less than `"abcd"'.
+
+ The left operand of the `~' and `!~' operators is a string. The
+right operand is either a constant regular expression enclosed in
+slashes (`/REGEXP/'), or any expression, whose string value is used as
+a dynamic regular expression (*note How to Use Regular Expressions:
+Regexp Usage.).
+
+ The following example prints the second field of each input record
+whose first field is precisely `foo'.
+
+ awk '$1 == "foo" { print $2 }' BBS-list
+
+Contrast this with the following regular expression match, which would
+accept any record with a first field that contains `foo':
+
+ awk '$1 ~ "foo" { print $2 }' BBS-list
+
+or, equivalently, this one:
+
+ awk '$1 ~ /foo/ { print $2 }' BBS-list
+
+
+File: gawk.info, Node: Boolean Patterns, Next: Expression Patterns, Prev: Comparison Patterns, Up: Patterns
+
+Boolean Operators and Patterns
+==============================
+
+ A "boolean pattern" is an expression which combines other patterns
+using the "boolean operators" "or" (`||'), "and" (`&&'), and "not"
+(`!'). Whether the boolean pattern matches an input record depends on
+whether its subpatterns match.
+
+ For example, the following command prints all records in the input
+file `BBS-list' that contain both `2400' and `foo'.
+
+ awk '/2400/ && /foo/' BBS-list
+
+ The following command prints all records in the input file
+`BBS-list' that contain *either* `2400' or `foo', or both.
+
+ awk '/2400/ || /foo/' BBS-list
+
+ The following command prints all records in the input file
+`BBS-list' that do *not* contain the string `foo'.
+
+ awk '! /foo/' BBS-list
+
+ Note that boolean patterns are a special case of expression patterns
+(*note Expressions as Patterns: Expression Patterns.); they are
+expressions that use the boolean operators. *Note Boolean Expressions:
+Boolean Ops, for complete information on the boolean operators.
+
+ The subpatterns of a boolean pattern can be constant regular
+expressions, comparisons, or any other `awk' expressions. Range
+patterns are not expressions, so they cannot appear inside boolean
+patterns. Likewise, the special patterns `BEGIN' and `END', which
+never match any input record, are not expressions and cannot appear
+inside boolean patterns.
+
+
+File: gawk.info, Node: Expression Patterns, Next: Ranges, Prev: Boolean Patterns, Up: Patterns
+
+Expressions as Patterns
+=======================
+
+ Any `awk' expression is also valid as an `awk' pattern. Then the
+pattern "matches" if the expression's value is nonzero (if a number) or
+nonnull (if a string).
+
+ The expression is reevaluated each time the rule is tested against a
+new input record. If the expression uses fields such as `$1', the
+value depends directly on the new input record's text; otherwise, it
+depends only on what has happened so far in the execution of the `awk'
+program, but that may still be useful.
+
+ Comparison patterns are actually a special case of this. For
+example, the expression `$5 == "foo"' has the value 1 when the value of
+`$5' equals `"foo"', and 0 otherwise; therefore, this expression as a
+pattern matches when the two values are equal.
+
+ Boolean patterns are also special cases of expression patterns.
+
+ A constant regexp as a pattern is also a special case of an
+expression pattern. `/foo/' as an expression has the value 1 if `foo'
+appears in the current input record; thus, as a pattern, `/foo/'
+matches any record containing `foo'.
+
+ Other implementations of `awk' that are not yet POSIX compliant are
+less general than `gawk': they allow comparison expressions, and
+boolean combinations thereof (optionally with parentheses), but not
+necessarily other kinds of expressions.
+
+
+File: gawk.info, Node: Ranges, Next: BEGIN/END, Prev: Expression Patterns, Up: Patterns
+
+Specifying Record Ranges with Patterns
+======================================
+
+ A "range pattern" is made of two patterns separated by a comma, of
+the form `BEGPAT, ENDPAT'. It matches ranges of consecutive input
+records. The first pattern BEGPAT controls where the range begins, and
+the second one ENDPAT controls where it ends. For example,
+
+ awk '$1 == "on", $1 == "off"'
+
+prints every record between `on'/`off' pairs, inclusive.
+
+ A range pattern starts out by matching BEGPAT against every input
+record; when a record matches BEGPAT, the range pattern becomes "turned
+on". The range pattern matches this record. As long as it stays
+turned on, it automatically matches every input record read. It also
+matches ENDPAT against every input record; when that succeeds, the
+range pattern is turned off again for the following record. Now it
+goes back to checking BEGPAT against each record.
+
+ The record that turns on the range pattern and the one that turns it
+off both match the range pattern. If you don't want to operate on
+these records, you can write `if' statements in the rule's action to
+distinguish them.
+
+ It is possible for a pattern to be turned both on and off by the same
+record, if both conditions are satisfied by that record. Then the
+action is executed for just that record.
+
+
+File: gawk.info, Node: BEGIN/END, Next: Empty, Prev: Ranges, Up: Patterns
+
+`BEGIN' and `END' Special Patterns
+==================================
+
+ `BEGIN' and `END' are special patterns. They are not used to match
+input records. Rather, they are used for supplying start-up or
+clean-up information to your `awk' script. A `BEGIN' rule is executed,
+once, before the first input record has been read. An `END' rule is
+executed, once, after all the input has been read. For example:
+
+ awk 'BEGIN { print "Analysis of `foo'" }
+ /foo/ { ++foobar }
+ END { print "`foo' appears " foobar " times." }' BBS-list
+
+ This program finds the number of records in the input file `BBS-list'
+that contain the string `foo'. The `BEGIN' rule prints a title for the
+report. There is no need to use the `BEGIN' rule to initialize the
+counter `foobar' to zero, as `awk' does this for us automatically
+(*note Variables::.).
+
+ The second rule increments the variable `foobar' every time a record
+containing the pattern `foo' is read. The `END' rule prints the value
+of `foobar' at the end of the run.
+
+ The special patterns `BEGIN' and `END' cannot be used in ranges or
+with boolean operators (indeed, they cannot be used with any operators).
+
+ An `awk' program may have multiple `BEGIN' and/or `END' rules. They
+are executed in the order they appear, all the `BEGIN' rules at
+start-up and all the `END' rules at termination.
+
+ Multiple `BEGIN' and `END' sections are useful for writing library
+functions, since each library can have its own `BEGIN' or `END' rule to
+do its own initialization and/or cleanup. Note that the order in which
+library functions are named on the command line controls the order in
+which their `BEGIN' and `END' rules are executed. Therefore you have
+to be careful to write such rules in library files so that the order in
+which they are executed doesn't matter. *Note Invoking `awk': Command
+Line, for more information on using library functions.
+
+ If an `awk' program only has a `BEGIN' rule, and no other rules,
+then the program exits after the `BEGIN' rule has been run. (Older
+versions of `awk' used to keep reading and ignoring input until end of
+file was seen.) However, if an `END' rule exists as well, then the
+input will be read, even if there are no other rules in the program.
+This is necessary in case the `END' rule checks the `NR' variable.
+
+ `BEGIN' and `END' rules must have actions; there is no default
+action for these rules since there is no current record when they run.
+
+
+File: gawk.info, Node: Empty, Prev: BEGIN/END, Up: Patterns
+
+The Empty Pattern
+=================
+
+ An empty pattern is considered to match *every* input record. For
+example, the program:
+
+ awk '{ print $1 }' BBS-list
+
+prints the first field of every record.
+
diff --git a/gawk.info-4 b/gawk.info-4
new file mode 100644
index 00000000..100e1d25
--- /dev/null
+++ b/gawk.info-4
@@ -0,0 +1,1305 @@
+This is Info file gawk.info, produced by Makeinfo-1.54 from the input
+file gawk.texi.
+
+ This file documents `awk', a program that you can use to select
+particular records in a file and perform operations upon them.
+
+ This is Edition 0.15 of `The GAWK Manual',
+for the 2.15 version of the GNU implementation
+of AWK.
+
+ Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that
+the entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Foundation.
+
+
+File: gawk.info, Node: Actions, Next: Expressions, Prev: Patterns, Up: Top
+
+Overview of Actions
+*******************
+
+ An `awk' program or script consists of a series of rules and
+function definitions, interspersed. (Functions are described later.
+*Note User-defined Functions: User-defined.)
+
+ A rule contains a pattern and an action, either of which may be
+omitted. The purpose of the "action" is to tell `awk' what to do once
+a match for the pattern is found. Thus, the entire program looks
+somewhat like this:
+
+ [PATTERN] [{ ACTION }]
+ [PATTERN] [{ ACTION }]
+ ...
+ function NAME (ARGS) { ... }
+ ...
+
+ An action consists of one or more `awk' "statements", enclosed in
+curly braces (`{' and `}'). Each statement specifies one thing to be
+done. The statements are separated by newlines or semicolons.
+
+ The curly braces around an action must be used even if the action
+contains only one statement, or even if it contains no statements at
+all. However, if you omit the action entirely, omit the curly braces as
+well. (An omitted action is equivalent to `{ print $0 }'.)
+
+ Here are the kinds of statements supported in `awk':
+
+ * Expressions, which can call functions or assign values to variables
+ (*note Expressions as Action Statements: Expressions.). Executing
+ this kind of statement simply computes the value of the expression
+ and then ignores it. This is useful when the expression has side
+ effects (*note Assignment Expressions: Assignment Ops.).
+
+ * Control statements, which specify the control flow of `awk'
+ programs. The `awk' language gives you C-like constructs (`if',
+ `for', `while', and so on) as well as a few special ones (*note
+ Control Statements in Actions: Statements.).
+
+ * Compound statements, which consist of one or more statements
+ enclosed in curly braces. A compound statement is used in order
+ to put several statements together in the body of an `if',
+ `while', `do' or `for' statement.
+
+ * Input control, using the `getline' command (*note Explicit Input
+ with `getline': Getline.), and the `next' statement (*note The
+ `next' Statement: Next Statement.).
+
+ * Output statements, `print' and `printf'. *Note Printing Output:
+ Printing.
+
+ * Deletion statements, for deleting array elements. *Note The
+ `delete' Statement: Delete.
+
+
+File: gawk.info, Node: Expressions, Next: Statements, Prev: Actions, Up: Top
+
+Expressions as Action Statements
+********************************
+
+ Expressions are the basic building block of `awk' actions. An
+expression evaluates to a value, which you can print, test, store in a
+variable or pass to a function. But beyond that, an expression can
+assign a new value to a variable or a field, with an assignment
+operator.
+
+ An expression can serve as a statement on its own. Most other kinds
+of statements contain one or more expressions which specify data to be
+operated on. As in other languages, expressions in `awk' include
+variables, array references, constants, and function calls, as well as
+combinations of these with various operators.
+
+* Menu:
+
+* Constants:: String, numeric, and regexp constants.
+* Variables:: Variables give names to values for later use.
+* Arithmetic Ops:: Arithmetic operations (`+', `-', etc.)
+* Concatenation:: Concatenating strings.
+* Comparison Ops:: Comparison of numbers and strings
+ with `<', etc.
+* Boolean Ops:: Combining comparison expressions
+ using boolean operators
+ `||' ("or"), `&&' ("and") and `!' ("not").
+
+* Assignment Ops:: Changing the value of a variable or a field.
+* Increment Ops:: Incrementing the numeric value of a variable.
+
+* Conversion:: The conversion of strings to numbers
+ and vice versa.
+* Values:: The whole truth about numbers and strings.
+* Conditional Exp:: Conditional expressions select
+ between two subexpressions under control
+ of a third subexpression.
+* Function Calls:: A function call is an expression.
+* Precedence:: How various operators nest.
+
+
+File: gawk.info, Node: Constants, Next: Variables, Prev: Expressions, Up: Expressions
+
+Constant Expressions
+====================
+
+ The simplest type of expression is the "constant", which always has
+the same value. There are three types of constants: numeric constants,
+string constants, and regular expression constants.
+
+ A "numeric constant" stands for a number. This number can be an
+integer, a decimal fraction, or a number in scientific (exponential)
+notation. Note that all numeric values are represented within `awk' in
+double-precision floating point. Here are some examples of numeric
+constants, which all have the same value:
+
+ 105
+ 1.05e+2
+ 1050e-1
+
+ A string constant consists of a sequence of characters enclosed in
+double-quote marks. For example:
+
+ "parrot"
+
+represents the string whose contents are `parrot'. Strings in `gawk'
+can be of any length and they can contain all the possible 8-bit ASCII
+characters including ASCII NUL. Other `awk' implementations may have
+difficulty with some character codes.
+
+ Some characters cannot be included literally in a string constant.
+You represent them instead with "escape sequences", which are character
+sequences beginning with a backslash (`\').
+
+ One use of an escape sequence is to include a double-quote character
+in a string constant. Since a plain double-quote would end the string,
+you must use `\"' to represent a single double-quote character as a
+part of the string. The backslash character itself is another
+character that cannot be included normally; you write `\\' to put one
+backslash in the string. Thus, the string whose contents are the two
+characters `"\' must be written `"\"\\"'.
+
+ Another use of backslash is to represent unprintable characters such
+as newline. While there is nothing to stop you from writing most of
+these characters directly in a string constant, they may look ugly.
+
+ Here is a table of all the escape sequences used in `awk':
+
+`\\'
+ Represents a literal backslash, `\'.
+
+`\a'
+ Represents the "alert" character, control-g, ASCII code 7.
+
+`\b'
+ Represents a backspace, control-h, ASCII code 8.
+
+`\f'
+ Represents a formfeed, control-l, ASCII code 12.
+
+`\n'
+ Represents a newline, control-j, ASCII code 10.
+
+`\r'
+ Represents a carriage return, control-m, ASCII code 13.
+
+`\t'
+ Represents a horizontal tab, control-i, ASCII code 9.
+
+`\v'
+ Represents a vertical tab, control-k, ASCII code 11.
+
+`\NNN'
+ Represents the octal value NNN, where NNN are one to three digits
+ between 0 and 7. For example, the code for the ASCII ESC (escape)
+ character is `\033'.
+
+`\xHH...'
+ Represents the hexadecimal value HH, where HH are hexadecimal
+ digits (`0' through `9' and either `A' through `F' or `a' through
+ `f'). Like the same construct in ANSI C, the escape sequence
+ continues until the first non-hexadecimal digit is seen. However,
+ using more than two hexadecimal digits produces undefined results.
+ (The `\x' escape sequence is not allowed in POSIX `awk'.)
+
+ A "constant regexp" is a regular expression description enclosed in
+slashes, such as `/^beginning and end$/'. Most regexps used in `awk'
+programs are constant, but the `~' and `!~' operators can also match
+computed or "dynamic" regexps (*note How to Use Regular Expressions:
+Regexp Usage.).
+
+ Constant regexps may be used like simple expressions. When a
+constant regexp is not on the right hand side of the `~' or `!~'
+operators, it has the same meaning as if it appeared in a pattern, i.e.
+`($0 ~ /foo/)' (*note Expressions as Patterns: Expression Patterns.).
+This means that the two code segments,
+
+ if ($0 ~ /barfly/ || $0 ~ /camelot/)
+ print "found"
+
+and
+
+ if (/barfly/ || /camelot/)
+ print "found"
+
+are exactly equivalent. One rather bizarre consequence of this rule is
+that the following boolean expression is legal, but does not do what
+the user intended:
+
+ if (/foo/ ~ $1) print "found foo"
+
+ This code is "obviously" testing `$1' for a match against the regexp
+`/foo/'. But in fact, the expression `(/foo/ ~ $1)' actually means
+`(($0 ~ /foo/) ~ $1)'. In other words, first match the input record
+against the regexp `/foo/'. The result will be either a 0 or a 1,
+depending upon the success or failure of the match. Then match that
+result against the first field in the record.
+
+ Since it is unlikely that you would ever really wish to make this
+kind of test, `gawk' will issue a warning when it sees this construct in
+a program.
+
+ Another consequence of this rule is that the assignment statement
+
+ matches = /foo/
+
+will assign either 0 or 1 to the variable `matches', depending upon the
+contents of the current input record.
+
+ Constant regular expressions are also used as the first argument for
+the `sub' and `gsub' functions (*note Built-in Functions for String
+Manipulation: String Functions.).
+
+ This feature of the language was never well documented until the
+POSIX specification.
+
+ You may be wondering, when is
+
+ $1 ~ /foo/ { ... }
+
+preferable to
+
+ $1 ~ "foo" { ... }
+
+ Since the right-hand sides of both `~' operators are constants, it
+is more efficient to use the `/foo/' form: `awk' can note that you have
+supplied a regexp and store it internally in a form that makes pattern
+matching more efficient. In the second form, `awk' must first convert
+the string into this internal form, and then perform the pattern
+matching. The first form is also better style; it shows clearly that
+you intend a regexp match.
+
+
+File: gawk.info, Node: Variables, Next: Arithmetic Ops, Prev: Constants, Up: Expressions
+
+Variables
+=========
+
+ Variables let you give names to values and refer to them later. You
+have already seen variables in many of the examples. The name of a
+variable must be a sequence of letters, digits and underscores, but it
+may not begin with a digit. Case is significant in variable names; `a'
+and `A' are distinct variables.
+
+ A variable name is a valid expression by itself; it represents the
+variable's current value. Variables are given new values with
+"assignment operators" and "increment operators". *Note Assignment
+Expressions: Assignment Ops.
+
+ A few variables have special built-in meanings, such as `FS', the
+field separator, and `NF', the number of fields in the current input
+record. *Note Built-in Variables::, for a list of them. These
+built-in variables can be used and assigned just like all other
+variables, but their values are also used or changed automatically by
+`awk'. Each built-in variable's name is made entirely of upper case
+letters.
+
+ Variables in `awk' can be assigned either numeric or string values.
+By default, variables are initialized to the null string, which is
+effectively zero if converted to a number. There is no need to
+"initialize" each variable explicitly in `awk', the way you would in C
+or most other traditional languages.
+
+* Menu:
+
+* Assignment Options:: Setting variables on the command line
+ and a summary of command line syntax.
+ This is an advanced method of input.
+
+
+File: gawk.info, Node: Assignment Options, Prev: Variables, Up: Variables
+
+Assigning Variables on the Command Line
+---------------------------------------
+
+ You can set any `awk' variable by including a "variable assignment"
+among the arguments on the command line when you invoke `awk' (*note
+Invoking `awk': Command Line.). Such an assignment has this form:
+
+ VARIABLE=TEXT
+
+With it, you can set a variable either at the beginning of the `awk'
+run or in between input files.
+
+ If you precede the assignment with the `-v' option, like this:
+
+ -v VARIABLE=TEXT
+
+then the variable is set at the very beginning, before even the `BEGIN'
+rules are run. The `-v' option and its assignment must precede all the
+file name arguments, as well as the program text.
+
+ Otherwise, the variable assignment is performed at a time determined
+by its position among the input file arguments: after the processing of
+the preceding input file argument. For example:
+
+ awk '{ print $n }' n=4 inventory-shipped n=2 BBS-list
+
+prints the value of field number `n' for all input records. Before the
+first file is read, the command line sets the variable `n' equal to 4.
+This causes the fourth field to be printed in lines from the file
+`inventory-shipped'. After the first file has finished, but before the
+second file is started, `n' is set to 2, so that the second field is
+printed in lines from `BBS-list'.
+
+ Command line arguments are made available for explicit examination by
+the `awk' program in an array named `ARGV' (*note Built-in
+Variables::.).
+
+ `awk' processes the values of command line assignments for escape
+sequences (*note Constant Expressions: Constants.).
+
+
+File: gawk.info, Node: Arithmetic Ops, Next: Concatenation, Prev: Variables, Up: Expressions
+
+Arithmetic Operators
+====================
+
+ The `awk' language uses the common arithmetic operators when
+evaluating expressions. All of these arithmetic operators follow normal
+precedence rules, and work as you would expect them to. This example
+divides field three by field four, adds field two, stores the result
+into field one, and prints the resulting altered input record:
+
+ awk '{ $1 = $2 + $3 / $4; print }' inventory-shipped
+
+ The arithmetic operators in `awk' are:
+
+`X + Y'
+ Addition.
+
+`X - Y'
+ Subtraction.
+
+`- X'
+ Negation.
+
+`+ X'
+ Unary plus. No real effect on the expression.
+
+`X * Y'
+ Multiplication.
+
+`X / Y'
+ Division. Since all numbers in `awk' are double-precision
+ floating point, the result is not rounded to an integer: `3 / 4'
+ has the value 0.75.
+
+`X % Y'
+ Remainder. The quotient is rounded toward zero to an integer,
+ multiplied by Y and this result is subtracted from X. This
+ operation is sometimes known as "trunc-mod." The following
+ relation always holds:
+
+ b * int(a / b) + (a % b) == a
+
+ One possibly undesirable effect of this definition of remainder is
+ that `X % Y' is negative if X is negative. Thus,
+
+ -17 % 8 = -1
+
+ In other `awk' implementations, the signedness of the remainder
+ may be machine dependent.
+
+`X ^ Y'
+`X ** Y'
+ Exponentiation: X raised to the Y power. `2 ^ 3' has the value 8.
+ The character sequence `**' is equivalent to `^'. (The POSIX
+ standard only specifies the use of `^' for exponentiation.)
+
+
+File: gawk.info, Node: Concatenation, Next: Comparison Ops, Prev: Arithmetic Ops, Up: Expressions
+
+String Concatenation
+====================
+
+ There is only one string operation: concatenation. It does not have
+a specific operator to represent it. Instead, concatenation is
+performed by writing expressions next to one another, with no operator.
+For example:
+
+ awk '{ print "Field number one: " $1 }' BBS-list
+
+produces, for the first record in `BBS-list':
+
+ Field number one: aardvark
+
+ Without the space in the string constant after the `:', the line
+would run together. For example:
+
+ awk '{ print "Field number one:" $1 }' BBS-list
+
+produces, for the first record in `BBS-list':
+
+ Field number one:aardvark
+
+ Since string concatenation does not have an explicit operator, it is
+often necessary to insure that it happens where you want it to by
+enclosing the items to be concatenated in parentheses. For example, the
+following code fragment does not concatenate `file' and `name' as you
+might expect:
+
+ file = "file"
+ name = "name"
+ print "something meaningful" > file name
+
+It is necessary to use the following:
+
+ print "something meaningful" > (file name)
+
+ We recommend you use parentheses around concatenation in all but the
+most common contexts (such as in the right-hand operand of `=').
+
+
+File: gawk.info, Node: Comparison Ops, Next: Boolean Ops, Prev: Concatenation, Up: Expressions
+
+Comparison Expressions
+======================
+
+ "Comparison expressions" compare strings or numbers for
+relationships such as equality. They are written using "relational
+operators", which are a superset of those in C. Here is a table of
+them:
+
+`X < Y'
+ True if X is less than Y.
+
+`X <= Y'
+ True if X is less than or equal to Y.
+
+`X > Y'
+ True if X is greater than Y.
+
+`X >= Y'
+ True if X is greater than or equal to Y.
+
+`X == Y'
+ True if X is equal to Y.
+
+`X != Y'
+ True if X is not equal to Y.
+
+`X ~ Y'
+ True if the string X matches the regexp denoted by Y.
+
+`X !~ Y'
+ True if the string X does not match the regexp denoted by Y.
+
+`SUBSCRIPT in ARRAY'
+ True if array ARRAY has an element with the subscript SUBSCRIPT.
+
+ Comparison expressions have the value 1 if true and 0 if false.
+
+ The rules `gawk' uses for performing comparisons are based on those
+in draft 11.2 of the POSIX standard. The POSIX standard introduced the
+concept of a "numeric string", which is simply a string that looks like
+a number, for example, `" +2"'.
+
+ When performing a relational operation, `gawk' considers the type of
+an operand to be the type it received on its last *assignment*, rather
+than the type of its last *use* (*note Numeric and String Values:
+Values.). This type is *unknown* when the operand is from an
+"external" source: field variables, command line arguments, array
+elements resulting from a `split' operation, and the value of an
+`ENVIRON' element. In this case only, if the operand is a numeric
+string, then it is considered to be of both string type and numeric
+type. If at least one operand of a comparison is of string type only,
+then a string comparison is performed. Any numeric operand will be
+converted to a string using the value of `CONVFMT' (*note Conversion of
+Strings and Numbers: Conversion.). If one operand of a comparison is
+numeric, and the other operand is either numeric or both numeric and
+string, then `gawk' does a numeric comparison. If both operands have
+both types, then the comparison is numeric. Strings are compared by
+comparing the first character of each, then the second character of
+each, and so on. Thus `"10"' is less than `"9"'. If there are two
+strings where one is a prefix of the other, the shorter string is less
+than the longer one. Thus `"abc"' is less than `"abcd"'.
+
+ Here are some sample expressions, how `gawk' compares them, and what
+the result of the comparison is.
+
+`1.5 <= 2.0'
+ numeric comparison (true)
+
+`"abc" >= "xyz"'
+ string comparison (false)
+
+`1.5 != " +2"'
+ string comparison (true)
+
+`"1e2" < "3"'
+ string comparison (true)
+
+`a = 2; b = "2"'
+`a == b'
+ string comparison (true)
+
+ echo 1e2 3 | awk '{ print ($1 < $2) ? "true" : "false" }'
+
+prints `false' since both `$1' and `$2' are numeric strings and thus
+have both string and numeric types, thus dictating a numeric comparison.
+
+ The purpose of the comparison rules and the use of numeric strings is
+to attempt to produce the behavior that is "least surprising," while
+still "doing the right thing."
+
+ String comparisons and regular expression comparisons are very
+different. For example,
+
+ $1 == "foo"
+
+has the value of 1, or is true, if the first field of the current input
+record is precisely `foo'. By contrast,
+
+ $1 ~ /foo/
+
+has the value 1 if the first field contains `foo', such as `foobar'.
+
+ The right hand operand of the `~' and `!~' operators may be either a
+constant regexp (`/.../'), or it may be an ordinary expression, in
+which case the value of the expression as a string is a dynamic regexp
+(*note How to Use Regular Expressions: Regexp Usage.).
+
+ In very recent implementations of `awk', a constant regular
+expression in slashes by itself is also an expression. The regexp
+`/REGEXP/' is an abbreviation for this comparison expression:
+
+ $0 ~ /REGEXP/
+
+ In some contexts it may be necessary to write parentheses around the
+regexp to avoid confusing the `gawk' parser. For example, `(/x/ - /y/)
+> threshold' is not allowed, but `((/x/) - (/y/)) > threshold' parses
+properly.
+
+ One special place where `/foo/' is *not* an abbreviation for `$0 ~
+/foo/' is when it is the right-hand operand of `~' or `!~'! *Note
+Constant Expressions: Constants, where this is discussed in more detail.
+
+
+File: gawk.info, Node: Boolean Ops, Next: Assignment Ops, Prev: Comparison Ops, Up: Expressions
+
+Boolean Expressions
+===================
+
+ A "boolean expression" is a combination of comparison expressions or
+matching expressions, using the boolean operators "or" (`||'), "and"
+(`&&'), and "not" (`!'), along with parentheses to control nesting.
+The truth of the boolean expression is computed by combining the truth
+values of the component expressions.
+
+ Boolean expressions can be used wherever comparison and matching
+expressions can be used. They can be used in `if', `while' `do' and
+`for' statements. They have numeric values (1 if true, 0 if false),
+which come into play if the result of the boolean expression is stored
+in a variable, or used in arithmetic.
+
+ In addition, every boolean expression is also a valid boolean
+pattern, so you can use it as a pattern to control the execution of
+rules.
+
+ Here are descriptions of the three boolean operators, with an
+example of each. It may be instructive to compare these examples with
+the analogous examples of boolean patterns (*note Boolean Operators and
+Patterns: Boolean Patterns.), which use the same boolean operators in
+patterns instead of expressions.
+
+`BOOLEAN1 && BOOLEAN2'
+ True if both BOOLEAN1 and BOOLEAN2 are true. For example, the
+ following statement prints the current input record if it contains
+ both `2400' and `foo'.
+
+ if ($0 ~ /2400/ && $0 ~ /foo/) print
+
+ The subexpression BOOLEAN2 is evaluated only if BOOLEAN1 is true.
+ This can make a difference when BOOLEAN2 contains expressions that
+ have side effects: in the case of `$0 ~ /foo/ && ($2 == bar++)',
+ the variable `bar' is not incremented if there is no `foo' in the
+ record.
+
+`BOOLEAN1 || BOOLEAN2'
+ True if at least one of BOOLEAN1 or BOOLEAN2 is true. For
+ example, the following command prints all records in the input
+ file `BBS-list' that contain *either* `2400' or `foo', or both.
+
+ awk '{ if ($0 ~ /2400/ || $0 ~ /foo/) print }' BBS-list
+
+ The subexpression BOOLEAN2 is evaluated only if BOOLEAN1 is false.
+ This can make a difference when BOOLEAN2 contains expressions
+ that have side effects.
+
+`!BOOLEAN'
+ True if BOOLEAN is false. For example, the following program
+ prints all records in the input file `BBS-list' that do *not*
+ contain the string `foo'.
+
+ awk '{ if (! ($0 ~ /foo/)) print }' BBS-list
+
+
+File: gawk.info, Node: Assignment Ops, Next: Increment Ops, Prev: Boolean Ops, Up: Expressions
+
+Assignment Expressions
+======================
+
+ An "assignment" is an expression that stores a new value into a
+variable. For example, let's assign the value 1 to the variable `z':
+
+ z = 1
+
+ After this expression is executed, the variable `z' has the value 1.
+Whatever old value `z' had before the assignment is forgotten.
+
+ Assignments can store string values also. For example, this would
+store the value `"this food is good"' in the variable `message':
+
+ thing = "food"
+ predicate = "good"
+ message = "this " thing " is " predicate
+
+(This also illustrates concatenation of strings.)
+
+ The `=' sign is called an "assignment operator". It is the simplest
+assignment operator because the value of the right-hand operand is
+stored unchanged.
+
+ Most operators (addition, concatenation, and so on) have no effect
+except to compute a value. If you ignore the value, you might as well
+not use the operator. An assignment operator is different; it does
+produce a value, but even if you ignore the value, the assignment still
+makes itself felt through the alteration of the variable. We call this
+a "side effect".
+
+ The left-hand operand of an assignment need not be a variable (*note
+Variables::.); it can also be a field (*note Changing the Contents of a
+Field: Changing Fields.) or an array element (*note Arrays in `awk':
+Arrays.). These are all called "lvalues", which means they can appear
+on the left-hand side of an assignment operator. The right-hand
+operand may be any expression; it produces the new value which the
+assignment stores in the specified variable, field or array element.
+
+ It is important to note that variables do *not* have permanent types.
+The type of a variable is simply the type of whatever value it happens
+to hold at the moment. In the following program fragment, the variable
+`foo' has a numeric value at first, and a string value later on:
+
+ foo = 1
+ print foo
+ foo = "bar"
+ print foo
+
+When the second assignment gives `foo' a string value, the fact that it
+previously had a numeric value is forgotten.
+
+ An assignment is an expression, so it has a value: the same value
+that is assigned. Thus, `z = 1' as an expression has the value 1. One
+consequence of this is that you can write multiple assignments together:
+
+ x = y = z = 0
+
+stores the value 0 in all three variables. It does this because the
+value of `z = 0', which is 0, is stored into `y', and then the value of
+`y = z = 0', which is 0, is stored into `x'.
+
+ You can use an assignment anywhere an expression is called for. For
+example, it is valid to write `x != (y = 1)' to set `y' to 1 and then
+test whether `x' equals 1. But this style tends to make programs hard
+to read; except in a one-shot program, you should rewrite it to get rid
+of such nesting of assignments. This is never very hard.
+
+ Aside from `=', there are several other assignment operators that do
+arithmetic with the old value of the variable. For example, the
+operator `+=' computes a new value by adding the right-hand value to
+the old value of the variable. Thus, the following assignment adds 5
+to the value of `foo':
+
+ foo += 5
+
+This is precisely equivalent to the following:
+
+ foo = foo + 5
+
+Use whichever one makes the meaning of your program clearer.
+
+ Here is a table of the arithmetic assignment operators. In each
+case, the right-hand operand is an expression whose value is converted
+to a number.
+
+`LVALUE += INCREMENT'
+ Adds INCREMENT to the value of LVALUE to make the new value of
+ LVALUE.
+
+`LVALUE -= DECREMENT'
+ Subtracts DECREMENT from the value of LVALUE.
+
+`LVALUE *= COEFFICIENT'
+ Multiplies the value of LVALUE by COEFFICIENT.
+
+`LVALUE /= QUOTIENT'
+ Divides the value of LVALUE by QUOTIENT.
+
+`LVALUE %= MODULUS'
+ Sets LVALUE to its remainder by MODULUS.
+
+`LVALUE ^= POWER'
+`LVALUE **= POWER'
+ Raises LVALUE to the power POWER. (Only the `^=' operator is
+ specified by POSIX.)
+
+
+File: gawk.info, Node: Increment Ops, Next: Conversion, Prev: Assignment Ops, Up: Expressions
+
+Increment Operators
+===================
+
+ "Increment operators" increase or decrease the value of a variable
+by 1. You could do the same thing with an assignment operator, so the
+increment operators add no power to the `awk' language; but they are
+convenient abbreviations for something very common.
+
+ The operator to add 1 is written `++'. It can be used to increment
+a variable either before or after taking its value.
+
+ To pre-increment a variable V, write `++V'. This adds 1 to the
+value of V and that new value is also the value of this expression.
+The assignment expression `V += 1' is completely equivalent.
+
+ Writing the `++' after the variable specifies post-increment. This
+increments the variable value just the same; the difference is that the
+value of the increment expression itself is the variable's *old* value.
+Thus, if `foo' has the value 4, then the expression `foo++' has the
+value 4, but it changes the value of `foo' to 5.
+
+ The post-increment `foo++' is nearly equivalent to writing `(foo +=
+1) - 1'. It is not perfectly equivalent because all numbers in `awk'
+are floating point: in floating point, `foo + 1 - 1' does not
+necessarily equal `foo'. But the difference is minute as long as you
+stick to numbers that are fairly small (less than a trillion).
+
+ Any lvalue can be incremented. Fields and array elements are
+incremented just like variables. (Use `$(i++)' when you wish to do a
+field reference and a variable increment at the same time. The
+parentheses are necessary because of the precedence of the field
+reference operator, `$'.)
+
+ The decrement operator `--' works just like `++' except that it
+subtracts 1 instead of adding. Like `++', it can be used before the
+lvalue to pre-decrement or after it to post-decrement.
+
+ Here is a summary of increment and decrement expressions.
+
+`++LVALUE'
+ This expression increments LVALUE and the new value becomes the
+ value of this expression.
+
+`LVALUE++'
+ This expression causes the contents of LVALUE to be incremented.
+ The value of the expression is the *old* value of LVALUE.
+
+`--LVALUE'
+ Like `++LVALUE', but instead of adding, it subtracts. It
+ decrements LVALUE and delivers the value that results.
+
+`LVALUE--'
+ Like `LVALUE++', but instead of adding, it subtracts. It
+ decrements LVALUE. The value of the expression is the *old* value
+ of LVALUE.
+
+
+File: gawk.info, Node: Conversion, Next: Values, Prev: Increment Ops, Up: Expressions
+
+Conversion of Strings and Numbers
+=================================
+
+ Strings are converted to numbers, and numbers to strings, if the
+context of the `awk' program demands it. For example, if the value of
+either `foo' or `bar' in the expression `foo + bar' happens to be a
+string, it is converted to a number before the addition is performed.
+If numeric values appear in string concatenation, they are converted to
+strings. Consider this:
+
+ two = 2; three = 3
+ print (two three) + 4
+
+This eventually prints the (numeric) value 27. The numeric values of
+the variables `two' and `three' are converted to strings and
+concatenated together, and the resulting string is converted back to the
+number 23, to which 4 is then added.
+
+ If, for some reason, you need to force a number to be converted to a
+string, concatenate the null string with that number. To force a string
+to be converted to a number, add zero to that string.
+
+ A string is converted to a number by interpreting a numeric prefix
+of the string as numerals: `"2.5"' converts to 2.5, `"1e3"' converts to
+1000, and `"25fix"' has a numeric value of 25. Strings that can't be
+interpreted as valid numbers are converted to zero.
+
+ The exact manner in which numbers are converted into strings is
+controlled by the `awk' built-in variable `CONVFMT' (*note Built-in
+Variables::.). Numbers are converted using a special version of the
+`sprintf' function (*note Built-in Functions: Built-in.) with `CONVFMT'
+as the format specifier.
+
+ `CONVFMT''s default value is `"%.6g"', which prints a value with at
+least six significant digits. For some applications you will want to
+change it to specify more precision. Double precision on most modern
+machines gives you 16 or 17 decimal digits of precision.
+
+ Strange results can happen if you set `CONVFMT' to a string that
+doesn't tell `sprintf' how to format floating point numbers in a useful
+way. For example, if you forget the `%' in the format, all numbers
+will be converted to the same constant string.
+
+ As a special case, if a number is an integer, then the result of
+converting it to a string is *always* an integer, no matter what the
+value of `CONVFMT' may be. Given the following code fragment:
+
+ CONVFMT = "%2.2f"
+ a = 12
+ b = a ""
+
+`b' has the value `"12"', not `"12.00"'.
+
+ Prior to the POSIX standard, `awk' specified that the value of
+`OFMT' was used for converting numbers to strings. `OFMT' specifies
+the output format to use when printing numbers with `print'. `CONVFMT'
+was introduced in order to separate the semantics of conversions from
+the semantics of printing. Both `CONVFMT' and `OFMT' have the same
+default value: `"%.6g"'. In the vast majority of cases, old `awk'
+programs will not change their behavior. However, this use of `OFMT'
+is something to keep in mind if you must port your program to other
+implementations of `awk'; we recommend that instead of changing your
+programs, you just port `gawk' itself!
+
+
+File: gawk.info, Node: Values, Next: Conditional Exp, Prev: Conversion, Up: Expressions
+
+Numeric and String Values
+=========================
+
+ Through most of this manual, we present `awk' values (such as
+constants, fields, or variables) as *either* numbers *or* strings.
+This is a convenient way to think about them, since typically they are
+used in only one way, or the other.
+
+ In truth though, `awk' values can be *both* string and numeric, at
+the same time. Internally, `awk' represents values with a string, a
+(floating point) number, and an indication that one, the other, or both
+representations of the value are valid.
+
+ Keeping track of both kinds of values is important for execution
+efficiency: a variable can acquire a string value the first time it is
+used as a string, and then that string value can be used until the
+variable is assigned a new value. Thus, if a variable with only a
+numeric value is used in several concatenations in a row, it only has
+to be given a string representation once. The numeric value remains
+valid, so that no conversion back to a number is necessary if the
+variable is later used in an arithmetic expression.
+
+ Tracking both kinds of values is also important for precise numerical
+calculations. Consider the following:
+
+ a = 123.321
+ CONVFMT = "%3.1f"
+ b = a " is a number"
+ c = a + 1.654
+
+The variable `a' receives a string value in the concatenation and
+assignment to `b'. The string value of `a' is `"123.3"'. If the
+numeric value was lost when it was converted to a string, then the
+numeric use of `a' in the last statement would lose information. `c'
+would be assigned the value 124.954 instead of 124.975. Such errors
+accumulate rapidly, and very adversely affect numeric computations.
+
+ Once a numeric value acquires a corresponding string value, it stays
+valid until a new assignment is made. If `CONVFMT' (*note Conversion
+of Strings and Numbers: Conversion.) changes in the meantime, the old
+string value will still be used. For example:
+
+ BEGIN {
+ CONVFMT = "%2.2f"
+ a = 123.456
+ b = a "" # force `a' to have string value too
+ printf "a = %s\n", a
+ CONVFMT = "%.6g"
+ printf "a = %s\n", a
+ a += 0 # make `a' numeric only again
+ printf "a = %s\n", a # use `a' as string
+ }
+
+This program prints `a = 123.46' twice, and then prints `a = 123.456'.
+
+ *Note Conversion of Strings and Numbers: Conversion, for the rules
+that specify how string values are made from numeric values.
+
+
+File: gawk.info, Node: Conditional Exp, Next: Function Calls, Prev: Values, Up: Expressions
+
+Conditional Expressions
+=======================
+
+ A "conditional expression" is a special kind of expression with
+three operands. It allows you to use one expression's value to select
+one of two other expressions.
+
+ The conditional expression looks the same as in the C language:
+
+ SELECTOR ? IF-TRUE-EXP : IF-FALSE-EXP
+
+There are three subexpressions. The first, SELECTOR, is always
+computed first. If it is "true" (not zero and not null) then
+IF-TRUE-EXP is computed next and its value becomes the value of the
+whole expression. Otherwise, IF-FALSE-EXP is computed next and its
+value becomes the value of the whole expression.
+
+ For example, this expression produces the absolute value of `x':
+
+ x > 0 ? x : -x
+
+ Each time the conditional expression is computed, exactly one of
+IF-TRUE-EXP and IF-FALSE-EXP is computed; the other is ignored. This
+is important when the expressions contain side effects. For example,
+this conditional expression examines element `i' of either array `a' or
+array `b', and increments `i'.
+
+ x == y ? a[i++] : b[i++]
+
+This is guaranteed to increment `i' exactly once, because each time one
+or the other of the two increment expressions is executed, and the
+other is not.
+
+
+File: gawk.info, Node: Function Calls, Next: Precedence, Prev: Conditional Exp, Up: Expressions
+
+Function Calls
+==============
+
+ A "function" is a name for a particular calculation. Because it has
+a name, you can ask for it by name at any point in the program. For
+example, the function `sqrt' computes the square root of a number.
+
+ A fixed set of functions are "built-in", which means they are
+available in every `awk' program. The `sqrt' function is one of these.
+*Note Built-in Functions: Built-in, for a list of built-in functions
+and their descriptions. In addition, you can define your own functions
+in the program for use elsewhere in the same program. *Note
+User-defined Functions: User-defined, for how to do this.
+
+ The way to use a function is with a "function call" expression,
+which consists of the function name followed by a list of "arguments"
+in parentheses. The arguments are expressions which give the raw
+materials for the calculation that the function will do. When there is
+more than one argument, they are separated by commas. If there are no
+arguments, write just `()' after the function name. Here are some
+examples:
+
+ sqrt(x^2 + y^2) # One argument
+ atan2(y, x) # Two arguments
+ rand() # No arguments
+
+ *Do not put any space between the function name and the
+open-parenthesis!* A user-defined function name looks just like the
+name of a variable, and space would make the expression look like
+concatenation of a variable with an expression inside parentheses.
+Space before the parenthesis is harmless with built-in functions, but
+it is best not to get into the habit of using space to avoid mistakes
+with user-defined functions.
+
+ Each function expects a particular number of arguments. For
+example, the `sqrt' function must be called with a single argument, the
+number to take the square root of:
+
+ sqrt(ARGUMENT)
+
+ Some of the built-in functions allow you to omit the final argument.
+If you do so, they use a reasonable default. *Note Built-in Functions:
+Built-in, for full details. If arguments are omitted in calls to
+user-defined functions, then those arguments are treated as local
+variables, initialized to the null string (*note User-defined
+Functions: User-defined.).
+
+ Like every other expression, the function call has a value, which is
+computed by the function based on the arguments you give it. In this
+example, the value of `sqrt(ARGUMENT)' is the square root of the
+argument. A function can also have side effects, such as assigning the
+values of certain variables or doing I/O.
+
+ Here is a command to read numbers, one number per line, and print the
+square root of each one:
+
+ awk '{ print "The square root of", $1, "is", sqrt($1) }'
+
+
+File: gawk.info, Node: Precedence, Prev: Function Calls, Up: Expressions
+
+Operator Precedence (How Operators Nest)
+========================================
+
+ "Operator precedence" determines how operators are grouped, when
+different operators appear close by in one expression. For example,
+`*' has higher precedence than `+'; thus, `a + b * c' means to multiply
+`b' and `c', and then add `a' to the product (i.e., `a + (b * c)').
+
+ You can overrule the precedence of the operators by using
+parentheses. You can think of the precedence rules as saying where the
+parentheses are assumed if you do not write parentheses yourself. In
+fact, it is wise to always use parentheses whenever you have an unusual
+combination of operators, because other people who read the program may
+not remember what the precedence is in this case. You might forget,
+too; then you could make a mistake. Explicit parentheses will help
+prevent any such mistake.
+
+ When operators of equal precedence are used together, the leftmost
+operator groups first, except for the assignment, conditional and
+exponentiation operators, which group in the opposite order. Thus, `a
+- b + c' groups as `(a - b) + c'; `a = b = c' groups as `a = (b = c)'.
+
+ The precedence of prefix unary operators does not matter as long as
+only unary operators are involved, because there is only one way to
+parse them--innermost first. Thus, `$++i' means `$(++i)' and `++$x'
+means `++($x)'. However, when another operator follows the operand,
+then the precedence of the unary operators can matter. Thus, `$x^2'
+means `($x)^2', but `-x^2' means `-(x^2)', because `-' has lower
+precedence than `^' while `$' has higher precedence.
+
+ Here is a table of the operators of `awk', in order of increasing
+precedence:
+
+assignment
+ `=', `+=', `-=', `*=', `/=', `%=', `^=', `**='. These operators
+ group right-to-left. (The `**=' operator is not specified by
+ POSIX.)
+
+conditional
+ `?:'. This operator groups right-to-left.
+
+logical "or".
+ `||'.
+
+logical "and".
+ `&&'.
+
+array membership
+ `in'.
+
+matching
+ `~', `!~'.
+
+relational, and redirection
+ The relational operators and the redirections have the same
+ precedence level. Characters such as `>' serve both as
+ relationals and as redirections; the context distinguishes between
+ the two meanings.
+
+ The relational operators are `<', `<=', `==', `!=', `>=' and `>'.
+
+ The I/O redirection operators are `<', `>', `>>' and `|'.
+
+ Note that I/O redirection operators in `print' and `printf'
+ statements belong to the statement level, not to expressions. The
+ redirection does not produce an expression which could be the
+ operand of another operator. As a result, it does not make sense
+ to use a redirection operator near another operator of lower
+ precedence, without parentheses. Such combinations, for example
+ `print foo > a ? b : c', result in syntax errors.
+
+concatenation
+ No special token is used to indicate concatenation. The operands
+ are simply written side by side.
+
+add, subtract
+ `+', `-'.
+
+multiply, divide, mod
+ `*', `/', `%'.
+
+unary plus, minus, "not"
+ `+', `-', `!'.
+
+exponentiation
+ `^', `**'. These operators group right-to-left. (The `**'
+ operator is not specified by POSIX.)
+
+increment, decrement
+ `++', `--'.
+
+field
+ `$'.
+
+
+File: gawk.info, Node: Statements, Next: Arrays, Prev: Expressions, Up: Top
+
+Control Statements in Actions
+*****************************
+
+ "Control statements" such as `if', `while', and so on control the
+flow of execution in `awk' programs. Most of the control statements in
+`awk' are patterned on similar statements in C.
+
+ All the control statements start with special keywords such as `if'
+and `while', to distinguish them from simple expressions.
+
+ Many control statements contain other statements; for example, the
+`if' statement contains another statement which may or may not be
+executed. The contained statement is called the "body". If you want
+to include more than one statement in the body, group them into a
+single compound statement with curly braces, separating them with
+newlines or semicolons.
+
+* Menu:
+
+* If Statement:: Conditionally execute
+ some `awk' statements.
+* While Statement:: Loop until some condition is satisfied.
+* Do Statement:: Do specified action while looping until some
+ condition is satisfied.
+* For Statement:: Another looping statement, that provides
+ initialization and increment clauses.
+* Break Statement:: Immediately exit the innermost enclosing loop.
+* Continue Statement:: Skip to the end of the innermost
+ enclosing loop.
+* Next Statement:: Stop processing the current input record.
+* Next File Statement:: Stop processing the current file.
+* Exit Statement:: Stop execution of `awk'.
+
+
+File: gawk.info, Node: If Statement, Next: While Statement, Prev: Statements, Up: Statements
+
+The `if' Statement
+==================
+
+ The `if'-`else' statement is `awk''s decision-making statement. It
+looks like this:
+
+ if (CONDITION) THEN-BODY [else ELSE-BODY]
+
+CONDITION is an expression that controls what the rest of the statement
+will do. If CONDITION is true, THEN-BODY is executed; otherwise,
+ELSE-BODY is executed (assuming that the `else' clause is present).
+The `else' part of the statement is optional. The condition is
+considered false if its value is zero or the null string, and true
+otherwise.
+
+ Here is an example:
+
+ if (x % 2 == 0)
+ print "x is even"
+ else
+ print "x is odd"
+
+ In this example, if the expression `x % 2 == 0' is true (that is,
+the value of `x' is divisible by 2), then the first `print' statement
+is executed, otherwise the second `print' statement is performed.
+
+ If the `else' appears on the same line as THEN-BODY, and THEN-BODY
+is not a compound statement (i.e., not surrounded by curly braces),
+then a semicolon must separate THEN-BODY from `else'. To illustrate
+this, let's rewrite the previous example:
+
+ awk '{ if (x % 2 == 0) print "x is even"; else
+ print "x is odd" }'
+
+If you forget the `;', `awk' won't be able to parse the statement, and
+you will get a syntax error.
+
+ We would not actually write this example this way, because a human
+reader might fail to see the `else' if it were not the first thing on
+its line.
+
+
+File: gawk.info, Node: While Statement, Next: Do Statement, Prev: If Statement, Up: Statements
+
+The `while' Statement
+=====================
+
+ In programming, a "loop" means a part of a program that is (or at
+least can be) executed two or more times in succession.
+
+ The `while' statement is the simplest looping statement in `awk'.
+It repeatedly executes a statement as long as a condition is true. It
+looks like this:
+
+ while (CONDITION)
+ BODY
+
+Here BODY is a statement that we call the "body" of the loop, and
+CONDITION is an expression that controls how long the loop keeps
+running.
+
+ The first thing the `while' statement does is test CONDITION. If
+CONDITION is true, it executes the statement BODY. (CONDITION is true
+when the value is not zero and not a null string.) After BODY has been
+executed, CONDITION is tested again, and if it is still true, BODY is
+executed again. This process repeats until CONDITION is no longer
+true. If CONDITION is initially false, the body of the loop is never
+executed.
+
+ This example prints the first three fields of each record, one per
+line.
+
+ awk '{ i = 1
+ while (i <= 3) {
+ print $i
+ i++
+ }
+ }'
+
+Here the body of the loop is a compound statement enclosed in braces,
+containing two statements.
+
+ The loop works like this: first, the value of `i' is set to 1.
+Then, the `while' tests whether `i' is less than or equal to three.
+This is the case when `i' equals one, so the `i'-th field is printed.
+Then the `i++' increments the value of `i' and the loop repeats. The
+loop terminates when `i' reaches 4.
+
+ As you can see, a newline is not required between the condition and
+the body; but using one makes the program clearer unless the body is a
+compound statement or is very simple. The newline after the open-brace
+that begins the compound statement is not required either, but the
+program would be hard to read without it.
+
+
+File: gawk.info, Node: Do Statement, Next: For Statement, Prev: While Statement, Up: Statements
+
+The `do'-`while' Statement
+==========================
+
+ The `do' loop is a variation of the `while' looping statement. The
+`do' loop executes the BODY once, then repeats BODY as long as
+CONDITION is true. It looks like this:
+
+ do
+ BODY
+ while (CONDITION)
+
+ Even if CONDITION is false at the start, BODY is executed at least
+once (and only once, unless executing BODY makes CONDITION true).
+Contrast this with the corresponding `while' statement:
+
+ while (CONDITION)
+ BODY
+
+This statement does not execute BODY even once if CONDITION is false to
+begin with.
+
+ Here is an example of a `do' statement:
+
+ awk '{ i = 1
+ do {
+ print $0
+ i++
+ } while (i <= 10)
+ }'
+
+prints each input record ten times. It isn't a very realistic example,
+since in this case an ordinary `while' would do just as well. But this
+reflects actual experience; there is only occasionally a real use for a
+`do' statement.
+
diff --git a/gawk.info-5 b/gawk.info-5
new file mode 100644
index 00000000..3a786bb4
--- /dev/null
+++ b/gawk.info-5
@@ -0,0 +1,1256 @@
+This is Info file gawk.info, produced by Makeinfo-1.54 from the input
+file gawk.texi.
+
+ This file documents `awk', a program that you can use to select
+particular records in a file and perform operations upon them.
+
+ This is Edition 0.15 of `The GAWK Manual',
+for the 2.15 version of the GNU implementation
+of AWK.
+
+ Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that
+the entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Foundation.
+
+
+File: gawk.info, Node: For Statement, Next: Break Statement, Prev: Do Statement, Up: Statements
+
+The `for' Statement
+===================
+
+ The `for' statement makes it more convenient to count iterations of a
+loop. The general form of the `for' statement looks like this:
+
+ for (INITIALIZATION; CONDITION; INCREMENT)
+ BODY
+
+This statement starts by executing INITIALIZATION. Then, as long as
+CONDITION is true, it repeatedly executes BODY and then INCREMENT.
+Typically INITIALIZATION sets a variable to either zero or one,
+INCREMENT adds 1 to it, and CONDITION compares it against the desired
+number of iterations.
+
+ Here is an example of a `for' statement:
+
+ awk '{ for (i = 1; i <= 3; i++)
+ print $i
+ }'
+
+This prints the first three fields of each input record, one field per
+line.
+
+ In the `for' statement, BODY stands for any statement, but
+INITIALIZATION, CONDITION and INCREMENT are just expressions. You
+cannot set more than one variable in the INITIALIZATION part unless you
+use a multiple assignment statement such as `x = y = 0', which is
+possible only if all the initial values are equal. (But you can
+initialize additional variables by writing their assignments as
+separate statements preceding the `for' loop.)
+
+ The same is true of the INCREMENT part; to increment additional
+variables, you must write separate statements at the end of the loop.
+The C compound expression, using C's comma operator, would be useful in
+this context, but it is not supported in `awk'.
+
+ Most often, INCREMENT is an increment expression, as in the example
+above. But this is not required; it can be any expression whatever.
+For example, this statement prints all the powers of 2 between 1 and
+100:
+
+ for (i = 1; i <= 100; i *= 2)
+ print i
+
+ Any of the three expressions in the parentheses following the `for'
+may be omitted if there is nothing to be done there. Thus,
+`for (;x > 0;)' is equivalent to `while (x > 0)'. If the CONDITION is
+omitted, it is treated as TRUE, effectively yielding an "infinite loop"
+(i.e., a loop that will never terminate).
+
+ In most cases, a `for' loop is an abbreviation for a `while' loop,
+as shown here:
+
+ INITIALIZATION
+ while (CONDITION) {
+ BODY
+ INCREMENT
+ }
+
+The only exception is when the `continue' statement (*note The
+`continue' Statement: Continue Statement.) is used inside the loop;
+changing a `for' statement to a `while' statement in this way can
+change the effect of the `continue' statement inside the loop.
+
+ There is an alternate version of the `for' loop, for iterating over
+all the indices of an array:
+
+ for (i in array)
+ DO SOMETHING WITH array[i]
+
+*Note Arrays in `awk': Arrays, for more information on this version of
+the `for' loop.
+
+ The `awk' language has a `for' statement in addition to a `while'
+statement because often a `for' loop is both less work to type and more
+natural to think of. Counting the number of iterations is very common
+in loops. It can be easier to think of this counting as part of
+looping rather than as something to do inside the loop.
+
+ The next section has more complicated examples of `for' loops.
+
+
+File: gawk.info, Node: Break Statement, Next: Continue Statement, Prev: For Statement, Up: Statements
+
+The `break' Statement
+=====================
+
+ The `break' statement jumps out of the innermost `for', `while', or
+`do'-`while' loop that encloses it. The following example finds the
+smallest divisor of any integer, and also identifies prime numbers:
+
+ awk '# find smallest divisor of num
+ { num = $1
+ for (div = 2; div*div <= num; div++)
+ if (num % div == 0)
+ break
+ if (num % div == 0)
+ printf "Smallest divisor of %d is %d\n", num, div
+ else
+ printf "%d is prime\n", num }'
+
+ When the remainder is zero in the first `if' statement, `awk'
+immediately "breaks out" of the containing `for' loop. This means that
+`awk' proceeds immediately to the statement following the loop and
+continues processing. (This is very different from the `exit'
+statement which stops the entire `awk' program. *Note The `exit'
+Statement: Exit Statement.)
+
+ Here is another program equivalent to the previous one. It
+illustrates how the CONDITION of a `for' or `while' could just as well
+be replaced with a `break' inside an `if':
+
+ awk '# find smallest divisor of num
+ { num = $1
+ for (div = 2; ; div++) {
+ if (num % div == 0) {
+ printf "Smallest divisor of %d is %d\n", num, div
+ break
+ }
+ if (div*div > num) {
+ printf "%d is prime\n", num
+ break
+ }
+ }
+ }'
+
+
+File: gawk.info, Node: Continue Statement, Next: Next Statement, Prev: Break Statement, Up: Statements
+
+The `continue' Statement
+========================
+
+ The `continue' statement, like `break', is used only inside `for',
+`while', and `do'-`while' loops. It skips over the rest of the loop
+body, causing the next cycle around the loop to begin immediately.
+Contrast this with `break', which jumps out of the loop altogether.
+Here is an example:
+
+ # print names that don't contain the string "ignore"
+
+ # first, save the text of each line
+ { names[NR] = $0 }
+
+ # print what we're interested in
+ END {
+ for (x in names) {
+ if (names[x] ~ /ignore/)
+ continue
+ print names[x]
+ }
+ }
+
+ If one of the input records contains the string `ignore', this
+example skips the print statement for that record, and continues back to
+the first statement in the loop.
+
+ This is not a practical example of `continue', since it would be
+just as easy to write the loop like this:
+
+ for (x in names)
+ if (names[x] !~ /ignore/)
+ print names[x]
+
+ The `continue' statement in a `for' loop directs `awk' to skip the
+rest of the body of the loop, and resume execution with the
+increment-expression of the `for' statement. The following program
+illustrates this fact:
+
+ awk 'BEGIN {
+ for (x = 0; x <= 20; x++) {
+ if (x == 5)
+ continue
+ printf ("%d ", x)
+ }
+ print ""
+ }'
+
+This program prints all the numbers from 0 to 20, except for 5, for
+which the `printf' is skipped. Since the increment `x++' is not
+skipped, `x' does not remain stuck at 5. Contrast the `for' loop above
+with the `while' loop:
+
+ awk 'BEGIN {
+ x = 0
+ while (x <= 20) {
+ if (x == 5)
+ continue
+ printf ("%d ", x)
+ x++
+ }
+ print ""
+ }'
+
+This program loops forever once `x' gets to 5.
+
+ As described above, the `continue' statement has no meaning when
+used outside the body of a loop. However, although it was never
+documented, historical implementations of `awk' have treated the
+`continue' statement outside of a loop as if it were a `next' statement
+(*note The `next' Statement: Next Statement.). By default, `gawk'
+silently supports this usage. However, if `-W posix' has been
+specified on the command line (*note Invoking `awk': Command Line.), it
+will be treated as an error, since the POSIX standard specifies that
+`continue' should only be used inside the body of a loop.
+
+
+File: gawk.info, Node: Next Statement, Next: Next File Statement, Prev: Continue Statement, Up: Statements
+
+The `next' Statement
+====================
+
+ The `next' statement forces `awk' to immediately stop processing the
+current record and go on to the next record. This means that no
+further rules are executed for the current record. The rest of the
+current rule's action is not executed either.
+
+ Contrast this with the effect of the `getline' function (*note
+Explicit Input with `getline': Getline.). That too causes `awk' to
+read the next record immediately, but it does not alter the flow of
+control in any way. So the rest of the current action executes with a
+new input record.
+
+ At the highest level, `awk' program execution is a loop that reads
+an input record and then tests each rule's pattern against it. If you
+think of this loop as a `for' statement whose body contains the rules,
+then the `next' statement is analogous to a `continue' statement: it
+skips to the end of the body of this implicit loop, and executes the
+increment (which reads another record).
+
+ For example, if your `awk' program works only on records with four
+fields, and you don't want it to fail when given bad input, you might
+use this rule near the beginning of the program:
+
+ NF != 4 {
+ printf("line %d skipped: doesn't have 4 fields", FNR) > "/dev/stderr"
+ next
+ }
+
+so that the following rules will not see the bad record. The error
+message is redirected to the standard error output stream, as error
+messages should be. *Note Standard I/O Streams: Special Files.
+
+ According to the POSIX standard, the behavior is undefined if the
+`next' statement is used in a `BEGIN' or `END' rule. `gawk' will treat
+it as a syntax error.
+
+ If the `next' statement causes the end of the input to be reached,
+then the code in the `END' rules, if any, will be executed. *Note
+`BEGIN' and `END' Special Patterns: BEGIN/END.
+
+
+File: gawk.info, Node: Next File Statement, Next: Exit Statement, Prev: Next Statement, Up: Statements
+
+The `next file' Statement
+=========================
+
+ The `next file' statement is similar to the `next' statement.
+However, instead of abandoning processing of the current record, the
+`next file' statement instructs `awk' to stop processing the current
+data file.
+
+ Upon execution of the `next file' statement, `FILENAME' is updated
+to the name of the next data file listed on the command line, `FNR' is
+reset to 1, and processing starts over with the first rule in the
+progam. *Note Built-in Variables::.
+
+ If the `next file' statement causes the end of the input to be
+reached, then the code in the `END' rules, if any, will be executed.
+*Note `BEGIN' and `END' Special Patterns: BEGIN/END.
+
+ The `next file' statement is a `gawk' extension; it is not
+(currently) available in any other `awk' implementation. You can
+simulate its behavior by creating a library file named `nextfile.awk',
+with the following contents. (This sample program uses user-defined
+functions, a feature that has not been presented yet. *Note
+User-defined Functions: User-defined, for more information.)
+
+ # nextfile --- function to skip remaining records in current file
+
+ # this should be read in before the "main" awk program
+
+ function nextfile() { _abandon_ = FILENAME; next }
+
+ _abandon_ == FILENAME && FNR > 1 { next }
+ _abandon_ == FILENAME && FNR == 1 { _abandon_ = "" }
+
+ The `nextfile' function simply sets a "private" variable(1) to the
+name of the current data file, and then retrieves the next record.
+Since this file is read before the main `awk' program, the rules that
+follows the function definition will be executed before the rules in
+the main program. The first rule continues to skip records as long as
+the name of the input file has not changed, and this is not the first
+record in the file. This rule is sufficient most of the time. But
+what if the *same* data file is named twice in a row on the command
+line? This rule would not process the data file the second time. The
+second rule catches this case: If the data file name is what was being
+skipped, but `FNR' is 1, then this is the second time the file is being
+processed, and it should not be skipped.
+
+ The `next file' statement would be useful if you have many data
+files to process, and due to the nature of the data, you expect that you
+would not want to process every record in the file. In order to move
+on to the next data file, you would have to continue scanning the
+unwanted records (as described above). The `next file' statement
+accomplishes this much more efficiently.
+
+ ---------- Footnotes ----------
+
+ (1) Since all variables in `awk' are global, this program uses the
+common practice of prefixing the variable name with an underscore. In
+fact, it also suffixes the variable name with an underscore, as extra
+insurance against using a variable name that might be used in some
+other library file.
+
+
+File: gawk.info, Node: Exit Statement, Prev: Next File Statement, Up: Statements
+
+The `exit' Statement
+====================
+
+ The `exit' statement causes `awk' to immediately stop executing the
+current rule and to stop processing input; any remaining input is
+ignored.
+
+ If an `exit' statement is executed from a `BEGIN' rule the program
+stops processing everything immediately. No input records are read.
+However, if an `END' rule is present, it is executed (*note `BEGIN' and
+`END' Special Patterns: BEGIN/END.).
+
+ If `exit' is used as part of an `END' rule, it causes the program to
+stop immediately.
+
+ An `exit' statement that is part of an ordinary rule (that is, not
+part of a `BEGIN' or `END' rule) stops the execution of any further
+automatic rules, but the `END' rule is executed if there is one. If
+you do not want the `END' rule to do its job in this case, you can set
+a variable to nonzero before the `exit' statement, and check that
+variable in the `END' rule.
+
+ If an argument is supplied to `exit', its value is used as the exit
+status code for the `awk' process. If no argument is supplied, `exit'
+returns status zero (success).
+
+ For example, let's say you've discovered an error condition you
+really don't know how to handle. Conventionally, programs report this
+by exiting with a nonzero status. Your `awk' program can do this using
+an `exit' statement with a nonzero argument. Here's an example of this:
+
+ BEGIN {
+ if (("date" | getline date_now) < 0) {
+ print "Can't get system date" > "/dev/stderr"
+ exit 4
+ }
+ }
+
+
+File: gawk.info, Node: Arrays, Next: Built-in, Prev: Statements, Up: Top
+
+Arrays in `awk'
+***************
+
+ An "array" is a table of values, called "elements". The elements of
+an array are distinguished by their indices. "Indices" may be either
+numbers or strings. Each array has a name, which looks like a variable
+name, but must not be in use as a variable name in the same `awk'
+program.
+
+* Menu:
+
+* Array Intro:: Introduction to Arrays
+* Reference to Elements:: How to examine one element of an array.
+* Assigning Elements:: How to change an element of an array.
+* Array Example:: Basic Example of an Array
+* Scanning an Array:: A variation of the `for' statement.
+ It loops through the indices of
+ an array's existing elements.
+* Delete:: The `delete' statement removes
+ an element from an array.
+* Numeric Array Subscripts:: How to use numbers as subscripts in `awk'.
+* Multi-dimensional:: Emulating multi-dimensional arrays in `awk'.
+* Multi-scanning:: Scanning multi-dimensional arrays.
+
+
+File: gawk.info, Node: Array Intro, Next: Reference to Elements, Prev: Arrays, Up: Arrays
+
+Introduction to Arrays
+======================
+
+ The `awk' language has one-dimensional "arrays" for storing groups
+of related strings or numbers.
+
+ Every `awk' array must have a name. Array names have the same
+syntax as variable names; any valid variable name would also be a valid
+array name. But you cannot use one name in both ways (as an array and
+as a variable) in one `awk' program.
+
+ Arrays in `awk' superficially resemble arrays in other programming
+languages; but there are fundamental differences. In `awk', you don't
+need to specify the size of an array before you start to use it.
+Additionally, any number or string in `awk' may be used as an array
+index.
+
+ In most other languages, you have to "declare" an array and specify
+how many elements or components it contains. In such languages, the
+declaration causes a contiguous block of memory to be allocated for that
+many elements. An index in the array must be a positive integer; for
+example, the index 0 specifies the first element in the array, which is
+actually stored at the beginning of the block of memory. Index 1
+specifies the second element, which is stored in memory right after the
+first element, and so on. It is impossible to add more elements to the
+array, because it has room for only as many elements as you declared.
+
+ A contiguous array of four elements might look like this,
+conceptually, if the element values are `8', `"foo"', `""' and `30':
+
+ +---------+---------+--------+---------+
+ | 8 | "foo" | "" | 30 | value
+ +---------+---------+--------+---------+
+ 0 1 2 3 index
+
+Only the values are stored; the indices are implicit from the order of
+the values. `8' is the value at index 0, because `8' appears in the
+position with 0 elements before it.
+
+ Arrays in `awk' are different: they are "associative". This means
+that each array is a collection of pairs: an index, and its
+corresponding array element value:
+
+ Element 4 Value 30
+ Element 2 Value "foo"
+ Element 1 Value 8
+ Element 3 Value ""
+
+We have shown the pairs in jumbled order because their order is
+irrelevant.
+
+ One advantage of an associative array is that new pairs can be added
+at any time. For example, suppose we add to the above array a tenth
+element whose value is `"number ten"'. The result is this:
+
+ Element 10 Value "number ten"
+ Element 4 Value 30
+ Element 2 Value "foo"
+ Element 1 Value 8
+ Element 3 Value ""
+
+Now the array is "sparse" (i.e., some indices are missing): it has
+elements 1-4 and 10, but doesn't have elements 5, 6, 7, 8, or 9.
+
+ Another consequence of associative arrays is that the indices don't
+have to be positive integers. Any number, or even a string, can be an
+index. For example, here is an array which translates words from
+English into French:
+
+ Element "dog" Value "chien"
+ Element "cat" Value "chat"
+ Element "one" Value "un"
+ Element 1 Value "un"
+
+Here we decided to translate the number 1 in both spelled-out and
+numeric form--thus illustrating that a single array can have both
+numbers and strings as indices.
+
+ When `awk' creates an array for you, e.g., with the `split' built-in
+function, that array's indices are consecutive integers starting at 1.
+(*Note Built-in Functions for String Manipulation: String Functions.)
+
+
+File: gawk.info, Node: Reference to Elements, Next: Assigning Elements, Prev: Array Intro, Up: Arrays
+
+Referring to an Array Element
+=============================
+
+ The principal way of using an array is to refer to one of its
+elements. An array reference is an expression which looks like this:
+
+ ARRAY[INDEX]
+
+Here, ARRAY is the name of an array. The expression INDEX is the index
+of the element of the array that you want.
+
+ The value of the array reference is the current value of that array
+element. For example, `foo[4.3]' is an expression for the element of
+array `foo' at index 4.3.
+
+ If you refer to an array element that has no recorded value, the
+value of the reference is `""', the null string. This includes elements
+to which you have not assigned any value, and elements that have been
+deleted (*note The `delete' Statement: Delete.). Such a reference
+automatically creates that array element, with the null string as its
+value. (In some cases, this is unfortunate, because it might waste
+memory inside `awk').
+
+ You can find out if an element exists in an array at a certain index
+with the expression:
+
+ INDEX in ARRAY
+
+This expression tests whether or not the particular index exists,
+without the side effect of creating that element if it is not present.
+The expression has the value 1 (true) if `ARRAY[INDEX]' exists, and 0
+(false) if it does not exist.
+
+ For example, to test whether the array `frequencies' contains the
+index `"2"', you could write this statement:
+
+ if ("2" in frequencies) print "Subscript \"2\" is present."
+
+ Note that this is *not* a test of whether or not the array
+`frequencies' contains an element whose *value* is `"2"'. (There is no
+way to do that except to scan all the elements.) Also, this *does not*
+create `frequencies["2"]', while the following (incorrect) alternative
+would do so:
+
+ if (frequencies["2"] != "") print "Subscript \"2\" is present."
+
+
+File: gawk.info, Node: Assigning Elements, Next: Array Example, Prev: Reference to Elements, Up: Arrays
+
+Assigning Array Elements
+========================
+
+ Array elements are lvalues: they can be assigned values just like
+`awk' variables:
+
+ ARRAY[SUBSCRIPT] = VALUE
+
+Here ARRAY is the name of your array. The expression SUBSCRIPT is the
+index of the element of the array that you want to assign a value. The
+expression VALUE is the value you are assigning to that element of the
+array.
+
+
+File: gawk.info, Node: Array Example, Next: Scanning an Array, Prev: Assigning Elements, Up: Arrays
+
+Basic Example of an Array
+=========================
+
+ The following program takes a list of lines, each beginning with a
+line number, and prints them out in order of line number. The line
+numbers are not in order, however, when they are first read: they are
+scrambled. This program sorts the lines by making an array using the
+line numbers as subscripts. It then prints out the lines in sorted
+order of their numbers. It is a very simple program, and gets confused
+if it encounters repeated numbers, gaps, or lines that don't begin with
+a number.
+
+ {
+ if ($1 > max)
+ max = $1
+ arr[$1] = $0
+ }
+
+ END {
+ for (x = 1; x <= max; x++)
+ print arr[x]
+ }
+
+ The first rule keeps track of the largest line number seen so far;
+it also stores each line into the array `arr', at an index that is the
+line's number.
+
+ The second rule runs after all the input has been read, to print out
+all the lines.
+
+ When this program is run with the following input:
+
+ 5 I am the Five man
+ 2 Who are you? The new number two!
+ 4 . . . And four on the floor
+ 1 Who is number one?
+ 3 I three you.
+
+its output is this:
+
+ 1 Who is number one?
+ 2 Who are you? The new number two!
+ 3 I three you.
+ 4 . . . And four on the floor
+ 5 I am the Five man
+
+ If a line number is repeated, the last line with a given number
+overrides the others.
+
+ Gaps in the line numbers can be handled with an easy improvement to
+the program's `END' rule:
+
+ END {
+ for (x = 1; x <= max; x++)
+ if (x in arr)
+ print arr[x]
+ }
+
+
+File: gawk.info, Node: Scanning an Array, Next: Delete, Prev: Array Example, Up: Arrays
+
+Scanning all Elements of an Array
+=================================
+
+ In programs that use arrays, often you need a loop that executes
+once for each element of an array. In other languages, where arrays are
+contiguous and indices are limited to positive integers, this is easy:
+the largest index is one less than the length of the array, and you can
+find all the valid indices by counting from zero up to that value. This
+technique won't do the job in `awk', since any number or string may be
+an array index. So `awk' has a special kind of `for' statement for
+scanning an array:
+
+ for (VAR in ARRAY)
+ BODY
+
+This loop executes BODY once for each different value that your program
+has previously used as an index in ARRAY, with the variable VAR set to
+that index.
+
+ Here is a program that uses this form of the `for' statement. The
+first rule scans the input records and notes which words appear (at
+least once) in the input, by storing a 1 into the array `used' with the
+word as index. The second rule scans the elements of `used' to find
+all the distinct words that appear in the input. It prints each word
+that is more than 10 characters long, and also prints the number of
+such words. *Note Built-in Functions: Built-in, for more information
+on the built-in function `length'.
+
+ # Record a 1 for each word that is used at least once.
+ {
+ for (i = 1; i <= NF; i++)
+ used[$i] = 1
+ }
+
+ # Find number of distinct words more than 10 characters long.
+ END {
+ for (x in used)
+ if (length(x) > 10) {
+ ++num_long_words
+ print x
+ }
+ print num_long_words, "words longer than 10 characters"
+ }
+
+*Note Sample Program::, for a more detailed example of this type.
+
+ The order in which elements of the array are accessed by this
+statement is determined by the internal arrangement of the array
+elements within `awk' and cannot be controlled or changed. This can
+lead to problems if new elements are added to ARRAY by statements in
+BODY; you cannot predict whether or not the `for' loop will reach them.
+Similarly, changing VAR inside the loop can produce strange results.
+It is best to avoid such things.
+
+
+File: gawk.info, Node: Delete, Next: Numeric Array Subscripts, Prev: Scanning an Array, Up: Arrays
+
+The `delete' Statement
+======================
+
+ You can remove an individual element of an array using the `delete'
+statement:
+
+ delete ARRAY[INDEX]
+
+ You can not refer to an array element after it has been deleted; it
+is as if you had never referred to it and had never given it any value.
+You can no longer obtain any value the element once had.
+
+ Here is an example of deleting elements in an array:
+
+ for (i in frequencies)
+ delete frequencies[i]
+
+This example removes all the elements from the array `frequencies'.
+
+ If you delete an element, a subsequent `for' statement to scan the
+array will not report that element, and the `in' operator to check for
+the presence of that element will return 0:
+
+ delete foo[4]
+ if (4 in foo)
+ print "This will never be printed"
+
+ It is not an error to delete an element which does not exist.
+
+
+File: gawk.info, Node: Numeric Array Subscripts, Next: Multi-dimensional, Prev: Delete, Up: Arrays
+
+Using Numbers to Subscript Arrays
+=================================
+
+ An important aspect of arrays to remember is that array subscripts
+are *always* strings. If you use a numeric value as a subscript, it
+will be converted to a string value before it is used for subscripting
+(*note Conversion of Strings and Numbers: Conversion.).
+
+ This means that the value of the `CONVFMT' can potentially affect
+how your program accesses elements of an array. For example:
+
+ a = b = 12.153
+ data[a] = 1
+ CONVFMT = "%2.2f"
+ if (b in data)
+ printf "%s is in data", b
+ else
+ printf "%s is not in data", b
+
+should print `12.15 is not in data'. The first statement gives both
+`a' and `b' the same numeric value. Assigning to `data[a]' first gives
+`a' the string value `"12.153"' (using the default conversion value of
+`CONVFMT', `"%.6g"'), and then assigns 1 to `data["12.153"]'. The
+program then changes the value of `CONVFMT'. The test `(b in data)'
+forces `b' to be converted to a string, this time `"12.15"', since the
+value of `CONVFMT' only allows two significant digits. This test fails,
+since `"12.15"' is a different string from `"12.153"'.
+
+ According to the rules for conversions (*note Conversion of Strings
+and Numbers: Conversion.), integer values are always converted to
+strings as integers, no matter what the value of `CONVFMT' may happen
+to be. So the usual case of
+
+ for (i = 1; i <= maxsub; i++)
+ do something with array[i]
+
+will work, no matter what the value of `CONVFMT'.
+
+ Like many things in `awk', the majority of the time things work as
+you would expect them to work. But it is useful to have a precise
+knowledge of the actual rules, since sometimes they can have a subtle
+effect on your programs.
+
+
+File: gawk.info, Node: Multi-dimensional, Next: Multi-scanning, Prev: Numeric Array Subscripts, Up: Arrays
+
+Multi-dimensional Arrays
+========================
+
+ A multi-dimensional array is an array in which an element is
+identified by a sequence of indices, not a single index. For example, a
+two-dimensional array requires two indices. The usual way (in most
+languages, including `awk') to refer to an element of a two-dimensional
+array named `grid' is with `grid[X,Y]'.
+
+ Multi-dimensional arrays are supported in `awk' through
+concatenation of indices into one string. What happens is that `awk'
+converts the indices into strings (*note Conversion of Strings and
+Numbers: Conversion.) and concatenates them together, with a separator
+between them. This creates a single string that describes the values
+of the separate indices. The combined string is used as a single index
+into an ordinary, one-dimensional array. The separator used is the
+value of the built-in variable `SUBSEP'.
+
+ For example, suppose we evaluate the expression `foo[5,12]="value"'
+when the value of `SUBSEP' is `"@"'. The numbers 5 and 12 are
+converted to strings and concatenated with an `@' between them,
+yielding `"5@12"'; thus, the array element `foo["5@12"]' is set to
+`"value"'.
+
+ Once the element's value is stored, `awk' has no record of whether
+it was stored with a single index or a sequence of indices. The two
+expressions `foo[5,12]' and `foo[5 SUBSEP 12]' always have the same
+value.
+
+ The default value of `SUBSEP' is the string `"\034"', which contains
+a nonprinting character that is unlikely to appear in an `awk' program
+or in the input data.
+
+ The usefulness of choosing an unlikely character comes from the fact
+that index values that contain a string matching `SUBSEP' lead to
+combined strings that are ambiguous. Suppose that `SUBSEP' were `"@"';
+then `foo["a@b", "c"]' and `foo["a", "b@c"]' would be indistinguishable
+because both would actually be stored as `foo["a@b@c"]'. Because
+`SUBSEP' is `"\034"', such confusion can arise only when an index
+contains the character with ASCII code 034, which is a rare event.
+
+ You can test whether a particular index-sequence exists in a
+"multi-dimensional" array with the same operator `in' used for single
+dimensional arrays. Instead of a single index as the left-hand operand,
+write the whole sequence of indices, separated by commas, in
+parentheses:
+
+ (SUBSCRIPT1, SUBSCRIPT2, ...) in ARRAY
+
+ The following example treats its input as a two-dimensional array of
+fields; it rotates this array 90 degrees clockwise and prints the
+result. It assumes that all lines have the same number of elements.
+
+ awk '{
+ if (max_nf < NF)
+ max_nf = NF
+ max_nr = NR
+ for (x = 1; x <= NF; x++)
+ vector[x, NR] = $x
+ }
+
+ END {
+ for (x = 1; x <= max_nf; x++) {
+ for (y = max_nr; y >= 1; --y)
+ printf("%s ", vector[x, y])
+ printf("\n")
+ }
+ }'
+
+When given the input:
+
+ 1 2 3 4 5 6
+ 2 3 4 5 6 1
+ 3 4 5 6 1 2
+ 4 5 6 1 2 3
+
+it produces:
+
+ 4 3 2 1
+ 5 4 3 2
+ 6 5 4 3
+ 1 6 5 4
+ 2 1 6 5
+ 3 2 1 6
+
+
+File: gawk.info, Node: Multi-scanning, Prev: Multi-dimensional, Up: Arrays
+
+Scanning Multi-dimensional Arrays
+=================================
+
+ There is no special `for' statement for scanning a
+"multi-dimensional" array; there cannot be one, because in truth there
+are no multi-dimensional arrays or elements; there is only a
+multi-dimensional *way of accessing* an array.
+
+ However, if your program has an array that is always accessed as
+multi-dimensional, you can get the effect of scanning it by combining
+the scanning `for' statement (*note Scanning all Elements of an Array:
+Scanning an Array.) with the `split' built-in function (*note Built-in
+Functions for String Manipulation: String Functions.). It works like
+this:
+
+ for (combined in ARRAY) {
+ split(combined, separate, SUBSEP)
+ ...
+ }
+
+This finds each concatenated, combined index in the array, and splits it
+into the individual indices by breaking it apart where the value of
+`SUBSEP' appears. The split-out indices become the elements of the
+array `separate'.
+
+ Thus, suppose you have previously stored in `ARRAY[1, "foo"]'; then
+an element with index `"1\034foo"' exists in ARRAY. (Recall that the
+default value of `SUBSEP' contains the character with code 034.)
+Sooner or later the `for' statement will find that index and do an
+iteration with `combined' set to `"1\034foo"'. Then the `split'
+function is called as follows:
+
+ split("1\034foo", separate, "\034")
+
+The result of this is to set `separate[1]' to 1 and `separate[2]' to
+`"foo"'. Presto, the original sequence of separate indices has been
+recovered.
+
+
+File: gawk.info, Node: Built-in, Next: User-defined, Prev: Arrays, Up: Top
+
+Built-in Functions
+******************
+
+ "Built-in" functions are functions that are always available for
+your `awk' program to call. This chapter defines all the built-in
+functions in `awk'; some of them are mentioned in other sections, but
+they are summarized here for your convenience. (You can also define
+new functions yourself. *Note User-defined Functions: User-defined.)
+
+* Menu:
+
+* Calling Built-in:: How to call built-in functions.
+* Numeric Functions:: Functions that work with numbers,
+ including `int', `sin' and `rand'.
+* String Functions:: Functions for string manipulation,
+ such as `split', `match', and `sprintf'.
+* I/O Functions:: Functions for files and shell commands.
+* Time Functions:: Functions for dealing with time stamps.
+
+
+File: gawk.info, Node: Calling Built-in, Next: Numeric Functions, Prev: Built-in, Up: Built-in
+
+Calling Built-in Functions
+==========================
+
+ To call a built-in function, write the name of the function followed
+by arguments in parentheses. For example, `atan2(y + z, 1)' is a call
+to the function `atan2', with two arguments.
+
+ Whitespace is ignored between the built-in function name and the
+open-parenthesis, but we recommend that you avoid using whitespace
+there. User-defined functions do not permit whitespace in this way, and
+you will find it easier to avoid mistakes by following a simple
+convention which always works: no whitespace after a function name.
+
+ Each built-in function accepts a certain number of arguments. In
+most cases, any extra arguments given to built-in functions are
+ignored. The defaults for omitted arguments vary from function to
+function and are described under the individual functions.
+
+ When a function is called, expressions that create the function's
+actual parameters are evaluated completely before the function call is
+performed. For example, in the code fragment:
+
+ i = 4
+ j = sqrt(i++)
+
+the variable `i' is set to 5 before `sqrt' is called with a value of 4
+for its actual parameter.
+
+
+File: gawk.info, Node: Numeric Functions, Next: String Functions, Prev: Calling Built-in, Up: Built-in
+
+Numeric Built-in Functions
+==========================
+
+ Here is a full list of built-in functions that work with numbers:
+
+`int(X)'
+ This gives you the integer part of X, truncated toward 0. This
+ produces the nearest integer to X, located between X and 0.
+
+ For example, `int(3)' is 3, `int(3.9)' is 3, `int(-3.9)' is -3,
+ and `int(-3)' is -3 as well.
+
+`sqrt(X)'
+ This gives you the positive square root of X. It reports an error
+ if X is negative. Thus, `sqrt(4)' is 2.
+
+`exp(X)'
+ This gives you the exponential of X, or reports an error if X is
+ out of range. The range of values X can have depends on your
+ machine's floating point representation.
+
+`log(X)'
+ This gives you the natural logarithm of X, if X is positive;
+ otherwise, it reports an error.
+
+`sin(X)'
+ This gives you the sine of X, with X in radians.
+
+`cos(X)'
+ This gives you the cosine of X, with X in radians.
+
+`atan2(Y, X)'
+ This gives you the arctangent of `Y / X' in radians.
+
+`rand()'
+ This gives you a random number. The values of `rand' are
+ uniformly-distributed between 0 and 1. The value is never 0 and
+ never 1.
+
+ Often you want random integers instead. Here is a user-defined
+ function you can use to obtain a random nonnegative integer less
+ than N:
+
+ function randint(n) {
+ return int(n * rand())
+ }
+
+ The multiplication produces a random real number greater than 0
+ and less than N. We then make it an integer (using `int') between
+ 0 and `N - 1'.
+
+ Here is an example where a similar function is used to produce
+ random integers between 1 and N. Note that this program will
+ print a new random number for each input record.
+
+ awk '
+ # Function to roll a simulated die.
+ function roll(n) { return 1 + int(rand() * n) }
+
+ # Roll 3 six-sided dice and print total number of points.
+ {
+ printf("%d points\n", roll(6)+roll(6)+roll(6))
+ }'
+
+ *Note:* `rand' starts generating numbers from the same point, or
+ "seed", each time you run `awk'. This means that a program will
+ produce the same results each time you run it. The numbers are
+ random within one `awk' run, but predictable from run to run.
+ This is convenient for debugging, but if you want a program to do
+ different things each time it is used, you must change the seed to
+ a value that will be different in each run. To do this, use
+ `srand'.
+
+`srand(X)'
+ The function `srand' sets the starting point, or "seed", for
+ generating random numbers to the value X.
+
+ Each seed value leads to a particular sequence of "random" numbers.
+ Thus, if you set the seed to the same value a second time, you
+ will get the same sequence of "random" numbers again.
+
+ If you omit the argument X, as in `srand()', then the current date
+ and time of day are used for a seed. This is the way to get random
+ numbers that are truly unpredictable.
+
+ The return value of `srand' is the previous seed. This makes it
+ easy to keep track of the seeds for use in consistently reproducing
+ sequences of random numbers.
+
+
+File: gawk.info, Node: String Functions, Next: I/O Functions, Prev: Numeric Functions, Up: Built-in
+
+Built-in Functions for String Manipulation
+==========================================
+
+ The functions in this section look at or change the text of one or
+more strings.
+
+`index(IN, FIND)'
+ This searches the string IN for the first occurrence of the string
+ FIND, and returns the position in characters where that occurrence
+ begins in the string IN. For example:
+
+ awk 'BEGIN { print index("peanut", "an") }'
+
+ prints `3'. If FIND is not found, `index' returns 0. (Remember
+ that string indices in `awk' start at 1.)
+
+`length(STRING)'
+ This gives you the number of characters in STRING. If STRING is a
+ number, the length of the digit string representing that number is
+ returned. For example, `length("abcde")' is 5. By contrast,
+ `length(15 * 35)' works out to 3. How? Well, 15 * 35 = 525, and
+ 525 is then converted to the string `"525"', which has three
+ characters.
+
+ If no argument is supplied, `length' returns the length of `$0'.
+
+ In older versions of `awk', you could call the `length' function
+ without any parentheses. Doing so is marked as "deprecated" in the
+ POSIX standard. This means that while you can do this in your
+ programs, it is a feature that can eventually be removed from a
+ future version of the standard. Therefore, for maximal
+ portability of your `awk' programs you should always supply the
+ parentheses.
+
+`match(STRING, REGEXP)'
+ The `match' function searches the string, STRING, for the longest,
+ leftmost substring matched by the regular expression, REGEXP. It
+ returns the character position, or "index", of where that
+ substring begins (1, if it starts at the beginning of STRING). If
+ no match if found, it returns 0.
+
+ The `match' function sets the built-in variable `RSTART' to the
+ index. It also sets the built-in variable `RLENGTH' to the length
+ in characters of the matched substring. If no match is found,
+ `RSTART' is set to 0, and `RLENGTH' to -1.
+
+ For example:
+
+ awk '{
+ if ($1 == "FIND")
+ regex = $2
+ else {
+ where = match($0, regex)
+ if (where)
+ print "Match of", regex, "found at", where, "in", $0
+ }
+ }'
+
+ This program looks for lines that match the regular expression
+ stored in the variable `regex'. This regular expression can be
+ changed. If the first word on a line is `FIND', `regex' is
+ changed to be the second word on that line. Therefore, given:
+
+ FIND fo*bar
+ My program was a foobar
+ But none of it would doobar
+ FIND Melvin
+ JF+KM
+ This line is property of The Reality Engineering Co.
+ This file created by Melvin.
+
+ `awk' prints:
+
+ Match of fo*bar found at 18 in My program was a foobar
+ Match of Melvin found at 26 in This file created by Melvin.
+
+`split(STRING, ARRAY, FIELDSEP)'
+ This divides STRING into pieces separated by FIELDSEP, and stores
+ the pieces in ARRAY. The first piece is stored in `ARRAY[1]', the
+ second piece in `ARRAY[2]', and so forth. The string value of the
+ third argument, FIELDSEP, is a regexp describing where to split
+ STRING (much as `FS' can be a regexp describing where to split
+ input records). If the FIELDSEP is omitted, the value of `FS' is
+ used. `split' returns the number of elements created.
+
+ The `split' function, then, splits strings into pieces in a manner
+ similar to the way input lines are split into fields. For example:
+
+ split("auto-da-fe", a, "-")
+
+ splits the string `auto-da-fe' into three fields using `-' as the
+ separator. It sets the contents of the array `a' as follows:
+
+ a[1] = "auto"
+ a[2] = "da"
+ a[3] = "fe"
+
+ The value returned by this call to `split' is 3.
+
+ As with input field-splitting, when the value of FIELDSEP is `"
+ "', leading and trailing whitespace is ignored, and the elements
+ are separated by runs of whitespace.
+
+`sprintf(FORMAT, EXPRESSION1,...)'
+ This returns (without printing) the string that `printf' would
+ have printed out with the same arguments (*note Using `printf'
+ Statements for Fancier Printing: Printf.). For example:
+
+ sprintf("pi = %.2f (approx.)", 22/7)
+
+ returns the string `"pi = 3.14 (approx.)"'.
+
+`sub(REGEXP, REPLACEMENT, TARGET)'
+ The `sub' function alters the value of TARGET. It searches this
+ value, which should be a string, for the leftmost substring
+ matched by the regular expression, REGEXP, extending this match as
+ far as possible. Then the entire string is changed by replacing
+ the matched text with REPLACEMENT. The modified string becomes
+ the new value of TARGET.
+
+ This function is peculiar because TARGET is not simply used to
+ compute a value, and not just any expression will do: it must be a
+ variable, field or array reference, so that `sub' can store a
+ modified value there. If this argument is omitted, then the
+ default is to use and alter `$0'.
+
+ For example:
+
+ str = "water, water, everywhere"
+ sub(/at/, "ith", str)
+
+ sets `str' to `"wither, water, everywhere"', by replacing the
+ leftmost, longest occurrence of `at' with `ith'.
+
+ The `sub' function returns the number of substitutions made (either
+ one or zero).
+
+ If the special character `&' appears in REPLACEMENT, it stands for
+ the precise substring that was matched by REGEXP. (If the regexp
+ can match more than one string, then this precise substring may
+ vary.) For example:
+
+ awk '{ sub(/candidate/, "& and his wife"); print }'
+
+ changes the first occurrence of `candidate' to `candidate and his
+ wife' on each input line.
+
+ Here is another example:
+
+ awk 'BEGIN {
+ str = "daabaaa"
+ sub(/a*/, "c&c", str)
+ print str
+ }'
+
+ prints `dcaacbaaa'. This show how `&' can represent a non-constant
+ string, and also illustrates the "leftmost, longest" rule.
+
+ The effect of this special character (`&') can be turned off by
+ putting a backslash before it in the string. As usual, to insert
+ one backslash in the string, you must write two backslashes.
+ Therefore, write `\\&' in a string constant to include a literal
+ `&' in the replacement. For example, here is how to replace the
+ first `|' on each line with an `&':
+
+ awk '{ sub(/\|/, "\\&"); print }'
+
+ *Note:* as mentioned above, the third argument to `sub' must be an
+ lvalue. Some versions of `awk' allow the third argument to be an
+ expression which is not an lvalue. In such a case, `sub' would
+ still search for the pattern and return 0 or 1, but the result of
+ the substitution (if any) would be thrown away because there is no
+ place to put it. Such versions of `awk' accept expressions like
+ this:
+
+ sub(/USA/, "United States", "the USA and Canada")
+
+ But that is considered erroneous in `gawk'.
+
+`gsub(REGEXP, REPLACEMENT, TARGET)'
+ This is similar to the `sub' function, except `gsub' replaces
+ *all* of the longest, leftmost, *nonoverlapping* matching
+ substrings it can find. The `g' in `gsub' stands for "global,"
+ which means replace everywhere. For example:
+
+ awk '{ gsub(/Britain/, "United Kingdom"); print }'
+
+ replaces all occurrences of the string `Britain' with `United
+ Kingdom' for all input records.
+
+ The `gsub' function returns the number of substitutions made. If
+ the variable to be searched and altered, TARGET, is omitted, then
+ the entire input record, `$0', is used.
+
+ As in `sub', the characters `&' and `\' are special, and the third
+ argument must be an lvalue.
+
+`substr(STRING, START, LENGTH)'
+ This returns a LENGTH-character-long substring of STRING, starting
+ at character number START. The first character of a string is
+ character number one. For example, `substr("washington", 5, 3)'
+ returns `"ing"'.
+
+ If LENGTH is not present, this function returns the whole suffix of
+ STRING that begins at character number START. For example,
+ `substr("washington", 5)' returns `"ington"'. This is also the
+ case if LENGTH is greater than the number of characters remaining
+ in the string, counting from character number START.
+
+`tolower(STRING)'
+ This returns a copy of STRING, with each upper-case character in
+ the string replaced with its corresponding lower-case character.
+ Nonalphabetic characters are left unchanged. For example,
+ `tolower("MiXeD cAsE 123")' returns `"mixed case 123"'.
+
+`toupper(STRING)'
+ This returns a copy of STRING, with each lower-case character in
+ the string replaced with its corresponding upper-case character.
+ Nonalphabetic characters are left unchanged. For example,
+ `toupper("MiXeD cAsE 123")' returns `"MIXED CASE 123"'.
+
diff --git a/gawk.info-6 b/gawk.info-6
new file mode 100644
index 00000000..2dfef35e
--- /dev/null
+++ b/gawk.info-6
@@ -0,0 +1,1234 @@
+This is Info file gawk.info, produced by Makeinfo-1.54 from the input
+file gawk.texi.
+
+ This file documents `awk', a program that you can use to select
+particular records in a file and perform operations upon them.
+
+ This is Edition 0.15 of `The GAWK Manual',
+for the 2.15 version of the GNU implementation
+of AWK.
+
+ Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that
+the entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Foundation.
+
+
+File: gawk.info, Node: I/O Functions, Next: Time Functions, Prev: String Functions, Up: Built-in
+
+Built-in Functions for Input/Output
+===================================
+
+`close(FILENAME)'
+ Close the file FILENAME, for input or output. The argument may
+ alternatively be a shell command that was used for redirecting to
+ or from a pipe; then the pipe is closed.
+
+ *Note Closing Input Files and Pipes: Close Input, regarding closing
+ input files and pipes. *Note Closing Output Files and Pipes:
+ Close Output, regarding closing output files and pipes.
+
+`system(COMMAND)'
+ The system function allows the user to execute operating system
+ commands and then return to the `awk' program. The `system'
+ function executes the command given by the string COMMAND. It
+ returns, as its value, the status returned by the command that was
+ executed.
+
+ For example, if the following fragment of code is put in your `awk'
+ program:
+
+ END {
+ system("mail -s 'awk run done' operator < /dev/null")
+ }
+
+ the system operator will be sent mail when the `awk' program
+ finishes processing input and begins its end-of-input processing.
+
+ Note that much the same result can be obtained by redirecting
+ `print' or `printf' into a pipe. However, if your `awk' program
+ is interactive, `system' is useful for cranking up large
+ self-contained programs, such as a shell or an editor.
+
+ Some operating systems cannot implement the `system' function.
+ `system' causes a fatal error if it is not supported.
+
+Controlling Output Buffering with `system'
+------------------------------------------
+
+ Many utility programs will "buffer" their output; they save
+information to be written to a disk file or terminal in memory, until
+there is enough to be written in one operation. This is often more
+efficient than writing every little bit of information as soon as it is
+ready. However, sometimes it is necessary to force a program to
+"flush" its buffers; that is, write the information to its destination,
+even if a buffer is not full. You can do this from your `awk' program
+by calling `system' with a null string as its argument:
+
+ system("") # flush output
+
+`gawk' treats this use of the `system' function as a special case, and
+is smart enough not to run a shell (or other command interpreter) with
+the empty command. Therefore, with `gawk', this idiom is not only
+useful, it is efficient. While this idiom should work with other `awk'
+implementations, it will not necessarily avoid starting an unnecessary
+shell.
+
+
+File: gawk.info, Node: Time Functions, Prev: I/O Functions, Up: Built-in
+
+Functions for Dealing with Time Stamps
+======================================
+
+ A common use for `awk' programs is the processing of log files. Log
+files often contain time stamp information, indicating when a
+particular log record was written. Many programs log their time stamp
+in the form returned by the `time' system call, which is the number of
+seconds since a particular epoch. On POSIX systems, it is the number
+of seconds since Midnight, January 1, 1970, UTC.
+
+ In order to make it easier to process such log files, and to easily
+produce useful reports, `gawk' provides two functions for working with
+time stamps. Both of these are `gawk' extensions; they are not
+specified in the POSIX standard, nor are they in any other known version
+of `awk'.
+
+`systime()'
+ This function returns the current time as the number of seconds
+ since the system epoch. On POSIX systems, this is the number of
+ seconds since Midnight, January 1, 1970, UTC. It may be a
+ different number on other systems.
+
+`strftime(FORMAT, TIMESTAMP)'
+ This function returns a string. It is similar to the function of
+ the same name in the ANSI C standard library. The time specified
+ by TIMESTAMP is used to produce a string, based on the contents of
+ the FORMAT string.
+
+ The `systime' function allows you to compare a time stamp from a log
+file with the current time of day. In particular, it is easy to
+determine how long ago a particular record was logged. It also allows
+you to produce log records using the "seconds since the epoch" format.
+
+ The `strftime' function allows you to easily turn a time stamp into
+human-readable information. It is similar in nature to the `sprintf'
+function, copying non-format specification characters verbatim to the
+returned string, and substituting date and time values for format
+specifications in the FORMAT string. If no TIMESTAMP argument is
+supplied, `gawk' will use the current time of day as the time stamp.
+
+ `strftime' is guaranteed by the ANSI C standard to support the
+following date format specifications:
+
+`%a'
+ The locale's abbreviated weekday name.
+
+`%A'
+ The locale's full weekday name.
+
+`%b'
+ The locale's abbreviated month name.
+
+`%B'
+ The locale's full month name.
+
+`%c'
+ The locale's "appropriate" date and time representation.
+
+`%d'
+ The day of the month as a decimal number (01-31).
+
+`%H'
+ The hour (24-hour clock) as a decimal number (00-23).
+
+`%I'
+ The hour (12-hour clock) as a decimal number (01-12).
+
+`%j'
+ The day of the year as a decimal number (001-366).
+
+`%m'
+ The month as a decimal number (01-12).
+
+`%M'
+ The minute as a decimal number (00-59).
+
+`%p'
+ The locale's equivalent of the AM/PM designations associated with
+ a 12-hour clock.
+
+`%S'
+ The second as a decimal number (00-61). (Occasionally there are
+ minutes in a year with one or two leap seconds, which is why the
+ seconds can go from 0 all the way to 61.)
+
+`%U'
+ The week number of the year (the first Sunday as the first day of
+ week 1) as a decimal number (00-53).
+
+`%w'
+ The weekday as a decimal number (0-6). Sunday is day 0.
+
+`%W'
+ The week number of the year (the first Monday as the first day of
+ week 1) as a decimal number (00-53).
+
+`%x'
+ The locale's "appropriate" date representation.
+
+`%X'
+ The locale's "appropriate" time representation.
+
+`%y'
+ The year without century as a decimal number (00-99).
+
+`%Y'
+ The year with century as a decimal number.
+
+`%Z'
+ The time zone name or abbreviation, or no characters if no time
+ zone is determinable.
+
+`%%'
+ A literal `%'.
+
+ If a conversion specifier is not one of the above, the behavior is
+undefined. (This is because the ANSI standard for C leaves the
+behavior of the C version of `strftime' undefined, and `gawk' will use
+the system's version of `strftime' if it's there. Typically, the
+conversion specifier will either not appear in the returned string, or
+it will appear literally.)
+
+ Informally, a "locale" is the geographic place in which a program is
+meant to run. For example, a common way to abbreviate the date
+September 4, 1991 in the United States would be "9/4/91". In many
+countries in Europe, however, it would be abbreviated "4.9.91". Thus,
+the `%x' specification in a `"US"' locale might produce `9/4/91', while
+in a `"EUROPE"' locale, it might produce `4.9.91'. The ANSI C standard
+defines a default `"C"' locale, which is an environment that is typical
+of what most C programmers are used to.
+
+ A public-domain C version of `strftime' is shipped with `gawk' for
+systems that are not yet fully ANSI-compliant. If that version is used
+to compile `gawk' (*note Installing `gawk': Installation.), then the
+following additional format specifications are available:
+
+`%D'
+ Equivalent to specifying `%m/%d/%y'.
+
+`%e'
+ The day of the month, padded with a blank if it is only one digit.
+
+`%h'
+ Equivalent to `%b', above.
+
+`%n'
+ A newline character (ASCII LF).
+
+`%r'
+ Equivalent to specifying `%I:%M:%S %p'.
+
+`%R'
+ Equivalent to specifying `%H:%M'.
+
+`%T'
+ Equivalent to specifying `%H:%M:%S'.
+
+`%t'
+ A TAB character.
+
+`%k'
+ is replaced by the hour (24-hour clock) as a decimal number (0-23).
+ Single digit numbers are padded with a blank.
+
+`%l'
+ is replaced by the hour (12-hour clock) as a decimal number (1-12).
+ Single digit numbers are padded with a blank.
+
+`%C'
+ The century, as a number between 00 and 99.
+
+`%u'
+ is replaced by the weekday as a decimal number [1 (Monday)-7].
+
+`%V'
+ is replaced by the week number of the year (the first Monday as
+ the first day of week 1) as a decimal number (01-53). The method
+ for determining the week number is as specified by ISO 8601 (to
+ wit: if the week containing January 1 has four or more days in the
+ new year, then it is week 1, otherwise it is week 53 of the
+ previous year and the next week is week 1).
+
+`%Ec %EC %Ex %Ey %EY %Od %Oe %OH %OI'
+`%Om %OM %OS %Ou %OU %OV %Ow %OW %Oy'
+ These are "alternate representations" for the specifications that
+ use only the second letter (`%c', `%C', and so on). They are
+ recognized, but their normal representations are used. (These
+ facilitate compliance with the POSIX `date' utility.)
+
+`%v'
+ The date in VMS format (e.g. 20-JUN-1991).
+
+ Here are two examples that use `strftime'. The first is an `awk'
+version of the C `ctime' function. (This is a user defined function,
+which we have not discussed yet. *Note User-defined Functions:
+User-defined, for more information.)
+
+ # ctime.awk
+ #
+ # awk version of C ctime(3) function
+
+ function ctime(ts, format)
+ {
+ format = "%a %b %e %H:%M:%S %Z %Y"
+ if (ts == 0)
+ ts = systime() # use current time as default
+ return strftime(format, ts)
+ }
+
+ This next example is an `awk' implementation of the POSIX `date'
+utility. Normally, the `date' utility prints the current date and time
+of day in a well known format. However, if you provide an argument to
+it that begins with a `+', `date' will copy non-format specifier
+characters to the standard output, and will interpret the current time
+according to the format specifiers in the string. For example:
+
+ date '+Today is %A, %B %d, %Y.'
+
+might print
+
+ Today is Thursday, July 11, 1991.
+
+ Here is the `awk' version of the `date' utility.
+
+ #! /usr/bin/gawk -f
+ #
+ # date --- implement the P1003.2 Draft 11 'date' command
+ #
+ # Bug: does not recognize the -u argument.
+
+ BEGIN \
+ {
+ format = "%a %b %e %H:%M:%S %Z %Y"
+ exitval = 0
+
+ if (ARGC > 2)
+ exitval = 1
+ else if (ARGC == 2) {
+ format = ARGV[1]
+ if (format ~ /^\+/)
+ format = substr(format, 2) # remove leading +
+ }
+ print strftime(format)
+ exit exitval
+ }
+
+
+File: gawk.info, Node: User-defined, Next: Built-in Variables, Prev: Built-in, Up: Top
+
+User-defined Functions
+**********************
+
+ Complicated `awk' programs can often be simplified by defining your
+own functions. User-defined functions can be called just like built-in
+ones (*note Function Calls::.), but it is up to you to define them--to
+tell `awk' what they should do.
+
+* Menu:
+
+* Definition Syntax:: How to write definitions and what they mean.
+* Function Example:: An example function definition and
+ what it does.
+* Function Caveats:: Things to watch out for.
+* Return Statement:: Specifying the value a function returns.
+
+
+File: gawk.info, Node: Definition Syntax, Next: Function Example, Prev: User-defined, Up: User-defined
+
+Syntax of Function Definitions
+==============================
+
+ Definitions of functions can appear anywhere between the rules of the
+`awk' program. Thus, the general form of an `awk' program is extended
+to include sequences of rules *and* user-defined function definitions.
+
+ The definition of a function named NAME looks like this:
+
+ function NAME (PARAMETER-LIST) {
+ BODY-OF-FUNCTION
+ }
+
+NAME is the name of the function to be defined. A valid function name
+is like a valid variable name: a sequence of letters, digits and
+underscores, not starting with a digit. Functions share the same pool
+of names as variables and arrays.
+
+ PARAMETER-LIST is a list of the function's arguments and local
+variable names, separated by commas. When the function is called, the
+argument names are used to hold the argument values given in the call.
+The local variables are initialized to the null string.
+
+ The BODY-OF-FUNCTION consists of `awk' statements. It is the most
+important part of the definition, because it says what the function
+should actually *do*. The argument names exist to give the body a way
+to talk about the arguments; local variables, to give the body places
+to keep temporary values.
+
+ Argument names are not distinguished syntactically from local
+variable names; instead, the number of arguments supplied when the
+function is called determines how many argument variables there are.
+Thus, if three argument values are given, the first three names in
+PARAMETER-LIST are arguments, and the rest are local variables.
+
+ It follows that if the number of arguments is not the same in all
+calls to the function, some of the names in PARAMETER-LIST may be
+arguments on some occasions and local variables on others. Another way
+to think of this is that omitted arguments default to the null string.
+
+ Usually when you write a function you know how many names you intend
+to use for arguments and how many you intend to use as locals. By
+convention, you should write an extra space between the arguments and
+the locals, so other people can follow how your function is supposed to
+be used.
+
+ During execution of the function body, the arguments and local
+variable values hide or "shadow" any variables of the same names used
+in the rest of the program. The shadowed variables are not accessible
+in the function definition, because there is no way to name them while
+their names have been taken away for the local variables. All other
+variables used in the `awk' program can be referenced or set normally
+in the function definition.
+
+ The arguments and local variables last only as long as the function
+body is executing. Once the body finishes, the shadowed variables come
+back.
+
+ The function body can contain expressions which call functions. They
+can even call this function, either directly or by way of another
+function. When this happens, we say the function is "recursive".
+
+ There is no need in `awk' to put the definition of a function before
+all uses of the function. This is because `awk' reads the entire
+program before starting to execute any of it.
+
+ In many `awk' implementations, the keyword `function' may be
+abbreviated `func'. However, POSIX only specifies the use of the
+keyword `function'. This actually has some practical implications. If
+`gawk' is in POSIX-compatibility mode (*note Invoking `awk': Command
+Line.), then the following statement will *not* define a function:
+
+ func foo() { a = sqrt($1) ; print a }
+
+Instead it defines a rule that, for each record, concatenates the value
+of the variable `func' with the return value of the function `foo', and
+based on the truth value of the result, executes the corresponding
+action. This is probably not what was desired. (`awk' accepts this
+input as syntactically valid, since functions may be used before they
+are defined in `awk' programs.)
+
+
+File: gawk.info, Node: Function Example, Next: Function Caveats, Prev: Definition Syntax, Up: User-defined
+
+Function Definition Example
+===========================
+
+ Here is an example of a user-defined function, called `myprint', that
+takes a number and prints it in a specific format.
+
+ function myprint(num)
+ {
+ printf "%6.3g\n", num
+ }
+
+To illustrate, here is an `awk' rule which uses our `myprint' function:
+
+ $3 > 0 { myprint($3) }
+
+This program prints, in our special format, all the third fields that
+contain a positive number in our input. Therefore, when given:
+
+ 1.2 3.4 5.6 7.8
+ 9.10 11.12 -13.14 15.16
+ 17.18 19.20 21.22 23.24
+
+this program, using our function to format the results, prints:
+
+ 5.6
+ 21.2
+
+ Here is a rather contrived example of a recursive function. It
+prints a string backwards:
+
+ function rev (str, len) {
+ if (len == 0) {
+ printf "\n"
+ return
+ }
+ printf "%c", substr(str, len, 1)
+ rev(str, len - 1)
+ }
+
+
+File: gawk.info, Node: Function Caveats, Next: Return Statement, Prev: Function Example, Up: User-defined
+
+Calling User-defined Functions
+==============================
+
+ "Calling a function" means causing the function to run and do its
+job. A function call is an expression, and its value is the value
+returned by the function.
+
+ A function call consists of the function name followed by the
+arguments in parentheses. What you write in the call for the arguments
+are `awk' expressions; each time the call is executed, these
+expressions are evaluated, and the values are the actual arguments. For
+example, here is a call to `foo' with three arguments (the first being
+a string concatenation):
+
+ foo(x y, "lose", 4 * z)
+
+ *Caution:* whitespace characters (spaces and tabs) are not allowed
+ between the function name and the open-parenthesis of the argument
+ list. If you write whitespace by mistake, `awk' might think that
+ you mean to concatenate a variable with an expression in
+ parentheses. However, it notices that you used a function name
+ and not a variable name, and reports an error.
+
+ When a function is called, it is given a *copy* of the values of its
+arguments. This is called "call by value". The caller may use a
+variable as the expression for the argument, but the called function
+does not know this: it only knows what value the argument had. For
+example, if you write this code:
+
+ foo = "bar"
+ z = myfunc(foo)
+
+then you should not think of the argument to `myfunc' as being "the
+variable `foo'." Instead, think of the argument as the string value,
+`"bar"'.
+
+ If the function `myfunc' alters the values of its local variables,
+this has no effect on any other variables. In particular, if `myfunc'
+does this:
+
+ function myfunc (win) {
+ print win
+ win = "zzz"
+ print win
+ }
+
+to change its first argument variable `win', this *does not* change the
+value of `foo' in the caller. The role of `foo' in calling `myfunc'
+ended when its value, `"bar"', was computed. If `win' also exists
+outside of `myfunc', the function body cannot alter this outer value,
+because it is shadowed during the execution of `myfunc' and cannot be
+seen or changed from there.
+
+ However, when arrays are the parameters to functions, they are *not*
+copied. Instead, the array itself is made available for direct
+manipulation by the function. This is usually called "call by
+reference". Changes made to an array parameter inside the body of a
+function *are* visible outside that function. This can be *very*
+dangerous if you do not watch what you are doing. For example:
+
+ function changeit (array, ind, nvalue) {
+ array[ind] = nvalue
+ }
+
+ BEGIN {
+ a[1] = 1 ; a[2] = 2 ; a[3] = 3
+ changeit(a, 2, "two")
+ printf "a[1] = %s, a[2] = %s, a[3] = %s\n", a[1], a[2], a[3]
+ }
+
+prints `a[1] = 1, a[2] = two, a[3] = 3', because calling `changeit'
+stores `"two"' in the second element of `a'.
+
+
+File: gawk.info, Node: Return Statement, Prev: Function Caveats, Up: User-defined
+
+The `return' Statement
+======================
+
+ The body of a user-defined function can contain a `return' statement.
+This statement returns control to the rest of the `awk' program. It
+can also be used to return a value for use in the rest of the `awk'
+program. It looks like this:
+
+ return EXPRESSION
+
+ The EXPRESSION part is optional. If it is omitted, then the returned
+value is undefined and, therefore, unpredictable.
+
+ A `return' statement with no value expression is assumed at the end
+of every function definition. So if control reaches the end of the
+function body, then the function returns an unpredictable value. `awk'
+will not warn you if you use the return value of such a function; you
+will simply get unpredictable or unexpected results.
+
+ Here is an example of a user-defined function that returns a value
+for the largest number among the elements of an array:
+
+ function maxelt (vec, i, ret) {
+ for (i in vec) {
+ if (ret == "" || vec[i] > ret)
+ ret = vec[i]
+ }
+ return ret
+ }
+
+You call `maxelt' with one argument, which is an array name. The local
+variables `i' and `ret' are not intended to be arguments; while there
+is nothing to stop you from passing two or three arguments to `maxelt',
+the results would be strange. The extra space before `i' in the
+function parameter list is to indicate that `i' and `ret' are not
+supposed to be arguments. This is a convention which you should follow
+when you define functions.
+
+ Here is a program that uses our `maxelt' function. It loads an
+array, calls `maxelt', and then reports the maximum number in that
+array:
+
+ awk '
+ function maxelt (vec, i, ret) {
+ for (i in vec) {
+ if (ret == "" || vec[i] > ret)
+ ret = vec[i]
+ }
+ return ret
+ }
+
+ # Load all fields of each record into nums.
+ {
+ for(i = 1; i <= NF; i++)
+ nums[NR, i] = $i
+ }
+
+ END {
+ print maxelt(nums)
+ }'
+
+ Given the following input:
+
+ 1 5 23 8 16
+ 44 3 5 2 8 26
+ 256 291 1396 2962 100
+ -6 467 998 1101
+ 99385 11 0 225
+
+our program tells us (predictably) that:
+
+ 99385
+
+is the largest number in our array.
+
+
+File: gawk.info, Node: Built-in Variables, Next: Command Line, Prev: User-defined, Up: Top
+
+Built-in Variables
+******************
+
+ Most `awk' variables are available for you to use for your own
+purposes; they never change except when your program assigns values to
+them, and never affect anything except when your program examines them.
+
+ A few variables have special built-in meanings. Some of them `awk'
+examines automatically, so that they enable you to tell `awk' how to do
+certain things. Others are set automatically by `awk', so that they
+carry information from the internal workings of `awk' to your program.
+
+ This chapter documents all the built-in variables of `gawk'. Most
+of them are also documented in the chapters where their areas of
+activity are described.
+
+* Menu:
+
+* User-modified:: Built-in variables that you change
+ to control `awk'.
+* Auto-set:: Built-in variables where `awk'
+ gives you information.
+
+
+File: gawk.info, Node: User-modified, Next: Auto-set, Prev: Built-in Variables, Up: Built-in Variables
+
+Built-in Variables that Control `awk'
+=====================================
+
+ This is a list of the variables which you can change to control how
+`awk' does certain things.
+
+`CONVFMT'
+ This string is used by `awk' to control conversion of numbers to
+ strings (*note Conversion of Strings and Numbers: Conversion.).
+ It works by being passed, in effect, as the first argument to the
+ `sprintf' function. Its default value is `"%.6g"'. `CONVFMT' was
+ introduced by the POSIX standard.
+
+`FIELDWIDTHS'
+ This is a space separated list of columns that tells `gawk' how to
+ manage input with fixed, columnar boundaries. It is an
+ experimental feature that is still evolving. Assigning to
+ `FIELDWIDTHS' overrides the use of `FS' for field splitting.
+ *Note Reading Fixed-width Data: Constant Size, for more
+ information.
+
+ If `gawk' is in compatibility mode (*note Invoking `awk': Command
+ Line.), then `FIELDWIDTHS' has no special meaning, and field
+ splitting operations are done based exclusively on the value of
+ `FS'.
+
+`FS'
+ `FS' is the input field separator (*note Specifying how Fields are
+ Separated: Field Separators.). The value is a single-character
+ string or a multi-character regular expression that matches the
+ separations between fields in an input record.
+
+ The default value is `" "', a string consisting of a single space.
+ As a special exception, this value actually means that any
+ sequence of spaces and tabs is a single separator. It also causes
+ spaces and tabs at the beginning or end of a line to be ignored.
+
+ You can set the value of `FS' on the command line using the `-F'
+ option:
+
+ awk -F, 'PROGRAM' INPUT-FILES
+
+ If `gawk' is using `FIELDWIDTHS' for field-splitting, assigning a
+ value to `FS' will cause `gawk' to return to the normal,
+ regexp-based, field splitting.
+
+`IGNORECASE'
+ If `IGNORECASE' is nonzero, then *all* regular expression matching
+ is done in a case-independent fashion. In particular, regexp
+ matching with `~' and `!~', and the `gsub' `index', `match',
+ `split' and `sub' functions all ignore case when doing their
+ particular regexp operations. *Note:* since field splitting with
+ the value of the `FS' variable is also a regular expression
+ operation, that too is done with case ignored. *Note
+ Case-sensitivity in Matching: Case-sensitivity.
+
+ If `gawk' is in compatibility mode (*note Invoking `awk': Command
+ Line.), then `IGNORECASE' has no special meaning, and regexp
+ operations are always case-sensitive.
+
+`OFMT'
+ This string is used by `awk' to control conversion of numbers to
+ strings (*note Conversion of Strings and Numbers: Conversion.) for
+ printing with the `print' statement. It works by being passed, in
+ effect, as the first argument to the `sprintf' function. Its
+ default value is `"%.6g"'. Earlier versions of `awk' also used
+ `OFMT' to specify the format for converting numbers to strings in
+ general expressions; this has been taken over by `CONVFMT'.
+
+`OFS'
+ This is the output field separator (*note Output Separators::.).
+ It is output between the fields output by a `print' statement. Its
+ default value is `" "', a string consisting of a single space.
+
+`ORS'
+ This is the output record separator. It is output at the end of
+ every `print' statement. Its default value is a string containing
+ a single newline character, which could be written as `"\n"'.
+ (*Note Output Separators::.)
+
+`RS'
+ This is `awk''s input record separator. Its default value is a
+ string containing a single newline character, which means that an
+ input record consists of a single line of text. (*Note How Input
+ is Split into Records: Records.)
+
+`SUBSEP'
+ `SUBSEP' is the subscript separator. It has the default value of
+ `"\034"', and is used to separate the parts of the name of a
+ multi-dimensional array. Thus, if you access `foo[12,3]', it
+ really accesses `foo["12\0343"]' (*note Multi-dimensional Arrays:
+ Multi-dimensional.).
+
+
+File: gawk.info, Node: Auto-set, Prev: User-modified, Up: Built-in Variables
+
+Built-in Variables that Convey Information
+==========================================
+
+ This is a list of the variables that are set automatically by `awk'
+on certain occasions so as to provide information to your program.
+
+`ARGC'
+`ARGV'
+ The command-line arguments available to `awk' programs are stored
+ in an array called `ARGV'. `ARGC' is the number of command-line
+ arguments present. *Note Invoking `awk': Command Line. `ARGV' is
+ indexed from zero to `ARGC - 1'. For example:
+
+ awk 'BEGIN {
+ for (i = 0; i < ARGC; i++)
+ print ARGV[i]
+ }' inventory-shipped BBS-list
+
+ In this example, `ARGV[0]' contains `"awk"', `ARGV[1]' contains
+ `"inventory-shipped"', and `ARGV[2]' contains `"BBS-list"'. The
+ value of `ARGC' is 3, one more than the index of the last element
+ in `ARGV' since the elements are numbered from zero.
+
+ The names `ARGC' and `ARGV', as well the convention of indexing
+ the array from 0 to `ARGC - 1', are derived from the C language's
+ method of accessing command line arguments.
+
+ Notice that the `awk' program is not entered in `ARGV'. The other
+ special command line options, with their arguments, are also not
+ entered. But variable assignments on the command line *are*
+ treated as arguments, and do show up in the `ARGV' array.
+
+ Your program can alter `ARGC' and the elements of `ARGV'. Each
+ time `awk' reaches the end of an input file, it uses the next
+ element of `ARGV' as the name of the next input file. By storing a
+ different string there, your program can change which files are
+ read. You can use `"-"' to represent the standard input. By
+ storing additional elements and incrementing `ARGC' you can cause
+ additional files to be read.
+
+ If you decrease the value of `ARGC', that eliminates input files
+ from the end of the list. By recording the old value of `ARGC'
+ elsewhere, your program can treat the eliminated arguments as
+ something other than file names.
+
+ To eliminate a file from the middle of the list, store the null
+ string (`""') into `ARGV' in place of the file's name. As a
+ special feature, `awk' ignores file names that have been replaced
+ with the null string.
+
+`ARGIND'
+ The index in `ARGV' of the current file being processed. Every
+ time `gawk' opens a new data file for processing, it sets `ARGIND'
+ to the index in `ARGV' of the file name. Thus, the condition
+ `FILENAME == ARGV[ARGIND]' is always true.
+
+ This variable is useful in file processing; it allows you to tell
+ how far along you are in the list of data files, and to
+ distinguish between multiple successive instances of the same
+ filename on the command line.
+
+ While you can change the value of `ARGIND' within your `awk'
+ program, `gawk' will automatically set it to a new value when the
+ next file is opened.
+
+ This variable is a `gawk' extension; in other `awk' implementations
+ it is not special.
+
+`ENVIRON'
+ This is an array that contains the values of the environment. The
+ array indices are the environment variable names; the values are
+ the values of the particular environment variables. For example,
+ `ENVIRON["HOME"]' might be `/u/close'. Changing this array does
+ not affect the environment passed on to any programs that `awk'
+ may spawn via redirection or the `system' function. (In a future
+ version of `gawk', it may do so.)
+
+ Some operating systems may not have environment variables. On
+ such systems, the array `ENVIRON' is empty.
+
+`ERRNO'
+ If a system error occurs either doing a redirection for `getline',
+ during a read for `getline', or during a `close' operation, then
+ `ERRNO' will contain a string describing the error.
+
+ This variable is a `gawk' extension; in other `awk' implementations
+ it is not special.
+
+`FILENAME'
+ This is the name of the file that `awk' is currently reading. If
+ `awk' is reading from the standard input (in other words, there
+ are no files listed on the command line), `FILENAME' is set to
+ `"-"'. `FILENAME' is changed each time a new file is read (*note
+ Reading Input Files: Reading Files.).
+
+`FNR'
+ `FNR' is the current record number in the current file. `FNR' is
+ incremented each time a new record is read (*note Explicit Input
+ with `getline': Getline.). It is reinitialized to 0 each time a
+ new input file is started.
+
+`NF'
+ `NF' is the number of fields in the current input record. `NF' is
+ set each time a new record is read, when a new field is created,
+ or when `$0' changes (*note Examining Fields: Fields.).
+
+`NR'
+ This is the number of input records `awk' has processed since the
+ beginning of the program's execution. (*note How Input is Split
+ into Records: Records.). `NR' is set each time a new record is
+ read.
+
+`RLENGTH'
+ `RLENGTH' is the length of the substring matched by the `match'
+ function (*note Built-in Functions for String Manipulation: String
+ Functions.). `RLENGTH' is set by invoking the `match' function.
+ Its value is the length of the matched string, or -1 if no match
+ was found.
+
+`RSTART'
+ `RSTART' is the start-index in characters of the substring matched
+ by the `match' function (*note Built-in Functions for String
+ Manipulation: String Functions.). `RSTART' is set by invoking the
+ `match' function. Its value is the position of the string where
+ the matched substring starts, or 0 if no match was found.
+
+
+File: gawk.info, Node: Command Line, Next: Language History, Prev: Built-in Variables, Up: Top
+
+Invoking `awk'
+**************
+
+ There are two ways to run `awk': with an explicit program, or with
+one or more program files. Here are templates for both of them; items
+enclosed in `[...]' in these templates are optional.
+
+ Besides traditional one-letter POSIX-style options, `gawk' also
+supports GNU long named options.
+
+ awk [POSIX OR GNU STYLE OPTIONS] -f progfile [`--'] FILE ...
+ awk [POSIX OR GNU STYLE OPTIONS] [`--'] 'PROGRAM' FILE ...
+
+* Menu:
+
+* Options:: Command line options and their meanings.
+* Other Arguments:: Input file names and variable assignments.
+* AWKPATH Variable:: Searching directories for `awk' programs.
+* Obsolete:: Obsolete Options and/or features.
+* Undocumented:: Undocumented Options and Features.
+
+
+File: gawk.info, Node: Options, Next: Other Arguments, Prev: Command Line, Up: Command Line
+
+Command Line Options
+====================
+
+ Options begin with a minus sign, and consist of a single character.
+GNU style long named options consist of two minus signs and a keyword
+that can be abbreviated if the abbreviation allows the option to be
+uniquely identified. If the option takes an argument, then the keyword
+is immediately followed by an equals sign (`=') and the argument's
+value. For brevity, the discussion below only refers to the
+traditional short options; however the long and short options are
+interchangeable in all contexts.
+
+ Each long named option for `gawk' has a corresponding POSIX-style
+option. The options and their meanings are as follows:
+
+`-F FS'
+`--field-separator=FS'
+ Sets the `FS' variable to FS (*note Specifying how Fields are
+ Separated: Field Separators.).
+
+`-f SOURCE-FILE'
+`--file=SOURCE-FILE'
+ Indicates that the `awk' program is to be found in SOURCE-FILE
+ instead of in the first non-option argument.
+
+`-v VAR=VAL'
+`--assign=VAR=VAL'
+ Sets the variable VAR to the value VAL *before* execution of the
+ program begins. Such variable values are available inside the
+ `BEGIN' rule (see below for a fuller explanation).
+
+ The `-v' option can only set one variable, but you can use it more
+ than once, setting another variable each time, like this:
+ `-v foo=1 -v bar=2'.
+
+`-W GAWK-OPT'
+ Following the POSIX standard, options that are implementation
+ specific are supplied as arguments to the `-W' option. With
+ `gawk', these arguments may be separated by commas, or quoted and
+ separated by whitespace. Case is ignored when processing these
+ options. These options also have corresponding GNU style long
+ named options. The following `gawk'-specific options are
+ available:
+
+ `-W compat'
+ `--compat'
+ Specifies "compatibility mode", in which the GNU extensions in
+ `gawk' are disabled, so that `gawk' behaves just like Unix
+ `awk'. *Note Extensions in `gawk' not in POSIX `awk':
+ POSIX/GNU, which summarizes the extensions. Also see *Note
+ Downward Compatibility and Debugging: Compatibility Mode.
+
+ `-W copyleft'
+ `-W copyright'
+ `--copyleft'
+ `--copyright'
+ Print the short version of the General Public License. This
+ option may disappear in a future version of `gawk'.
+
+ `-W help'
+ `-W usage'
+ `--help'
+ `--usage'
+ Print a "usage" message summarizing the short and long style
+ options that `gawk' accepts, and then exit.
+
+ `-W lint'
+ `--lint'
+ Provide warnings about constructs that are dubious or
+ non-portable to other `awk' implementations. Some warnings
+ are issued when `gawk' first reads your program. Others are
+ issued at run-time, as your program executes.
+
+ `-W posix'
+ `--posix'
+ Operate in strict POSIX mode. This disables all `gawk'
+ extensions (just like `-W compat'), and adds the following
+ additional restrictions:
+
+ * `\x' escape sequences are not recognized (*note Constant
+ Expressions: Constants.).
+
+ * The synonym `func' for the keyword `function' is not
+ recognized (*note Syntax of Function Definitions:
+ Definition Syntax.).
+
+ * The operators `**' and `**=' cannot be used in place of
+ `^' and `^=' (*note Arithmetic Operators: Arithmetic
+ Ops., and also *note Assignment Expressions: Assignment
+ Ops.).
+
+ * Specifying `-Ft' on the command line does not set the
+ value of `FS' to be a single tab character (*note
+ Specifying how Fields are Separated: Field Separators.).
+
+ Although you can supply both `-W compat' and `-W posix' on the
+ command line, `-W posix' will take precedence.
+
+ `-W source=PROGRAM-TEXT'
+ `--source=PROGRAM-TEXT'
+ Program source code is taken from the PROGRAM-TEXT. This
+ option allows you to mix `awk' source code in files with
+ program source code that you would enter on the command line.
+ This is particularly useful when you have library functions
+ that you wish to use from your command line programs (*note
+ The `AWKPATH' Environment Variable: AWKPATH Variable.).
+
+ `-W version'
+ `--version'
+ Prints version information for this particular copy of `gawk'.
+ This is so you can determine if your copy of `gawk' is up to
+ date with respect to whatever the Free Software Foundation is
+ currently distributing. This option may disappear in a
+ future version of `gawk'.
+
+`--'
+ Signals the end of the command line options. The following
+ arguments are not treated as options even if they begin with `-'.
+ This interpretation of `--' follows the POSIX argument parsing
+ conventions.
+
+ This is useful if you have file names that start with `-', or in
+ shell scripts, if you have file names that will be specified by
+ the user which could start with `-'.
+
+ Any other options are flagged as invalid with a warning message, but
+are otherwise ignored.
+
+ In compatibility mode, as a special case, if the value of FS supplied
+to the `-F' option is `t', then `FS' is set to the tab character
+(`"\t"'). This is only true for `-W compat', and not for `-W posix'
+(*note Specifying how Fields are Separated: Field Separators.).
+
+ If the `-f' option is *not* used, then the first non-option command
+line argument is expected to be the program text.
+
+ The `-f' option may be used more than once on the command line. If
+it is, `awk' reads its program source from all of the named files, as
+if they had been concatenated together into one big file. This is
+useful for creating libraries of `awk' functions. Useful functions can
+be written once, and then retrieved from a standard place, instead of
+having to be included into each individual program. You can still type
+in a program at the terminal and use library functions, by specifying
+`-f /dev/tty'. `awk' will read a file from the terminal to use as part
+of the `awk' program. After typing your program, type `Control-d' (the
+end-of-file character) to terminate it. (You may also use `-f -' to
+read program source from the standard input, but then you will not be
+able to also use the standard input as a source of data.)
+
+ Because it is clumsy using the standard `awk' mechanisms to mix
+source file and command line `awk' programs, `gawk' provides the
+`--source' option. This does not require you to pre-empt the standard
+input for your source code, and allows you to easily mix command line
+and library source code (*note The `AWKPATH' Environment Variable:
+AWKPATH Variable.).
+
+ If no `-f' or `--source' option is specified, then `gawk' will use
+the first non-option command line argument as the text of the program
+source code.
+
+
+File: gawk.info, Node: Other Arguments, Next: AWKPATH Variable, Prev: Options, Up: Command Line
+
+Other Command Line Arguments
+============================
+
+ Any additional arguments on the command line are normally treated as
+input files to be processed in the order specified. However, an
+argument that has the form `VAR=VALUE', means to assign the value VALUE
+to the variable VAR--it does not specify a file at all.
+
+ All these arguments are made available to your `awk' program in the
+`ARGV' array (*note Built-in Variables::.). Command line options and
+the program text (if present) are omitted from the `ARGV' array. All
+other arguments, including variable assignments, are included.
+
+ The distinction between file name arguments and variable-assignment
+arguments is made when `awk' is about to open the next input file. At
+that point in execution, it checks the "file name" to see whether it is
+really a variable assignment; if so, `awk' sets the variable instead of
+reading a file.
+
+ Therefore, the variables actually receive the specified values after
+all previously specified files have been read. In particular, the
+values of variables assigned in this fashion are *not* available inside
+a `BEGIN' rule (*note `BEGIN' and `END' Special Patterns: BEGIN/END.),
+since such rules are run before `awk' begins scanning the argument list.
+The values given on the command line are processed for escape sequences
+(*note Constant Expressions: Constants.).
+
+ In some earlier implementations of `awk', when a variable assignment
+occurred before any file names, the assignment would happen *before*
+the `BEGIN' rule was executed. Some applications came to depend upon
+this "feature." When `awk' was changed to be more consistent, the `-v'
+option was added to accommodate applications that depended upon this
+old behavior.
+
+ The variable assignment feature is most useful for assigning to
+variables such as `RS', `OFS', and `ORS', which control input and
+output formats, before scanning the data files. It is also useful for
+controlling state if multiple passes are needed over a data file. For
+example:
+
+ awk 'pass == 1 { PASS 1 STUFF }
+ pass == 2 { PASS 2 STUFF }' pass=1 datafile pass=2 datafile
+
+ Given the variable assignment feature, the `-F' option is not
+strictly necessary. It remains for historical compatibility.
+
+
+File: gawk.info, Node: AWKPATH Variable, Next: Obsolete, Prev: Other Arguments, Up: Command Line
+
+The `AWKPATH' Environment Variable
+==================================
+
+ The previous section described how `awk' program files can be named
+on the command line with the `-f' option. In some `awk'
+implementations, you must supply a precise path name for each program
+file, unless the file is in the current directory.
+
+ But in `gawk', if the file name supplied in the `-f' option does not
+contain a `/', then `gawk' searches a list of directories (called the
+"search path"), one by one, looking for a file with the specified name.
+
+ The search path is actually a string consisting of directory names
+separated by colons. `gawk' gets its search path from the `AWKPATH'
+environment variable. If that variable does not exist, `gawk' uses the
+default path, which is `.:/usr/lib/awk:/usr/local/lib/awk'. (Programs
+written by system administrators should use an `AWKPATH' variable that
+does not include the current directory, `.'.)
+
+ The search path feature is particularly useful for building up
+libraries of useful `awk' functions. The library files can be placed
+in a standard directory that is in the default path, and then specified
+on the command line with a short file name. Otherwise, the full file
+name would have to be typed for each file.
+
+ By combining the `--source' and `-f' options, your command line
+`awk' programs can use facilities in `awk' library files.
+
+ Path searching is not done if `gawk' is in compatibility mode. This
+is true for both `-W compat' and `-W posix'. *Note Command Line
+Options: Options.
+
+ *Note:* if you want files in the current directory to be found, you
+must include the current directory in the path, either by writing `.'
+as an entry in the path, or by writing a null entry in the path. (A
+null entry is indicated by starting or ending the path with a colon, or
+by placing two colons next to each other (`::').) If the current
+directory is not included in the path, then files cannot be found in
+the current directory. This path search mechanism is identical to the
+shell's.
+
+
+File: gawk.info, Node: Obsolete, Next: Undocumented, Prev: AWKPATH Variable, Up: Command Line
+
+Obsolete Options and/or Features
+================================
+
+ This section describes features and/or command line options from the
+previous release of `gawk' that are either not available in the current
+version, or that are still supported but deprecated (meaning that they
+will *not* be in the next release).
+
+ For version 2.15 of `gawk', the following command line options from
+version 2.11.1 are no longer recognized.
+
+`-c'
+ Use `-W compat' instead.
+
+`-V'
+ Use `-W version' instead.
+
+`-C'
+ Use `-W copyright' instead.
+
+`-a'
+`-e'
+ These options produce an "unrecognized option" error message but
+ have no effect on the execution of `gawk'. The POSIX standard now
+ specifies traditional `awk' regular expressions for the `awk'
+ utility.
+
+ The public-domain version of `strftime' that is distributed with
+`gawk' changed for the 2.14 release. The `%V' conversion specifier
+that used to generate the date in VMS format was changed to `%v'. This
+is because the POSIX standard for the `date' utility now specifies a
+`%V' conversion specifier. *Note Functions for Dealing with Time
+Stamps: Time Functions, for details.
+
+
+File: gawk.info, Node: Undocumented, Prev: Obsolete, Up: Command Line
+
+Undocumented Options and Features
+=================================
+
+ This section intentionally left blank.
+
+
+File: gawk.info, Node: Language History, Next: Installation, Prev: Command Line, Up: Top
+
+The Evolution of the `awk' Language
+***********************************
+
+ This manual describes the GNU implementation of `awk', which is
+patterned after the POSIX specification. Many `awk' users are only
+familiar with the original `awk' implementation in Version 7 Unix,
+which is also the basis for the version in Berkeley Unix (through
+4.3-Reno). This chapter briefly describes the evolution of the `awk'
+language.
+
+* Menu:
+
+* V7/S5R3.1:: The major changes between V7 and
+ System V Release 3.1.
+* S5R4:: Minor changes between System V
+ Releases 3.1 and 4.
+* POSIX:: New features from the POSIX standard.
+* POSIX/GNU:: The extensions in `gawk'
+ not in POSIX `awk'.
+
diff --git a/gawk.info-7 b/gawk.info-7
new file mode 100644
index 00000000..b3ac7254
--- /dev/null
+++ b/gawk.info-7
@@ -0,0 +1,1265 @@
+This is Info file gawk.info, produced by Makeinfo-1.54 from the input
+file gawk.texi.
+
+ This file documents `awk', a program that you can use to select
+particular records in a file and perform operations upon them.
+
+ This is Edition 0.15 of `The GAWK Manual',
+for the 2.15 version of the GNU implementation
+of AWK.
+
+ Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that
+the entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Foundation.
+
+
+File: gawk.info, Node: V7/S5R3.1, Next: S5R4, Prev: Language History, Up: Language History
+
+Major Changes between V7 and S5R3.1
+===================================
+
+ The `awk' language evolved considerably between the release of
+Version 7 Unix (1978) and the new version first made widely available in
+System V Release 3.1 (1987). This section summarizes the changes, with
+cross-references to further details.
+
+ * The requirement for `;' to separate rules on a line (*note `awk'
+ Statements versus Lines: Statements/Lines.).
+
+ * User-defined functions, and the `return' statement (*note
+ User-defined Functions: User-defined.).
+
+ * The `delete' statement (*note The `delete' Statement: Delete.).
+
+ * The `do'-`while' statement (*note The `do'-`while' Statement: Do
+ Statement.).
+
+ * The built-in functions `atan2', `cos', `sin', `rand' and `srand'
+ (*note Numeric Built-in Functions: Numeric Functions.).
+
+ * The built-in functions `gsub', `sub', and `match' (*note Built-in
+ Functions for String Manipulation: String Functions.).
+
+ * The built-in functions `close', which closes an open file, and
+ `system', which allows the user to execute operating system
+ commands (*note Built-in Functions for Input/Output: I/O
+ Functions.).
+
+ * The `ARGC', `ARGV', `FNR', `RLENGTH', `RSTART', and `SUBSEP'
+ built-in variables (*note Built-in Variables::.).
+
+ * The conditional expression using the operators `?' and `:' (*note
+ Conditional Expressions: Conditional Exp.).
+
+ * The exponentiation operator `^' (*note Arithmetic Operators:
+ Arithmetic Ops.) and its assignment operator form `^=' (*note
+ Assignment Expressions: Assignment Ops.).
+
+ * C-compatible operator precedence, which breaks some old `awk'
+ programs (*note Operator Precedence (How Operators Nest):
+ Precedence.).
+
+ * Regexps as the value of `FS' (*note Specifying how Fields are
+ Separated: Field Separators.), and as the third argument to the
+ `split' function (*note Built-in Functions for String
+ Manipulation: String Functions.).
+
+ * Dynamic regexps as operands of the `~' and `!~' operators (*note
+ How to Use Regular Expressions: Regexp Usage.).
+
+ * Escape sequences (*note Constant Expressions: Constants.) in
+ regexps.
+
+ * The escape sequences `\b', `\f', and `\r' (*note Constant
+ Expressions: Constants.).
+
+ * Redirection of input for the `getline' function (*note Explicit
+ Input with `getline': Getline.).
+
+ * Multiple `BEGIN' and `END' rules (*note `BEGIN' and `END' Special
+ Patterns: BEGIN/END.).
+
+ * Simulated multi-dimensional arrays (*note Multi-dimensional
+ Arrays: Multi-dimensional.).
+
+
+File: gawk.info, Node: S5R4, Next: POSIX, Prev: V7/S5R3.1, Up: Language History
+
+Changes between S5R3.1 and S5R4
+===============================
+
+ The System V Release 4 version of Unix `awk' added these features
+(some of which originated in `gawk'):
+
+ * The `ENVIRON' variable (*note Built-in Variables::.).
+
+ * Multiple `-f' options on the command line (*note Invoking `awk':
+ Command Line.).
+
+ * The `-v' option for assigning variables before program execution
+ begins (*note Invoking `awk': Command Line.).
+
+ * The `--' option for terminating command line options.
+
+ * The `\a', `\v', and `\x' escape sequences (*note Constant
+ Expressions: Constants.).
+
+ * A defined return value for the `srand' built-in function (*note
+ Numeric Built-in Functions: Numeric Functions.).
+
+ * The `toupper' and `tolower' built-in string functions for case
+ translation (*note Built-in Functions for String Manipulation:
+ String Functions.).
+
+ * A cleaner specification for the `%c' format-control letter in the
+ `printf' function (*note Using `printf' Statements for Fancier
+ Printing: Printf.).
+
+ * The ability to dynamically pass the field width and precision
+ (`"%*.*d"') in the argument list of the `printf' function (*note
+ Using `printf' Statements for Fancier Printing: Printf.).
+
+ * The use of constant regexps such as `/foo/' as expressions, where
+ they are equivalent to use of the matching operator, as in `$0 ~
+ /foo/' (*note Constant Expressions: Constants.).
+
+
+File: gawk.info, Node: POSIX, Next: POSIX/GNU, Prev: S5R4, Up: Language History
+
+Changes between S5R4 and POSIX `awk'
+====================================
+
+ The POSIX Command Language and Utilities standard for `awk'
+introduced the following changes into the language:
+
+ * The use of `-W' for implementation-specific options.
+
+ * The use of `CONVFMT' for controlling the conversion of numbers to
+ strings (*note Conversion of Strings and Numbers: Conversion.).
+
+ * The concept of a numeric string, and tighter comparison rules to go
+ with it (*note Comparison Expressions: Comparison Ops.).
+
+ * More complete documentation of many of the previously undocumented
+ features of the language.
+
+
+File: gawk.info, Node: POSIX/GNU, Prev: POSIX, Up: Language History
+
+Extensions in `gawk' not in POSIX `awk'
+=======================================
+
+ The GNU implementation, `gawk', adds these features:
+
+ * The `AWKPATH' environment variable for specifying a path search for
+ the `-f' command line option (*note Invoking `awk': Command Line.).
+
+ * The various `gawk' specific features available via the `-W'
+ command line option (*note Invoking `awk': Command Line.).
+
+ * The `ARGIND' variable, that tracks the movement of `FILENAME'
+ through `ARGV'. (*note Built-in Variables::.).
+
+ * The `ERRNO' variable, that contains the system error message when
+ `getline' returns -1, or when `close' fails. (*note Built-in
+ Variables::.).
+
+ * The `IGNORECASE' variable and its effects (*note Case-sensitivity
+ in Matching: Case-sensitivity.).
+
+ * The `FIELDWIDTHS' variable and its effects (*note Reading
+ Fixed-width Data: Constant Size.).
+
+ * The `next file' statement for skipping to the next data file
+ (*note The `next file' Statement: Next File Statement.).
+
+ * The `systime' and `strftime' built-in functions for obtaining and
+ printing time stamps (*note Functions for Dealing with Time
+ Stamps: Time Functions.).
+
+ * The `/dev/stdin', `/dev/stdout', `/dev/stderr', and `/dev/fd/N'
+ file name interpretation (*note Standard I/O Streams: Special
+ Files.).
+
+ * The `-W compat' option to turn off these extensions (*note
+ Invoking `awk': Command Line.).
+
+ * The `-W posix' option for full POSIX compliance (*note Invoking
+ `awk': Command Line.).
+
+
+File: gawk.info, Node: Installation, Next: Gawk Summary, Prev: Language History, Up: Top
+
+Installing `gawk'
+*****************
+
+ This chapter provides instructions for installing `gawk' on the
+various platforms that are supported by the developers. The primary
+developers support Unix (and one day, GNU), while the other ports were
+contributed. The file `ACKNOWLEDGMENT' in the `gawk' distribution
+lists the electronic mail addresses of the people who did the
+respective ports.
+
+* Menu:
+
+* Gawk Distribution:: What is in the `gawk' distribution.
+* Unix Installation:: Installing `gawk' under various versions
+ of Unix.
+* VMS Installation:: Installing `gawk' on VMS.
+* MS-DOS Installation:: Installing `gawk' on MS-DOS.
+* Atari Installation:: Installing `gawk' on the Atari ST.
+
+
+File: gawk.info, Node: Gawk Distribution, Next: Unix Installation, Prev: Installation, Up: Installation
+
+The `gawk' Distribution
+=======================
+
+ This section first describes how to get and extract the `gawk'
+distribution, and then discusses what is in the various files and
+subdirectories.
+
+* Menu:
+
+* Extracting:: How to get and extract the distribution.
+* Distribution contents:: What is in the distribution.
+
+
+File: gawk.info, Node: Extracting, Next: Distribution contents, Prev: Gawk Distribution, Up: Gawk Distribution
+
+Getting the `gawk' Distribution
+-------------------------------
+
+ `gawk' is distributed as a `tar' file compressed with the GNU Zip
+program, `gzip'. You can get it via anonymous `ftp' to the Internet
+host `prep.ai.mit.edu'. Like all GNU software, it will be archived at
+other well known systems, from which it will be possible to use some
+sort of anonymous `uucp' to obtain the distribution as well. You can
+also order `gawk' on tape or CD-ROM directly from the Free Software
+Foundation. (The address is on the copyright page.) Doing so directly
+contributes to the support of the foundation and to the production of
+more free software.
+
+ Once you have the distribution (for example, `gawk-2.15.0.tar.z'),
+first use `gzip' to expand the file, and then use `tar' to extract it.
+You can use the following pipeline to produce the `gawk' distribution:
+
+ # Under System V, add 'o' to the tar flags
+ gzip -d -c gawk-2.15.0.tar.z | tar -xvpf -
+
+This will create a directory named `gawk-2.15' in the current directory.
+
+ The distribution file name is of the form `gawk-2.15.N.tar.Z'. The
+N represents a "patchlevel", meaning that minor bugs have been fixed in
+the major release. The current patchlevel is 0, but when retrieving
+distributions, you should get the version with the highest patchlevel.
+
+ If you are not on a Unix system, you will need to make other
+arrangements for getting and extracting the `gawk' distribution. You
+should consult a local expert.
+
+
+File: gawk.info, Node: Distribution contents, Prev: Extracting, Up: Gawk Distribution
+
+Contents of the `gawk' Distribution
+-----------------------------------
+
+ `gawk' has a number of C source files, documentation files,
+subdirectories and files related to the configuration process (*note
+Compiling and Installing `gawk' on Unix: Unix Installation.), and
+several subdirectories related to different, non-Unix, operating
+systems.
+
+various `.c', `.y', and `.h' files
+ The C and YACC source files are the actual `gawk' source code.
+
+`README'
+`README.VMS'
+`README.dos'
+`README.rs6000'
+`README.ultrix'
+ Descriptive files: `README' for `gawk' under Unix, and the rest
+ for the various hardware and software combinations.
+
+`PORTS'
+ A list of systems to which `gawk' has been ported, and which have
+ successfully run the test suite.
+
+`ACKNOWLEDGMENT'
+ A list of the people who contributed major parts of the code or
+ documentation.
+
+`NEWS'
+ A list of changes to `gawk' since the last release or patch.
+
+`COPYING'
+ The GNU General Public License.
+
+`FUTURES'
+ A brief list of features and/or changes being contemplated for
+ future releases, with some indication of the time frame for the
+ feature, based on its difficulty.
+
+`LIMITATIONS'
+ A list of those factors that limit `gawk''s performance. Most of
+ these depend on the hardware or operating system software, and are
+ not limits in `gawk' itself.
+
+`PROBLEMS'
+ A file describing known problems with the current release.
+
+`gawk.1'
+ The `troff' source for a manual page describing `gawk'.
+
+`gawk.texinfo'
+ The `texinfo' source file for this Info file. It should be
+ processed with TeX to produce a printed manual, and with
+ `makeinfo' to produce the Info file.
+
+`Makefile.in'
+`config'
+`config.in'
+`configure'
+`missing'
+`mungeconf'
+ These files and subdirectories are used when configuring `gawk'
+ for various Unix systems. They are explained in detail in *Note
+ Compiling and Installing `gawk' on Unix: Unix Installation.
+
+`atari'
+ Files needed for building `gawk' on an Atari ST. *Note Installing
+ `gawk' on the Atari ST: Atari Installation, for details.
+
+`pc'
+ Files needed for building `gawk' under MS-DOS. *Note Installing
+ `gawk' on MS-DOS: MS-DOS Installation, for details.
+
+`vms'
+ Files needed for building `gawk' under VMS. *Note Compiling
+ Installing and Running `gawk' on VMS: VMS Installation, for
+ details.
+
+`test'
+ Many interesting `awk' programs, provided as a test suite for
+ `gawk'. You can use `make test' from the top level `gawk'
+ directory to run your version of `gawk' against the test suite.
+ If `gawk' successfully passes `make test' then you can be
+ confident of a successful port.
+
+
+File: gawk.info, Node: Unix Installation, Next: VMS Installation, Prev: Gawk Distribution, Up: Installation
+
+Compiling and Installing `gawk' on Unix
+=======================================
+
+ Often, you can compile and install `gawk' by typing only two
+commands. However, if you do not use a supported system, you may need
+to configure `gawk' for your system yourself.
+
+* Menu:
+
+* Quick Installation:: Compiling `gawk' on a
+ supported Unix version.
+* Configuration Philosophy:: How it's all supposed to work.
+* New Configurations:: What to do if there is no supplied
+ configuration for your system.
+
+
+File: gawk.info, Node: Quick Installation, Next: Configuration Philosophy, Prev: Unix Installation, Up: Unix Installation
+
+Compiling `gawk' for a Supported Unix Version
+---------------------------------------------
+
+ After you have extracted the `gawk' distribution, `cd' to
+`gawk-2.15'. Look in the `config' subdirectory for a file that matches
+your hardware/software combination. In general, only the software is
+relevant; for example `sunos41' is used for SunOS 4.1, on both Sun 3
+and Sun 4 hardware.
+
+ If you find such a file, run the command:
+
+ # assume you have SunOS 4.1
+ ./configure sunos41
+
+ This produces a `Makefile' and `config.h' tailored to your system.
+You may wish to edit the `Makefile' to use a different C compiler, such
+as `gcc', the GNU C compiler, if you have it. You may also wish to
+change the `CFLAGS' variable, which controls the command line options
+that are passed to the C compiler (such as optimization levels, or
+compiling for debugging).
+
+ After you have configured `Makefile' and `config.h', type:
+
+ make
+
+and shortly thereafter, you should have an executable version of `gawk'.
+That's all there is to it!
+
+
+File: gawk.info, Node: Configuration Philosophy, Next: New Configurations, Prev: Quick Installation, Up: Unix Installation
+
+The Configuration Process
+-------------------------
+
+ (This section is of interest only if you know something about using
+the C language and the Unix operating system.)
+
+ The source code for `gawk' generally attempts to adhere to industry
+standards wherever possible. This means that `gawk' uses library
+routines that are specified by the ANSI C standard and by the POSIX
+operating system interface standard. When using an ANSI C compiler,
+function prototypes are provided to help improve the compile-time
+checking.
+
+ Many older Unix systems do not support all of either the ANSI or the
+POSIX standards. The `missing' subdirectory in the `gawk' distribution
+contains replacement versions of those subroutines that are most likely
+to be missing.
+
+ The `config.h' file that is created by the `configure' program
+contains definitions that describe features of the particular operating
+system where you are attempting to compile `gawk'. For the most part,
+it lists which standard subroutines are *not* available. For example,
+if your system lacks the `getopt' routine, then `GETOPT_MISSING' would
+be defined.
+
+ `config.h' also defines constants that describe facts about your
+variant of Unix. For example, there may not be an `st_blksize' element
+in the `stat' structure. In this case `BLKSIZE_MISSING' would be
+defined.
+
+ Based on the list in `config.h' of standard subroutines that are
+missing, `missing.c' will do a `#include' of the appropriate file(s)
+from the `missing' subdirectory.
+
+ Conditionally compiled code in the other source files relies on the
+other definitions in the `config.h' file.
+
+ Besides creating `config.h', `configure' produces a `Makefile' from
+`Makefile.in'. There are a number of lines in `Makefile.in' that are
+system or feature specific. For example, there is line that begins
+with `##MAKE_ALLOCA_C##'. This is normally a comment line, since it
+starts with `#'. If a configuration file has `MAKE_ALLOCA_C' in it,
+then `configure' will delete the `##MAKE_ALLOCA_C##' from the beginning
+of the line. This will enable the rules in the `Makefile' that use a C
+version of `alloca'. There are several similar features that work in
+this fashion.
+
+
+File: gawk.info, Node: New Configurations, Prev: Configuration Philosophy, Up: Unix Installation
+
+Configuring `gawk' for a New System
+-----------------------------------
+
+ (This section is of interest only if you know something about using
+the C language and the Unix operating system, and if you have to install
+`gawk' on a system that is not supported by the `gawk' distribution.
+If you are a C or Unix novice, get help from a local expert.)
+
+ If you need to configure `gawk' for a Unix system that is not
+supported in the distribution, first see *Note The Configuration
+Process: Configuration Philosophy. Then, copy `config.in' to
+`config.h', and copy `Makefile.in' to `Makefile'.
+
+ Next, edit both files. Both files are liberally commented, and the
+necessary changes should be straightforward.
+
+ While editing `config.h', you need to determine what library
+routines you do or do not have by consulting your system documentation,
+or by perusing your actual libraries using the `ar' or `nm' utilities.
+In the worst case, simply do not define *any* of the macros for missing
+subroutines. When you compile `gawk', the final link-editing step will
+fail. The link editor will provide you with a list of unresolved
+external references--these are the missing subroutines. Edit
+`config.h' again and recompile, and you should be set.
+
+ Editing the `Makefile' should also be straightforward. Enable or
+disable the lines that begin with `##MAKE_WHATEVER##', as appropriate.
+Select the correct C compiler and `CFLAGS' for it. Then run `make'.
+
+ Getting a correct configuration is likely to be an iterative process.
+Do not be discouraged if it takes you several tries. If you have no
+luck whatsoever, please report your system type, and the steps you took.
+Once you do have a working configuration, please send it to the
+maintainers so that support for your system can be added to the
+official release.
+
+ *Note Reporting Problems and Bugs: Bugs, for information on how to
+report problems in configuring `gawk'. You may also use the same
+mechanisms for sending in new configurations.
+
+
+File: gawk.info, Node: VMS Installation, Next: MS-DOS Installation, Prev: Unix Installation, Up: Installation
+
+Compiling, Installing, and Running `gawk' on VMS
+================================================
+
+ This section describes how to compile and install `gawk' under VMS.
+
+* Menu:
+
+* VMS Compilation:: How to compile `gawk' under VMS.
+* VMS Installation Details:: How to install `gawk' under VMS.
+* VMS Running:: How to run `gawk' under VMS.
+* VMS POSIX:: Alternate instructions for VMS POSIX.
+
+
+File: gawk.info, Node: VMS Compilation, Next: VMS Installation Details, Prev: VMS Installation, Up: VMS Installation
+
+Compiling `gawk' under VMS
+--------------------------
+
+ To compile `gawk' under VMS, there is a `DCL' command procedure that
+will issue all the necessary `CC' and `LINK' commands, and there is
+also a `Makefile' for use with the `MMS' utility. From the source
+directory, use either
+
+ $ @[.VMS]VMSBUILD.COM
+
+or
+
+ $ MMS/DESCRIPTION=[.VMS]DECSRIP.MMS GAWK
+
+ Depending upon which C compiler you are using, follow one of the sets
+of instructions in this table:
+
+VAX C V3.x
+ Use either `vmsbuild.com' or `descrip.mms' as is. These use
+ `CC/OPTIMIZE=NOLINE', which is essential for Version 3.0.
+
+VAX C V2.x
+ You must have Version 2.3 or 2.4; older ones won't work. Edit
+ either `vmsbuild.com' or `descrip.mms' according to the comments
+ in them. For `vmsbuild.com', this just entails removing two `!'
+ delimiters. Also edit `config.h' (which is a copy of file
+ `[.config]vms-conf.h') and comment out or delete the two lines
+ `#define __STDC__ 0' and `#define VAXC_BUILTINS' near the end.
+
+GNU C
+ Edit `vmsbuild.com' or `descrip.mms'; the changes are different
+ from those for VAX C V2.x, but equally straightforward. No
+ changes to `config.h' should be needed.
+
+DEC C
+ Edit `vmsbuild.com' or `descrip.mms' according to their comments.
+ No changes to `config.h' should be needed.
+
+ `gawk' 2.15 has been tested under VAX/VMS 5.5-1 using VAX C V3.2,
+GNU C 1.40 and 2.3. It should work without modifications for VMS V4.6
+and up.
+
+
+File: gawk.info, Node: VMS Installation Details, Next: VMS Running, Prev: VMS Compilation, Up: VMS Installation
+
+Installing `gawk' on VMS
+------------------------
+
+ To install `gawk', all you need is a "foreign" command, which is a
+`DCL' symbol whose value begins with a dollar sign.
+
+ $ GAWK :== $device:[directory]GAWK
+
+(Substitute the actual location of `gawk.exe' for
+`device:[directory]'.) The symbol should be placed in the `login.com'
+of any user who wishes to run `gawk', so that it will be defined every
+time the user logs on. Alternatively, the symbol may be placed in the
+system-wide `sylogin.com' procedure, which will allow all users to run
+`gawk'.
+
+ Optionally, the help entry can be loaded into a VMS help library:
+
+ $ LIBRARY/HELP SYS$HELP:HELPLIB [.VMS]GAWK.HLP
+
+(You may want to substitute a site-specific help library rather than
+the standard VMS library `HELPLIB'.) After loading the help text,
+
+ $ HELP GAWK
+
+will provide information about both the `gawk' implementation and the
+`awk' programming language.
+
+ The logical name `AWK_LIBRARY' can designate a default location for
+`awk' program files. For the `-f' option, if the specified filename
+has no device or directory path information in it, `gawk' will look in
+the current directory first, then in the directory specified by the
+translation of `AWK_LIBRARY' if the file was not found. If after
+searching in both directories, the file still is not found, then `gawk'
+appends the suffix `.awk' to the filename and the file search will be
+re-tried. If `AWK_LIBRARY' is not defined, that portion of the file
+search will fail benignly.
+
+
+File: gawk.info, Node: VMS Running, Next: VMS POSIX, Prev: VMS Installation Details, Up: VMS Installation
+
+Running `gawk' on VMS
+---------------------
+
+ Command line parsing and quoting conventions are significantly
+different on VMS, so examples in this manual or from other sources
+often need minor changes. They *are* minor though, and all `awk'
+programs should run correctly.
+
+ Here are a couple of trivial tests:
+
+ $ gawk -- "BEGIN {print ""Hello, World!""}"
+ $ gawk -"W" version ! could also be -"W version" or "-W version"
+
+Note that upper-case and mixed-case text must be quoted.
+
+ The VMS port of `gawk' includes a `DCL'-style interface in addition
+to the original shell-style interface (see the help entry for details).
+One side-effect of dual command line parsing is that if there is only a
+single parameter (as in the quoted string program above), the command
+becomes ambiguous. To work around this, the normally optional `--'
+flag is required to force Unix style rather than `DCL' parsing. If any
+other dash-type options (or multiple parameters such as data files to be
+processed) are present, there is no ambiguity and `--' can be omitted.
+
+ The default search path when looking for `awk' program files
+specified by the `-f' option is `"SYS$DISK:[],AWK_LIBRARY:"'. The
+logical name `AWKPATH' can be used to override this default. The format
+of `AWKPATH' is a comma-separated list of directory specifications.
+When defining it, the value should be quoted so that it retains a single
+translation, and not a multi-translation `RMS' searchlist.
+
+
+File: gawk.info, Node: VMS POSIX, Prev: VMS Running, Up: VMS Installation
+
+Building and using `gawk' under VMS POSIX
+-----------------------------------------
+
+ Ignore the instructions above, although `vms/gawk.hlp' should still
+be made available in a help library. Make sure that the two scripts,
+`configure' and `mungeconf', are executable; use `chmod +x' on them if
+necessary. Then execute the following commands:
+
+ $ POSIX
+ psx> configure vms-posix
+ psx> make awktab.c gawk
+
+The first command will construct files `config.h' and `Makefile' out of
+templates. The second command will compile and link `gawk'. Due to a
+`make' bug in VMS POSIX V1.0 and V1.1, the file `awktab.c' must be
+given as an explicit target or it will not be built and the final link
+step will fail. Ignore the warning `"Could not find lib m in lib
+list"'; it is harmless, caused by the explicit use of `-lm' as a linker
+option which is not needed under VMS POSIX. Under V1.1 (but not V1.0)
+a problem with the `yacc' skeleton `/etc/yyparse.c' will cause a
+compiler warning for `awktab.c', followed by a linker warning about
+compilation warnings in the resulting object module. These warnings
+can be ignored.
+
+ Once built, `gawk' will work like any other shell utility. Unlike
+the normal VMS port of `gawk', no special command line manipulation is
+needed in the VMS POSIX environment.
+
+
+File: gawk.info, Node: MS-DOS Installation, Next: Atari Installation, Prev: VMS Installation, Up: Installation
+
+Installing `gawk' on MS-DOS
+===========================
+
+ The first step is to get all the files in the `gawk' distribution
+onto your PC. Move all the files from the `pc' directory into the main
+directory where the other files are. Edit the file `make.bat' so that
+it will be an acceptable MS-DOS batch file. This means making sure
+that all lines are terminated with the ASCII carriage return and line
+feed characters. restrictions.
+
+ `gawk' has only been compiled with version 5.1 of the Microsoft C
+compiler. The file `make.bat' from the `pc' directory assumes that you
+have this compiler.
+
+ Copy the file `setargv.obj' from the library directory where it
+resides to the `gawk' source code directory.
+
+ Run `make.bat'. This will compile `gawk' for you, and link it.
+That's all there is to it!
+
+
+File: gawk.info, Node: Atari Installation, Prev: MS-DOS Installation, Up: Installation
+
+Installing `gawk' on the Atari ST
+=================================
+
+ This section assumes that you are running TOS. It applies to other
+Atari models (STe, TT) as well.
+
+ In order to use `gawk', you need to have a shell, either text or
+graphics, that does not map all the characters of a command line to
+upper case. Maintaining case distinction in option flags is very
+important (*note Invoking `awk': Command Line.). Popular shells like
+`gulam' or `gemini' will work, as will newer versions of `desktop'.
+Support for I/O redirection is necessary to make it easy to import
+`awk' programs from other environments. Pipes are nice to have, but
+not vital.
+
+ If you have received an executable version of `gawk', place it, as
+usual, anywhere in your `PATH' where your shell will find it.
+
+ While executing, `gawk' creates a number of temporary files. `gawk'
+looks for either of the environment variables `TEMP' or `TMPDIR', in
+that order. If either one is found, its value is assumed to be a
+directory for temporary files. This directory must exist, and if you
+can spare the memory, it is a good idea to put it on a RAM drive. If
+neither `TEMP' nor `TMPDIR' are found, then `gawk' uses the current
+directory for its temporary files.
+
+ The ST version of `gawk' searches for its program files as described
+in *Note The `AWKPATH' Environment Variable: AWKPATH Variable. On the
+ST, the default value for the `AWKPATH' variable is
+`".,c:\lib\awk,c:\gnu\lib\awk"'. The search path can be modified by
+explicitly setting `AWKPATH' to whatever you wish. Note that colons
+cannot be used on the ST to separate elements in the `AWKPATH'
+variable, since they have another, reserved, meaning. Instead, you
+must use a comma to separate elements in the path. If you are
+recompiling `gawk' on the ST, then you can choose a new default search
+path, by setting the value of `DEFPATH' in the file `...\config\atari'.
+You may choose a different separator character by setting the value of
+`ENVSEP' in the same file. The new values will be used when creating
+the header file `config.h'.
+
+ Although `awk' allows great flexibility in doing I/O redirections
+from within a program, this facility should be used with care on the ST.
+In some circumstances the OS routines for file handle pool processing
+lose track of certain events, causing the computer to crash, and
+requiring a reboot. Often a warm reboot is sufficient. Fortunately,
+this happens infrequently, and in rather esoteric situations. In
+particular, avoid having one part of an `awk' program using `print'
+statements explicitly redirected to `"/dev/stdout"', while other
+`print' statements use the default standard output, and a calling shell
+has redirected standard output to a file.
+
+ When `gawk' is compiled with the ST version of `gcc' and its usual
+libraries, it will accept both `/' and `\' as path separators. While
+this is convenient, it should be remembered that this removes one,
+technically legal, character (`/') from your file names, and that it
+may create problems for external programs, called via the `system()'
+function, which may not support this convention. Whenever it is
+possible that a file created by `gawk' will be used by some other
+program, use only backslashes. Also remember that in `awk',
+backslashes in strings have to be doubled in order to get literal
+backslashes.
+
+ The initial port of `gawk' to the ST was done with `gcc'. If you
+wish to recompile `gawk' from scratch, you will need to use a compiler
+that accepts ANSI standard C (such as `gcc', Turbo C, or Prospero C).
+If `sizeof(int) != sizeof(int *)', the correctness of the generated
+code depends heavily on the fact that all function calls have function
+prototypes in the current scope. If your compiler does not accept
+function prototypes, you will probably have to add a number of casts to
+the code.
+
+ If you are using `gcc', make sure that you have up-to-date libraries.
+Older versions have problems with some library functions (`atan2()',
+`strftime()', the `%g' conversion in `sprintf()') which may affect the
+operation of `gawk'.
+
+ In the `atari' subdirectory of the `gawk' distribution is a version
+of the `system()' function that has been tested with `gulam' and `msh';
+it should work with other shells as well. With `gulam', it passes the
+string to be executed without spawning an extra copy of a shell. It is
+possible to replace this version of `system()' with a similar function
+from a library or from some other source if that version would be a
+better choice for the shell you prefer.
+
+ The files needed to recompile `gawk' on the ST can be found in the
+`atari' directory. The provided files and instructions below assume
+that you have the GNU C compiler (`gcc'), the `gulam' shell, and an ST
+version of `sed'. The `Makefile' is set up to use `byacc' as a `yacc'
+replacement. With a different set of tools some adjustments and/or
+editing will be needed.
+
+ `cd' to the `atari' directory. Copy `Makefile.st' to `makefile' in
+the source (parent) directory. Possibly adjust `../config/atari' to
+suit your system. Execute the script `mkconf.g' which will create the
+header file `../config.h'. Go back to the source directory. If you
+are not using `gcc', check the file `missing.c'. It may be necessary
+to change forward slashes in the references to files from the `atari'
+subdirectory into backslashes. Type `make' and enjoy.
+
+ Compilation with `gcc' of some of the bigger modules, like
+`awk_tab.c', may require a full four megabytes of memory. On smaller
+machines you would need to cut down on optimizations, or you would have
+to switch to another, less memory hungry, compiler.
+
+
+File: gawk.info, Node: Gawk Summary, Next: Sample Program, Prev: Installation, Up: Top
+
+`gawk' Summary
+**************
+
+ This appendix provides a brief summary of the `gawk' command line
+and the `awk' language. It is designed to serve as "quick reference."
+It is therefore terse, but complete.
+
+* Menu:
+
+* Command Line Summary:: Recapitulation of the command line.
+* Language Summary:: A terse review of the language.
+* Variables/Fields:: Variables, fields, and arrays.
+* Rules Summary:: Patterns and Actions, and their
+ component parts.
+* Functions Summary:: Defining and calling functions.
+* Historical Features:: Some undocumented but supported "features".
+
+
+File: gawk.info, Node: Command Line Summary, Next: Language Summary, Prev: Gawk Summary, Up: Gawk Summary
+
+Command Line Options Summary
+============================
+
+ The command line consists of options to `gawk' itself, the `awk'
+program text (if not supplied via the `-f' option), and values to be
+made available in the `ARGC' and `ARGV' predefined `awk' variables:
+
+ awk [POSIX OR GNU STYLE OPTIONS] -f source-file [`--'] FILE ...
+ awk [POSIX OR GNU STYLE OPTIONS] [`--'] 'PROGRAM' FILE ...
+
+ The options that `gawk' accepts are:
+
+`-F FS'
+`--field-separator=FS'
+ Use FS for the input field separator (the value of the `FS'
+ predefined variable).
+
+`-f PROGRAM-FILE'
+`--file=PROGRAM-FILE'
+ Read the `awk' program source from the file PROGRAM-FILE, instead
+ of from the first command line argument.
+
+`-v VAR=VAL'
+`--assign=VAR=VAL'
+ Assign the variable VAR the value VAL before program execution
+ begins.
+
+`-W compat'
+`--compat'
+ Specifies compatibility mode, in which `gawk' extensions are turned
+ off.
+
+`-W copyleft'
+`-W copyright'
+`--copyleft'
+`--copyright'
+ Print the short version of the General Public License on the error
+ output. This option may disappear in a future version of `gawk'.
+
+`-W help'
+`-W usage'
+`--help'
+`--usage'
+ Print a relatively short summary of the available options on the
+ error output.
+
+`-W lint'
+`--lint'
+ Give warnings about dubious or non-portable `awk' constructs.
+
+`-W posix'
+`--posix'
+ Specifies POSIX compatibility mode, in which `gawk' extensions are
+ turned off and additional restrictions apply.
+
+`-W source=PROGRAM-TEXT'
+`--source=PROGRAM-TEXT'
+ Use PROGRAM-TEXT as `awk' program source code. This option allows
+ mixing command line source code with source code from files, and is
+ particularly useful for mixing command line programs with library
+ functions.
+
+`-W version'
+`--version'
+ Print version information for this particular copy of `gawk' on
+ the error output. This option may disappear in a future version
+ of `gawk'.
+
+`--'
+ Signal the end of options. This is useful to allow further
+ arguments to the `awk' program itself to start with a `-'. This
+ is mainly for consistency with the argument parsing conventions of
+ POSIX.
+
+ Any other options are flagged as invalid, but are otherwise ignored.
+*Note Invoking `awk': Command Line, for more details.
+
+
+File: gawk.info, Node: Language Summary, Next: Variables/Fields, Prev: Command Line Summary, Up: Gawk Summary
+
+Language Summary
+================
+
+ An `awk' program consists of a sequence of pattern-action statements
+and optional function definitions.
+
+ PATTERN { ACTION STATEMENTS }
+
+ function NAME(PARAMETER LIST) { ACTION STATEMENTS }
+
+ `gawk' first reads the program source from the PROGRAM-FILE(s) if
+specified, or from the first non-option argument on the command line.
+The `-f' option may be used multiple times on the command line. `gawk'
+reads the program text from all the PROGRAM-FILE files, effectively
+concatenating them in the order they are specified. This is useful for
+building libraries of `awk' functions, without having to include them
+in each new `awk' program that uses them. To use a library function in
+a file from a program typed in on the command line, specify `-f
+/dev/tty'; then type your program, and end it with a `Control-d'.
+*Note Invoking `awk': Command Line.
+
+ The environment variable `AWKPATH' specifies a search path to use
+when finding source files named with the `-f' option. The default
+path, which is `.:/usr/lib/awk:/usr/local/lib/awk' is used if `AWKPATH'
+is not set. If a file name given to the `-f' option contains a `/'
+character, no path search is performed. *Note The `AWKPATH'
+Environment Variable: AWKPATH Variable, for a full description of the
+`AWKPATH' environment variable.
+
+ `gawk' compiles the program into an internal form, and then proceeds
+to read each file named in the `ARGV' array. If there are no files
+named on the command line, `gawk' reads the standard input.
+
+ If a "file" named on the command line has the form `VAR=VAL', it is
+treated as a variable assignment: the variable VAR is assigned the
+value VAL. If any of the files have a value that is the null string,
+that element in the list is skipped.
+
+ For each line in the input, `gawk' tests to see if it matches any
+PATTERN in the `awk' program. For each pattern that the line matches,
+the associated ACTION is executed.
+
+
+File: gawk.info, Node: Variables/Fields, Next: Rules Summary, Prev: Language Summary, Up: Gawk Summary
+
+Variables and Fields
+====================
+
+ `awk' variables are dynamic; they come into existence when they are
+first used. Their values are either floating-point numbers or strings.
+`awk' also has one-dimension arrays; multiple-dimensional arrays may be
+simulated. There are several predefined variables that `awk' sets as a
+program runs; these are summarized below.
+
+* Menu:
+
+* Fields Summary:: Input field splitting.
+* Built-in Summary:: `awk''s built-in variables.
+* Arrays Summary:: Using arrays.
+* Data Type Summary:: Values in `awk' are numbers or strings.
+
+
+File: gawk.info, Node: Fields Summary, Next: Built-in Summary, Prev: Variables/Fields, Up: Variables/Fields
+
+Fields
+------
+
+ As each input line is read, `gawk' splits the line into FIELDS,
+using the value of the `FS' variable as the field separator. If `FS'
+is a single character, fields are separated by that character.
+Otherwise, `FS' is expected to be a full regular expression. In the
+special case that `FS' is a single blank, fields are separated by runs
+of blanks and/or tabs. Note that the value of `IGNORECASE' (*note
+Case-sensitivity in Matching: Case-sensitivity.) also affects how
+fields are split when `FS' is a regular expression.
+
+ Each field in the input line may be referenced by its position, `$1',
+`$2', and so on. `$0' is the whole line. The value of a field may be
+assigned to as well. Field numbers need not be constants:
+
+ n = 5
+ print $n
+
+prints the fifth field in the input line. The variable `NF' is set to
+the total number of fields in the input line.
+
+ References to nonexistent fields (i.e., fields after `$NF') return
+the null-string. However, assigning to a nonexistent field (e.g.,
+`$(NF+2) = 5') increases the value of `NF', creates any intervening
+fields with the null string as their value, and causes the value of
+`$0' to be recomputed, with the fields being separated by the value of
+`OFS'.
+
+ *Note Reading Input Files: Reading Files, for a full description of
+the way `awk' defines and uses fields.
+
+
+File: gawk.info, Node: Built-in Summary, Next: Arrays Summary, Prev: Fields Summary, Up: Variables/Fields
+
+Built-in Variables
+------------------
+
+ `awk''s built-in variables are:
+
+`ARGC'
+ The number of command line arguments (not including options or the
+ `awk' program itself).
+
+`ARGIND'
+ The index in `ARGV' of the current file being processed. It is
+ always true that `FILENAME == ARGV[ARGIND]'.
+
+`ARGV'
+ The array of command line arguments. The array is indexed from 0
+ to `ARGC' - 1. Dynamically changing the contents of `ARGV' can
+ control the files used for data.
+
+`CONVFMT'
+ The conversion format to use when converting numbers to strings.
+
+`FIELDWIDTHS'
+ A space separated list of numbers describing the fixed-width input
+ data.
+
+`ENVIRON'
+ An array containing the values of the environment variables. The
+ array is indexed by variable name, each element being the value of
+ that variable. Thus, the environment variable `HOME' would be in
+ `ENVIRON["HOME"]'. Its value might be `/u/close'.
+
+ Changing this array does not affect the environment seen by
+ programs which `gawk' spawns via redirection or the `system'
+ function. (This may change in a future version of `gawk'.)
+
+ Some operating systems do not have environment variables. The
+ array `ENVIRON' is empty when running on these systems.
+
+`ERRNO'
+ The system error message when an error occurs using `getline' or
+ `close'.
+
+`FILENAME'
+ The name of the current input file. If no files are specified on
+ the command line, the value of `FILENAME' is `-'.
+
+`FNR'
+ The input record number in the current input file.
+
+`FS'
+ The input field separator, a blank by default.
+
+`IGNORECASE'
+ The case-sensitivity flag for regular expression operations. If
+ `IGNORECASE' has a nonzero value, then pattern matching in rules,
+ field splitting with `FS', regular expression matching with `~'
+ and `!~', and the `gsub', `index', `match', `split' and `sub'
+ predefined functions all ignore case when doing regular expression
+ operations.
+
+`NF'
+ The number of fields in the current input record.
+
+`NR'
+ The total number of input records seen so far.
+
+`OFMT'
+ The output format for numbers for the `print' statement, `"%.6g"'
+ by default.
+
+`OFS'
+ The output field separator, a blank by default.
+
+`ORS'
+ The output record separator, by default a newline.
+
+`RS'
+ The input record separator, by default a newline. `RS' is
+ exceptional in that only the first character of its string value
+ is used for separating records. If `RS' is set to the null
+ string, then records are separated by blank lines. When `RS' is
+ set to the null string, then the newline character always acts as
+ a field separator, in addition to whatever value `FS' may have.
+
+`RSTART'
+ The index of the first character matched by `match'; 0 if no match.
+
+`RLENGTH'
+ The length of the string matched by `match'; -1 if no match.
+
+`SUBSEP'
+ The string used to separate multiple subscripts in array elements,
+ by default `"\034"'.
+
+ *Note Built-in Variables::, for more information.
+
+
+File: gawk.info, Node: Arrays Summary, Next: Data Type Summary, Prev: Built-in Summary, Up: Variables/Fields
+
+Arrays
+------
+
+ Arrays are subscripted with an expression between square brackets
+(`[' and `]'). Array subscripts are *always* strings; numbers are
+converted to strings as necessary, following the standard conversion
+rules (*note Conversion of Strings and Numbers: Conversion.).
+
+ If you use multiple expressions separated by commas inside the square
+brackets, then the array subscript is a string consisting of the
+concatenation of the individual subscript values, converted to strings,
+separated by the subscript separator (the value of `SUBSEP').
+
+ The special operator `in' may be used in an `if' or `while'
+statement to see if an array has an index consisting of a particular
+value.
+
+ if (val in array)
+ print array[val]
+
+ If the array has multiple subscripts, use `(i, j, ...) in array' to
+test for existence of an element.
+
+ The `in' construct may also be used in a `for' loop to iterate over
+all the elements of an array. *Note Scanning all Elements of an Array:
+Scanning an Array.
+
+ An element may be deleted from an array using the `delete' statement.
+
+ *Note Arrays in `awk': Arrays, for more detailed information.
+
+
+File: gawk.info, Node: Data Type Summary, Prev: Arrays Summary, Up: Variables/Fields
+
+Data Types
+----------
+
+ The value of an `awk' expression is always either a number or a
+string.
+
+ Certain contexts (such as arithmetic operators) require numeric
+values. They convert strings to numbers by interpreting the text of
+the string as a numeral. If the string does not look like a numeral,
+it converts to 0.
+
+ Certain contexts (such as concatenation) require string values.
+They convert numbers to strings by effectively printing them with
+`sprintf'. *Note Conversion of Strings and Numbers: Conversion, for
+the details.
+
+ To force conversion of a string value to a number, simply add 0 to
+it. If the value you start with is already a number, this does not
+change it.
+
+ To force conversion of a numeric value to a string, concatenate it
+with the null string.
+
+ The `awk' language defines comparisons as being done numerically if
+both operands are numeric, or if one is numeric and the other is a
+numeric string. Otherwise one or both operands are converted to
+strings and a string comparison is performed.
+
+ Uninitialized variables have the string value `""' (the null, or
+empty, string). In contexts where a number is required, this is
+equivalent to 0.
+
+ *Note Variables::, for more information on variable naming and
+initialization; *note Conversion of Strings and Numbers: Conversion.,
+for more information on how variable values are interpreted.
+
+
+File: gawk.info, Node: Rules Summary, Next: Functions Summary, Prev: Variables/Fields, Up: Gawk Summary
+
+Patterns and Actions
+====================
+
+* Menu:
+
+* Pattern Summary:: Quick overview of patterns.
+* Regexp Summary:: Quick overview of regular expressions.
+* Actions Summary:: Quick overview of actions.
+
+ An `awk' program is mostly composed of rules, each consisting of a
+pattern followed by an action. The action is enclosed in `{' and `}'.
+Either the pattern may be missing, or the action may be missing, but,
+of course, not both. If the pattern is missing, the action is executed
+for every single line of input. A missing action is equivalent to this
+action,
+
+ { print }
+
+which prints the entire line.
+
+ Comments begin with the `#' character, and continue until the end of
+the line. Blank lines may be used to separate statements. Normally, a
+statement ends with a newline, however, this is not the case for lines
+ending in a `,', `{', `?', `:', `&&', or `||'. Lines ending in `do' or
+`else' also have their statements automatically continued on the
+following line. In other cases, a line can be continued by ending it
+with a `\', in which case the newline is ignored.
+
+ Multiple statements may be put on one line by separating them with a
+`;'. This applies to both the statements within the action part of a
+rule (the usual case), and to the rule statements.
+
+ *Note Comments in `awk' Programs: Comments, for information on
+`awk''s commenting convention; *note `awk' Statements versus Lines:
+Statements/Lines., for a description of the line continuation mechanism
+in `awk'.
+
+
+File: gawk.info, Node: Pattern Summary, Next: Regexp Summary, Prev: Rules Summary, Up: Rules Summary
+
+Patterns
+--------
+
+ `awk' patterns may be one of the following:
+
+ /REGULAR EXPRESSION/
+ RELATIONAL EXPRESSION
+ PATTERN && PATTERN
+ PATTERN || PATTERN
+ PATTERN ? PATTERN : PATTERN
+ (PATTERN)
+ ! PATTERN
+ PATTERN1, PATTERN2
+ BEGIN
+ END
+
+ `BEGIN' and `END' are two special kinds of patterns that are not
+tested against the input. The action parts of all `BEGIN' rules are
+merged as if all the statements had been written in a single `BEGIN'
+rule. They are executed before any of the input is read. Similarly,
+all the `END' rules are merged, and executed when all the input is
+exhausted (or when an `exit' statement is executed). `BEGIN' and `END'
+patterns cannot be combined with other patterns in pattern expressions.
+`BEGIN' and `END' rules cannot have missing action parts.
+
+ For `/REGULAR-EXPRESSION/' patterns, the associated statement is
+executed for each input line that matches the regular expression.
+Regular expressions are extensions of those in `egrep', and are
+summarized below.
+
+ A RELATIONAL EXPRESSION may use any of the operators defined below in
+the section on actions. These generally test whether certain fields
+match certain regular expressions.
+
+ The `&&', `||', and `!' operators are logical "and," logical "or,"
+and logical "not," respectively, as in C. They do short-circuit
+evaluation, also as in C, and are used for combining more primitive
+pattern expressions. As in most languages, parentheses may be used to
+change the order of evaluation.
+
+ The `?:' operator is like the same operator in C. If the first
+pattern matches, then the second pattern is matched against the input
+record; otherwise, the third is matched. Only one of the second and
+third patterns is matched.
+
+ The `PATTERN1, PATTERN2' form of a pattern is called a range
+pattern. It matches all input lines starting with a line that matches
+PATTERN1, and continuing until a line that matches PATTERN2, inclusive.
+A range pattern cannot be used as an operand to any of the pattern
+operators.
+
+ *Note Patterns::, for a full description of the pattern part of `awk'
+rules.
+
diff --git a/gawk.info-8 b/gawk.info-8
new file mode 100644
index 00000000..d0d693ff
--- /dev/null
+++ b/gawk.info-8
@@ -0,0 +1,1173 @@
+This is Info file gawk.info, produced by Makeinfo-1.54 from the input
+file gawk.texi.
+
+ This file documents `awk', a program that you can use to select
+particular records in a file and perform operations upon them.
+
+ This is Edition 0.15 of `The GAWK Manual',
+for the 2.15 version of the GNU implementation
+of AWK.
+
+ Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that
+the entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Foundation.
+
+
+File: gawk.info, Node: Regexp Summary, Next: Actions Summary, Prev: Pattern Summary, Up: Rules Summary
+
+Regular Expressions
+-------------------
+
+ Regular expressions are the extended kind found in `egrep'. They
+are composed of characters as follows:
+
+`C'
+ matches the character C (assuming C is a character with no special
+ meaning in regexps).
+
+`\C'
+ matches the literal character C.
+
+`.'
+ matches any character except newline.
+
+`^'
+ matches the beginning of a line or a string.
+
+`$'
+ matches the end of a line or a string.
+
+`[ABC...]'
+ matches any of the characters ABC... (character class).
+
+`[^ABC...]'
+ matches any character except ABC... and newline (negated character
+ class).
+
+`R1|R2'
+ matches either R1 or R2 (alternation).
+
+`R1R2'
+ matches R1, and then R2 (concatenation).
+
+`R+'
+ matches one or more R's.
+
+`R*'
+ matches zero or more R's.
+
+`R?'
+ matches zero or one R's.
+
+`(R)'
+ matches R (grouping).
+
+ *Note Regular Expressions as Patterns: Regexp, for a more detailed
+explanation of regular expressions.
+
+ The escape sequences allowed in string constants are also valid in
+regular expressions (*note Constant Expressions: Constants.).
+
+
+File: gawk.info, Node: Actions Summary, Prev: Regexp Summary, Up: Rules Summary
+
+Actions
+-------
+
+ Action statements are enclosed in braces, `{' and `}'. Action
+statements consist of the usual assignment, conditional, and looping
+statements found in most languages. The operators, control statements,
+and input/output statements available are patterned after those in C.
+
+* Menu:
+
+* Operator Summary:: `awk' operators.
+* Control Flow Summary:: The control statements.
+* I/O Summary:: The I/O statements.
+* Printf Summary:: A summary of `printf'.
+* Special File Summary:: Special file names interpreted internally.
+* Numeric Functions Summary:: Built-in numeric functions.
+* String Functions Summary:: Built-in string functions.
+* Time Functions Summary:: Built-in time functions.
+* String Constants Summary:: Escape sequences in strings.
+
+
+File: gawk.info, Node: Operator Summary, Next: Control Flow Summary, Prev: Actions Summary, Up: Actions Summary
+
+Operators
+.........
+
+ The operators in `awk', in order of increasing precedence, are:
+
+`= += -= *= /= %= ^='
+ Assignment. Both absolute assignment (`VAR=VALUE') and operator
+ assignment (the other forms) are supported.
+
+`?:'
+ A conditional expression, as in C. This has the form `EXPR1 ?
+ eXPR2 : EXPR3'. If EXPR1 is true, the value of the expression is
+ EXPR2; otherwise it is EXPR3. Only one of EXPR2 and EXPR3 is
+ evaluated.
+
+`||'
+ Logical "or".
+
+`&&'
+ Logical "and".
+
+`~ !~'
+ Regular expression match, negated match.
+
+`< <= > >= != =='
+ The usual relational operators.
+
+`BLANK'
+ String concatenation.
+
+`+ -'
+ Addition and subtraction.
+
+`* / %'
+ Multiplication, division, and modulus.
+
+`+ - !'
+ Unary plus, unary minus, and logical negation.
+
+`^'
+ Exponentiation (`**' may also be used, and `**=' for the assignment
+ operator, but they are not specified in the POSIX standard).
+
+`++ --'
+ Increment and decrement, both prefix and postfix.
+
+`$'
+ Field reference.
+
+ *Note Expressions as Action Statements: Expressions, for a full
+description of all the operators listed above. *Note Examining Fields:
+Fields, for a description of the field reference operator.
+
+
+File: gawk.info, Node: Control Flow Summary, Next: I/O Summary, Prev: Operator Summary, Up: Actions Summary
+
+Control Statements
+..................
+
+ The control statements are as follows:
+
+ if (CONDITION) STATEMENT [ else STATEMENT ]
+ while (CONDITION) STATEMENT
+ do STATEMENT while (CONDITION)
+ for (EXPR1; EXPR2; EXPR3) STATEMENT
+ for (VAR in ARRAY) STATEMENT
+ break
+ continue
+ delete ARRAY[INDEX]
+ exit [ EXPRESSION ]
+ { STATEMENTS }
+
+ *Note Control Statements in Actions: Statements, for a full
+description of all the control statements listed above.
+
+
+File: gawk.info, Node: I/O Summary, Next: Printf Summary, Prev: Control Flow Summary, Up: Actions Summary
+
+I/O Statements
+..............
+
+ The input/output statements are as follows:
+
+`getline'
+ Set `$0' from next input record; set `NF', `NR', `FNR'.
+
+`getline <FILE'
+ Set `$0' from next record of FILE; set `NF'.
+
+`getline VAR'
+ Set VAR from next input record; set `NF', `FNR'.
+
+`getline VAR <FILE'
+ Set VAR from next record of FILE.
+
+`next'
+ Stop processing the current input record. The next input record
+ is read and processing starts over with the first pattern in the
+ `awk' program. If the end of the input data is reached, the `END'
+ rule(s), if any, are executed.
+
+`next file'
+ Stop processing the current input file. The next input record
+ read comes from the next input file. `FILENAME' is updated, `FNR'
+ is set to 1, and processing starts over with the first pattern in
+ the `awk' program. If the end of the input data is reached, the
+ `END' rule(s), if any, are executed.
+
+`print'
+ Prints the current record.
+
+`print EXPR-LIST'
+ Prints expressions.
+
+`print EXPR-LIST > FILE'
+ Prints expressions on FILE.
+
+`printf FMT, EXPR-LIST'
+ Format and print.
+
+`printf FMT, EXPR-LIST > file'
+ Format and print on FILE.
+
+ Other input/output redirections are also allowed. For `print' and
+`printf', `>> FILE' appends output to the FILE, and `| COMMAND' writes
+on a pipe. In a similar fashion, `COMMAND | getline' pipes input into
+`getline'. `getline' returns 0 on end of file, and -1 on an error.
+
+ *Note Explicit Input with `getline': Getline, for a full description
+of the `getline' statement. *Note Printing Output: Printing, for a
+full description of `print' and `printf'. Finally, *note The `next'
+Statement: Next Statement., for a description of how the `next'
+statement works.
+
+
+File: gawk.info, Node: Printf Summary, Next: Special File Summary, Prev: I/O Summary, Up: Actions Summary
+
+`printf' Summary
+................
+
+ The `awk' `printf' statement and `sprintf' function accept the
+following conversion specification formats:
+
+`%c'
+ An ASCII character. If the argument used for `%c' is numeric, it
+ is treated as a character and printed. Otherwise, the argument is
+ assumed to be a string, and the only first character of that
+ string is printed.
+
+`%d'
+`%i'
+ A decimal number (the integer part).
+
+`%e'
+ A floating point number of the form `[-]d.ddddddE[+-]dd'.
+
+`%f'
+ A floating point number of the form [`-']`ddd.dddddd'.
+
+`%g'
+ Use `%e' or `%f' conversion, whichever produces a shorter string,
+ with nonsignificant zeros suppressed.
+
+`%o'
+ An unsigned octal number (again, an integer).
+
+`%s'
+ A character string.
+
+`%x'
+ An unsigned hexadecimal number (an integer).
+
+`%X'
+ Like `%x', except use `A' through `F' instead of `a' through `f'
+ for decimal 10 through 15.
+
+`%%'
+ A single `%' character; no argument is converted.
+
+ There are optional, additional parameters that may lie between the
+`%' and the control letter:
+
+`-'
+ The expression should be left-justified within its field.
+
+`WIDTH'
+ The field should be padded to this width. If WIDTH has a leading
+ zero, then the field is padded with zeros. Otherwise it is padded
+ with blanks.
+
+`.PREC'
+ A number indicating the maximum width of strings or digits to the
+ right of the decimal point.
+
+ Either or both of the WIDTH and PREC values may be specified as `*'.
+In that case, the particular value is taken from the argument list.
+
+ *Note Using `printf' Statements for Fancier Printing: Printf, for
+examples and for a more detailed description.
+
+
+File: gawk.info, Node: Special File Summary, Next: Numeric Functions Summary, Prev: Printf Summary, Up: Actions Summary
+
+Special File Names
+..................
+
+ When doing I/O redirection from either `print' or `printf' into a
+file, or via `getline' from a file, `gawk' recognizes certain special
+file names internally. These file names allow access to open file
+descriptors inherited from `gawk''s parent process (usually the shell).
+The file names are:
+
+`/dev/stdin'
+ The standard input.
+
+`/dev/stdout'
+ The standard output.
+
+`/dev/stderr'
+ The standard error output.
+
+`/dev/fd/N'
+ The file denoted by the open file descriptor N.
+
+ In addition the following files provide process related information
+about the running `gawk' program.
+
+`/dev/pid'
+ Reading this file returns the process ID of the current process,
+ in decimal, terminated with a newline.
+
+`/dev/ppid'
+ Reading this file returns the parent process ID of the current
+ process, in decimal, terminated with a newline.
+
+`/dev/pgrpid'
+ Reading this file returns the process group ID of the current
+ process, in decimal, terminated with a newline.
+
+`/dev/user'
+ Reading this file returns a single record terminated with a
+ newline. The fields are separated with blanks. The fields
+ represent the following information:
+
+ `$1'
+ The value of the `getuid' system call.
+
+ `$2'
+ The value of the `geteuid' system call.
+
+ `$3'
+ The value of the `getgid' system call.
+
+ `$4'
+ The value of the `getegid' system call.
+
+ If there are any additional fields, they are the group IDs
+ returned by `getgroups' system call. (Multiple groups may not be
+ supported on all systems.)
+
+These file names may also be used on the command line to name data
+files. These file names are only recognized internally if you do not
+actually have files by these names on your system.
+
+ *Note Standard I/O Streams: Special Files, for a longer description
+that provides the motivation for this feature.
+
+
+File: gawk.info, Node: Numeric Functions Summary, Next: String Functions Summary, Prev: Special File Summary, Up: Actions Summary
+
+Numeric Functions
+.................
+
+ `awk' has the following predefined arithmetic functions:
+
+`atan2(Y, X)'
+ returns the arctangent of Y/X in radians.
+
+`cos(EXPR)'
+ returns the cosine in radians.
+
+`exp(EXPR)'
+ the exponential function.
+
+`int(EXPR)'
+ truncates to integer.
+
+`log(EXPR)'
+ the natural logarithm function.
+
+`rand()'
+ returns a random number between 0 and 1.
+
+`sin(EXPR)'
+ returns the sine in radians.
+
+`sqrt(EXPR)'
+ the square root function.
+
+`srand(EXPR)'
+ use EXPR as a new seed for the random number generator. If no EXPR
+ is provided, the time of day is used. The return value is the
+ previous seed for the random number generator.
+
+
+File: gawk.info, Node: String Functions Summary, Next: Time Functions Summary, Prev: Numeric Functions Summary, Up: Actions Summary
+
+String Functions
+................
+
+ `awk' has the following predefined string functions:
+
+`gsub(R, S, T)'
+ for each substring matching the regular expression R in the string
+ T, substitute the string S, and return the number of substitutions.
+ If T is not supplied, use `$0'.
+
+`index(S, T)'
+ returns the index of the string T in the string S, or 0 if T is
+ not present.
+
+`length(S)'
+ returns the length of the string S. The length of `$0' is
+ returned if no argument is supplied.
+
+`match(S, R)'
+ returns the position in S where the regular expression R occurs,
+ or 0 if R is not present, and sets the values of `RSTART' and
+ `RLENGTH'.
+
+`split(S, A, R)'
+ splits the string S into the array A on the regular expression R,
+ and returns the number of fields. If R is omitted, `FS' is used
+ instead.
+
+`sprintf(FMT, EXPR-LIST)'
+ prints EXPR-LIST according to FMT, and returns the resulting
+ string.
+
+`sub(R, S, T)'
+ this is just like `gsub', but only the first matching substring is
+ replaced.
+
+`substr(S, I, N)'
+ returns the N-character substring of S starting at I. If N is
+ omitted, the rest of S is used.
+
+`tolower(STR)'
+ returns a copy of the string STR, with all the upper-case
+ characters in STR translated to their corresponding lower-case
+ counterparts. Nonalphabetic characters are left unchanged.
+
+`toupper(STR)'
+ returns a copy of the string STR, with all the lower-case
+ characters in STR translated to their corresponding upper-case
+ counterparts. Nonalphabetic characters are left unchanged.
+
+`system(CMD-LINE)'
+ Execute the command CMD-LINE, and return the exit status.
+
+
+File: gawk.info, Node: Time Functions Summary, Next: String Constants Summary, Prev: String Functions Summary, Up: Actions Summary
+
+Built-in time functions
+.......................
+
+ The following two functions are available for getting the current
+time of day, and for formatting time stamps.
+
+`systime()'
+ returns the current time of day as the number of seconds since a
+ particular epoch (Midnight, January 1, 1970 UTC, on POSIX systems).
+
+`strftime(FORMAT, TIMESTAMP)'
+ formats TIMESTAMP according to the specification in FORMAT. The
+ current time of day is used if no TIMESTAMP is supplied. *Note
+ Functions for Dealing with Time Stamps: Time Functions, for the
+ details on the conversion specifiers that `strftime' accepts.
+
+
+File: gawk.info, Node: String Constants Summary, Prev: Time Functions Summary, Up: Actions Summary
+
+String Constants
+................
+
+ String constants in `awk' are sequences of characters enclosed
+between double quotes (`"'). Within strings, certain "escape sequences"
+are recognized, as in C. These are:
+
+`\\'
+ A literal backslash.
+
+`\a'
+ The "alert" character; usually the ASCII BEL character.
+
+`\b'
+ Backspace.
+
+`\f'
+ Formfeed.
+
+`\n'
+ Newline.
+
+`\r'
+ Carriage return.
+
+`\t'
+ Horizontal tab.
+
+`\v'
+ Vertical tab.
+
+`\xHEX DIGITS'
+ The character represented by the string of hexadecimal digits
+ following the `\x'. As in ANSI C, all following hexadecimal
+ digits are considered part of the escape sequence. (This feature
+ should tell us something about language design by committee.)
+ E.g., `"\x1B"' is a string containing the ASCII ESC (escape)
+ character. (The `\x' escape sequence is not in POSIX `awk'.)
+
+`\DDD'
+ The character represented by the 1-, 2-, or 3-digit sequence of
+ octal digits. Thus, `"\033"' is also a string containing the
+ ASCII ESC (escape) character.
+
+`\C'
+ The literal character C.
+
+ The escape sequences may also be used inside constant regular
+expressions (e.g., the regexp `/[ \t\f\n\r\v]/' matches whitespace
+characters).
+
+ *Note Constant Expressions: Constants.
+
+
+File: gawk.info, Node: Functions Summary, Next: Historical Features, Prev: Rules Summary, Up: Gawk Summary
+
+Functions
+=========
+
+ Functions in `awk' are defined as follows:
+
+ function NAME(PARAMETER LIST) { STATEMENTS }
+
+ Actual parameters supplied in the function call are used to
+instantiate the formal parameters declared in the function. Arrays are
+passed by reference, other variables are passed by value.
+
+ If there are fewer arguments passed than there are names in
+PARAMETER-LIST, the extra names are given the null string as value.
+Extra names have the effect of local variables.
+
+ The open-parenthesis in a function call of a user-defined function
+must immediately follow the function name, without any intervening
+white space. This is to avoid a syntactic ambiguity with the
+concatenation operator.
+
+ The word `func' may be used in place of `function' (but not in POSIX
+`awk').
+
+ Use the `return' statement to return a value from a function.
+
+ *Note User-defined Functions: User-defined, for a more complete
+description.
+
+
+File: gawk.info, Node: Historical Features, Prev: Functions Summary, Up: Gawk Summary
+
+Historical Features
+===================
+
+ There are two features of historical `awk' implementations that
+`gawk' supports. First, it is possible to call the `length' built-in
+function not only with no arguments, but even without parentheses!
+
+ a = length
+
+is the same as either of
+
+ a = length()
+ a = length($0)
+
+This feature is marked as "deprecated" in the POSIX standard, and
+`gawk' will issue a warning about its use if `-W lint' is specified on
+the command line.
+
+ The other feature is the use of the `continue' statement outside the
+body of a `while', `for', or `do' loop. Traditional `awk'
+implementations have treated such usage as equivalent to the `next'
+statement. `gawk' will support this usage if `-W posix' has not been
+specified.
+
+
+File: gawk.info, Node: Sample Program, Next: Bugs, Prev: Gawk Summary, Up: Top
+
+Sample Program
+**************
+
+ The following example is a complete `awk' program, which prints the
+number of occurrences of each word in its input. It illustrates the
+associative nature of `awk' arrays by using strings as subscripts. It
+also demonstrates the `for X in ARRAY' construction. Finally, it shows
+how `awk' can be used in conjunction with other utility programs to do
+a useful task of some complexity with a minimum of effort. Some
+explanations follow the program listing.
+
+ awk '
+ # Print list of word frequencies
+ {
+ for (i = 1; i <= NF; i++)
+ freq[$i]++
+ }
+
+ END {
+ for (word in freq)
+ printf "%s\t%d\n", word, freq[word]
+ }'
+
+ The first thing to notice about this program is that it has two
+rules. The first rule, because it has an empty pattern, is executed on
+every line of the input. It uses `awk''s field-accessing mechanism
+(*note Examining Fields: Fields.) to pick out the individual words from
+the line, and the built-in variable `NF' (*note Built-in Variables::.)
+to know how many fields are available.
+
+ For each input word, an element of the array `freq' is incremented to
+reflect that the word has been seen an additional time.
+
+ The second rule, because it has the pattern `END', is not executed
+until the input has been exhausted. It prints out the contents of the
+`freq' table that has been built up inside the first action.
+
+ Note that this program has several problems that would prevent it
+from being useful by itself on real text files:
+
+ * Words are detected using the `awk' convention that fields are
+ separated by whitespace and that other characters in the input
+ (except newlines) don't have any special meaning to `awk'. This
+ means that punctuation characters count as part of words.
+
+ * The `awk' language considers upper and lower case characters to be
+ distinct. Therefore, `foo' and `Foo' are not treated by this
+ program as the same word. This is undesirable since in normal
+ text, words are capitalized if they begin sentences, and a
+ frequency analyzer should not be sensitive to that.
+
+ * The output does not come out in any useful order. You're more
+ likely to be interested in which words occur most frequently, or
+ having an alphabetized table of how frequently each word occurs.
+
+ The way to solve these problems is to use some of the more advanced
+features of the `awk' language. First, we use `tolower' to remove case
+distinctions. Next, we use `gsub' to remove punctuation characters.
+Finally, we use the system `sort' utility to process the output of the
+`awk' script. First, here is the new version of the program:
+
+ awk '
+ # Print list of word frequencies
+ {
+ $0 = tolower($0) # remove case distinctions
+ gsub(/[^a-z0-9_ \t]/, "", $0) # remove punctuation
+ for (i = 1; i <= NF; i++)
+ freq[$i]++
+ }
+
+ END {
+ for (word in freq)
+ printf "%s\t%d\n", word, freq[word]
+ }'
+
+ Assuming we have saved this program in a file named `frequency.awk',
+and that the data is in `file1', the following pipeline
+
+ awk -f frequency.awk file1 | sort +1 -nr
+
+produces a table of the words appearing in `file1' in order of
+decreasing frequency.
+
+ The `awk' program suitably massages the data and produces a word
+frequency table, which is not ordered.
+
+ The `awk' script's output is then sorted by the `sort' command and
+printed on the terminal. The options given to `sort' in this example
+specify to sort using the second field of each input line (skipping one
+field), that the sort keys should be treated as numeric quantities
+(otherwise `15' would come before `5'), and that the sorting should be
+done in descending (reverse) order.
+
+ We could have even done the `sort' from within the program, by
+changing the `END' action to:
+
+ END {
+ sort = "sort +1 -nr"
+ for (word in freq)
+ printf "%s\t%d\n", word, freq[word] | sort
+ close(sort)
+ }'
+
+ See the general operating system documentation for more information
+on how to use the `sort' command.
+
+
+File: gawk.info, Node: Bugs, Next: Notes, Prev: Sample Program, Up: Top
+
+Reporting Problems and Bugs
+***************************
+
+ If you have problems with `gawk' or think that you have found a bug,
+please report it to the developers; we cannot promise to do anything
+but we might well want to fix it.
+
+ Before reporting a bug, make sure you have actually found a real bug.
+Carefully reread the documentation and see if it really says you can do
+what you're trying to do. If it's not clear whether you should be able
+to do something or not, report that too; it's a bug in the
+documentation!
+
+ Before reporting a bug or trying to fix it yourself, try to isolate
+it to the smallest possible `awk' program and input data file that
+reproduces the problem. Then send us the program and data file, some
+idea of what kind of Unix system you're using, and the exact results
+`gawk' gave you. Also say what you expected to occur; this will help
+us decide whether the problem was really in the documentation.
+
+ Once you have a precise problem, send e-mail to (Internet)
+`bug-gnu-utils@prep.ai.mit.edu' or (UUCP)
+`mit-eddie!prep.ai.mit.edu!bug-gnu-utils'. Please include the version
+number of `gawk' you are using. You can get this information with the
+command `gawk -W version '{}' /dev/null'. You should send carbon
+copies of your mail to David Trueman at `david@cs.dal.ca', and to
+Arnold Robbins, who can be reached at `arnold@skeeve.atl.ga.us'. David
+is most likely to fix code problems, while Arnold is most likely to fix
+documentation problems.
+
+ Non-bug suggestions are always welcome as well. If you have
+questions about things that are unclear in the documentation or are
+just obscure features, ask Arnold Robbins; he will try to help you out,
+although he may not have the time to fix the problem. You can send him
+electronic mail at the Internet address above.
+
+ If you find bugs in one of the non-Unix ports of `gawk', please send
+an electronic mail message to the person who maintains that port. They
+are listed below, and also in the `README' file in the `gawk'
+distribution. Information in the `README' file should be considered
+authoritative if it conflicts with this manual.
+
+ The people maintaining the non-Unix ports of `gawk' are:
+
+MS-DOS
+ The port to MS-DOS is maintained by Scott Deifik. His electronic
+ mail address is `scottd@amgen.com'.
+
+VMS
+ The port to VAX VMS is maintained by Pat Rankin. His electronic
+ mail address is `rankin@eql.caltech.edu'.
+
+Atari ST
+ The port to the Atari ST is maintained by Michal Jaegermann. His
+ electronic mail address is `ntomczak@vm.ucs.ualberta.ca'.
+
+ If your bug is also reproducible under Unix, please send copies of
+your report to the general GNU bug list, as well as to Arnold Robbins
+and David Trueman, at the addresses listed above.
+
+
+File: gawk.info, Node: Notes, Next: Glossary, Prev: Bugs, Up: Top
+
+Implementation Notes
+********************
+
+ This appendix contains information mainly of interest to
+implementors and maintainers of `gawk'. Everything in it applies
+specifically to `gawk', and not to other implementations.
+
+* Menu:
+
+* Compatibility Mode:: How to disable certain `gawk' extensions.
+* Future Extensions:: New features we may implement soon.
+* Improvements:: Suggestions for improvements by volunteers.
+
+
+File: gawk.info, Node: Compatibility Mode, Next: Future Extensions, Prev: Notes, Up: Notes
+
+Downward Compatibility and Debugging
+====================================
+
+ *Note Extensions in `gawk' not in POSIX `awk': POSIX/GNU, for a
+summary of the GNU extensions to the `awk' language and program. All
+of these features can be turned off by invoking `gawk' with the `-W
+compat' option, or with the `-W posix' option.
+
+ If `gawk' is compiled for debugging with `-DDEBUG', then there is
+one more option available on the command line:
+
+`-W parsedebug'
+ Print out the parse stack information as the program is being
+ parsed.
+
+ This option is intended only for serious `gawk' developers, and not
+for the casual user. It probably has not even been compiled into your
+version of `gawk', since it slows down execution.
+
+
+File: gawk.info, Node: Future Extensions, Next: Improvements, Prev: Compatibility Mode, Up: Notes
+
+Probable Future Extensions
+==========================
+
+ This section briefly lists extensions that indicate the directions
+we are currently considering for `gawk'. The file `FUTURES' in the
+`gawk' distributions lists these extensions, as well as several others.
+
+`RS' as a regexp
+ The meaning of `RS' may be generalized along the lines of `FS'.
+
+Control of subprocess environment
+ Changes made in `gawk' to the array `ENVIRON' may be propagated to
+ subprocesses run by `gawk'.
+
+Databases
+ It may be possible to map a GDBM/NDBM/SDBM file into an `awk'
+ array.
+
+Single-character fields
+ The null string, `""', as a field separator, will cause field
+ splitting and the `split' function to separate individual
+ characters. Thus, `split(a, "abcd", "")' would yield `a[1] ==
+ "a"', `a[2] == "b"', and so on.
+
+More `lint' warnings
+ There are more things that could be checked for portability.
+
+`RECLEN' variable for fixed length records
+ Along with `FIELDWIDTHS', this would speed up the processing of
+ fixed-length records.
+
+`RT' variable to hold the record terminator
+ It is occasionally useful to have access to the actual string of
+ characters that matched the `RS' variable. The `RT' variable
+ would hold these characters.
+
+A `restart' keyword
+ After modifying `$0', `restart' would restart the pattern matching
+ loop, without reading a new record from the input.
+
+A `|&' redirection
+ The `|&' redirection, in place of `|', would open a two-way
+ pipeline for communication with a sub-process (via `getline' and
+ `print' and `printf').
+
+`IGNORECASE' affecting all comparisons
+ The effects of the `IGNORECASE' variable may be generalized to all
+ string comparisons, and not just regular expression operations.
+
+A way to mix command line source code and library files
+ There may be a new option that would make it possible to easily
+ use library functions from a program entered on the command line.
+
+GNU-style long options
+ We will add GNU-style long options to `gawk' for compatibility
+ with other GNU programs. (For example, `--field-separator=:'
+ would be equivalent to `-F:'.)
+
+
+File: gawk.info, Node: Improvements, Prev: Future Extensions, Up: Notes
+
+Suggestions for Improvements
+============================
+
+ Here are some projects that would-be `gawk' hackers might like to
+take on. They vary in size from a few days to a few weeks of
+programming, depending on which one you choose and how fast a
+programmer you are. Please send any improvements you write to the
+maintainers at the GNU project.
+
+ 1. Compilation of `awk' programs: `gawk' uses a Bison (YACC-like)
+ parser to convert the script given it into a syntax tree; the
+ syntax tree is then executed by a simple recursive evaluator.
+ This method incurs a lot of overhead, since the recursive
+ evaluator performs many procedure calls to do even the simplest
+ things.
+
+ It should be possible for `gawk' to convert the script's parse tree
+ into a C program which the user would then compile, using the
+ normal C compiler and a special `gawk' library to provide all the
+ needed functions (regexps, fields, associative arrays, type
+ coercion, and so on).
+
+ An easier possibility might be for an intermediate phase of `awk'
+ to convert the parse tree into a linear byte code form like the
+ one used in GNU Emacs Lisp. The recursive evaluator would then be
+ replaced by a straight line byte code interpreter that would be
+ intermediate in speed between running a compiled program and doing
+ what `gawk' does now.
+
+ This may actually happen for the 3.0 version of `gawk'.
+
+ 2. An error message section has not been included in this version of
+ the manual. Perhaps some nice beta testers will document some of
+ the messages for the future.
+
+ 3. The programs in the test suite could use documenting in this
+ manual.
+
+ 4. The programs and data files in the manual should be available in
+ separate files to facilitate experimentation.
+
+ 5. See the `FUTURES' file for more ideas. Contact us if you would
+ seriously like to tackle any of the items listed there.
+
+
+File: gawk.info, Node: Glossary, Next: Index, Prev: Notes, Up: Top
+
+Glossary
+********
+
+Action
+ A series of `awk' statements attached to a rule. If the rule's
+ pattern matches an input record, the `awk' language executes the
+ rule's action. Actions are always enclosed in curly braces.
+ *Note Overview of Actions: Actions.
+
+Amazing `awk' Assembler
+ Henry Spencer at the University of Toronto wrote a retargetable
+ assembler completely as `awk' scripts. It is thousands of lines
+ long, including machine descriptions for several 8-bit
+ microcomputers. It is a good example of a program that would have
+ been better written in another language.
+
+ANSI
+ The American National Standards Institute. This organization
+ produces many standards, among them the standard for the C
+ programming language.
+
+Assignment
+ An `awk' expression that changes the value of some `awk' variable
+ or data object. An object that you can assign to is called an
+ "lvalue". *Note Assignment Expressions: Assignment Ops.
+
+`awk' Language
+ The language in which `awk' programs are written.
+
+`awk' Program
+ An `awk' program consists of a series of "patterns" and "actions",
+ collectively known as "rules". For each input record given to the
+ program, the program's rules are all processed in turn. `awk'
+ programs may also contain function definitions.
+
+`awk' Script
+ Another name for an `awk' program.
+
+Built-in Function
+ The `awk' language provides built-in functions that perform various
+ numerical, time stamp related, and string computations. Examples
+ are `sqrt' (for the square root of a number) and `substr' (for a
+ substring of a string). *Note Built-in Functions: Built-in.
+
+Built-in Variable
+ `ARGC', `ARGIND', `ARGV', `CONVFMT', `ENVIRON', `ERRNO',
+ `FIELDWIDTHS', `FILENAME', `FNR', `FS', `IGNORECASE', `NF', `NR',
+ `OFMT', `OFS', `ORS', `RLENGTH', `RSTART', `RS', and `SUBSEP', are
+ the variables that have special meaning to `awk'. Changing some
+ of them affects `awk''s running environment. *Note Built-in
+ Variables::.
+
+Braces
+ See "Curly Braces."
+
+C
+ The system programming language that most GNU software is written
+ in. The `awk' programming language has C-like syntax, and this
+ manual points out similarities between `awk' and C when
+ appropriate.
+
+CHEM
+ A preprocessor for `pic' that reads descriptions of molecules and
+ produces `pic' input for drawing them. It was written by Brian
+ Kernighan, and is available from `netlib@research.att.com'.
+
+Compound Statement
+ A series of `awk' statements, enclosed in curly braces. Compound
+ statements may be nested. *Note Control Statements in Actions:
+ Statements.
+
+Concatenation
+ Concatenating two strings means sticking them together, one after
+ another, giving a new string. For example, the string `foo'
+ concatenated with the string `bar' gives the string `foobar'.
+ *Note String Concatenation: Concatenation.
+
+Conditional Expression
+ An expression using the `?:' ternary operator, such as `EXPR1 ?
+ EXPR2 : EXPR3'. The expression EXPR1 is evaluated; if the result
+ is true, the value of the whole expression is the value of EXPR2
+ otherwise the value is EXPR3. In either case, only one of EXPR2
+ and EXPR3 is evaluated. *Note Conditional Expressions:
+ Conditional Exp.
+
+Constant Regular Expression
+ A constant regular expression is a regular expression written
+ within slashes, such as `/foo/'. This regular expression is chosen
+ when you write the `awk' program, and cannot be changed doing its
+ execution. *Note How to Use Regular Expressions: Regexp Usage.
+
+Comparison Expression
+ A relation that is either true or false, such as `(a < b)'.
+ Comparison expressions are used in `if', `while', and `for'
+ statements, and in patterns to select which input records to
+ process. *Note Comparison Expressions: Comparison Ops.
+
+Curly Braces
+ The characters `{' and `}'. Curly braces are used in `awk' for
+ delimiting actions, compound statements, and function bodies.
+
+Data Objects
+ These are numbers and strings of characters. Numbers are
+ converted into strings and vice versa, as needed. *Note
+ Conversion of Strings and Numbers: Conversion.
+
+Dynamic Regular Expression
+ A dynamic regular expression is a regular expression written as an
+ ordinary expression. It could be a string constant, such as
+ `"foo"', but it may also be an expression whose value may vary.
+ *Note How to Use Regular Expressions: Regexp Usage.
+
+Escape Sequences
+ A special sequence of characters used for describing nonprinting
+ characters, such as `\n' for newline, or `\033' for the ASCII ESC
+ (escape) character. *Note Constant Expressions: Constants.
+
+Field
+ When `awk' reads an input record, it splits the record into pieces
+ separated by whitespace (or by a separator regexp which you can
+ change by setting the built-in variable `FS'). Such pieces are
+ called fields. If the pieces are of fixed length, you can use the
+ built-in variable `FIELDWIDTHS' to describe their lengths. *Note
+ How Input is Split into Records: Records.
+
+Format
+ Format strings are used to control the appearance of output in the
+ `printf' statement. Also, data conversions from numbers to strings
+ are controlled by the format string contained in the built-in
+ variable `CONVFMT'. *Note Format-Control Letters: Control Letters.
+
+Function
+ A specialized group of statements often used to encapsulate general
+ or program-specific tasks. `awk' has a number of built-in
+ functions, and also allows you to define your own. *Note Built-in
+ Functions: Built-in. Also, see *Note User-defined Functions:
+ User-defined.
+
+`gawk'
+ The GNU implementation of `awk'.
+
+GNU
+ "GNU's not Unix". An on-going project of the Free Software
+ Foundation to create a complete, freely distributable,
+ POSIX-compliant computing environment.
+
+Input Record
+ A single chunk of data read in by `awk'. Usually, an `awk' input
+ record consists of one line of text. *Note How Input is Split
+ into Records: Records.
+
+Keyword
+ In the `awk' language, a keyword is a word that has special
+ meaning. Keywords are reserved and may not be used as variable
+ names.
+
+ `awk''s keywords are: `if', `else', `while', `do...while', `for',
+ `for...in', `break', `continue', `delete', `next', `function',
+ `func', and `exit'.
+
+Lvalue
+ An expression that can appear on the left side of an assignment
+ operator. In most languages, lvalues can be variables or array
+ elements. In `awk', a field designator can also be used as an
+ lvalue.
+
+Number
+ A numeric valued data object. The `gawk' implementation uses
+ double precision floating point to represent numbers.
+
+Pattern
+ Patterns tell `awk' which input records are interesting to which
+ rules.
+
+ A pattern is an arbitrary conditional expression against which
+ input is tested. If the condition is satisfied, the pattern is
+ said to "match" the input record. A typical pattern might compare
+ the input record against a regular expression. *Note Patterns::.
+
+POSIX
+ The name for a series of standards being developed by the IEEE
+ that specify a Portable Operating System interface. The "IX"
+ denotes the Unix heritage of these standards. The main standard
+ of interest for `awk' users is P1003.2, the Command Language and
+ Utilities standard.
+
+Range (of input lines)
+ A sequence of consecutive lines from the input file. A pattern
+ can specify ranges of input lines for `awk' to process, or it can
+ specify single lines. *Note Patterns::.
+
+Recursion
+ When a function calls itself, either directly or indirectly. If
+ this isn't clear, refer to the entry for "recursion."
+
+Redirection
+ Redirection means performing input from other than the standard
+ input stream, or output to other than the standard output stream.
+
+ You can redirect the output of the `print' and `printf' statements
+ to a file or a system command, using the `>', `>>', and `|'
+ operators. You can redirect input to the `getline' statement using
+ the `<' and `|' operators. *Note Redirecting Output of `print'
+ and `printf': Redirection.
+
+Regular Expression
+ See "regexp."
+
+Regexp
+ Short for "regular expression". A regexp is a pattern that
+ denotes a set of strings, possibly an infinite set. For example,
+ the regexp `R.*xp' matches any string starting with the letter `R'
+ and ending with the letters `xp'. In `awk', regexps are used in
+ patterns and in conditional expressions. Regexps may contain
+ escape sequences. *Note Regular Expressions as Patterns: Regexp.
+
+Rule
+ A segment of an `awk' program, that specifies how to process single
+ input records. A rule consists of a "pattern" and an "action".
+ `awk' reads an input record; then, for each rule, if the input
+ record satisfies the rule's pattern, `awk' executes the rule's
+ action. Otherwise, the rule does nothing for that input record.
+
+Side Effect
+ A side effect occurs when an expression has an effect aside from
+ merely producing a value. Assignment expressions, increment
+ expressions and function calls have side effects. *Note
+ Assignment Expressions: Assignment Ops.
+
+Special File
+ A file name interpreted internally by `gawk', instead of being
+ handed directly to the underlying operating system. For example,
+ `/dev/stdin'. *Note Standard I/O Streams: Special Files.
+
+Stream Editor
+ A program that reads records from an input stream and processes
+ them one or more at a time. This is in contrast with batch
+ programs, which may expect to read their input files in entirety
+ before starting to do anything, and with interactive programs,
+ which require input from the user.
+
+String
+ A datum consisting of a sequence of characters, such as `I am a
+ string'. Constant strings are written with double-quotes in the
+ `awk' language, and may contain escape sequences. *Note Constant
+ Expressions: Constants.
+
+Whitespace
+ A sequence of blank or tab characters occurring inside an input
+ record or a string.
+
diff --git a/gawk.info-9 b/gawk.info-9
new file mode 100644
index 00000000..636de34d
--- /dev/null
+++ b/gawk.info-9
@@ -0,0 +1,359 @@
+This is Info file gawk.info, produced by Makeinfo-1.54 from the input
+file gawk.texi.
+
+ This file documents `awk', a program that you can use to select
+particular records in a file and perform operations upon them.
+
+ This is Edition 0.15 of `The GAWK Manual',
+for the 2.15 version of the GNU implementation
+of AWK.
+
+ Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that
+the entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Foundation.
+
+
+File: gawk.info, Node: Index, Prev: Glossary, Up: Top
+
+Index
+*****
+
+* Menu:
+
+* $ (field operator): Fields.
+* -assign option: Options.
+* -compat option: Options.
+* -copyleft option: Options.
+* -copyright option: Options.
+* -field-separator option: Options.
+* -file option: Options.
+* -help option: Options.
+* -lint option: Options.
+* -posix option: Options.
+* -source option: Options.
+* -usage option: Options.
+* -version option: Options.
+* AWKPATH environment variable: AWKPATH Variable.
+* awk language: This Manual.
+* awk program: This Manual.
+* BEGIN special pattern: BEGIN/END.
+* break statement: Break Statement.
+* continue statement: Continue Statement.
+* delete statement: Delete.
+* END special pattern: BEGIN/END.
+* exit statement: Exit Statement.
+* for (x in ...): Scanning an Array.
+* for statement: For Statement.
+* if statement: If Statement.
+* next file statement: Next File Statement.
+* next statement: Next Statement.
+* printf statement, syntax of: Basic Printf.
+* printf, format-control characters: Control Letters.
+* printf, modifiers: Format Modifiers.
+* print statement: Print.
+* return statement: Return Statement.
+* while statement: While Statement.
+* /dev/fd/: Special Files.
+* /dev/pgrpid: Special Files.
+* /dev/pid: Special Files.
+* /dev/ppid: Special Files.
+* /dev/stderr: Special Files.
+* /dev/stdin: Special Files.
+* /dev/stdout: Special Files.
+* /dev/user: Special Files.
+* BBS-list file: Sample Data Files.
+* inventory-shipped file: Sample Data Files.
+* #!: Executable Scripts.
+* #: Comments.
+* -F option: Field Separators.
+* -f option: Long.
+* -v option: Options.
+* -W option: Options.
+* print $0: Very Simple.
+* accessing fields: Fields.
+* acronym: History.
+* action, curly braces: Actions.
+* action, default: Very Simple.
+* action, definition of: Actions.
+* action, separating statements: Actions.
+* addition: Arithmetic Ops.
+* and operator: Boolean Ops.
+* anonymous ftp: Extracting.
+* anonymous uucp: Extracting.
+* applications of awk: When.
+* ARGIND: Auto-set.
+* arguments in function call: Function Calls.
+* arguments, command line: Command Line.
+* ARGV: Other Arguments.
+* arithmetic operators: Arithmetic Ops.
+* array assignment: Assigning Elements.
+* array reference: Reference to Elements.
+* arrays: Array Intro.
+* arrays, definition of: Array Intro.
+* arrays, deleting an element: Delete.
+* arrays, multi-dimensional subscripts: Multi-dimensional.
+* arrays, presence of elements: Reference to Elements.
+* arrays, special for statement: Scanning an Array.
+* assignment operators: Assignment Ops.
+* assignment to fields: Changing Fields.
+* associative arrays: Array Intro.
+* backslash continuation: Statements/Lines.
+* basic function of gawk: Getting Started.
+* body of a loop: While Statement.
+* boolean expressions: Boolean Ops.
+* boolean operators: Boolean Ops.
+* boolean patterns: Boolean Patterns.
+* buffering output: I/O Functions.
+* buffers, flushing: I/O Functions.
+* built-in functions: Built-in.
+* built-in variables: Built-in Variables.
+* built-in variables, user modifiable: User-modified.
+* call by reference: Function Caveats.
+* call by value: Function Caveats.
+* calling a function: Function Calls.
+* case sensitivity: Read Terminal.
+* changing contents of a field: Changing Fields.
+* close: Close Input.
+* close: Close Output.
+* closing input files and pipes: Close Input.
+* closing output files and pipes: Close Output.
+* command line: Command Line.
+* command line formats: Running gawk.
+* command line, setting FS on: Field Separators.
+* comments: Comments.
+* comparison expressions: Comparison Ops.
+* comparison expressions as patterns: Comparison Patterns.
+* computed regular expressions: Regexp Usage.
+* concatenation: Concatenation.
+* conditional expression: Conditional Exp.
+* constants, types of: Constants.
+* continuation of lines: Statements/Lines.
+* control statement: Statements.
+* conversion of strings and numbers: Conversion.
+* conversion of strings and numbers: Values.
+* conversions, during subscripting: Numeric Array Subscripts.
+* CONVFMT: Numeric Array Subscripts.
+* CONVFMT: Comparison Ops.
+* CONVFMT: Conversion.
+* curly braces: Actions.
+* default action: Very Simple.
+* default pattern: Very Simple.
+* defining functions: Definition Syntax.
+* deleting elements of arrays: Delete.
+* deprecated features: Obsolete.
+* deprecated options: Obsolete.
+* differences: gawk and awk: Getline.
+* directory search: AWKPATH Variable.
+* division: Arithmetic Ops.
+* documenting awk programs: Comments.
+* dynamic regular expressions: Regexp Usage.
+* element assignment: Assigning Elements.
+* element of array: Reference to Elements.
+* empty pattern: Empty.
+* ENVIRON: Auto-set.
+* ERRNO: Getline.
+* escape sequence notation: Constants.
+* examining fields: Fields.
+* executable scripts: Executable Scripts.
+* explicit input: Getline.
+* exponentiation: Arithmetic Ops.
+* expression: Expressions.
+* expression, conditional: Conditional Exp.
+* expressions, assignment: Assignment Ops.
+* expressions, boolean: Boolean Ops.
+* expressions, comparison: Comparison Ops.
+* field separator, FS: Field Separators.
+* field separator, choice of: Field Separators.
+* field separator: on command line: Field Separators.
+* field, changing contents of: Changing Fields.
+* fields: Fields.
+* fields, separating: Field Separators.
+* file descriptors: Special Files.
+* file, awk program: Long.
+* FILENAME: Reading Files.
+* flushing buffers: I/O Functions.
+* FNR: Records.
+* format specifier: Control Letters.
+* format string: Basic Printf.
+* formatted output: Printf.
+* FS: Field Separators.
+* ftp, anonymous: Extracting.
+* function call: Function Calls.
+* function definition: Definition Syntax.
+* functions, user-defined: User-defined.
+* getline: Getline.
+* getting gawk: Extracting.
+* gsub: String Functions.
+* history of awk: History.
+* how awk works: Two Rules.
+* increment operators: Increment Ops.
+* input: Reading Files.
+* input file, sample: Sample Data Files.
+* input redirection: Getline.
+* input, getline command: Getline.
+* input, explicit: Getline.
+* input, multiple line records: Multiple Line.
+* input, standard: Read Terminal.
+* installation, atari: Atari Installation.
+* installation, ms-dos: MS-DOS Installation.
+* installation, unix: Quick Installation.
+* installation, vms: VMS Installation.
+* interaction, awk and other programs: I/O Functions.
+* invocation of gawk: Command Line.
+* language, awk: This Manual.
+* length: String Functions.
+* logical operations: Boolean Ops.
+* long options: Command Line.
+* loop: While Statement.
+* loops, exiting: Break Statement.
+* lvalue: Assignment Ops.
+* manual, using this: This Manual.
+* match: String Functions.
+* match: String Functions.
+* metacharacters: Regexp Operators.
+* modifiers (in format specifiers): Format Modifiers.
+* multi-dimensional subscripts: Multi-dimensional.
+* multiple line records: Multiple Line.
+* multiple passes over data: Other Arguments.
+* multiple statements on one line: Statements/Lines.
+* multiplication: Arithmetic Ops.
+* NF: Fields.
+* not operator: Boolean Ops.
+* NR: Records.
+* number of fields, NF: Fields.
+* number of records, NR or FNR: Records.
+* numbers, used as subscripts: Numeric Array Subscripts.
+* numeric constant: Constants.
+* numeric value: Constants.
+* obsolete features: Obsolete.
+* obsolete options: Obsolete.
+* OFMT: Conversion.
+* OFMT: OFMT.
+* OFS: Output Separators.
+* one-liners: One-liners.
+* operator precedence: Precedence.
+* operators, $: Fields.
+* operators, arithmetic: Arithmetic Ops.
+* operators, assignment: Assignment Ops.
+* operators, boolean: Boolean Ops.
+* operators, increment: Increment Ops.
+* operators, regexp matching: Regexp Usage.
+* operators, relational: Comparison Patterns.
+* operators, relational: Comparison Ops.
+* operators, string: Concatenation.
+* operators, string-matching: Regexp Usage.
+* options, command line: Command Line.
+* options, long: Command Line.
+* or operator: Boolean Ops.
+* ORS: Output Separators.
+* output: Printing.
+* output field separator, OFS: Output Separators.
+* output record separator, ORS: Output Separators.
+* output redirection: Redirection.
+* output, buffering: I/O Functions.
+* output, formatted: Printf.
+* output, piping: File/Pipe Redirection.
+* passes, multiple: Other Arguments.
+* path, search: AWKPATH Variable.
+* pattern, case sensitive: Read Terminal.
+* pattern, comparison expressions: Comparison Patterns.
+* pattern, default: Very Simple.
+* pattern, definition of: Patterns.
+* pattern, empty: Empty.
+* pattern, regular expressions: Regexp.
+* patterns, BEGIN: BEGIN/END.
+* patterns, END: BEGIN/END.
+* patterns, boolean: Boolean Patterns.
+* patterns, range: Ranges.
+* patterns, types of: Kinds of Patterns.
+* pipes for output: File/Pipe Redirection.
+* precedence: Precedence.
+* printing: Printing.
+* program file: Long.
+* program, awk: This Manual.
+* program, definition of: Getting Started.
+* program, self contained: Executable Scripts.
+* programs, documenting: Comments.
+* quotient: Arithmetic Ops.
+* range pattern: Ranges.
+* reading files: Reading Files.
+* reading files, getline command: Getline.
+* reading files, multiple line records: Multiple Line.
+* record separator: Records.
+* records, multiple line: Multiple Line.
+* redirection of input: Getline.
+* redirection of output: Redirection.
+* reference to array: Reference to Elements.
+* regexp: Regexp.
+* regexp as expression: Comparison Ops.
+* regexp operators: Comparison Ops.
+* regexp search operators: Regexp Usage.
+* regular expression matching operators: Regexp Usage.
+* regular expression metacharacters: Regexp Operators.
+* regular expressions as field separators: Field Separators.
+* regular expressions as patterns: Regexp.
+* regular expressions, computed: Regexp Usage.
+* relational operators: Comparison Ops.
+* relational operators: Comparison Patterns.
+* remainder: Arithmetic Ops.
+* removing elements of arrays: Delete.
+* RLENGTH: String Functions.
+* RS: Records.
+* RSTART: String Functions.
+* rule, definition of: Getting Started.
+* running awk programs: Running gawk.
+* running long programs: Long.
+* sample input file: Sample Data Files.
+* scanning an array: Scanning an Array.
+* script, definition of: Getting Started.
+* scripts, executable: Executable Scripts.
+* scripts, shell: Executable Scripts.
+* search path: AWKPATH Variable.
+* self contained programs: Executable Scripts.
+* shell scripts: Executable Scripts.
+* side effect: Assignment Ops.
+* single quotes, why needed: One-shot.
+* split: String Functions.
+* sprintf: String Functions.
+* standard error output: Special Files.
+* standard input: Read Terminal.
+* standard input: Reading Files.
+* standard input: Special Files.
+* standard output: Special Files.
+* strftime: Time Functions.
+* string constants: Constants.
+* string operators: Concatenation.
+* string-matching operators: Regexp Usage.
+* sub: String Functions.
+* subscripts in arrays: Multi-dimensional.
+* SUBSEP: Multi-dimensional.
+* substr: String Functions.
+* subtraction: Arithmetic Ops.
+* system: I/O Functions.
+* systime: Time Functions.
+* time of day: Time Functions.
+* time stamps: Time Functions.
+* tolower: String Functions.
+* toupper: String Functions.
+* use of comments: Comments.
+* user-defined functions: User-defined.
+* user-defined variables: Variables.
+* uses of awk: Preface.
+* using this manual: This Manual.
+* uucp, anonymous: Extracting.
+* variables, user-defined: Variables.
+* when to use awk: When.
+
+
diff --git a/gawk.texi b/gawk.texi
index f7b0fa33..b2802623 100644
--- a/gawk.texi
+++ b/gawk.texi
@@ -32,11 +32,11 @@
This file documents @code{awk}, a program that you can use to select
particular records in a file and perform operations upon them.
-This is Edition 0.14 of @cite{The GAWK Manual}, @*
-for the 2.14 version of the GNU implementation @*
+This is Edition 0.15 of @cite{The GAWK Manual}, @*
+for the 2.15 version of the GNU implementation @*
of AWK.
-Copyright (C) 1989, 1991, 1992 Free Software Foundation, Inc.
+Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@@ -65,8 +65,8 @@ by the Foundation.
@c !!set edition, date, version
@titlepage
@title The GAWK Manual
-@subtitle Edition 0.14
-@subtitle November 1992
+@subtitle Edition 0.15
+@subtitle April 1993
@author Diane Barlow Close
@author Arnold D. Robbins
@author Paul H. Rubin
@@ -77,19 +77,19 @@ by the Foundation.
@page
@vskip 0pt plus 1filll
-Copyright @copyright{} 1989, 1991, 1992 Free Software Foundation, Inc.
+Copyright @copyright{} 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
@sp 2
@c !!set edition, date, version
-This is Edition 0.14 of @cite{The GAWK Manual}, @*
-for the 2.14 version of the GNU implementation @*
+This is Edition 0.15 of @cite{The GAWK Manual}, @*
+for the 2.15 version of the GNU implementation @*
of AWK.
@sp 2
Published by the Free Software Foundation @*
675 Massachusetts Avenue @*
Cambridge, MA 02139 USA @*
-Printed copies are available for $15 each.
+Printed copies are available for $20 each.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@@ -117,8 +117,8 @@ This file documents @code{awk}, a program that you can use to select
particular records in a file and perform operations upon them.
@c !!set edition, date, version
-This is Edition 0.14 of @cite{The GAWK Manual}, @*
-for the 2.14 version of the GNU implementation @*
+This is Edition 0.15 of @cite{The GAWK Manual}, @*
+for the 2.15 version of the GNU implementation @*
of AWK.
@end ifinfo
@@ -639,7 +639,8 @@ when it starts in an interactive mode:
@smallexample
Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
-Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
+type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
@end smallexample
@@ -1821,9 +1822,9 @@ expression. @code{awk} scans the input record for matches for the
separator; the fields themselves are the text between the matches. For
example, if the field separator is @samp{oo}, then the following line:
-@example
+@smallexample
moo goo gai pan
-@end example
+@end smallexample
@noindent
would be split into three fields: @samp{m}, @samp{@ g} and @samp{@ gai@
@@ -1843,16 +1844,16 @@ will be read with the proper separator. To do this, use the special
For example, here we set the value of @code{FS} to the string
@code{","}:@refill
-@example
+@smallexample
awk 'BEGIN @{ FS = "," @} ; @{ print $2 @}'
-@end example
+@end smallexample
@noindent
Given the input line,
-@example
+@smallexample
John Q. Smith, 29 Oak St., Walamazoo, MI 42139
-@end example
+@end smallexample
@noindent
this @code{awk} program extracts the string @samp{@ 29 Oak St.}.
@@ -1865,9 +1866,9 @@ person's name in the example we've been using might have a title or
suffix attached, such as @samp{John Q. Smith, LXIX}. From input
containing such a name:
-@example
+@smallexample
John Q. Smith, LXIX, 29 Oak St., Walamazoo, MI 42139
-@end example
+@end smallexample
@noindent
the previous sample program would extract @samp{@ LXIX}, instead of
@@ -1896,9 +1897,9 @@ More generally, the value of @code{FS} may be a string containing any
regular expression. Then each match in the record for the regular
expression separates fields. For example, the assignment:@refill
-@example
+@smallexample
FS = ", \t"
-@end example
+@end smallexample
@noindent
makes every area of an input line that consists of a comma followed by a
@@ -1916,9 +1917,9 @@ matches a single space and nothing else.
@code{FS} can be set on the command line. You use the @samp{-F} argument to
do so. For example:
-@example
+@smallexample
awk -F, '@var{program}' @var{input-files}
-@end example
+@end smallexample
@noindent
sets @code{FS} to be the @samp{,} character. Notice that the argument uses
@@ -1935,10 +1936,10 @@ if the field separator contains special characters, they must be escaped
appropriately. For example, to use a @samp{\} as the field separator, you
would have to type:
-@example
+@smallexample
# same as FS = "\\"
awk -F\\\\ '@dots{}' files @dots{}
-@end example
+@end smallexample
@noindent
Since @samp{\} is used for quoting in the shell, @code{awk} will see
@@ -1960,23 +1961,23 @@ For example, let's use an @code{awk} program file called @file{baud.awk}
that contains the pattern @code{/300/}, and the action @samp{print $1}.
Here is the program:
-@example
+@smallexample
/300/ @{ print $1 @}
-@end example
+@end smallexample
Let's also set @code{FS} to be the @samp{-} character, and run the
program on the file @file{BBS-list}. The following command prints a
list of the names of the bulletin boards that operate at 300 baud and
the first three digits of their phone numbers:@refill
-@example
+@smallexample
awk -F- -f baud.awk BBS-list
-@end example
+@end smallexample
@noindent
It produces this output:
-@example
+@smallexample
aardvark 555
alpo
barfly 555
@@ -1988,15 +1989,15 @@ foot 555
macfoo 555
sdace 555
sabafoo 555
-@end example
+@end smallexample
@noindent
Note the second line of output. If you check the original file, you will
see that the second line looked like this:
-@example
+@smallexample
alpo-net 555-3412 2400/1200/300 A
-@end example
+@end smallexample
The @samp{-} as part of the system's name was used as the field
separator, instead of the @samp{-} in the phone number that was
@@ -2006,9 +2007,9 @@ choosing your field and record separators.
The following program searches the system password file, and prints
the entries for users who have no password:
-@example
+@smallexample
awk -F: '$2 == ""' /etc/passwd
-@end example
+@end smallexample
@noindent
Here we use the @samp{-F} option on the command line to set the field
@@ -2030,24 +2031,24 @@ using the @emph{current} value of @code{FS}! This behavior can be difficult
to diagnose. The following example illustrates the results of the two methods.
(The @code{sed} command prints just the first line of @file{/etc/passwd}.)
-@example
+@smallexample
sed 1q /etc/passwd | awk '@{ FS = ":" ; print $1 @}'
-@end example
+@end smallexample
@noindent
will usually print
-@example
+@smallexample
root
-@end example
+@end smallexample
@noindent
on an incorrect implementation of @code{awk}, while @code{gawk}
will print something like
-@example
+@smallexample
root:nSijPlPhZZwgE:0:0:Root:/:
-@end example
+@end smallexample
@c end expert info
@c begin expert info
@@ -2060,16 +2061,16 @@ from the record, and then decide where the fields are.
For example, the following expression prints @samp{b}:
-@example
+@smallexample
echo ' a b c d ' | awk '@{ print $2 @}'
-@end example
+@end smallexample
@noindent
However, the following prints @samp{a}:
-@example
+@smallexample
echo ' a b c d ' | awk 'BEGIN @{ FS = "[ \t]+" @} ; @{ print $2 @}'
-@end example
+@end smallexample
@noindent
In this case, the first field is null.
@@ -2077,17 +2078,17 @@ In this case, the first field is null.
The stripping of leading and trailing whitespace also comes into
play whenever @code{$0} is recomputed. For instance, this pipeline
-@example
+@smallexample
echo ' a b c d' | awk '@{ print; $2 = $2; print @}'
-@end example
+@end smallexample
@noindent
produces this output:
-@example
+@smallexample
a b c d
a b c d
-@end example
+@end smallexample
@noindent
The first @code{print} statement prints the record as it was read,
@@ -2145,7 +2146,7 @@ subsequently ignored.
The following data is the output of the @code{w} utility. It is useful
to illustrate the use of @code{FIELDWIDTHS}.
-@example
+@smallexample
10:06pm up 21 days, 14:04, 23 users
User tty login@ idle JCPU PCPU what
hzuo ttyV0 8:58pm 9 5 vi p24.tex
@@ -2156,14 +2157,14 @@ gierd ttyD3 10:00pm 1 elm
dave ttyD4 9:47pm 4 4 w
brent ttyp0 26Jun91 4:46 26:46 4:41 bash
dave ttyq4 26Jun9115days 46 46 wnewmail
-@end example
+@end smallexample
The following program takes the above input, converts the idle time to
number of seconds and prints out the first two fields and the calculated
idle time. (This program uses a number of @code{awk} features that
haven't been introduced yet.)@refill
-@example
+@smallexample
BEGIN @{ FIELDWIDTHS = "9 6 10 6 7 7 35" @}
NR > 2 @{
idle = $4
@@ -2174,11 +2175,11 @@ NR > 2 @{
print $1, $2, idle
@}
-@end example
+@end smallexample
Here is the result of running the program on the data:
-@example
+@smallexample
hzuo ttyV0 0
hzang ttyV3 50
eklye ttyV5 0
@@ -2187,7 +2188,7 @@ gierd ttyD3 1
dave ttyD4 0
brent ttyp0 286
dave ttyq4 1296000
-@end example
+@end smallexample
Another (possibly more practical) example of fixed-width input data
would be the input from a deck of balloting cards. In some parts of
@@ -2310,9 +2311,13 @@ include material that has not been covered yet. Therefore, come back
and study the @code{getline} command @emph{after} you have reviewed the
rest of this manual and have a good knowledge of how @code{awk} works.
+@vindex ERRNO
+@cindex differences: @code{gawk} and @code{awk}
@code{getline} returns 1 if it finds a record, and 0 if the end of the
file is encountered. If there is some error in getting a record, such
as a file that cannot be opened, then @code{getline} returns @minus{}1.
+In this case, @code{gawk} sets the variable @code{ERRNO} to a string
+describing the error that occurred.
In the following examples, @var{command} stands for a string value that
represents a shell command.
@@ -2620,6 +2625,15 @@ close("sort -r names")
Once this function call is executed, the next @code{getline} from that
file or command will reopen the file or rerun the command.
+@iftex
+@vindex ERRNO
+@cindex differences: @code{gawk} and @code{awk}
+@end iftex
+@code{close} returns a value of zero if the close succeeded.
+Otherwise, the value will be non-zero.
+In this case, @code{gawk} sets the variable @code{ERRNO} to a string
+describing the error that occurred.
+
@node Printing, One-liners, Reading Files, Top
@chapter Printing Output
@@ -2898,7 +2912,7 @@ printf @var{format}, @var{item1}, @var{item2}, @dots{}
@end example
@noindent
-The entire list of items may optionally be enclosed in parentheses. The
+The entire list of arguments may optionally be enclosed in parentheses. The
parentheses are necessary if any of the item expressions uses a
relational operator; otherwise it could be confused with a redirection
(@pxref{Redirection, ,Redirecting Output of @code{print} and @code{printf}}).
@@ -3367,6 +3381,15 @@ a single message of several lines. By contrast, if you close the pipe
after each line of output, then each line makes a separate message.
@end itemize
+@iftex
+@vindex ERRNO
+@cindex differences: @code{gawk} and @code{awk}
+@end iftex
+@code{close} returns a value of zero if the close succeeded.
+Otherwise, the value will be non-zero.
+In this case, @code{gawk} sets the variable @code{ERRNO} to a string
+describing the error that occurred.
+
@node Special Files, , Redirection, Printing
@section Standard I/O Streams
@cindex standard input
@@ -3436,8 +3459,8 @@ The standard output (file descriptor 1).
@item /dev/stderr
The standard error output (file descriptor 2).
-@item /dev/fd/@var{n}
-The file associated with file descriptor @var{n}. Such a file must have
+@item /dev/fd/@var{N}
+The file associated with file descriptor @var{N}. Such a file must have
been opened by the program initiating the @code{awk} execution (typically
the shell). Unless you take special pains, only descriptors 0, 1 and 2
are available.
@@ -3456,11 +3479,64 @@ NF != 4 @{
@}
@end smallexample
+@code{gawk} also provides special file names that give access to information
+about the running @code{gawk} process. Each of these ``files'' provides
+a single record of information. To read them more than once, you must
+first close them with the @code{close} function
+(@pxref{Close Input, ,Closing Input Files and Pipes}).
+The filenames are:
+
+@cindex @file{/dev/pid}
+@cindex @file{/dev/pgrpid}
+@cindex @file{/dev/ppid}
+@cindex @file{/dev/user}
+@table @file
+@item /dev/pid
+Reading this file returns the process ID of the current process,
+in decimal, terminated with a newline.
+
+@item /dev/ppid
+Reading this file returns the parent process ID of the current process,
+in decimal, terminated with a newline.
+
+@item /dev/pgrpid
+Reading this file returns the process group ID of the current process,
+in decimal, terminated with a newline.
+
+@item /dev/user
+Reading this file returns a single record terminated with a newline.
+The fields are separated with blanks. The fields represent the
+following information:
+
+@table @code
+@item $1
+The value of the @code{getuid} system call.
+
+@item $2
+The value of the @code{geteuid} system call.
+
+@item $3
+The value of the @code{getgid} system call.
+
+@item $4
+The value of the @code{getegid} system call.
+@end table
+
+If there are any additional fields, they are the group IDs returned by
+@code{getgroups} system call.
+(Multiple groups may not be supported on all systems.)@refill
+@end table
+
+These special file names may be used on the command line as data
+files, as well as for I/O redirections within an @code{awk} program.
+They may not be used as source files with the @samp{-f} option.
+
Recognition of these special file names is disabled if @code{gawk} is in
compatibility mode (@pxref{Command Line, ,Invoking @code{awk}}).
@quotation
-@strong{Caution}: Unless your system actually has a @file{/dev/fd} directory,
+@strong{Caution}: Unless your system actually has a @file{/dev/fd} directory
+(or any of the other above listed special files),
the interpretation of these file names is done by @code{gawk} itself.
For example, using @samp{/dev/fd/4} for output will actually write on
file descriptor 4, and not on a new file descriptor that was @code{dup}'ed
@@ -5849,7 +5925,7 @@ The @code{break} statement jumps out of the innermost @code{for},
following example finds the smallest divisor of any integer, and also
identifies prime numbers:@refill
-@example
+@smallexample
awk '# find smallest divisor of num
@{ num = $1
for (div = 2; div*div <= num; div++)
@@ -5859,7 +5935,7 @@ awk '# find smallest divisor of num
printf "Smallest divisor of %d is %d\n", num, div
else
printf "%d is prime\n", num @}'
-@end example
+@end smallexample
When the remainder is zero in the first @code{if} statement, @code{awk}
immediately @dfn{breaks out} of the containing @code{for} loop. This means
@@ -5872,7 +5948,7 @@ Here is another program equivalent to the previous one. It illustrates how
the @var{condition} of a @code{for} or @code{while} could just as well be
replaced with a @code{break} inside an @code{if}:
-@example
+@smallexample
@group
awk '# find smallest divisor of num
@{ num = $1
@@ -5888,7 +5964,7 @@ awk '# find smallest divisor of num
@}
@}'
@end group
-@end example
+@end smallexample
@node Continue Statement, Next Statement, Break Statement, Statements
@section The @code{continue} Statement
@@ -6062,7 +6138,7 @@ functions, a feature that has not been presented yet.
@xref{User-defined, ,User-defined Functions},
for more information.)@refill
-@example
+@smallexample
# nextfile --- function to skip remaining records in current file
# this should be read in before the "main" awk program
@@ -6071,7 +6147,7 @@ function nextfile() @{ _abandon_ = FILENAME; next @}
_abandon_ == FILENAME && FNR > 1 @{ next @}
_abandon_ == FILENAME && FNR == 1 @{ _abandon_ = "" @}
-@end example
+@end smallexample
The @code{nextfile} function simply sets a ``private'' variable@footnote{Since
all variables in @code{awk} are global, this program uses the common
@@ -6097,6 +6173,13 @@ the next data file, you would have to continue scanning the unwanted
records (as described above). The @code{next file} statement accomplishes
this much more efficiently.
+@ignore
+Would it make sense down the road to nuke `next file' in favor of
+semantics that would make this work?
+
+ function nextfile() { ARGIND++ ; next }
+@end ignore
+
@node Exit Statement, , Next File Statement, Statements
@section The @code{exit} Statement
@@ -7358,12 +7441,15 @@ no time zone is determinable.
A literal @samp{%}.
@end table
-If a conversion specifier is not one of the above, the behavior is undefined.
-@footnote{This is because the @sc{ansi} standard for C leaves the behavior
-of the C version of @code{strftime} undefined, and @code{gawk} will use the
-system's version of @code{strftime} if it's there. Typically, the conversion
-specifier will either not appear in the returned string, or it will appear
-literally.}
+@c The parenthetical remark here should really be a footnote, but
+@c it gave formatting problems at the FSF. So for now put it in
+@c parentheses.
+If a conversion specifier is not one of the above, the behavior is
+undefined. (This is because the @sc{ansi} standard for C leaves the
+behavior of the C version of @code{strftime} undefined, and @code{gawk}
+will use the system's version of @code{strftime} if it's there.
+Typically, the conversion specifier will either not appear in the
+returned string, or it will appear literally.)
Informally, a @dfn{locale} is the geographic place in which a program
is meant to run. For example, a common way to abbreviate the date
@@ -7405,6 +7491,14 @@ Equivalent to specifying @samp{%H:%M:%S}.
@item %t
A TAB character.
+@item %k
+is replaced by the hour (24-hour clock) as a decimal number (0-23).
+Single digit numbers are padded with a blank.
+
+@item %l
+is replaced by the hour (12-hour clock) as a decimal number (1-12).
+Single digit numbers are padded with a blank.
+
@item %C
The century, as a number between 00 and 99.
@@ -7437,7 +7531,7 @@ Here are two examples that use @code{strftime}. The first is an
user defined function, which we have not discussed yet.
@xref{User-defined, ,User-defined Functions}, for more information.)
-@example
+@smallexample
# ctime.awk
#
# awk version of C ctime(3) function
@@ -7449,7 +7543,7 @@ function ctime(ts, format)
ts = systime() # use current time as default
return strftime(format, ts)
@}
-@end example
+@end smallexample
This next example is an @code{awk} implementation of the @sc{posix}
@code{date} utility. Normally, the @code{date} utility prints the
@@ -7459,20 +7553,20 @@ will copy non-format specifier characters to the standard output, and
will interpret the current time according to the format specifiers in
the string. For example:
-@example
+@smallexample
date '+Today is %A, %B %d, %Y.'
-@end example
+@end smallexample
@noindent
might print
-@example
+@smallexample
Today is Thursday, July 11, 1991.
-@end example
+@end smallexample
Here is the @code{awk} version of the @code{date} utility.
-@example
+@smallexample
#! /usr/bin/gawk -f
#
# date --- implement the P1003.2 Draft 11 'date' command
@@ -7494,7 +7588,7 @@ BEGIN \
print strftime(format)
exit exitval
@}
-@end example
+@end smallexample
@node User-defined, Built-in Variables, Built-in, Top
@chapter User-defined Functions
@@ -8019,10 +8113,12 @@ an array called @code{ARGV}. @code{ARGC} is the number of command-line
arguments present. @xref{Command Line, ,Invoking @code{awk}}.
@code{ARGV} is indexed from zero to @w{@code{ARGC - 1}}. For example:@refill
-@smallexample
-awk 'BEGIN @{ for (i = 0; i < ARGC; i++)
- print ARGV[i] @}' inventory-shipped BBS-list
-@end smallexample
+@example
+awk 'BEGIN @{
+ for (i = 0; i < ARGC; i++)
+ print ARGV[i]
+ @}' inventory-shipped BBS-list
+@end example
@noindent
In this example, @code{ARGV[0]} contains @code{"awk"}, @code{ARGV[1]}
@@ -8062,6 +8158,24 @@ replaced with the null string.
see getopt.awk in the examples...
@end ignore
+@item ARGIND
+@vindex ARGIND
+The index in @code{ARGV} of the current file being processed.
+Every time @code{gawk} opens a new data file for processing, it sets
+@code{ARGIND} to the index in @code{ARGV} of the file name. Thus, the
+condition @samp{FILENAME == ARGV[ARGIND]} is always true.
+
+This variable is useful in file processing; it allows you to tell how far
+along you are in the list of data files, and to distinguish between
+multiple successive instances of the same filename on the command line.
+
+While you can change the value of @code{ARGIND} within your @code{awk}
+program, @code{gawk} will automatically set it to a new value when the
+next file is opened.
+
+This variable is a @code{gawk} extension; in other @code{awk} implementations
+it is not special.
+
@item ENVIRON
@vindex ENVIRON
This is an array that contains the values of the environment. The array
@@ -8075,6 +8189,17 @@ does not affect the environment passed on to any programs that
Some operating systems may not have environment variables.
On such systems, the array @code{ENVIRON} is empty.
+@item ERRNO
+@iftex
+@vindex ERRNO
+@end iftex
+If a system error occurs either doing a redirection for @code{getline},
+during a read for @code{getline}, or during a @code{close} operation,
+then @code{ERRNO} will contain a string describing the error.
+
+This variable is a @code{gawk} extension; in other @code{awk} implementations
+it is not special.
+
@item FILENAME
@iftex
@vindex FILENAME
@@ -8141,15 +8266,19 @@ if no match was found.@refill
@cindex invocation of @code{gawk}
@cindex arguments, command line
@cindex options, command line
+@cindex long options
+@cindex options, long
There are two ways to run @code{awk}: with an explicit program, or with
one or more program files. Here are templates for both of them; items
enclosed in @samp{@r{[}@dots{}@r{]}} in these templates are optional.
+Besides traditional one-letter @sc{posix}-style options, @code{gawk} also
+supports GNU long named options.
+
@example
-awk @r{[@code{-F@var{fs}}] [@code{-W} @var{gawk-opts}] [@code{-v @var{var}=@var{val}}] [@code{--}]} '@var{program}' @var{file} @dots{}
-awk @r{[@code{-F@var{fs}}] [@code{-W} @var{gawk-opts}] [@code{-v @var{var}=@var{val}}] @code{-f @var{source-file}}
- [@code{-f @var{source-file} @dots{}}] [@code{--}]} @var{file} @dots{}
+awk @r{[@var{POSIX or GNU style options}]} -f progfile @r{[@code{--}]} @var{file} @dots{}
+awk @r{[@var{POSIX or GNU style options}]} @r{[@code{--}]} '@var{program}' @var{file} @dots{}
@end example
@menu
@@ -8164,19 +8293,40 @@ awk @r{[@code{-F@var{fs}}] [@code{-W} @var{gawk-opts}] [@code{-v @var{var}=@var{
@section Command Line Options
Options begin with a minus sign, and consist of a single character.
-The options and their meanings are as follows:
+GNU style long named options consist of two minus signs and
+a keyword that can be abbreviated if the abbreviation allows the option
+to be uniquely identified. If the option takes an argument, then the
+keyword is immediately followed by an equals sign (@samp{=}) and the
+argument's value. For brevity, the discussion below only refers to the
+traditional short options; however the long and short options are
+interchangeable in all contexts.
+
+Each long named option for @code{gawk} has a corresponding
+@sc{posix}-style option. The options and their meanings are as follows:
@table @code
-@item -F@var{fs}
+@item -F @var{fs}
+@itemx --field-separator=@var{fs}
+@iftex
+@cindex @code{-F} option
+@end iftex
+@cindex @code{--field-separator} option
Sets the @code{FS} variable to @var{fs}
(@pxref{Field Separators, ,Specifying how Fields are Separated}).@refill
@item -f @var{source-file}
+@itemx --file=@var{source-file}
+@iftex
+@cindex @code{-f} option
+@end iftex
+@cindex @code{--file} option
Indicates that the @code{awk} program is to be found in @var{source-file}
instead of in the first non-option argument.
@item -v @var{var}=@var{val}
+@itemx --assign=@var{var}=@var{val}
@cindex @samp{-v} option
+@cindex @code{--assign} option
Sets the variable @var{var} to the value @var{val} @emph{before}
execution of the program begins. Such variable values are available
inside the @code{BEGIN} rule (see below for a fuller explanation).
@@ -8187,14 +8337,17 @@ it more than once, setting another variable each time, like this:
@item -W @var{gawk-opt}
@cindex @samp{-W} option
-Following the @sc{posix} standard, options that are specific to @code{gawk}
-are supplied as arguments to the @samp{-W} option. These arguments
-may be separated by commas, or quoted and separated by whitespace.
-Case is ignored when processing these options. The following options
-are available:
+Following the @sc{posix} standard, options that are implementation
+specific are supplied as arguments to the @samp{-W} option. With @code{gawk},
+these arguments may be separated by commas, or quoted and separated by
+whitespace. Case is ignored when processing these options. These options
+also have corresponding GNU style long named options. The following
+@code{gawk}-specific options are available:
@table @code
-@item compat
+@item -W compat
+@itemx --compat
+@cindex @code{--compat} option
Specifies @dfn{compatibility mode}, in which the GNU extensions in
@code{gawk} are disabled, so that @code{gawk} behaves just like Unix
@code{awk}.
@@ -8202,18 +8355,37 @@ Specifies @dfn{compatibility mode}, in which the GNU extensions in
which summarizes the extensions. Also see
@ref{Compatibility Mode, ,Downward Compatibility and Debugging}.@refill
-@item lint
-Provide warnings about constructs that are dubious or non-portable to
-other @code{awk} implementations.
-
-@item copyleft
-@itemx copyright
+@item -W copyleft
+@itemx -W copyright
+@itemx --copyleft
+@itemx --copyright
+@cindex @code{--copyleft} option
+@cindex @code{--copyright} option
Print the short version of the General Public License.
This option may disappear in a future version of @code{gawk}.
-@item posix
+@item -W help
+@itemx -W usage
+@itemx --help
+@itemx --usage
+@cindex @code{--help} option
+@cindex @code{--usage} option
+Print a ``usage'' message summarizing the short and long style options
+that @code{gawk} accepts, and then exit.
+
+@item -W lint
+@itemx --lint
+@cindex @code{--lint} option
+Provide warnings about constructs that are dubious or non-portable to
+other @code{awk} implementations.
+Some warnings are issued when @code{gawk} first reads your program. Others
+are issued at run-time, as your program executes.
+
+@item -W posix
+@itemx --posix
+@cindex @code{--posix} option
Operate in strict @sc{posix} mode. This disables all @code{gawk}
-extensions (just like @code{compat}), and adds the following additional
+extensions (just like @code{-W compat}), and adds the following additional
restrictions:
@itemize @bullet{}
@@ -8239,7 +8411,18 @@ of @code{FS} to be a single tab character
Although you can supply both @samp{-W compat} and @samp{-W posix} on the
command line, @samp{-W posix} will take precedence.
-@item version
+@item -W source=@var{program-text}
+@itemx --source=@var{program-text}
+@cindex @code{--source} option
+Program source code is taken from the @var{program-text}. This option
+allows you to mix @code{awk} source code in files with program source
+code that you would enter on the command line. This is particularly useful
+when you have library functions that you wish to use from your command line
+programs (@pxref{AWKPATH Variable, ,The @code{AWKPATH} Environment Variable}).
+
+@item -W version
+@itemx --version
+@cindex @code{--version} option
Prints version information for this particular copy of @code{gawk}.
This is so you can determine if your copy of @code{gawk} is up to date
with respect to whatever the Free Software Foundation is currently
@@ -8257,10 +8440,6 @@ or in shell scripts, if you have file names that will be specified
by the user which could start with @samp{-}.
@end table
-The @samp{-a}, @samp{-e}, @samp{-c}, @samp{-C}, and @samp{-V} options
-of @code{gawk} version 2.11.1 are recognized, but produce a warning
-message. They will go away in the next major release of @code{gawk}.
-
Any other options are flagged as invalid with a warning message, but
are otherwise ignored.
@@ -8274,7 +8453,7 @@ If the @samp{-f} option is @emph{not} used, then the first non-option
command line argument is expected to be the program text.
The @samp{-f} option may be used more than once on the command line.
-Then @code{awk} reads its program source from all of the named files, as
+If it is, @code{awk} reads its program source from all of the named files, as
if they had been concatenated together into one big file. This is
useful for creating libraries of @code{awk} functions. Useful functions
can be written once, and then retrieved from a standard place, instead
@@ -8287,6 +8466,17 @@ type @kbd{Control-d} (the end-of-file character) to terminate it.
input, but then you will not be able to also use the standard input as a
source of data.)
+Because it is clumsy using the standard @code{awk} mechanisms to mix source
+file and command line @code{awk} programs, @code{gawk} provides the
+@samp{--source} option. This does not require you to pre-empt the standard
+input for your source code, and allows you to easily mix command line
+and library source code
+(@pxref{AWKPATH Variable, ,The @code{AWKPATH} Environment Variable}).
+
+If no @samp{-f} or @samp{--source} option is specified, then @code{gawk}
+will use the first non-option command line argument as the text of the
+program source code.
+
@node Other Arguments, AWKPATH Variable, Options, Command Line
@section Other Command Line Arguments
@@ -8375,9 +8565,12 @@ standard directory that is in the default path, and then specified on
the command line with a short file name. Otherwise, the full file name
would have to be typed for each file.
+By combining the @samp{--source} and @samp{-f} options, your command line
+@code{awk} programs can use facilities in @code{awk} library files.
+
Path searching is not done if @code{gawk} is in compatibility mode.
This is true for both @samp{-W compat} and @samp{-W posix}.
-@xref{Command Line, ,Invoking @code{awk}}.
+@xref{Options, ,Command Line Options}.
@strong{Note:} if you want files in the current directory to be found,
you must include the current directory in the path, either by writing
@@ -8403,9 +8596,8 @@ they will @emph{not} be in the next release).
@c update this section for each release!
-For version 2.14 of @code{gawk}, the following command line options
-are recognized, but produce a warning message
-(@pxref{Command Line, ,Invoking @code{awk}}).@refill
+For version 2.15 of @code{gawk}, the following command line options
+from version 2.11.1 are no longer recognized.
@table @samp
@ignore
@@ -8424,9 +8616,9 @@ Use @samp{-W copyright} instead.
@item -a
@itemx -e
-These options produce a warning message but have no effect on the
-execution of @code{gawk}. The @sc{posix} standard now specifies
-traditional @code{awk} regular expressions for the @code{awk} utility.
+These options produce an ``unrecognized option'' error message but have
+no effect on the execution of @code{gawk}. The @sc{posix} standard now
+specifies traditional @code{awk} regular expressions for the @code{awk} utility.
@end table
The public-domain version of @code{strftime} that is distributed with
@@ -8698,6 +8890,15 @@ The various @code{gawk} specific features available via the @samp{-W}
command line option (@pxref{Command Line, ,Invoking @code{awk}}).
@item
+The @code{ARGIND} variable, that tracks the movement of @code{FILENAME}
+through @code{ARGV}. (@pxref{Built-in Variables}).
+
+@item
+The @code{ERRNO} variable, that contains the system error message when
+@code{getline} returns @minus{}1, or when @code{close} fails.
+(@pxref{Built-in Variables}).
+
+@item
The @code{IGNORECASE} variable and its effects
(@pxref{Case-sensitivity, ,Case-sensitivity in Matching}).@refill
@@ -8768,28 +8969,32 @@ subdirectories.
@cindex anonymous uucp
@cindex ftp, anonymous
@cindex uucp, anonymous
-@code{gawk} is distributed as a compressed @code{tar} file. You can
+@code{gawk} is distributed as a @code{tar} file compressed with the
+GNU Zip program, @code{gzip}. You can
get it via anonymous @code{ftp} to the Internet host @code{prep.ai.mit.edu}.
Like all GNU software, it will be archived at other well known systems,
from which it will be possible to use some sort of anonymous @code{uucp} to
obtain the distribution as well.
-
-Once you have the distribution (for example, @file{gawk-2.14.0.tar.Z}), first
-use @code{uncompress} to expand the file, and then use @code{tar} to extract it.
-@code{uncompress} usually has a link named @code{zcat}, which causes it
-to decompress the file to the standard output. You can use the following
+You can also order @code{gawk} on tape or CD-ROM directly from the
+Free Software Foundation. (The address is on the copyright page.)
+Doing so directly contributes to the support of the foundation and to
+the production of more free software.
+
+Once you have the distribution (for example,
+@file{gawk-2.15.0.tar.z}), first use @code{gzip} to expand the
+file, and then use @code{tar} to extract it. You can use the following
pipeline to produce the @code{gawk} distribution:
@example
# Under System V, add 'o' to the tar flags
-zcat gawk-2.14.0.tar.Z | tar -xvpf -
+gzip -d -c gawk-2.15.0.tar.z | tar -xvpf -
@end example
@noindent
-This will create a directory named @file{gawk-2.14} in the current
+This will create a directory named @file{gawk-2.15} in the current
directory.
-The distribution file name is of the form @file{gawk-2.14.@var{n}.tar.Z}.
+The distribution file name is of the form @file{gawk-2.15.@var{n}.tar.Z}.
The @var{n} represents a @dfn{patchlevel}, meaning that minor bugs have
been fixed in the major release. The current patchlevel is 0, but when
retrieving distributions, you should get the version with the highest
@@ -8890,8 +9095,8 @@ Files needed for building @code{gawk} under VMS.
Many interesting @code{awk} programs, provided as a test suite for
@code{gawk}. You can use @samp{make test} from the top level @code{gawk}
directory to run your version of @code{gawk} against the test suite.
-There are many programs here that are useful in their own right.
-If @code{gawk} successfully passes @samp{make bigtest} then you can
+@c There are many programs here that are useful in their own right.
+If @code{gawk} successfully passes @samp{make test} then you can
be confident of a successful port.@refill
@end table
@@ -8915,7 +9120,7 @@ to configure @code{gawk} for your system yourself.
@cindex installation, unix
After you have extracted the @code{gawk} distribution, @code{cd}
-to @file{gawk-2.14}. Look in the @file{config} subdirectory for a
+to @file{gawk-2.15}. Look in the @file{config} subdirectory for a
file that matches your hardware/software combination. In general,
only the software is relevant; for example @code{sunos41} is used
for SunOS 4.1, on both Sun 3 and Sun 4 hardware.@refill
@@ -9092,7 +9297,7 @@ Edit @file{vmsbuild.com} or @file{descrip.mms} according to their comments.
No changes to @file{config.h} should be needed.
@end table
-@code{gawk} 2.14 has been tested under VAX/VMS 5.5-1 using VAX C V3.2,
+@code{gawk} 2.15 has been tested under VAX/VMS 5.5-1 using VAX C V3.2,
GNU C 1.40 and 2.3. It should work without modifications for VMS V4.6 and up.
@node VMS Installation Details, VMS Running, VMS Compilation, VMS Installation
@@ -9373,45 +9578,66 @@ values to be made available in the @code{ARGC} and @code{ARGV}
predefined @code{awk} variables:
@example
-awk @r{[@code{-F@var{fs}}] [@code{-W} @var{gawk-opts}] [@code{-v @var{var}=@var{val}}] [@code{--}]} '@var{program}' @var{file} @dots{}
-awk @r{[@code{-F@var{fs}}] [@code{-W} @var{gawk-opts}] [@code{-v @var{var}=@var{val}}]} @code{-f} @var{source-file} @r{[@code{-f @var{source-file} @dots{}}]} @var{file} @dots{}
+awk @r{[@var{POSIX or GNU style options}]} -f source-file @r{[@code{--}]} @var{file} @dots{}
+awk @r{[@var{POSIX or GNU style options}]} @r{[@code{--}]} '@var{program}' @var{file} @dots{}
@end example
The options that @code{gawk} accepts are:
@table @code
-@item -F@var{fs}
+@item -F @var{fs}
+@itemx --field-separator=@var{fs}
Use @var{fs} for the input field separator (the value of the @code{FS}
predefined variable).
@item -f @var{program-file}
+@itemx --file=@var{program-file}
Read the @code{awk} program source from the file @var{program-file}, instead
of from the first command line argument.
@item -v @var{var}=@var{val}
+@itemx --assign=@var{var}=@var{val}
Assign the variable @var{var} the value @var{val} before program execution
begins.
@item -W compat
+@itemx --compat
Specifies compatibility mode, in which @code{gawk} extensions are turned
off.
-@item -W posix
-Specifies @sc{posix} compatibility mode, in which @code{gawk} extensions
-are turned off and additional restrictions apply.
-
-@item -W version
-Print version information for this particular copy of @code{gawk} on the error
-output. This option may disappear in a future version of @code{gawk}.
-
@item -W copyleft
@itemx -W copyright
+@itemx --copyleft
+@itemx --copyright
Print the short version of the General Public License on the error
output. This option may disappear in a future version of @code{gawk}.
+@item -W help
+@itemx -W usage
+@itemx --help
+@itemx --usage
+Print a relatively short summary of the available options on the error output.
+
@item -W lint
+@itemx --lint
Give warnings about dubious or non-portable @code{awk} constructs.
+@item -W posix
+@itemx --posix
+Specifies @sc{posix} compatibility mode, in which @code{gawk} extensions
+are turned off and additional restrictions apply.
+
+@item -W source=@var{program-text}
+@itemx --source=@var{program-text}
+Use @var{program-text} as @code{awk} program source code. This option allows
+mixing command line source code with source code from files, and is
+particularly useful for mixing command line programs with library functions.
+
+@item -W version
+@itemx --version
+Print version information for this particular copy of @code{gawk} on the error
+output. This option may disappear in a future version of @code{gawk}.
+
@item --
Signal the end of options. This is useful to allow further arguments to the
@code{awk} program itself to start with a @samp{-}. This is mainly for
@@ -9529,6 +9755,10 @@ way @code{awk} defines and uses fields.
The number of command line arguments (not including options or the
@code{awk} program itself).
+@item ARGIND
+The index in @code{ARGV} of the current file being processed.
+It is always true that @samp{FILENAME == ARGV[ARGIND]}.
+
@item ARGV
The array of command line arguments. The array is indexed from 0 to
@code{ARGC} @minus{} 1. Dynamically changing the contents of @code{ARGV}
@@ -9553,6 +9783,10 @@ which @code{gawk} spawns via redirection or the @code{system} function.
Some operating systems do not have environment variables.
The array @code{ENVIRON} is empty when running on these systems.
+@item ERRNO
+The system error message when an error occurs using @code{getline}
+or @code{close}.
+
@item FILENAME
The name of the current input file. If no files are specified on the command
line, the value of @code{FILENAME} is @samp{-}.
@@ -10075,8 +10309,50 @@ The standard error output.
The file denoted by the open file descriptor @var{n}.
@end table
+In addition the following files provide process related information
+about the running @code{gawk} program.
+
+@table @file
+@item /dev/pid
+Reading this file returns the process ID of the current process,
+in decimal, terminated with a newline.
+
+@item /dev/ppid
+Reading this file returns the parent process ID of the current process,
+in decimal, terminated with a newline.
+
+@item /dev/pgrpid
+Reading this file returns the process group ID of the current process,
+in decimal, terminated with a newline.
+
+@item /dev/user
+Reading this file returns a single record terminated with a newline.
+The fields are separated with blanks. The fields represent the
+following information:
+
+@table @code
+@item $1
+The value of the @code{getuid} system call.
+
+@item $2
+The value of the @code{geteuid} system call.
+
+@item $3
+The value of the @code{getgid} system call.
+
+@item $4
+The value of the @code{getegid} system call.
+@end table
+
+If there are any additional fields, they are the group IDs returned by
+@code{getgroups} system call.
+(Multiple groups may not be supported on all systems.)@refill
+@end table
+
@noindent
These file names may also be used on the command line to name data files.
+These file names are only recognized internally if you do not
+actually have files by these names on your system.
@xref{Special Files, ,Standard I/O Streams}, for a longer description that
provides the motivation for this feature.
@@ -10298,7 +10574,7 @@ a = length($0)
@noindent
This feature is marked as ``deprecated'' in the @sc{posix} standard, and
-@code{gawk} will issuge a warning about its use if @samp{-W lint} is
+@code{gawk} will issue a warning about its use if @samp{-W lint} is
specified on the command line.
The other feature is the use of the @code{continue} statement outside the
@@ -10530,7 +10806,7 @@ If @code{gawk} is compiled for debugging with @samp{-DDEBUG}, then there
is one more option available on the command line:
@table @samp
-@item -W debug
+@item -W parsedebug
Print out the parse stack information as the program is being parsed.
@end table
@@ -10565,21 +10841,6 @@ Thus, @code{split(a, "abcd", "")} would yield @code{a[1] == "a"},
@item More @code{lint} warnings
There are more things that could be checked for portability.
-@item @code{ARGIND} variable to indicate the position in @code{ARGV}
-It would occasionally be useful to know which element in @code{ARGV}
-is the current file being processed. It is not sufficient to simply
-loop through @code{ARGV} comparing each element to @code{FILENAME},
-particularly if a program makes more than one pass through a single
-data file. Initially @code{ARGIND} would be a read-only variable.
-That is, @code{gawk} would set it for you as each file is processed, but
-would ignore any changes that your program made to it.@refill
-@ignore
-Would it make sense down the road to nuke `next file' in favor of
-semantics that would make this work?
-
- function nextfile() { ARGIND++ ; next }
-@end ignore
-
@item @code{RECLEN} variable for fixed length records
Along with @code{FIELDWIDTHS}, this would speed up the processing of
fixed-length records.
@@ -10685,8 +10946,9 @@ rule's action. Actions are always enclosed in curly braces.
@item Amazing @code{awk} Assembler
Henry Spencer at the University of Toronto wrote a retargetable assembler
completely as @code{awk} scripts. It is thousands of lines long, including
-machine descriptions for several 8-bit microcomputers. It is distributed
-with @code{gawk} (as part of the test suite) and is a good example of a
+machine descriptions for several 8-bit microcomputers.
+@c It is distributed with @code{gawk} (as part of the test suite) and
+It is a good example of a
program that would have been better written in another language.@refill
@item @sc{ansi}
@@ -10717,9 +10979,9 @@ numerical, time stamp related, and string computations. Examples are
substring of a string). @xref{Built-in, ,Built-in Functions}.@refill
@item Built-in Variable
-@code{ARGC}, @code{ARGV}, @code{CONVFMT}, @code{FIELDWIDTHS},
-@code{ENVIRON}, @code{FILENAME}, @code{FNR}, @code{FS}, @code{IGNORECASE},
-@code{NF}, @code{NR}, @code{OFMT}, @code{OFS}, @code{ORS},
+@code{ARGC}, @code{ARGIND}, @code{ARGV}, @code{CONVFMT}, @code{ENVIRON},
+@code{ERRNO}, @code{FIELDWIDTHS}, @code{FILENAME}, @code{FNR}, @code{FS},
+@code{IGNORECASE}, @code{NF}, @code{NR}, @code{OFMT}, @code{OFS}, @code{ORS},
@code{RLENGTH}, @code{RSTART}, @code{RS}, and @code{SUBSEP},
are the variables that have special
meaning to @code{awk}. Changing some of them affects @code{awk}'s running
diff --git a/getopt1.c b/getopt1.c
new file mode 100644
index 00000000..e2127cd5
--- /dev/null
+++ b/getopt1.c
@@ -0,0 +1,160 @@
+/* Getopt for GNU.
+ Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc.
+
+This file is part of the libiberty library.
+Libiberty is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+Libiberty is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with libiberty; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#ifdef LIBC
+/* For when compiled as part of the GNU C library. */
+#include <ansidecl.h>
+#endif
+
+#include "getopt.h"
+
+#ifndef __STDC__
+#define const
+#endif
+
+#if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__) || defined (LIBC)
+#include <stdlib.h>
+#else /* STDC_HEADERS or __GNU_LIBRARY__ */
+char *getenv ();
+#endif /* STDC_HEADERS or __GNU_LIBRARY__ */
+
+#if !defined (NULL)
+#define NULL 0
+#endif
+
+int
+getopt_long (argc, argv, options, long_options, opt_index)
+ int argc;
+ char *const *argv;
+ const char *options;
+ const struct option *long_options;
+ int *opt_index;
+{
+ return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
+}
+
+/* Like getopt_long, but '-' as well as '--' can indicate a long option.
+ If an option that starts with '-' (not '--') doesn't match a long option,
+ but does match a short option, it is parsed as a short option
+ instead. */
+
+int
+getopt_long_only (argc, argv, options, long_options, opt_index)
+ int argc;
+ char *const *argv;
+ const char *options;
+ const struct option *long_options;
+ int *opt_index;
+{
+ return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
+}
+
+#ifdef TEST
+
+#include <stdio.h>
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ int c;
+ int digit_optind = 0;
+
+ while (1)
+ {
+ int this_option_optind = optind ? optind : 1;
+ int option_index = 0;
+ static struct option long_options[] =
+ {
+ {"add", 1, 0, 0},
+ {"append", 0, 0, 0},
+ {"delete", 1, 0, 0},
+ {"verbose", 0, 0, 0},
+ {"create", 0, 0, 0},
+ {"file", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long (argc, argv, "abc:d:0123456789",
+ long_options, &option_index);
+ if (c == EOF)
+ break;
+
+ switch (c)
+ {
+ case 0:
+ printf ("option %s", long_options[option_index].name);
+ if (optarg)
+ printf (" with arg %s", optarg);
+ printf ("\n");
+ break;
+
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf ("digits occur in two different argv-elements.\n");
+ digit_optind = this_option_optind;
+ printf ("option %c\n", c);
+ break;
+
+ case 'a':
+ printf ("option a\n");
+ break;
+
+ case 'b':
+ printf ("option b\n");
+ break;
+
+ case 'c':
+ printf ("option c with value `%s'\n", optarg);
+ break;
+
+ case 'd':
+ printf ("option d with value `%s'\n", optarg);
+ break;
+
+ case '?':
+ break;
+
+ default:
+ printf ("?? getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+ if (optind < argc)
+ {
+ printf ("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf ("%s ", argv[optind++]);
+ printf ("\n");
+ }
+
+ exit (0);
+}
+
+#endif /* TEST */
diff --git a/io.c b/io.c
index 478bd367..bf553c59 100644
--- a/io.c
+++ b/io.c
@@ -1,5 +1,5 @@
/*
- * io.c - routines for dealing with input and output and records
+ * io.c --- routines for dealing with input and output and records
*/
/*
@@ -29,6 +29,10 @@
#include <fcntl.h>
#endif
+#if !defined(S_ISDIR) && defined(S_IFDIR)
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#endif
+
#ifndef atarist
#define INVALID_HANDLE (-1)
#else
@@ -49,27 +53,24 @@ static int close_redir P((struct redirect *rp));
static int wait_any P((int interesting));
#endif
static IOBUF *gawk_popen P((char *cmd, struct redirect *rp));
+static IOBUF *iop_open P((char *file, char *how));
static int gawk_pclose P((struct redirect *rp));
static int do_pathopen P((char *file));
-#ifndef MSDOS
-#ifndef _CRAY
-#ifndef VMS
-extern FILE *fdopen P((int, const char *));
-#else /* avoid conflicting prototype */
extern FILE *fdopen();
-#endif /* VMS */
-#endif /* _CRAY */
-#endif /* MSDOS */
static struct redirect *red_head = NULL;
extern int output_is_tty;
extern NODE *ARGC_node;
extern NODE *ARGV_node;
+extern NODE *ARGIND_node;
+extern NODE *ERRNO_node;
extern NODE **fields_arr;
-static jmp_buf filebuf; /* for nextfile() */
+static jmp_buf filebuf; /* for do_nextfile() */
+
+/* do_nextfile --- implement gawk "next file" extension */
void
do_nextfile()
@@ -95,9 +96,10 @@ int skipping;
return NULL;
}
if (curfile != NULL) {
- if (curfile->cnt == EOF)
+ if (curfile->cnt == EOF) {
(void) iop_close(curfile);
- else
+ curfile = NULL;
+ } else
return curfile;
}
for (; i < (int) (ARGC_node->lnode->numbr); i++) {
@@ -105,10 +107,14 @@ int skipping;
if (arg->stptr[0] == '\0')
continue;
arg->stptr[arg->stlen] = '\0';
+ if (! do_unix) {
+ ARGIND_node->var_value->numbr = i;
+ ARGIND_node->var_value->flags = NUM|NUMBER;
+ }
if (!arg_assign(arg->stptr)) {
files++;
- fd = devopen(arg->stptr, "r");
- if (fd == INVALID_HANDLE)
+ curfile = iop_open(arg->stptr, "r");
+ if (curfile == NULL)
fatal("cannot open file `%s' for reading (%s)",
arg->stptr, strerror(errno));
/* NOTREACHED */
@@ -126,11 +132,9 @@ int skipping;
/* no args. -- use stdin */
/* FILENAME is init'ed to "-" */
/* FNR is init'ed to 0 */
- fd = 0;
+ curfile = iop_alloc(fileno(stdin));
}
- if (fd == INVALID_HANDLE)
- return curfile = NULL;
- return curfile = iop_alloc(fd);
+ return curfile;
}
void
@@ -156,7 +160,7 @@ IOBUF *iop;
register int cnt;
int retval = 0;
- cnt = get_a_record(&begin, iop, *RS);
+ cnt = get_a_record(&begin, iop, *RS, NULL);
if (cnt == EOF) {
cnt = 0;
retval = 1;
@@ -185,6 +189,15 @@ IOBUF *iop;
ret = 0;
else
#endif
+ /* save these for re-use; don't free the storage */
+ if ((iop->flag & IOP_IS_INTERNAL) != 0) {
+ iop->off = iop->buf;
+ iop->end = iop->buf + strlen(iop->buf);
+ iop->cnt = 0;
+ iop->secsiz = 0;
+ return 0;
+ }
+
/* Don't close standard files or else crufty code elsewhere will lose */
if (iop->fd == fileno(stdin) ||
iop->fd == fileno(stdout) ||
@@ -194,9 +207,27 @@ IOBUF *iop;
ret = close(iop->fd);
if (ret == -1)
warning("close of fd %d failed (%s)", iop->fd, strerror(errno));
- if (iop->buf)
- free(iop->buf);
- free((char *)iop);
+ if ((iop->flag & IOP_NO_FREE) == 0) {
+ /*
+ * be careful -- $0 may still reference the buffer even though
+ * an explicit close is being done; in the future, maybe we
+ * can do this a bit better
+ */
+ if (iop->buf) {
+ if ((fields_arr[0]->stptr >= iop->buf)
+ && (fields_arr[0]->stptr < iop->end)) {
+ NODE *t;
+
+ t = make_string(fields_arr[0]->stptr,
+ fields_arr[0]->stlen);
+ unref(fields_arr[0]);
+ fields_arr [0] = t;
+ reset_record ();
+ }
+ free(iop->buf);
+ }
+ free((char *)iop);
+ }
return ret == -1 ? 1 : 0;
}
@@ -330,7 +361,7 @@ int *errflg;
break;
case Node_redirect_input:
direction = "from";
- rp->iop = iop_alloc(devopen(str, "r"));
+ rp->iop = iop_open(str, "r");
break;
default:
cant_happen();
@@ -352,11 +383,7 @@ int *errflg;
}
if (rp->fp == NULL && rp->iop == NULL) {
/* too many files open -- close one and try again */
-#ifdef atarist
if (errno == EMFILE)
-#else
- if (errno == ENFILE || errno == EMFILE)
-#endif
close_one();
else {
/*
@@ -368,7 +395,7 @@ int *errflg;
* complain. The shell will complain on
* a bad command to a pipe.
*/
- *errflg = 1;
+ *errflg = errno;
if (tree->type == Node_redirect_output
|| tree->type == Node_redirect_append)
fatal("can't redirect %s `%s' (%s)",
@@ -453,11 +480,20 @@ register struct redirect *rp;
}
}
/* SVR4 awk checks and warns about status of close */
- if (status)
+ if (status) {
+ char *s = strerror(errno);
+
warning("failure status (%d) on %s close of \"%s\" (%s).",
status,
(rp->flag & RED_PIPE) ? "pipe" :
- "file", rp->value, strerror(errno));
+ "file", rp->value, s);
+
+ if (! do_unix) {
+ /* set ERRNO too so that program can get at it */
+ unref(ERRNO_node->var_value);
+ ERRNO_node->var_value = make_string(s, strlen(s));
+ }
+ }
if (rp->next)
rp->next->prev = rp->prev;
if (rp->prev)
@@ -515,36 +551,60 @@ close_io ()
return status;
}
-/* devopen --- handle /dev/std{in,out,err}, /dev/fd/N, regular files */
-int
-devopen (name, mode)
-char *name, *mode;
+/* str2mode --- convert a string mode to an integer mode */
+
+static int
+str2mode(mode)
+char *mode;
{
- int openfd = INVALID_HANDLE;
- char *cp, *ptr;
- int flag = 0;
- struct stat buf;
+ int ret;
switch(mode[0]) {
case 'r':
- flag = O_RDONLY;
+ ret = O_RDONLY;
break;
case 'w':
- flag = O_WRONLY|O_CREAT|O_TRUNC;
+ ret = O_WRONLY|O_CREAT|O_TRUNC;
break;
case 'a':
- flag = O_WRONLY|O_APPEND|O_CREAT;
+ ret = O_WRONLY|O_APPEND|O_CREAT;
break;
default:
cant_happen();
}
+ return ret;
+}
+
+/* devopen --- handle /dev/std{in,out,err}, /dev/fd/N, regular files */
+
+/*
+ * This separate version is still needed for output, since file and pipe
+ * output is done with stdio. iop_open() handles input with IOBUFs of
+ * more "special" files. Those files are not handled here since it makes
+ * no sense to use them for output.
+ */
+
+int
+devopen(name, mode)
+char *name, *mode;
+{
+ int openfd = INVALID_HANDLE;
+ char *cp, *ptr;
+ int flag = 0;
+ struct stat buf;
+ extern double strtod();
+
+ flag = str2mode(mode);
+
+ if (do_unix)
+ goto strictopen;
#ifdef VMS
if ((openfd = vms_devopen(name, flag)) >= 0)
return openfd;
-#endif /*VMS*/
+#endif /* VMS */
if (STREQ(name, "-"))
openfd = fileno(stdin);
@@ -562,23 +622,209 @@ char *name, *mode;
openfd = (int)strtod(cp, &ptr);
if (openfd <= INVALID_HANDLE || ptr == cp)
openfd = INVALID_HANDLE;
-#ifdef VMS
- } else if (STREQ(cp, "null")) {
- name = "NL:"; /* "/dev/null" => "NL:" */
- } else if (STREQ(cp, "tty")) {
- name = "TT:"; /* "/dev/tty" => "TT:" */
-#endif /*VMS*/
}
}
+strictopen:
if (openfd == INVALID_HANDLE)
openfd = open(name, flag, 0666);
if (openfd != INVALID_HANDLE && fstat(openfd, &buf) > 0)
- if ((buf.st_mode & S_IFMT) == S_IFDIR)
+ if (S_ISDIR(buf.st_mode))
fatal("file `%s' is a directory", name);
return openfd;
}
+
+/* spec_setup --- setup an IOBUF for a special internal file */
+
+void
+spec_setup(iop, len, allocate)
+IOBUF *iop;
+int len;
+int allocate;
+{
+ char *cp;
+
+ if (allocate) {
+ emalloc(cp, char *, len+2, "spec_setup");
+ iop->buf = cp;
+ } else {
+ len = strlen(iop->buf);
+ iop->buf[len++] = '\n'; /* get_a_record clobbered it */
+ iop->buf[len] = '\0'; /* just in case */
+ }
+ iop->off = iop->buf;
+ iop->cnt = 0;
+ iop->secsiz = 0;
+ iop->size = len;
+ iop->end = iop->buf + len;
+ iop->fd = -1;
+ iop->flag = IOP_IS_INTERNAL;
+}
+
+/* specfdopen --- open a fd special file */
+
+int
+specfdopen(iop, name, mode)
+IOBUF *iop;
+char *name, *mode;
+{
+ int fd;
+ IOBUF *tp;
+
+ fd = devopen(name, mode);
+ if (fd == INVALID_HANDLE)
+ return INVALID_HANDLE;
+ tp = iop_alloc(fd);
+ if (tp == NULL)
+ return INVALID_HANDLE;
+ *iop = *tp;
+ iop->flag |= IOP_NO_FREE;
+ free(tp);
+ return 0;
+}
+
+/* pidopen --- "open" /dev/pid, /dev/ppid, and /dev/pgrpid */
+
+int
+pidopen(iop, name, mode)
+IOBUF *iop;
+char *name, *mode;
+{
+ char tbuf[BUFSIZ];
+ int i;
+
+ if (name[6] == 'g')
+#if defined(__svr4__) || defined(i860)
+ sprintf(tbuf, "%d\n", getpgrp());
+#else
+ sprintf(tbuf, "%d\n", getpgrp(getpid()));
+#endif
+ else if (name[6] == 'i')
+ sprintf(tbuf, "%d\n", getpid());
+ else
+ sprintf(tbuf, "%d\n", getppid());
+ i = strlen(tbuf);
+ spec_setup(iop, i, 1);
+ strcpy(iop->buf, tbuf);
+ return 0;
+}
+
+/* useropen --- "open" /dev/user */
+
+/*
+ * /dev/user creates a record as follows:
+ * $1 = getuid()
+ * $2 = geteuid()
+ * $3 = getgid()
+ * $4 = getegid()
+ * If multiple groups are supported, the $5 through $NF are the
+ * supplementary group set.
+ */
+
+int
+useropen(iop, name, mode)
+IOBUF *iop;
+char *name, *mode;
+{
+ char tbuf[BUFSIZ], *cp;
+ int i;
+#if defined(NGROUPS_MAX) && NGROUPS_MAX > 0
+ int groupset[NGROUPS_MAX];
+ int ngroups;
+#endif
+
+ sprintf(tbuf, "%d %d %d %d", getuid(), geteuid(), getgid(), getegid());
+
+ cp = tbuf + strlen(tbuf);
+#if defined(NGROUPS_MAX) && NGROUPS_MAX > 0
+ ngroups = getgroups(NGROUPS_MAX, groupset);
+ if (ngroups == -1)
+ fatal("could not find groups: %s", strerror(errno));
+
+ for (i = 0; i < ngroups; i++) {
+ *cp++ = ' ';
+ sprintf(cp, "%d", groupset[i]);
+ cp += strlen(cp);
+ }
+#endif
+ *cp++ = '\n';
+ *cp++ = '\0';
+
+
+ i = strlen(tbuf);
+ spec_setup(iop, i, 1);
+ strcpy(iop->buf, tbuf);
+ return 0;
+}
+
+/* iop_open --- handle special and regular files for input */
+
+static IOBUF *
+iop_open(name, mode)
+char *name, *mode;
+{
+ int openfd = INVALID_HANDLE;
+ char *cp, *ptr;
+ int flag = 0;
+ int i;
+ struct stat buf;
+ IOBUF *iop;
+ static struct internal {
+ char *name;
+ int compare;
+ int (*fp)();
+ IOBUF iob;
+ } table[] = {
+ { "/dev/fd/", 8, specfdopen },
+ { "/dev/stdin", 10, specfdopen },
+ { "/dev/stdout", 11, specfdopen },
+ { "/dev/stderr", 11, specfdopen },
+ { "/dev/pid", 8, pidopen },
+ { "/dev/ppid", 9, pidopen },
+ { "/dev/pgrpid", 11, pidopen },
+ { "/dev/user", 9, useropen },
+ };
+ int devcount = sizeof(table) / sizeof(table[0]);
+
+ flag = str2mode(mode);
+
+ if (do_unix)
+ goto strictopen;
+
+ if (STREQ(name, "-"))
+ openfd = fileno(stdin);
+ else if (STREQN(name, "/dev/", 5) && stat(name, &buf) == -1) {
+ int i;
+
+ for (i = 0; i < devcount; i++) {
+ if (STREQN(name, table[i].name, table[i].compare)) {
+ IOBUF *iop = & table[i].iob;
+
+ if (iop->buf != NULL) {
+ spec_setup(iop, 0, 0);
+ return iop;
+ } else if ((*table[i].fp)(iop, name, mode) == 0)
+ return iop;
+ else {
+ warning("could not open %s, mode `%s'",
+ name, mode);
+ return NULL;
+ }
+ }
+ }
+ }
+
+strictopen:
+ if (openfd == INVALID_HANDLE)
+ openfd = open(name, flag, 0666);
+ if (openfd != INVALID_HANDLE && fstat(openfd, &buf) > 0)
+ if ((buf.st_mode & S_IFMT) == S_IFDIR)
+ fatal("file `%s' is a directory", name);
+ iop = iop_alloc(openfd);
+ return iop;
+}
+
#ifndef PIPES_SIMULATED
/* real pipes */
static int
@@ -595,7 +841,11 @@ int interesting; /* pid of interest, if any */
istat = signal(SIGINT, SIG_IGN);
qstat = signal(SIGQUIT, SIG_IGN);
for (;;) {
+#ifdef NeXT
+ pid = wait((union wait *)&status);
+#else
pid = wait(&status);
+#endif /* NeXT */
if (interesting && pid == interesting) {
break;
} else if (pid != -1) {
@@ -767,6 +1017,7 @@ NODE *tree;
IOBUF *iop;
int cnt = EOF;
char *s = NULL;
+ int errcode;
while (cnt == EOF) {
if (tree->rnode == NULL) { /* no redirection */
@@ -777,26 +1028,37 @@ NODE *tree;
int redir_error = 0;
rp = redirect(tree->rnode, &redir_error);
- if (rp == NULL && redir_error) /* failed redirect */
+ if (rp == NULL && redir_error) { /* failed redirect */
+ if (! do_unix) {
+ char *s = strerror(redir_error);
+
+ unref(ERRNO_node->var_value);
+ ERRNO_node->var_value =
+ make_string(s, strlen(s));
+ }
return tmp_number((AWKNUM) -1.0);
+ }
iop = rp->iop;
if (iop == NULL) /* end of input */
return tmp_number((AWKNUM) 0.0);
}
- cnt = get_a_record(&s, iop, *RS);
+ errcode = 0;
+ cnt = get_a_record(&s, iop, *RS, & errcode);
+ if (! do_unix && errcode != 0) {
+ char *s = strerror(errcode);
+
+ unref(ERRNO_node->var_value);
+ ERRNO_node->var_value = make_string(s, strlen(s));
+ return tmp_number((AWKNUM) -1.0);
+ }
if (cnt == EOF) {
if (rp) {
-#ifdef PIPES_SIMULATED
/*
* Don't do iop_close() here if we are
- * reading from a simulated pipe; otherwise
- * gawk_close will not remove temporary
- * files from where we were reading.
+ * reading from a pipe; otherwise
+ * gawk_pclose will not be called.
*/
- if ((rp->flag & (RED_PIPE|RED_READ)) !=
- (RED_PIPE|RED_READ))
-#endif /* PIPES_SIMULATED */
- {
+ if (!(rp->flag & RED_PIPE)) {
(void) iop_close(iop);
rp->iop = NULL;
}
@@ -818,6 +1080,7 @@ NODE *tree;
lhs = get_lhs(tree->lnode, &after_assign);
unref(*lhs);
*lhs = make_string(s, strlen(s));
+ (*lhs)->flags |= MAYBE_NUM;
/* we may have to regenerate $0 here! */
if (after_assign)
(*after_assign)();
@@ -833,7 +1096,7 @@ char *file;
int fd = do_pathopen(file);
#ifdef DEFAULT_FILETYPE
- if (!strict && fd <= INVALID_HANDLE) {
+ if (! do_unix && fd <= INVALID_HANDLE) {
char *file_awk;
int save = errno;
#ifdef VMS
@@ -843,7 +1106,7 @@ char *file;
/* append ".awk" and try again */
emalloc(file_awk, char *, strlen(file) +
sizeof(DEFAULT_FILETYPE) + 1, "pathopen");
- strcat(strcpy(file_awk, file), DEFAULT_FILETYPE);
+ sprintf(file_awk, "%s%s", file, DEFAULT_FILETYPE);
fd = do_pathopen(file_awk);
free(file_awk);
if (fd <= INVALID_HANDLE) {
@@ -871,7 +1134,7 @@ char *file;
if (STREQ(file, "-"))
return (0);
- if (strict)
+ if (do_unix)
return (devopen(file, "r"));
if (first) {
diff --git a/iop.c b/iop.c
index 172e7e88..0d7af121 100644
--- a/iop.c
+++ b/iop.c
@@ -137,10 +137,11 @@ int fd;
* loop can run as a single test.
*/
int
-get_a_record(out, iop, grRS)
+get_a_record(out, iop, grRS, errcode)
char **out;
IOBUF *iop;
register int grRS;
+int *errcode;
{
register char *bp = iop->off;
char *bufend;
@@ -175,11 +176,14 @@ register int grRS;
* we expand this space. This is done so that we can return
* the record as a contiguous area of memory.
*/
- if (bp >= bufend) {
+ if ((iop->flag & IOP_IS_INTERNAL) == 0 && bp >= bufend) {
char *oldbuf = NULL;
char *oldsplit = iop->buf + iop->secsiz;
long len; /* record length so far */
+ if ((iop->flag & IOP_IS_INTERNAL) != 0)
+ cant_happen();
+
len = bp - start;
if (len > iop->secsiz) {
/* expand secondary buffer */
@@ -217,10 +221,20 @@ register int grRS;
* we may be doing smallish reads into more advanced positions.
*/
if (bp >= iop->end) {
+ if ((iop->flag & IOP_IS_INTERNAL) != 0) {
+ iop->cnt = EOF;
+ break;
+ }
iop->cnt = read(iop->fd, iop->end, bufend - iop->end);
- if (iop->cnt == -1)
- fatal("error reading input: %s", strerror(errno));
- else if (iop->cnt == 0) {
+ if (iop->cnt == -1) {
+ if (! do_unix && errcode != NULL) {
+ *errcode = errno;
+ iop->cnt = EOF;
+ break;
+ } else
+ fatal("error reading input: %s",
+ strerror(errno));
+ } else if (iop->cnt == 0) {
iop->cnt = EOF;
break;
}
@@ -256,15 +270,19 @@ register int grRS;
break;
} else
bp--;
+
+ if ((iop->flag & IOP_IS_INTERNAL) != 0)
+ iop->cnt = bp - start;
}
- if (iop->cnt == EOF && start == bp)
+ if (iop->cnt == EOF
+ && (((iop->flag & IOP_IS_INTERNAL) != 0) || start == bp))
return EOF;
iop->off = bp;
- if (*--bp == rs)
- *bp = '\0';
- else
+ bp--;
+ if (*bp != rs)
bp++;
+ *bp = '\0';
if (grRS == 0) {
if (*--bp == rs)
*bp = '\0';
@@ -292,7 +310,7 @@ char *argv[];
if (argc > 2)
rs[0] = *argv[2];
iop = iop_alloc(0);
- while ((cnt = get_a_record(&out, iop, rs[0])) > 0) {
+ while ((cnt = get_a_record(&out, iop, rs[0], NULL)) > 0) {
fwrite(out, 1, cnt, stdout);
fwrite(rs, 1, 1, stdout);
}
diff --git a/main.c b/main.c
index 04cb1e9d..77d0bf74 100644
--- a/main.c
+++ b/main.c
@@ -23,10 +23,11 @@
* the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include "getopt.h"
#include "awk.h"
#include "patchlevel.h"
-static void usage P((void));
+static void usage P((int exitval));
static void copyleft P((void));
static void cmdline_fs P((char *str));
static void init_args P((int argc0, int argc, char *argv0, char **argv));
@@ -35,27 +36,29 @@ static void pre_assign P((char *v));
SIGTYPE catchsig P((int sig, int code));
static void gawk_option P((char *optstr));
static void nostalgia P((void));
-static char *gawk_name P((char *filespec));
+static void version P((void));
+char *gawk_name P((char *filespec));
#ifdef MSDOS
-extern int getopt P((int argc, char **argv, char *optstring));
extern int isatty P((int));
#endif
+extern void resetup P((void));
+
/* These nodes store all the special variables AWK uses */
NODE *FS_node, *NF_node, *RS_node, *NR_node;
NODE *FILENAME_node, *OFS_node, *ORS_node, *OFMT_node;
NODE *CONVFMT_node;
+NODE *ERRNO_node;
NODE *FNR_node, *RLENGTH_node, *RSTART_node, *SUBSEP_node;
NODE *ENVIRON_node, *IGNORECASE_node;
-NODE *ARGC_node, *ARGV_node;
+NODE *ARGC_node, *ARGV_node, *ARGIND_node;
NODE *FIELDWIDTHS_node;
int NF;
int NR;
int FNR;
int IGNORECASE;
-char *FS;
char *RS;
char *OFS;
char *ORS;
@@ -87,13 +90,14 @@ int exit_val = 0; /* optional exit value */
extern int yydebug;
#endif
-char **srcfiles = NULL; /* source file name(s) */
+struct src *srcfiles = NULL; /* source file name(s) */
int numfiles = -1; /* how many source files */
-char *cmdline_src = NULL; /* if prog is on command line */
-int strict = 0; /* turn off gnu extensions */
-int do_posix = 0; /* turn off gnu extensions and \x */
+int do_unix = 0; /* turn off gnu extensions */
+int do_posix = 0; /* turn off gnu and unix extensions */
int do_lint = 0; /* provide warnings about questionable stuff */
+int do_nostalgia = 0; /* provide a blast from the past */
+
int in_begin_rule = 0; /* we're in a BEGIN rule */
int in_end_rule = 0; /* we're in a END rule */
@@ -103,21 +107,25 @@ extern char *version_string; /* current version, for printing */
NODE *expression_value;
-/*
- * for strict to work, legal options must be first
- *
- * Unfortunately, -a and -e are orthogonal to -c.
- *
- * Note that after 2.13, c,a,e,C,D, and V go away.
- */
-/* the + on the front is for GNU getopt */
+static struct option optab[] = {
+ { "compat", no_argument, & do_unix, 1 },
+ { "lint", no_argument, & do_lint, 1 },
+ { "posix", no_argument, & do_posix, 1 },
+ { "nostalgia", no_argument, & do_nostalgia, 1 },
+ { "copyleft", no_argument, NULL, 'C' },
+ { "copyright", no_argument, NULL, 'C' },
+ { "field-separator", required_argument, NULL, 'F' },
+ { "file", required_argument, NULL, 'f' },
+ { "assign", required_argument, NULL, 'v' },
+ { "version", no_argument, NULL, 'V' },
+ { "usage", no_argument, NULL, 'u' },
+ { "help", no_argument, NULL, 'u' },
+ { "source", required_argument, NULL, 's' },
#ifdef DEBUG
-char awk_opts[] = "+F:f:v:W:caeCVD";
-#else
-char awk_opts[] = "+F:f:v:W:caeCV";
+ { "parsedebug", no_argument, NULL, 'D' },
#endif
-
-extern void resetup P((void));
+ { 0, 0, 0, 0 }
+};
int
main(argc, argv)
@@ -127,13 +135,13 @@ char **argv;
int c;
char *scan;
extern int optind;
+ extern int opterr;
extern char *optarg;
int i;
- int do_nostalgia;
(void) signal(SIGFPE, (SIGTYPE (*) P((int))) catchsig);
(void) signal(SIGSEGV, (SIGTYPE (*) P((int))) catchsig);
-#ifndef MSDOS
+#ifdef SIGBUS
(void) signal(SIGBUS, (SIGTYPE (*) P((int))) catchsig);
#endif
@@ -142,13 +150,14 @@ char **argv;
#ifdef VMS
vms_arg_fixup(&argc, &argv); /* emulate redirection, expand wildcards */
#endif
- if (argc < 2)
- usage();
/* remove sccs gunk */
if (strncmp(version_string, "@(#)", 4) == 0)
version_string += 4;
+ if (argc < 2)
+ usage(1);
+
/* initialize the null string */
Nnull_string = make_string("", 0);
Nnull_string->numbr = 0.0;
@@ -164,47 +173,20 @@ char **argv;
init_vars();
/* worst case */
- emalloc(srcfiles, char **, argc * sizeof(char *), "main");
- srcfiles[0] = NULL;
+ emalloc(srcfiles, struct src *, argc * sizeof(struct src), "main");
+ memset(srcfiles, '\0', argc * sizeof(struct src));
- /* undocumented feature, inspired by nostalgia, and a T-shirt */
- do_nostalgia = 0;
- for (i = 1; i < argc && argv[i][0] == '-'; i++) {
- if (argv[i][1] == '-') /* -- */
- break;
- else if (argv[i][1] == 'c') { /* compat not in next release */
- do_nostalgia = 0;
- break;
- } else if (STREQ(&argv[i][1], "nostalgia"))
- do_nostalgia = 1;
- /* keep looping, in case -c after -nostalgia */
- }
- if (do_nostalgia) {
- fprintf(stderr, "%s, %s\n",
- "warning: option -nostalgia will go away in a future release",
- "use -W nostalgia");
- nostalgia();
- /* NOTREACHED */
- }
/* Tell the regex routines how they should work. . . */
resetup();
- while ((c = getopt (argc, argv, awk_opts)) != EOF) {
- switch (c) {
-#ifdef DEBUG
- case 'D':
- fprintf(stderr,
-"warning: option -D will go away in a future release, use -W parsedebug\n");
- gawk_option("parsedebug");
- break;
-#endif
-
- case 'c':
- fprintf(stderr,
- "warning: option -c will go away in a future release, use -W compat\n");
- gawk_option("compat");
- break;
+ /* we do error messages ourselves on invalid options */
+ opterr = 0;
+ /* the + on the front tells GNU getopt not to rearrange argv */
+ while ((c = getopt_long(argc, argv, "+F:f:v:W:", optab, NULL)) != EOF) {
+ if (do_posix)
+ opterr = 1;
+ switch (c) {
case 'F':
cmdline_fs(optarg);
break;
@@ -221,62 +203,87 @@ char **argv;
scan = optarg;
while (isspace(*scan))
scan++;
+ ++numfiles;
+ srcfiles[numfiles].stype = SOURCEFILE;
if (*scan == '\0')
- srcfiles[++numfiles] = argv[optind++];
+ srcfiles[numfiles].val = argv[optind++];
else
- srcfiles[++numfiles] = optarg;
+ srcfiles[numfiles].val = optarg;
break;
case 'v':
pre_assign(optarg);
break;
+ case 'W': /* gawk specific options */
+ gawk_option(optarg);
+ break;
+
+ /* These can only come from long form options */
case 'V':
- warning(
- "option -V will go away in a future release, use -W version");
- gawk_option("version");
+ version();
break;
case 'C':
- warning(
- "option -C will go away in a future release, use -W copyright");
- gawk_option("copyright");
+ copyleft();
break;
- case 'a': /* use old fashioned awk regexps */
- warning("option -a will go away in a future release");
+ case 'u':
+ usage(0);
break;
- case 'e': /* use Posix style regexps */
- warning("option -e will go away in a future release");
+ case 's':
+ if (strlen(optarg) == 0)
+ warning("empty argument to --source ignored");
+ else {
+ srcfiles[++numfiles].stype = CMDLINE;
+ srcfiles[numfiles].val = optarg;
+ }
break;
- case 'W': /* gawk specific options */
- gawk_option(optarg);
+#ifdef DEBUG
+ case 'D':
+ yydebug = 2;
break;
+#endif
case '?':
default:
- /* getopt will print a message for us */
- /* S5R4 awk ignores bad options and keeps going */
+ /*
+ * New behavior. If not posix, an unrecognized
+ * option stops argument processing so that it can
+ * go into ARGV for the awk program to see. This
+ * makes use of ``#! /bin/gawk -f'' easier.
+ */
+ if (! do_posix)
+ goto out;
+ /* else
+ let getopt print error message for us */
break;
}
}
+out:
+
+ if (do_nostalgia)
+ nostalgia();
+
+ /* POSIX compliance also implies no Unix extensions either */
+ if (do_posix)
+ do_unix = 1;
#ifdef DEBUG
setbuf(stdout, (char *) NULL); /* make debugging easier */
#endif
if (isatty(fileno(stdout)))
output_is_tty = 1;
- /* No -f option, use next arg */
- /* write to temp file and save sourcefile name */
+ /* No -f or --source options, use next arg */
if (numfiles == -1) {
if (optind > argc - 1) /* no args left */
- usage();
- cmdline_src = argv[optind];
+ usage(1);
+ srcfiles[++numfiles].stype = CMDLINE;
+ srcfiles[numfiles].val = argv[optind];
optind++;
}
- srcfiles[++numfiles] = NULL;
init_args(optind, argc, (char *) myname, argv);
(void) tokexpand();
@@ -305,72 +312,41 @@ char **argv;
return exit_val; /* to suppress warnings */
}
+/* usage --- print usage information and exit */
+
static void
-usage()
+usage(exitval)
+int exitval;
{
char *opt1 = " -f progfile [--]";
char *opt2 = " [--] 'program'";
- char *regops = " [-F fs] [-v var=val] [-W gawk-opts]";
+ char *regops = " [POSIX or GNU style options]";
+ version();
fprintf(stderr, "usage: %s%s%s file ...\n %s%s%s file ...\n",
myname, regops, opt1, myname, regops, opt2);
- exit(11);
-}
-
-Regexp *
-mk_re_parse(s, ignorecase)
-char *s;
-int ignorecase;
-{
- char *src;
- register char *dest;
- register int c;
- int in_brack = 0;
-
- for (dest = src = s; *src != '\0';) {
- if (*src == '\\') {
- c = *++src;
- switch (c) {
- case '/':
- case 'a':
- case 'b':
- case 'f':
- case 'n':
- case 'r':
- case 't':
- case 'v':
- case 'x':
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- c = parse_escape(&src);
- if (c < 0)
- cant_happen();
- *dest++ = (char)c;
- break;
- default:
- *dest++ = '\\';
- *dest++ = (char)c;
- src++;
- break;
- }
- } else if (*src == '/' && ! in_brack)
- break;
- else {
- if (*src == '[')
- in_brack = 1;
- else if (*src == ']')
- in_brack = 0;
- *dest++ = *src++;
- }
- }
- return make_regexp(tmp_string(s, dest-s), ignorecase, 1);
+ /* GNU long options info. Gack. */
+ fputs("\nPOSIX options:\t\tGNU long options:\n", stderr);
+ fputs("\t-f progfile\t\t--file=progfile\n", stderr);
+ fputs("\t-F fs\t\t\t--field-separator=fs\n", stderr);
+ fputs("\t-v var=val\t\t--assign=var=val\n", stderr);
+ fputs("\t-W compat\t\t--compat\n", stderr);
+ fputs("\t-W copyleft\t\t--copyleft\n", stderr);
+ fputs("\t-W copyright\t\t--copyright\n", stderr);
+ fputs("\t-W help\t\t\t--help\n", stderr);
+ fputs("\t-W lint\t\t\t--lint\n", stderr);
+#if 0
+ fputs("\t-W nostalgia\t\t--nostalgia\n", stderr);
+#endif
+#ifdef DEBUG
+ fputs("\t-W parsedebug\t\t--parsedebug\n", stderr);
+#endif
+ fputs("\t-W posix\t\t--posix\n", stderr);
+ fputs("\t-W source=program-text\t--source=program-text\n", stderr);
+ fputs("\t-W usage\t\t--usage\n", stderr);
+ fputs("\t-W version\t\t--version\n", stderr);
+ exit(exitval);
}
static void
@@ -395,7 +371,7 @@ GNU General Public License for more details.\n\
along with this program; if not, write to the Free Software\n\
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n";
- fprintf(stderr, "%s, patchlevel %d\n", version_string, PATCHLEVEL);
+ version();
fputs(blurb_part1, stderr);
fputs(blurb_part2, stderr);
fputs(blurb_part3, stderr);
@@ -421,7 +397,7 @@ char *str;
if (str[0] == 't' && str[1] == '\0') {
if (do_lint)
warning("-Ft does not set FS to tab in POSIX awk");
- if (strict && ! do_posix)
+ if (do_unix && ! do_posix)
str[0] = '\t';
}
*tmp = make_str_node(str, len, SCAN); /* do process escapes */
@@ -478,6 +454,8 @@ static struct varinit varinit[] = {
{&RLENGTH_node, "RLENGTH", Node_var, 0, 0, 0 },
{&RSTART_node, "RSTART", Node_var, 0, 0, 0 },
{&SUBSEP_node, "SUBSEP", Node_var, "\034", 0, 0 },
+{&ARGIND_node, "ARGIND", Node_var, 0, 0, 0 },
+{&ERRNO_node, "ERRNO", Node_var, 0, 0, 0 },
{0, 0, Node_illegal, 0, 0, 0 },
};
@@ -566,7 +544,7 @@ char *v;
fprintf (stderr,
"%s: '%s' argument to -v not in 'var=value' form\n",
myname, v);
- usage();
+ usage(1);
}
}
@@ -580,7 +558,7 @@ int sig, code;
if (sig == SIGFPE) {
fatal("floating point exception");
} else if (sig == SIGSEGV
-#ifndef MSDOS
+#ifdef SIGBUS
|| sig == SIGBUS
#endif
) {
@@ -613,8 +591,7 @@ char *optstr;
goto unknown;
else
cp += 6;
- fprintf(stderr, "%s, patchlevel %d\n",
- version_string, PATCHLEVEL);
+ version();
break;
case 'c':
case 'C':
@@ -626,12 +603,16 @@ char *optstr;
copyleft();
} else if (strncasecmp(cp, "compat", 6) == 0) {
cp += 5;
- strict = 1;
+ do_unix = 1;
} else
goto unknown;
break;
case 'n':
case 'N':
+ /*
+ * Undocumented feature,
+ * inspired by nostalgia, and a T-shirt
+ */
if (strncasecmp(cp, "nostalgia", 9) != 0)
goto unknown;
nostalgia();
@@ -640,7 +621,7 @@ char *optstr;
case 'P':
#ifdef DEBUG
if (strncasecmp(cp, "parsedebug", 10) == 0) {
- cp += 10;
+ cp += 9;
yydebug = 2;
break;
}
@@ -648,8 +629,7 @@ char *optstr;
if (strncasecmp(cp, "posix", 5) != 0)
goto unknown;
cp += 4;
- do_posix = 1;
- strict = 1;
+ do_posix = do_unix = 1;
break;
case 'l':
case 'L':
@@ -658,6 +638,33 @@ char *optstr;
cp += 3;
do_lint = 1;
break;
+ case 'H':
+ case 'h':
+ if (strncasecmp(cp, "help", 4) != 0)
+ goto unknown;
+ cp += 3;
+ usage(0);
+ break;
+ case 'U':
+ case 'u':
+ if (strncasecmp(cp, "usage", 5) != 0)
+ goto unknown;
+ cp += 4;
+ usage(0);
+ break;
+ case 's':
+ case 'S':
+ if (strncasecmp(cp, "source=", 7) != 0)
+ goto unknown;
+ cp += 7;
+ if (strlen(cp) == 0)
+ warning("empty argument to -Wsource ignored");
+ else {
+ srcfiles[++numfiles].stype = CMDLINE;
+ srcfiles[numfiles].val = cp;
+ return;
+ }
+ break;
default:
unknown:
fprintf(stderr, "'%c' -- unknown option, ignored\n",
@@ -676,7 +683,16 @@ nostalgia()
abort();
}
-static char *
+/* version --- print version message */
+
+static void
+version()
+{
+ fprintf(stderr, "%s, patchlevel %d\n", version_string, PATCHLEVEL);
+}
+
+/* static */
+char *
gawk_name(filespec)
char *filespec;
{
diff --git a/missing.c b/missing.c
index 66c79b41..39c620fc 100644
--- a/missing.c
+++ b/missing.c
@@ -16,6 +16,10 @@
#include "config.h"
+#ifndef __STDC__
+#define const
+#endif /* !__STDC__ */
+
#ifdef STDC_HEADERS
#include <string.h>
#endif
@@ -61,13 +65,9 @@
#endif /* RANDOM_MISSING */
#ifdef STRCASE_MISSING
-#include "missing/strcase.c"
+#include "missing/strncasecmp.c"
#endif /* STRCASE_MISSING */
-#ifdef STRCHR_MISSING
-#include "missing/strchr.c"
-#endif /* STRCHR_MISSING */
-
#ifdef STRERROR_MISSING
#include "missing/strerror.c"
#endif /* STRERROR_MISSING */
@@ -76,6 +76,10 @@
#include "missing/strftime.c"
#endif /* STRFTIME_MISSING */
+#ifdef STRCHR_MISSING
+#include "missing/strchr.c"
+#endif /* STRCHR_MISSING */
+
#ifdef STRTOD_MISSING
#include "missing/strtod.c"
#endif /* STRTOD_MISSING */
diff --git a/missing/strchr.c b/missing/strchr.c
index 234ac883..76016d89 100644
--- a/missing/strchr.c
+++ b/missing/strchr.c
@@ -6,11 +6,11 @@
char *
strchr (str, c)
-register char *str, c;
+register const char *str, c;
{
for (; *str; str++)
if (*str == c)
- return str;
+ return (char *) str;
return NULL;
}
@@ -23,13 +23,13 @@ register char *str, c;
char *
strrchr (str, c)
-register char *str, c;
+register const char *str, c;
{
- register char *save = NULL;
+ register const char *save = NULL;
for (; *str; str++)
if (*str == c)
save = str;
- return save;
+ return (char *) save;
}
diff --git a/missing/strftime.3 b/missing/strftime.3
index 254db661..88d1a222 100644
--- a/missing/strftime.3
+++ b/missing/strftime.3
@@ -180,11 +180,30 @@ is equivalent to specifying
.TP
.B %t
is replaced with a \s-1TAB\s+1 character.
+.PP
+If
+.B SUNOS_EXT
+is defined when the routine is compiled, then the following additional
+conversions will be available.
+These are borrowed from the SunOS version of
+.IR strftime .
+.TP
+.B %k
+is replaced by the hour (24-hour clock) as a decimal number
+.RB ( 0 - 23 ).
+Single digit numbers are padded with a blank.
+.TP
+.B %l
+is replaced by the hour (12-hour clock) as a decimal number
+.RB ( 1 - 12 ).
+Single digit numbers are padded with a blank.
.SH POSIX 1003.2 EXTENSIONS
If
.B POSIX2_DATE
is defined, then all of the conversions available with
.B SYSV_EXT
+and
+.B SUNOS_EXT
are available, as well as the
following additional conversions:
.TP
@@ -259,7 +278,10 @@ is defined, then the following additional conversion is available:
.B %v
The date in VMS format (e.g. 20-JUN-1991).
.SH SEE ALSO
-time(2), ctime(3), localtime(3)
+.IR time (2),
+.IR ctime (3),
+.IR localtime (3),
+.IR tzset (3)
.SH BUGS
This version does not handle multibyte characters or pay attention to the
setting of the
diff --git a/missing/strftime.c b/missing/strftime.c
index da696a8d..85d2e23c 100644
--- a/missing/strftime.c
+++ b/missing/strftime.c
@@ -1,13 +1,14 @@
/*
* strftime.c
*
- * Public-domain relatively quick-and-dirty implemenation of
+ * Public-domain relatively quick-and-dirty implementation of
* ANSI library routine for System V Unix systems.
*
* It's written in old-style C for maximal portability.
* However, since I'm used to prototypes, I've included them too.
*
* If you want stuff in the System V ascftime routine, add the SYSV_EXT define.
+ * For extensions from SunOS, add SUNOS_EXT.
* For stuff needed to implement the P1003.2 date command, add POSIX2_DATE.
* For complete POSIX semantics, add POSIX_SEMANTICS.
*
@@ -22,9 +23,12 @@
* Arnold Robbins
* January, February, March, 1991
* Updated March, April 1992
+ * Updated April, 1993
*
* Fixes from ado@elsie.nci.nih.gov
* February 1991, May 1992
+ * Fixes from Tor Lillqvist tor@tik.vtt.fi
+ * May, 1993
*/
#ifndef GAWK
@@ -37,15 +41,21 @@
/* defaults: season to taste */
#define SYSV_EXT 1 /* stuff in System V ascftime routine */
+#define SUNOS_EXT 1 /* stuff in SunOS strftime routine */
#define POSIX2_DATE 1 /* stuff in Posix 1003.2 date command */
#define VMS_EXT 1 /* include %v for VMS date format */
#ifndef GAWK
#define POSIX_SEMANTICS 1 /* call tzset() if TZ changes */
#endif
-#if defined(POSIX2_DATE) && ! defined(SYSV_EXT)
+#if defined(POSIX2_DATE)
+#if ! defined(SYSV_EXT)
#define SYSV_EXT 1
#endif
+#if ! defined(SUNOS_EXT)
+#define SUNOS_EXT 1
+#endif
+#endif
#if defined(POSIX2_DATE)
#define adddecl(stuff) stuff
@@ -53,6 +63,8 @@
#define adddecl(stuff)
#endif
+#undef strchr /* avoid AIX weirdness */
+
#ifndef __STDC__
#define const /**/
extern void *malloc();
@@ -136,8 +148,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
static char *savetz = NULL;
static int savetzlen = 0;
char *tz;
- int tzlen;
-#endif
+#endif /* POSIX_SEMANTICS */
/* various tables, useful in North America */
static char *days_a[] = {
@@ -172,9 +183,10 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
}
#else /* POSIX_SEMANTICS */
tz = getenv("TZ");
- tzlen = strlen(tz);
if (first) {
if (tz != NULL) {
+ int tzlen = strlen(tz);
+
savetz = (char *) malloc(tzlen + 1);
if (savetz != NULL) {
savetzlen = tzlen + 1;
@@ -387,6 +399,21 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
break;
#endif
+#ifdef SUNOS_EXT
+ case 'k': /* hour, 24-hour clock, blank pad */
+ sprintf(tbuf, "%2d", range(0, timeptr->tm_hour, 23));
+ break;
+
+ case 'l': /* hour, 12-hour clock, 1 - 12, blank pad */
+ i = range(0, timeptr->tm_hour, 23);
+ if (i == 0)
+ i = 12;
+ else if (i > 12)
+ i -= 12;
+ sprintf(tbuf, "%2d", i);
+ break;
+#endif
+
#ifdef VMS_EXT
case 'v': /* date as dd-bbb-YYYY */
@@ -486,19 +513,19 @@ iso8601wknum(const struct tm *timeptr)
simple_wknum = weeknumber(timeptr, 1) + 1;
/*
- * With thanks and tip of the hatlo to ado@elsie.nci.nih.gov
+ * With thanks and tip of the hatlo to tml@tik.vtt.fi
*
* What day of the week does January 1 fall on?
* We know that
* (timeptr->tm_yday - jan1.tm_yday) MOD 7 ==
* (timeptr->tm_wday - jan1.tm_wday) MOD 7
* and that
- * jan1.tm_yday == 1
+ * jan1.tm_yday == 0
* and that
* timeptr->tm_wday MOD 7 == timeptr->tm_wday
* from which it follows that. . .
*/
- jan1day = (timeptr->tm_yday - 1) % 7 - timeptr->tm_wday;
+ jan1day = timeptr->tm_wday - (timeptr->tm_yday % 7);
if (jan1day < 0)
jan1day += 7;
@@ -564,3 +591,117 @@ How nicer it depends on a compiler, of course, but always a tiny bit.
Michal
ntomczak@vm.ucs.ualberta.ca
#endif
+
+#ifdef TEST_STRFTIME
+
+/*
+ * NAME:
+ * tst
+ *
+ * SYNOPSIS:
+ * tst
+ *
+ * DESCRIPTION:
+ * "tst" is a test driver for the function "strftime".
+ *
+ * OPTIONS:
+ * None.
+ *
+ * AUTHOR:
+ * Karl Vogel
+ * Control Data Systems, Inc.
+ * vogelke@c-17igp.wpafb.af.mil
+ *
+ * BUGS:
+ * None noticed yet.
+ *
+ * COMPILE:
+ * cc -o tst -DTEST_STRFTIME strftime.c
+ */
+
+/* ADR: I reformatted this to my liking, and deleted some unneeded code. */
+
+#ifndef NULL
+#include <stdio.h>
+#endif
+#include <sys/time.h>
+#include <string.h>
+
+#define MAXTIME 132
+
+/*
+ * Array of time formats.
+ */
+
+static char *array[] =
+{
+ "(%%A) full weekday name, var length (Sunday..Saturday) %A",
+ "(%%B) full month name, var length (January..December) %B",
+ "(%%C) Century %C",
+ "(%%D) date (%%m/%%d/%%y) %D",
+ "(%%E) Locale extensions (ignored) %E",
+ "(%%H) hour (24-hour clock, 00..23) %H",
+ "(%%I) hour (12-hour clock, 01..12) %I",
+ "(%%M) minute (00..59) %M",
+ "(%%O) Locale extensions (ignored) %O",
+ "(%%R) time, 24-hour (%%H:%%M) %R",
+ "(%%S) second (00..61) %S",
+ "(%%T) time, 24-hour (%%H:%%M:%%S) %T",
+ "(%%U) week of year, Sunday as first day of week (00..53) %U",
+ "(%%V) week of year according to ISO 8601 %V",
+ "(%%W) week of year, Monday as first day of week (00..53) %W",
+ "(%%X) appropriate locale time representation (%H:%M:%S) %X",
+ "(%%Y) year with century (1970...) %Y",
+ "(%%Z) timezone (EDT), or blank if timezone not determinable %Z",
+ "(%%a) locale's abbreviated weekday name (Sun..Sat) %a",
+ "(%%b) locale's abbreviated month name (Jan..Dec) %b",
+ "(%%c) full date (Sat Nov 4 12:02:33 1989)%n%t%t%t %c",
+ "(%%d) day of the month (01..31) %d",
+ "(%%e) day of the month, blank-padded ( 1..31) %e",
+ "(%%h) should be same as (%%b) %h",
+ "(%%j) day of the year (001..366) %j",
+ "(%%k) hour, 24-hour clock, blank pad ( 0..23) %k",
+ "(%%l) hour, 12-hour clock, blank pad ( 0..12) %l",
+ "(%%m) month (01..12) %m",
+ "(%%p) locale's AM or PM based on 12-hour clock %p",
+ "(%%r) time, 12-hour (same as %%I:%%M:%%S %%p) %r",
+ "(%%u) ISO 8601: Weekday as decimal number [1 (Monday) - 7] %u",
+ "(%%v) VAX date (dd-bbb-YYYY) %v",
+ "(%%w) day of week (0..6, Sunday == 0) %w",
+ "(%%x) appropriate locale date representation %x",
+ "(%%y) last two digits of year (00..99) %y",
+ (char *) NULL
+};
+
+/* Main routine. */
+
+int
+main(argc, argv)
+int argc;
+char **argv;
+{
+ long time();
+
+ char *next;
+ char string[MAXTIME];
+
+ int k;
+ int length;
+
+ struct tm *tm;
+
+ long clock;
+
+ /* Call the function. */
+
+ clock = time((long *) 0);
+ tm = localtime(&clock);
+
+ for (k = 0; next = array[k]; k++) {
+ length = strftime(string, MAXTIME, next, tm);
+ printf("%s\n", string);
+ }
+
+ exit(0);
+}
+#endif /* TEST_STRFTIME */
diff --git a/missing/strcase.c b/missing/strncasecmp.c
index 5d93911f..5d93911f 100644
--- a/missing/strcase.c
+++ b/missing/strncasecmp.c
diff --git a/missing/system.c b/missing/system.c
index a062917a..fffb39c1 100644
--- a/missing/system.c
+++ b/missing/system.c
@@ -23,6 +23,8 @@
* the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+extern void fatal();
+
int
system(s)
char *s;
diff --git a/node.c b/node.c
index 925fe8bc..65ecb0ed 100644
--- a/node.c
+++ b/node.c
@@ -25,6 +25,8 @@
#include "awk.h"
+extern double strtod();
+
AWKNUM
r_force_number(n)
register NODE *n;
@@ -299,16 +301,13 @@ NODE *it;
#ifdef MPROF
it->stref = 0;
free((char *) it);
-#else
-#ifdef MALLOCDEBUG
- memset(it, '\04', sizeof(*it));
-#endif
+#else /* not MPROF */
/* add it to head of freelist */
it->nextp = nextfree;
nextfree = it;
-#endif
+#endif /* not MPROF */
}
-#endif
+#endif /* DEBUG */
void
unref(tmp)
diff --git a/protos.h b/protos.h
index 4a49f477..25af3216 100644
--- a/protos.h
+++ b/protos.h
@@ -33,7 +33,6 @@ extern aptr_t realloc P((aptr_t, MALLOC_ARG_T));
extern aptr_t calloc P((MALLOC_ARG_T, MALLOC_ARG_T));
extern void free P((aptr_t));
-extern int getopt P((int argc, char **argv, char *optstring));
extern char *getenv P((char *));
extern char *strcpy P((char *, const char *));
diff --git a/re.c b/re.c
index d9d5fa09..495b0963 100644
--- a/re.c
+++ b/re.c
@@ -26,15 +26,68 @@
#include "awk.h"
/* Generate compiled regular expressions */
+
Regexp *
-make_regexp(s, ignorecase, dfa)
-NODE *s;
+make_regexp(s, len, ignorecase, dfa)
+char *s;
+int len;
int ignorecase;
int dfa;
{
Regexp *rp;
char *err;
+ char *src = s;
+ char *temp;
+ char *end = s + len;
+ register char *dest;
+ register int c;
+
+ /* Handle escaped characters first. */
+
+ /* Build a copy of the string (in dest) with the
+ escaped characters translated, and generate the regex
+ from that.
+ */
+ emalloc(dest, char *, len + 2, "make_regexp");
+ temp = dest;
+
+ while (src < end) {
+ if (*src == '\\') {
+ c = *++src;
+ switch (c) {
+ case 'a':
+ case 'b':
+ case 'f':
+ case 'n':
+ case 'r':
+ case 't':
+ case 'v':
+ case 'x':
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ c = parse_escape(&src);
+ if (c < 0)
+ cant_happen();
+ *dest++ = (char)c;
+ break;
+ default:
+ *dest++ = '\\';
+ *dest++ = (char)c;
+ src++;
+ break;
+ } /* switch */
+ } else {
+ *dest++ = *src++; /* not '\\' */
+ }
+ } /* for */
+ *dest = '\0' ; /* Only necessary if we print dest ? */
emalloc(rp, Regexp *, sizeof(*rp), "make_regexp");
memset((char *) rp, 0, sizeof(*rp));
emalloc(rp->pat.buffer, char *, 16, "make_regexp");
@@ -45,14 +98,15 @@ int dfa;
rp->pat.translate = casetable;
else
rp->pat.translate = NULL;
- if ((err = re_compile_pattern(s->stptr, (size_t) s->stlen, &(rp->pat))) != NULL)
- fatal("%s: /%s/", err, s->stptr);
+ len = dest - temp;
+ if ((err = re_compile_pattern(temp, (size_t) len, &(rp->pat))) != NULL)
+ fatal("%s: /%s/", err, temp);
if (dfa && !ignorecase) {
- regcompile(s->stptr, s->stlen, &(rp->dfareg), 1);
+ regcompile(temp, len, &(rp->dfareg), 1);
rp->dfa = 1;
} else
rp->dfa = 0;
- free_temp(s);
+ free(temp);
return rp;
}
@@ -140,7 +194,7 @@ NODE *t;
t->re_text = dupnode(t1);
free_temp(t1);
}
- t->re_reg = make_regexp(t->re_text, IGNORECASE, t->re_cnt);
+ t->re_reg = make_regexp(t->re_text->stptr, t->re_text->stlen, IGNORECASE, t->re_cnt);
t->re_flags &= ~CASE;
t->re_flags |= IGNORECASE;
return t->re_reg;
diff --git a/regex.h b/regex.h
index e0977bcb..fce11c3a 100644
--- a/regex.h
+++ b/regex.h
@@ -30,7 +30,9 @@
/* Maximum number of duplicates an interval can allow. */
+#ifndef RE_DUP_MAX
#define RE_DUP_MAX ((1 << 15) - 1)
+#endif
/* This defines the various regexp syntaxes. */
diff --git a/test/Makefile b/test/Makefile
index dcf4f15f..cbe054fd 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,19 +1,19 @@
SHELL = /bin/sh
-all: msg swaplns messages argarray longwrds \
- getline inftest fstabplus compare arrayref rs fsrs rand \
- fsbs negexp asgext anchgsub splitargv awkpath nfset reparse
+bigtest: basic poundbang gawk.extensions
-gawk.extensions: fieldwidths ignorecase posix manyfiles igncfs
+basic: msg swaplns messages argarray longwrds \
+ getline fstabplus compare arrayref rs fsrs rand \
+ fsbs negexp asgext anchgsub splitargv awkpath nfset reparse
-bigtest: all pound-bang gawk.extensions
+gawk.extensions: fieldwdth ignrcase posix manyfiles igncfs
-extra: regtest
+extra: regtest inftest
-pound-bang::
- cp ../gawk /tmp && chmod +x pound-bang && ./pound-bang pound-bang >tmp
+poundbang::
+ cp ../gawk /tmp && chmod +x poundbang && ./poundbang poundbang >tmp
rm -f /tmp/gawk
- cmp pound-bang.good tmp && rm -f tmp
+ cmp poundbang.good tmp && rm -f tmp
msg::
@echo 'Any output from "cmp" is bad news, although some differences'
@@ -50,13 +50,13 @@ longwrds::
@../gawk -f longwrds.awk manpage | sort >tmp
cmp longwrds.good tmp && rm -f tmp
-fieldwidths::
+fieldwdth::
@echo '123456789' | ../gawk -v FIELDWIDTHS="2 3 4" '{print $$2}' >tmp
- cmp fieldwidths.good tmp && rm -f tmp
+ cmp fieldwdth.good tmp && rm -f tmp
-ignorecase::
+ignrcase::
@echo xYz | ../gawk -v IGNORECASE=1 '{sub(/y/, ""); print}' >tmp
- cmp ignorecase.good tmp && rm -f tmp
+ cmp ignrcase.good tmp && rm -f tmp
regtest::
@echo 'Some of the output from regtest is very system specific, do not'
@@ -93,6 +93,7 @@ fsbs::
cmp fsbs.good tmp && rm -f tmp
inftest::
+ @echo This test is very machine specific...
@../gawk -f inftest.awk >tmp
cmp inftest.good tmp && rm -f tmp
diff --git a/test/fieldwidths.good b/test/fieldwdth.good
index 51b40081..51b40081 100644
--- a/test/fieldwidths.good
+++ b/test/fieldwdth.good
diff --git a/test/ignorecase.good b/test/ignrcase.good
index d66e95ca..d66e95ca 100644
--- a/test/ignorecase.good
+++ b/test/ignrcase.good
diff --git a/test/pound-bang b/test/pound-bang
deleted file mode 100755
index a1c24d2b..00000000
--- a/test/pound-bang
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /tmp/gawk -f
- { ccount += length($0) }
-END { print "average line length is", ccount/NR}
diff --git a/test/pound-bang.good b/test/pound-bang.good
deleted file mode 100644
index a94f6a99..00000000
--- a/test/pound-bang.good
+++ /dev/null
@@ -1 +0,0 @@
-average line length is 29.6667
diff --git a/test/poundbang b/test/poundbang
new file mode 100755
index 00000000..d60652e3
--- /dev/null
+++ b/test/poundbang
@@ -0,0 +1,3 @@
+#! /tmp/gawk -f
+ { ccount += length($0) }
+END { printf "average line length is %2.4f\n", ccount/NR}
diff --git a/test/poundbang.good b/test/poundbang.good
new file mode 100644
index 00000000..143e28dd
--- /dev/null
+++ b/test/poundbang.good
@@ -0,0 +1 @@
+average line length is 32.6667
diff --git a/version.c b/version.c
index 0c365f85..adea5faf 100644
--- a/version.c
+++ b/version.c
@@ -1,4 +1,4 @@
-char *version_string = "@(#)Gnu Awk (gawk) 2.14";
+char *version_string = "@(#)Gnu Awk (gawk) 2.15";
/* 1.02 fixed /= += *= etc to return the new Left Hand Side instead
of the Right Hand Side */
@@ -41,3 +41,6 @@ char *version_string = "@(#)Gnu Awk (gawk) 2.14";
/* 2.14 Mostly bug fixes. */
+/* 2.15 Bug fixes plus intermixing of command-line source and files,
+ GNU long options, ARGIND, ERRNO and Plan 9 style /dev/ files. */
+
diff --git a/vms/vms_misc.c b/vms/vms_misc.c
index 58231ff4..4d065115 100644
--- a/vms/vms_misc.c
+++ b/vms/vms_misc.c
@@ -139,7 +139,11 @@ vms_devopen( const char *name, int mode )
{
FILE *file = NULL;
- if (strncasecmp(name, "SYS$", 4) == 0) {
+ if (STREQ(name, "/dev/null"))
+ return open("NL:", mode); /* "/dev/null" => "NL:" */
+ else if (STREQ(name, "/dev/tty"))
+ return open("TT:", mode); /* "/dev/tty" => "TT:" */
+ else if (strncasecmp(name, "SYS$", 4) == 0) {
name += 4; /* skip "SYS$" */
if (strncasecmp(name, "INPUT", 5) == 0 && (mode & O_WRONLY) == 0)
file = stdin, name += 5;
@@ -166,16 +170,6 @@ void tzset()
return;
}
-#ifndef __GNUC__
-# ifdef bcopy
-# undef bcopy
-# endif
-void bcopy( const char *src, char *dst, int len )
-{
- (void) memcpy(dst, src, len);
-}
-#endif /*!__GNUC__*/
-
/*----------------------------------------------------------------------*/
#ifdef NO_VMS_ARGS /* real code is in "vms/vms_args.c" */
void vms_arg_fixup( int *argc, char ***argv ) { return; } /* dummy */