aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog16
-rw-r--r--NEWS3
-rw-r--r--awkgram.c2
-rw-r--r--awkgram.y2
-rw-r--r--awklib/eg/lib/groupawk.in3
-rw-r--r--awklib/eg/lib/noassign.awk2
-rw-r--r--awklib/eg/lib/readable.awk2
-rw-r--r--awklib/eg/prog/cut.awk8
-rw-r--r--awklib/eg/prog/egrep.awk7
-rw-r--r--awklib/eg/prog/extract.awk11
-rw-r--r--awklib/eg/prog/id.awk22
-rw-r--r--awklib/eg/prog/split.awk5
-rw-r--r--awklib/eg/prog/uniq.awk5
-rw-r--r--configh.in3
-rwxr-xr-xconfigure13
-rw-r--r--configure.ac6
-rw-r--r--doc/ChangeLog6
-rw-r--r--doc/gawk.info1394
-rw-r--r--doc/gawk.texi258
-rw-r--r--doc/gawktexi.in258
-rw-r--r--pc/config.h6
-rw-r--r--profile.c2
-rw-r--r--test/ChangeLog5
-rw-r--r--test/profile2.ok2
-rw-r--r--test/profile3.ok2
-rw-r--r--test/profile4.ok2
-rw-r--r--test/profile5.ok4
27 files changed, 1024 insertions, 1025 deletions
diff --git a/ChangeLog b/ChangeLog
index 8e551fee..847dc2a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2014-09-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * awkgram.y (check_for_bad): Bitwise-and the bad character with 0xFF
+ to avoid sign extension into a large integer.
+
+ Unrelated:
+
+ * configure.ac: Add an option to enable locale letters in identifiers.
+ Undocumented and subject to being rescinded at any time in the future.
+ * NEWS: Mention to look at configure --help.
+
+ Unrelated:
+
+ * profile.c (pprint): Use "rule(s)" instead of "block(s)" in the
+ header.
+
2014-09-23 Arnold D. Robbins <arnold@skeeve.com>
* awkgram.y (yylex): Don't check for junk characters inside
diff --git a/NEWS b/NEWS
index 58c77e7a..36d54f25 100644
--- a/NEWS
+++ b/NEWS
@@ -57,6 +57,9 @@ Changes from 4.1.1 to 4.1.2
beside those of the English alphabet in identifiers. This has
been fixed. (isalpha and isalnum are NOT our friends.)
+ If you feel that you must have this misfeature, use `configure --help'
+ to see what option to use when configuring gawk to reenable it.
+
XX. A number of bugs have been fixed. See the ChangeLog.
Changes from 4.1.0 to 4.1.1
diff --git a/awkgram.c b/awkgram.c
index 6a61787d..071a01a1 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -5155,7 +5155,7 @@ check_bad_char(int c)
}
if (iscntrl(c) && ! isspace(c))
- fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), c);
+ fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), c & 0xFF);
}
/* nextc --- get the next input character */
diff --git a/awkgram.y b/awkgram.y
index fb1f76f8..be183998 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2816,7 +2816,7 @@ check_bad_char(int c)
}
if (iscntrl(c) && ! isspace(c))
- fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), c);
+ fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), c & 0xFF);
}
/* nextc --- get the next input character */
diff --git a/awklib/eg/lib/groupawk.in b/awklib/eg/lib/groupawk.in
index 9382bce8..54a27f3d 100644
--- a/awklib/eg/lib/groupawk.in
+++ b/awklib/eg/lib/groupawk.in
@@ -38,8 +38,7 @@ function _gr_init( oldfs, oldrs, olddol0, grcat,
n = split($4, a, "[ \t]*,[ \t]*")
for (i = 1; i <= n; i++)
if (a[i] in _gr_groupsbyuser)
- _gr_groupsbyuser[a[i]] = \
- _gr_groupsbyuser[a[i]] " " $1
+ _gr_groupsbyuser[a[i]] = gr_groupsbyuser[a[i]] " " $1
else
_gr_groupsbyuser[a[i]] = $1
diff --git a/awklib/eg/lib/noassign.awk b/awklib/eg/lib/noassign.awk
index 1f750edf..99227b37 100644
--- a/awklib/eg/lib/noassign.awk
+++ b/awklib/eg/lib/noassign.awk
@@ -7,7 +7,7 @@
function disable_assigns(argc, argv, i)
{
for (i = 1; i < argc; i++)
- if (argv[i] ~ /^[[:alpha:]_][[:alnum:]_]*=.*/)
+ if (argv[i] ~ /^[a-zA-Z_][a-zA-Z0-9_]*=.*/)
argv[i] = ("./" argv[i])
}
diff --git a/awklib/eg/lib/readable.awk b/awklib/eg/lib/readable.awk
index 6942dcca..37970a82 100644
--- a/awklib/eg/lib/readable.awk
+++ b/awklib/eg/lib/readable.awk
@@ -6,7 +6,7 @@
BEGIN {
for (i = 1; i < ARGC; i++) {
- if (ARGV[i] ~ /^[[:alpha:]_][[:alnum:]_]*=.*/ \
+ if (ARGV[i] ~ /^[a-zA-Z_][a-zA-Z0-9_]*=.*/ \
|| ARGV[i] == "-" || ARGV[i] == "/dev/stdin")
continue # assignment or standard input
else if ((getline junk < ARGV[i]) < 0) # unreadable
diff --git a/awklib/eg/prog/cut.awk b/awklib/eg/prog/cut.awk
index 56e35e71..080279bc 100644
--- a/awklib/eg/prog/cut.awk
+++ b/awklib/eg/prog/cut.awk
@@ -12,12 +12,10 @@
#
# Requires getopt() and join() library functions
-function usage( e1, e2)
+function usage()
{
- e1 = "usage: cut [-f list] [-d c] [-s] [files...]"
- e2 = "usage: cut [-c list] [files...]"
- print e1 > "/dev/stderr"
- print e2 > "/dev/stderr"
+ print("usage: cut [-f list] [-d c] [-s] [files...]") > "/dev/stderr"
+ print("usage: cut [-c list] [files...]") > "/dev/stderr"
exit 1
}
BEGIN {
diff --git a/awklib/eg/prog/egrep.awk b/awklib/eg/prog/egrep.awk
index 094bdea5..a4165a90 100644
--- a/awklib/eg/prog/egrep.awk
+++ b/awklib/eg/prog/egrep.awk
@@ -91,10 +91,9 @@ function endfile(file)
END {
exit (total == 0)
}
-function usage( e)
+function usage()
{
- e = "Usage: egrep [-csvil] [-e pat] [files ...]"
- e = e "\n\tegrep [-csvil] pat [files ...]"
- print e > "/dev/stderr"
+ print("Usage: egrep [-csvil] [-e pat] [files ...]") > "/dev/stderr"
+ print("\n\tegrep [-csvil] pat [files ...]") > "/dev/stderr"
exit 1
}
diff --git a/awklib/eg/prog/extract.awk b/awklib/eg/prog/extract.awk
index 12e30b54..24f40ce5 100644
--- a/awklib/eg/prog/extract.awk
+++ b/awklib/eg/prog/extract.awk
@@ -1,5 +1,4 @@
-# extract.awk --- extract files and run programs
-# from texinfo files
+# extract.awk --- extract files and run programs from texinfo files
#
# Arnold Robbins, arnold@skeeve.com, Public Domain
# May 1993
@@ -7,8 +6,7 @@
BEGIN { IGNORECASE = 1 }
-/^@c(omment)?[ \t]+system/ \
-{
+/^@c(omment)?[ \t]+system/ {
if (NF < 3) {
e = ("extract: " FILENAME ":" FNR)
e = (e ": badly formed `system' line")
@@ -24,8 +22,7 @@ BEGIN { IGNORECASE = 1 }
print e > "/dev/stderr"
}
}
-/^@c(omment)?[ \t]+file/ \
-{
+/^@c(omment)?[ \t]+file/ {
if (NF != 3) {
e = ("extract: " FILENAME ":" FNR ": badly formed `file' line")
print e > "/dev/stderr"
@@ -66,7 +63,7 @@ BEGIN { IGNORECASE = 1 }
function unexpected_eof()
{
printf("extract: %s:%d: unexpected EOF or error\n",
- FILENAME, FNR) > "/dev/stderr"
+ FILENAME, FNR) > "/dev/stderr"
exit 1
}
diff --git a/awklib/eg/prog/id.awk b/awklib/eg/prog/id.awk
index 992fa57c..b6061f9b 100644
--- a/awklib/eg/prog/id.awk
+++ b/awklib/eg/prog/id.awk
@@ -6,6 +6,7 @@
# May 1993
# Revised February 1996
# Revised May 2014
+# Revised September 2014
# output is:
# uid=12(foo) euid=34(bar) gid=3(baz) \
@@ -19,26 +20,22 @@ BEGIN {
printf("uid=%d", uid)
pw = getpwuid(uid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (euid != uid) {
printf(" euid=%d", euid)
pw = getpwuid(euid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
}
printf(" gid=%d", gid)
pw = getgrgid(gid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (egid != gid) {
printf(" egid=%d", egid)
pw = getgrgid(egid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
}
for (i = 1; ("group" i) in PROCINFO; i++) {
@@ -47,8 +44,7 @@ BEGIN {
group = PROCINFO["group" i]
printf("%d", group)
pw = getgrgid(group)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (("group" (i+1)) in PROCINFO)
printf(",")
}
@@ -58,6 +54,8 @@ BEGIN {
function pr_first_field(str, a)
{
- split(str, a, ":")
- printf("(%s)", a[1])
+ if (str != "") {
+ split(str, a, ":")
+ printf("(%s)", a[1])
+ }
}
diff --git a/awklib/eg/prog/split.awk b/awklib/eg/prog/split.awk
index bcc73ae6..6a7198f6 100644
--- a/awklib/eg/prog/split.awk
+++ b/awklib/eg/prog/split.awk
@@ -50,9 +50,8 @@ BEGIN {
}
print > out
}
-function usage( e)
+function usage()
{
- e = "usage: split [-num] [file] [outname]"
- print e > "/dev/stderr"
+ print("usage: split [-num] [file] [outname]") > "/dev/stderr"
exit 1
}
diff --git a/awklib/eg/prog/uniq.awk b/awklib/eg/prog/uniq.awk
index 2a2cf63e..7dd16099 100644
--- a/awklib/eg/prog/uniq.awk
+++ b/awklib/eg/prog/uniq.awk
@@ -5,10 +5,9 @@
# Arnold Robbins, arnold@skeeve.com, Public Domain
# May 1993
-function usage( e)
+function usage()
{
- e = "Usage: uniq [-udc [-n]] [+n] [ in [ out ]]"
- print e > "/dev/stderr"
+ print("Usage: uniq [-udc [-n]] [+n] [ in [ out ]]") > "/dev/stderr"
exit 1
}
diff --git a/configh.in b/configh.in
index 1ca2946a..301fa21a 100644
--- a/configh.in
+++ b/configh.in
@@ -320,6 +320,9 @@
/* Define to 1 if the system has the type `_Bool'. */
#undef HAVE__BOOL
+/* enable severe portability problems */
+#undef I_DONT_KNOW_WHAT_IM_DOING
+
/* disable lint checks */
#undef NO_LINT
diff --git a/configure b/configure
index 038e2081..cb2e6ba7 100755
--- a/configure
+++ b/configure
@@ -761,6 +761,7 @@ enable_option_checking
enable_silent_rules
with_whiny_user_strftime
enable_lint
+enable_severe_portability_problems
enable_dependency_tracking
enable_largefile
enable_nls
@@ -1405,6 +1406,7 @@ Optional Features:
--enable-silent-rules less verbose build output (undo: "make V=1")
--disable-silent-rules verbose build output (undo: "make V=0")
--disable-lint Disable gawk lint checking
+ --enable-severe-portability-problems Enable really nasty portability problems
--enable-dependency-tracking
do not reject slow dependency extractors
--disable-dependency-tracking
@@ -3181,6 +3183,17 @@ $as_echo "#define NO_LINT 1" >>confdefs.h
fi
+# Check whether --enable-severe-portability-problems was given.
+if test "${enable_severe_portability_problems+set}" = set; then :
+ enableval=$enable_severe_portability_problems; if test "$enableval" = yes
+ then
+
+$as_echo "#define I_DONT_KNOW_WHAT_IM_DOING 1" >>confdefs.h
+
+ fi
+
+fi
+
# Make sure we can run config.sub.
$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
diff --git a/configure.ac b/configure.ac
index 8b4f188e..6122ee07 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,6 +58,12 @@ AC_ARG_ENABLE([lint], [ --disable-lint Disable gawk lint checking],
AC_DEFINE(NO_LINT, 1, [disable lint checks])
fi
)
+AC_ARG_ENABLE([severe-portability-problems], [ --enable-severe-portability-problems Enable really nasty portability problems],
+ if test "$enableval" = yes
+ then
+ AC_DEFINE(I_DONT_KNOW_WHAT_IM_DOING, 1, [enable severe portability problems])
+ fi
+)
AC_CANONICAL_HOST
AC_USE_SYSTEM_EXTENSIONS
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 245af617..7693f5e5 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,6 +1,10 @@
+2014-09-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawktexi.in: Lots more fixes after reading through the MS.
+
2014-09-23 Arnold D. Robbins <arnold@skeeve.com>
- * gawktex.in: Rework the documentation of special files in
+ * gawktexi.in: Rework the documentation of special files in
Chapter 5; some reordering as well as rewriting.
2014-09-22 Arnold D. Robbins <arnold@skeeve.com>
diff --git a/doc/gawk.info b/doc/gawk.info
index 77a3b20e..c41ef683 100644
--- a/doc/gawk.info
+++ b/doc/gawk.info
@@ -2570,6 +2570,8 @@ The following list describes options mandated by the POSIX standard:
CAUTION: This option can severely break old programs. Use
with care.
+ This option may disappear in a future version of `gawk'.
+
`-N'
`--use-lc-numeric'
Force the use of the locale's decimal point character when parsing
@@ -15151,15 +15153,12 @@ over with it from the top. For lack of a better name, we'll call it
nextfile
}
- This code relies on the `ARGIND' variable (*note Auto-set::), which
-is specific to `gawk'. If you are not using `gawk', you can use ideas
-presented in *note Filetrans Function::, to either update `ARGIND' on
-your own or modify this code as appropriate.
-
- The `rewind()' function also relies on the `nextfile' keyword (*note
-Nextfile Statement::). Because of this, you should not call it from an
-`ENDFILE' rule. (This isn't necessary anyway, since as soon as an
-`ENDFILE' rule finishes `gawk' goes to the next file!)
+ The `rewind()' function relies on the `ARGIND' variable (*note
+Auto-set::), which is specific to `gawk'. It also relies on the
+`nextfile' keyword (*note Nextfile Statement::). Because of this, you
+should not call it from an `ENDFILE' rule. (This isn't necessary
+anyway, since as soon as an `ENDFILE' rule finishes `gawk' goes to the
+next file!)

File: gawk.info, Node: File Checking, Next: Empty Files, Prev: Rewind Function, Up: Data File Management
@@ -15176,7 +15175,7 @@ following program to your `awk' program:
BEGIN {
for (i = 1; i < ARGC; i++) {
- if (ARGV[i] ~ /^[[:alpha:]_][[:alnum:]_]*=.*/ \
+ if (ARGV[i] ~ /^[a-zA-Z_][a-zA-Z0-9_]*=.*/ \
|| ARGV[i] == "-" || ARGV[i] == "/dev/stdin")
continue # assignment or standard input
else if ((getline junk < ARGV[i]) < 0) # unreadable
@@ -15190,6 +15189,10 @@ following program to your `awk' program:
element from `ARGV' with `delete' skips the file (since it's no longer
in the list). See also *note ARGC and ARGV::.
+ The regular expression check purposely does not use character classes
+such as `[:alpha:]' and `[:alnum:]' (*note Bracket Expressions::) since
+`awk' variable names only allow the English letters.
+
---------- Footnotes ----------
(1) The `BEGINFILE' special pattern (*note BEGINFILE/ENDFILE::)
@@ -15268,7 +15271,7 @@ programming with a library file does the trick:
function disable_assigns(argc, argv, i)
{
for (i = 1; i < argc; i++)
- if (argv[i] ~ /^[[:alpha:]_][[:alnum:]_]*=.*/)
+ if (argv[i] ~ /^[a-zA-Z_][a-zA-Z0-9_]*=.*/)
argv[i] = ("./" argv[i])
}
@@ -15568,10 +15571,14 @@ result of two sample runs of the test program:
In both runs, the first `--' terminates the arguments to `awk', so
that it does not try to interpret the `-a', etc., as its own options.
- NOTE: After `getopt()' is through, it is the responsibility of the
- user level code to clear out all the elements of `ARGV' from 1 to
- `Optind', so that `awk' does not try to process the command-line
- options as file names.
+ NOTE: After `getopt()' is through, user level code must clear out
+ all the elements of `ARGV' from 1 to `Optind', so that `awk' does
+ not try to process the command-line options as file names.
+
+ Using `#!' with the `-E' option may help avoid conflicts between
+your program's options and `gawk''s options, since `-E' causes `gawk'
+to abandon processing of further options (*note Executable Scripts::,
+and *note Options::).
Several of the sample programs presented in *note Sample Programs::,
use `getopt()' to process their arguments.
@@ -15730,8 +15737,8 @@ corresponding to the C functions of the same names:
routine, we have chosen to put it in `/usr/local/libexec/awk'; however,
you might want it to be in a different directory on your system.
- The function `_pw_init()' keeps three copies of the user information
-in three associative arrays. The arrays are indexed by username
+ The function `_pw_init()' fills three copies of the user information
+into three associative arrays. The arrays are indexed by username
(`_pw_byname'), by user ID number (`_pw_byuid'), and by order of
occurrence (`_pw_bycount'). The variable `_pw_inited' is used for
efficiency, since `_pw_init()' needs to be called only once.
@@ -15741,13 +15748,10 @@ efficiency, since `_pw_init()' needs to be called only once.
in the variable `using_fw' whether field splitting with `FIELDWIDTHS'
is in effect or not. Doing so is necessary, since these functions
could be called from anywhere within a user's program, and the user may
-have his or her own way of splitting records and fields.
-
- The `using_fw' variable checks `PROCINFO["FS"]', which is
-`"FIELDWIDTHS"' if field splitting is being done with `FIELDWIDTHS'.
-This makes it possible to restore the correct field-splitting mechanism
-later. The test can only be true for `gawk'. It is false if using
-`FS' or `FPAT', or on some other `awk' implementation.
+have his or her own way of splitting records and fields. This makes it
+possible to restore the correct field-splitting mechanism later. The
+test can only be true for `gawk'. It is false if using `FS' or `FPAT',
+or on some other `awk' implementation.
The code that checks for using `FPAT', using `using_fpat' and
`PROCINFO["FS"]', is similar.
@@ -15943,8 +15947,7 @@ the same names:
n = split($4, a, "[ \t]*,[ \t]*")
for (i = 1; i <= n; i++)
if (a[i] in _gr_groupsbyuser)
- _gr_groupsbyuser[a[i]] = \
- _gr_groupsbyuser[a[i]] " " $1
+ _gr_groupsbyuser[a[i]] = gr_groupsbyuser[a[i]] " " $1
else
_gr_groupsbyuser[a[i]] = $1
@@ -16120,8 +16123,8 @@ File: gawk.info, Node: Library Functions Summary, Next: Library Exercises, Pr
============
* Reading programs is an excellent way to learn Good Programming.
- The functions provided in this major node and the next are intended
- to serve that purpose.
+ The functions and programs provided in this major node and the next
+ are intended to serve that purpose.
* When writing general-purpose library functions, put some thought
into how to name any global variables so that they won't conflict
@@ -16312,18 +16315,13 @@ supplied:
#
# Requires getopt() and join() library functions
- function usage( e1, e2)
+ function usage()
{
- e1 = "usage: cut [-f list] [-d c] [-s] [files...]"
- e2 = "usage: cut [-c list] [files...]"
- print e1 > "/dev/stderr"
- print e2 > "/dev/stderr"
+ print("usage: cut [-f list] [-d c] [-s] [files...]") > "/dev/stderr"
+ print("usage: cut [-c list] [files...]") > "/dev/stderr"
exit 1
}
-The variables `e1' and `e2' are used so that the function fits nicely
-on the screen.
-
Next comes a `BEGIN' rule that parses the command-line options. It
sets `FS' to a single TAB character, because that is `cut''s default
field separator. The rule then sets the output field separator to be the
@@ -16725,17 +16723,13 @@ there are no matches, the exit status is one; otherwise it is zero:
The `usage()' function prints a usage message in case of invalid
options, and then exits:
- function usage( e)
+ function usage()
{
- e = "Usage: egrep [-csvil] [-e pat] [files ...]"
- e = e "\n\tegrep [-csvil] pat [files ...]"
- print e > "/dev/stderr"
+ print("Usage: egrep [-csvil] [-e pat] [files ...]") > "/dev/stderr"
+ print("\n\tegrep [-csvil] pat [files ...]") > "/dev/stderr"
exit 1
}
- The variable `e' is used so that the function fits nicely on the
-printed page.
-
---------- Footnotes ----------
(1) It also introduces a subtle bug; if a match happens, we output
@@ -16786,26 +16780,22 @@ and the group numbers:
printf("uid=%d", uid)
pw = getpwuid(uid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (euid != uid) {
printf(" euid=%d", euid)
pw = getpwuid(euid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
}
printf(" gid=%d", gid)
pw = getgrgid(gid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (egid != gid) {
printf(" egid=%d", egid)
pw = getgrgid(egid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
}
for (i = 1; ("group" i) in PROCINFO; i++) {
@@ -16814,8 +16804,7 @@ and the group numbers:
group = PROCINFO["group" i]
printf("%d", group)
pw = getgrgid(group)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (("group" (i+1)) in PROCINFO)
printf(",")
}
@@ -16825,8 +16814,10 @@ and the group numbers:
function pr_first_field(str, a)
{
- split(str, a, ":")
- printf("(%s)", a[1])
+ if (str != "") {
+ split(str, a, ":")
+ printf("(%s)", a[1])
+ }
}
The test in the `for' loop is worth noting. Any supplementary
@@ -16844,8 +16835,9 @@ then the condition is false the first time it's tested, and the loop
body never executes.
The `pr_first_field()' function simply isolates out some code that
-is used repeatedly, making the whole program slightly shorter and
-cleaner.
+is used repeatedly, making the whole program shorter and cleaner. In
+particular, moving the check for the empty string into this function
+saves several lines of code.

File: gawk.info, Node: Split Program, Next: Tee Program, Prev: Id Program, Up: Clones
@@ -16936,15 +16928,12 @@ moves to the next letter in the alphabet and `s2' starts over again at
The `usage()' function simply prints an error message and exits:
- function usage( e)
+ function usage()
{
- e = "usage: split [-num] [file] [outname]"
- print e > "/dev/stderr"
+ print("usage: split [-num] [file] [outname]") > "/dev/stderr"
exit 1
}
-The variable `e' is used so that the function fits nicely on the screen.
-
This program is a bit sloppy; it relies on `awk' to automatically
close the last file instead of doing it in an `END' rule. It also
assumes that letters are contiguous in the character set, which isn't
@@ -17057,10 +17046,10 @@ usage is as follows:
The options for `uniq' are:
`-d'
- Print only repeated lines.
+ Print only repeated (duplicated) lines.
`-u'
- Print only nonrepeated lines.
+ Print only nonrepeated (unique) lines.
`-c'
Count lines. This option overrides `-d' and `-u'. Both repeated
@@ -17110,10 +17099,9 @@ standard output, `/dev/stdout':
#
# Requires getopt() and join() library functions
- function usage( e)
+ function usage()
{
- e = "Usage: uniq [-udc [-n]] [+n] [ in [ out ]]"
- print e > "/dev/stderr"
+ print("Usage: uniq [-udc [-n]] [+n] [ in [ out ]]") > "/dev/stderr"
exit 1
}
@@ -17167,16 +17155,18 @@ standard output, `/dev/stdout':
The following function, `are_equal()', compares the current line,
`$0', to the previous line, `last'. It handles skipping fields and
characters. If no field count and no character count are specified,
-`are_equal()' simply returns one or zero depending upon the result of a
-simple string comparison of `last' and `$0'. Otherwise, things get more
-complicated. If fields have to be skipped, each line is broken into an
-array using `split()' (*note String Functions::); the desired fields
-are then joined back into a line using `join()'. The joined lines are
-stored in `clast' and `cline'. If no fields are skipped, `clast' and
-`cline' are set to `last' and `$0', respectively. Finally, if
-characters are skipped, `substr()' is used to strip off the leading
-`charcount' characters in `clast' and `cline'. The two strings are
-then compared and `are_equal()' returns the result:
+`are_equal()' returns one or zero depending upon the result of a simple
+string comparison of `last' and `$0'.
+
+ Otherwise, things get more complicated. If fields have to be
+skipped, each line is broken into an array using `split()' (*note
+String Functions::); the desired fields are then joined back into a line
+using `join()'. The joined lines are stored in `clast' and `cline'.
+If no fields are skipped, `clast' and `cline' are set to `last' and
+`$0', respectively. Finally, if characters are skipped, `substr()' is
+used to strip off the leading `charcount' characters in `clast' and
+`cline'. The two strings are then compared and `are_equal()' returns
+the result:
function are_equal( n, m, clast, cline, alast, aline)
{
@@ -17272,8 +17262,8 @@ one or more input files. Its usage is as follows:
If no files are specified on the command line, `wc' reads its
standard input. If there are multiple files, it also prints total
-counts for all the files. The options and their meanings are shown in
-the following list:
+counts for all the files. The options and their meanings are as
+follows:
`-l'
Count only lines.
@@ -17764,12 +17754,12 @@ splits records at blank lines (*note Records::). It sets `MAXLINES' to
Most of the work is done in the `printpage()' function. The label
lines are stored sequentially in the `line' array. But they have to
print horizontally; `line[1]' next to `line[6]', `line[2]' next to
-`line[7]', and so on. Two loops are used to accomplish this. The
-outer loop, controlled by `i', steps through every 10 lines of data;
-this is each row of labels. The inner loop, controlled by `j', goes
-through the lines within the row. As `j' goes from 0 to 4, `i+j' is
-the `j'-th line in the row, and `i+j+5' is the entry next to it. The
-output ends up looking something like this:
+`line[7]', and so on. Two loops accomplish this. The outer loop,
+controlled by `i', steps through every 10 lines of data; this is each
+row of labels. The inner loop, controlled by `j', goes through the
+lines within the row. As `j' goes from 0 to 4, `i+j' is the `j'-th
+line in the row, and `i+j+5' is the entry next to it. The output ends
+up looking something like this:
line 1 line 6
line 2 line 7
@@ -17860,7 +17850,7 @@ a useful format.
At first glance, a program like this would seem to do the job:
- # Print list of word frequencies
+ # wordfreq-first-try.awk --- print list of word frequencies
{
for (i = 1; i <= NF; i++)
@@ -18014,9 +18004,9 @@ Texinfo input file into separate files.
This Info file is written in Texinfo
(http://www.gnu.org/software/texinfo/), the GNU project's document
formatting language. A single Texinfo source file can be used to
-produce both printed and online documentation. The Texinfo language is
-described fully, starting with *note (Texinfo)Top::
-texinfo,Texinfo--The GNU Documentation Format.
+produce both printed documentation, with TeX, and online documentation.
+(The Texinfo language is described fully, starting with *note
+(Texinfo)Top:: texinfo,Texinfo--The GNU Documentation Format.)
For our purposes, it is enough to know three things about Texinfo
input files:
@@ -18078,13 +18068,11 @@ upper- and lowercase letters in the directives won't matter.
given (`NF' is at least three) and also checking that the command exits
with a zero exit status, signifying OK:
- # extract.awk --- extract files and run programs
- # from texinfo files
+ # extract.awk --- extract files and run programs from texinfo files
BEGIN { IGNORECASE = 1 }
- /^@c(omment)?[ \t]+system/ \
- {
+ /^@c(omment)?[ \t]+system/ {
if (NF < 3) {
e = ("extract: " FILENAME ":" FNR)
e = (e ": badly formed `system' line")
@@ -18132,8 +18120,7 @@ with the value of `SUBSEP' (*note Multidimensional::), to rejoin the
pieces back into a single line. That line is then printed to the
output file:
- /^@c(omment)?[ \t]+file/ \
- {
+ /^@c(omment)?[ \t]+file/ {
if (NF != 3) {
e = ("extract: " FILENAME ":" FNR ": badly formed `file' line")
print e > "/dev/stderr"
@@ -18187,7 +18174,7 @@ closing the open file:
function unexpected_eof()
{
printf("extract: %s:%d: unexpected EOF or error\n",
- FILENAME, FNR) > "/dev/stderr"
+ FILENAME, FNR) > "/dev/stderr"
exit 1
}
@@ -18396,8 +18383,8 @@ arguments are supplied, then the first nonoption argument should be the
`awk' program. If there are no command-line arguments left, `igawk'
prints an error message and exits. Otherwise, the first argument is
appended to `program'. In any case, after the arguments have been
-processed, `program' contains the complete text of the original `awk'
-program.
+processed, the shell variable `program' contains the complete text of
+the original `awk' program.
The program is as follows:
@@ -18643,7 +18630,7 @@ and it is frequently easier to do certain kinds of string and argument
manipulation using the shell than it is in `awk'.
Finally, `igawk' shows that it is not always necessary to add new
-features to a program; they can often be layered on top.
+features to a program; they can often be layered on top.(3)
---------- Footnotes ----------
@@ -18654,6 +18641,9 @@ programming book if you wish to understand things in more depth.
(2) On some very old versions of `awk', the test `getline junk < t'
can loop forever if the file exists but is empty.
+ (3) `gawk' does `@include' processing itself in order to support the
+use of `awk' programs as Web CGI scripts.
+

File: gawk.info, Node: Anagram Program, Next: Signature Program, Prev: Igawk Program, Up: Miscellaneous Programs
@@ -18665,12 +18655,11 @@ word list (such as `/usr/share/dict/words' on many GNU/Linux systems).
One word is an anagram of another if both words contain the same letters
(for example, "babbling" and "blabbing").
- An elegant algorithm is presented in Column 2, Problem C of Jon
-Bentley's `Programming Pearls', second edition. The idea is to give
-words that are anagrams a common signature, sort all the words together
-by their signature, and then print them. Dr. Bentley observes that
-taking the letters in each word and sorting them produces that common
-signature.
+ Column 2, Problem C of Jon Bentley's `Programming Pearls', second
+edition, presents an elegant algorithm. The idea is to give words that
+are anagrams a common signature, sort all the words together by their
+signature, and then print them. Dr. Bentley observes that taking the
+letters in each word and sorting them produces that common signature.
The following program uses arrays of arrays to bring together words
with the same signature and array sorting to print the words in sorted
@@ -18779,9 +18768,9 @@ File: gawk.info, Node: Programs Summary, Next: Programs Exercises, Prev: Misc
11.4 Summary
============
- * The functions provided in this major node and the previous one
- continue on the theme that reading programs is an excellent way to
- learn Good Programming.
+ * The programs provided in this major node continue on the theme
+ that reading programs is an excellent way to learn Good
+ Programming.
* Using `#!' to make `awk' programs directly runnable makes them
easier to use. Otherwise, invoke the program using `awk -f ...'.
@@ -18958,11 +18947,10 @@ File: gawk.info, Node: Nondecimal Data, Next: Array Sorting, Up: Advanced Fea
===================================
If you run `gawk' with the `--non-decimal-data' option, you can have
-nondecimal constants in your input data:
+nondecimal values in your input data:
$ echo 0123 123 0x123 |
- > gawk --non-decimal-data '{ printf "%d, %d, %d\n",
- > $1, $2, $3 }'
+ > gawk --non-decimal-data '{ printf "%d, %d, %d\n", $1, $2, $3 }'
-| 83, 123, 291
For this feature to work, write your program so that `gawk' treats
@@ -18993,6 +18981,8 @@ request it.
programs easier to write and easier to read, and leads to less
surprising results.
+ This option may disappear in a future version of `gawk'.
+

File: gawk.info, Node: Array Sorting, Next: Two-way I/O, Prev: Nondecimal Data, Up: Advanced Features
@@ -19031,7 +19021,7 @@ pre-defined values to `PROCINFO["sorted_in"]' in order to control the
order in which `gawk' traverses an array during a `for' loop.
In addition, the value of `PROCINFO["sorted_in"]' can be a function
-name. This lets you traverse an array based on any custom criterion.
+name.(1) This lets you traverse an array based on any custom criterion.
The array elements are ordered according to the return value of this
function. The comparison function should be defined with at least four
arguments:
@@ -19146,7 +19136,7 @@ of the previous functions:
according to login name. The following program sorts records by a
specific field position and can be used for this purpose:
- # sort.awk --- simple program to sort by field position
+ # passwd-sort.awk --- simple program to sort by field position
# field position is specified by the global variable POS
function cmp_field(i1, v1, i2, v2)
@@ -19198,13 +19188,14 @@ seemingly ordered data:
elements compare equal. This is usually not a problem, but letting the
tied elements come out in arbitrary order can be an issue, especially
when comparing item values. The partial ordering of the equal elements
-may change during the next loop traversal, if other elements are added
-or removed from the array. One way to resolve ties when comparing
-elements with otherwise equal values is to include the indices in the
-comparison rules. Note that doing this may make the loop traversal
-less efficient, so consider it only if necessary. The following
-comparison functions force a deterministic order, and are based on the
-fact that the (string) indices of two elements are never equal:
+may change the next time the array is traversed, if other elements are
+added or removed from the array. One way to resolve ties when
+comparing elements with otherwise equal values is to include the
+indices in the comparison rules. Note that doing this may make the
+loop traversal less efficient, so consider it only if necessary. The
+following comparison functions force a deterministic order, and are
+based on the fact that the (string) indices of two elements are never
+equal:
function cmp_numeric(i1, v1, i2, v2)
{
@@ -19243,6 +19234,11 @@ array has been reported to add 15% to 20% overhead to the execution
time of `awk' programs. For this reason, sorted array traversal is not
the default.
+ ---------- Footnotes ----------
+
+ (1) This is why the predefined sorting orders start with an `@'
+character, which cannot be part of an identifier.
+

File: gawk.info, Node: Array Sorting Functions, Prev: Controlling Array Traversal, Up: Array Sorting
@@ -19455,7 +19451,7 @@ using regular pipes.
(1) Michael Brennan suggests the use of `rand()' to generate unique
file names. This is a valid point; nevertheless, temporary files remain
-more difficult than two-way pipes.
+more difficult to use than two-way pipes.
(2) This is very different from the same operator in the C shell and
in Bash.
@@ -19470,7 +19466,7 @@ File: gawk.info, Node: TCP/IP Networking, Next: Profiling, Prev: Two-way I/O,
A host is a host from coast to coast,
and no-one can talk to host that's close,
unless the host that isn't close
- is busy hung or dead.
+ is busy, hung, or dead.
In addition to being able to open a two-way pipeline to a coprocess on
the same system (*note Two-way I/O::), it is possible to make a two-way
@@ -19494,8 +19490,8 @@ NET-TYPE
PROTOCOL
The protocol to use over IP. This must be either `tcp', or `udp',
- for a TCP or UDP IP connection, respectively. The use of TCP is
- recommended for most applications.
+ for a TCP or UDP IP connection, respectively. TCP should be used
+ for most applications.
LOCAL-PORT
The local TCP or UDP port number to use. Use a port number of `0'
@@ -19521,10 +19517,10 @@ REMOTE-PORT
Consider the following very simple example:
BEGIN {
- Service = "/inet/tcp/0/localhost/daytime"
- Service |& getline
- print $0
- close(Service)
+ Service = "/inet/tcp/0/localhost/daytime"
+ Service |& getline
+ print $0
+ close(Service)
}
This program reads the current date and time from the local system's
@@ -31180,20 +31176,20 @@ Index
* --include option: Options. (line 159)
* --lint option <1>: Options. (line 185)
* --lint option: Command Line. (line 20)
-* --lint-old option: Options. (line 293)
+* --lint-old option: Options. (line 295)
* --load option: Options. (line 173)
* --non-decimal-data option <1>: Nondecimal Data. (line 6)
* --non-decimal-data option: Options. (line 211)
* --non-decimal-data option, strtonum() function and: Nondecimal Data.
- (line 36)
-* --optimize option: Options. (line 235)
-* --posix option: Options. (line 252)
-* --posix option, --traditional option and: Options. (line 271)
-* --pretty-print option: Options. (line 224)
+ (line 35)
+* --optimize option: Options. (line 237)
+* --posix option: Options. (line 254)
+* --posix option, --traditional option and: Options. (line 273)
+* --pretty-print option: Options. (line 226)
* --profile option <1>: Profiling. (line 12)
-* --profile option: Options. (line 240)
-* --re-interval option: Options. (line 277)
-* --sandbox option: Options. (line 284)
+* --profile option: Options. (line 242)
+* --re-interval option: Options. (line 279)
+* --sandbox option: Options. (line 286)
* --sandbox option, disabling system() function: I/O Functions.
(line 96)
* --sandbox option, input redirection with getline: Getline. (line 19)
@@ -31201,9 +31197,9 @@ Index
(line 6)
* --source option: Options. (line 117)
* --traditional option: Options. (line 81)
-* --traditional option, --posix option and: Options. (line 271)
-* --use-lc-numeric option: Options. (line 219)
-* --version option: Options. (line 298)
+* --traditional option, --posix option and: Options. (line 273)
+* --use-lc-numeric option: Options. (line 221)
+* --version option: Options. (line 300)
* --with-whiny-user-strftime configuration option: Additional Configuration Options.
(line 35)
* -b option: Options. (line 68)
@@ -31211,32 +31207,32 @@ Index
* -c option: Options. (line 81)
* -D option: Options. (line 108)
* -d option: Options. (line 93)
-* -e option: Options. (line 334)
+* -e option: Options. (line 336)
* -E option: Options. (line 125)
* -e option: Options. (line 117)
* -f option: Options. (line 25)
* -F option: Options. (line 21)
* -f option: Long. (line 12)
-* -F option, -Ft sets FS to TAB: Options. (line 306)
+* -F option, -Ft sets FS to TAB: Options. (line 308)
* -F option, command-line: Command Line Field Separator.
(line 6)
-* -f option, multiple uses: Options. (line 311)
+* -f option, multiple uses: Options. (line 313)
* -g option: Options. (line 147)
* -h option: Options. (line 154)
* -i option: Options. (line 159)
-* -L option: Options. (line 293)
+* -L option: Options. (line 295)
* -l option: Options. (line 173)
* -M option: Options. (line 205)
-* -N option: Options. (line 219)
+* -N option: Options. (line 221)
* -n option: Options. (line 211)
-* -O option: Options. (line 235)
-* -o option: Options. (line 224)
-* -P option: Options. (line 252)
-* -p option: Options. (line 240)
-* -r option: Options. (line 277)
-* -S option: Options. (line 284)
+* -O option: Options. (line 237)
+* -o option: Options. (line 226)
+* -P option: Options. (line 254)
+* -p option: Options. (line 242)
+* -r option: Options. (line 279)
+* -S option: Options. (line 286)
* -v option: Assignment Options. (line 12)
-* -V option: Options. (line 298)
+* -V option: Options. (line 300)
* -v option: Options. (line 32)
* -W option: Options. (line 46)
* . (period), regexp operator: Regexp Operators. (line 44)
@@ -31396,7 +31392,7 @@ Index
* ampersand (&), && operator: Boolean Ops. (line 59)
* ampersand (&), gsub()/gensub()/sub() functions and: Gory Details.
(line 6)
-* anagram.awk program: Anagram Program. (line 22)
+* anagram.awk program: Anagram Program. (line 21)
* anagrams, finding: Anagram Program. (line 6)
* and: Bitwise Functions. (line 40)
* AND bitwise operation: Bitwise Functions. (line 6)
@@ -31509,7 +31505,7 @@ Index
* awf (amazingly workable formatter) program: Glossary. (line 24)
* awk debugging, enabling: Options. (line 108)
* awk language, POSIX version: Assignment Ops. (line 137)
-* awk profiling, enabling: Options. (line 240)
+* awk profiling, enabling: Options. (line 242)
* awk programs <1>: Two Rules. (line 6)
* awk programs <2>: Executable Scripts. (line 6)
* awk programs: Getting Started. (line 12)
@@ -31636,7 +31632,7 @@ Index
* BEGIN pattern, operators and: Using BEGIN/END. (line 17)
* BEGIN pattern, print statement and: I/O And BEGIN/END. (line 16)
* BEGIN pattern, pwcat program: Passwd Functions. (line 143)
-* BEGIN pattern, running awk programs and: Cut Program. (line 68)
+* BEGIN pattern, running awk programs and: Cut Program. (line 63)
* BEGIN pattern, TEXTDOMAIN variable and: Programmer i18n. (line 60)
* BEGINFILE pattern: BEGINFILE/ENDFILE. (line 6)
* BEGINFILE pattern, Boolean patterns and: Expression Patterns.
@@ -31913,7 +31909,7 @@ Index
* cosine: Numeric Functions. (line 15)
* counting: Wc Program. (line 6)
* csh utility: Statements/Lines. (line 44)
-* csh utility, POSIXLY_CORRECT environment variable: Options. (line 352)
+* csh utility, POSIXLY_CORRECT environment variable: Options. (line 354)
* csh utility, |& operator, comparison with: Two-way I/O. (line 25)
* ctime() user-defined function: Function Example. (line 74)
* currency symbols, localization: Explaining gettext. (line 104)
@@ -32097,7 +32093,7 @@ Index
* debugger, read commands from a file: Debugger Info. (line 96)
* debugging awk programs: Debugger. (line 6)
* debugging gawk, bug reports: Bugs. (line 9)
-* decimal point character, locale specific: Options. (line 268)
+* decimal point character, locale specific: Options. (line 270)
* decrement operators: Increment Ops. (line 35)
* default keyword: Switch Statement. (line 6)
* Deifik, Scott <1>: Bugs. (line 71)
@@ -32262,10 +32258,10 @@ Index
* ENDFILE pattern: BEGINFILE/ENDFILE. (line 6)
* ENDFILE pattern, Boolean patterns and: Expression Patterns. (line 70)
* endfile() user-defined function: Filetrans Function. (line 61)
-* endgrent() function (C library): Group Functions. (line 212)
-* endgrent() user-defined function: Group Functions. (line 215)
-* endpwent() function (C library): Passwd Functions. (line 210)
-* endpwent() user-defined function: Passwd Functions. (line 213)
+* endgrent() function (C library): Group Functions. (line 211)
+* endgrent() user-defined function: Group Functions. (line 214)
+* endpwent() function (C library): Passwd Functions. (line 207)
+* endpwent() user-defined function: Passwd Functions. (line 210)
* English, Steve: Advanced Features. (line 6)
* ENVIRON array: Auto-set. (line 60)
* environment variables used by gawk: Environment Variables.
@@ -32399,7 +32395,7 @@ Index
(line 6)
* field separators, regular expressions as: Field Separators. (line 51)
* field separators, See Also OFS: Changing Fields. (line 64)
-* field separators, spaces as: Cut Program. (line 108)
+* field separators, spaces as: Cut Program. (line 103)
* fields <1>: Basic High Level. (line 73)
* fields <2>: Fields. (line 6)
* fields: Reading Files. (line 14)
@@ -32527,9 +32523,9 @@ Index
* FS variable, --field-separator option and: Options. (line 21)
* FS variable, as null string: Single Character Fields.
(line 20)
-* FS variable, as TAB character: Options. (line 264)
+* FS variable, as TAB character: Options. (line 266)
* FS variable, changing value of: Field Separators. (line 35)
-* FS variable, running awk programs and: Cut Program. (line 68)
+* FS variable, running awk programs and: Cut Program. (line 63)
* FS variable, setting from command line: Command Line Field Separator.
(line 6)
* FS, containing ^: Regexp Field Splitting.
@@ -32615,7 +32611,7 @@ Index
(line 140)
* gawk, ERRNO variable in: Getline. (line 19)
* gawk, escape sequences: Escape Sequences. (line 132)
-* gawk, extensions, disabling: Options. (line 252)
+* gawk, extensions, disabling: Options. (line 254)
* gawk, features, adding: Adding Code. (line 6)
* gawk, features, advanced: Advanced Features. (line 6)
* gawk, field separators and: User-modified. (line 71)
@@ -32676,7 +32672,7 @@ Index
* gawk, TEXTDOMAIN variable in: User-modified. (line 151)
* gawk, timestamps: Time Functions. (line 6)
* gawk, uses for: Preface. (line 34)
-* gawk, versions of, information about, printing: Options. (line 298)
+* gawk, versions of, information about, printing: Options. (line 300)
* gawk, VMS version of: VMS Installation. (line 6)
* gawk, word-boundary operator: GNU Regexp Operators.
(line 63)
@@ -32692,12 +32688,12 @@ Index
* getaddrinfo() function (C library): TCP/IP Networking. (line 38)
* getgrent() function (C library): Group Functions. (line 6)
* getgrent() user-defined function: Group Functions. (line 6)
-* getgrgid() function (C library): Group Functions. (line 183)
-* getgrgid() user-defined function: Group Functions. (line 186)
-* getgrnam() function (C library): Group Functions. (line 172)
-* getgrnam() user-defined function: Group Functions. (line 177)
-* getgruser() function (C library): Group Functions. (line 192)
-* getgruser() function, user-defined: Group Functions. (line 195)
+* getgrgid() function (C library): Group Functions. (line 182)
+* getgrgid() user-defined function: Group Functions. (line 185)
+* getgrnam() function (C library): Group Functions. (line 171)
+* getgrnam() user-defined function: Group Functions. (line 176)
+* getgruser() function (C library): Group Functions. (line 191)
+* getgruser() function, user-defined: Group Functions. (line 194)
* getline command: Reading Files. (line 20)
* getline command, _gr_init() user-defined function: Group Functions.
(line 83)
@@ -32721,10 +32717,10 @@ Index
* getopt() user-defined function: Getopt Function. (line 108)
* getpwent() function (C library): Passwd Functions. (line 16)
* getpwent() user-defined function: Passwd Functions. (line 16)
-* getpwnam() function (C library): Passwd Functions. (line 177)
-* getpwnam() user-defined function: Passwd Functions. (line 182)
-* getpwuid() function (C library): Passwd Functions. (line 188)
-* getpwuid() user-defined function: Passwd Functions. (line 192)
+* getpwnam() function (C library): Passwd Functions. (line 174)
+* getpwnam() user-defined function: Passwd Functions. (line 179)
+* getpwuid() function (C library): Passwd Functions. (line 185)
+* getpwuid() user-defined function: Passwd Functions. (line 189)
* gettext library: Explaining gettext. (line 6)
* gettext library, locale categories: Explaining gettext. (line 81)
* gettext() function (C library): Explaining gettext. (line 63)
@@ -32988,7 +32984,7 @@ Index
* lint checking, empty programs: Command Line. (line 16)
* lint checking, issuing warnings: Options. (line 185)
* lint checking, POSIXLY_CORRECT environment variable: Options.
- (line 337)
+ (line 339)
* lint checking, undefined functions: Pass By Value/Reference.
(line 88)
* LINT variable: User-modified. (line 88)
@@ -33004,7 +33000,7 @@ Index
* loading, extensions: Options. (line 173)
* local variables, in a function: Variable Scope. (line 6)
* locale categories: Explaining gettext. (line 81)
-* locale decimal point character: Options. (line 268)
+* locale decimal point character: Options. (line 270)
* locale, definition of: Locales. (line 6)
* localization: I18N and L10N. (line 6)
* localization, See internationalization, localization: I18N and L10N.
@@ -33085,7 +33081,7 @@ Index
* networks, programming: TCP/IP Networking. (line 6)
* networks, support for: Special Network. (line 6)
* newlines <1>: Boolean Ops. (line 69)
-* newlines <2>: Options. (line 258)
+* newlines <2>: Options. (line 260)
* newlines: Statements/Lines. (line 6)
* newlines, as field separators: Default Field Splitting.
(line 6)
@@ -33306,7 +33302,7 @@ Index
* portability, NF variable, decrementing: Changing Fields. (line 115)
* portability, operators: Increment Ops. (line 60)
* portability, operators, not in POSIX awk: Precedence. (line 98)
-* portability, POSIXLY_CORRECT environment variable: Options. (line 357)
+* portability, POSIXLY_CORRECT environment variable: Options. (line 359)
* portability, substr() function: String Functions. (line 511)
* portable object files <1>: Translator i18n. (line 6)
* portable object files: Explaining gettext. (line 37)
@@ -33355,11 +33351,11 @@ Index
* POSIX awk, regular expressions and: Regexp Operators. (line 161)
* POSIX awk, timestamps and: Time Functions. (line 6)
* POSIX awk, | I/O operator and: Getline/Pipe. (line 55)
-* POSIX mode: Options. (line 252)
+* POSIX mode: Options. (line 254)
* POSIX, awk and: Preface. (line 21)
* POSIX, gawk extensions not included in: POSIX/GNU. (line 6)
* POSIX, programs, implementing in awk: Clones. (line 6)
-* POSIXLY_CORRECT environment variable: Options. (line 337)
+* POSIXLY_CORRECT environment variable: Options. (line 339)
* PREC variable: User-modified. (line 123)
* precedence <1>: Precedence. (line 6)
* precedence: Increment Ops. (line 60)
@@ -33413,7 +33409,7 @@ Index
* PROCINFO array, and group membership: Group Functions. (line 6)
* PROCINFO array, and user and group ID numbers: Id Program. (line 15)
* PROCINFO array, testing the field splitting: Passwd Functions.
- (line 161)
+ (line 154)
* PROCINFO array, uses: Auto-set. (line 249)
* PROCINFO, values of sorted_in: Controlling Scanning.
(line 26)
@@ -33422,7 +33418,7 @@ Index
* program identifiers: Auto-set. (line 155)
* program, definition of: Getting Started. (line 21)
* programming conventions, --non-decimal-data option: Nondecimal Data.
- (line 36)
+ (line 35)
* programming conventions, ARGC/ARGV variables: Auto-set. (line 35)
* programming conventions, exit statement: Exit Statement. (line 38)
* programming conventions, function parameters: Return Statement.
@@ -33538,7 +33534,7 @@ Index
(line 59)
* regular expressions, gawk, command-line options: GNU Regexp Operators.
(line 70)
-* regular expressions, interval expressions and: Options. (line 277)
+* regular expressions, interval expressions and: Options. (line 279)
* regular expressions, leftmost longest match: Leftmost Longest.
(line 6)
* regular expressions, operators <1>: Regexp Operators. (line 6)
@@ -33619,7 +33615,7 @@ Index
(line 68)
* sample debugging session: Sample Debugging Session.
(line 6)
-* sandbox mode: Options. (line 284)
+* sandbox mode: Options. (line 286)
* save debugger options: Debugger Info. (line 84)
* scalar or array: Type Functions. (line 11)
* scalar values: Basic Data Typing. (line 13)
@@ -33852,7 +33848,7 @@ Index
* strings, numeric: Variable Typing. (line 6)
* strtonum: String Functions. (line 389)
* strtonum() function (gawk), --non-decimal-data option and: Nondecimal Data.
- (line 36)
+ (line 35)
* sub <1>: String Functions. (line 407)
* sub: Using Constant Regexps.
(line 43)
@@ -34089,7 +34085,7 @@ Index
* whitespace, as field separators: Default Field Splitting.
(line 6)
* whitespace, functions, calling: Calling Built-in. (line 10)
-* whitespace, newlines as: Options. (line 258)
+* whitespace, newlines as: Options. (line 260)
* Williams, Kent: Contributors. (line 34)
* Woehlke, Matthew: Contributors. (line 79)
* Woods, John: Contributors. (line 27)
@@ -34181,515 +34177,517 @@ Node: Intro Summary110420
Node: Invoking Gawk111303
Node: Command Line112818
Node: Options113609
-Ref: Options-Footnote-1129307
-Node: Other Arguments129332
-Node: Naming Standard Input132293
-Node: Environment Variables133386
-Node: AWKPATH Variable133944
-Ref: AWKPATH Variable-Footnote-1136796
-Ref: AWKPATH Variable-Footnote-2136841
-Node: AWKLIBPATH Variable137101
-Node: Other Environment Variables137860
-Node: Exit Status141333
-Node: Include Files142008
-Node: Loading Shared Libraries145586
-Node: Obsolete147013
-Node: Undocumented147710
-Node: Invoking Summary147977
-Node: Regexp149643
-Node: Regexp Usage151102
-Node: Escape Sequences153135
-Node: Regexp Operators159235
-Ref: Regexp Operators-Footnote-1166670
-Ref: Regexp Operators-Footnote-2166817
-Node: Bracket Expressions166915
-Ref: table-char-classes168932
-Node: Leftmost Longest171872
-Node: Computed Regexps173174
-Node: GNU Regexp Operators176571
-Node: Case-sensitivity180277
-Ref: Case-sensitivity-Footnote-1183167
-Ref: Case-sensitivity-Footnote-2183402
-Node: Regexp Summary183510
-Node: Reading Files184979
-Node: Records187071
-Node: awk split records187799
-Node: gawk split records192711
-Ref: gawk split records-Footnote-1197250
-Node: Fields197287
-Ref: Fields-Footnote-1200083
-Node: Nonconstant Fields200169
-Ref: Nonconstant Fields-Footnote-1202399
-Node: Changing Fields202601
-Node: Field Separators208533
-Node: Default Field Splitting211235
-Node: Regexp Field Splitting212352
-Node: Single Character Fields215702
-Node: Command Line Field Separator216761
-Node: Full Line Fields219971
-Ref: Full Line Fields-Footnote-1220479
-Node: Field Splitting Summary220525
-Ref: Field Splitting Summary-Footnote-1223656
-Node: Constant Size223757
-Node: Splitting By Content228363
-Ref: Splitting By Content-Footnote-1232436
-Node: Multiple Line232476
-Ref: Multiple Line-Footnote-1238365
-Node: Getline238544
-Node: Plain Getline240755
-Node: Getline/Variable243395
-Node: Getline/File244542
-Node: Getline/Variable/File245926
-Ref: Getline/Variable/File-Footnote-1247525
-Node: Getline/Pipe247612
-Node: Getline/Variable/Pipe250295
-Node: Getline/Coprocess251424
-Node: Getline/Variable/Coprocess252676
-Node: Getline Notes253413
-Node: Getline Summary256205
-Ref: table-getline-variants256613
-Node: Read Timeout257442
-Ref: Read Timeout-Footnote-1261256
-Node: Command-line directories261314
-Node: Input Summary262218
-Node: Input Exercises265470
-Node: Printing266198
-Node: Print267975
-Node: Print Examples269432
-Node: Output Separators272211
-Node: OFMT274227
-Node: Printf275579
-Node: Basic Printf276364
-Node: Control Letters277935
-Node: Format Modifiers281919
-Node: Printf Examples287926
-Node: Redirection290408
-Node: Special FD297139
-Ref: Special FD-Footnote-1300296
-Node: Special Files300370
-Node: Other Inherited Files300986
-Node: Special Network301986
-Node: Special Caveats302847
-Node: Close Files And Pipes303798
-Ref: Close Files And Pipes-Footnote-1310975
-Ref: Close Files And Pipes-Footnote-2311123
-Node: Output Summary311273
-Node: Output Exercises312269
-Node: Expressions312949
-Node: Values314134
-Node: Constants314810
-Node: Scalar Constants315490
-Ref: Scalar Constants-Footnote-1316349
-Node: Nondecimal-numbers316599
-Node: Regexp Constants319599
-Node: Using Constant Regexps320124
-Node: Variables323262
-Node: Using Variables323917
-Node: Assignment Options325821
-Node: Conversion327696
-Node: Strings And Numbers328220
-Ref: Strings And Numbers-Footnote-1331282
-Node: Locale influences conversions331391
-Ref: table-locale-affects334106
-Node: All Operators334694
-Node: Arithmetic Ops335324
-Node: Concatenation337829
-Ref: Concatenation-Footnote-1340648
-Node: Assignment Ops340754
-Ref: table-assign-ops345737
-Node: Increment Ops347015
-Node: Truth Values and Conditions350453
-Node: Truth Values351536
-Node: Typing and Comparison352585
-Node: Variable Typing353378
-Node: Comparison Operators357030
-Ref: table-relational-ops357440
-Node: POSIX String Comparison360955
-Ref: POSIX String Comparison-Footnote-1362027
-Node: Boolean Ops362165
-Ref: Boolean Ops-Footnote-1366644
-Node: Conditional Exp366735
-Node: Function Calls368462
-Node: Precedence372342
-Node: Locales376010
-Node: Expressions Summary377641
-Node: Patterns and Actions380215
-Node: Pattern Overview381331
-Node: Regexp Patterns383010
-Node: Expression Patterns383553
-Node: Ranges387333
-Node: BEGIN/END390439
-Node: Using BEGIN/END391201
-Ref: Using BEGIN/END-Footnote-1393938
-Node: I/O And BEGIN/END394044
-Node: BEGINFILE/ENDFILE396358
-Node: Empty399259
-Node: Using Shell Variables399576
-Node: Action Overview401852
-Node: Statements404179
-Node: If Statement406027
-Node: While Statement407525
-Node: Do Statement409553
-Node: For Statement410695
-Node: Switch Statement413850
-Node: Break Statement416238
-Node: Continue Statement418279
-Node: Next Statement420104
-Node: Nextfile Statement422484
-Node: Exit Statement425114
-Node: Built-in Variables427517
-Node: User-modified428644
-Ref: User-modified-Footnote-1436324
-Node: Auto-set436386
-Ref: Auto-set-Footnote-1449580
-Ref: Auto-set-Footnote-2449785
-Node: ARGC and ARGV449841
-Node: Pattern Action Summary454045
-Node: Arrays456464
-Node: Array Basics457793
-Node: Array Intro458637
-Ref: figure-array-elements460610
-Ref: Array Intro-Footnote-1463134
-Node: Reference to Elements463262
-Node: Assigning Elements465712
-Node: Array Example466203
-Node: Scanning an Array467961
-Node: Controlling Scanning470977
-Ref: Controlling Scanning-Footnote-1476166
-Node: Numeric Array Subscripts476482
-Node: Uninitialized Subscripts478665
-Node: Delete480282
-Ref: Delete-Footnote-1483026
-Node: Multidimensional483083
-Node: Multiscanning486178
-Node: Arrays of Arrays487767
-Node: Arrays Summary492528
-Node: Functions494633
-Node: Built-in495506
-Node: Calling Built-in496584
-Node: Numeric Functions498572
-Ref: Numeric Functions-Footnote-1503396
-Ref: Numeric Functions-Footnote-2503753
-Ref: Numeric Functions-Footnote-3503801
-Node: String Functions504070
-Ref: String Functions-Footnote-1527530
-Ref: String Functions-Footnote-2527659
-Ref: String Functions-Footnote-3527907
-Node: Gory Details527994
-Ref: table-sub-escapes529775
-Ref: table-sub-proposed531295
-Ref: table-posix-sub532659
-Ref: table-gensub-escapes534199
-Ref: Gory Details-Footnote-1535031
-Node: I/O Functions535182
-Ref: I/O Functions-Footnote-1542283
-Node: Time Functions542430
-Ref: Time Functions-Footnote-1552899
-Ref: Time Functions-Footnote-2552967
-Ref: Time Functions-Footnote-3553125
-Ref: Time Functions-Footnote-4553236
-Ref: Time Functions-Footnote-5553348
-Ref: Time Functions-Footnote-6553575
-Node: Bitwise Functions553841
-Ref: table-bitwise-ops554403
-Ref: Bitwise Functions-Footnote-1558711
-Node: Type Functions558880
-Node: I18N Functions560029
-Node: User-defined561674
-Node: Definition Syntax562478
-Ref: Definition Syntax-Footnote-1567882
-Node: Function Example567951
-Ref: Function Example-Footnote-1570868
-Node: Function Caveats570890
-Node: Calling A Function571408
-Node: Variable Scope572363
-Node: Pass By Value/Reference575351
-Node: Return Statement578861
-Node: Dynamic Typing581845
-Node: Indirect Calls582774
-Ref: Indirect Calls-Footnote-1592495
-Node: Functions Summary592623
-Node: Library Functions595322
-Ref: Library Functions-Footnote-1598940
-Ref: Library Functions-Footnote-2599083
-Node: Library Names599254
-Ref: Library Names-Footnote-1602712
-Ref: Library Names-Footnote-2602932
-Node: General Functions603018
-Node: Strtonum Function604046
-Node: Assert Function607066
-Node: Round Function610390
-Node: Cliff Random Function611931
-Node: Ordinal Functions612947
-Ref: Ordinal Functions-Footnote-1616012
-Ref: Ordinal Functions-Footnote-2616264
-Node: Join Function616475
-Ref: Join Function-Footnote-1618246
-Node: Getlocaltime Function618446
-Node: Readfile Function622187
-Node: Data File Management624135
-Node: Filetrans Function624767
-Node: Rewind Function628826
-Node: File Checking630384
-Ref: File Checking-Footnote-1631516
-Node: Empty Files631717
-Node: Ignoring Assigns633696
-Node: Getopt Function635250
-Ref: Getopt Function-Footnote-1646514
-Node: Passwd Functions646717
-Ref: Passwd Functions-Footnote-1655696
-Node: Group Functions655784
-Ref: Group Functions-Footnote-1663715
-Node: Walking Arrays663928
-Node: Library Functions Summary665531
-Node: Library Exercises666919
-Node: Sample Programs668199
-Node: Running Examples668969
-Node: Clones669697
-Node: Cut Program670921
-Node: Egrep Program680779
-Ref: Egrep Program-Footnote-1688366
-Node: Id Program688476
-Node: Split Program692130
-Ref: Split Program-Footnote-1695668
-Node: Tee Program695796
-Node: Uniq Program698583
-Node: Wc Program706006
-Ref: Wc Program-Footnote-1710271
-Node: Miscellaneous Programs710363
-Node: Dupword Program711576
-Node: Alarm Program713607
-Node: Translate Program718411
-Ref: Translate Program-Footnote-1722984
-Ref: Translate Program-Footnote-2723254
-Node: Labels Program723393
-Ref: Labels Program-Footnote-1726754
-Node: Word Sorting726838
-Node: History Sorting730881
-Node: Extract Program732717
-Node: Simple Sed740253
-Node: Igawk Program743315
-Ref: Igawk Program-Footnote-1757619
-Ref: Igawk Program-Footnote-2757820
-Node: Anagram Program757942
-Node: Signature Program761010
-Node: Programs Summary762257
-Node: Programs Exercises763472
-Ref: Programs Exercises-Footnote-1767603
-Node: Advanced Features767694
-Node: Nondecimal Data769642
-Node: Array Sorting771219
-Node: Controlling Array Traversal771916
-Node: Array Sorting Functions780196
-Ref: Array Sorting Functions-Footnote-1784088
-Node: Two-way I/O784282
-Ref: Two-way I/O-Footnote-1789226
-Ref: Two-way I/O-Footnote-2789405
-Node: TCP/IP Networking789487
-Node: Profiling792329
-Node: Advanced Features Summary799880
-Node: Internationalization801741
-Node: I18N and L10N803221
-Node: Explaining gettext803907
-Ref: Explaining gettext-Footnote-1808933
-Ref: Explaining gettext-Footnote-2809117
-Node: Programmer i18n809282
-Ref: Programmer i18n-Footnote-1814076
-Node: Translator i18n814125
-Node: String Extraction814919
-Ref: String Extraction-Footnote-1816052
-Node: Printf Ordering816138
-Ref: Printf Ordering-Footnote-1818920
-Node: I18N Portability818984
-Ref: I18N Portability-Footnote-1821433
-Node: I18N Example821496
-Ref: I18N Example-Footnote-1824202
-Node: Gawk I18N824274
-Node: I18N Summary824912
-Node: Debugger826251
-Node: Debugging827273
-Node: Debugging Concepts827714
-Node: Debugging Terms829570
-Node: Awk Debugging832167
-Node: Sample Debugging Session833059
-Node: Debugger Invocation833579
-Node: Finding The Bug834915
-Node: List of Debugger Commands841394
-Node: Breakpoint Control842726
-Node: Debugger Execution Control846390
-Node: Viewing And Changing Data849750
-Node: Execution Stack853108
-Node: Debugger Info854621
-Node: Miscellaneous Debugger Commands858615
-Node: Readline Support863799
-Node: Limitations864691
-Node: Debugging Summary866964
-Node: Arbitrary Precision Arithmetic868132
-Node: Computer Arithmetic869619
-Ref: Computer Arithmetic-Footnote-1874006
-Node: Math Definitions874063
-Ref: table-ieee-formats877352
-Ref: Math Definitions-Footnote-1877892
-Node: MPFR features877995
-Node: FP Math Caution879612
-Ref: FP Math Caution-Footnote-1880662
-Node: Inexactness of computations881031
-Node: Inexact representation881979
-Node: Comparing FP Values883334
-Node: Errors accumulate884298
-Node: Getting Accuracy885731
-Node: Try To Round888390
-Node: Setting precision889289
-Ref: table-predefined-precision-strings889971
-Node: Setting the rounding mode891764
-Ref: table-gawk-rounding-modes892128
-Ref: Setting the rounding mode-Footnote-1895582
-Node: Arbitrary Precision Integers895761
-Ref: Arbitrary Precision Integers-Footnote-1899534
-Node: POSIX Floating Point Problems899683
-Ref: POSIX Floating Point Problems-Footnote-1903559
-Node: Floating point summary903597
-Node: Dynamic Extensions905801
-Node: Extension Intro907353
-Node: Plugin License908618
-Node: Extension Mechanism Outline909303
-Ref: figure-load-extension909727
-Ref: figure-load-new-function911212
-Ref: figure-call-new-function912214
-Node: Extension API Description914198
-Node: Extension API Functions Introduction915648
-Node: General Data Types920515
-Ref: General Data Types-Footnote-1926208
-Node: Requesting Values926507
-Ref: table-value-types-returned927244
-Node: Memory Allocation Functions928202
-Ref: Memory Allocation Functions-Footnote-1930949
-Node: Constructor Functions931045
-Node: Registration Functions932803
-Node: Extension Functions933488
-Node: Exit Callback Functions935790
-Node: Extension Version String937038
-Node: Input Parsers937688
-Node: Output Wrappers947502
-Node: Two-way processors952018
-Node: Printing Messages954222
-Ref: Printing Messages-Footnote-1955299
-Node: Updating `ERRNO'955451
-Node: Accessing Parameters956190
-Node: Symbol Table Access957420
-Node: Symbol table by name957934
-Node: Symbol table by cookie959910
-Ref: Symbol table by cookie-Footnote-1964043
-Node: Cached values964106
-Ref: Cached values-Footnote-1967610
-Node: Array Manipulation967701
-Ref: Array Manipulation-Footnote-1968799
-Node: Array Data Types968838
-Ref: Array Data Types-Footnote-1971541
-Node: Array Functions971633
-Node: Flattening Arrays975507
-Node: Creating Arrays982359
-Node: Extension API Variables987090
-Node: Extension Versioning987726
-Node: Extension API Informational Variables989627
-Node: Extension API Boilerplate990713
-Node: Finding Extensions994517
-Node: Extension Example995077
-Node: Internal File Description995807
-Node: Internal File Ops999898
-Ref: Internal File Ops-Footnote-11011330
-Node: Using Internal File Ops1011470
-Ref: Using Internal File Ops-Footnote-11013817
-Node: Extension Samples1014085
-Node: Extension Sample File Functions1015609
-Node: Extension Sample Fnmatch1023177
-Node: Extension Sample Fork1024659
-Node: Extension Sample Inplace1025872
-Node: Extension Sample Ord1027547
-Node: Extension Sample Readdir1028383
-Ref: table-readdir-file-types1029239
-Node: Extension Sample Revout1030038
-Node: Extension Sample Rev2way1030629
-Node: Extension Sample Read write array1031370
-Node: Extension Sample Readfile1033249
-Node: Extension Sample API Tests1034349
-Node: Extension Sample Time1034874
-Node: gawkextlib1036189
-Node: Extension summary1039002
-Node: Extension Exercises1042695
-Node: Language History1043417
-Node: V7/SVR3.11045060
-Node: SVR41047380
-Node: POSIX1048822
-Node: BTL1050208
-Node: POSIX/GNU1050942
-Node: Feature History1056718
-Node: Common Extensions1069809
-Node: Ranges and Locales1071121
-Ref: Ranges and Locales-Footnote-11075738
-Ref: Ranges and Locales-Footnote-21075765
-Ref: Ranges and Locales-Footnote-31075999
-Node: Contributors1076220
-Node: History summary1081645
-Node: Installation1083014
-Node: Gawk Distribution1083965
-Node: Getting1084449
-Node: Extracting1085273
-Node: Distribution contents1086915
-Node: Unix Installation1092685
-Node: Quick Installation1093302
-Node: Additional Configuration Options1095744
-Node: Configuration Philosophy1097482
-Node: Non-Unix Installation1099833
-Node: PC Installation1100291
-Node: PC Binary Installation1101602
-Node: PC Compiling1103450
-Ref: PC Compiling-Footnote-11106449
-Node: PC Testing1106554
-Node: PC Using1107730
-Node: Cygwin1111882
-Node: MSYS1112691
-Node: VMS Installation1113189
-Node: VMS Compilation1113985
-Ref: VMS Compilation-Footnote-11115207
-Node: VMS Dynamic Extensions1115265
-Node: VMS Installation Details1116638
-Node: VMS Running1118890
-Node: VMS GNV1121724
-Node: VMS Old Gawk1122447
-Node: Bugs1122917
-Node: Other Versions1126921
-Node: Installation summary1133145
-Node: Notes1134201
-Node: Compatibility Mode1135066
-Node: Additions1135848
-Node: Accessing The Source1136773
-Node: Adding Code1138209
-Node: New Ports1144387
-Node: Derived Files1148868
-Ref: Derived Files-Footnote-11154343
-Ref: Derived Files-Footnote-21154377
-Ref: Derived Files-Footnote-31154973
-Node: Future Extensions1155087
-Node: Implementation Limitations1155693
-Node: Extension Design1156941
-Node: Old Extension Problems1158095
-Ref: Old Extension Problems-Footnote-11159612
-Node: Extension New Mechanism Goals1159669
-Ref: Extension New Mechanism Goals-Footnote-11163029
-Node: Extension Other Design Decisions1163218
-Node: Extension Future Growth1165324
-Node: Old Extension Mechanism1166160
-Node: Notes summary1167922
-Node: Basic Concepts1169108
-Node: Basic High Level1169789
-Ref: figure-general-flow1170061
-Ref: figure-process-flow1170660
-Ref: Basic High Level-Footnote-11173889
-Node: Basic Data Typing1174074
-Node: Glossary1177402
-Node: Copying1202554
-Node: GNU Free Documentation License1240110
-Node: Index1265246
+Ref: Options-Footnote-1129375
+Node: Other Arguments129400
+Node: Naming Standard Input132361
+Node: Environment Variables133454
+Node: AWKPATH Variable134012
+Ref: AWKPATH Variable-Footnote-1136864
+Ref: AWKPATH Variable-Footnote-2136909
+Node: AWKLIBPATH Variable137169
+Node: Other Environment Variables137928
+Node: Exit Status141401
+Node: Include Files142076
+Node: Loading Shared Libraries145654
+Node: Obsolete147081
+Node: Undocumented147778
+Node: Invoking Summary148045
+Node: Regexp149711
+Node: Regexp Usage151170
+Node: Escape Sequences153203
+Node: Regexp Operators159303
+Ref: Regexp Operators-Footnote-1166738
+Ref: Regexp Operators-Footnote-2166885
+Node: Bracket Expressions166983
+Ref: table-char-classes169000
+Node: Leftmost Longest171940
+Node: Computed Regexps173242
+Node: GNU Regexp Operators176639
+Node: Case-sensitivity180345
+Ref: Case-sensitivity-Footnote-1183235
+Ref: Case-sensitivity-Footnote-2183470
+Node: Regexp Summary183578
+Node: Reading Files185047
+Node: Records187139
+Node: awk split records187867
+Node: gawk split records192779
+Ref: gawk split records-Footnote-1197318
+Node: Fields197355
+Ref: Fields-Footnote-1200151
+Node: Nonconstant Fields200237
+Ref: Nonconstant Fields-Footnote-1202467
+Node: Changing Fields202669
+Node: Field Separators208601
+Node: Default Field Splitting211303
+Node: Regexp Field Splitting212420
+Node: Single Character Fields215770
+Node: Command Line Field Separator216829
+Node: Full Line Fields220039
+Ref: Full Line Fields-Footnote-1220547
+Node: Field Splitting Summary220593
+Ref: Field Splitting Summary-Footnote-1223724
+Node: Constant Size223825
+Node: Splitting By Content228431
+Ref: Splitting By Content-Footnote-1232504
+Node: Multiple Line232544
+Ref: Multiple Line-Footnote-1238433
+Node: Getline238612
+Node: Plain Getline240823
+Node: Getline/Variable243463
+Node: Getline/File244610
+Node: Getline/Variable/File245994
+Ref: Getline/Variable/File-Footnote-1247593
+Node: Getline/Pipe247680
+Node: Getline/Variable/Pipe250363
+Node: Getline/Coprocess251492
+Node: Getline/Variable/Coprocess252744
+Node: Getline Notes253481
+Node: Getline Summary256273
+Ref: table-getline-variants256681
+Node: Read Timeout257510
+Ref: Read Timeout-Footnote-1261324
+Node: Command-line directories261382
+Node: Input Summary262286
+Node: Input Exercises265538
+Node: Printing266266
+Node: Print268043
+Node: Print Examples269500
+Node: Output Separators272279
+Node: OFMT274295
+Node: Printf275647
+Node: Basic Printf276432
+Node: Control Letters278003
+Node: Format Modifiers281987
+Node: Printf Examples287994
+Node: Redirection290476
+Node: Special FD297207
+Ref: Special FD-Footnote-1300364
+Node: Special Files300438
+Node: Other Inherited Files301054
+Node: Special Network302054
+Node: Special Caveats302915
+Node: Close Files And Pipes303866
+Ref: Close Files And Pipes-Footnote-1311043
+Ref: Close Files And Pipes-Footnote-2311191
+Node: Output Summary311341
+Node: Output Exercises312337
+Node: Expressions313017
+Node: Values314202
+Node: Constants314878
+Node: Scalar Constants315558
+Ref: Scalar Constants-Footnote-1316417
+Node: Nondecimal-numbers316667
+Node: Regexp Constants319667
+Node: Using Constant Regexps320192
+Node: Variables323330
+Node: Using Variables323985
+Node: Assignment Options325889
+Node: Conversion327764
+Node: Strings And Numbers328288
+Ref: Strings And Numbers-Footnote-1331350
+Node: Locale influences conversions331459
+Ref: table-locale-affects334174
+Node: All Operators334762
+Node: Arithmetic Ops335392
+Node: Concatenation337897
+Ref: Concatenation-Footnote-1340716
+Node: Assignment Ops340822
+Ref: table-assign-ops345805
+Node: Increment Ops347083
+Node: Truth Values and Conditions350521
+Node: Truth Values351604
+Node: Typing and Comparison352653
+Node: Variable Typing353446
+Node: Comparison Operators357098
+Ref: table-relational-ops357508
+Node: POSIX String Comparison361023
+Ref: POSIX String Comparison-Footnote-1362095
+Node: Boolean Ops362233
+Ref: Boolean Ops-Footnote-1366712
+Node: Conditional Exp366803
+Node: Function Calls368530
+Node: Precedence372410
+Node: Locales376078
+Node: Expressions Summary377709
+Node: Patterns and Actions380283
+Node: Pattern Overview381399
+Node: Regexp Patterns383078
+Node: Expression Patterns383621
+Node: Ranges387401
+Node: BEGIN/END390507
+Node: Using BEGIN/END391269
+Ref: Using BEGIN/END-Footnote-1394006
+Node: I/O And BEGIN/END394112
+Node: BEGINFILE/ENDFILE396426
+Node: Empty399327
+Node: Using Shell Variables399644
+Node: Action Overview401920
+Node: Statements404247
+Node: If Statement406095
+Node: While Statement407593
+Node: Do Statement409621
+Node: For Statement410763
+Node: Switch Statement413918
+Node: Break Statement416306
+Node: Continue Statement418347
+Node: Next Statement420172
+Node: Nextfile Statement422552
+Node: Exit Statement425182
+Node: Built-in Variables427585
+Node: User-modified428712
+Ref: User-modified-Footnote-1436392
+Node: Auto-set436454
+Ref: Auto-set-Footnote-1449648
+Ref: Auto-set-Footnote-2449853
+Node: ARGC and ARGV449909
+Node: Pattern Action Summary454113
+Node: Arrays456532
+Node: Array Basics457861
+Node: Array Intro458705
+Ref: figure-array-elements460678
+Ref: Array Intro-Footnote-1463202
+Node: Reference to Elements463330
+Node: Assigning Elements465780
+Node: Array Example466271
+Node: Scanning an Array468029
+Node: Controlling Scanning471045
+Ref: Controlling Scanning-Footnote-1476234
+Node: Numeric Array Subscripts476550
+Node: Uninitialized Subscripts478733
+Node: Delete480350
+Ref: Delete-Footnote-1483094
+Node: Multidimensional483151
+Node: Multiscanning486246
+Node: Arrays of Arrays487835
+Node: Arrays Summary492596
+Node: Functions494701
+Node: Built-in495574
+Node: Calling Built-in496652
+Node: Numeric Functions498640
+Ref: Numeric Functions-Footnote-1503464
+Ref: Numeric Functions-Footnote-2503821
+Ref: Numeric Functions-Footnote-3503869
+Node: String Functions504138
+Ref: String Functions-Footnote-1527598
+Ref: String Functions-Footnote-2527727
+Ref: String Functions-Footnote-3527975
+Node: Gory Details528062
+Ref: table-sub-escapes529843
+Ref: table-sub-proposed531363
+Ref: table-posix-sub532727
+Ref: table-gensub-escapes534267
+Ref: Gory Details-Footnote-1535099
+Node: I/O Functions535250
+Ref: I/O Functions-Footnote-1542351
+Node: Time Functions542498
+Ref: Time Functions-Footnote-1552967
+Ref: Time Functions-Footnote-2553035
+Ref: Time Functions-Footnote-3553193
+Ref: Time Functions-Footnote-4553304
+Ref: Time Functions-Footnote-5553416
+Ref: Time Functions-Footnote-6553643
+Node: Bitwise Functions553909
+Ref: table-bitwise-ops554471
+Ref: Bitwise Functions-Footnote-1558779
+Node: Type Functions558948
+Node: I18N Functions560097
+Node: User-defined561742
+Node: Definition Syntax562546
+Ref: Definition Syntax-Footnote-1567950
+Node: Function Example568019
+Ref: Function Example-Footnote-1570936
+Node: Function Caveats570958
+Node: Calling A Function571476
+Node: Variable Scope572431
+Node: Pass By Value/Reference575419
+Node: Return Statement578929
+Node: Dynamic Typing581913
+Node: Indirect Calls582842
+Ref: Indirect Calls-Footnote-1592563
+Node: Functions Summary592691
+Node: Library Functions595390
+Ref: Library Functions-Footnote-1599008
+Ref: Library Functions-Footnote-2599151
+Node: Library Names599322
+Ref: Library Names-Footnote-1602780
+Ref: Library Names-Footnote-2603000
+Node: General Functions603086
+Node: Strtonum Function604114
+Node: Assert Function607134
+Node: Round Function610458
+Node: Cliff Random Function611999
+Node: Ordinal Functions613015
+Ref: Ordinal Functions-Footnote-1616080
+Ref: Ordinal Functions-Footnote-2616332
+Node: Join Function616543
+Ref: Join Function-Footnote-1618314
+Node: Getlocaltime Function618514
+Node: Readfile Function622255
+Node: Data File Management624203
+Node: Filetrans Function624835
+Node: Rewind Function628894
+Node: File Checking630279
+Ref: File Checking-Footnote-1631607
+Node: Empty Files631808
+Node: Ignoring Assigns633787
+Node: Getopt Function635338
+Ref: Getopt Function-Footnote-1646798
+Node: Passwd Functions647001
+Ref: Passwd Functions-Footnote-1655852
+Node: Group Functions655940
+Ref: Group Functions-Footnote-1663843
+Node: Walking Arrays664056
+Node: Library Functions Summary665659
+Node: Library Exercises667060
+Node: Sample Programs668340
+Node: Running Examples669110
+Node: Clones669838
+Node: Cut Program671062
+Node: Egrep Program680792
+Ref: Egrep Program-Footnote-1688294
+Node: Id Program688404
+Node: Split Program692048
+Ref: Split Program-Footnote-1695494
+Node: Tee Program695622
+Node: Uniq Program698409
+Node: Wc Program705830
+Ref: Wc Program-Footnote-1710078
+Node: Miscellaneous Programs710170
+Node: Dupword Program711383
+Node: Alarm Program713414
+Node: Translate Program718218
+Ref: Translate Program-Footnote-1722791
+Ref: Translate Program-Footnote-2723061
+Node: Labels Program723200
+Ref: Labels Program-Footnote-1726549
+Node: Word Sorting726633
+Node: History Sorting730703
+Node: Extract Program732539
+Node: Simple Sed740071
+Node: Igawk Program743133
+Ref: Igawk Program-Footnote-1757459
+Ref: Igawk Program-Footnote-2757660
+Ref: Igawk Program-Footnote-3757782
+Node: Anagram Program757897
+Node: Signature Program760959
+Node: Programs Summary762206
+Node: Programs Exercises763399
+Ref: Programs Exercises-Footnote-1767530
+Node: Advanced Features767621
+Node: Nondecimal Data769569
+Node: Array Sorting771159
+Node: Controlling Array Traversal771856
+Ref: Controlling Array Traversal-Footnote-1780187
+Node: Array Sorting Functions780305
+Ref: Array Sorting Functions-Footnote-1784197
+Node: Two-way I/O784391
+Ref: Two-way I/O-Footnote-1789335
+Ref: Two-way I/O-Footnote-2789521
+Node: TCP/IP Networking789603
+Node: Profiling792444
+Node: Advanced Features Summary799995
+Node: Internationalization801856
+Node: I18N and L10N803336
+Node: Explaining gettext804022
+Ref: Explaining gettext-Footnote-1809048
+Ref: Explaining gettext-Footnote-2809232
+Node: Programmer i18n809397
+Ref: Programmer i18n-Footnote-1814191
+Node: Translator i18n814240
+Node: String Extraction815034
+Ref: String Extraction-Footnote-1816167
+Node: Printf Ordering816253
+Ref: Printf Ordering-Footnote-1819035
+Node: I18N Portability819099
+Ref: I18N Portability-Footnote-1821548
+Node: I18N Example821611
+Ref: I18N Example-Footnote-1824317
+Node: Gawk I18N824389
+Node: I18N Summary825027
+Node: Debugger826366
+Node: Debugging827388
+Node: Debugging Concepts827829
+Node: Debugging Terms829685
+Node: Awk Debugging832282
+Node: Sample Debugging Session833174
+Node: Debugger Invocation833694
+Node: Finding The Bug835030
+Node: List of Debugger Commands841509
+Node: Breakpoint Control842841
+Node: Debugger Execution Control846505
+Node: Viewing And Changing Data849865
+Node: Execution Stack853223
+Node: Debugger Info854736
+Node: Miscellaneous Debugger Commands858730
+Node: Readline Support863914
+Node: Limitations864806
+Node: Debugging Summary867079
+Node: Arbitrary Precision Arithmetic868247
+Node: Computer Arithmetic869734
+Ref: Computer Arithmetic-Footnote-1874121
+Node: Math Definitions874178
+Ref: table-ieee-formats877467
+Ref: Math Definitions-Footnote-1878007
+Node: MPFR features878110
+Node: FP Math Caution879727
+Ref: FP Math Caution-Footnote-1880777
+Node: Inexactness of computations881146
+Node: Inexact representation882094
+Node: Comparing FP Values883449
+Node: Errors accumulate884413
+Node: Getting Accuracy885846
+Node: Try To Round888505
+Node: Setting precision889404
+Ref: table-predefined-precision-strings890086
+Node: Setting the rounding mode891879
+Ref: table-gawk-rounding-modes892243
+Ref: Setting the rounding mode-Footnote-1895697
+Node: Arbitrary Precision Integers895876
+Ref: Arbitrary Precision Integers-Footnote-1899649
+Node: POSIX Floating Point Problems899798
+Ref: POSIX Floating Point Problems-Footnote-1903674
+Node: Floating point summary903712
+Node: Dynamic Extensions905916
+Node: Extension Intro907468
+Node: Plugin License908733
+Node: Extension Mechanism Outline909418
+Ref: figure-load-extension909842
+Ref: figure-load-new-function911327
+Ref: figure-call-new-function912329
+Node: Extension API Description914313
+Node: Extension API Functions Introduction915763
+Node: General Data Types920630
+Ref: General Data Types-Footnote-1926323
+Node: Requesting Values926622
+Ref: table-value-types-returned927359
+Node: Memory Allocation Functions928317
+Ref: Memory Allocation Functions-Footnote-1931064
+Node: Constructor Functions931160
+Node: Registration Functions932918
+Node: Extension Functions933603
+Node: Exit Callback Functions935905
+Node: Extension Version String937153
+Node: Input Parsers937803
+Node: Output Wrappers947617
+Node: Two-way processors952133
+Node: Printing Messages954337
+Ref: Printing Messages-Footnote-1955414
+Node: Updating `ERRNO'955566
+Node: Accessing Parameters956305
+Node: Symbol Table Access957535
+Node: Symbol table by name958049
+Node: Symbol table by cookie960025
+Ref: Symbol table by cookie-Footnote-1964158
+Node: Cached values964221
+Ref: Cached values-Footnote-1967725
+Node: Array Manipulation967816
+Ref: Array Manipulation-Footnote-1968914
+Node: Array Data Types968953
+Ref: Array Data Types-Footnote-1971656
+Node: Array Functions971748
+Node: Flattening Arrays975622
+Node: Creating Arrays982474
+Node: Extension API Variables987205
+Node: Extension Versioning987841
+Node: Extension API Informational Variables989742
+Node: Extension API Boilerplate990828
+Node: Finding Extensions994632
+Node: Extension Example995192
+Node: Internal File Description995922
+Node: Internal File Ops1000013
+Ref: Internal File Ops-Footnote-11011445
+Node: Using Internal File Ops1011585
+Ref: Using Internal File Ops-Footnote-11013932
+Node: Extension Samples1014200
+Node: Extension Sample File Functions1015724
+Node: Extension Sample Fnmatch1023292
+Node: Extension Sample Fork1024774
+Node: Extension Sample Inplace1025987
+Node: Extension Sample Ord1027662
+Node: Extension Sample Readdir1028498
+Ref: table-readdir-file-types1029354
+Node: Extension Sample Revout1030153
+Node: Extension Sample Rev2way1030744
+Node: Extension Sample Read write array1031485
+Node: Extension Sample Readfile1033364
+Node: Extension Sample API Tests1034464
+Node: Extension Sample Time1034989
+Node: gawkextlib1036304
+Node: Extension summary1039117
+Node: Extension Exercises1042810
+Node: Language History1043532
+Node: V7/SVR3.11045175
+Node: SVR41047495
+Node: POSIX1048937
+Node: BTL1050323
+Node: POSIX/GNU1051057
+Node: Feature History1056833
+Node: Common Extensions1069924
+Node: Ranges and Locales1071236
+Ref: Ranges and Locales-Footnote-11075853
+Ref: Ranges and Locales-Footnote-21075880
+Ref: Ranges and Locales-Footnote-31076114
+Node: Contributors1076335
+Node: History summary1081760
+Node: Installation1083129
+Node: Gawk Distribution1084080
+Node: Getting1084564
+Node: Extracting1085388
+Node: Distribution contents1087030
+Node: Unix Installation1092800
+Node: Quick Installation1093417
+Node: Additional Configuration Options1095859
+Node: Configuration Philosophy1097597
+Node: Non-Unix Installation1099948
+Node: PC Installation1100406
+Node: PC Binary Installation1101717
+Node: PC Compiling1103565
+Ref: PC Compiling-Footnote-11106564
+Node: PC Testing1106669
+Node: PC Using1107845
+Node: Cygwin1111997
+Node: MSYS1112806
+Node: VMS Installation1113304
+Node: VMS Compilation1114100
+Ref: VMS Compilation-Footnote-11115322
+Node: VMS Dynamic Extensions1115380
+Node: VMS Installation Details1116753
+Node: VMS Running1119005
+Node: VMS GNV1121839
+Node: VMS Old Gawk1122562
+Node: Bugs1123032
+Node: Other Versions1127036
+Node: Installation summary1133260
+Node: Notes1134316
+Node: Compatibility Mode1135181
+Node: Additions1135963
+Node: Accessing The Source1136888
+Node: Adding Code1138324
+Node: New Ports1144502
+Node: Derived Files1148983
+Ref: Derived Files-Footnote-11154458
+Ref: Derived Files-Footnote-21154492
+Ref: Derived Files-Footnote-31155088
+Node: Future Extensions1155202
+Node: Implementation Limitations1155808
+Node: Extension Design1157056
+Node: Old Extension Problems1158210
+Ref: Old Extension Problems-Footnote-11159727
+Node: Extension New Mechanism Goals1159784
+Ref: Extension New Mechanism Goals-Footnote-11163144
+Node: Extension Other Design Decisions1163333
+Node: Extension Future Growth1165439
+Node: Old Extension Mechanism1166275
+Node: Notes summary1168037
+Node: Basic Concepts1169223
+Node: Basic High Level1169904
+Ref: figure-general-flow1170176
+Ref: figure-process-flow1170775
+Ref: Basic High Level-Footnote-11174004
+Node: Basic Data Typing1174189
+Node: Glossary1177517
+Node: Copying1202669
+Node: GNU Free Documentation License1240225
+Node: Index1265361

End Tag Table
diff --git a/doc/gawk.texi b/doc/gawk.texi
index b3077fa5..2e7efca5 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -3914,6 +3914,8 @@ values in input data
@quotation CAUTION
This option can severely break old programs.
Use with care.
+
+This option may disappear in a future version of @command{gawk}.
@end quotation
@item @option{-N}
@@ -21499,24 +21501,12 @@ function rewind( i)
@c endfile
@end example
-This code relies on the @code{ARGIND} variable
-(@pxref{Auto-set}),
-which is specific to @command{gawk}.
-If you are not using
-@command{gawk}, you can use ideas presented in
-@ifnotinfo
-the previous @value{SECTION}
-@end ifnotinfo
-@ifinfo
-@ref{Filetrans Function},
-@end ifinfo
-to either update @code{ARGIND} on your own
-or modify this code as appropriate.
-
-The @code{rewind()} function also relies on the @code{nextfile} keyword
-(@pxref{Nextfile Statement}). Because of this, you should not call it
-from an @code{ENDFILE} rule. (This isn't necessary anyway, since as soon
-as an @code{ENDFILE} rule finishes @command{gawk} goes to the next file!)
+The @code{rewind()} function relies on the @code{ARGIND} variable
+(@pxref{Auto-set}), which is specific to @command{gawk}. It also
+relies on the @code{nextfile} keyword (@pxref{Nextfile Statement}).
+Because of this, you should not call it from an @code{ENDFILE} rule.
+(This isn't necessary anyway, since as soon as an @code{ENDFILE} rule
+finishes @command{gawk} goes to the next file!)
@node File Checking
@subsection Checking for Readable @value{DDF}s
@@ -21549,7 +21539,7 @@ the following program to your @command{awk} program:
BEGIN @{
for (i = 1; i < ARGC; i++) @{
- if (ARGV[i] ~ /^[[:alpha:]_][[:alnum:]_]*=.*/ \
+ if (ARGV[i] ~ /^[a-zA-Z_][a-zA-Z0-9_]*=.*/ \
|| ARGV[i] == "-" || ARGV[i] == "/dev/stdin")
continue # assignment or standard input
else if ((getline junk < ARGV[i]) < 0) # unreadable
@@ -21567,6 +21557,11 @@ Removing the element from @code{ARGV} with @code{delete}
skips the file (since it's no longer in the list).
See also @ref{ARGC and ARGV}.
+The regular expression check purposely does not use character classes
+such as @samp{[:alpha:]} and @samp{[:alnum:]}
+(@pxref{Bracket Expressions})
+since @command{awk} variable names only allow the English letters.
+
@node Empty Files
@subsection Checking for Zero-length Files
@@ -21663,7 +21658,7 @@ a library file does the trick:
function disable_assigns(argc, argv, i)
@{
for (i = 1; i < argc; i++)
- if (argv[i] ~ /^[[:alpha:]_][[:alnum:]_]*=.*/)
+ if (argv[i] ~ /^[a-zA-Z_][a-zA-Z0-9_]*=.*/)
argv[i] = ("./" argv[i])
@}
@@ -22035,12 +22030,18 @@ In both runs, the first @option{--} terminates the arguments to
etc., as its own options.
@quotation NOTE
-After @code{getopt()} is through, it is the responsibility of the
-user level code to clear out all the elements of @code{ARGV} from 1
+After @code{getopt()} is through,
+user level code must clear out all the elements of @code{ARGV} from 1
to @code{Optind}, so that @command{awk} does not try to process the
command-line options as @value{FN}s.
@end quotation
+Using @samp{#!} with the @option{-E} option may help avoid
+conflicts between your program's options and @command{gawk}'s options,
+since @option{-E} causes @command{gawk} to abandon processing of
+further options
+(@pxref{Executable Scripts}, and @pxref{Options}).
+
Several of the sample programs presented in
@ref{Sample Programs},
use @code{getopt()} to process their arguments.
@@ -22285,13 +22286,14 @@ The @code{BEGIN} rule sets a private variable to the directory where
routine, we have chosen to put it in @file{/usr/local/libexec/awk};
however, you might want it to be in a different directory on your system.
-The function @code{_pw_init()} keeps three copies of the user information
-in three associative arrays. The arrays are indexed by username
+The function @code{_pw_init()} fills three copies of the user information
+into three associative arrays. The arrays are indexed by username
(@code{_pw_byname}), by user ID number (@code{_pw_byuid}), and by order of
occurrence (@code{_pw_bycount}).
The variable @code{_pw_inited} is used for efficiency, since @code{_pw_init()}
needs to be called only once.
+@cindex @code{PROCINFO} array, testing the field splitting
@cindex @code{getline} command, @code{_pw_init()} function
Because this function uses @code{getline} to read information from
@command{pwcat}, it first saves the values of @code{FS}, @code{RS}, and @code{$0}.
@@ -22299,13 +22301,8 @@ It notes in the variable @code{using_fw} whether field splitting
with @code{FIELDWIDTHS} is in effect or not.
Doing so is necessary, since these functions could be called
from anywhere within a user's program, and the user may have his
-or her
-own way of splitting records and fields.
-
-@cindex @code{PROCINFO} array, testing the field splitting
-The @code{using_fw} variable checks @code{PROCINFO["FS"]}, which
-is @code{"FIELDWIDTHS"} if field splitting is being done with
-@code{FIELDWIDTHS}. This makes it possible to restore the correct
+or her own way of splitting records and fields.
+This makes it possible to restore the correct
field-splitting mechanism later. The test can only be true for
@command{gawk}. It is false if using @code{FS} or @code{FPAT},
or on some other @command{awk} implementation.
@@ -22619,8 +22616,7 @@ function _gr_init( oldfs, oldrs, olddol0, grcat,
n = split($4, a, "[ \t]*,[ \t]*")
for (i = 1; i <= n; i++)
if (a[i] in _gr_groupsbyuser)
- _gr_groupsbyuser[a[i]] = \
- _gr_groupsbyuser[a[i]] " " $1
+ _gr_groupsbyuser[a[i]] = gr_groupsbyuser[a[i]] " " $1
else
_gr_groupsbyuser[a[i]] = $1
@@ -22847,8 +22843,8 @@ $ @kbd{gawk -f walk_array.awk}
@itemize @value{BULLET}
@item
Reading programs is an excellent way to learn Good Programming.
-The functions provided in this @value{CHAPTER} and the next are intended
-to serve that purpose.
+The functions and programs provided in this @value{CHAPTER} and the next
+are intended to serve that purpose.
@item
When writing general-purpose library functions, put some thought into how
@@ -23135,22 +23131,16 @@ supplied:
# Requires getopt() and join() library functions
@group
-function usage( e1, e2)
+function usage()
@{
- e1 = "usage: cut [-f list] [-d c] [-s] [files...]"
- e2 = "usage: cut [-c list] [files...]"
- print e1 > "/dev/stderr"
- print e2 > "/dev/stderr"
+ print("usage: cut [-f list] [-d c] [-s] [files...]") > "/dev/stderr"
+ print("usage: cut [-c list] [files...]") > "/dev/stderr"
exit 1
@}
@end group
@c endfile
@end example
-@noindent
-The variables @code{e1} and @code{e2} are used so that the function
-fits nicely on the @value{PAGE}.
-
@cindex @code{BEGIN} pattern, running @command{awk} programs and
@cindex @code{FS} variable, running @command{awk} programs and
Next comes a @code{BEGIN} rule that parses the command-line options.
@@ -23651,19 +23641,15 @@ and then exits:
@example
@c file eg/prog/egrep.awk
-function usage( e)
+function usage()
@{
- e = "Usage: egrep [-csvil] [-e pat] [files ...]"
- e = e "\n\tegrep [-csvil] pat [files ...]"
- print e > "/dev/stderr"
+ print("Usage: egrep [-csvil] [-e pat] [files ...]") > "/dev/stderr"
+ print("\n\tegrep [-csvil] pat [files ...]") > "/dev/stderr"
exit 1
@}
@c endfile
@end example
-The variable @code{e} is used so that the function fits nicely
-on the printed page.
-
@c ENDOFRANGE regexps
@c ENDOFRANGE sfregexp
@c ENDOFRANGE fsregexp
@@ -23721,6 +23707,7 @@ numbers:
# May 1993
# Revised February 1996
# Revised May 2014
+# Revised September 2014
@c endfile
@end ignore
@@ -23739,26 +23726,22 @@ BEGIN @{
printf("uid=%d", uid)
pw = getpwuid(uid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (euid != uid) @{
printf(" euid=%d", euid)
pw = getpwuid(euid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
@}
printf(" gid=%d", gid)
pw = getgrgid(gid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (egid != gid) @{
printf(" egid=%d", egid)
pw = getgrgid(egid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
@}
for (i = 1; ("group" i) in PROCINFO; i++) @{
@@ -23767,8 +23750,7 @@ BEGIN @{
group = PROCINFO["group" i]
printf("%d", group)
pw = getgrgid(group)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (("group" (i+1)) in PROCINFO)
printf(",")
@}
@@ -23778,8 +23760,10 @@ BEGIN @{
function pr_first_field(str, a)
@{
- split(str, a, ":")
- printf("(%s)", a[1])
+ if (str != "") @{
+ split(str, a, ":")
+ printf("(%s)", a[1])
+ @}
@}
@c endfile
@end example
@@ -23802,7 +23786,8 @@ tested, and the loop body never executes.
The @code{pr_first_field()} function simply isolates out some
code that is used repeatedly, making the whole program
-slightly shorter and cleaner.
+shorter and cleaner. In particular, moving the check for
+the empty string into this function saves several lines of code.
@c ENDOFRANGE id
@@ -23929,19 +23914,14 @@ The @code{usage()} function simply prints an error message and exits:
@example
@c file eg/prog/split.awk
-function usage( e)
+function usage()
@{
- e = "usage: split [-num] [file] [outname]"
- print e > "/dev/stderr"
+ print("usage: split [-num] [file] [outname]") > "/dev/stderr"
exit 1
@}
@c endfile
@end example
-@noindent
-The variable @code{e} is used so that the function
-fits nicely on the @value{PAGE}.
-
This program is a bit sloppy; it relies on @command{awk} to automatically close the last file
instead of doing it in an @code{END} rule.
It also assumes that letters are contiguous in the character set,
@@ -24100,10 +24080,10 @@ The options for @command{uniq} are:
@table @code
@item -d
-Print only repeated lines.
+Print only repeated (duplicated) lines.
@item -u
-Print only nonrepeated lines.
+Print only nonrepeated (unique) lines.
@item -c
Count lines. This option overrides @option{-d} and @option{-u}. Both repeated
@@ -24172,10 +24152,9 @@ standard output, @file{/dev/stdout}:
@end ignore
@c file eg/prog/uniq.awk
-function usage( e)
+function usage()
@{
- e = "Usage: uniq [-udc [-n]] [+n] [ in [ out ]]"
- print e > "/dev/stderr"
+ print("Usage: uniq [-udc [-n]] [+n] [ in [ out ]]") > "/dev/stderr"
exit 1
@}
@@ -24229,22 +24208,20 @@ BEGIN @{
@end example
The following function, @code{are_equal()}, compares the current line,
-@code{$0}, to the
-previous line, @code{last}. It handles skipping fields and characters.
-If no field count and no character count are specified, @code{are_equal()}
-simply returns one or zero depending upon the result of a simple string
-comparison of @code{last} and @code{$0}. Otherwise, things get more
-complicated.
-If fields have to be skipped, each line is broken into an array using
-@code{split()}
-(@pxref{String Functions});
-the desired fields are then joined back into a line using @code{join()}.
-The joined lines are stored in @code{clast} and @code{cline}.
-If no fields are skipped, @code{clast} and @code{cline} are set to
-@code{last} and @code{$0}, respectively.
-Finally, if characters are skipped, @code{substr()} is used to strip off the
-leading @code{charcount} characters in @code{clast} and @code{cline}. The
-two strings are then compared and @code{are_equal()} returns the result:
+@code{$0}, to the previous line, @code{last}. It handles skipping fields
+and characters. If no field count and no character count are specified,
+@code{are_equal()} returns one or zero depending upon the result of a
+simple string comparison of @code{last} and @code{$0}.
+
+Otherwise, things get more complicated. If fields have to be skipped,
+each line is broken into an array using @code{split()} (@pxref{String
+Functions}); the desired fields are then joined back into a line
+using @code{join()}. The joined lines are stored in @code{clast} and
+@code{cline}. If no fields are skipped, @code{clast} and @code{cline}
+are set to @code{last} and @code{$0}, respectively. Finally, if
+characters are skipped, @code{substr()} is used to strip off the leading
+@code{charcount} characters in @code{clast} and @code{cline}. The two
+strings are then compared and @code{are_equal()} returns the result:
@example
@c file eg/prog/uniq.awk
@@ -24335,6 +24312,13 @@ END @{
@c endfile
@end example
+@c FIXME: Include this?
+@ignore
+This program does not follow our recommended convention of naming
+global variables with a leading capital letter. Doing that would
+make the program a little easier to follow.
+@end ignore
+
@ifset FOR_PRINT
The logic for choosing which lines to print represents a @dfn{state
machine}, which is ``a device that can be in one of a set number of stable
@@ -24380,7 +24364,7 @@ one or more input files. Its usage is as follows:
If no files are specified on the command line, @command{wc} reads its standard
input. If there are multiple files, it also prints total counts for all
-the files. The options and their meanings are shown in the following list:
+the files. The options and their meanings are as follows:
@table @code
@item -l
@@ -25032,7 +25016,7 @@ of lines on the page
Most of the work is done in the @code{printpage()} function.
The label lines are stored sequentially in the @code{line} array. But they
have to print horizontally; @code{line[1]} next to @code{line[6]},
-@code{line[2]} next to @code{line[7]}, and so on. Two loops are used to
+@code{line[2]} next to @code{line[7]}, and so on. Two loops
accomplish this. The outer loop, controlled by @code{i}, steps through
every 10 lines of data; this is each row of labels. The inner loop,
controlled by @code{j}, goes through the lines within the row.
@@ -25146,7 +25130,7 @@ in a useful format.
At first glance, a program like this would seem to do the job:
@example
-# Print list of word frequencies
+# wordfreq-first-try.awk --- print list of word frequencies
@{
for (i = 1; i <= NF; i++)
@@ -25363,16 +25347,16 @@ Texinfo input file into separate files.
This @value{DOCUMENT} is written in @uref{http://www.gnu.org/software/texinfo/, Texinfo},
the GNU project's document formatting language.
A single Texinfo source file can be used to produce both
-printed and online documentation.
+printed documentation, with @TeX{}, and online documentation.
@ifnotinfo
-Texinfo is fully documented in the book
+(Texinfo is fully documented in the book
@cite{Texinfo---The GNU Documentation Format},
available from the Free Software Foundation,
-and also available @uref{http://www.gnu.org/software/texinfo/manual/texinfo/, online}.
+and also available @uref{http://www.gnu.org/software/texinfo/manual/texinfo/, online}.)
@end ifnotinfo
@ifinfo
-The Texinfo language is described fully, starting with
-@inforef{Top, , Texinfo, texinfo,Texinfo---The GNU Documentation Format}.
+(The Texinfo language is described fully, starting with
+@inforef{Top, , Texinfo, texinfo,Texinfo---The GNU Documentation Format}.)
@end ifinfo
For our purposes, it is enough to know three things about Texinfo input
@@ -25450,8 +25434,7 @@ exits with a zero exit status, signifying OK:
@cindex @code{extract.awk} program
@example
@c file eg/prog/extract.awk
-# extract.awk --- extract files and run programs
-# from texinfo files
+# extract.awk --- extract files and run programs from texinfo files
@c endfile
@ignore
@c file eg/prog/extract.awk
@@ -25465,8 +25448,7 @@ exits with a zero exit status, signifying OK:
BEGIN @{ IGNORECASE = 1 @}
-/^@@c(omment)?[ \t]+system/ \
-@{
+/^@@c(omment)?[ \t]+system/ @{
if (NF < 3) @{
e = ("extract: " FILENAME ":" FNR)
e = (e ": badly formed `system' line")
@@ -25523,8 +25505,7 @@ line. That line is then printed to the output file:
@example
@c file eg/prog/extract.awk
-/^@@c(omment)?[ \t]+file/ \
-@{
+/^@@c(omment)?[ \t]+file/ @{
if (NF != 3) @{
e = ("extract: " FILENAME ":" FNR ": badly formed `file' line")
print e > "/dev/stderr"
@@ -25584,7 +25565,7 @@ The @code{END} rule handles the final cleanup, closing the open file:
function unexpected_eof()
@{
printf("extract: %s:%d: unexpected EOF or error\n",
- FILENAME, FNR) > "/dev/stderr"
+ FILENAME, FNR) > "/dev/stderr"
exit 1
@}
@end group
@@ -25844,6 +25825,7 @@ should be the @command{awk} program. If there are no command-line
arguments left, @command{igawk} prints an error message and exits.
Otherwise, the first argument is appended to @code{program}.
In any case, after the arguments have been processed,
+the shell variable
@code{program} contains the complete text of the original @command{awk}
program.
@@ -26167,12 +26149,10 @@ in C or C++, and it is frequently easier to do certain kinds of string
and argument manipulation using the shell than it is in @command{awk}.
Finally, @command{igawk} shows that it is not always necessary to add new
-features to a program; they can often be layered on top.
-@ignore
-With @command{igawk},
-there is no real reason to build @code{@@include} processing into
-@command{gawk} itself.
-@end ignore
+features to a program; they can often be layered on top.@footnote{@command{gawk}
+does @code{@@include} processing itself in order to support the use
+of @command{awk} programs as Web CGI scripts.}
+
@c ENDOFRANGE libfex
@c ENDOFRANGE flibex
@c ENDOFRANGE awkpex
@@ -26190,12 +26170,11 @@ One word is an anagram of another if both words contain
the same letters
(for example, ``babbling'' and ``blabbing'').
-An elegant algorithm is presented in Column 2, Problem C of
-Jon Bentley's @cite{Programming Pearls}, second edition.
-The idea is to give words that are anagrams a common signature,
-sort all the words together by their signature, and then print them.
-Dr.@: Bentley observes that taking the letters in each word and
-sorting them produces that common signature.
+Column 2, Problem C of Jon Bentley's @cite{Programming Pearls}, second
+edition, presents an elegant algorithm. The idea is to give words that
+are anagrams a common signature, sort all the words together by their
+signature, and then print them. Dr.@: Bentley observes that taking the
+letters in each word and sorting them produces that common signature.
The following program uses arrays of arrays to bring together
words with the same signature and array sorting to print the words
@@ -26429,7 +26408,7 @@ BEGIN {
@itemize @value{BULLET}
@item
-The functions provided in this @value{CHAPTER} and the previous one
+The programs provided in this @value{CHAPTER}
continue on the theme that reading programs is an excellent way to learn
Good Programming.
@@ -26706,13 +26685,11 @@ discusses the ability to dynamically add new built-in functions to
@cindex constants, nondecimal
If you run @command{gawk} with the @option{--non-decimal-data} option,
-you can have nondecimal constants in your input data:
+you can have nondecimal values in your input data:
-@c line break here for small book format
@example
$ @kbd{echo 0123 123 0x123 |}
-> @kbd{gawk --non-decimal-data '@{ printf "%d, %d, %d\n",}
-> @kbd{$1, $2, $3 @}'}
+> @kbd{gawk --non-decimal-data '@{ printf "%d, %d, %d\n", $1, $2, $3 @}'}
@print{} 83, 123, 291
@end example
@@ -26753,6 +26730,8 @@ Instead, use the @code{strtonum()} function to convert your data
(@pxref{String Functions}).
This makes your programs easier to write and easier to read, and
leads to less surprising results.
+
+This option may disappear in a future version of @command{gawk}.
@end quotation
@node Array Sorting
@@ -26787,7 +26766,9 @@ pre-defined values to @code{PROCINFO["sorted_in"]} in order to
control the order in which @command{gawk} traverses an array
during a @code{for} loop.
-In addition, the value of @code{PROCINFO["sorted_in"]} can be a function name.
+In addition, the value of @code{PROCINFO["sorted_in"]} can be a
+function name.@footnote{This is why the predefined sorting orders
+start with an @samp{@@} character, which cannot be part of an identifier.}
This lets you traverse an array based on any custom criterion.
The array elements are ordered according to the return value of this
function. The comparison function should be defined with at least
@@ -26919,7 +26900,7 @@ according to login name. The following program sorts records
by a specific field position and can be used for this purpose:
@example
-# sort.awk --- simple program to sort by field position
+# passwd-sort.awk --- simple program to sort by field position
# field position is specified by the global variable POS
function cmp_field(i1, v1, i2, v2)
@@ -26978,7 +26959,7 @@ As mentioned above, the order of the indices is arbitrary if two
elements compare equal. This is usually not a problem, but letting
the tied elements come out in arbitrary order can be an issue, especially
when comparing item values. The partial ordering of the equal elements
-may change during the next loop traversal, if other elements are added or
+may change the next time the array is traversed, if other elements are added or
removed from the array. One way to resolve ties when comparing elements
with otherwise equal values is to include the indices in the comparison
rules. Note that doing this may make the loop traversal less efficient,
@@ -27212,7 +27193,7 @@ for example, @file{/tmp} will not do, as another user might happen
to be using a temporary file with the same name.@footnote{Michael
Brennan suggests the use of @command{rand()} to generate unique
@value{FN}s. This is a valid point; nevertheless, temporary files
-remain more difficult than two-way pipes.} @c 8/2014
+remain more difficult to use than two-way pipes.} @c 8/2014
@cindex coprocesses
@cindex input/output, two-way
@@ -27355,7 +27336,7 @@ using regular pipes.
@ @ @ @ @i{A host is a host from coast to coast,@*
@ @ @ @ and no-one can talk to host that's close,@*
@ @ @ @ unless the host that isn't close@*
-@ @ @ @ is busy hung or dead.}
+@ @ @ @ is busy, hung, or dead.}
@end quotation
@end ifnotdocbook
@@ -27365,7 +27346,7 @@ using regular pipes.
&nbsp;&nbsp;&nbsp;&nbsp;<emphasis>A host is a host from coast to coast,</emphasis>
&nbsp;&nbsp;&nbsp;&nbsp;<emphasis>and no-one can talk to host that's close,</emphasis>
&nbsp;&nbsp;&nbsp;&nbsp;<emphasis>unless the host that isn't close</emphasis>
-&nbsp;&nbsp;&nbsp;&nbsp;<emphasis>is busy hung or dead.</emphasis></literallayout>
+&nbsp;&nbsp;&nbsp;&nbsp;<emphasis>is busy, hung, or dead.</emphasis></literallayout>
</blockquote>
@end docbook
@@ -27396,7 +27377,7 @@ the system default, most likely IPv4.
@item protocol
The protocol to use over IP. This must be either @samp{tcp}, or
@samp{udp}, for a TCP or UDP IP connection,
-respectively. The use of TCP is recommended for most applications.
+respectively. TCP should be used for most applications.
@item local-port
@cindex @code{getaddrinfo()} function (C library)
@@ -27429,10 +27410,10 @@ Consider the following very simple example:
@example
BEGIN @{
- Service = "/inet/tcp/0/localhost/daytime"
- Service |& getline
- print $0
- close(Service)
+ Service = "/inet/tcp/0/localhost/daytime"
+ Service |& getline
+ print $0
+ close(Service)
@}
@end example
@@ -38111,10 +38092,8 @@ Date: Wed, 4 Sep 1996 08:11:48 -0700 (PDT)
@docbook
<blockquote><attribution>Michael Brennan</attribution>
-<literallayout>
-<emphasis>It's kind of fun to put comments like this in your awk code.</emphasis>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<literal>// Do C++ comments work? answer: yes! of course</literal>
-</literallayout>
+<literallayout><emphasis>It's kind of fun to put comments like this in your awk code.</emphasis>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<literal>// Do C++ comments work? answer: yes! of course</literal></literallayout>
</blockquote>
@end docbook
@@ -41755,4 +41734,3 @@ But to use it you have to say
which sorta sucks.
TODO:
------
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index 43234e7c..d026a3b1 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -3825,6 +3825,8 @@ values in input data
@quotation CAUTION
This option can severely break old programs.
Use with care.
+
+This option may disappear in a future version of @command{gawk}.
@end quotation
@item @option{-N}
@@ -20596,24 +20598,12 @@ function rewind( i)
@c endfile
@end example
-This code relies on the @code{ARGIND} variable
-(@pxref{Auto-set}),
-which is specific to @command{gawk}.
-If you are not using
-@command{gawk}, you can use ideas presented in
-@ifnotinfo
-the previous @value{SECTION}
-@end ifnotinfo
-@ifinfo
-@ref{Filetrans Function},
-@end ifinfo
-to either update @code{ARGIND} on your own
-or modify this code as appropriate.
-
-The @code{rewind()} function also relies on the @code{nextfile} keyword
-(@pxref{Nextfile Statement}). Because of this, you should not call it
-from an @code{ENDFILE} rule. (This isn't necessary anyway, since as soon
-as an @code{ENDFILE} rule finishes @command{gawk} goes to the next file!)
+The @code{rewind()} function relies on the @code{ARGIND} variable
+(@pxref{Auto-set}), which is specific to @command{gawk}. It also
+relies on the @code{nextfile} keyword (@pxref{Nextfile Statement}).
+Because of this, you should not call it from an @code{ENDFILE} rule.
+(This isn't necessary anyway, since as soon as an @code{ENDFILE} rule
+finishes @command{gawk} goes to the next file!)
@node File Checking
@subsection Checking for Readable @value{DDF}s
@@ -20646,7 +20636,7 @@ the following program to your @command{awk} program:
BEGIN @{
for (i = 1; i < ARGC; i++) @{
- if (ARGV[i] ~ /^[[:alpha:]_][[:alnum:]_]*=.*/ \
+ if (ARGV[i] ~ /^[a-zA-Z_][a-zA-Z0-9_]*=.*/ \
|| ARGV[i] == "-" || ARGV[i] == "/dev/stdin")
continue # assignment or standard input
else if ((getline junk < ARGV[i]) < 0) # unreadable
@@ -20664,6 +20654,11 @@ Removing the element from @code{ARGV} with @code{delete}
skips the file (since it's no longer in the list).
See also @ref{ARGC and ARGV}.
+The regular expression check purposely does not use character classes
+such as @samp{[:alpha:]} and @samp{[:alnum:]}
+(@pxref{Bracket Expressions})
+since @command{awk} variable names only allow the English letters.
+
@node Empty Files
@subsection Checking for Zero-length Files
@@ -20760,7 +20755,7 @@ a library file does the trick:
function disable_assigns(argc, argv, i)
@{
for (i = 1; i < argc; i++)
- if (argv[i] ~ /^[[:alpha:]_][[:alnum:]_]*=.*/)
+ if (argv[i] ~ /^[a-zA-Z_][a-zA-Z0-9_]*=.*/)
argv[i] = ("./" argv[i])
@}
@@ -21132,12 +21127,18 @@ In both runs, the first @option{--} terminates the arguments to
etc., as its own options.
@quotation NOTE
-After @code{getopt()} is through, it is the responsibility of the
-user level code to clear out all the elements of @code{ARGV} from 1
+After @code{getopt()} is through,
+user level code must clear out all the elements of @code{ARGV} from 1
to @code{Optind}, so that @command{awk} does not try to process the
command-line options as @value{FN}s.
@end quotation
+Using @samp{#!} with the @option{-E} option may help avoid
+conflicts between your program's options and @command{gawk}'s options,
+since @option{-E} causes @command{gawk} to abandon processing of
+further options
+(@pxref{Executable Scripts}, and @pxref{Options}).
+
Several of the sample programs presented in
@ref{Sample Programs},
use @code{getopt()} to process their arguments.
@@ -21382,13 +21383,14 @@ The @code{BEGIN} rule sets a private variable to the directory where
routine, we have chosen to put it in @file{/usr/local/libexec/awk};
however, you might want it to be in a different directory on your system.
-The function @code{_pw_init()} keeps three copies of the user information
-in three associative arrays. The arrays are indexed by username
+The function @code{_pw_init()} fills three copies of the user information
+into three associative arrays. The arrays are indexed by username
(@code{_pw_byname}), by user ID number (@code{_pw_byuid}), and by order of
occurrence (@code{_pw_bycount}).
The variable @code{_pw_inited} is used for efficiency, since @code{_pw_init()}
needs to be called only once.
+@cindex @code{PROCINFO} array, testing the field splitting
@cindex @code{getline} command, @code{_pw_init()} function
Because this function uses @code{getline} to read information from
@command{pwcat}, it first saves the values of @code{FS}, @code{RS}, and @code{$0}.
@@ -21396,13 +21398,8 @@ It notes in the variable @code{using_fw} whether field splitting
with @code{FIELDWIDTHS} is in effect or not.
Doing so is necessary, since these functions could be called
from anywhere within a user's program, and the user may have his
-or her
-own way of splitting records and fields.
-
-@cindex @code{PROCINFO} array, testing the field splitting
-The @code{using_fw} variable checks @code{PROCINFO["FS"]}, which
-is @code{"FIELDWIDTHS"} if field splitting is being done with
-@code{FIELDWIDTHS}. This makes it possible to restore the correct
+or her own way of splitting records and fields.
+This makes it possible to restore the correct
field-splitting mechanism later. The test can only be true for
@command{gawk}. It is false if using @code{FS} or @code{FPAT},
or on some other @command{awk} implementation.
@@ -21716,8 +21713,7 @@ function _gr_init( oldfs, oldrs, olddol0, grcat,
n = split($4, a, "[ \t]*,[ \t]*")
for (i = 1; i <= n; i++)
if (a[i] in _gr_groupsbyuser)
- _gr_groupsbyuser[a[i]] = \
- _gr_groupsbyuser[a[i]] " " $1
+ _gr_groupsbyuser[a[i]] = gr_groupsbyuser[a[i]] " " $1
else
_gr_groupsbyuser[a[i]] = $1
@@ -21944,8 +21940,8 @@ $ @kbd{gawk -f walk_array.awk}
@itemize @value{BULLET}
@item
Reading programs is an excellent way to learn Good Programming.
-The functions provided in this @value{CHAPTER} and the next are intended
-to serve that purpose.
+The functions and programs provided in this @value{CHAPTER} and the next
+are intended to serve that purpose.
@item
When writing general-purpose library functions, put some thought into how
@@ -22232,22 +22228,16 @@ supplied:
# Requires getopt() and join() library functions
@group
-function usage( e1, e2)
+function usage()
@{
- e1 = "usage: cut [-f list] [-d c] [-s] [files...]"
- e2 = "usage: cut [-c list] [files...]"
- print e1 > "/dev/stderr"
- print e2 > "/dev/stderr"
+ print("usage: cut [-f list] [-d c] [-s] [files...]") > "/dev/stderr"
+ print("usage: cut [-c list] [files...]") > "/dev/stderr"
exit 1
@}
@end group
@c endfile
@end example
-@noindent
-The variables @code{e1} and @code{e2} are used so that the function
-fits nicely on the @value{PAGE}.
-
@cindex @code{BEGIN} pattern, running @command{awk} programs and
@cindex @code{FS} variable, running @command{awk} programs and
Next comes a @code{BEGIN} rule that parses the command-line options.
@@ -22748,19 +22738,15 @@ and then exits:
@example
@c file eg/prog/egrep.awk
-function usage( e)
+function usage()
@{
- e = "Usage: egrep [-csvil] [-e pat] [files ...]"
- e = e "\n\tegrep [-csvil] pat [files ...]"
- print e > "/dev/stderr"
+ print("Usage: egrep [-csvil] [-e pat] [files ...]") > "/dev/stderr"
+ print("\n\tegrep [-csvil] pat [files ...]") > "/dev/stderr"
exit 1
@}
@c endfile
@end example
-The variable @code{e} is used so that the function fits nicely
-on the printed page.
-
@c ENDOFRANGE regexps
@c ENDOFRANGE sfregexp
@c ENDOFRANGE fsregexp
@@ -22818,6 +22804,7 @@ numbers:
# May 1993
# Revised February 1996
# Revised May 2014
+# Revised September 2014
@c endfile
@end ignore
@@ -22836,26 +22823,22 @@ BEGIN @{
printf("uid=%d", uid)
pw = getpwuid(uid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (euid != uid) @{
printf(" euid=%d", euid)
pw = getpwuid(euid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
@}
printf(" gid=%d", gid)
pw = getgrgid(gid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (egid != gid) @{
printf(" egid=%d", egid)
pw = getgrgid(egid)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
@}
for (i = 1; ("group" i) in PROCINFO; i++) @{
@@ -22864,8 +22847,7 @@ BEGIN @{
group = PROCINFO["group" i]
printf("%d", group)
pw = getgrgid(group)
- if (pw != "")
- pr_first_field(pw)
+ pr_first_field(pw)
if (("group" (i+1)) in PROCINFO)
printf(",")
@}
@@ -22875,8 +22857,10 @@ BEGIN @{
function pr_first_field(str, a)
@{
- split(str, a, ":")
- printf("(%s)", a[1])
+ if (str != "") @{
+ split(str, a, ":")
+ printf("(%s)", a[1])
+ @}
@}
@c endfile
@end example
@@ -22899,7 +22883,8 @@ tested, and the loop body never executes.
The @code{pr_first_field()} function simply isolates out some
code that is used repeatedly, making the whole program
-slightly shorter and cleaner.
+shorter and cleaner. In particular, moving the check for
+the empty string into this function saves several lines of code.
@c ENDOFRANGE id
@@ -23026,19 +23011,14 @@ The @code{usage()} function simply prints an error message and exits:
@example
@c file eg/prog/split.awk
-function usage( e)
+function usage()
@{
- e = "usage: split [-num] [file] [outname]"
- print e > "/dev/stderr"
+ print("usage: split [-num] [file] [outname]") > "/dev/stderr"
exit 1
@}
@c endfile
@end example
-@noindent
-The variable @code{e} is used so that the function
-fits nicely on the @value{PAGE}.
-
This program is a bit sloppy; it relies on @command{awk} to automatically close the last file
instead of doing it in an @code{END} rule.
It also assumes that letters are contiguous in the character set,
@@ -23197,10 +23177,10 @@ The options for @command{uniq} are:
@table @code
@item -d
-Print only repeated lines.
+Print only repeated (duplicated) lines.
@item -u
-Print only nonrepeated lines.
+Print only nonrepeated (unique) lines.
@item -c
Count lines. This option overrides @option{-d} and @option{-u}. Both repeated
@@ -23269,10 +23249,9 @@ standard output, @file{/dev/stdout}:
@end ignore
@c file eg/prog/uniq.awk
-function usage( e)
+function usage()
@{
- e = "Usage: uniq [-udc [-n]] [+n] [ in [ out ]]"
- print e > "/dev/stderr"
+ print("Usage: uniq [-udc [-n]] [+n] [ in [ out ]]") > "/dev/stderr"
exit 1
@}
@@ -23326,22 +23305,20 @@ BEGIN @{
@end example
The following function, @code{are_equal()}, compares the current line,
-@code{$0}, to the
-previous line, @code{last}. It handles skipping fields and characters.
-If no field count and no character count are specified, @code{are_equal()}
-simply returns one or zero depending upon the result of a simple string
-comparison of @code{last} and @code{$0}. Otherwise, things get more
-complicated.
-If fields have to be skipped, each line is broken into an array using
-@code{split()}
-(@pxref{String Functions});
-the desired fields are then joined back into a line using @code{join()}.
-The joined lines are stored in @code{clast} and @code{cline}.
-If no fields are skipped, @code{clast} and @code{cline} are set to
-@code{last} and @code{$0}, respectively.
-Finally, if characters are skipped, @code{substr()} is used to strip off the
-leading @code{charcount} characters in @code{clast} and @code{cline}. The
-two strings are then compared and @code{are_equal()} returns the result:
+@code{$0}, to the previous line, @code{last}. It handles skipping fields
+and characters. If no field count and no character count are specified,
+@code{are_equal()} returns one or zero depending upon the result of a
+simple string comparison of @code{last} and @code{$0}.
+
+Otherwise, things get more complicated. If fields have to be skipped,
+each line is broken into an array using @code{split()} (@pxref{String
+Functions}); the desired fields are then joined back into a line
+using @code{join()}. The joined lines are stored in @code{clast} and
+@code{cline}. If no fields are skipped, @code{clast} and @code{cline}
+are set to @code{last} and @code{$0}, respectively. Finally, if
+characters are skipped, @code{substr()} is used to strip off the leading
+@code{charcount} characters in @code{clast} and @code{cline}. The two
+strings are then compared and @code{are_equal()} returns the result:
@example
@c file eg/prog/uniq.awk
@@ -23432,6 +23409,13 @@ END @{
@c endfile
@end example
+@c FIXME: Include this?
+@ignore
+This program does not follow our recommended convention of naming
+global variables with a leading capital letter. Doing that would
+make the program a little easier to follow.
+@end ignore
+
@ifset FOR_PRINT
The logic for choosing which lines to print represents a @dfn{state
machine}, which is ``a device that can be in one of a set number of stable
@@ -23477,7 +23461,7 @@ one or more input files. Its usage is as follows:
If no files are specified on the command line, @command{wc} reads its standard
input. If there are multiple files, it also prints total counts for all
-the files. The options and their meanings are shown in the following list:
+the files. The options and their meanings are as follows:
@table @code
@item -l
@@ -24129,7 +24113,7 @@ of lines on the page
Most of the work is done in the @code{printpage()} function.
The label lines are stored sequentially in the @code{line} array. But they
have to print horizontally; @code{line[1]} next to @code{line[6]},
-@code{line[2]} next to @code{line[7]}, and so on. Two loops are used to
+@code{line[2]} next to @code{line[7]}, and so on. Two loops
accomplish this. The outer loop, controlled by @code{i}, steps through
every 10 lines of data; this is each row of labels. The inner loop,
controlled by @code{j}, goes through the lines within the row.
@@ -24243,7 +24227,7 @@ in a useful format.
At first glance, a program like this would seem to do the job:
@example
-# Print list of word frequencies
+# wordfreq-first-try.awk --- print list of word frequencies
@{
for (i = 1; i <= NF; i++)
@@ -24460,16 +24444,16 @@ Texinfo input file into separate files.
This @value{DOCUMENT} is written in @uref{http://www.gnu.org/software/texinfo/, Texinfo},
the GNU project's document formatting language.
A single Texinfo source file can be used to produce both
-printed and online documentation.
+printed documentation, with @TeX{}, and online documentation.
@ifnotinfo
-Texinfo is fully documented in the book
+(Texinfo is fully documented in the book
@cite{Texinfo---The GNU Documentation Format},
available from the Free Software Foundation,
-and also available @uref{http://www.gnu.org/software/texinfo/manual/texinfo/, online}.
+and also available @uref{http://www.gnu.org/software/texinfo/manual/texinfo/, online}.)
@end ifnotinfo
@ifinfo
-The Texinfo language is described fully, starting with
-@inforef{Top, , Texinfo, texinfo,Texinfo---The GNU Documentation Format}.
+(The Texinfo language is described fully, starting with
+@inforef{Top, , Texinfo, texinfo,Texinfo---The GNU Documentation Format}.)
@end ifinfo
For our purposes, it is enough to know three things about Texinfo input
@@ -24547,8 +24531,7 @@ exits with a zero exit status, signifying OK:
@cindex @code{extract.awk} program
@example
@c file eg/prog/extract.awk
-# extract.awk --- extract files and run programs
-# from texinfo files
+# extract.awk --- extract files and run programs from texinfo files
@c endfile
@ignore
@c file eg/prog/extract.awk
@@ -24562,8 +24545,7 @@ exits with a zero exit status, signifying OK:
BEGIN @{ IGNORECASE = 1 @}
-/^@@c(omment)?[ \t]+system/ \
-@{
+/^@@c(omment)?[ \t]+system/ @{
if (NF < 3) @{
e = ("extract: " FILENAME ":" FNR)
e = (e ": badly formed `system' line")
@@ -24620,8 +24602,7 @@ line. That line is then printed to the output file:
@example
@c file eg/prog/extract.awk
-/^@@c(omment)?[ \t]+file/ \
-@{
+/^@@c(omment)?[ \t]+file/ @{
if (NF != 3) @{
e = ("extract: " FILENAME ":" FNR ": badly formed `file' line")
print e > "/dev/stderr"
@@ -24681,7 +24662,7 @@ The @code{END} rule handles the final cleanup, closing the open file:
function unexpected_eof()
@{
printf("extract: %s:%d: unexpected EOF or error\n",
- FILENAME, FNR) > "/dev/stderr"
+ FILENAME, FNR) > "/dev/stderr"
exit 1
@}
@end group
@@ -24941,6 +24922,7 @@ should be the @command{awk} program. If there are no command-line
arguments left, @command{igawk} prints an error message and exits.
Otherwise, the first argument is appended to @code{program}.
In any case, after the arguments have been processed,
+the shell variable
@code{program} contains the complete text of the original @command{awk}
program.
@@ -25264,12 +25246,10 @@ in C or C++, and it is frequently easier to do certain kinds of string
and argument manipulation using the shell than it is in @command{awk}.
Finally, @command{igawk} shows that it is not always necessary to add new
-features to a program; they can often be layered on top.
-@ignore
-With @command{igawk},
-there is no real reason to build @code{@@include} processing into
-@command{gawk} itself.
-@end ignore
+features to a program; they can often be layered on top.@footnote{@command{gawk}
+does @code{@@include} processing itself in order to support the use
+of @command{awk} programs as Web CGI scripts.}
+
@c ENDOFRANGE libfex
@c ENDOFRANGE flibex
@c ENDOFRANGE awkpex
@@ -25287,12 +25267,11 @@ One word is an anagram of another if both words contain
the same letters
(for example, ``babbling'' and ``blabbing'').
-An elegant algorithm is presented in Column 2, Problem C of
-Jon Bentley's @cite{Programming Pearls}, second edition.
-The idea is to give words that are anagrams a common signature,
-sort all the words together by their signature, and then print them.
-Dr.@: Bentley observes that taking the letters in each word and
-sorting them produces that common signature.
+Column 2, Problem C of Jon Bentley's @cite{Programming Pearls}, second
+edition, presents an elegant algorithm. The idea is to give words that
+are anagrams a common signature, sort all the words together by their
+signature, and then print them. Dr.@: Bentley observes that taking the
+letters in each word and sorting them produces that common signature.
The following program uses arrays of arrays to bring together
words with the same signature and array sorting to print the words
@@ -25526,7 +25505,7 @@ BEGIN {
@itemize @value{BULLET}
@item
-The functions provided in this @value{CHAPTER} and the previous one
+The programs provided in this @value{CHAPTER}
continue on the theme that reading programs is an excellent way to learn
Good Programming.
@@ -25803,13 +25782,11 @@ discusses the ability to dynamically add new built-in functions to
@cindex constants, nondecimal
If you run @command{gawk} with the @option{--non-decimal-data} option,
-you can have nondecimal constants in your input data:
+you can have nondecimal values in your input data:
-@c line break here for small book format
@example
$ @kbd{echo 0123 123 0x123 |}
-> @kbd{gawk --non-decimal-data '@{ printf "%d, %d, %d\n",}
-> @kbd{$1, $2, $3 @}'}
+> @kbd{gawk --non-decimal-data '@{ printf "%d, %d, %d\n", $1, $2, $3 @}'}
@print{} 83, 123, 291
@end example
@@ -25850,6 +25827,8 @@ Instead, use the @code{strtonum()} function to convert your data
(@pxref{String Functions}).
This makes your programs easier to write and easier to read, and
leads to less surprising results.
+
+This option may disappear in a future version of @command{gawk}.
@end quotation
@node Array Sorting
@@ -25884,7 +25863,9 @@ pre-defined values to @code{PROCINFO["sorted_in"]} in order to
control the order in which @command{gawk} traverses an array
during a @code{for} loop.
-In addition, the value of @code{PROCINFO["sorted_in"]} can be a function name.
+In addition, the value of @code{PROCINFO["sorted_in"]} can be a
+function name.@footnote{This is why the predefined sorting orders
+start with an @samp{@@} character, which cannot be part of an identifier.}
This lets you traverse an array based on any custom criterion.
The array elements are ordered according to the return value of this
function. The comparison function should be defined with at least
@@ -26016,7 +25997,7 @@ according to login name. The following program sorts records
by a specific field position and can be used for this purpose:
@example
-# sort.awk --- simple program to sort by field position
+# passwd-sort.awk --- simple program to sort by field position
# field position is specified by the global variable POS
function cmp_field(i1, v1, i2, v2)
@@ -26075,7 +26056,7 @@ As mentioned above, the order of the indices is arbitrary if two
elements compare equal. This is usually not a problem, but letting
the tied elements come out in arbitrary order can be an issue, especially
when comparing item values. The partial ordering of the equal elements
-may change during the next loop traversal, if other elements are added or
+may change the next time the array is traversed, if other elements are added or
removed from the array. One way to resolve ties when comparing elements
with otherwise equal values is to include the indices in the comparison
rules. Note that doing this may make the loop traversal less efficient,
@@ -26309,7 +26290,7 @@ for example, @file{/tmp} will not do, as another user might happen
to be using a temporary file with the same name.@footnote{Michael
Brennan suggests the use of @command{rand()} to generate unique
@value{FN}s. This is a valid point; nevertheless, temporary files
-remain more difficult than two-way pipes.} @c 8/2014
+remain more difficult to use than two-way pipes.} @c 8/2014
@cindex coprocesses
@cindex input/output, two-way
@@ -26452,7 +26433,7 @@ using regular pipes.
@ @ @ @ @i{A host is a host from coast to coast,@*
@ @ @ @ and no-one can talk to host that's close,@*
@ @ @ @ unless the host that isn't close@*
-@ @ @ @ is busy hung or dead.}
+@ @ @ @ is busy, hung, or dead.}
@end quotation
@end ifnotdocbook
@@ -26462,7 +26443,7 @@ using regular pipes.
&nbsp;&nbsp;&nbsp;&nbsp;<emphasis>A host is a host from coast to coast,</emphasis>
&nbsp;&nbsp;&nbsp;&nbsp;<emphasis>and no-one can talk to host that's close,</emphasis>
&nbsp;&nbsp;&nbsp;&nbsp;<emphasis>unless the host that isn't close</emphasis>
-&nbsp;&nbsp;&nbsp;&nbsp;<emphasis>is busy hung or dead.</emphasis></literallayout>
+&nbsp;&nbsp;&nbsp;&nbsp;<emphasis>is busy, hung, or dead.</emphasis></literallayout>
</blockquote>
@end docbook
@@ -26493,7 +26474,7 @@ the system default, most likely IPv4.
@item protocol
The protocol to use over IP. This must be either @samp{tcp}, or
@samp{udp}, for a TCP or UDP IP connection,
-respectively. The use of TCP is recommended for most applications.
+respectively. TCP should be used for most applications.
@item local-port
@cindex @code{getaddrinfo()} function (C library)
@@ -26526,10 +26507,10 @@ Consider the following very simple example:
@example
BEGIN @{
- Service = "/inet/tcp/0/localhost/daytime"
- Service |& getline
- print $0
- close(Service)
+ Service = "/inet/tcp/0/localhost/daytime"
+ Service |& getline
+ print $0
+ close(Service)
@}
@end example
@@ -37208,10 +37189,8 @@ Date: Wed, 4 Sep 1996 08:11:48 -0700 (PDT)
@docbook
<blockquote><attribution>Michael Brennan</attribution>
-<literallayout>
-<emphasis>It's kind of fun to put comments like this in your awk code.</emphasis>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<literal>// Do C++ comments work? answer: yes! of course</literal>
-</literallayout>
+<literallayout><emphasis>It's kind of fun to put comments like this in your awk code.</emphasis>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<literal>// Do C++ comments work? answer: yes! of course</literal></literallayout>
</blockquote>
@end docbook
@@ -40852,4 +40831,3 @@ But to use it you have to say
which sorta sucks.
TODO:
------
diff --git a/pc/config.h b/pc/config.h
index c5d78a96..a6b2d4c4 100644
--- a/pc/config.h
+++ b/pc/config.h
@@ -242,6 +242,9 @@
#define HAVE_STDLIB_H 1
#endif
+/* Define to 1 if you have the `strcasecmp' function. */
+#undef HAVE_STRCASECMP
+
/* Define to 1 if you have the `strchr' function. */
#define HAVE_STRCHR 1
@@ -407,6 +410,9 @@
/* Define to 1 if the system has the type `_Bool'. */
#undef HAVE__BOOL
+/* enable severe portability problems */
+#undef I_DONT_KNOW_WHAT_IM_DOING
+
/* libc is broken for regex handling */
#undef LIBC_IS_BORKED
diff --git a/profile.c b/profile.c
index d07bea4a..b0fbbedb 100644
--- a/profile.c
+++ b/profile.c
@@ -190,7 +190,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header)
if (rule != Rule) {
if (! rule_count[rule]++)
- fprintf(prof_fp, _("\t# %s block(s)\n\n"), ruletab[rule]);
+ fprintf(prof_fp, _("\t# %s rules(s)\n\n"), ruletab[rule]);
fprintf(prof_fp, "\t%s {\n", ruletab[rule]);
ip = (pc + 1)->firsti;
} else {
diff --git a/test/ChangeLog b/test/ChangeLog
index 8e89f0d2..fda75ee8 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2014-09-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * profile2.ok, profile3.ok, profile4.ok, profile5.ok:
+ Adjusted after minor code change.
+
2014-09-18 Arnold D. Robbins <arnold@skeeve.com>
* filefuncs.awk: Change to build directory instead of "..".
diff --git a/test/profile2.ok b/test/profile2.ok
index 50c7e190..66b01402 100644
--- a/test/profile2.ok
+++ b/test/profile2.ok
@@ -1,4 +1,4 @@
- # BEGIN block(s)
+ # BEGIN rules(s)
BEGIN {
1 if (sortcmd == "") {
diff --git a/test/profile3.ok b/test/profile3.ok
index 50172c48..5a9eeea9 100644
--- a/test/profile3.ok
+++ b/test/profile3.ok
@@ -1,4 +1,4 @@
- # BEGIN block(s)
+ # BEGIN rules(s)
BEGIN {
1 the_func = "p"
diff --git a/test/profile4.ok b/test/profile4.ok
index 8ff4470f..df52aa1a 100644
--- a/test/profile4.ok
+++ b/test/profile4.ok
@@ -1,4 +1,4 @@
- # BEGIN block(s)
+ # BEGIN rules(s)
BEGIN {
a = "foo" (c = "bar")
diff --git a/test/profile5.ok b/test/profile5.ok
index cc83dc06..c688fbb8 100644
--- a/test/profile5.ok
+++ b/test/profile5.ok
@@ -1,4 +1,4 @@
- # BEGIN block(s)
+ # BEGIN rules(s)
BEGIN {
_addlib("_BASE")
@@ -263,7 +263,7 @@
_END()
}
- # END block(s)
+ # END rules(s)
END {
_EXIT()