diff options
-rw-r--r-- | ChangeLog | 81 | ||||
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | array.c | 3 | ||||
-rw-r--r-- | awk.h | 33 | ||||
-rw-r--r-- | awkgram.c | 1 | ||||
-rw-r--r-- | awkgram.y | 1 | ||||
-rw-r--r-- | builtin.c | 24 | ||||
-rw-r--r-- | doc/ChangeLog | 30 | ||||
-rw-r--r-- | doc/awkcard.in | 31 | ||||
-rw-r--r-- | doc/gawk.1 | 16 | ||||
-rw-r--r-- | doc/gawk.info | 1344 | ||||
-rw-r--r-- | doc/gawk.texi | 176 | ||||
-rw-r--r-- | doc/gawktexi.in | 176 | ||||
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | extension/ChangeLog | 9 | ||||
-rw-r--r-- | extension/rwarray.c | 40 | ||||
-rw-r--r-- | extension/testext.c | 7 | ||||
-rw-r--r-- | gawkapi.c | 44 | ||||
-rw-r--r-- | gawkapi.h | 63 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | node.c | 21 | ||||
-rw-r--r-- | pc/ChangeLog | 4 | ||||
-rw-r--r-- | pc/Makefile.tst | 7 | ||||
-rw-r--r-- | test/ChangeLog | 21 | ||||
-rw-r--r-- | test/Makefile.am | 4 | ||||
-rw-r--r-- | test/Makefile.in | 9 | ||||
-rw-r--r-- | test/Maketests | 5 | ||||
-rw-r--r-- | test/asortbool.awk | 19 | ||||
-rw-r--r-- | test/asortbool.ok | 6 | ||||
-rw-r--r-- | test/dumpvars.ok | 2 | ||||
-rw-r--r-- | test/functab5.ok | 1 | ||||
-rw-r--r-- | test/id.ok | 1 | ||||
-rw-r--r-- | test/intest.awk | 4 | ||||
-rw-r--r-- | test/rwarray.awk | 11 | ||||
-rw-r--r-- | test/symtab11.ok | 1 | ||||
-rw-r--r-- | test/symtab8.ok | 2 |
36 files changed, 1423 insertions, 782 deletions
@@ -5,6 +5,38 @@ * configure.ac (AM_INIT_AUTOMAKE): Add subdir-objects option. * NEWS: Updated. +2021-05-03 Arnold D. Robbins <arnold@skeeve.com> + + * eval.c (flags2str): Move BOOL entry into the right place in the + list. + * NEWS: Update with info on mkbool. + +2021-05-02 Arnold D. Robbins <arnold@skeeve.com> + + * awk.h (do_bool): Renamed do_mkbool. + * awkgram.y (tokentab): Rename bool to mkbool. + * builtin.c (do_bool): Renamed do_mkbool. + +2021-04-30 Arnold D. Robbins <arnold@skeeve.com> + + * awk.h (boolval): Remove check for BOOL flag. It was incorrect. + Thanks to Andrew Schorr for the catch. + For Node_val, update the comment to describe the BOOL flag, and + move BOOL up to be alongside the flags for Node_val. + +2021-04-28 Arnold D. Robbins <arnold@skeeve.com> + + Make bools plain numbers that have bool flag instead of + being weird string values. + + * array.c (do_sort_up_value_type): Remove special ordering + for booleans. + * awk.h (warn_bool): Remove declaration. + * builtin.c (warn_bool): Remove function and all calls. + * gawkapi.c (node_to_awk_value): Update switches to look for + NUMBER|BOOL. + * node.c (make_bool_node): Revise string values and flag bits. + 2021-04-16 Arnold D. Robbins <arnold@skeeve.com> * main (arg_assign): For -v '@/...' make sure that there are @@ -26,12 +58,61 @@ * interpret.h (r_interpret): Remove LINT_no_effect from Op_lint case. +2021-04-14 Arnold D. Robbins <arnold@skeeve.com> + + * array.c (do_sort_up_value_type): Fix order with bools. + +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 @@ -15,6 +15,12 @@ regular numbers; it should not be noticeable most of the time. 2. If the AWK_HASH environment variable is set to "fnv1a" gawk will use the FNV1-A hash function for associative arrays. +3. There is now a new function, mkbool(), that creates Boolean-typed +values. These values *are* numbers, but they are also tagged as +Boolean. This is mainly for use with data exchange to/from languages +or environments that support real Boolean values. See the manual +for details. + Changes from 5.1.0 to 5.1.1 --------------------------- @@ -1209,11 +1209,12 @@ do_sort_up_value_type(const void *p1, const void *p2) (void) fixtype(n1); (void) fixtype(n2); + /* 3a. Numbers first */ 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. */ + /* 3b. 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) { @@ -436,6 +436,10 @@ typedef struct exp_node { * is a hint to indicate that an integer array optimization may be * used when this value appears as a subscript. * + * The BOOL flag indicates that this number should be converted to True + * or False by extensions that interchange data with other languages, + * via JSON, XML or some other serialization mechanism. + * * We hope that the rest of the flags are self-explanatory. :-) */ MALLOC = 0x0001, /* stptr can be free'd, i.e. not a field node pointing into a shared buffer */ @@ -445,24 +449,25 @@ typedef struct exp_node { NUMBER = 0x0010, /* assigned as number */ USER_INPUT = 0x0020, /* user input: if NUMERIC then * a NUMBER */ - INTLSTR = 0x0040, /* use localized version */ - NUMINT = 0x0080, /* numeric value is an integer */ - INTIND = 0x0100, /* integral value is array index; + BOOL = 0x0040, /* this is a boolean value */ + INTLSTR = 0x0080, /* use localized version */ + NUMINT = 0x0100, /* numeric value is an integer */ + INTIND = 0x0200, /* integral value is array index; * lazy conversion to string. */ - WSTRCUR = 0x0200, /* wide str value is current */ - MPFN = 0x0400, /* arbitrary-precision floating-point number */ - MPZN = 0x0800, /* arbitrary-precision integer */ - NO_EXT_SET = 0x1000, /* extension cannot set a value for this variable */ - NULL_FIELD = 0x2000, /* this is the null field */ + WSTRCUR = 0x0400, /* wide str value is current */ + MPFN = 0x0800, /* arbitrary-precision floating-point number */ + MPZN = 0x01000, /* arbitrary-precision integer */ + NO_EXT_SET = 0x02000, /* extension cannot set a value for this variable */ + NULL_FIELD = 0x04000, /* this is the null field */ /* type = Node_var_array */ - ARRAYMAXED = 0x4000, /* array is at max size */ - HALFHAT = 0x8000, /* half-capacity Hashed Array Tree; + ARRAYMAXED = 0x08000, /* array is at max size */ + HALFHAT = 0x010000, /* half-capacity Hashed Array Tree; * See cint_array.c */ - XARRAY = 0x10000, - NUMCONSTSTR = 0x20000, /* have string value for numeric constant */ - REGEX = 0x40000, /* this is a typed regex */ + XARRAY = 0x020000, + NUMCONSTSTR = 0x040000, /* have string value for numeric constant */ + REGEX = 0x080000, /* this is a typed regex */ } flags; long valref; } NODE; @@ -1503,6 +1508,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_mkbool(int nargs); /* debug.c */ extern void init_debug(void); extern int debug_prog(INSTRUCTION *pc); @@ -1714,6 +1720,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); @@ -4815,6 +4815,7 @@ static const struct token tokentab[] = { {"log", Op_builtin, LEX_BUILTIN, A(1), do_log, MPF(log)}, {"lshift", Op_builtin, LEX_BUILTIN, GAWKX|A(2), do_lshift, MPF(lshift)}, {"match", Op_builtin, LEX_BUILTIN, NOT_OLD|A(2)|A(3), do_match, 0}, +{"mkbool", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_mkbool, 0}, {"mktime", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2), do_mktime, 0}, {"namespace", Op_symbol, LEX_NAMESPACE, GAWKX, 0, 0}, {"next", Op_K_next, LEX_NEXT, 0, 0, 0}, @@ -2313,6 +2313,7 @@ static const struct token tokentab[] = { {"log", Op_builtin, LEX_BUILTIN, A(1), do_log, MPF(log)}, {"lshift", Op_builtin, LEX_BUILTIN, GAWKX|A(2), do_lshift, MPF(lshift)}, {"match", Op_builtin, LEX_BUILTIN, NOT_OLD|A(2)|A(3), do_match, 0}, +{"mkbool", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_mkbool, 0}, {"mktime", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2), do_mktime, 0}, {"namespace", Op_symbol, LEX_NAMESPACE, GAWKX, 0, 0}, {"next", Op_K_next, LEX_NEXT, 0, 0, 0}, @@ -2924,6 +2924,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 +4116,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 NUMBER|BOOL: + res = "number|bool"; + break; case NUMBER: res = "number"; break; @@ -4321,3 +4328,18 @@ check_symtab_functab(NODE *dest, const char *fname, const char *msg) else if (dest == func_table) fatal(msg, fname, "FUNCTAB"); } + +/* do_mkbool --- create boolean values */ + +NODE * +do_mkbool(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..151b03f0 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,29 @@ +2021-05-02 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in, gawk.1, awkcard.in: Renamed bool to mkbool. + +2021-04-28 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in: Revise doc for bools; they're now just numbers + with an extra flag. + * gawk.1: Ditto. + * awkcard.in: Ditto. + +2021-04-14 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Controlling Scanning): Document bools for + "@val_type_asc". + * awkcard.in: Add doc on bool() function. + +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 +35,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/awkcard.in b/doc/awkcard.in index 7cf90cc7..659a4a72 100644 --- a/doc/awkcard.in +++ b/doc/awkcard.in @@ -2,7 +2,7 @@ .\" .\" Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, .\" 2005, 2007, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, -.\" 2019, 2020 +.\" 2019, 2020, 2021 .\" Free Software Foundation, Inc. .\" .\" Permission is granted to make and distribute verbatim copies of @@ -100,7 +100,7 @@ Variables 5\*(CX \*(CD .SL .nf -\*(FRCopyright \(co 1996\(en2005, 2007, 2009\(en2020 +\*(FRCopyright \(co 1996\(en2005, 2007, 2009\(en2021 Free Software Foundation, Inc. .nf .BT @@ -1916,6 +1916,19 @@ See the manual for details.\*(CB .EB "\s+2\f(HBDYNAMIC EXTENSIONS (\*(GK\f(HB)\*(FR\s0" .BT +.\" --- Generator Functions +.ES +.fi +.in +.2i +.ti -.2i +\*(CD\*(FCmkbool(\*(FIexpression\*(FC)\*(FR +.br +Return a Boolean-typed value based on the Boolean value +of \*(FIexpression\fP. True values have a numeric value of one. +False values have a numeric value of zero.\*(CB +.in -.2i +.EB "\s+2\f(HBGENERATOR FUNCTIONS (\*(GK\f(HB)\*(FR\s0" +.sp .5 .\" --- Type Functions .ES .fi @@ -1959,11 +1972,6 @@ Return the translation of \*(FIstring\*(FR in text domain \*(FIdomain\*(FR for locale category \*(FIcategory\*(FR. The default value for \*(FIdomain\*(FR is the current value of \*(FCTEXTDOMAIN\*(FR. The default value for \*(FIcategory\*(FR is \*(FC"LC_MESSAGES"\*(FR. -.sp .5 -If you supply a value for \*(FIcategory\*(FR, it must be a string equal to -one of the known locale categories. -You must also supply a text domain. Use \*(FCTEXTDOMAIN\*(FR -to use the current domain. .ti -.2i \*(FCdcngettext(\*(FIstring1\*(FC, \*(FIstring2\*(FC, \*(FInumber\*(FR [\*(FC, \*(FIdom \*(FR[\*(FC, \*(FIcat\*(FR]]\*(FC)\*(FR .br @@ -1971,12 +1979,7 @@ Return the plural form used for \*(FInumber\*(FR of the translation of \*(FIstring1\*(FR and \*(FIstring2\*(FR in text domain \*(FIdom\*(FR for locale category \*(FIcat\*(FR. The default value for \*(FIdom\*(FR is the current value of \*(FCTEXTDOMAIN\*(FR. -The default for \*(FIcat\*(FR is \*(FC"LC_MESSAGES"\*(FR. -.sp .5 -If you supply a value for \*(FIcat\*(FR, it must be a string equal to -one of the known locale categories. -You must also supply a text domain. Use \*(FCTEXTDOMAIN\*(FR -to use the current domain.\*(CB +The default for \*(FIcat\*(FR is \*(FC"LC_MESSAGES"\*(FR.\*(CB .in -.2i .EB "\s+2\f(HBINTERNATIONALIZATION (\*(GK\f(HB)\*(FR\s0" .sp .5 @@ -2012,7 +2015,7 @@ maintains it.\*(CX .ES .fi \*(CDCopyright \(co 1996\(en2005, -2007, 2009\(en2020 Free Software Foundation, Inc. +2007, 2009\(en2021 Free Software Foundation, Inc. .sp .5 Permission is granted to make and distribute verbatim copies of this reference card provided the copyright notice and this permission notice @@ -13,7 +13,7 @@ . if \w'\(rq' .ds rq "\(rq . \} .\} -.TH GAWK 1 "Aug 31 2020" "Free Software Foundation" "Utility Commands" +.TH GAWK 1 "May 02 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 mkbool( expression\^ ) +Based on the boolean value of +.I expression +return either a true value or a false value. +True values have numeric value one. +False values have numeric value zero. .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..824d78e7 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,24 @@ 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::): + +'bmkool(EXPRESSION)' + Return a Boolean-typed value based on the regular Boolean value of + EXPRESSION. Boolean "true" values have numeric value one. Boolean + "false" values have numeric zero. 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 +12983,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 +13551,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 +13697,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 +13914,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 +14231,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 +14413,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 @@ -14418,6 +14437,9 @@ contexts. '"number"' X is a number. + '"number|bool"' + X is a Boolean typed value (*note Boolean Typed Values::). + '"string"' X is a string. @@ -14479,7 +14501,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 +15180,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 +20895,7 @@ their own: * Menu: * Nondecimal Data:: Allowing nondecimal input data. +* Boolean Typed Values:: Values with 'number|bool' type. * Array Sorting:: Facilities for controlling array traversal and sorting arrays. * Two-way I/O:: Two-way communications with another process. @@ -20882,7 +20905,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 +20948,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. + + 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 'mkbool()'. +It takes one argument, which is any 'awk' expression, and it returns a +value of Boolean type. + + The returned values are normal 'awk' numeric values, with values of +either one or zero, depending upon the truth value of the original +expression passed in the call to 'bool()'. + + The 'typeof()' function (*note Type Functions::) returns +'"number|bool"' for these values. + + Thus Boolean-typed values _are_ numbers as far as 'gawk' is +concerned, except that extension code can treat them as Booleans if +desired. + + While it would have been possible to add two new built-in variables +of Boolean type named '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 +as much existing code. + + +File: gawk.info, Node: Array Sorting, Next: Two-way I/O, Prev: Boolean Typed Values, Up: Advanced Features -12.2 Controlling Array Traversal and Array Sorting +12.3 Controlling Array Traversal and Array Sorting ================================================== 'gawk' lets you control the order in which a 'for (INDX in ARRAY)' loop @@ -20946,7 +21013,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 +21252,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 +21392,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 +21587,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 +21667,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 +21929,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 +21965,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 +25587,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 +25601,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 +25617,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 +25928,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 +26658,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 @@ -33152,8 +33228,8 @@ Localization Logical Expression An expression using the operators for logic, AND, OR, and NOT, - written '&&', '||', and '!' in 'awk'. Often called Boolean - expressions, after the mathematician who pioneered this kind of + written '&&', '||', and '!' in 'awk'. Often called "Boolean + expressions", after the mathematician who pioneered this kind of mathematical logic. Lvalue @@ -35310,6 +35386,7 @@ Index * body, in loops: While Statement. (line 14) * 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) @@ -36898,6 +36975,7 @@ Index * metacharacters, escape sequences for: Escape Sequences. (line 140) * metacharacters, in regular expressions: Regexp Operators. (line 6) * minimum precision required by MPFR library: Auto-set. (line 279) +* mkbool: Boolean Functions. (line 10) * mktime: Time Functions. (line 25) * modifiers, in format specifiers: Format Modifiers. (line 6) * module, definition of: Global Namespace. (line 18) @@ -38116,604 +38194,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 Functions545452 +Ref: Numeric Functions-Footnote-1549479 +Ref: Numeric Functions-Footnote-2550127 +Ref: Numeric Functions-Footnote-3550175 +Node: String Functions550447 +Ref: String Functions-Footnote-1574588 +Ref: String Functions-Footnote-2574716 +Ref: String Functions-Footnote-3574964 +Node: Gory Details575051 +Ref: table-sub-escapes576842 +Ref: table-sub-proposed578361 +Ref: table-posix-sub579724 +Ref: table-gensub-escapes581265 +Ref: Gory Details-Footnote-1582088 +Node: I/O Functions582242 +Ref: table-system-return-values588696 +Ref: I/O Functions-Footnote-1590776 +Ref: I/O Functions-Footnote-2590924 +Node: Time Functions591044 +Ref: Time Functions-Footnote-1601715 +Ref: Time Functions-Footnote-2601783 +Ref: Time Functions-Footnote-3601941 +Ref: Time Functions-Footnote-4602052 +Ref: Time Functions-Footnote-5602164 +Ref: Time Functions-Footnote-6602391 +Node: Bitwise Functions602657 +Ref: table-bitwise-ops603251 +Ref: Bitwise Functions-Footnote-1609314 +Ref: Bitwise Functions-Footnote-2609487 +Node: Type Functions609678 +Node: I18N Functions612632 +Node: User-defined614283 +Node: Definition Syntax615095 +Ref: Definition Syntax-Footnote-1620789 +Node: Function Example620860 +Ref: Function Example-Footnote-1623782 +Node: Function Calling623804 +Node: Calling A Function624392 +Node: Variable Scope625350 +Node: Pass By Value/Reference628344 +Node: Function Caveats630988 +Ref: Function Caveats-Footnote-1633035 +Node: Return Statement633155 +Node: Dynamic Typing636134 +Node: Indirect Calls637064 +Ref: Indirect Calls-Footnote-1647319 +Node: Functions Summary647447 +Node: Library Functions650152 +Ref: Library Functions-Footnote-1653759 +Ref: Library Functions-Footnote-2653902 +Node: Library Names654073 +Ref: Library Names-Footnote-1657740 +Ref: Library Names-Footnote-2657963 +Node: General Functions658049 +Node: Strtonum Function659152 +Node: Assert Function662174 +Node: Round Function665500 +Node: Cliff Random Function667040 +Node: Ordinal Functions668056 +Ref: Ordinal Functions-Footnote-1671119 +Ref: Ordinal Functions-Footnote-2671371 +Node: Join Function671581 +Ref: Join Function-Footnote-1673351 +Node: Getlocaltime Function673551 +Node: Readfile Function677293 +Node: Shell Quoting679270 +Node: Data File Management680671 +Node: Filetrans Function681303 +Node: Rewind Function685399 +Node: File Checking687308 +Ref: File Checking-Footnote-1688642 +Node: Empty Files688843 +Node: Ignoring Assigns690822 +Node: Getopt Function692372 +Ref: Getopt Function-Footnote-1707583 +Node: Passwd Functions707783 +Ref: Passwd Functions-Footnote-1716622 +Node: Group Functions716710 +Ref: Group Functions-Footnote-1724608 +Node: Walking Arrays724815 +Node: Library Functions Summary727823 +Node: Library Exercises729229 +Node: Sample Programs729694 +Node: Running Examples730464 +Node: Clones731192 +Node: Cut Program732416 +Node: Egrep Program742556 +Node: Id Program751557 +Node: Split Program761504 +Ref: Split Program-Footnote-1771394 +Node: Tee Program771567 +Node: Uniq Program774357 +Node: Wc Program781945 +Node: Bytes vs. Characters782332 +Node: Using extensions783880 +Node: wc program784634 +Node: Miscellaneous Programs789499 +Node: Dupword Program790712 +Node: Alarm Program792742 +Node: Translate Program797597 +Ref: Translate Program-Footnote-1802162 +Node: Labels Program802432 +Ref: Labels Program-Footnote-1805783 +Node: Word Sorting805867 +Node: History Sorting809939 +Node: Extract Program812164 +Node: Simple Sed820218 +Node: Igawk Program823292 +Ref: Igawk Program-Footnote-1837623 +Ref: Igawk Program-Footnote-2837825 +Ref: Igawk Program-Footnote-3837947 +Node: Anagram Program838062 +Node: Signature Program841124 +Node: Programs Summary842371 +Node: Programs Exercises843585 +Ref: Programs Exercises-Footnote-1847715 +Node: Advanced Features847801 +Node: Nondecimal Data849932 +Node: Boolean Typed Values851530 +Node: Array Sorting853409 +Node: Controlling Array Traversal854114 +Ref: Controlling Array Traversal-Footnote-1862482 +Node: Array Sorting Functions862600 +Ref: Array Sorting Functions-Footnote-1867691 +Node: Two-way I/O867887 +Ref: Two-way I/O-Footnote-1875608 +Ref: Two-way I/O-Footnote-2875795 +Node: TCP/IP Networking875877 +Node: Profiling878995 +Node: Extension Philosophy888304 +Node: Advanced Features Summary889783 +Node: Internationalization891798 +Node: I18N and L10N893278 +Node: Explaining gettext893965 +Ref: Explaining gettext-Footnote-1899857 +Ref: Explaining gettext-Footnote-2900042 +Node: Programmer i18n900207 +Ref: Programmer i18n-Footnote-1905156 +Node: Translator i18n905205 +Node: String Extraction905999 +Ref: String Extraction-Footnote-1907131 +Node: Printf Ordering907217 +Ref: Printf Ordering-Footnote-1910003 +Node: I18N Portability910067 +Ref: I18N Portability-Footnote-1912523 +Node: I18N Example912586 +Ref: I18N Example-Footnote-1915861 +Ref: I18N Example-Footnote-2915934 +Node: Gawk I18N916043 +Node: I18N Summary916692 +Node: Debugger918033 +Node: Debugging919033 +Node: Debugging Concepts919474 +Node: Debugging Terms921283 +Node: Awk Debugging923858 +Ref: Awk Debugging-Footnote-1924803 +Node: Sample Debugging Session924935 +Node: Debugger Invocation925469 +Node: Finding The Bug926855 +Node: List of Debugger Commands933329 +Node: Breakpoint Control934662 +Node: Debugger Execution Control938356 +Node: Viewing And Changing Data941718 +Node: Execution Stack945259 +Node: Debugger Info946896 +Node: Miscellaneous Debugger Commands950967 +Node: Readline Support956029 +Node: Limitations956925 +Node: Debugging Summary959479 +Node: Namespaces960758 +Node: Global Namespace961869 +Node: Qualified Names963267 +Node: Default Namespace964266 +Node: Changing The Namespace965007 +Node: Naming Rules966621 +Node: Internal Name Management968469 +Node: Namespace Example969511 +Node: Namespace And Features972073 +Node: Namespace Summary973508 +Node: Arbitrary Precision Arithmetic974985 +Node: Computer Arithmetic976472 +Ref: table-numeric-ranges980238 +Ref: table-floating-point-ranges980731 +Ref: Computer Arithmetic-Footnote-1981389 +Node: Math Definitions981446 +Ref: table-ieee-formats984422 +Node: MPFR features984989 +Node: FP Math Caution986707 +Ref: FP Math Caution-Footnote-1987779 +Node: Inexactness of computations988148 +Node: Inexact representation989179 +Node: Comparing FP Values990539 +Node: Errors accumulate991780 +Node: Strange values993236 +Ref: Strange values-Footnote-1995824 +Node: Getting Accuracy995929 +Node: Try To Round998639 +Node: Setting precision999538 +Ref: table-predefined-precision-strings1000235 +Node: Setting the rounding mode1002065 +Ref: table-gawk-rounding-modes1002439 +Ref: Setting the rounding mode-Footnote-11006370 +Node: Arbitrary Precision Integers1006549 +Ref: Arbitrary Precision Integers-Footnote-11009724 +Node: Checking for MPFR1009873 +Node: POSIX Floating Point Problems1011347 +Ref: POSIX Floating Point Problems-Footnote-11015632 +Node: Floating point summary1015670 +Node: Dynamic Extensions1017860 +Node: Extension Intro1019413 +Node: Plugin License1020679 +Node: Extension Mechanism Outline1021476 +Ref: figure-load-extension1021915 +Ref: figure-register-new-function1023480 +Ref: figure-call-new-function1024572 +Node: Extension API Description1026634 +Node: Extension API Functions Introduction1028347 +Ref: table-api-std-headers1030183 +Node: General Data Types1034432 +Ref: General Data Types-Footnote-11043138 +Node: Memory Allocation Functions1043437 +Ref: Memory Allocation Functions-Footnote-11047938 +Node: Constructor Functions1048037 +Node: API Ownership of MPFR and GMP Values1051690 +Node: Registration Functions1053003 +Node: Extension Functions1053703 +Node: Exit Callback Functions1059025 +Node: Extension Version String1060275 +Node: Input Parsers1060938 +Node: Output Wrappers1073659 +Node: Two-way processors1078171 +Node: Printing Messages1080436 +Ref: Printing Messages-Footnote-11081607 +Node: Updating ERRNO1081760 +Node: Requesting Values1082499 +Ref: table-value-types-returned1083236 +Node: Accessing Parameters1084344 +Node: Symbol Table Access1085581 +Node: Symbol table by name1086093 +Ref: Symbol table by name-Footnote-11089117 +Node: Symbol table by cookie1089245 +Ref: Symbol table by cookie-Footnote-11093430 +Node: Cached values1093494 +Ref: Cached values-Footnote-11097030 +Node: Array Manipulation1097183 +Ref: Array Manipulation-Footnote-11098274 +Node: Array Data Types1098311 +Ref: Array Data Types-Footnote-11100969 +Node: Array Functions1101061 +Node: Flattening Arrays1105559 +Node: Creating Arrays1112535 +Node: Redirection API1117302 +Node: Extension API Variables1120135 +Node: Extension Versioning1120846 +Ref: gawk-api-version1121275 +Node: Extension GMP/MPFR Versioning1123006 +Node: Extension API Informational Variables1124634 +Node: Extension API Boilerplate1125707 +Node: Changes from API V11129681 +Node: Finding Extensions1131253 +Node: Extension Example1131812 +Node: Internal File Description1132610 +Node: Internal File Ops1136690 +Ref: Internal File Ops-Footnote-11148040 +Node: Using Internal File Ops1148180 +Ref: Using Internal File Ops-Footnote-11150563 +Node: Extension Samples1150837 +Node: Extension Sample File Functions1152366 +Node: Extension Sample Fnmatch1160015 +Node: Extension Sample Fork1161502 +Node: Extension Sample Inplace1162720 +Node: Extension Sample Ord1166346 +Node: Extension Sample Readdir1167182 +Ref: table-readdir-file-types1168071 +Node: Extension Sample Revout1169138 +Node: Extension Sample Rev2way1169727 +Node: Extension Sample Read write array1170467 +Node: Extension Sample Readfile1172409 +Node: Extension Sample Time1173504 +Node: Extension Sample API Tests1175256 +Node: gawkextlib1175748 +Node: Extension summary1178666 +Node: Extension Exercises1182368 +Node: Language History1183610 +Node: V7/SVR3.11185266 +Node: SVR41187418 +Node: POSIX1188852 +Node: BTL1190233 +Node: POSIX/GNU1190962 +Node: Feature History1196740 +Node: Common Extensions1213059 +Node: Ranges and Locales1214342 +Ref: Ranges and Locales-Footnote-11218958 +Ref: Ranges and Locales-Footnote-21218985 +Ref: Ranges and Locales-Footnote-31219220 +Node: Contributors1219443 +Node: History summary1225440 +Node: Installation1226820 +Node: Gawk Distribution1227764 +Node: Getting1228248 +Node: Extracting1229211 +Node: Distribution contents1230849 +Node: Unix Installation1237329 +Node: Quick Installation1238011 +Node: Shell Startup Files1240425 +Node: Additional Configuration Options1241514 +Node: Configuration Philosophy1243829 +Node: Non-Unix Installation1246198 +Node: PC Installation1246658 +Node: PC Binary Installation1247496 +Node: PC Compiling1247931 +Node: PC Using1249048 +Node: Cygwin1252601 +Node: MSYS1253825 +Node: VMS Installation1254427 +Node: VMS Compilation1255218 +Ref: VMS Compilation-Footnote-11256447 +Node: VMS Dynamic Extensions1256505 +Node: VMS Installation Details1258190 +Node: VMS Running1260443 +Node: VMS GNV1264722 +Node: VMS Old Gawk1265457 +Node: Bugs1265928 +Node: Bug address1266591 +Node: Usenet1269573 +Node: Maintainers1270577 +Node: Other Versions1271762 +Node: Installation summary1279627 +Node: Notes1280836 +Node: Compatibility Mode1281630 +Node: Additions1282412 +Node: Accessing The Source1283337 +Node: Adding Code1284774 +Node: New Ports1290993 +Node: Derived Files1295368 +Ref: Derived Files-Footnote-11301028 +Ref: Derived Files-Footnote-21301063 +Ref: Derived Files-Footnote-31301661 +Node: Future Extensions1301775 +Node: Implementation Limitations1302433 +Node: Extension Design1303643 +Node: Old Extension Problems1304787 +Ref: Old Extension Problems-Footnote-11306305 +Node: Extension New Mechanism Goals1306362 +Ref: Extension New Mechanism Goals-Footnote-11309726 +Node: Extension Other Design Decisions1309915 +Node: Extension Future Growth1312028 +Node: Notes summary1312634 +Node: Basic Concepts1313792 +Node: Basic High Level1314473 +Ref: figure-general-flow1314755 +Ref: figure-process-flow1315440 +Ref: Basic High Level-Footnote-11318741 +Node: Basic Data Typing1318926 +Node: Glossary1322254 +Node: Copying1354141 +Node: GNU Free Documentation License1391684 +Node: Index1416804 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index e87a1e84..89921663 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{bmkool(@var{expression})} +@cindexgawkfunc{mkbool} +Return a Boolean-typed value based on the regular Boolean value +of @var{expression}. Boolean ``true'' values have numeric value one. +Boolean ``false'' values have numeric +zero. This is discussed in more +detail in @ref{Boolean Typed Values}. +@end table + @node Numeric Functions @subsection Numeric Functions @cindex numeric @subentry functions @@ -20898,6 +20921,9 @@ Return one of the following strings, depending upon the type of @var{x}: @item "number" @var{x} is a number. +@item "number|bool" +@var{x} is a Boolean typed value (@pxref{Boolean Typed Values}). + @item "string" @var{x} is a string. @@ -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{number|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,49 @@ leads to less surprising results. This option may disappear in a future version of @command{gawk}. @end quotation +@node Boolean Typed Values +@section Boolean Typed Values + +Scalar values in @command{awk} are either numbers or strings. +@command{gawk} also supports values of type @code{regexp} +(@pxref{Strong Regexp Constants}). + +As described in @ref{Truth Values}, Boolean values in @command{awk} +don't have a separate type: a value counts as ``true'' if it is nonzero +or non-null, and as ``false'' otherwise. + +When interchanging data with languages that do have a real Boolean type, +using a standard format such as JSON or XML, the lack of a true Boolean +type in @command{awk} is problematic. +(See, for example, the @code{json} extension provided by +@uref{https://sourceforge.net/projects/gawkextlib, the @code{gawkextlib} project}.) + +It's easy to import Boolean data into @command{awk}, but then the fact +that it was originally Boolean is lost. Exporting data is even harder; +there's no way to indicate that a value is really Boolean. + +To solve this problem, @command{gawk} provides a function named @code{mkbool()}. +It takes one argument, which is any @command{awk} expression, and it +returns a value of Boolean type. + +The returned values are normal @command{awk} numeric values, with +values of either one or zero, +depending upon the truth +value of the original expression passed in the call to @code{bool()}. + +The @code{typeof()} function (@pxref{Type Functions}) returns +@code{"number|bool"} for these values. + +Thus Boolean-typed values @emph{are} numbers as far as @command{gawk} +is concerned, except that extension code can treat them as Booleans +if desired. + +While it would have been possible to add two new built-in variables +of Boolean type named @code{TRUE} and @code{FALSE}, doing so would +undoubtedly have broken many existing @command{awk} programs. Instead, +having a ``generator'' function that creates Boolean values gives +flexibility, without breaking as much existing code. + @node Array Sorting @section Controlling Array Traversal and Array Sorting @@ -35586,7 +35656,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 +35670,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 +35686,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 +36014,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 +36819,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 +36830,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 +36843,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 +36856,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 +36865,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 +36874,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 +36882,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 +36909,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 +36920,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 +36933,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 +36950,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 @@ -45202,8 +45304,8 @@ internationalized program to work in a particular language. @item Logical Expression An expression using the operators for logic, AND, OR, and NOT, written -@samp{&&}, @samp{||}, and @samp{!} in @command{awk}. Often called Boolean -expressions, after the mathematician who pioneered this kind of +@samp{&&}, @samp{||}, and @samp{!} in @command{awk}. Often called @dfn{Boolean +expressions}, after the mathematician who pioneered this kind of mathematical logic. @item Lvalue diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 95606cf3..75607b2b 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{bmkool(@var{expression})} +@cindexgawkfunc{mkbool} +Return a Boolean-typed value based on the regular Boolean value +of @var{expression}. Boolean ``true'' values have numeric value one. +Boolean ``false'' values have numeric +zero. This is discussed in more +detail in @ref{Boolean Typed Values}. +@end table + @node Numeric Functions @subsection Numeric Functions @cindex numeric @subentry functions @@ -19810,6 +19833,9 @@ Return one of the following strings, depending upon the type of @var{x}: @item "number" @var{x} is a number. +@item "number|bool" +@var{x} is a Boolean typed value (@pxref{Boolean Typed Values}). + @item "string" @var{x} is a string. @@ -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{number|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,49 @@ leads to less surprising results. This option may disappear in a future version of @command{gawk}. @end quotation +@node Boolean Typed Values +@section Boolean Typed Values + +Scalar values in @command{awk} are either numbers or strings. +@command{gawk} also supports values of type @code{regexp} +(@pxref{Strong Regexp Constants}). + +As described in @ref{Truth Values}, Boolean values in @command{awk} +don't have a separate type: a value counts as ``true'' if it is nonzero +or non-null, and as ``false'' otherwise. + +When interchanging data with languages that do have a real Boolean type, +using a standard format such as JSON or XML, the lack of a true Boolean +type in @command{awk} is problematic. +(See, for example, the @code{json} extension provided by +@uref{https://sourceforge.net/projects/gawkextlib, the @code{gawkextlib} project}.) + +It's easy to import Boolean data into @command{awk}, but then the fact +that it was originally Boolean is lost. Exporting data is even harder; +there's no way to indicate that a value is really Boolean. + +To solve this problem, @command{gawk} provides a function named @code{mkbool()}. +It takes one argument, which is any @command{awk} expression, and it +returns a value of Boolean type. + +The returned values are normal @command{awk} numeric values, with +values of either one or zero, +depending upon the truth +value of the original expression passed in the call to @code{bool()}. + +The @code{typeof()} function (@pxref{Type Functions}) returns +@code{"number|bool"} for these values. + +Thus Boolean-typed values @emph{are} numbers as far as @command{gawk} +is concerned, except that extension code can treat them as Booleans +if desired. + +While it would have been possible to add two new built-in variables +of Boolean type named @code{TRUE} and @code{FALSE}, doing so would +undoubtedly have broken many existing @command{awk} programs. Instead, +having a ``generator'' function that creates Boolean values gives +flexibility, without breaking as much existing code. + @node Array Sorting @section Controlling Array Traversal and Array Sorting @@ -34429,7 +34499,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 +34513,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 +34529,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 +34857,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 +35662,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 +35673,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 +35686,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 +35699,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 +35708,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 +35717,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 +35725,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 +35752,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 +35763,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 +35776,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 +35793,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 @@ -44045,8 +44147,8 @@ internationalized program to work in a particular language. @item Logical Expression An expression using the operators for logic, AND, OR, and NOT, written -@samp{&&}, @samp{||}, and @samp{!} in @command{awk}. Often called Boolean -expressions, after the mathematician who pioneered this kind of +@samp{&&}, @samp{||}, and @samp{!} in @command{awk}. Often called @dfn{Boolean +expressions}, after the mathematician who pioneered this kind of mathematical logic. @item Lvalue @@ -442,6 +442,7 @@ flags2str(int flagval) { NUMCUR, "NUMCUR" }, { NUMBER, "NUMBER" }, { USER_INPUT, "USER_INPUT" }, + { BOOL, "BOOL" }, { INTLSTR, "INTLSTR" }, { NUMINT, "NUMINT" }, { INTIND, "INTIND" }, 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; @@ -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 NUMBER|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 NUMBER|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 NUMBER|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 NUMBER|BOOL: + assign_bool(node, val); + ret = awk_true; + break; case STRING: assign_string(node, val, AWK_STRING); ret = awk_true; @@ -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: @@ -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 */ @@ -1082,3 +1082,24 @@ 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 ? "1" : "0"); + nval = (value ? 1.0 : 0.0); + + val = make_number(nval); + val->stptr = estrdup(sval, strlen(sval)); + val->stlen = strlen(sval); + 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 641a9849..7198c0fe 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,9 +1,30 @@ +2021-05-02 Arnold D. Robbins <arnold@skeeve.com> + + * asortbool.awk, functab5.ok, id.ok, rwarrray.awk, + symtab11.ok: Revise after code changes. + +2021-04-28 Arnold D. Robbins <arnold@skeeve.com> + + * asortbool.ok: Revise after code changes. + * rwarray.awk: Ditto. + 2021-04-14 Arnold D. Robbins <arnold@skeeve.com> * noeffect.awk: Add more test cases. Thanks to Wolfgang Laun <wolfgang.laun@gmail.com>. * lintwarn.ok, noeffect.ok: Updated after code and test changes. +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 559e0163..9876863d 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..3ee02cb2 --- /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] = mkbool(1) + a[6] = mkbool(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..623e417a --- /dev/null +++ b/test/asortbool.ok @@ -0,0 +1,6 @@ +1, number: -45 +2, number|bool: 0 +3, number|bool: 1 +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..d27f1393 100644 --- a/test/functab5.ok +++ b/test/functab5.ok @@ -21,6 +21,7 @@ length' log' lshift' match' +mkbool' mktime' or' patsplit' @@ -52,6 +52,7 @@ length -> builtin log -> builtin lshift -> builtin match -> builtin +mkbool -> builtin mktime -> builtin or -> builtin patsplit -> 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..eae22304 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] = mkbool(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]) != "number|bool") + printf("dict[\"%s\"] should be number|bool, is %s\n", + bool_sub, typeof(dict[bool_sub])); + + if ((dict[bool_sub] "") != "1") + printf("dict[\"%s\"] should be 1, is %s\n", + bool_sub, dict[bool_sub]); } diff --git a/test/symtab11.ok b/test/symtab11.ok index 7d4be46c..c46d3aed 100644 --- a/test/symtab11.ok +++ b/test/symtab11.ok @@ -53,6 +53,7 @@ BEGIN -- Functab is next [log] = log [lshift] = lshift [match] = match +[mkbool] = mkbool [mktime] = mktime [or] = or [patsplit] = patsplit 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 |