diff options
-rw-r--r-- | ChangeLog | 39 | ||||
-rw-r--r-- | array.c | 15 | ||||
-rw-r--r-- | awk.h | 6 | ||||
-rw-r--r-- | awkgram.c | 1 | ||||
-rw-r--r-- | awkgram.y | 1 | ||||
-rw-r--r-- | bool.notes | 53 | ||||
-rw-r--r-- | builtin.c | 42 | ||||
-rw-r--r-- | doc/ChangeLog | 4 | ||||
-rw-r--r-- | doc/gawk.info | 309 | ||||
-rw-r--r-- | doc/gawk.texi | 100 | ||||
-rw-r--r-- | doc/gawktexi.in | 100 | ||||
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | extension/ChangeLog | 4 | ||||
-rw-r--r-- | extension/testext.c | 7 | ||||
-rw-r--r-- | field.c | 2 | ||||
-rw-r--r-- | gawkapi.c | 38 | ||||
-rw-r--r-- | gawkapi.h | 61 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | node.c | 22 | ||||
-rw-r--r-- | test/ChangeLog | 5 | ||||
-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/symtab11.ok | 1 | ||||
-rw-r--r-- | test/symtab8.ok | 2 |
26 files changed, 568 insertions, 254 deletions
@@ -1,9 +1,48 @@ +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 @@ -1209,11 +1209,24 @@ do_sort_up_value_type(const void *p1, const void *p2) (void) fixtype(n1); (void) fixtype(n2); + /* 3a. Bools first */ + if ((n1->flags & BOOL) != 0 && (n2->flags & BOOL) != 0) { + return cmp_numbers(n1, n2); + } + + /* 3b. Numbers next */ if ((n1->flags & NUMBER) != 0 && (n2->flags & NUMBER) != 0) { return cmp_numbers(n1, n2); } - /* 3. All numbers are less than all strings. This is aribitrary. */ + /* 3c. Bools before everything else */ + if ((n1->flags & BOOL) != 0 && (n2->flags & BOOL) == 0) { + return -1; + } else if ((n1->flags & BOOL) == 0 && (n2->flags & BOOL) != 0) { + return 1; + } + + /* 3d. All numbers are less than all strings. This is aribitrary. */ if ((n1->flags & NUMBER) != 0 && (n2->flags & STRING) != 0) { return -1; } else if ((n1->flags & STRING) != 0 && (n2->flags & NUMBER) != 0) { @@ -463,6 +463,7 @@ typedef struct exp_node { XARRAY = 0x10000, NUMCONSTSTR = 0x20000, /* have string value for numeric constant */ REGEX = 0x40000, /* this is a typed regex */ + BOOL = 0x80000, /* this is a boolean value */ } flags; long valref; } NODE; @@ -1454,6 +1455,7 @@ extern bool is_identchar(int c); extern NODE *make_regnode(NODETYPE type, NODE *exp); extern bool validate_qualified_name(char *token); /* builtin.c */ +extern void warn_bool(const char *func, int argnum, NODE *n); extern double double_to_int(double d); extern NODE *do_exp(int nargs); extern NODE *do_fflush(int nargs); @@ -1503,6 +1505,7 @@ extern int strncasecmpmbs(const unsigned char *, const unsigned char *, size_t); extern int sanitize_exit_status(int status); extern void check_symtab_functab(NODE *dest, const char *fname, const char *msg); +extern NODE *do_bool(int nargs); /* debug.c */ extern void init_debug(void); extern int debug_prog(INSTRUCTION *pc); @@ -1714,6 +1717,7 @@ extern NODE *r_force_number(NODE *n); extern NODE *r_format_val(const char *format, int index, NODE *s); extern NODE *r_dupnode(NODE *n); extern NODE *make_str_node(const char *s, size_t len, int flags); +extern NODE *make_bool_node(bool value); extern NODE *make_typed_regex(const char *re, size_t len); extern void *more_blocks(int id); extern int parse_escape(const char **string_ptr); @@ -1995,7 +1999,7 @@ static inline bool boolval(NODE *t) { (void) fixtype(t); - if ((t->flags & NUMBER) != 0) + if ((t->flags & (BOOL|NUMBER)) != 0) return ! is_zero(t); return (t->stlen > 0); } @@ -4779,6 +4779,7 @@ static const struct token tokentab[] = { {"asorti", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2)|A(3), do_asorti, 0}, {"atan2", Op_builtin, LEX_BUILTIN, NOT_OLD|A(2), do_atan2, MPF(atan2)}, {"bindtextdomain", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2), do_bindtextdomain, 0}, +{"bool", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_bool, 0}, {"break", Op_K_break, LEX_BREAK, 0, 0, 0}, {"case", Op_K_case, LEX_CASE, GAWKX, 0, 0}, {"close", Op_builtin, LEX_BUILTIN, NOT_OLD|A(1)|A(2), do_close, 0}, @@ -2277,6 +2277,7 @@ static const struct token tokentab[] = { {"asorti", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2)|A(3), do_asorti, 0}, {"atan2", Op_builtin, LEX_BUILTIN, NOT_OLD|A(2), do_atan2, MPF(atan2)}, {"bindtextdomain", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2), do_bindtextdomain, 0}, +{"bool", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_bool, 0}, {"break", Op_K_break, LEX_BREAK, 0, 0, 0}, {"case", Op_K_case, LEX_CASE, GAWKX, 0, 0}, {"close", Op_builtin, LEX_BUILTIN, NOT_OLD|A(1)|A(2), do_close, 0}, diff --git a/bool.notes b/bool.notes new file mode 100644 index 00000000..8e24c2b5 --- /dev/null +++ b/bool.notes @@ -0,0 +1,53 @@ +Thu Mar 18 21:05:29 IST 2021 +============================ + +Design Notes for a Boolean Type in Gawk + +1. A new function bool(val) converts val to bool, returning Boolean TRUE +or FALSE. This is the generator for boolean values and is enough to have +instead of predefining new variables TRUE and FALSE. + +2. Assigning from a boolean value copies the bool type. + +3. Boolean variables have numeric values 1 and 0 respectively, and string +values "TRUE" and "FALSE". Thus they differ from other variables where a +"false" value must be zero and null. + +Given: + + true = bool(1) + false = bool(0) + +this implies all of the following: + + print(true) --> "TRUE" + print(false) --> "FALSE" + Same for %s in printf + Same for bool_var "" + printf %d gives 0/1 + +4. typeof() returns "bool". + +5. Numeric operators treat booleans as numbers. asort() sorts booleans before +numbers, and false before true. + +6. These string function generate a runtime fatal error +if given an argument / target of boolean type: + + gsub sub + +These functions merely treat the value as a string +but issue a lint warning. + + substr match index gensub + length split patsplit + tolower toupper + +7. Updates to API needed for an additional type, and the table +for requested vs. returns. + +8. The following extensions need revising: + + - JSON extension + - dump / read array extensions + - what else? @@ -381,6 +381,8 @@ do_index(int nargs) s1 = force_string(s1); s2 = force_string(s2); + warn_bool("index", 1, s1); + warn_bool("index", 2, s2); p1 = s1->stptr; p2 = s2->stptr; @@ -552,6 +554,7 @@ do_length(int nargs) if (do_lint && (fixtype(tmp)->flags & STRING) == 0) lintwarn(_("%s: received non-string argument"), "length"); tmp = force_string(tmp); + warn_bool("length", 1, tmp); if (gawk_mb_cur_max > 1) { tmp = force_wstring(tmp); @@ -1779,6 +1782,16 @@ do_sqrt(int nargs) return make_number((AWKNUM) sqrt(arg)); } +/* warn_bool --- warn that bool parameter is used as a string */ + +void +warn_bool(const char *func, int argnum, NODE *n) +{ + if (do_lint && (n->flags & BOOL) != 0) + lintwarn(_("%s: argument %d of type bool used as a string"), + func, argnum); +} + /* do_substr --- do the substr function */ NODE * @@ -1802,6 +1815,7 @@ do_substr(int nargs) DEREF(t1); t1 = POP_STRING(); + warn_bool("substr", 1, t1); if (nargs == 3) { if (! (d_length >= 1)) { @@ -2407,6 +2421,7 @@ do_tolower(int nargs) NODE *t1, *t2; t1 = POP_SCALAR(); + warn_bool("tolower", 1, t1); if (do_lint && (fixtype(t1)->flags & STRING) == 0) lintwarn(_("%s: received non-string argument"), "tolower"); t1 = force_string(t1); @@ -2438,6 +2453,7 @@ do_toupper(int nargs) NODE *t1, *t2; t1 = POP_SCALAR(); + warn_bool("toupper", 1, t1); if (do_lint && (fixtype(t1)->flags & STRING) == 0) lintwarn(_("%s: received non-string argument"), "toupper"); t1 = force_string(t1); @@ -2662,6 +2678,7 @@ do_match(int nargs) tre = POP(); rp = re_update(tre); t1 = POP_STRING(); + warn_bool("mastch", 1, t1); rstart = research(rp, t1->stptr, 0, t1->stlen, RE_NEED_START); if (rstart >= 0) { /* match succeded */ @@ -2882,6 +2899,7 @@ do_sub(int nargs, unsigned int flags) rp = re_update(tmp); target = POP_STRING(); /* original string */ + warn_bool("gensub", 3, target); glob_flag = POP_SCALAR(); /* value of global flag */ if ( (glob_flag->flags & STRING) != 0 @@ -2924,6 +2942,10 @@ do_sub(int nargs, unsigned int flags) } } + if ((target->flags & BOOL) != 0) + fatal(_("%s: target cannot be of type bool"), + (flags & GSUB) != 0 ? "gsub" : "sub"); + global = (how_many == -1); rep_node = POP_STRING(); /* replacement text */ @@ -4112,7 +4134,10 @@ do_typeof(int nargs) } break; case Node_val: - switch (fixtype(arg)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) { + switch (fixtype(arg)->flags & (STRING|NUMBER|USER_INPUT|REGEX|BOOL)) { + case BOOL: + res = "bool"; + break; case NUMBER: res = "number"; break; @@ -4321,3 +4346,18 @@ check_symtab_functab(NODE *dest, const char *fname, const char *msg) else if (dest == func_table) fatal(msg, fname, "FUNCTAB"); } + +/* do_bool --- create boolean values */ + +NODE * +do_bool(int nargs) +{ + NODE *tmp; + bool result; + + tmp = POP_SCALAR(); + result = boolval(tmp); + DEREF(tmp); + + return make_bool_node(result); +} diff --git a/doc/ChangeLog b/doc/ChangeLog index 3dd82e08..748f24f4 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2021-03-22 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Constructor Functions): Add doc on `make_bool'. + 2021-03-21 Arnold D. Robbins <arnold@skeeve.com> * gawktexi.in (Other Environment Variables): Document "fnv1a" diff --git a/doc/gawk.info b/doc/gawk.info index 445d06dd..1337e0e2 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -25483,7 +25483,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'. @@ -25496,6 +25497,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 @@ -25511,6 +25513,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. @@ -25821,6 +25824,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 @@ -26546,16 +26554,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 @@ -38532,145 +38541,145 @@ Node: Extension API Description1022630 Node: Extension API Functions Introduction1024343 Ref: table-api-std-headers1026179 Node: General Data Types1030428 -Ref: General Data Types-Footnote-11039058 -Node: Memory Allocation Functions1039357 -Ref: Memory Allocation Functions-Footnote-11043858 -Node: Constructor Functions1043957 -Node: API Ownership of MPFR and GMP Values1047423 -Node: Registration Functions1048736 -Node: Extension Functions1049436 -Node: Exit Callback Functions1054758 -Node: Extension Version String1056008 -Node: Input Parsers1056671 -Node: Output Wrappers1069392 -Node: Two-way processors1073904 -Node: Printing Messages1076169 -Ref: Printing Messages-Footnote-11077340 -Node: Updating ERRNO1077493 -Node: Requesting Values1078232 -Ref: table-value-types-returned1078969 -Node: Accessing Parameters1079905 -Node: Symbol Table Access1081142 -Node: Symbol table by name1081654 -Ref: Symbol table by name-Footnote-11084678 -Node: Symbol table by cookie1084806 -Ref: Symbol table by cookie-Footnote-11088991 -Node: Cached values1089055 -Ref: Cached values-Footnote-11092591 -Node: Array Manipulation1092744 -Ref: Array Manipulation-Footnote-11093835 -Node: Array Data Types1093872 -Ref: Array Data Types-Footnote-11096530 -Node: Array Functions1096622 -Node: Flattening Arrays1101120 -Node: Creating Arrays1108096 -Node: Redirection API1112863 -Node: Extension API Variables1115696 -Node: Extension Versioning1116407 -Ref: gawk-api-version1116836 -Node: Extension GMP/MPFR Versioning1118567 -Node: Extension API Informational Variables1120195 -Node: Extension API Boilerplate1121268 -Node: Changes from API V11125242 -Node: Finding Extensions1126814 -Node: Extension Example1127373 -Node: Internal File Description1128171 -Node: Internal File Ops1132251 -Ref: Internal File Ops-Footnote-11143601 -Node: Using Internal File Ops1143741 -Ref: Using Internal File Ops-Footnote-11146124 -Node: Extension Samples1146398 -Node: Extension Sample File Functions1147927 -Node: Extension Sample Fnmatch1155576 -Node: Extension Sample Fork1157063 -Node: Extension Sample Inplace1158281 -Node: Extension Sample Ord1161907 -Node: Extension Sample Readdir1162743 -Ref: table-readdir-file-types1163632 -Node: Extension Sample Revout1164699 -Node: Extension Sample Rev2way1165288 -Node: Extension Sample Read write array1166028 -Node: Extension Sample Readfile1167970 -Node: Extension Sample Time1169065 -Node: Extension Sample API Tests1170817 -Node: gawkextlib1171309 -Node: Extension summary1174227 -Node: Extension Exercises1177929 -Node: Language History1179171 -Node: V7/SVR3.11180827 -Node: SVR41182979 -Node: POSIX1184413 -Node: BTL1185794 -Node: POSIX/GNU1186523 -Node: Feature History1192301 -Node: Common Extensions1208620 -Node: Ranges and Locales1209903 -Ref: Ranges and Locales-Footnote-11214519 -Ref: Ranges and Locales-Footnote-21214546 -Ref: Ranges and Locales-Footnote-31214781 -Node: Contributors1215004 -Node: History summary1221001 -Node: Installation1222381 -Node: Gawk Distribution1223325 -Node: Getting1223809 -Node: Extracting1224772 -Node: Distribution contents1226410 -Node: Unix Installation1232890 -Node: Quick Installation1233572 -Node: Shell Startup Files1235986 -Node: Additional Configuration Options1237075 -Node: Configuration Philosophy1239390 -Node: Non-Unix Installation1241759 -Node: PC Installation1242219 -Node: PC Binary Installation1243057 -Node: PC Compiling1243492 -Node: PC Using1244609 -Node: Cygwin1248162 -Node: MSYS1249386 -Node: VMS Installation1249988 -Node: VMS Compilation1250779 -Ref: VMS Compilation-Footnote-11252008 -Node: VMS Dynamic Extensions1252066 -Node: VMS Installation Details1253751 -Node: VMS Running1256004 -Node: VMS GNV1260283 -Node: VMS Old Gawk1261018 -Node: Bugs1261489 -Node: Bug address1262152 -Node: Usenet1265134 -Node: Maintainers1266138 -Node: Other Versions1267323 -Node: Installation summary1275188 -Node: Notes1276397 -Node: Compatibility Mode1277191 -Node: Additions1277973 -Node: Accessing The Source1278898 -Node: Adding Code1280335 -Node: New Ports1286554 -Node: Derived Files1290929 -Ref: Derived Files-Footnote-11296589 -Ref: Derived Files-Footnote-21296624 -Ref: Derived Files-Footnote-31297222 -Node: Future Extensions1297336 -Node: Implementation Limitations1297994 -Node: Extension Design1299204 -Node: Old Extension Problems1300348 -Ref: Old Extension Problems-Footnote-11301866 -Node: Extension New Mechanism Goals1301923 -Ref: Extension New Mechanism Goals-Footnote-11305287 -Node: Extension Other Design Decisions1305476 -Node: Extension Future Growth1307589 -Node: Notes summary1308195 -Node: Basic Concepts1309353 -Node: Basic High Level1310034 -Ref: figure-general-flow1310316 -Ref: figure-process-flow1311001 -Ref: Basic High Level-Footnote-11314302 -Node: Basic Data Typing1314487 -Node: Glossary1317815 -Node: Copying1349700 -Node: GNU Free Documentation License1387243 -Node: Index1412363 +Ref: General Data Types-Footnote-11039134 +Node: Memory Allocation Functions1039433 +Ref: Memory Allocation Functions-Footnote-11043934 +Node: Constructor Functions1044033 +Node: API Ownership of MPFR and GMP Values1047686 +Node: Registration Functions1048999 +Node: Extension Functions1049699 +Node: Exit Callback Functions1055021 +Node: Extension Version String1056271 +Node: Input Parsers1056934 +Node: Output Wrappers1069655 +Node: Two-way processors1074167 +Node: Printing Messages1076432 +Ref: Printing Messages-Footnote-11077603 +Node: Updating ERRNO1077756 +Node: Requesting Values1078495 +Ref: table-value-types-returned1079232 +Node: Accessing Parameters1080340 +Node: Symbol Table Access1081577 +Node: Symbol table by name1082089 +Ref: Symbol table by name-Footnote-11085113 +Node: Symbol table by cookie1085241 +Ref: Symbol table by cookie-Footnote-11089426 +Node: Cached values1089490 +Ref: Cached values-Footnote-11093026 +Node: Array Manipulation1093179 +Ref: Array Manipulation-Footnote-11094270 +Node: Array Data Types1094307 +Ref: Array Data Types-Footnote-11096965 +Node: Array Functions1097057 +Node: Flattening Arrays1101555 +Node: Creating Arrays1108531 +Node: Redirection API1113298 +Node: Extension API Variables1116131 +Node: Extension Versioning1116842 +Ref: gawk-api-version1117271 +Node: Extension GMP/MPFR Versioning1119002 +Node: Extension API Informational Variables1120630 +Node: Extension API Boilerplate1121703 +Node: Changes from API V11125677 +Node: Finding Extensions1127249 +Node: Extension Example1127808 +Node: Internal File Description1128606 +Node: Internal File Ops1132686 +Ref: Internal File Ops-Footnote-11144036 +Node: Using Internal File Ops1144176 +Ref: Using Internal File Ops-Footnote-11146559 +Node: Extension Samples1146833 +Node: Extension Sample File Functions1148362 +Node: Extension Sample Fnmatch1156011 +Node: Extension Sample Fork1157498 +Node: Extension Sample Inplace1158716 +Node: Extension Sample Ord1162342 +Node: Extension Sample Readdir1163178 +Ref: table-readdir-file-types1164067 +Node: Extension Sample Revout1165134 +Node: Extension Sample Rev2way1165723 +Node: Extension Sample Read write array1166463 +Node: Extension Sample Readfile1168405 +Node: Extension Sample Time1169500 +Node: Extension Sample API Tests1171252 +Node: gawkextlib1171744 +Node: Extension summary1174662 +Node: Extension Exercises1178364 +Node: Language History1179606 +Node: V7/SVR3.11181262 +Node: SVR41183414 +Node: POSIX1184848 +Node: BTL1186229 +Node: POSIX/GNU1186958 +Node: Feature History1192736 +Node: Common Extensions1209055 +Node: Ranges and Locales1210338 +Ref: Ranges and Locales-Footnote-11214954 +Ref: Ranges and Locales-Footnote-21214981 +Ref: Ranges and Locales-Footnote-31215216 +Node: Contributors1215439 +Node: History summary1221436 +Node: Installation1222816 +Node: Gawk Distribution1223760 +Node: Getting1224244 +Node: Extracting1225207 +Node: Distribution contents1226845 +Node: Unix Installation1233325 +Node: Quick Installation1234007 +Node: Shell Startup Files1236421 +Node: Additional Configuration Options1237510 +Node: Configuration Philosophy1239825 +Node: Non-Unix Installation1242194 +Node: PC Installation1242654 +Node: PC Binary Installation1243492 +Node: PC Compiling1243927 +Node: PC Using1245044 +Node: Cygwin1248597 +Node: MSYS1249821 +Node: VMS Installation1250423 +Node: VMS Compilation1251214 +Ref: VMS Compilation-Footnote-11252443 +Node: VMS Dynamic Extensions1252501 +Node: VMS Installation Details1254186 +Node: VMS Running1256439 +Node: VMS GNV1260718 +Node: VMS Old Gawk1261453 +Node: Bugs1261924 +Node: Bug address1262587 +Node: Usenet1265569 +Node: Maintainers1266573 +Node: Other Versions1267758 +Node: Installation summary1275623 +Node: Notes1276832 +Node: Compatibility Mode1277626 +Node: Additions1278408 +Node: Accessing The Source1279333 +Node: Adding Code1280770 +Node: New Ports1286989 +Node: Derived Files1291364 +Ref: Derived Files-Footnote-11297024 +Ref: Derived Files-Footnote-21297059 +Ref: Derived Files-Footnote-31297657 +Node: Future Extensions1297771 +Node: Implementation Limitations1298429 +Node: Extension Design1299639 +Node: Old Extension Problems1300783 +Ref: Old Extension Problems-Footnote-11302301 +Node: Extension New Mechanism Goals1302358 +Ref: Extension New Mechanism Goals-Footnote-11305722 +Node: Extension Other Design Decisions1305911 +Node: Extension Future Growth1308024 +Node: Notes summary1308630 +Node: Basic Concepts1309788 +Node: Basic High Level1310469 +Ref: figure-general-flow1310751 +Ref: figure-process-flow1311436 +Ref: Basic High Level-Footnote-11314737 +Node: Basic Data Typing1314922 +Node: Glossary1318250 +Node: Copying1350135 +Node: GNU Free Documentation License1387678 +Node: Index1412798 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index b472316b..7e0a7a99 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -35488,7 +35488,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}. @@ -35501,6 +35502,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.'' @@ -35516,6 +35518,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. @@ -35843,6 +35846,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 @@ -36643,7 +36651,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> @@ -36653,6 +36662,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> @@ -36665,6 +36675,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> @@ -36677,6 +36688,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> @@ -36685,6 +36697,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> @@ -36693,6 +36706,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> @@ -36700,11 +36714,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> @@ -36715,6 +36741,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> @@ -36725,6 +36752,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> @@ -36737,6 +36765,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> @@ -36753,43 +36782,46 @@ value type, as appropriate. This behavior is summarized in \vglue-1.1\baselineskip @end tex @c @multitable @columnfractions .166 .166 .198 .15 .15 .166 -@multitable {Requested} {Undefined} {Number} {Number} {Scalar} {Regex} {Array} {Undefined} -@headitem @tab @tab String @tab Strnum @tab Number @tab Regex @tab Array @tab Undefined -@item @tab @b{String} @tab String @tab String @tab String @tab String @tab false @tab false -@item @tab @b{Strnum} @tab false @tab Strnum @tab Strnum @tab false @tab false @tab false -@item @tab @b{Number} @tab Number @tab Number @tab Number @tab false @tab false @tab false -@item @b{Type} @tab @b{Regex} @tab false @tab false @tab false @tab Regex @tab false @tab false -@item @b{Requested} @tab @b{Array} @tab false @tab false @tab false @tab false @tab Array @tab false -@item @tab @b{Scalar} @tab Scalar @tab Scalar @tab Scalar @tab Scalar @tab false @tab false -@item @tab @b{Undefined} @tab String @tab Strnum @tab Number @tab Regex @tab Array @tab Undefined -@item @tab @b{Value cookie} @tab false @tab false @tab false @tab false @tab false @tab false +@multitable {Requested} {Undefined} {Number} {Number} {Scalar} {Regex} {Number} {Array} {Undefined} +@headitem @tab @tab String @tab Strnum @tab Number @tab Regex @tab Bool @tab Array @tab Undefined +@item @tab @b{String} @tab String @tab String @tab String @tab String @tab String @tab false @tab false +@item @tab @b{Strnum} @tab false @tab Strnum @tab Strnum @tab false @tab false @tab false @tab false +@item @tab @b{Number} @tab Number @tab Number @tab Number @tab false @tab Number @tab false @tab false +@item @b{Type} @tab @b{Regex} @tab false @tab false @tab false @tab Regex @tab false @tab false @tab false +@item @b{Requested} @tab @b{Bool} @tab false @tab false @tab false @tab false @tab Bool @tab false @tab false +@item @tab @b{Array} @tab false @tab false @tab false @tab false @tab false @tab Array @tab false +@item @tab @b{Scalar} @tab Scalar @tab Scalar @tab Scalar @tab Scalar @tab Scalar @tab false @tab false +@item @tab @b{Undefined} @tab String @tab Strnum @tab Number @tab Regex @tab Bool @tab Array @tab Undefined +@item @tab @b{Value cookie} @tab false @tab false @tab false @tab false @tab false @tab false @tab false @end multitable @end ifnotdocbook @end ifnotplaintext @ifplaintext @verbatim - +-------------------------------------------------------+ - | Type of Actual Value: | - +--------+--------+--------+--------+-------+-----------+ - | String | Strnum | Number | Regex | Array | Undefined | -+-----------+-----------+--------+--------+--------+--------+-------+-----------+ -| | String | String | String | String | String | false | false | -| +-----------+--------+--------+--------+--------+-------+-----------+ -| | Strnum | false | Strnum | Strnum | false | false | false | -| +-----------+--------+--------+--------+--------+-------+-----------+ -| | Number | Number | Number | Number | false | false | false | -| +-----------+--------+--------+--------+--------+-------+-----------+ -| | Regex | false | false | false | Regex | false | false | -| Type +-----------+--------+--------+--------+--------+-------+-----------+ -| Requested | Array | false | false | false | false | Array | false | -| +-----------+--------+--------+--------+--------+-------+-----------+ -| | Scalar | Scalar | Scalar | Scalar | Scalar | false | false | -| +-----------+--------+--------+--------+--------+-------+-----------+ -| | Undefined | String | Strnum | Number | Regex | Array | Undefined | -| +-----------+--------+--------+--------+--------+-------+-----------+ -| | Value | false | false | false | false | false | false | -| | Cookie | | | | | | | -+-----------+-----------+--------+--------+--------+--------+-------+-----------+ + +----------------------------------------------------------------+ + | Type of Actual Value: | + +--------+--------+--------+--------+--------+-------+-----------+ + | String | Strnum | Number | Regex | Bool | Array | Undefined | ++-----------+-----------+--------+--------+--------+--------+--------+-------+-----------+ +| | String | String | String | String | String | String | false | false | +| +-----------+--------+--------+--------+--------+--------+-------+-----------+ +| | Strnum | false | Strnum | Strnum | false | false | false | false | +| +-----------+--------+--------+--------+--------+--------+-------+-----------+ +| | Number | Number | Number | Number | false | Number | false | false | +| +-----------+--------+--------+--------+--------+--------+-------+-----------+ +| | Regex | false | false | false | Regex | false | false | false | +| +-----------+--------+--------+--------+--------+--------+-------+-----------+ +| Type | Bool | false | false | false | false | Bool | false | false | +| Requested +-----------+--------+--------+--------+--------+--------+-------+-----------+ +| | Array | false | false | false | false | false | Array | false | +| +-----------+--------+--------+--------+--------+--------+-------+-----------+ +| | Scalar | Scalar | Scalar | Scalar | Scalar | Scalar | false | false | +| +-----------+--------+--------+--------+--------+--------+-------+-----------+ +| | Undefined | String | Strnum | Number | Regex | Bool | Array | Undefined | +| +-----------+--------+--------+--------+--------+--------+-------+-----------+ +| | Value | false | false | false | false | false | false | false | +| | Cookie | | | | | | | | ++-----------+-----------+--------+--------+--------+--------+--------+-------+-----------+ @end verbatim @end ifplaintext @end float diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 2c2d7297..228ea0d7 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -34385,7 +34385,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}. @@ -34398,6 +34399,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.'' @@ -34413,6 +34415,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. @@ -34740,6 +34743,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 @@ -35540,7 +35548,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> @@ -35550,6 +35559,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> @@ -35562,6 +35572,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> @@ -35574,6 +35585,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> @@ -35582,6 +35594,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> @@ -35590,6 +35603,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> @@ -35597,11 +35611,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> @@ -35612,6 +35638,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> @@ -35622,6 +35649,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> @@ -35634,6 +35662,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> @@ -35650,43 +35679,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 @@ -455,6 +455,7 @@ flags2str(int flagval) { XARRAY, "XARRAY" }, { NUMCONSTSTR, "NUMCONSTSTR" }, { REGEX, "REGEX" }, + { BOOL, "BOOL" }, { 0, NULL }, }; diff --git a/extension/ChangeLog b/extension/ChangeLog index fef32337..cf580649 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -2,6 +2,10 @@ * 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/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; @@ -1019,6 +1019,7 @@ do_split(int nargs) assoc_clear(arr); src = TOP_STRING(); + warn_bool("split", 1, src); if (src->stlen == 0) { /* * Skip the work if first arg is the null string. @@ -1096,6 +1097,7 @@ do_patsplit(int nargs) _("%s: cannot use %s as second argument")); src = TOP_STRING(); + warn_bool("patsplit", 1, src); if ((sep->flags & REGEX) != 0) sep = sep->typed_re; @@ -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: @@ -567,9 +570,20 @@ 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) { + val->val_type = AWK_BOOL; + val->bool_value = (get_number_si(node) ? awk_true : awk_false); + 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 if ((node->flags & BOOL) != 0) + val->val_type = AWK_BOOL; else { (void) force_number(node); assign_number(node, val); @@ -578,7 +592,10 @@ node_to_awk_value(NODE *node, awk_value_t *val, awk_valtype_t wanted) break; case AWK_STRNUM: - switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) { + switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX|BOOL)) { + case BOOL: + val->val_type = AWK_BOOL; + break; case STRING: val->val_type = AWK_STRING; break; @@ -612,10 +629,13 @@ node_to_awk_value(NODE *node, awk_value_t *val, awk_valtype_t wanted) break; case AWK_REGEX: - switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) { + switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX|BOOL)) { case STRING: val->val_type = AWK_STRING; break; + case BOOL: + val->val_type = AWK_BOOL; + break; case NUMBER: val->val_type = AWK_NUMBER; break; @@ -640,7 +660,10 @@ node_to_awk_value(NODE *node, awk_value_t *val, awk_valtype_t wanted) break; case AWK_SCALAR: - switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) { + switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX|BOOL)) { + case BOOL: + val->val_type = AWK_BOOL; + break; case STRING: val->val_type = AWK_STRING; break; @@ -668,7 +691,12 @@ node_to_awk_value(NODE *node, awk_value_t *val, awk_valtype_t wanted) case AWK_UNDEFINED: /* return true and actual type for request of undefined */ - switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX)) { + switch (fixtype(node)->flags & (STRING|NUMBER|USER_INPUT|REGEX|BOOL)) { + case BOOL: + val->val_type = AWK_BOOL; + val->bool_value = (get_number_si(node) ? awk_true : awk_false); + ret = awk_true; + break; case STRING: assign_string(node, val, AWK_STRING); ret = awk_true; @@ -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,25 @@ more_blocks(int id) } #endif + +/* make_bool_node --- make a boolean-valued node */ + +extern NODE * +make_bool_node(bool value) +{ + NODE *val; + const char *sval; + AWKNUM nval; + + sval = (value ? "TRUE" : "FALSE"); + nval = (value ? 1.0 : 0.0); + + val = make_number(nval); + val->stptr = estrdup(sval, strlen(sval)); + val->stlen = strlen(sval); + val->flags &= ~NUMBER; + val->flags |= NUMCUR|STRCUR|BOOL; + val->stfmt = STFMT_UNUSED; + + return val; +} diff --git a/test/ChangeLog b/test/ChangeLog index 53fe5627..2604c270 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +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/dumpvars.ok b/test/dumpvars.ok index 85d1c859..7caecd35 100644 --- a/test/dumpvars.ok +++ b/test/dumpvars.ok @@ -9,7 +9,7 @@ FILENAME: "-" FNR: 3 FPAT: "[^[:space:]]+" FS: " " -FUNCTAB: array, 41 elements +FUNCTAB: array, 42 elements IGNORECASE: 0 LINT: 0 NF: 1 diff --git a/test/functab5.ok b/test/functab5.ok index 9ac4295d..ef110989 100644 --- a/test/functab5.ok +++ b/test/functab5.ok @@ -3,6 +3,7 @@ asort' asorti' atan2' bindtextdomain' +bool' chdir' close' compl' @@ -34,6 +34,7 @@ asort -> builtin asorti -> builtin atan2 -> builtin bindtextdomain -> builtin +bool -> builtin close -> builtin compl -> builtin cos -> builtin diff --git a/test/intest.awk b/test/intest.awk index f030d07a..18e0cc4d 100644 --- a/test/intest.awk +++ b/test/intest.awk @@ -1,4 +1,4 @@ BEGIN { - bool = ((b = 1) in c); - print bool, b # gawk-3.0.1 prints "0 "; should print "0 1" + bool_result = ((b = 1) in c); + print bool_result, b # gawk-3.0.1 prints "0 "; should print "0 1" } diff --git a/test/symtab11.ok b/test/symtab11.ok index 7d4be46c..da2cfcba 100644 --- a/test/symtab11.ok +++ b/test/symtab11.ok @@ -37,6 +37,7 @@ BEGIN -- Functab is next [asorti] = asorti [atan2] = atan2 [bindtextdomain] = bindtextdomain +[bool] = bool [close] = close [compl] = compl [cos] = cos diff --git a/test/symtab8.ok b/test/symtab8.ok index da29b585..0cf40fe9 100644 --- a/test/symtab8.ok +++ b/test/symtab8.ok @@ -9,7 +9,7 @@ FIELDWIDTHS: "" FNR: 1 FPAT: "[^[:space:]]+" FS: " " -FUNCTAB: array, 41 elements +FUNCTAB: array, 42 elements IGNORECASE: 0 LINT: 0 NF: 1 |