aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog45
-rw-r--r--array.c15
-rw-r--r--awk.h6
-rw-r--r--awkgram.c1
-rw-r--r--awkgram.y1
-rw-r--r--bool.notes53
-rw-r--r--builtin.c42
-rw-r--r--doc/ChangeLog13
-rw-r--r--doc/gawk.116
-rw-r--r--doc/gawk.info1341
-rw-r--r--doc/gawk.texi171
-rw-r--r--doc/gawktexi.in171
-rw-r--r--eval.c1
-rw-r--r--extension/ChangeLog9
-rw-r--r--extension/rwarray.c40
-rw-r--r--extension/testext.c7
-rw-r--r--field.c2
-rw-r--r--gawkapi.c44
-rw-r--r--gawkapi.h63
-rw-r--r--main.c1
-rw-r--r--node.c22
-rw-r--r--pc/ChangeLog4
-rw-r--r--pc/Makefile.tst7
-rw-r--r--test/ChangeLog11
-rw-r--r--test/Makefile.am4
-rw-r--r--test/Makefile.in9
-rw-r--r--test/Maketests5
-rw-r--r--test/asortbool.awk19
-rw-r--r--test/asortbool.ok6
-rw-r--r--test/dumpvars.ok2
-rw-r--r--test/functab5.ok1
-rw-r--r--test/id.ok1
-rw-r--r--test/intest.awk4
-rw-r--r--test/rwarray.awk11
-rw-r--r--test/symtab11.ok1
-rw-r--r--test/symtab8.ok2
36 files changed, 1401 insertions, 750 deletions
diff --git a/ChangeLog b/ChangeLog
index 56deef6b..e4843cb8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,54 @@
+2021-03-30 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawk_api.h (gawk_api_minor_version): Increase to 2.
+ * gawk_api.c (+assign_bool): New function.
+ (node_to_awk_value): Finish updating for bool types and values.
+
+2021-03-22 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawkapi.h (make_bool): New inline function.
+ Update table of request/return types.
+ * gawkapi.c (awk_value_to_node): Add support for AWK_BOOL.
+ (node_to_awk_value): Start on same. Not yet complete.
+
2021-03-21 Arnold D. Robbins <arnold@skeeve.com>
* str_array.c (fnv1a_hash_string): New function.
(str_array_init): Use fnv1a_hash_string if AWK_HASH env var
set to "fnv1a".
+2021-03-20 Arnold D. Robbins <arnold@skeeve.com>
+
+ * array.c (do_sort_up_value_type): Add logic for handling bools.
+
+2021-03-08 Arnold D. Robbins <arnold@skeeve.com>
+
+ * awk.h (warn_bool, do_bool): Add function declarations.
+ * awkgram.y (tokentab): Add entry for "bool" builtin.
+ * builtin.c (warn_bool): New function.
+ (do_index, do_substr, do_toupper, do_tolower, do_match,
+ do_length): Call it.
+ (do_sub): If first arg to sub/gsub is bool, fatal error.
+ (do_bool): New function.
+ * field.c (do_split, do_patsplit): Call warn_bool.
+ * main.c (load_procinfo_bools): Removed function and call.
+
+2021-03-05 Arnold D. Robbins <arnold@skeeve.com>
+
+ Start on a bool type for gawk.
+
+ * awk.h (BOOL): New flag value.
+ (make_bool_node): Add declaration of new function.
+ (bool_val): Check for BOOL along with NUMBER.
+ * builtin.c (do_typeof): Add support for BOOL.
+ * eval.c (flags2str): Ditto.
+ * gawkapi.h (awk_val_type): Add AWK_BOOL.
+ (awk_value_t): Add awk_bool_t element to the union and macro for it.
+ (struct gawk_api): Update the table of request/return values.
+ * main.c (load_procinfo_bools): New function.
+ (load_procinfo): Call it.
+ * node.c (make_bool_node): New function.
+
2021-02-13 Arnold D. Robbins <arnold@skeeve.com>
* io.c (nextfile): Use the value of ARGC directly in the for
diff --git a/array.c b/array.c
index 50efddb2..b4ce86bc 100644
--- a/array.c
+++ b/array.c
@@ -1209,11 +1209,24 @@ do_sort_up_value_type(const void *p1, const void *p2)
(void) fixtype(n1);
(void) fixtype(n2);
+ /* 3a. Bools first */
+ if ((n1->flags & BOOL) != 0 && (n2->flags & BOOL) != 0) {
+ return cmp_numbers(n1, n2);
+ }
+
+ /* 3b. Numbers next */
if ((n1->flags & NUMBER) != 0 && (n2->flags & NUMBER) != 0) {
return cmp_numbers(n1, n2);
}
- /* 3. All numbers are less than all strings. This is aribitrary. */
+ /* 3c. Bools before everything else */
+ if ((n1->flags & BOOL) != 0 && (n2->flags & BOOL) == 0) {
+ return -1;
+ } else if ((n1->flags & BOOL) == 0 && (n2->flags & BOOL) != 0) {
+ return 1;
+ }
+
+ /* 3d. All numbers are less than all strings. This is aribitrary. */
if ((n1->flags & NUMBER) != 0 && (n2->flags & STRING) != 0) {
return -1;
} else if ((n1->flags & STRING) != 0 && (n2->flags & NUMBER) != 0) {
diff --git a/awk.h b/awk.h
index c9eec663..f4fa4d4d 100644
--- a/awk.h
+++ b/awk.h
@@ -463,6 +463,7 @@ typedef struct exp_node {
XARRAY = 0x10000,
NUMCONSTSTR = 0x20000, /* have string value for numeric constant */
REGEX = 0x40000, /* this is a typed regex */
+ BOOL = 0x80000, /* this is a boolean value */
} flags;
long valref;
} NODE;
@@ -1454,6 +1455,7 @@ extern bool is_identchar(int c);
extern NODE *make_regnode(NODETYPE type, NODE *exp);
extern bool validate_qualified_name(char *token);
/* builtin.c */
+extern void warn_bool(const char *func, int argnum, NODE *n);
extern double double_to_int(double d);
extern NODE *do_exp(int nargs);
extern NODE *do_fflush(int nargs);
@@ -1503,6 +1505,7 @@ extern int strncasecmpmbs(const unsigned char *,
const unsigned char *, size_t);
extern int sanitize_exit_status(int status);
extern void check_symtab_functab(NODE *dest, const char *fname, const char *msg);
+extern NODE *do_bool(int nargs);
/* debug.c */
extern void init_debug(void);
extern int debug_prog(INSTRUCTION *pc);
@@ -1714,6 +1717,7 @@ extern NODE *r_force_number(NODE *n);
extern NODE *r_format_val(const char *format, int index, NODE *s);
extern NODE *r_dupnode(NODE *n);
extern NODE *make_str_node(const char *s, size_t len, int flags);
+extern NODE *make_bool_node(bool value);
extern NODE *make_typed_regex(const char *re, size_t len);
extern void *more_blocks(int id);
extern int parse_escape(const char **string_ptr);
@@ -1995,7 +1999,7 @@ static inline bool
boolval(NODE *t)
{
(void) fixtype(t);
- if ((t->flags & NUMBER) != 0)
+ if ((t->flags & (BOOL|NUMBER)) != 0)
return ! is_zero(t);
return (t->stlen > 0);
}
diff --git a/awkgram.c b/awkgram.c
index 9c2700a3..40c3cbd2 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -4779,6 +4779,7 @@ static const struct token tokentab[] = {
{"asorti", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2)|A(3), do_asorti, 0},
{"atan2", Op_builtin, LEX_BUILTIN, NOT_OLD|A(2), do_atan2, MPF(atan2)},
{"bindtextdomain", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2), do_bindtextdomain, 0},
+{"bool", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_bool, 0},
{"break", Op_K_break, LEX_BREAK, 0, 0, 0},
{"case", Op_K_case, LEX_CASE, GAWKX, 0, 0},
{"close", Op_builtin, LEX_BUILTIN, NOT_OLD|A(1)|A(2), do_close, 0},
diff --git a/awkgram.y b/awkgram.y
index 6dfbe7e0..3fe0272b 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2277,6 +2277,7 @@ static const struct token tokentab[] = {
{"asorti", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2)|A(3), do_asorti, 0},
{"atan2", Op_builtin, LEX_BUILTIN, NOT_OLD|A(2), do_atan2, MPF(atan2)},
{"bindtextdomain", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2), do_bindtextdomain, 0},
+{"bool", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_bool, 0},
{"break", Op_K_break, LEX_BREAK, 0, 0, 0},
{"case", Op_K_case, LEX_CASE, GAWKX, 0, 0},
{"close", Op_builtin, LEX_BUILTIN, NOT_OLD|A(1)|A(2), do_close, 0},
diff --git a/bool.notes b/bool.notes
new file mode 100644
index 00000000..8e24c2b5
--- /dev/null
+++ b/bool.notes
@@ -0,0 +1,53 @@
+Thu Mar 18 21:05:29 IST 2021
+============================
+
+Design Notes for a Boolean Type in Gawk
+
+1. A new function bool(val) converts val to bool, returning Boolean TRUE
+or FALSE. This is the generator for boolean values and is enough to have
+instead of predefining new variables TRUE and FALSE.
+
+2. Assigning from a boolean value copies the bool type.
+
+3. Boolean variables have numeric values 1 and 0 respectively, and string
+values "TRUE" and "FALSE". Thus they differ from other variables where a
+"false" value must be zero and null.
+
+Given:
+
+ true = bool(1)
+ false = bool(0)
+
+this implies all of the following:
+
+ print(true) --> "TRUE"
+ print(false) --> "FALSE"
+ Same for %s in printf
+ Same for bool_var ""
+ printf %d gives 0/1
+
+4. typeof() returns "bool".
+
+5. Numeric operators treat booleans as numbers. asort() sorts booleans before
+numbers, and false before true.
+
+6. These string function generate a runtime fatal error
+if given an argument / target of boolean type:
+
+ gsub sub
+
+These functions merely treat the value as a string
+but issue a lint warning.
+
+ substr match index gensub
+ length split patsplit
+ tolower toupper
+
+7. Updates to API needed for an additional type, and the table
+for requested vs. returns.
+
+8. The following extensions need revising:
+
+ - JSON extension
+ - dump / read array extensions
+ - what else?
diff --git a/builtin.c b/builtin.c
index 1b612f4a..1158fad2 100644
--- a/builtin.c
+++ b/builtin.c
@@ -381,6 +381,8 @@ do_index(int nargs)
s1 = force_string(s1);
s2 = force_string(s2);
+ warn_bool("index", 1, s1);
+ warn_bool("index", 2, s2);
p1 = s1->stptr;
p2 = s2->stptr;
@@ -552,6 +554,7 @@ do_length(int nargs)
if (do_lint && (fixtype(tmp)->flags & STRING) == 0)
lintwarn(_("%s: received non-string argument"), "length");
tmp = force_string(tmp);
+ warn_bool("length", 1, tmp);
if (gawk_mb_cur_max > 1) {
tmp = force_wstring(tmp);
@@ -1779,6 +1782,16 @@ do_sqrt(int nargs)
return make_number((AWKNUM) sqrt(arg));
}
+/* warn_bool --- warn that bool parameter is used as a string */
+
+void
+warn_bool(const char *func, int argnum, NODE *n)
+{
+ if (do_lint && (n->flags & BOOL) != 0)
+ lintwarn(_("%s: argument %d of type bool used as a string"),
+ func, argnum);
+}
+
/* do_substr --- do the substr function */
NODE *
@@ -1802,6 +1815,7 @@ do_substr(int nargs)
DEREF(t1);
t1 = POP_STRING();
+ warn_bool("substr", 1, t1);
if (nargs == 3) {
if (! (d_length >= 1)) {
@@ -2407,6 +2421,7 @@ do_tolower(int nargs)
NODE *t1, *t2;
t1 = POP_SCALAR();
+ warn_bool("tolower", 1, t1);
if (do_lint && (fixtype(t1)->flags & STRING) == 0)
lintwarn(_("%s: received non-string argument"), "tolower");
t1 = force_string(t1);
@@ -2438,6 +2453,7 @@ do_toupper(int nargs)
NODE *t1, *t2;
t1 = POP_SCALAR();
+ warn_bool("toupper", 1, t1);
if (do_lint && (fixtype(t1)->flags & STRING) == 0)
lintwarn(_("%s: received non-string argument"), "toupper");
t1 = force_string(t1);
@@ -2662,6 +2678,7 @@ do_match(int nargs)
tre = POP();
rp = re_update(tre);
t1 = POP_STRING();
+ warn_bool("mastch", 1, t1);
rstart = research(rp, t1->stptr, 0, t1->stlen, RE_NEED_START);
if (rstart >= 0) { /* match succeded */
@@ -2882,6 +2899,7 @@ do_sub(int nargs, unsigned int flags)
rp = re_update(tmp);
target = POP_STRING(); /* original string */
+ warn_bool("gensub", 3, target);
glob_flag = POP_SCALAR(); /* value of global flag */
if ( (glob_flag->flags & STRING) != 0
@@ -2924,6 +2942,10 @@ do_sub(int nargs, unsigned int flags)
}
}
+ if ((target->flags & BOOL) != 0)
+ fatal(_("%s: target cannot be of type bool"),
+ (flags & GSUB) != 0 ? "gsub" : "sub");
+
global = (how_many == -1);
rep_node = POP_STRING(); /* replacement text */
@@ -4112,7 +4134,10 @@ do_typeof(int nargs)
}
break;
case Node_val:
- switch (fixtype(arg)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) {
+ switch (fixtype(arg)->flags & (STRING|NUMBER|USER_INPUT|REGEX|BOOL)) {
+ case BOOL:
+ res = "bool";
+ break;
case NUMBER:
res = "number";
break;
@@ -4321,3 +4346,18 @@ check_symtab_functab(NODE *dest, const char *fname, const char *msg)
else if (dest == func_table)
fatal(msg, fname, "FUNCTAB");
}
+
+/* do_bool --- create boolean values */
+
+NODE *
+do_bool(int nargs)
+{
+ NODE *tmp;
+ bool result;
+
+ tmp = POP_SCALAR();
+ result = boolval(tmp);
+ DEREF(tmp);
+
+ return make_bool_node(result);
+}
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 8e311ec8..9cf4aa3f 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,12 @@
+2021-04-06 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawktexi.in: Finish documenting bool features.
+ * gawk.1: Add minimal documentation on bool.
+
+2021-04-04 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawktexi.in: Start documenting bool features.
+
2021-04-04 Arnold D. Robbins <arnold@skeeve.com>
* gawktexi.in: Update menues.
@@ -9,6 +18,10 @@
<arkadiusz@drabczyk.org> for pointing out the lack of
documentation.
+2021-03-22 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawktexi.in (Constructor Functions): Add doc on `make_bool'.
+
2021-03-21 Arnold D. Robbins <arnold@skeeve.com>
* gawktexi.in (Other Environment Variables): Document "fnv1a"
diff --git a/doc/gawk.1 b/doc/gawk.1
index a8cf39f6..86ddd7c7 100644
--- a/doc/gawk.1
+++ b/doc/gawk.1
@@ -13,7 +13,7 @@
. if \w'\(rq' .ds rq "\(rq
. \}
.\}
-.TH GAWK 1 "Aug 31 2020" "Free Software Foundation" "Utility Commands"
+.TH GAWK 1 "Apr 6 2021" "Free Software Foundation" "Utility Commands"
.SH NAME
gawk \- pattern scanning and processing language
.SH SYNOPSIS
@@ -3480,6 +3480,16 @@ in \*(EP.
You must also supply a text domain. Use
.B TEXTDOMAIN
if you want to use the current domain.
+.SS Boolean Valued Functions
+You can create special Boolean-typed values; see the manual for how
+they work and why they exist.
+.TP
+.BI bool( expression\^ )
+Based on the boolean value of
+.I expression
+return either a true value or a false value.
+True values have numeric value one and string value \fB"TRUE"\fR.
+False values have numeric value zero and string value \fB"False"\fR.
.SH USER-DEFINED FUNCTIONS
Functions in \*(AK are defined as follows:
.PP
@@ -3700,7 +3710,7 @@ accommodate applications that depended upon the old behavior.
(This feature was agreed upon by both the Bell Laboratories developers
and the \*(GN developers.)
.PP
-When processing arguments,
+When procesiing arguments,
.I gawk
uses the special option \*(lq\-\^\-\*(rq to signal the end of
arguments.
@@ -4265,7 +4275,7 @@ We thank him.
.SH COPYING PERMISSIONS
Copyright \(co 1989, 1991, 1992, 1993, 1994, 1995, 1996,
1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2007, 2009,
-2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020,
+2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021,
Free Software Foundation, Inc.
.PP
Permission is granted to make and distribute verbatim copies of
diff --git a/doc/gawk.info b/doc/gawk.info
index f5f417a6..008160c7 100644
--- a/doc/gawk.info
+++ b/doc/gawk.info
@@ -381,6 +381,8 @@ in (a) below. A copy of the license is included in the section entitled
* 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 'int()', 'sin()'
and 'rand()'.
@@ -488,6 +490,7 @@ in (a) below. A copy of the license is included in the section entitled
* Programs Summary:: Summary of programs.
* Programs Exercises:: Exercises.
* Nondecimal Data:: Allowing nondecimal input data.
+* Boolean Typed Values:: Values with 'bool' type.
* Array Sorting:: Facilities for controlling array
traversal and sorting arrays.
* Controlling Array Traversal:: How to use PROCINFO["sorted_in"].
@@ -12782,6 +12785,7 @@ 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
'int()', 'sin()' and 'rand()'.
* String Functions:: Functions for string manipulation, such as
@@ -12794,7 +12798,7 @@ your convenience.
* I18N Functions:: Functions for string translation.

-File: gawk.info, Node: Calling Built-in, Next: Numeric Functions, Up: Built-in
+File: gawk.info, Node: Calling Built-in, Next: Boolean Functions, Up: Built-in
9.1.1 Calling Built-in Functions
--------------------------------
@@ -12838,9 +12842,25 @@ six, and then 12, and 'atan2()' is called with the two arguments six and
10, then 11, and 'atan2()' is called with the two arguments 11 and 10.

-File: gawk.info, Node: Numeric Functions, Next: String Functions, Prev: Calling Built-in, Up: Built-in
+File: gawk.info, Node: Boolean Functions, Next: Numeric Functions, Prev: Calling Built-in, Up: Built-in
-9.1.2 Numeric Functions
+9.1.2 Generating Boolean Values
+-------------------------------
+
+This function is specific to 'gawk'. It is not available in
+compatibility mode (*note Options::):
+
+'bool(EXPRESSION)'
+ Return a Boolean-typed value based on the regular Boolean value of
+ EXPRESSION. Boolean "true" values have numeric value one and
+ string value '"TRUE"'. Boolean "false" values have numeric zero
+ and string value '"FALSE"'. This is discussed in more detail in
+ *note Boolean Typed Values::.
+
+
+File: gawk.info, Node: Numeric Functions, Next: String Functions, Prev: Boolean Functions, Up: Built-in
+
+9.1.3 Numeric Functions
-----------------------
The following list describes all of the built-in functions that work
@@ -12964,7 +12984,7 @@ the same sequence of random numbers over and over again.

File: gawk.info, Node: String Functions, Next: I/O Functions, Prev: Numeric Functions, Up: Built-in
-9.1.3 String-Manipulation Functions
+9.1.4 String-Manipulation Functions
-----------------------------------
The functions in this minor node look at or change the text of one or
@@ -13532,7 +13552,7 @@ number zero.

File: gawk.info, Node: Gory Details, Up: String Functions
-9.1.3.1 More about '\' and '&' with 'sub()', 'gsub()', and 'gensub()'
+9.1.4.1 More about '\' and '&' with 'sub()', 'gsub()', and 'gensub()'
.....................................................................
CAUTION: This subsubsection has been reported to cause headaches.
@@ -13678,7 +13698,7 @@ POSIX rules.

File: gawk.info, Node: I/O Functions, Next: Time Functions, Prev: String Functions, Up: Built-in
-9.1.4 Input/Output Functions
+9.1.5 Input/Output Functions
----------------------------
The following functions relate to input/output (I/O). Optional
@@ -13895,7 +13915,7 @@ the way this was done was probably a mistake.

File: gawk.info, Node: Time Functions, Next: Bitwise Functions, Prev: I/O Functions, Up: Built-in
-9.1.5 Time Functions
+9.1.6 Time Functions
--------------------
'awk' programs are commonly used to process log files containing
@@ -14212,7 +14232,7 @@ does not appear in the returned string or appears literally.

File: gawk.info, Node: Bitwise Functions, Next: Type Functions, Prev: Time Functions, Up: Built-in
-9.1.6 Bit-Manipulation Functions
+9.1.7 Bit-Manipulation Functions
--------------------------------
I can explain it for you, but I can't understand it for you.
@@ -14394,7 +14414,7 @@ that range are reduced to fit within the range.

File: gawk.info, Node: Type Functions, Next: I18N Functions, Prev: Bitwise Functions, Up: Built-in
-9.1.7 Getting Type Information
+9.1.8 Getting Type Information
------------------------------
'gawk' provides two functions that let you distinguish the type of a
@@ -14411,6 +14431,9 @@ contexts.
'"array"'
X is an array.
+ '"bool"'
+ X is a Boolean typed value (*note Boolean Typed Values::).
+
'"regexp"'
X is a strongly typed regexp (*note Strong Regexp
Constants::).
@@ -14479,7 +14502,7 @@ arguments from untyped to unassigned.

File: gawk.info, Node: I18N Functions, Prev: Type Functions, Up: Built-in
-9.1.8 String-Translation Functions
+9.1.9 String-Translation Functions
----------------------------------
'gawk' provides facilities for internationalizing 'awk' programs. These
@@ -15158,7 +15181,7 @@ File: gawk.info, Node: Indirect Calls, Next: Functions Summary, Prev: User-de
9.3 Indirect Function Calls
===========================
-This section describes an advanced, 'gawk'-specific extension.
+This minor node describes an advanced, '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
@@ -20873,6 +20896,7 @@ their own:
* Menu:
* Nondecimal Data:: Allowing nondecimal input data.
+* Boolean Typed Values:: Values with 'bool' type.
* Array Sorting:: Facilities for controlling array traversal and
sorting arrays.
* Two-way I/O:: Two-way communications with another process.
@@ -20882,7 +20906,7 @@ their own:
* Advanced Features Summary:: Summary of advanced features.

-File: gawk.info, Node: Nondecimal Data, Next: Array Sorting, Up: Advanced Features
+File: gawk.info, Node: Nondecimal Data, Next: Boolean Typed Values, Up: Advanced Features
12.1 Allowing Nondecimal Input Data
===================================
@@ -20925,9 +20949,53 @@ request it.
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
+File: gawk.info, Node: Boolean Typed Values, Next: Array Sorting, Prev: Nondecimal Data, Up: Advanced Features
+
+12.2 Boolean Typed Values
+=========================
+
+Scalar values in 'awk' are either numbers or strings. 'gawk' also
+supports values of type 'regexp' (*note Strong Regexp Constants::).
+
+ As described in *note Truth Values::, Boolean values in 'awk' don't
+have a separate type: a value counts as "true" if it is nonzero or
+non-null, and as "false" otherwise.
-12.2 Controlling Array Traversal and Array Sorting
+ 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 'awk' is problematic. (See, for example, the 'json'
+extension provided by the 'gawkextlib' project
+(https://sourceforge.net/projects/gawkextlib).)
+
+ It's easy to import Boolean data into '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, 'gawk' provides a function named 'bool()'. It
+takes one argument, which is any 'awk' expression, and it returns a
+value of Boolean type.
+
+ The returned values are different than normal 'awk' values. When
+treated as numbers, they are either one or zero, depending upon the
+truth value of the original expression passed in the call to 'bool()'.
+When treated as strings, they are either '"TRUE"' or '"FALSE"', again
+depending upon the truth value of the expression passed in the call to
+'bool()'. The value for "false" is thus unusual; it is zero
+numerically, but not empty when treated as a string.
+
+ The 'typeof()' function (*note Type Functions::) returns '"bool"' for
+these values.
+
+ While it would have been possible to add two new built-in variables
+of Boolean type named 'TRUE' and 'FALSE', doing so would undoubtedly
+have broken many existing 'awk' programs. Instead, having a "generator"
+function that creates Boolean values gives flexibility, without breaking
+any existing code.
+
+
+File: gawk.info, Node: Array Sorting, Next: Two-way I/O, Prev: Boolean Typed Values, Up: Advanced Features
+
+12.3 Controlling Array Traversal and Array Sorting
==================================================
'gawk' lets you control the order in which a 'for (INDX in ARRAY)' loop
@@ -20946,7 +21014,7 @@ to order the elements during sorting.

File: gawk.info, Node: Controlling Array Traversal, Next: Array Sorting Functions, Up: Array Sorting
-12.2.1 Controlling Array Traversal
+12.3.1 Controlling Array Traversal
----------------------------------
By default, the order in which a 'for (INDX in ARRAY)' loop scans an
@@ -21185,7 +21253,7 @@ character, which cannot be part of an identifier.

File: gawk.info, Node: Array Sorting Functions, Prev: Controlling Array Traversal, Up: Array Sorting
-12.2.2 Sorting Array Values and Indices with 'gawk'
+12.3.2 Sorting Array Values and Indices with 'gawk'
---------------------------------------------------
In most 'awk' implementations, sorting an array requires writing a
@@ -21325,7 +21393,7 @@ POSIX-compatibility mode, and because 'asort()' and 'asorti()' are

File: gawk.info, Node: Two-way I/O, Next: TCP/IP Networking, Prev: Array Sorting, Up: Advanced Features
-12.3 Two-Way Communications with Another Process
+12.4 Two-Way Communications with Another Process
================================================
It is often useful to be able to send data to a separate program for
@@ -21520,7 +21588,7 @@ in Bash.

File: gawk.info, Node: TCP/IP Networking, Next: Profiling, Prev: Two-way I/O, Up: Advanced Features
-12.4 Using 'gawk' for Network Programming
+12.5 Using 'gawk' for Network Programming
=========================================
'EMRED':
@@ -21600,7 +21668,7 @@ complete introduction and discussion, as well as extensive examples.

File: gawk.info, Node: Profiling, Next: Extension Philosophy, Prev: TCP/IP Networking, Up: Advanced Features
-12.5 Profiling Your 'awk' Programs
+12.6 Profiling Your 'awk' Programs
==================================
You may produce execution traces of your 'awk' programs. This is done
@@ -21862,7 +21930,7 @@ source code, it will appear that way in the output.

File: gawk.info, Node: Extension Philosophy, Next: Advanced Features Summary, Prev: Profiling, Up: Advanced Features
-12.6 Builtin Features versus Extensions
+12.7 Builtin Features versus Extensions
=======================================
As this and subsequent major nodes show, 'gawk' has a large number of
@@ -21898,7 +21966,7 @@ or need.

File: gawk.info, Node: Advanced Features Summary, Prev: Extension Philosophy, Up: Advanced Features
-12.7 Summary
+12.8 Summary
============
* The '--non-decimal-data' option causes 'gawk' to treat octal- and
@@ -25520,7 +25588,8 @@ use them.
' AWK_STRNUM,'
' AWK_ARRAY,'
' AWK_SCALAR, /* opaque access to a variable */'
-' AWK_VALUE_COOKIE /* for updating a previously created value */'
+' AWK_VALUE_COOKIE, /* for updating a previously created value */'
+' AWK_BOOL'
'} awk_valtype_t;'
This 'enum' indicates the type of a value. It is used in the
following 'struct'.
@@ -25533,6 +25602,7 @@ use them.
' awk_array_t a;'
' awk_scalar_t scl;'
' awk_value_cookie_t vc;'
+' awk_bool_t b;'
' } u;'
'} awk_value_t;'
An "'awk' value." The 'val_type' member indicates what kind of
@@ -25548,6 +25618,7 @@ use them.
'#define array_cookie u.a'
'#define scalar_cookie u.scl'
'#define value_cookie u.vc'
+'#define bool_value u.b'
Using these macros makes accessing the fields of the 'awk_value_t'
more readable.
@@ -25858,6 +25929,11 @@ code would use them:
a 'char *' value pointing to data previously obtained from
'gawk_malloc()', 'gawk_calloc()', or 'gawk_realloc()'.
+'static inline awk_value_t *'
+'make_bool(awk_bool_t boolval, awk_value_t *result);'
+ This function creates a boolean value in the 'awk_value_t' variable
+ pointed to by 'result'.
+

File: gawk.info, Node: API Ownership of MPFR and GMP Values, Next: Registration Functions, Prev: Constructor Functions, Up: Extension API Description
@@ -26583,16 +26659,17 @@ summarized in *note Table 17.2: table-value-types-returned.
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
-Type Regex false false false Regex false false
-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
+ 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
+Type Regex false false false Regex false false false
+Requested Bool false false false false Bool false false
+ 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
Table 17.2: API value types returned
@@ -35308,8 +35385,10 @@ Index
* bitwise, XOR: Bitwise Functions. (line 57)
* body, in actions: Statements. (line 10)
* body, in loops: While Statement. (line 14)
+* bool: Boolean Functions. (line 10)
* Boolean expressions: Boolean Ops. (line 6)
* Boolean expressions, as patterns: Expression Patterns. (line 39)
+* boolean function: Boolean Functions. (line 6)
* Bourne shell, quoting rules for: Quoting. (line 18)
* braces ({}), regexp operator: Regexp Operator Details.
(line 118)
@@ -38116,604 +38195,606 @@ Index

Tag Table:
Node: Top1200
-Node: Foreword344859
-Node: Foreword449301
-Node: Preface50833
-Ref: Preface-Footnote-153692
-Ref: Preface-Footnote-253801
-Ref: Preface-Footnote-354035
-Node: History54177
-Node: Names56529
-Ref: Names-Footnote-157633
-Node: This Manual57780
-Ref: This Manual-Footnote-164419
-Node: Conventions64519
-Node: Manual History66888
-Ref: Manual History-Footnote-169885
-Ref: Manual History-Footnote-269926
-Node: How To Contribute70000
-Node: Acknowledgments70926
-Node: Getting Started75863
-Node: Running gawk78302
-Node: One-shot79492
-Node: Read Terminal80755
-Node: Long82748
-Node: Executable Scripts84261
-Ref: Executable Scripts-Footnote-186894
-Node: Comments86997
-Node: Quoting89481
-Node: DOS Quoting95007
-Node: Sample Data Files97063
-Node: Very Simple99658
-Node: Two Rules105760
-Node: More Complex107645
-Node: Statements/Lines109977
-Ref: Statements/Lines-Footnote-1114461
-Node: Other Features114726
-Node: When115662
-Ref: When-Footnote-1117416
-Node: Intro Summary117481
-Node: Invoking Gawk118365
-Node: Command Line119879
-Node: Options120677
-Ref: Options-Footnote-1138591
-Ref: Options-Footnote-2138822
-Node: Other Arguments138847
-Node: Naming Standard Input142858
-Node: Environment Variables144068
-Node: AWKPATH Variable144626
-Ref: AWKPATH Variable-Footnote-1148038
-Ref: AWKPATH Variable-Footnote-2148072
-Node: AWKLIBPATH Variable148443
-Ref: AWKLIBPATH Variable-Footnote-1150140
-Node: Other Environment Variables150515
-Node: Exit Status154467
-Node: Include Files155144
-Node: Loading Shared Libraries158834
-Node: Obsolete160262
-Node: Undocumented160954
-Node: Invoking Summary161251
-Node: Regexp164092
-Node: Regexp Usage165546
-Node: Escape Sequences167583
-Node: Regexp Operators173824
-Node: Regexp Operator Details174309
-Ref: Regexp Operator Details-Footnote-1181673
-Node: Interval Expressions181820
-Ref: Interval Expressions-Footnote-1183241
-Node: Bracket Expressions183339
-Ref: table-char-classes185815
-Node: Leftmost Longest189141
-Node: Computed Regexps190444
-Node: GNU Regexp Operators193871
-Node: Case-sensitivity197608
-Ref: Case-sensitivity-Footnote-1200474
-Ref: Case-sensitivity-Footnote-2200709
-Node: Regexp Summary200817
-Node: Reading Files202283
-Node: Records204552
-Node: awk split records205627
-Node: gawk split records210327
-Ref: gawk split records-Footnote-1215401
-Node: Fields215438
-Node: Nonconstant Fields218179
-Ref: Nonconstant Fields-Footnote-1220415
-Node: Changing Fields220619
-Node: Field Separators226650
-Node: Default Field Splitting229348
-Node: Regexp Field Splitting230466
-Node: Single Character Fields234143
-Node: Command Line Field Separator235203
-Node: Full Line Fields238421
-Ref: Full Line Fields-Footnote-1239943
-Ref: Full Line Fields-Footnote-2239989
-Node: Field Splitting Summary240090
-Node: Constant Size242164
-Node: Fixed width data242896
-Node: Skipping intervening246363
-Node: Allowing trailing data247161
-Node: Fields with fixed data248198
-Node: Splitting By Content249716
-Ref: Splitting By Content-Footnote-1253499
-Node: More CSV253662
-Node: Testing field creation255254
-Node: Multiple Line256879
-Node: Getline263156
-Node: Plain Getline265625
-Node: Getline/Variable268198
-Node: Getline/File269349
-Node: Getline/Variable/File270737
-Ref: Getline/Variable/File-Footnote-1272342
-Node: Getline/Pipe272430
-Node: Getline/Variable/Pipe275134
-Node: Getline/Coprocess276269
-Node: Getline/Variable/Coprocess277536
-Node: Getline Notes278278
-Node: Getline Summary281075
-Ref: table-getline-variants281499
-Node: Read Timeout282247
-Ref: Read Timeout-Footnote-1286153
-Node: Retrying Input286211
-Node: Command-line directories287410
-Node: Input Summary288316
-Node: Input Exercises291488
-Node: Printing291922
-Node: Print293756
-Node: Print Examples295213
-Node: Output Separators297993
-Node: OFMT300010
-Node: Printf301366
-Node: Basic Printf302151
-Node: Control Letters303725
-Node: Format Modifiers308887
-Node: Printf Examples314902
-Node: Redirection317388
-Node: Special FD324229
-Ref: Special FD-Footnote-1327397
-Node: Special Files327471
-Node: Other Inherited Files328088
-Node: Special Network329089
-Node: Special Caveats329949
-Node: Close Files And Pipes330898
-Ref: table-close-pipe-return-values337805
-Ref: Close Files And Pipes-Footnote-1338618
-Ref: Close Files And Pipes-Footnote-2338766
-Node: Nonfatal338918
-Node: Output Summary341256
-Node: Output Exercises342478
-Node: Expressions343157
-Node: Values344345
-Node: Constants345023
-Node: Scalar Constants345714
-Ref: Scalar Constants-Footnote-1348224
-Node: Nondecimal-numbers348474
-Node: Regexp Constants351475
-Node: Using Constant Regexps352001
-Node: Standard Regexp Constants352623
-Node: Strong Regexp Constants355811
-Node: Variables358823
-Node: Using Variables359480
-Node: Assignment Options361390
-Node: Conversion363861
-Node: Strings And Numbers364385
-Ref: Strings And Numbers-Footnote-1367448
-Node: Locale influences conversions367557
-Ref: table-locale-affects370315
-Node: All Operators370933
-Node: Arithmetic Ops371562
-Node: Concatenation374278
-Ref: Concatenation-Footnote-1377125
-Node: Assignment Ops377232
-Ref: table-assign-ops382223
-Node: Increment Ops383536
-Node: Truth Values and Conditions386996
-Node: Truth Values388070
-Node: Typing and Comparison389118
-Node: Variable Typing389938
-Ref: Variable Typing-Footnote-1396401
-Ref: Variable Typing-Footnote-2396473
-Node: Comparison Operators396550
-Ref: table-relational-ops396969
-Node: POSIX String Comparison400464
-Ref: POSIX String Comparison-Footnote-1402159
-Ref: POSIX String Comparison-Footnote-2402298
-Node: Boolean Ops402382
-Ref: Boolean Ops-Footnote-1406864
-Node: Conditional Exp406956
-Node: Function Calls408692
-Node: Precedence412569
-Node: Locales416228
-Node: Expressions Summary417860
-Node: Patterns and Actions420433
-Node: Pattern Overview421553
-Node: Regexp Patterns423230
-Node: Expression Patterns423772
-Node: Ranges427553
-Node: BEGIN/END430661
-Node: Using BEGIN/END431422
-Ref: Using BEGIN/END-Footnote-1434176
-Node: I/O And BEGIN/END434282
-Node: BEGINFILE/ENDFILE436595
-Node: Empty439826
-Node: Using Shell Variables440143
-Node: Action Overview442417
-Node: Statements444742
-Node: If Statement446590
-Node: While Statement448085
-Node: Do Statement450113
-Node: For Statement451261
-Node: Switch Statement454432
-Node: Break Statement456873
-Node: Continue Statement458965
-Node: Next Statement460792
-Node: Nextfile Statement463175
-Node: Exit Statement465864
-Node: Built-in Variables468267
-Node: User-modified469400
-Node: Auto-set477167
-Ref: Auto-set-Footnote-1493974
-Ref: Auto-set-Footnote-2494180
-Node: ARGC and ARGV494236
-Node: Pattern Action Summary498449
-Node: Arrays500879
-Node: Array Basics502208
-Node: Array Intro503052
-Ref: figure-array-elements505027
-Ref: Array Intro-Footnote-1507731
-Node: Reference to Elements507859
-Node: Assigning Elements510323
-Node: Array Example510814
-Node: Scanning an Array512573
-Node: Controlling Scanning515595
-Ref: Controlling Scanning-Footnote-1522051
-Node: Numeric Array Subscripts522367
-Node: Uninitialized Subscripts524551
-Node: Delete526170
-Ref: Delete-Footnote-1528922
-Node: Multidimensional528979
-Node: Multiscanning532074
-Node: Arrays of Arrays533665
-Node: Arrays Summary538433
-Node: Functions540526
-Node: Built-in541564
-Node: Calling Built-in542645
-Node: Numeric Functions544641
-Ref: Numeric Functions-Footnote-1548667
-Ref: Numeric Functions-Footnote-2549315
-Ref: Numeric Functions-Footnote-3549363
-Node: String Functions549635
-Ref: String Functions-Footnote-1573776
-Ref: String Functions-Footnote-2573904
-Ref: String Functions-Footnote-3574152
-Node: Gory Details574239
-Ref: table-sub-escapes576030
-Ref: table-sub-proposed577549
-Ref: table-posix-sub578912
-Ref: table-gensub-escapes580453
-Ref: Gory Details-Footnote-1581276
-Node: I/O Functions581430
-Ref: table-system-return-values587884
-Ref: I/O Functions-Footnote-1589964
-Ref: I/O Functions-Footnote-2590112
-Node: Time Functions590232
-Ref: Time Functions-Footnote-1600903
-Ref: Time Functions-Footnote-2600971
-Ref: Time Functions-Footnote-3601129
-Ref: Time Functions-Footnote-4601240
-Ref: Time Functions-Footnote-5601352
-Ref: Time Functions-Footnote-6601579
-Node: Bitwise Functions601845
-Ref: table-bitwise-ops602439
-Ref: Bitwise Functions-Footnote-1608502
-Ref: Bitwise Functions-Footnote-2608675
-Node: Type Functions608866
-Node: I18N Functions611729
-Node: User-defined613380
-Node: Definition Syntax614192
-Ref: Definition Syntax-Footnote-1619886
-Node: Function Example619957
-Ref: Function Example-Footnote-1622879
-Node: Function Calling622901
-Node: Calling A Function623489
-Node: Variable Scope624447
-Node: Pass By Value/Reference627441
-Node: Function Caveats630085
-Ref: Function Caveats-Footnote-1632132
-Node: Return Statement632252
-Node: Dynamic Typing635231
-Node: Indirect Calls636161
-Ref: Indirect Calls-Footnote-1646413
-Node: Functions Summary646541
-Node: Library Functions649246
-Ref: Library Functions-Footnote-1652853
-Ref: Library Functions-Footnote-2652996
-Node: Library Names653167
-Ref: Library Names-Footnote-1656834
-Ref: Library Names-Footnote-2657057
-Node: General Functions657143
-Node: Strtonum Function658246
-Node: Assert Function661268
-Node: Round Function664594
-Node: Cliff Random Function666134
-Node: Ordinal Functions667150
-Ref: Ordinal Functions-Footnote-1670213
-Ref: Ordinal Functions-Footnote-2670465
-Node: Join Function670675
-Ref: Join Function-Footnote-1672445
-Node: Getlocaltime Function672645
-Node: Readfile Function676387
-Node: Shell Quoting678364
-Node: Data File Management679765
-Node: Filetrans Function680397
-Node: Rewind Function684493
-Node: File Checking686402
-Ref: File Checking-Footnote-1687736
-Node: Empty Files687937
-Node: Ignoring Assigns689916
-Node: Getopt Function691466
-Ref: Getopt Function-Footnote-1706677
-Node: Passwd Functions706877
-Ref: Passwd Functions-Footnote-1715716
-Node: Group Functions715804
-Ref: Group Functions-Footnote-1723702
-Node: Walking Arrays723909
-Node: Library Functions Summary726917
-Node: Library Exercises728323
-Node: Sample Programs728788
-Node: Running Examples729558
-Node: Clones730286
-Node: Cut Program731510
-Node: Egrep Program741650
-Node: Id Program750651
-Node: Split Program760598
-Ref: Split Program-Footnote-1770488
-Node: Tee Program770661
-Node: Uniq Program773451
-Node: Wc Program781039
-Node: Bytes vs. Characters781426
-Node: Using extensions782974
-Node: wc program783728
-Node: Miscellaneous Programs788593
-Node: Dupword Program789806
-Node: Alarm Program791836
-Node: Translate Program796691
-Ref: Translate Program-Footnote-1801256
-Node: Labels Program801526
-Ref: Labels Program-Footnote-1804877
-Node: Word Sorting804961
-Node: History Sorting809033
-Node: Extract Program811258
-Node: Simple Sed819312
-Node: Igawk Program822386
-Ref: Igawk Program-Footnote-1836717
-Ref: Igawk Program-Footnote-2836919
-Ref: Igawk Program-Footnote-3837041
-Node: Anagram Program837156
-Node: Signature Program840218
-Node: Programs Summary841465
-Node: Programs Exercises842679
-Ref: Programs Exercises-Footnote-1846809
-Node: Advanced Features846895
-Node: Nondecimal Data848962
-Node: Array Sorting850553
-Node: Controlling Array Traversal851253
-Ref: Controlling Array Traversal-Footnote-1859621
-Node: Array Sorting Functions859739
-Ref: Array Sorting Functions-Footnote-1864830
-Node: Two-way I/O865026
-Ref: Two-way I/O-Footnote-1872747
-Ref: Two-way I/O-Footnote-2872934
-Node: TCP/IP Networking873016
-Node: Profiling876134
-Node: Extension Philosophy885443
-Node: Advanced Features Summary886922
-Node: Internationalization888937
-Node: I18N and L10N890417
-Node: Explaining gettext891104
-Ref: Explaining gettext-Footnote-1896996
-Ref: Explaining gettext-Footnote-2897181
-Node: Programmer i18n897346
-Ref: Programmer i18n-Footnote-1902295
-Node: Translator i18n902344
-Node: String Extraction903138
-Ref: String Extraction-Footnote-1904270
-Node: Printf Ordering904356
-Ref: Printf Ordering-Footnote-1907142
-Node: I18N Portability907206
-Ref: I18N Portability-Footnote-1909662
-Node: I18N Example909725
-Ref: I18N Example-Footnote-1913000
-Ref: I18N Example-Footnote-2913073
-Node: Gawk I18N913182
-Node: I18N Summary913831
-Node: Debugger915172
-Node: Debugging916172
-Node: Debugging Concepts916613
-Node: Debugging Terms918422
-Node: Awk Debugging920997
-Ref: Awk Debugging-Footnote-1921942
-Node: Sample Debugging Session922074
-Node: Debugger Invocation922608
-Node: Finding The Bug923994
-Node: List of Debugger Commands930468
-Node: Breakpoint Control931801
-Node: Debugger Execution Control935495
-Node: Viewing And Changing Data938857
-Node: Execution Stack942398
-Node: Debugger Info944035
-Node: Miscellaneous Debugger Commands948106
-Node: Readline Support953168
-Node: Limitations954064
-Node: Debugging Summary956618
-Node: Namespaces957897
-Node: Global Namespace959008
-Node: Qualified Names960406
-Node: Default Namespace961405
-Node: Changing The Namespace962146
-Node: Naming Rules963760
-Node: Internal Name Management965608
-Node: Namespace Example966650
-Node: Namespace And Features969212
-Node: Namespace Summary970647
-Node: Arbitrary Precision Arithmetic972124
-Node: Computer Arithmetic973611
-Ref: table-numeric-ranges977377
-Ref: table-floating-point-ranges977870
-Ref: Computer Arithmetic-Footnote-1978528
-Node: Math Definitions978585
-Ref: table-ieee-formats981561
-Node: MPFR features982128
-Node: FP Math Caution983846
-Ref: FP Math Caution-Footnote-1984918
-Node: Inexactness of computations985287
-Node: Inexact representation986318
-Node: Comparing FP Values987678
-Node: Errors accumulate988919
-Node: Strange values990375
-Ref: Strange values-Footnote-1992963
-Node: Getting Accuracy993068
-Node: Try To Round995778
-Node: Setting precision996677
-Ref: table-predefined-precision-strings997374
-Node: Setting the rounding mode999204
-Ref: table-gawk-rounding-modes999578
-Ref: Setting the rounding mode-Footnote-11003509
-Node: Arbitrary Precision Integers1003688
-Ref: Arbitrary Precision Integers-Footnote-11006863
-Node: Checking for MPFR1007012
-Node: POSIX Floating Point Problems1008486
-Ref: POSIX Floating Point Problems-Footnote-11012771
-Node: Floating point summary1012809
-Node: Dynamic Extensions1014999
-Node: Extension Intro1016552
-Node: Plugin License1017818
-Node: Extension Mechanism Outline1018615
-Ref: figure-load-extension1019054
-Ref: figure-register-new-function1020619
-Ref: figure-call-new-function1021711
-Node: Extension API Description1023773
-Node: Extension API Functions Introduction1025486
-Ref: table-api-std-headers1027322
-Node: General Data Types1031571
-Ref: General Data Types-Footnote-11040201
-Node: Memory Allocation Functions1040500
-Ref: Memory Allocation Functions-Footnote-11045001
-Node: Constructor Functions1045100
-Node: API Ownership of MPFR and GMP Values1048566
-Node: Registration Functions1049879
-Node: Extension Functions1050579
-Node: Exit Callback Functions1055901
-Node: Extension Version String1057151
-Node: Input Parsers1057814
-Node: Output Wrappers1070535
-Node: Two-way processors1075047
-Node: Printing Messages1077312
-Ref: Printing Messages-Footnote-11078483
-Node: Updating ERRNO1078636
-Node: Requesting Values1079375
-Ref: table-value-types-returned1080112
-Node: Accessing Parameters1081048
-Node: Symbol Table Access1082285
-Node: Symbol table by name1082797
-Ref: Symbol table by name-Footnote-11085821
-Node: Symbol table by cookie1085949
-Ref: Symbol table by cookie-Footnote-11090134
-Node: Cached values1090198
-Ref: Cached values-Footnote-11093734
-Node: Array Manipulation1093887
-Ref: Array Manipulation-Footnote-11094978
-Node: Array Data Types1095015
-Ref: Array Data Types-Footnote-11097673
-Node: Array Functions1097765
-Node: Flattening Arrays1102263
-Node: Creating Arrays1109239
-Node: Redirection API1114006
-Node: Extension API Variables1116839
-Node: Extension Versioning1117550
-Ref: gawk-api-version1117979
-Node: Extension GMP/MPFR Versioning1119710
-Node: Extension API Informational Variables1121338
-Node: Extension API Boilerplate1122411
-Node: Changes from API V11126385
-Node: Finding Extensions1127957
-Node: Extension Example1128516
-Node: Internal File Description1129314
-Node: Internal File Ops1133394
-Ref: Internal File Ops-Footnote-11144744
-Node: Using Internal File Ops1144884
-Ref: Using Internal File Ops-Footnote-11147267
-Node: Extension Samples1147541
-Node: Extension Sample File Functions1149070
-Node: Extension Sample Fnmatch1156719
-Node: Extension Sample Fork1158206
-Node: Extension Sample Inplace1159424
-Node: Extension Sample Ord1163050
-Node: Extension Sample Readdir1163886
-Ref: table-readdir-file-types1164775
-Node: Extension Sample Revout1165842
-Node: Extension Sample Rev2way1166431
-Node: Extension Sample Read write array1167171
-Node: Extension Sample Readfile1169113
-Node: Extension Sample Time1170208
-Node: Extension Sample API Tests1171960
-Node: gawkextlib1172452
-Node: Extension summary1175370
-Node: Extension Exercises1179072
-Node: Language History1180314
-Node: V7/SVR3.11181970
-Node: SVR41184122
-Node: POSIX1185556
-Node: BTL1186937
-Node: POSIX/GNU1187666
-Node: Feature History1193444
-Node: Common Extensions1209763
-Node: Ranges and Locales1211046
-Ref: Ranges and Locales-Footnote-11215662
-Ref: Ranges and Locales-Footnote-21215689
-Ref: Ranges and Locales-Footnote-31215924
-Node: Contributors1216147
-Node: History summary1222144
-Node: Installation1223524
-Node: Gawk Distribution1224468
-Node: Getting1224952
-Node: Extracting1225915
-Node: Distribution contents1227553
-Node: Unix Installation1234033
-Node: Quick Installation1234715
-Node: Shell Startup Files1237129
-Node: Additional Configuration Options1238218
-Node: Configuration Philosophy1240533
-Node: Non-Unix Installation1242902
-Node: PC Installation1243362
-Node: PC Binary Installation1244200
-Node: PC Compiling1244635
-Node: PC Using1245752
-Node: Cygwin1249305
-Node: MSYS1250529
-Node: VMS Installation1251131
-Node: VMS Compilation1251922
-Ref: VMS Compilation-Footnote-11253151
-Node: VMS Dynamic Extensions1253209
-Node: VMS Installation Details1254894
-Node: VMS Running1257147
-Node: VMS GNV1261426
-Node: VMS Old Gawk1262161
-Node: Bugs1262632
-Node: Bug address1263295
-Node: Usenet1266277
-Node: Maintainers1267281
-Node: Other Versions1268466
-Node: Installation summary1276331
-Node: Notes1277540
-Node: Compatibility Mode1278334
-Node: Additions1279116
-Node: Accessing The Source1280041
-Node: Adding Code1281478
-Node: New Ports1287697
-Node: Derived Files1292072
-Ref: Derived Files-Footnote-11297732
-Ref: Derived Files-Footnote-21297767
-Ref: Derived Files-Footnote-31298365
-Node: Future Extensions1298479
-Node: Implementation Limitations1299137
-Node: Extension Design1300347
-Node: Old Extension Problems1301491
-Ref: Old Extension Problems-Footnote-11303009
-Node: Extension New Mechanism Goals1303066
-Ref: Extension New Mechanism Goals-Footnote-11306430
-Node: Extension Other Design Decisions1306619
-Node: Extension Future Growth1308732
-Node: Notes summary1309338
-Node: Basic Concepts1310496
-Node: Basic High Level1311177
-Ref: figure-general-flow1311459
-Ref: figure-process-flow1312144
-Ref: Basic High Level-Footnote-11315445
-Node: Basic Data Typing1315630
-Node: Glossary1318958
-Node: Copying1350843
-Node: GNU Free Documentation License1388386
-Node: Index1413506
+Node: Foreword345044
+Node: Foreword449486
+Node: Preface51018
+Ref: Preface-Footnote-153877
+Ref: Preface-Footnote-253986
+Ref: Preface-Footnote-354220
+Node: History54362
+Node: Names56714
+Ref: Names-Footnote-157818
+Node: This Manual57965
+Ref: This Manual-Footnote-164604
+Node: Conventions64704
+Node: Manual History67073
+Ref: Manual History-Footnote-170070
+Ref: Manual History-Footnote-270111
+Node: How To Contribute70185
+Node: Acknowledgments71111
+Node: Getting Started76048
+Node: Running gawk78487
+Node: One-shot79677
+Node: Read Terminal80940
+Node: Long82933
+Node: Executable Scripts84446
+Ref: Executable Scripts-Footnote-187079
+Node: Comments87182
+Node: Quoting89666
+Node: DOS Quoting95192
+Node: Sample Data Files97248
+Node: Very Simple99843
+Node: Two Rules105945
+Node: More Complex107830
+Node: Statements/Lines110162
+Ref: Statements/Lines-Footnote-1114646
+Node: Other Features114911
+Node: When115847
+Ref: When-Footnote-1117601
+Node: Intro Summary117666
+Node: Invoking Gawk118550
+Node: Command Line120064
+Node: Options120862
+Ref: Options-Footnote-1138776
+Ref: Options-Footnote-2139007
+Node: Other Arguments139032
+Node: Naming Standard Input143043
+Node: Environment Variables144253
+Node: AWKPATH Variable144811
+Ref: AWKPATH Variable-Footnote-1148223
+Ref: AWKPATH Variable-Footnote-2148257
+Node: AWKLIBPATH Variable148628
+Ref: AWKLIBPATH Variable-Footnote-1150325
+Node: Other Environment Variables150700
+Node: Exit Status154652
+Node: Include Files155329
+Node: Loading Shared Libraries159019
+Node: Obsolete160447
+Node: Undocumented161139
+Node: Invoking Summary161436
+Node: Regexp164277
+Node: Regexp Usage165731
+Node: Escape Sequences167768
+Node: Regexp Operators174009
+Node: Regexp Operator Details174494
+Ref: Regexp Operator Details-Footnote-1181858
+Node: Interval Expressions182005
+Ref: Interval Expressions-Footnote-1183426
+Node: Bracket Expressions183524
+Ref: table-char-classes186000
+Node: Leftmost Longest189326
+Node: Computed Regexps190629
+Node: GNU Regexp Operators194056
+Node: Case-sensitivity197793
+Ref: Case-sensitivity-Footnote-1200659
+Ref: Case-sensitivity-Footnote-2200894
+Node: Regexp Summary201002
+Node: Reading Files202468
+Node: Records204737
+Node: awk split records205812
+Node: gawk split records210512
+Ref: gawk split records-Footnote-1215586
+Node: Fields215623
+Node: Nonconstant Fields218364
+Ref: Nonconstant Fields-Footnote-1220600
+Node: Changing Fields220804
+Node: Field Separators226835
+Node: Default Field Splitting229533
+Node: Regexp Field Splitting230651
+Node: Single Character Fields234328
+Node: Command Line Field Separator235388
+Node: Full Line Fields238606
+Ref: Full Line Fields-Footnote-1240128
+Ref: Full Line Fields-Footnote-2240174
+Node: Field Splitting Summary240275
+Node: Constant Size242349
+Node: Fixed width data243081
+Node: Skipping intervening246548
+Node: Allowing trailing data247346
+Node: Fields with fixed data248383
+Node: Splitting By Content249901
+Ref: Splitting By Content-Footnote-1253684
+Node: More CSV253847
+Node: Testing field creation255439
+Node: Multiple Line257064
+Node: Getline263341
+Node: Plain Getline265810
+Node: Getline/Variable268383
+Node: Getline/File269534
+Node: Getline/Variable/File270922
+Ref: Getline/Variable/File-Footnote-1272527
+Node: Getline/Pipe272615
+Node: Getline/Variable/Pipe275319
+Node: Getline/Coprocess276454
+Node: Getline/Variable/Coprocess277721
+Node: Getline Notes278463
+Node: Getline Summary281260
+Ref: table-getline-variants281684
+Node: Read Timeout282432
+Ref: Read Timeout-Footnote-1286338
+Node: Retrying Input286396
+Node: Command-line directories287595
+Node: Input Summary288501
+Node: Input Exercises291673
+Node: Printing292107
+Node: Print293941
+Node: Print Examples295398
+Node: Output Separators298178
+Node: OFMT300195
+Node: Printf301551
+Node: Basic Printf302336
+Node: Control Letters303910
+Node: Format Modifiers309072
+Node: Printf Examples315087
+Node: Redirection317573
+Node: Special FD324414
+Ref: Special FD-Footnote-1327582
+Node: Special Files327656
+Node: Other Inherited Files328273
+Node: Special Network329274
+Node: Special Caveats330134
+Node: Close Files And Pipes331083
+Ref: table-close-pipe-return-values337990
+Ref: Close Files And Pipes-Footnote-1338803
+Ref: Close Files And Pipes-Footnote-2338951
+Node: Nonfatal339103
+Node: Output Summary341441
+Node: Output Exercises342663
+Node: Expressions343342
+Node: Values344530
+Node: Constants345208
+Node: Scalar Constants345899
+Ref: Scalar Constants-Footnote-1348409
+Node: Nondecimal-numbers348659
+Node: Regexp Constants351660
+Node: Using Constant Regexps352186
+Node: Standard Regexp Constants352808
+Node: Strong Regexp Constants355996
+Node: Variables359008
+Node: Using Variables359665
+Node: Assignment Options361575
+Node: Conversion364046
+Node: Strings And Numbers364570
+Ref: Strings And Numbers-Footnote-1367633
+Node: Locale influences conversions367742
+Ref: table-locale-affects370500
+Node: All Operators371118
+Node: Arithmetic Ops371747
+Node: Concatenation374463
+Ref: Concatenation-Footnote-1377310
+Node: Assignment Ops377417
+Ref: table-assign-ops382408
+Node: Increment Ops383721
+Node: Truth Values and Conditions387181
+Node: Truth Values388255
+Node: Typing and Comparison389303
+Node: Variable Typing390123
+Ref: Variable Typing-Footnote-1396586
+Ref: Variable Typing-Footnote-2396658
+Node: Comparison Operators396735
+Ref: table-relational-ops397154
+Node: POSIX String Comparison400649
+Ref: POSIX String Comparison-Footnote-1402344
+Ref: POSIX String Comparison-Footnote-2402483
+Node: Boolean Ops402567
+Ref: Boolean Ops-Footnote-1407049
+Node: Conditional Exp407141
+Node: Function Calls408877
+Node: Precedence412754
+Node: Locales416413
+Node: Expressions Summary418045
+Node: Patterns and Actions420618
+Node: Pattern Overview421738
+Node: Regexp Patterns423415
+Node: Expression Patterns423957
+Node: Ranges427738
+Node: BEGIN/END430846
+Node: Using BEGIN/END431607
+Ref: Using BEGIN/END-Footnote-1434361
+Node: I/O And BEGIN/END434467
+Node: BEGINFILE/ENDFILE436780
+Node: Empty440011
+Node: Using Shell Variables440328
+Node: Action Overview442602
+Node: Statements444927
+Node: If Statement446775
+Node: While Statement448270
+Node: Do Statement450298
+Node: For Statement451446
+Node: Switch Statement454617
+Node: Break Statement457058
+Node: Continue Statement459150
+Node: Next Statement460977
+Node: Nextfile Statement463360
+Node: Exit Statement466049
+Node: Built-in Variables468452
+Node: User-modified469585
+Node: Auto-set477352
+Ref: Auto-set-Footnote-1494159
+Ref: Auto-set-Footnote-2494365
+Node: ARGC and ARGV494421
+Node: Pattern Action Summary498634
+Node: Arrays501064
+Node: Array Basics502393
+Node: Array Intro503237
+Ref: figure-array-elements505212
+Ref: Array Intro-Footnote-1507916
+Node: Reference to Elements508044
+Node: Assigning Elements510508
+Node: Array Example510999
+Node: Scanning an Array512758
+Node: Controlling Scanning515780
+Ref: Controlling Scanning-Footnote-1522236
+Node: Numeric Array Subscripts522552
+Node: Uninitialized Subscripts524736
+Node: Delete526355
+Ref: Delete-Footnote-1529107
+Node: Multidimensional529164
+Node: Multiscanning532259
+Node: Arrays of Arrays533850
+Node: Arrays Summary538618
+Node: Functions540711
+Node: Built-in541749
+Node: Calling Built-in542902
+Node: Boolean Functions544898
+Node: Numeric Functions545508
+Ref: Numeric Functions-Footnote-1549535
+Ref: Numeric Functions-Footnote-2550183
+Ref: Numeric Functions-Footnote-3550231
+Node: String Functions550503
+Ref: String Functions-Footnote-1574644
+Ref: String Functions-Footnote-2574772
+Ref: String Functions-Footnote-3575020
+Node: Gory Details575107
+Ref: table-sub-escapes576898
+Ref: table-sub-proposed578417
+Ref: table-posix-sub579780
+Ref: table-gensub-escapes581321
+Ref: Gory Details-Footnote-1582144
+Node: I/O Functions582298
+Ref: table-system-return-values588752
+Ref: I/O Functions-Footnote-1590832
+Ref: I/O Functions-Footnote-2590980
+Node: Time Functions591100
+Ref: Time Functions-Footnote-1601771
+Ref: Time Functions-Footnote-2601839
+Ref: Time Functions-Footnote-3601997
+Ref: Time Functions-Footnote-4602108
+Ref: Time Functions-Footnote-5602220
+Ref: Time Functions-Footnote-6602447
+Node: Bitwise Functions602713
+Ref: table-bitwise-ops603307
+Ref: Bitwise Functions-Footnote-1609370
+Ref: Bitwise Functions-Footnote-2609543
+Node: Type Functions609734
+Node: I18N Functions612681
+Node: User-defined614332
+Node: Definition Syntax615144
+Ref: Definition Syntax-Footnote-1620838
+Node: Function Example620909
+Ref: Function Example-Footnote-1623831
+Node: Function Calling623853
+Node: Calling A Function624441
+Node: Variable Scope625399
+Node: Pass By Value/Reference628393
+Node: Function Caveats631037
+Ref: Function Caveats-Footnote-1633084
+Node: Return Statement633204
+Node: Dynamic Typing636183
+Node: Indirect Calls637113
+Ref: Indirect Calls-Footnote-1647368
+Node: Functions Summary647496
+Node: Library Functions650201
+Ref: Library Functions-Footnote-1653808
+Ref: Library Functions-Footnote-2653951
+Node: Library Names654122
+Ref: Library Names-Footnote-1657789
+Ref: Library Names-Footnote-2658012
+Node: General Functions658098
+Node: Strtonum Function659201
+Node: Assert Function662223
+Node: Round Function665549
+Node: Cliff Random Function667089
+Node: Ordinal Functions668105
+Ref: Ordinal Functions-Footnote-1671168
+Ref: Ordinal Functions-Footnote-2671420
+Node: Join Function671630
+Ref: Join Function-Footnote-1673400
+Node: Getlocaltime Function673600
+Node: Readfile Function677342
+Node: Shell Quoting679319
+Node: Data File Management680720
+Node: Filetrans Function681352
+Node: Rewind Function685448
+Node: File Checking687357
+Ref: File Checking-Footnote-1688691
+Node: Empty Files688892
+Node: Ignoring Assigns690871
+Node: Getopt Function692421
+Ref: Getopt Function-Footnote-1707632
+Node: Passwd Functions707832
+Ref: Passwd Functions-Footnote-1716671
+Node: Group Functions716759
+Ref: Group Functions-Footnote-1724657
+Node: Walking Arrays724864
+Node: Library Functions Summary727872
+Node: Library Exercises729278
+Node: Sample Programs729743
+Node: Running Examples730513
+Node: Clones731241
+Node: Cut Program732465
+Node: Egrep Program742605
+Node: Id Program751606
+Node: Split Program761553
+Ref: Split Program-Footnote-1771443
+Node: Tee Program771616
+Node: Uniq Program774406
+Node: Wc Program781994
+Node: Bytes vs. Characters782381
+Node: Using extensions783929
+Node: wc program784683
+Node: Miscellaneous Programs789548
+Node: Dupword Program790761
+Node: Alarm Program792791
+Node: Translate Program797646
+Ref: Translate Program-Footnote-1802211
+Node: Labels Program802481
+Ref: Labels Program-Footnote-1805832
+Node: Word Sorting805916
+Node: History Sorting809988
+Node: Extract Program812213
+Node: Simple Sed820267
+Node: Igawk Program823341
+Ref: Igawk Program-Footnote-1837672
+Ref: Igawk Program-Footnote-2837874
+Ref: Igawk Program-Footnote-3837996
+Node: Anagram Program838111
+Node: Signature Program841173
+Node: Programs Summary842420
+Node: Programs Exercises843634
+Ref: Programs Exercises-Footnote-1847764
+Node: Advanced Features847850
+Node: Nondecimal Data849974
+Node: Boolean Typed Values851572
+Node: Array Sorting853580
+Node: Controlling Array Traversal854285
+Ref: Controlling Array Traversal-Footnote-1862653
+Node: Array Sorting Functions862771
+Ref: Array Sorting Functions-Footnote-1867862
+Node: Two-way I/O868058
+Ref: Two-way I/O-Footnote-1875779
+Ref: Two-way I/O-Footnote-2875966
+Node: TCP/IP Networking876048
+Node: Profiling879166
+Node: Extension Philosophy888475
+Node: Advanced Features Summary889954
+Node: Internationalization891969
+Node: I18N and L10N893449
+Node: Explaining gettext894136
+Ref: Explaining gettext-Footnote-1900028
+Ref: Explaining gettext-Footnote-2900213
+Node: Programmer i18n900378
+Ref: Programmer i18n-Footnote-1905327
+Node: Translator i18n905376
+Node: String Extraction906170
+Ref: String Extraction-Footnote-1907302
+Node: Printf Ordering907388
+Ref: Printf Ordering-Footnote-1910174
+Node: I18N Portability910238
+Ref: I18N Portability-Footnote-1912694
+Node: I18N Example912757
+Ref: I18N Example-Footnote-1916032
+Ref: I18N Example-Footnote-2916105
+Node: Gawk I18N916214
+Node: I18N Summary916863
+Node: Debugger918204
+Node: Debugging919204
+Node: Debugging Concepts919645
+Node: Debugging Terms921454
+Node: Awk Debugging924029
+Ref: Awk Debugging-Footnote-1924974
+Node: Sample Debugging Session925106
+Node: Debugger Invocation925640
+Node: Finding The Bug927026
+Node: List of Debugger Commands933500
+Node: Breakpoint Control934833
+Node: Debugger Execution Control938527
+Node: Viewing And Changing Data941889
+Node: Execution Stack945430
+Node: Debugger Info947067
+Node: Miscellaneous Debugger Commands951138
+Node: Readline Support956200
+Node: Limitations957096
+Node: Debugging Summary959650
+Node: Namespaces960929
+Node: Global Namespace962040
+Node: Qualified Names963438
+Node: Default Namespace964437
+Node: Changing The Namespace965178
+Node: Naming Rules966792
+Node: Internal Name Management968640
+Node: Namespace Example969682
+Node: Namespace And Features972244
+Node: Namespace Summary973679
+Node: Arbitrary Precision Arithmetic975156
+Node: Computer Arithmetic976643
+Ref: table-numeric-ranges980409
+Ref: table-floating-point-ranges980902
+Ref: Computer Arithmetic-Footnote-1981560
+Node: Math Definitions981617
+Ref: table-ieee-formats984593
+Node: MPFR features985160
+Node: FP Math Caution986878
+Ref: FP Math Caution-Footnote-1987950
+Node: Inexactness of computations988319
+Node: Inexact representation989350
+Node: Comparing FP Values990710
+Node: Errors accumulate991951
+Node: Strange values993407
+Ref: Strange values-Footnote-1995995
+Node: Getting Accuracy996100
+Node: Try To Round998810
+Node: Setting precision999709
+Ref: table-predefined-precision-strings1000406
+Node: Setting the rounding mode1002236
+Ref: table-gawk-rounding-modes1002610
+Ref: Setting the rounding mode-Footnote-11006541
+Node: Arbitrary Precision Integers1006720
+Ref: Arbitrary Precision Integers-Footnote-11009895
+Node: Checking for MPFR1010044
+Node: POSIX Floating Point Problems1011518
+Ref: POSIX Floating Point Problems-Footnote-11015803
+Node: Floating point summary1015841
+Node: Dynamic Extensions1018031
+Node: Extension Intro1019584
+Node: Plugin License1020850
+Node: Extension Mechanism Outline1021647
+Ref: figure-load-extension1022086
+Ref: figure-register-new-function1023651
+Ref: figure-call-new-function1024743
+Node: Extension API Description1026805
+Node: Extension API Functions Introduction1028518
+Ref: table-api-std-headers1030354
+Node: General Data Types1034603
+Ref: General Data Types-Footnote-11043309
+Node: Memory Allocation Functions1043608
+Ref: Memory Allocation Functions-Footnote-11048109
+Node: Constructor Functions1048208
+Node: API Ownership of MPFR and GMP Values1051861
+Node: Registration Functions1053174
+Node: Extension Functions1053874
+Node: Exit Callback Functions1059196
+Node: Extension Version String1060446
+Node: Input Parsers1061109
+Node: Output Wrappers1073830
+Node: Two-way processors1078342
+Node: Printing Messages1080607
+Ref: Printing Messages-Footnote-11081778
+Node: Updating ERRNO1081931
+Node: Requesting Values1082670
+Ref: table-value-types-returned1083407
+Node: Accessing Parameters1084515
+Node: Symbol Table Access1085752
+Node: Symbol table by name1086264
+Ref: Symbol table by name-Footnote-11089288
+Node: Symbol table by cookie1089416
+Ref: Symbol table by cookie-Footnote-11093601
+Node: Cached values1093665
+Ref: Cached values-Footnote-11097201
+Node: Array Manipulation1097354
+Ref: Array Manipulation-Footnote-11098445
+Node: Array Data Types1098482
+Ref: Array Data Types-Footnote-11101140
+Node: Array Functions1101232
+Node: Flattening Arrays1105730
+Node: Creating Arrays1112706
+Node: Redirection API1117473
+Node: Extension API Variables1120306
+Node: Extension Versioning1121017
+Ref: gawk-api-version1121446
+Node: Extension GMP/MPFR Versioning1123177
+Node: Extension API Informational Variables1124805
+Node: Extension API Boilerplate1125878
+Node: Changes from API V11129852
+Node: Finding Extensions1131424
+Node: Extension Example1131983
+Node: Internal File Description1132781
+Node: Internal File Ops1136861
+Ref: Internal File Ops-Footnote-11148211
+Node: Using Internal File Ops1148351
+Ref: Using Internal File Ops-Footnote-11150734
+Node: Extension Samples1151008
+Node: Extension Sample File Functions1152537
+Node: Extension Sample Fnmatch1160186
+Node: Extension Sample Fork1161673
+Node: Extension Sample Inplace1162891
+Node: Extension Sample Ord1166517
+Node: Extension Sample Readdir1167353
+Ref: table-readdir-file-types1168242
+Node: Extension Sample Revout1169309
+Node: Extension Sample Rev2way1169898
+Node: Extension Sample Read write array1170638
+Node: Extension Sample Readfile1172580
+Node: Extension Sample Time1173675
+Node: Extension Sample API Tests1175427
+Node: gawkextlib1175919
+Node: Extension summary1178837
+Node: Extension Exercises1182539
+Node: Language History1183781
+Node: V7/SVR3.11185437
+Node: SVR41187589
+Node: POSIX1189023
+Node: BTL1190404
+Node: POSIX/GNU1191133
+Node: Feature History1196911
+Node: Common Extensions1213230
+Node: Ranges and Locales1214513
+Ref: Ranges and Locales-Footnote-11219129
+Ref: Ranges and Locales-Footnote-21219156
+Ref: Ranges and Locales-Footnote-31219391
+Node: Contributors1219614
+Node: History summary1225611
+Node: Installation1226991
+Node: Gawk Distribution1227935
+Node: Getting1228419
+Node: Extracting1229382
+Node: Distribution contents1231020
+Node: Unix Installation1237500
+Node: Quick Installation1238182
+Node: Shell Startup Files1240596
+Node: Additional Configuration Options1241685
+Node: Configuration Philosophy1244000
+Node: Non-Unix Installation1246369
+Node: PC Installation1246829
+Node: PC Binary Installation1247667
+Node: PC Compiling1248102
+Node: PC Using1249219
+Node: Cygwin1252772
+Node: MSYS1253996
+Node: VMS Installation1254598
+Node: VMS Compilation1255389
+Ref: VMS Compilation-Footnote-11256618
+Node: VMS Dynamic Extensions1256676
+Node: VMS Installation Details1258361
+Node: VMS Running1260614
+Node: VMS GNV1264893
+Node: VMS Old Gawk1265628
+Node: Bugs1266099
+Node: Bug address1266762
+Node: Usenet1269744
+Node: Maintainers1270748
+Node: Other Versions1271933
+Node: Installation summary1279798
+Node: Notes1281007
+Node: Compatibility Mode1281801
+Node: Additions1282583
+Node: Accessing The Source1283508
+Node: Adding Code1284945
+Node: New Ports1291164
+Node: Derived Files1295539
+Ref: Derived Files-Footnote-11301199
+Ref: Derived Files-Footnote-21301234
+Ref: Derived Files-Footnote-31301832
+Node: Future Extensions1301946
+Node: Implementation Limitations1302604
+Node: Extension Design1303814
+Node: Old Extension Problems1304958
+Ref: Old Extension Problems-Footnote-11306476
+Node: Extension New Mechanism Goals1306533
+Ref: Extension New Mechanism Goals-Footnote-11309897
+Node: Extension Other Design Decisions1310086
+Node: Extension Future Growth1312199
+Node: Notes summary1312805
+Node: Basic Concepts1313963
+Node: Basic High Level1314644
+Ref: figure-general-flow1314926
+Ref: figure-process-flow1315611
+Ref: Basic High Level-Footnote-11318912
+Node: Basic Data Typing1319097
+Node: Glossary1322425
+Node: Copying1354310
+Node: GNU Free Documentation License1391853
+Node: Index1416973

End Tag Table
diff --git a/doc/gawk.texi b/doc/gawk.texi
index e87a1e84..6a7feaaa 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -754,6 +754,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()}.
@@ -861,6 +863,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{bool} type.
* Array Sorting:: Facilities for controlling array
traversal and sorting arrays.
* Controlling Array Traversal:: How to use PROCINFO["sorted_in"].
@@ -18307,6 +18310,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
@@ -18376,6 +18380,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{bool(@var{expression})}
+@cindexgawkfunc{bool}
+Return a Boolean-typed value based on the regular Boolean value
+of @var{expression}. Boolean ``true'' values have numeric value one
+and string value @code{"TRUE"}. Boolean ``false'' values have numeric
+zero and string value @code{"FALSE"}. This is discussed in more
+detail in @ref{Boolean Typed Values}.
+@end table
+
@node Numeric Functions
@subsection Numeric Functions
@cindex numeric @subentry functions
@@ -20892,6 +20915,9 @@ Return one of the following strings, depending upon the type of @var{x}:
@item "array"
@var{x} is an array.
+@item "bool"
+@var{x} is a Boolean typed value (@pxref{Boolean Typed Values}).
+
@item "regexp"
@var{x} is a strongly typed regexp (@pxref{Strong Regexp Constants}).
@@ -21776,7 +21802,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
@@ -29385,6 +29411,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{bool} type.
* Array Sorting:: Facilities for controlling array traversal and
sorting arrays.
* Two-way I/O:: Two-way communications with another process.
@@ -29451,6 +29478,48 @@ 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{bool()}.
+It takes one argument, which is any @command{awk} expression, and it
+returns a value of Boolean type.
+
+The returned values are different than normal @command{awk} values. When
+treated as numbers, they are either one or zero, depending upon the truth
+value of the original expression passed in the call to @code{bool()}. When
+treated as strings, they are either @code{"TRUE"} or @code{"FALSE"},
+again depending upon the truth value of the expression passed in the
+call to @code{bool()}. The value for ``false'' is thus unusual; it is
+zero numerically, but not empty when treated as a string.
+
+The @code{typeof()} function (@pxref{Type Functions}) returns
+@code{"bool"} for these values.
+
+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 any existing code.
+
@node Array Sorting
@section Controlling Array Traversal and Array Sorting
@@ -35586,7 +35655,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}.
@@ -35599,6 +35669,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.''
@@ -35614,6 +35685,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.
@@ -35941,6 +36013,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
@@ -36741,7 +36818,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>
@@ -36751,6 +36829,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>
@@ -36763,6 +36842,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>
@@ -36775,6 +36855,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>
@@ -36783,6 +36864,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>
@@ -36791,6 +36873,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>
@@ -36798,11 +36881,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>
@@ -36813,6 +36908,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>
@@ -36823,6 +36919,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>
@@ -36835,6 +36932,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>
@@ -36851,43 +36949,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
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index 95606cf3..ae46956d 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -749,6 +749,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()}.
@@ -856,6 +858,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{bool} type.
* Array Sorting:: Facilities for controlling array
traversal and sorting arrays.
* Controlling Array Traversal:: How to use PROCINFO["sorted_in"].
@@ -17448,6 +17451,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
@@ -17517,6 +17521,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{bool(@var{expression})}
+@cindexgawkfunc{bool}
+Return a Boolean-typed value based on the regular Boolean value
+of @var{expression}. Boolean ``true'' values have numeric value one
+and string value @code{"TRUE"}. Boolean ``false'' values have numeric
+zero and string value @code{"FALSE"}. This is discussed in more
+detail in @ref{Boolean Typed Values}.
+@end table
+
@node Numeric Functions
@subsection Numeric Functions
@cindex numeric @subentry functions
@@ -19804,6 +19827,9 @@ Return one of the following strings, depending upon the type of @var{x}:
@item "array"
@var{x} is an array.
+@item "bool"
+@var{x} is a Boolean typed value (@pxref{Boolean Typed Values}).
+
@item "regexp"
@var{x} is a strongly typed regexp (@pxref{Strong Regexp Constants}).
@@ -20688,7 +20714,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
@@ -28267,6 +28293,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{bool} type.
* Array Sorting:: Facilities for controlling array traversal and
sorting arrays.
* Two-way I/O:: Two-way communications with another process.
@@ -28333,6 +28360,48 @@ 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{bool()}.
+It takes one argument, which is any @command{awk} expression, and it
+returns a value of Boolean type.
+
+The returned values are different than normal @command{awk} values. When
+treated as numbers, they are either one or zero, depending upon the truth
+value of the original expression passed in the call to @code{bool()}. When
+treated as strings, they are either @code{"TRUE"} or @code{"FALSE"},
+again depending upon the truth value of the expression passed in the
+call to @code{bool()}. The value for ``false'' is thus unusual; it is
+zero numerically, but not empty when treated as a string.
+
+The @code{typeof()} function (@pxref{Type Functions}) returns
+@code{"bool"} for these values.
+
+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 any existing code.
+
@node Array Sorting
@section Controlling Array Traversal and Array Sorting
@@ -34429,7 +34498,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}.
@@ -34442,6 +34512,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.''
@@ -34457,6 +34528,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.
@@ -34784,6 +34856,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
@@ -35584,7 +35661,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>
@@ -35594,6 +35672,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>
@@ -35606,6 +35685,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>
@@ -35618,6 +35698,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>
@@ -35626,6 +35707,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>
@@ -35634,6 +35716,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>
@@ -35641,11 +35724,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>
@@ -35656,6 +35751,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>
@@ -35666,6 +35762,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>
@@ -35678,6 +35775,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>
@@ -35694,43 +35792,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
diff --git a/eval.c b/eval.c
index 640f939f..75c39327 100644
--- a/eval.c
+++ b/eval.c
@@ -455,6 +455,7 @@ flags2str(int flagval)
{ XARRAY, "XARRAY" },
{ NUMCONSTSTR, "NUMCONSTSTR" },
{ REGEX, "REGEX" },
+ { BOOL, "BOOL" },
{ 0, NULL },
};
diff --git a/extension/ChangeLog b/extension/ChangeLog
index fef32337..986a8358 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,7 +1,16 @@
+2021-03-30 Arnold D. Robbins <arnold@skeeve.com>
+
+ * rwarray.c (write_value): Add support for writing boolean values.
+ (read_value): Ditto.
+
2021-03-29 Arnold D. Robbins <arnold@skeeve.com>
* testext.c (var_test): Fix a comment. Update copyright year.
+2021-03-22 Arnold D. Robbins <arnold@skeeve.com>
+
+ * testext.c (valrep2str): Add support for AWK_BOOL.
+
2020-07-26 Arnold D. Robbins <arnold@skeeve.com>
* intdiv.c (do_intdiv): Change quotient and remainder to
diff --git a/extension/rwarray.c b/extension/rwarray.c
index 45f9c734..a534a5a4 100644
--- a/extension/rwarray.c
+++ b/extension/rwarray.c
@@ -8,7 +8,7 @@
*/
/*
- * Copyright (C) 2009-2014, 2017, 2018, 2020 the Free Software Foundation, Inc.
+ * Copyright (C) 2009-2014, 2017, 2018, 2020, 2021 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -36,6 +36,7 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -249,6 +250,9 @@ write_value(FILE *fp, awk_value_t *val)
case AWK_UNDEFINED:
code = htonl(5);
break;
+ case AWK_BOOL:
+ code = htonl(6);
+ break;
default:
/* XXX can this happen? */
code = htonl(0);
@@ -258,13 +262,25 @@ write_value(FILE *fp, awk_value_t *val)
if (fwrite(& code, 1, sizeof(code), fp) != sizeof(code))
return awk_false;
- len = htonl(val->str_value.len);
- if (fwrite(& len, 1, sizeof(len), fp) != sizeof(len))
- return awk_false;
+ if (code == ntohl(6)) {
+ len = (val->bool_value == awk_true ? 4 : 5);
+ len = htonl(len);
+ const char *s = (val->bool_value == awk_true ? "TRUE" : "FALSE");
- if (fwrite(val->str_value.str, 1, val->str_value.len, fp)
- != (ssize_t) val->str_value.len)
- return awk_false;
+ if (fwrite(& len, 1, sizeof(len), fp) != sizeof(len))
+ return awk_false;
+
+ if (fwrite(s, 1, strlen(s), fp) != (ssize_t) strlen(s))
+ return awk_false;
+ } else {
+ len = htonl(val->str_value.len);
+ if (fwrite(& len, 1, sizeof(len), fp) != sizeof(len))
+ return awk_false;
+
+ if (fwrite(val->str_value.str, 1, val->str_value.len, fp)
+ != (ssize_t) val->str_value.len)
+ return awk_false;
+ }
}
return awk_true;
@@ -484,6 +500,9 @@ read_value(FILE *fp, awk_value_t *value)
case 5:
value->val_type = AWK_UNDEFINED;
break;
+ case 6:
+ value->val_type = AWK_BOOL;
+ break;
default:
/* this cannot happen! */
warning(ext_id, _("treating recovered value with unknown type code %d as a string"), code);
@@ -498,6 +517,13 @@ read_value(FILE *fp, awk_value_t *value)
return awk_false;
}
value->str_value.str[len] = '\0';
+ value->str_value.len = len;
+ if (code == 6) {
+ /* bool type */
+ bool val = (strcmp(value->str_value.str, "TRUE") == 0);
+ gawk_free(value->str_value.str);
+ value->bool_value = val ? awk_true : awk_false;
+ }
}
return awk_true;
diff --git a/extension/testext.c b/extension/testext.c
index a5bef7ae..bfaa8637 100644
--- a/extension/testext.c
+++ b/extension/testext.c
@@ -88,6 +88,13 @@ valrep2str(const awk_value_t *value)
size,
value->str_value.str);
break;
+ case AWK_BOOL:
+ if (value->str_value.len + 8 < size)
+ size = value->str_value.len;
+ sprintf(buf, "<bool>: %.*s",
+ size,
+ value->str_value.str);
+ break;
case AWK_NUMBER:
sprintf(buf, "%g", value->num_value);
break;
diff --git a/field.c b/field.c
index c21046b9..2bd58863 100644
--- a/field.c
+++ b/field.c
@@ -1019,6 +1019,7 @@ do_split(int nargs)
assoc_clear(arr);
src = TOP_STRING();
+ warn_bool("split", 1, src);
if (src->stlen == 0) {
/*
* Skip the work if first arg is the null string.
@@ -1096,6 +1097,7 @@ do_patsplit(int nargs)
_("%s: cannot use %s as second argument"));
src = TOP_STRING();
+ warn_bool("patsplit", 1, src);
if ((sep->flags & REGEX) != 0)
sep = sep->typed_re;
diff --git a/gawkapi.c b/gawkapi.c
index a60549dd..e8a9c312 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -160,6 +160,9 @@ awk_value_to_node(const awk_value_t *retval)
case AWK_UNDEFINED:
ext_ret_val = dupnode(Nnull_string);
break;
+ case AWK_BOOL:
+ ext_ret_val = make_bool_node(retval->bool_value != awk_false);
+ break;
case AWK_NUMBER:
switch (retval->num_type) {
case AWK_NUMBER_TYPE_DOUBLE:
@@ -532,6 +535,16 @@ assign_regex(NODE *node, awk_value_t *val)
val->val_type = AWK_REGEX;
}
+/* assign_bool --- return a bool node */
+
+static inline void
+assign_bool(NODE *node, awk_value_t *val)
+{
+ assert((node->flags & BOOL) != 0);
+ val->val_type = AWK_BOOL;
+ val->bool_value = get_number_si(node) != 0 ? awk_true : awk_false;
+}
+
/* node_to_awk_value --- convert a node into a value for an extension */
static awk_bool_t
@@ -567,8 +580,16 @@ node_to_awk_value(NODE *node, awk_value_t *val, awk_valtype_t wanted)
case Node_val:
/* a scalar value */
switch (wanted) {
+ case AWK_BOOL:
+ if ((node->flags & BOOL) != 0) {
+ assign_bool(node, val);
+ ret = awk_true;
+ } else
+ ret = awk_false;
+ break;
+
case AWK_NUMBER:
- if (node->flags & REGEX)
+ if ((node->flags & REGEX) != 0)
val->val_type = AWK_REGEX;
else {
(void) force_number(node);
@@ -578,7 +599,10 @@ node_to_awk_value(NODE *node, awk_value_t *val, awk_valtype_t wanted)
break;
case AWK_STRNUM:
- switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) {
+ switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX|BOOL)) {
+ case BOOL:
+ val->val_type = AWK_BOOL;
+ break;
case STRING:
val->val_type = AWK_STRING;
break;
@@ -612,10 +636,13 @@ node_to_awk_value(NODE *node, awk_value_t *val, awk_valtype_t wanted)
break;
case AWK_REGEX:
- switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) {
+ switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX|BOOL)) {
case STRING:
val->val_type = AWK_STRING;
break;
+ case BOOL:
+ val->val_type = AWK_BOOL;
+ break;
case NUMBER:
val->val_type = AWK_NUMBER;
break;
@@ -640,7 +667,10 @@ node_to_awk_value(NODE *node, awk_value_t *val, awk_valtype_t wanted)
break;
case AWK_SCALAR:
- switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) {
+ switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX|BOOL)) {
+ case BOOL:
+ val->val_type = AWK_BOOL;
+ break;
case STRING:
val->val_type = AWK_STRING;
break;
@@ -668,7 +698,11 @@ node_to_awk_value(NODE *node, awk_value_t *val, awk_valtype_t wanted)
case AWK_UNDEFINED:
/* return true and actual type for request of undefined */
- switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) {
+ switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX|BOOL)) {
+ case BOOL:
+ assign_bool(node, val);
+ ret = awk_true;
+ break;
case STRING:
assign_string(node, val, AWK_STRING);
ret = awk_true;
diff --git a/gawkapi.h b/gawkapi.h
index 54130b15..9967aa26 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -297,7 +297,7 @@ typedef struct awk_two_way_processor {
} awk_two_way_processor_t;
#define gawk_api_major_version 3
-#define gawk_api_minor_version 1
+#define gawk_api_minor_version 2
/* Current version of the API. */
enum {
@@ -366,7 +366,8 @@ typedef enum {
AWK_STRNUM,
AWK_ARRAY,
AWK_SCALAR, /* opaque access to a variable */
- AWK_VALUE_COOKIE /* for updating a previously created value */
+ AWK_VALUE_COOKIE, /* for updating a previously created value */
+ AWK_BOOL
} awk_valtype_t;
/*
@@ -381,6 +382,7 @@ typedef struct awk_value {
awk_array_t a;
awk_scalar_t scl;
awk_value_cookie_t vc;
+ awk_bool_t b;
} u;
#define str_value u.s
#define strnum_value str_value
@@ -391,6 +393,7 @@ typedef struct awk_value {
#define array_cookie u.a
#define scalar_cookie u.scl
#define value_cookie u.vc
+#define bool_value u.b
} awk_value_t;
/*
@@ -565,28 +568,30 @@ typedef struct gawk_api {
Table entry is type returned:
- +-------------------------------------------------------+
- | 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 | Array | false | false | false | false | Array | false |
- | Requested +-----------+--------+--------+--------+--------+-------+-----------+
- | | 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 | | | | | | | |
+ +-----------+-----------+--------+--------+--------+--------+--------+-------+-----------+
*/
/* Functions to handle parameters passed to the extension. */
@@ -1069,6 +1074,16 @@ make_number_mpfr(void *mpfr_ptr, awk_value_t *result)
return result;
}
+/* make_bool --- make a bool value in result */
+
+static inline awk_value_t *
+make_bool(awk_bool_t boolval, awk_value_t *result)
+{
+ result->val_type = AWK_BOOL;
+ result->bool_value = boolval;
+ return result;
+}
+
/*
* Each extension must define a function with this prototype:
diff --git a/main.c b/main.c
index 5b153bc3..76f28289 100644
--- a/main.c
+++ b/main.c
@@ -980,7 +980,6 @@ load_procinfo_argv()
// hook it into PROCINFO
sub = make_string("argv", 4);
assoc_set(PROCINFO_node, sub, argv_array);
-
}
/* load_procinfo --- populate the PROCINFO array */
diff --git a/node.c b/node.c
index c22c06ab..dda90f0f 100644
--- a/node.c
+++ b/node.c
@@ -1082,3 +1082,25 @@ more_blocks(int id)
}
#endif
+
+/* make_bool_node --- make a boolean-valued node */
+
+extern NODE *
+make_bool_node(bool value)
+{
+ NODE *val;
+ const char *sval;
+ AWKNUM nval;
+
+ sval = (value ? "TRUE" : "FALSE");
+ nval = (value ? 1.0 : 0.0);
+
+ val = make_number(nval);
+ val->stptr = estrdup(sval, strlen(sval));
+ val->stlen = strlen(sval);
+ val->flags &= ~NUMBER;
+ val->flags |= NUMCUR|STRCUR|BOOL;
+ val->stfmt = STFMT_UNUSED;
+
+ return val;
+}
diff --git a/pc/ChangeLog b/pc/ChangeLog
index 399dcc90..51b367dd 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,7 @@
+2021-03-30 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.tst: Rebuilt.
+
2021-02-13 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.tst: Rebuilt.
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index 573981fc..f2293ac6 100644
--- a/pc/Makefile.tst
+++ b/pc/Makefile.tst
@@ -190,7 +190,7 @@ UNIX_TESTS = \
GAWK_EXT_TESTS = \
aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort arraysort2 \
- arraytype \
+ arraytype asortbool \
backw badargs beginfile1 beginfile2 binmode1 \
charasbytes colonwarn clos1way clos1way2 clos1way3 clos1way4 clos1way5 \
clos1way6 crlf \
@@ -2586,6 +2586,11 @@ arraytype:
then $(CMP) "$(srcdir)"/$@-mpfr.ok _$@ && rm -f _$@ ; \
else $(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ ; fi
+asortbool:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
backw:
@echo $@
@echo Expect $@ to fail with DJGPP.
diff --git a/test/ChangeLog b/test/ChangeLog
index 53fe5627..a65ff619 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,14 @@
+2021-03-30 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (EXTRA_DIST): asortbool, new test.
+ * asortbool.awk, asortbool.ok: New files.
+ * rwarray.awk: Add test of saving/restoring bool values.
+
+2021-03-08 Arnold D. Robbins <arnold@skeeve.com>
+
+ * dumpvars.ok, functab5.ok, id.ok, intest.awk, symtab11.ok,
+ symtab8.ok: Updated after code changes.
+
2021-02-13 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (EXTRA_DIST): argcasfile, new test.
diff --git a/test/Makefile.am b/test/Makefile.am
index bdb8831f..0c56b7e4 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -133,6 +133,8 @@ EXTRA_DIST = \
assignnumfield.ok \
assignnumfield2.awk \
assignnumfield2.ok \
+ asortbool.awk \
+ asortbool.ok \
awkpath.ok \
back89.awk \
back89.in \
@@ -1430,7 +1432,7 @@ UNIX_TESTS = \
GAWK_EXT_TESTS = \
aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort arraysort2 \
- arraytype \
+ arraytype asortbool \
backw badargs beginfile1 beginfile2 binmode1 \
charasbytes colonwarn clos1way clos1way2 clos1way3 clos1way4 clos1way5 \
clos1way6 crlf \
diff --git a/test/Makefile.in b/test/Makefile.in
index 92ef9d06..fa823d0a 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -396,6 +396,8 @@ EXTRA_DIST = \
assignnumfield.ok \
assignnumfield2.awk \
assignnumfield2.ok \
+ asortbool.awk \
+ asortbool.ok \
awkpath.ok \
back89.awk \
back89.in \
@@ -1693,7 +1695,7 @@ UNIX_TESTS = \
GAWK_EXT_TESTS = \
aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort arraysort2 \
- arraytype \
+ arraytype asortbool \
backw badargs beginfile1 beginfile2 binmode1 \
charasbytes colonwarn clos1way clos1way2 clos1way3 clos1way4 clos1way5 \
clos1way6 crlf \
@@ -4265,6 +4267,11 @@ arraytype:
then $(CMP) "$(srcdir)"/$@-mpfr.ok _$@ && rm -f _$@ ; \
else $(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ ; fi
+asortbool:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
backw:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 20ed4a7f..d3c4a231 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1330,6 +1330,11 @@ arraytype:
then $(CMP) "$(srcdir)"/$@-mpfr.ok _$@ && rm -f _$@ ; \
else $(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ ; fi
+asortbool:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
backw:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/asortbool.awk b/test/asortbool.awk
new file mode 100644
index 00000000..7f5a94fb
--- /dev/null
+++ b/test/asortbool.awk
@@ -0,0 +1,19 @@
+BEGIN {
+ a[1] = "foo"
+ a[2] = -45
+ a[3] = 45
+ a[4][1] = 47
+ a[5] = bool(1)
+ a[6] = bool(0)
+
+ asort(a, b, "@val_type_asc")
+
+ j = length(b)
+ for (i = 1; i <= j; i++) {
+ printf("%d, %s: ", i, typeof(b[i]))
+ if (isarray(b[i]))
+ print b[i][1]
+ else
+ print b[i]
+ }
+}
diff --git a/test/asortbool.ok b/test/asortbool.ok
new file mode 100644
index 00000000..de08a770
--- /dev/null
+++ b/test/asortbool.ok
@@ -0,0 +1,6 @@
+1, bool: FALSE
+2, bool: TRUE
+3, number: -45
+4, number: 45
+5, string: foo
+6, array: 47
diff --git a/test/dumpvars.ok b/test/dumpvars.ok
index 85d1c859..7caecd35 100644
--- a/test/dumpvars.ok
+++ b/test/dumpvars.ok
@@ -9,7 +9,7 @@ FILENAME: "-"
FNR: 3
FPAT: "[^[:space:]]+"
FS: " "
-FUNCTAB: array, 41 elements
+FUNCTAB: array, 42 elements
IGNORECASE: 0
LINT: 0
NF: 1
diff --git a/test/functab5.ok b/test/functab5.ok
index 9ac4295d..ef110989 100644
--- a/test/functab5.ok
+++ b/test/functab5.ok
@@ -3,6 +3,7 @@ asort'
asorti'
atan2'
bindtextdomain'
+bool'
chdir'
close'
compl'
diff --git a/test/id.ok b/test/id.ok
index ab4df74a..f990546f 100644
--- a/test/id.ok
+++ b/test/id.ok
@@ -34,6 +34,7 @@ asort -> builtin
asorti -> builtin
atan2 -> builtin
bindtextdomain -> builtin
+bool -> builtin
close -> builtin
compl -> builtin
cos -> builtin
diff --git a/test/intest.awk b/test/intest.awk
index f030d07a..18e0cc4d 100644
--- a/test/intest.awk
+++ b/test/intest.awk
@@ -1,4 +1,4 @@
BEGIN {
- bool = ((b = 1) in c);
- print bool, b # gawk-3.0.1 prints "0 "; should print "0 1"
+ bool_result = ((b = 1) in c);
+ print bool_result, b # gawk-3.0.1 prints "0 "; should print "0 1"
}
diff --git a/test/rwarray.awk b/test/rwarray.awk
index 86a4b589..831f17c3 100644
--- a/test/rwarray.awk
+++ b/test/rwarray.awk
@@ -11,6 +11,9 @@ BEGIN {
split("-2.4", f)
dict[strnum_sub] = f[1]
+ bool_sub = "bool-sub"
+ dict[bool_sub] = bool(1)
+
n = asorti(dict, dictindices)
for (i = 1; i <= n; i++)
printf("dict[%s] = %s\n", dictindices[i], dict[dictindices[i]]) > "orig.out"
@@ -51,4 +54,12 @@ BEGIN {
if (typeof(dict[strnum_sub]) != "strnum")
printf("dict[\"%s\"] should be strnum, is %s\n",
strnum_sub, typeof(dict[strnum_sub]));
+
+ if (typeof(dict[bool_sub]) != "bool")
+ printf("dict[\"%s\"] should be bool, is %s\n",
+ bool_sub, typeof(dict[bool_sub]));
+
+ if ((dict[bool_sub] "") != "TRUE")
+ printf("dict[\"%s\"] should be TRUE, is %s\n",
+ bool_sub, dict[bool_sub]);
}
diff --git a/test/symtab11.ok b/test/symtab11.ok
index 7d4be46c..da2cfcba 100644
--- a/test/symtab11.ok
+++ b/test/symtab11.ok
@@ -37,6 +37,7 @@ BEGIN -- Functab is next
[asorti] = asorti
[atan2] = atan2
[bindtextdomain] = bindtextdomain
+[bool] = bool
[close] = close
[compl] = compl
[cos] = cos
diff --git a/test/symtab8.ok b/test/symtab8.ok
index da29b585..0cf40fe9 100644
--- a/test/symtab8.ok
+++ b/test/symtab8.ok
@@ -9,7 +9,7 @@ FIELDWIDTHS: ""
FNR: 1
FPAT: "[^[:space:]]+"
FS: " "
-FUNCTAB: array, 41 elements
+FUNCTAB: array, 42 elements
IGNORECASE: 0
LINT: 0
NF: 1