summaryrefslogtreecommitdiff
path: root/doc/gawk.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/gawk.texi')
-rw-r--r--doc/gawk.texi544
1 files changed, 454 insertions, 90 deletions
diff --git a/doc/gawk.texi b/doc/gawk.texi
index 9a840708..af97e678 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -756,6 +756,8 @@ particular records in a file and perform operations upon them.
* Arrays Summary:: Summary of arrays.
* Built-in:: Summarizes the built-in functions.
* Calling Built-in:: How to call built-in functions.
+* Boolean Functions:: A function that returns Boolean
+ values.
* Numeric Functions:: Functions that work with numbers,
including @code{int()}, @code{sin()}
and @code{rand()}.
@@ -865,6 +867,7 @@ particular records in a file and perform operations upon them.
* Programs Summary:: Summary of programs.
* Programs Exercises:: Exercises.
* Nondecimal Data:: Allowing nondecimal input data.
+* Boolean Typed Values:: Values with @code{number|bool} type.
* Array Sorting:: Facilities for controlling array
traversal and sorting arrays.
* Controlling Array Traversal:: How to use PROCINFO["sorted_in"].
@@ -928,6 +931,7 @@ particular records in a file and perform operations upon them.
* Inexact representation:: Numbers are not exactly represented.
* Comparing FP Values:: How to compare floating point values.
* Errors accumulate:: Errors get bigger as they go.
+* Strange values:: A few words about infinities and NaNs.
* Getting Accuracy:: Getting more accuracy takes some work.
* Try To Round:: Add digits and round.
* Setting precision:: How to set the precision.
@@ -3149,11 +3153,12 @@ column means that the person is a friend.
An @samp{R} means that the person is a relative:
@example
-@c system if test ! -d eg ; then mkdir eg ; fi
-@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi
-@c system if test ! -d eg/data ; then mkdir eg/data ; fi
-@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi
-@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi
+@c system if test ! -d eg ; then mkdir eg ; fi
+@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi
+@c system if test ! -d eg/data ; then mkdir eg/data ; fi
+@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi
+@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi
+@c system if test ! -d eg/test-programs ; then mkdir eg/test-programs ; fi
@c file eg/data/mail-list
Amelia 555-5553 amelia.zodiacusque@@gmail.com F
Anthony 555-3412 anthony.asserturo@@hotmail.com A
@@ -4316,8 +4321,7 @@ Allow interval expressions
(@pxref{Regexp Operators})
in regexps.
This is now @command{gawk}'s default behavior.
-Nevertheless, this option remains (both for backward compatibility
-and for use in combination with @option{--traditional}).
+Nevertheless, this option remains for backward compatibility.
@item @option{-s}
@itemx @option{--no-optimize}
@@ -4853,7 +4857,10 @@ blocksize, which is usually the filesystem's I/O blocksize.)
If this variable exists with a value of @samp{gst}, @command{gawk}
switches to using the hash function from GNU Smalltalk for
managing arrays.
-This function may be marginally faster than the standard function.
+With a value of @samp{fnv1a}, @command{gawk} uses the
+@uref{http://www.isthe.com/chongo/tech/comp/fnv/index.html,
+FNV1-A hash function}.
+These functions may be marginally faster than the standard function.
@item AWKREADFUNC
If this variable exists, @command{gawk} switches to reading source
@@ -6102,11 +6109,12 @@ When @samp{@{} and @samp{@}} appear in regexp constants
in a way that cannot be interpreted as an interval expression
(such as @code{/q@{a@}/}), then they stand for themselves.
+@cindex BWK @command{awk} @subentry interval expressions in
As mentioned, interval expressions were not traditionally available
in @command{awk}. In March of 2019, BWK @command{awk} (finally) acquired them.
-Nonetheless, because they were not available for
-so many decades, @command{gawk} continues to not supply them
-when in compatibility mode (@pxref{Options}).
+Starting with @value{PVERSION} 5.2, @command{gawk}'s
+@option{--traditional} option no longer disables interval
+expressions in regular expressions.
POSIX says that interval expressions containing repetition counts greater
than 255 produce unspecified results.
@@ -6670,16 +6678,15 @@ are allowed.
@cindex Brian Kernighan's @command{awk}
@item @option{--traditional}
Match traditional Unix @command{awk} regexps. The GNU operators
-are not special, and interval expressions are not available.
-Because BWK @command{awk} supports them,
+are not special. Because BWK @command{awk} supports them,
the POSIX character classes (@samp{[[:alnum:]]}, etc.) are available.
+So too, interval expressions are allowed.
Characters described by octal and hexadecimal escape sequences are
treated literally, even if they represent regexp metacharacters.
@item @option{--re-interval}
-Allow interval expressions in regexps, if @option{--traditional}
-has been provided.
-Otherwise, interval expressions are available by default.
+This option remains for backwards compatibility but no longer has any
+real effect.
@end table
@node Case-sensitivity
@@ -10251,7 +10258,7 @@ infinity are formatted as
and positive infinity as
@samp{inf} or @samp{infinity}.
The special ``not a number'' value formats as @samp{-nan} or @samp{nan}
-(@pxref{Math Definitions}).
+(@pxref{Strange values}).
@item @code{%F}
Like @samp{%f}, but the infinity and ``not a number'' values are spelled
@@ -18385,6 +18392,7 @@ but are summarized here for your convenience.
@menu
* Calling Built-in:: How to call built-in functions.
+* Boolean Functions:: A function that returns Boolean values.
* Numeric Functions:: Functions that work with numbers, including
@code{int()}, @code{sin()} and @code{rand()}.
* String Functions:: Functions for string manipulation, such as
@@ -18454,6 +18462,25 @@ and 12. But if the order of evaluation is right to left, @code{i}
first becomes 10, then 11, and @code{atan2()} is called with the
two arguments 11 and 10.
+
+@node Boolean Functions
+@subsection Generating Boolean Values
+@cindex boolean function
+
+This function is specific to @command{gawk}. It is not
+available in compatibility mode (@pxref{Options}):
+
+@c @asis for docbook
+@table @asis
+@item @code{mkbool(@var{expression})}
+@cindexgawkfunc{mkbool}
+Return a Boolean-typed value based on the regular Boolean value
+of @var{expression}. Boolean ``true'' values have numeric value one.
+Boolean ``false'' values have numeric
+zero. This is discussed in more
+detail in @ref{Boolean Typed Values}.
+@end table
+
@node Numeric Functions
@subsection Numeric Functions
@cindex numeric @subentry functions
@@ -18518,7 +18545,7 @@ compatibility mode (@pxref{Options}).
@cindexawkfunc{log}
@cindex logarithm
Return the natural logarithm of @var{x}, if @var{x} is positive;
-otherwise, return @code{NaN} (``not a number'') on IEEE 754 systems.
+otherwise, return NaN (``not a number'') on IEEE 754 systems.
Additionally, @command{gawk} prints a warning message when @code{x}
is negative.
@@ -20993,6 +21020,9 @@ Return one of the following strings, depending upon the type of @var{x}:
@item "number"
@var{x} is a number.
+@item "number|bool"
+@var{x} is a Boolean typed value (@pxref{Boolean Typed Values}).
+
@item "string"
@var{x} is a string.
@@ -21894,7 +21924,7 @@ being aware of them.
@cindex pointers to functions
@cindex differences in @command{awk} and @command{gawk} @subentry indirect function calls
-This section describes an advanced, @command{gawk}-specific extension.
+This @value{SECTION} describes an advanced, @command{gawk}-specific extension.
Often, you may wish to defer the choice of function to call until runtime.
For example, you may have different kinds of records, each of which
@@ -29559,6 +29589,7 @@ discusses the ability to dynamically add new built-in functions to
@menu
* Nondecimal Data:: Allowing nondecimal input data.
+* Boolean Typed Values:: Values with @code{number|bool} type.
* Array Sorting:: Facilities for controlling array traversal and
sorting arrays.
* Two-way I/O:: Two-way communications with another process.
@@ -29625,6 +29656,49 @@ leads to less surprising results.
This option may disappear in a future version of @command{gawk}.
@end quotation
+@node Boolean Typed Values
+@section Boolean Typed Values
+
+Scalar values in @command{awk} are either numbers or strings.
+@command{gawk} also supports values of type @code{regexp}
+(@pxref{Strong Regexp Constants}).
+
+As described in @ref{Truth Values}, Boolean values in @command{awk}
+don't have a separate type: a value counts as ``true'' if it is nonzero
+or non-null, and as ``false'' otherwise.
+
+When interchanging data with languages that do have a real Boolean type,
+using a standard format such as JSON or XML, the lack of a true Boolean
+type in @command{awk} is problematic.
+(See, for example, the @code{json} extension provided by
+@uref{https://sourceforge.net/projects/gawkextlib, the @code{gawkextlib} project}.)
+
+It's easy to import Boolean data into @command{awk}, but then the fact
+that it was originally Boolean is lost. Exporting data is even harder;
+there's no way to indicate that a value is really Boolean.
+
+To solve this problem, @command{gawk} provides a function named @code{mkbool()}.
+It takes one argument, which is any @command{awk} expression, and it
+returns a value of Boolean type.
+
+The returned values are normal @command{awk} numeric values, with
+values of either one or zero,
+depending upon the truth
+value of the original expression passed in the call to @code{mkbool()}.
+
+The @code{typeof()} function (@pxref{Type Functions}) returns
+@code{"number|bool"} for these values.
+
+Thus Boolean-typed values @emph{are} numbers as far as @command{gawk}
+is concerned, except that extension code can treat them as Booleans
+if desired.
+
+While it would have been possible to add two new built-in variables
+of Boolean type named @code{TRUE} and @code{FALSE}, doing so would
+undoubtedly have broken many existing @command{awk} programs. Instead,
+having a ``generator'' function that creates Boolean values gives
+flexibility, without breaking as much existing code.
+
@node Array Sorting
@section Controlling Array Traversal and Array Sorting
@@ -33989,21 +34063,9 @@ A special value representing infinity. Operations involving another
number and infinity produce infinity.
@item NaN
-``Not a number.''@footnote{Thanks to Michael Brennan for this description,
-which we have paraphrased, and for the examples.} A special value that
-results from attempting a calculation that has no answer as a real number.
-In such a case, programs can either receive a floating-point exception,
-or get @code{NaN} back as the result. The IEEE 754 standard recommends
-that systems return @code{NaN}. Some examples:
-
-@table @code
-@item sqrt(-1)
-This makes sense in the range of complex numbers, but not in the
-range of real numbers, so the result is @code{NaN}.
-
-@item log(-8)
-@minus{}8 is out of the domain of @code{log()}, so the result is @code{NaN}.
-@end table
+``Not a number.'' A special value that results from attempting a
+calculation that has no answer as a real number. @xref{Strange values},
+for more information about infinity and not-a-number values.
@item Normalized
How the significand (see later in this list) is usually stored. The
@@ -34172,6 +34234,7 @@ decimal places in the final result.
* Inexact representation:: Numbers are not exactly represented.
* Comparing FP Values:: How to compare floating point values.
* Errors accumulate:: Errors get bigger as they go.
+* Strange values:: A few words about infinities and NaNs.
@end menu
@node Inexact representation
@@ -34293,6 +34356,242 @@ $ @kbd{gawk 'BEGIN @{}
@print{} 4
@end example
+@node Strange values
+@subsubsection Floating Point Values They Didn't Talk About In School
+
+Both IEEE 754 floating-point hardware, and MPFR, support two kinds of
+values that you probably didn't learn about in school. The first is
+@dfn{infinity}, a special value, that can be either negative or positive,
+and which is either smaller than any other value (negative infinity),
+or larger than any other value (positive infinity). When such values
+are generated, @command{gawk} prints them as either @samp{-inf} or
+@samp{+inf}, respectively. It accepts those strings as data input and
+converts them to the proper floating-point values internally.
+
+Infinity values of the same sign compare as equal to each other.
+Otherwise, operations (addition, subtraction, etc.) involving another
+number and infinity produce mathematically reasonable results.
+
+The second kind of value is ``not a number'', or NaN for
+short.@footnote{Thanks to Michael Brennan for this description, which we
+have paraphrased, and for the examples.} This is a special value that results
+from attempting a calculation that has no answer as a real number.
+In such a case, programs can either receive a floating-point exception,
+or get NaN back as the result. The IEEE 754 standard recommends
+that systems return NaN. Some examples:
+
+@table @code
+@item sqrt(-1)
+@iftex
+The @math{\sqrt{-1}}
+@end iftex
+@ifnottex
+This
+@end ifnottex
+makes sense in the range of complex numbers, but not in the
+range of real numbers, so the result is NaN.
+
+@item log(-8)
+@minus{}8 is out of the domain of @code{log()}, so the result is NaN.
+@end table
+
+NaN values are strange. In particular, they cannot be compared with other
+floating point values; any such comparison, except for ``is not equal
+to'', returns false. NaN values are so much unequal to other values that
+even comparing two identical NaN values with @code{!=} returns true!
+
+NaN values can also be signed, although it depends upon the implementation
+as to which sign you get for any operation that returns a NaN. For
+example, on some systems, @code{sqrt(-1)} returns a negative NaN. On
+others, it returns a positive NaN.
+
+When such values are generated, @command{gawk} prints them as either
+@samp{-nan} or @samp{+nan}, respectively. Here too, @command{gawk}
+accepts those strings as data input and converts them to the proper
+floating-point values internally.
+
+If you want to dive more deeply into this topic, you can find
+test programs in C, @command{awk} and Python in the directory
+@file{awklib/eg/test-programs} in the @command{gawk} distribution.
+These programs enable comparison among programming languages as to how
+they handle NaN and infinity values.
+
+@ignore
+@c file eg/test-programs/gen-float-table.awk
+function eq(left, right)
+@{
+ return left == right
+@}
+
+function ne(left, right)
+@{
+ return left != right
+@}
+
+function lt(left, right)
+@{
+ return left < right
+@}
+
+function le(left, right)
+@{
+ return left <= right
+@}
+
+function gt(left, right)
+@{
+ return left > right
+@}
+
+function ge(left, right)
+@{
+ return left >= right
+@}
+
+BEGIN @{
+ nan = sqrt(-1)
+ inf = -log(0)
+ split("== != < <= > >=", names)
+ names[3] = names[3] " "
+ names[5] = names[5] " "
+ split("eq ne lt le gt ge", funcs)
+
+ compare[1] = 2.0
+ compare[2] = values[1] = -sqrt(-1.0) # nan
+ compare[3] = values[2] = sqrt(-1.0) # -nan
+ compare[4] = values[3] = -log(0.0) # inf
+ compare[5] = values[4] = log(0.0) # -inf
+
+ for (i = 1; i in values; i++) @{
+ for (j = 1; j in compare; j++) @{
+ for (k = 1; k in names; k++) @{
+ the_func = funcs[k]
+ printf("%g %s %g -> %s\n",
+ values[i],
+ names[k],
+ compare[j],
+ @@the_func(values[i], compare[j]) ?
+ "True" : "False");
+ @}
+ printf("\n");
+ @}
+ @}
+@}
+@c endfile
+@end ignore
+
+@ignore
+@c file eg/test-programs/gen-float-table.c
+#include <stdio.h>
+#include <math.h>
+#include <stdbool.h>
+
+#define def_func(name, op) \
+ bool name(double left, double right) @{ \
+ return left op right; \
+ @}
+
+def_func(eq, ==)
+def_func(ne, !=)
+def_func(lt, <)
+def_func(le, <=)
+def_func(gt, >)
+def_func(ge, >=)
+
+struct @{
+ const char *name;
+ bool (*func)(double left, double right);
+@} functions[] = @{
+ @{ "==", eq @},
+ @{ "!=", ne @},
+ @{ "< ", lt @},
+ @{ "<=", le @},
+ @{ "> ", gt @},
+ @{ ">=", ge @},
+ @{ 0, 0 @}
+@};
+
+int main()
+@{
+ double values[] = @{
+ -sqrt(-1), // nan
+ sqrt(-1), // -nan
+ -log(0.0), // inf
+ log(0.0) // -inf
+ @};
+ double compare[] = @{ 2.0,
+ -sqrt(-1), // nan
+ sqrt(-1), // -nan
+ -log(0.0), // inf
+ log(0.0) // -inf
+ @};
+
+ int i, j, k;
+
+ for (i = 0; i < 4; i++) @{
+ for (j = 0; j < 5; j++) @{
+ for (k = 0; functions[k].name != NULL; k++) @{
+ printf("%g %s %g -> %s\n", values[i],
+ functions[k].name,
+ compare[j],
+ functions[k].func(values[i], compare[j]) ? "True" : "False");
+ @}
+ printf("\n");
+ @}
+ @}
+
+ return 0;
+@}
+@c endfile
+@end ignore
+
+@ignore
+@c file eg/test-programs/gen-float-table.py
+from math import *
+
+nan = float('NaN')
+inf = float('Inf')
+
+def eq(left, right):
+ return left == right
+
+def ne(left, right):
+ return left != right
+
+def lt(left, right):
+ return left < right
+
+def le(left, right):
+ return left <= right
+
+def gt(left, right):
+ return left > right
+
+def ge(left, right):
+ return left >= right
+
+func_map = {
+ "==": eq,
+ "!=": ne,
+ "< ": lt,
+ "<=": le,
+ "> ": gt,
+ ">=": ge,
+}
+
+compare = [2.0, nan, -nan, inf, -inf]
+values = [nan, -nan, inf, -inf]
+
+for i in range(len(values)):
+ for j in range(len(compare)):
+ for op in func_map:
+ print("%g %s %g -> %s" %
+ (values[i], op, compare[j], func_map[op](values[i], compare[j])))
+
+ print("")
+@c endfile
+@end ignore
+
@node Getting Accuracy
@subsection Getting the Accuracy You Need
@@ -35572,7 +35871,8 @@ multibyte encoding.
@itemx @ @ @ @ AWK_STRNUM,
@itemx @ @ @ @ AWK_ARRAY,
@itemx @ @ @ @ AWK_SCALAR,@ @ @ @ @ @ @ @ @ /* opaque access to a variable */
-@itemx @ @ @ @ AWK_VALUE_COOKIE@ @ @ @ /* for updating a previously created value */
+@itemx @ @ @ @ AWK_VALUE_COOKIE,@ @ @ /* for updating a previously created value */
+@itemx @ @ @ @ AWK_BOOL
@itemx @} awk_valtype_t;
This @code{enum} indicates the type of a value.
It is used in the following @code{struct}.
@@ -35585,6 +35885,7 @@ It is used in the following @code{struct}.
@itemx @ @ @ @ @ @ @ @ awk_array_t@ @ @ @ @ @ @ @ a;
@itemx @ @ @ @ @ @ @ @ awk_scalar_t@ @ @ @ @ @ @ scl;
@itemx @ @ @ @ @ @ @ @ awk_value_cookie_t@ vc;
+@itemx @ @ @ @ @ @ @ @ awk_bool_t@ @ @ @ @ @ @ @ @ b;
@itemx @ @ @ @ @} u;
@itemx @} awk_value_t;
An ``@command{awk} value.''
@@ -35600,6 +35901,7 @@ The @code{val_type} member indicates what kind of value the
@itemx #define array_cookie@ @ @ u.a
@itemx #define scalar_cookie@ @ u.scl
@itemx #define value_cookie@ @ @ u.vc
+@itemx #define bool_value@ @ @ @ @ u.b
Using these macros makes accessing the fields of the @code{awk_value_t} more
readable.
@@ -35927,6 +36229,11 @@ the regular expression of length @code{len}. It expects @code{string}
to be a @samp{char *} value pointing to data previously obtained from
@code{gawk_malloc()}, @code{gawk_calloc()}, or @code{gawk_realloc()}.
+@item static inline awk_value_t *
+@itemx make_bool(awk_bool_t boolval, awk_value_t *result);
+This function creates a boolean value in the @code{awk_value_t} variable
+pointed to by @code{result}.
+
@end table
@node API Ownership of MPFR and GMP Values
@@ -35947,8 +36254,13 @@ p = NULL; @ii{now} q @ii{``owns'' it}
MPFR and GMP objects are indeed allocated on the stack or dynamically,
but the MPFR and GMP libraries treat these objects as values, the same way that
you would pass an @code{int} or a @code{double} by value. There is no
-way to ``transfer ownership'' of MPFR and GMP objects. Thus, code in
-an extension should look like this:
+way to ``transfer ownership'' of MPFR and GMP objects.
+
+The final results of an MPFR or GMP calculation should be passed back
+to @command{gawk}, by value, as you would a string or a @code{double}.
+@command{gawk} will take care of freeing the storage.
+
+Thus, code in an extension should look like this:
@example
mpz_t part1, part2, answer; @ii{declare local values}
@@ -35962,9 +36274,8 @@ make_number_mpz(answer, & result); @ii{set it with final GMP value}
mpz_clear(part1); @ii{release intermediate values}
mpz_clear(part2);
-mpz_clear(answer);
-return result;
+return result; @ii{value in @code{answer} managed by @code{gawk}}
@end example
@node Registration Functions
@@ -36727,7 +37038,8 @@ value type, as appropriate. This behavior is summarized in
<colspec colname="c6"/>
<colspec colname="c7"/>
<colspec colname="c8"/>
- <spanspec spanname="hspan" namest="c3" nameend="c8" align="center"/>
+ <colspec colname="c9"/>
+ <spanspec spanname="hspan" namest="c3" nameend="c9" align="center"/>
<thead>
<row><entry></entry><entry spanname="hspan"><para>Type of Actual Value</para></entry></row>
<row>
@@ -36737,6 +37049,7 @@ value type, as appropriate. This behavior is summarized in
<entry><para>Strnum</para></entry>
<entry><para>Number</para></entry>
<entry><para>Regex</para></entry>
+ <entry><para>Bool</para></entry>
<entry><para>Array</para></entry>
<entry><para>Undefined</para></entry>
</row>
@@ -36749,6 +37062,7 @@ value type, as appropriate. This behavior is summarized in
<entry><para>String</para></entry>
<entry><para>String</para></entry>
<entry><para>String</para></entry>
+ <entry><para>String</para></entry>
<entry><para>false</para></entry>
<entry><para>false</para></entry>
</row>
@@ -36761,6 +37075,7 @@ value type, as appropriate. This behavior is summarized in
<entry><para>false</para></entry>
<entry><para>false</para></entry>
<entry><para>false</para></entry>
+ <entry><para>false</para></entry>
</row>
<row>
<entry></entry>
@@ -36769,6 +37084,7 @@ value type, as appropriate. This behavior is summarized in
<entry><para>Number</para></entry>
<entry><para>Number</para></entry>
<entry><para>false</para></entry>
+ <entry><para>Number</para></entry>
<entry><para>false</para></entry>
<entry><para>false</para></entry>
</row>
@@ -36777,6 +37093,7 @@ value type, as appropriate. This behavior is summarized in
<entry><para><emphasis role="bold">Regex</emphasis></para></entry>
<entry><para>false</para></entry>
<entry><para>false</para></entry>
+ <entry><para>false</para></entry>
<entry><para>Regex</para></entry>
<entry><para>false</para></entry>
<entry><para>false</para></entry>
@@ -36784,11 +37101,23 @@ value type, as appropriate. This behavior is summarized in
</row>
<row>
<entry><para><emphasis role="bold">Requested</emphasis></para></entry>
+ <entry><para><emphasis role="bold">Bool</emphasis></para></entry>
+ <entry><para>false</para></entry>
+ <entry><para>false</para></entry>
+ <entry><para>false</para></entry>
+ <entry><para>false</para></entry>
+ <entry><para>Bool</para></entry>
+ <entry><para>false</para></entry>
+ <entry><para>false</para></entry>
+ </row>
+ <row>
+ <entry><para></para></entry>
<entry><para><emphasis role="bold">Array</emphasis></para></entry>
<entry><para>false</para></entry>
<entry><para>false</para></entry>
<entry><para>false</para></entry>
<entry><para>false</para></entry>
+ <entry><para>false</para></entry>
<entry><para>Array</para></entry>
<entry><para>false</para></entry>
</row>
@@ -36799,6 +37128,7 @@ value type, as appropriate. This behavior is summarized in
<entry><para>Scalar</para></entry>
<entry><para>Scalar</para></entry>
<entry><para>Scalar</para></entry>
+ <entry><para>Scalar</para></entry>
<entry><para>false</para></entry>
<entry><para>false</para></entry>
</row>
@@ -36809,6 +37139,7 @@ value type, as appropriate. This behavior is summarized in
<entry><para>Strnum</para></entry>
<entry><para>Number</para></entry>
<entry><para>Regex</para></entry>
+ <entry><para>Bool</para></entry>
<entry><para>Array</para></entry>
<entry><para>Undefined</para></entry>
</row>
@@ -36821,6 +37152,7 @@ value type, as appropriate. This behavior is summarized in
<entry><para>false</para></entry>
<entry><para>false</para></entry>
<entry><para>false</para></entry>
+ <entry><para>false</para></entry>
</row>
</tbody>
</tgroup>
@@ -36837,43 +37169,46 @@ value type, as appropriate. This behavior is summarized in
\vglue-1.1\baselineskip
@end tex
@c @multitable @columnfractions .166 .166 .198 .15 .15 .166
-@multitable {Requested} {Undefined} {Number} {Number} {Scalar} {Regex} {Array} {Undefined}
-@headitem @tab @tab String @tab Strnum @tab Number @tab Regex @tab Array @tab Undefined
-@item @tab @b{String} @tab String @tab String @tab String @tab String @tab false @tab false
-@item @tab @b{Strnum} @tab false @tab Strnum @tab Strnum @tab false @tab false @tab false
-@item @tab @b{Number} @tab Number @tab Number @tab Number @tab false @tab false @tab false
-@item @b{Type} @tab @b{Regex} @tab false @tab false @tab false @tab Regex @tab false @tab false
-@item @b{Requested} @tab @b{Array} @tab false @tab false @tab false @tab false @tab Array @tab false
-@item @tab @b{Scalar} @tab Scalar @tab Scalar @tab Scalar @tab Scalar @tab false @tab false
-@item @tab @b{Undefined} @tab String @tab Strnum @tab Number @tab Regex @tab Array @tab Undefined
-@item @tab @b{Value cookie} @tab false @tab false @tab false @tab false @tab false @tab false
+@multitable {Requested} {Undefined} {Number} {Number} {Scalar} {Regex} {Number} {Array} {Undefined}
+@headitem @tab @tab String @tab Strnum @tab Number @tab Regex @tab Bool @tab Array @tab Undefined
+@item @tab @b{String} @tab String @tab String @tab String @tab String @tab String @tab false @tab false
+@item @tab @b{Strnum} @tab false @tab Strnum @tab Strnum @tab false @tab false @tab false @tab false
+@item @tab @b{Number} @tab Number @tab Number @tab Number @tab false @tab Number @tab false @tab false
+@item @b{Type} @tab @b{Regex} @tab false @tab false @tab false @tab Regex @tab false @tab false @tab false
+@item @b{Requested} @tab @b{Bool} @tab false @tab false @tab false @tab false @tab Bool @tab false @tab false
+@item @tab @b{Array} @tab false @tab false @tab false @tab false @tab false @tab Array @tab false
+@item @tab @b{Scalar} @tab Scalar @tab Scalar @tab Scalar @tab Scalar @tab Scalar @tab false @tab false
+@item @tab @b{Undefined} @tab String @tab Strnum @tab Number @tab Regex @tab Bool @tab Array @tab Undefined
+@item @tab @b{Value cookie} @tab false @tab false @tab false @tab false @tab false @tab false @tab false
@end multitable
@end ifnotdocbook
@end ifnotplaintext
@ifplaintext
@verbatim
- +-------------------------------------------------------+
- | Type of Actual Value: |
- +--------+--------+--------+--------+-------+-----------+
- | String | Strnum | Number | Regex | Array | Undefined |
-+-----------+-----------+--------+--------+--------+--------+-------+-----------+
-| | String | String | String | String | String | false | false |
-| +-----------+--------+--------+--------+--------+-------+-----------+
-| | Strnum | false | Strnum | Strnum | false | false | false |
-| +-----------+--------+--------+--------+--------+-------+-----------+
-| | Number | Number | Number | Number | false | false | false |
-| +-----------+--------+--------+--------+--------+-------+-----------+
-| | Regex | false | false | false | Regex | false | false |
-| Type +-----------+--------+--------+--------+--------+-------+-----------+
-| Requested | Array | false | false | false | false | Array | false |
-| +-----------+--------+--------+--------+--------+-------+-----------+
-| | Scalar | Scalar | Scalar | Scalar | Scalar | false | false |
-| +-----------+--------+--------+--------+--------+-------+-----------+
-| | Undefined | String | Strnum | Number | Regex | Array | Undefined |
-| +-----------+--------+--------+--------+--------+-------+-----------+
-| | Value | false | false | false | false | false | false |
-| | Cookie | | | | | | |
-+-----------+-----------+--------+--------+--------+--------+-------+-----------+
+ +----------------------------------------------------------------+
+ | Type of Actual Value: |
+ +--------+--------+--------+--------+--------+-------+-----------+
+ | String | Strnum | Number | Regex | Bool | Array | Undefined |
++-----------+-----------+--------+--------+--------+--------+--------+-------+-----------+
+| | String | String | String | String | String | String | false | false |
+| +-----------+--------+--------+--------+--------+--------+-------+-----------+
+| | Strnum | false | Strnum | Strnum | false | false | false | false |
+| +-----------+--------+--------+--------+--------+--------+-------+-----------+
+| | Number | Number | Number | Number | false | Number | false | false |
+| +-----------+--------+--------+--------+--------+--------+-------+-----------+
+| | Regex | false | false | false | Regex | false | false | false |
+| +-----------+--------+--------+--------+--------+--------+-------+-----------+
+| Type | Bool | false | false | false | false | Bool | false | false |
+| Requested +-----------+--------+--------+--------+--------+--------+-------+-----------+
+| | Array | false | false | false | false | false | Array | false |
+| +-----------+--------+--------+--------+--------+--------+-------+-----------+
+| | Scalar | Scalar | Scalar | Scalar | Scalar | Scalar | false | false |
+| +-----------+--------+--------+--------+--------+--------+-------+-----------+
+| | Undefined | String | Strnum | Number | Regex | Bool | Array | Undefined |
+| +-----------+--------+--------+--------+--------+--------+-------+-----------+
+| | Value | false | false | false | false | false | false | false |
+| | Cookie | | | | | | | |
++-----------+-----------+--------+--------+--------+--------+--------+-------+-----------+
@end verbatim
@end ifplaintext
@end float
@@ -39428,8 +39763,9 @@ is:
@node Extension Sample Read write array
@subsection Dumping and Restoring an Array
-The @code{rwarray} extension adds two functions,
-named @code{writea()} and @code{reada()}, as follows:
+The @code{rwarray} extension adds four functions,
+named @code{writea()}, @code{reada()},
+@code{writeall()} and @code{readall()}, as follows:
@table @code
@item @@load "rwarray"
@@ -39448,6 +39784,24 @@ success, or zero upon failure.
it reads the file named as its first argument, filling in
the array named as the second argument. It clears the array first.
Here too, the return value is one on success, or zero upon failure.
+
+@cindex @code{writeall()} extension function
+@item ret = writeall(file)
+This function takes a string argument, which is the name of the file
+to which to dump the state of all variables.
+Calling this function
+is completely equivalent to calling
+@code{writea(file, SYMTAB)}.
+It returns one on success, or zero upon failure
+
+@cindex @code{readall()} extension function
+@item ret = readall(file)
+This function takes a string argument, which is the name of the
+file from which to read the contents of various global variables.
+For each variable in the file, the data is loaded unless the variable
+already exists. If the variable already exists, the data for that variable
+in the file is ignored.
+It returns one on success, or zero upon failure.
@end table
The array created by @code{reada()} is identical to that written by
@@ -39465,6 +39819,13 @@ as native binary data. Thus, arrays containing only string data can
theoretically be dumped on systems with one byte order and restored on
systems with a different one, but this has not been tried.
+Note that the @code{writeall()} and @code{readall()} functions provide
+a mechanism for maintaining persistent state across repeated invocations of a
+program. If, for example, a program calculates some statistics based on the
+data in a series of files, it could save state using @code{writeall()} after
+processing N files, and then reload the state using @code{readall()} when
+the N+1st file arrives to update the results.
+
Here is an example:
@example
@@ -39473,6 +39834,10 @@ Here is an example:
ret = writea("arraydump.bin", array)
@dots{}
ret = reada("arraydump.bin", array)
+@dots{}
+ret = writeall("globalstate.bin")
+@dots{}
+ret = readall("globalstate.bin")
@end example
@node Extension Sample Readfile
@@ -43105,17 +43470,17 @@ to do something or not, report that too; it's a bug in the documentation!
@item
Before reporting a bug or trying to fix it yourself, try to isolate it
to the smallest possible @command{awk} program and input @value{DF} that
-reproduce the problem. Then send us:
-
-@itemize @bullet
-@item
-The program and @value{DF}.
+reproduce the problem.
@item
-Some idea of what kind of Unix system you're using.
+@cindex @command{gawkbug} utility
+Use the @command{gawkbug} program to submit the bug report. This
+program sets up a bug report template and opens it in your editor.
+You then need to edit it appropriately to include:
+@itemize @bullet
@item
-The compiler you used to compile @command{gawk}.
+The program and @value{DF}.
@item
The exact results
@@ -43123,17 +43488,16 @@ The exact results
us decide whether the problem is really in the documentation.
@item
-The version number of @command{gawk} you are using.
-You can get this information with the command @samp{gawk --version}.
+A fix if you have one.
@end itemize
@item
Do @emph{not} send screenshots. Instead, use copy/paste to send text, or
send files.
-@item
-Do send files as attachments, instead of inline. This avoids corruption
-by mailer programs out in the wilds of the Internet.
+@c @item
+@c Do send files as attachments, instead of inline. This avoids corruption
+@c by mailer programs out in the wilds of the Internet.
@item
Please be sure to send all mail in @emph{plain text},
@@ -43147,12 +43511,12 @@ understood in common by all the maintainers.}
@cindex @email{bug-gawk@@gnu.org} bug reporting address
@cindex email address for bug reports, @email{bug-gawk@@gnu.org}
@cindex bug reports, email address, @email{bug-gawk@@gnu.org}
-Once you have a precise problem description, send email to
+The @command{gawkbug} program sends email to
@EMAIL{bug-gawk@@gnu.org,bug dash gawk at gnu dot org}.
The @command{gawk} maintainers subscribe to this address, and
thus they will receive your bug report.
-Although you can send mail to the maintainers directly,
+Do @emph{not} send mail to the maintainers directly;
the bug reporting address is preferred because the
email list is archived at the GNU Project.
@@ -45574,8 +45938,8 @@ internationalized program to work in a particular language.
@item Logical Expression
An expression using the operators for logic, AND, OR, and NOT, written
-@samp{&&}, @samp{||}, and @samp{!} in @command{awk}. Often called Boolean
-expressions, after the mathematician who pioneered this kind of
+@samp{&&}, @samp{||}, and @samp{!} in @command{awk}. Often called @dfn{Boolean
+expressions}, after the mathematician who pioneered this kind of
mathematical logic.
@item Lvalue