diff options
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | NEWS | 11 | ||||
-rw-r--r-- | awk.h | 9 | ||||
-rw-r--r-- | awklib/eg/test-programs/gen-float-table.awk | 59 | ||||
-rw-r--r-- | awklib/eg/test-programs/gen-float-table.c | 60 | ||||
-rw-r--r-- | awklib/eg/test-programs/gen-float-table.py | 42 | ||||
-rw-r--r-- | builtin.c | 2 | ||||
-rw-r--r-- | doc/ChangeLog | 39 | ||||
-rw-r--r-- | doc/gawk.info | 1288 | ||||
-rw-r--r-- | doc/gawk.texi | 276 | ||||
-rw-r--r-- | doc/gawktexi.in | 276 | ||||
-rw-r--r-- | doc/it/ChangeLog | 37 | ||||
-rwxr-xr-x[-rw-r--r--] | doc/it/gawktexi.in | 734 | ||||
-rwxr-xr-x | doc/it/gendocs.sh | 510 | ||||
-rwxr-xr-x | doc/it/gendocs_template | 101 | ||||
-rwxr-xr-x | doc/it/genera_formati.sh | 13 | ||||
-rwxr-xr-x[-rw-r--r--] | doc/it/texinfo.tex | 191 | ||||
-rw-r--r-- | doc/wordlist | 1 | ||||
-rw-r--r-- | eval.c | 96 | ||||
-rw-r--r-- | interpret.h | 12 | ||||
-rw-r--r-- | mpfr.c | 44 | ||||
-rw-r--r-- | node.c | 3 | ||||
-rw-r--r-- | str_array.c | 38 |
23 files changed, 2901 insertions, 960 deletions
@@ -19,6 +19,12 @@ * interpret.h (r_interpret): Remove LINT_no_effect from Op_lint case. +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-02-13 Arnold D. Robbins <arnold@skeeve.com> * io.c (nextfile): Use the value of ARGC directly in the for @@ -141,6 +147,19 @@ 2020-11-02 Arnold D. Robbins <arnold@skeeve.com> + Make gawk numeric comparisons act like C doubles. + MPFR differs from doubles w.r.t. NaN, not sure why yet. + + * awk.h (scalar_cmp_t): New enum. + * builtin.c (format_nan_inf): Use mpfr_signbit, not mpfr_sgn. + * eval.c (cmp_doubles): New routine. + (cmp_scalars): Change type to bool, rework logic. + * interpret.h (r_interpret): Rework scalar comparisons. + * mpfr.c (mpg_cmp_as_numbers): New routine. + * node.c: Use <math.h>, not "math.h", minor comment edits. + +2020-11-02 Arnold D. Robbins <arnold@skeeve.com> + * re.c (make_regexp): Cast len parameter to int to avoid compiler warnings. @@ -4,6 +4,17 @@ are permitted in any medium without royalty provided the copyright notice and this notice are preserved. +Changes from 5.1.x to 5.2.0 +--------------------------- + +1. Numeric scalars now compare in the same way as C for the relational +operators. Comparison order for sorting has not changed. This only +makes a difference when comparing Infinity and NaN values with +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. + Changes from 5.1.0 to 5.1.1 --------------------------- @@ -1576,6 +1576,15 @@ typedef enum { extern field_sep_type current_field_sep(void); extern const char *current_field_sep_str(void); +typedef enum { + SCALAR_EQ, + SCALAR_NEQ, + SCALAR_LT, + SCALAR_LE, + SCALAR_GT, + SCALAR_GE, +} scalar_cmp_t; + /* gawkapi.c: */ extern gawk_api_t api_impl; extern void init_ext_api(void); diff --git a/awklib/eg/test-programs/gen-float-table.awk b/awklib/eg/test-programs/gen-float-table.awk new file mode 100644 index 00000000..ea6269c3 --- /dev/null +++ b/awklib/eg/test-programs/gen-float-table.awk @@ -0,0 +1,59 @@ +function eq(left, right) +{ + return left == right +} + +function ne(left, right) +{ + return left != right +} + +function lt(left, right) +{ + return left < right +} + +function le(left, right) +{ + return left <= right +} + +function gt(left, right) +{ + return left > right +} + +function ge(left, right) +{ + return left >= right +} + +BEGIN { + nan = sqrt(-1) + inf = -log(0) + split("== != < <= > >=", names) + names[3] = names[3] " " + names[5] = names[5] " " + split("eq ne lt le gt ge", funcs) + + compare[1] = 2.0 + compare[2] = values[1] = -sqrt(-1.0) # nan + compare[3] = values[2] = sqrt(-1.0) # -nan + compare[4] = values[3] = -log(0.0) # inf + compare[5] = values[4] = log(0.0) # -inf + + for (i = 1; i in values; i++) { + for (j = 1; j in compare; j++) { + for (k = 1; k in names; k++) { + the_func = funcs[k] + printf("%g %s %g -> %s\n", + values[i], + names[k], + compare[j], + @the_func(values[i], compare[j]) ? + "True" : "False"); + } + printf("\n"); + } + } +} diff --git a/awklib/eg/test-programs/gen-float-table.c b/awklib/eg/test-programs/gen-float-table.c new file mode 100644 index 00000000..ba3a0d05 --- /dev/null +++ b/awklib/eg/test-programs/gen-float-table.c @@ -0,0 +1,60 @@ +#include <stdio.h> +#include <math.h> +#include <stdbool.h> + +#define def_func(name, op) \ + bool name(double left, double right) { \ + return left op right; \ + } + +def_func(eq, ==) +def_func(ne, !=) +def_func(lt, <) +def_func(le, <=) +def_func(gt, >) +def_func(ge, >=) + +struct { + const char *name; + bool (*func)(double left, double right); +} functions[] = { + { "==", eq }, + { "!=", ne }, + { "< ", lt }, + { "<=", le }, + { "> ", gt }, + { ">=", ge }, + { 0, 0 } +}; + +int main() +{ + double values[] = { + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + }; + double compare[] = { 2.0, + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + }; + + int i, j, k; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 5; j++) { + for (k = 0; functions[k].name != NULL; k++) { + printf("%g %s %g -> %s\n", values[i], + functions[k].name, + compare[j], + functions[k].func(values[i], compare[j]) ? "True" : "False"); + } + printf("\n"); + } + } + + return 0; +} diff --git a/awklib/eg/test-programs/gen-float-table.py b/awklib/eg/test-programs/gen-float-table.py new file mode 100644 index 00000000..8631b817 --- /dev/null +++ b/awklib/eg/test-programs/gen-float-table.py @@ -0,0 +1,42 @@ +from math import * + +nan = float('NaN') +inf = float('Inf') + +def eq(left, right): + return left == right + +def ne(left, right): + return left != right + +def lt(left, right): + return left < right + +def le(left, right): + return left <= right + +def gt(left, right): + return left > right + +def ge(left, right): + return left >= right + +func_map = { + "==": eq, + "!=": ne, + "< ": lt, + "<=": le, + "> ": gt, + ">=": ge, +} + +compare = [2.0, nan, -nan, inf, -inf] +values = [nan, -nan, inf, -inf] + +for i in range(len(values)): + for j in range(len(compare)): + for op in func_map: + print("%g %s %g -> %s" % + (values[i], op, compare[j], func_map[op](values[i], compare[j]))) + + print("") @@ -4277,7 +4277,7 @@ format_nan_inf(NODE *n, char format) goto fmt; } else if (mpfr_inf_p(n->mpg_numbr)) { - strcpy(buf, mpfr_sgn(n->mpg_numbr) < 0 ? "-inf" : "+inf"); + strcpy(buf, mpfr_signbit(n->mpg_numbr) ? "-inf" : "+inf"); goto fmt; } else diff --git a/doc/ChangeLog b/doc/ChangeLog index a4a4b275..8e311ec8 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -9,10 +9,22 @@ <arkadiusz@drabczyk.org> for pointing out the lack of documentation. +2021-03-21 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Other Environment Variables): Document "fnv1a" + possible value for AWK_HASH environment variable. + 2021-03-18 Arnold D. Robbins <arnold@skeeve.com> * texinfo.tex: Updated from GNULIB. +2021-02-01 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Strange values): Fix a typo in the awk test + program. Make the C and Awk versions print "True" and + "False" to match Python, making comparisons easier. Thanks to + Antonio Columbo for the suggestions. + 2021-01-25 Arnold D. Robbins <arnold@skeeve.com> * gawktexi.in: Fix some spelling errors. @@ -83,12 +95,39 @@ * gawkworkflow.texi: Add an additional web resource. * gawktexi.in: More edits in sample programs chapter. +2020-11-20 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Strange values): Correct the description of what + happens with infinity. Thanks to Antonio Columbo for pointing + out the problem. + 2020-11-16 Arnold D. Robbins <arnold@skeeve.com> * gawktexi.in (Nextfile Statement): Clarify what happens in a BEGINFILE rule. * gawktexi.in: Additional small fixes. +2020-11-15 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Strange values): Add test programs inside + @ignore; extracted to example directory. + +2020-11-09 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in: Samll improvement in strange numbers section. + +2020-11-04 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Strange values): New section on NaN and infinity. + Update some other bits to point to it. + * wordlist: Updated with more words. + +2020-11-16 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Nextfile Statement): Clarify what happens in + a BEGINFILE rule. +>>>>>>> master + 2020-10-31 Arnold D. Robbins <arnold@skeeve.com> * texinfo.tex: Updated from GNULIB. diff --git a/doc/gawk.info b/doc/gawk.info index 87f7901c..f5f417a6 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -551,6 +551,7 @@ in (a) below. A copy of the license is included in the section entitled * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. * Getting Accuracy:: Getting more accuracy takes some work. * Try To Round:: Add digits and round. * Setting precision:: How to set the precision. @@ -3219,7 +3220,9 @@ change. The variables are: 'AWK_HASH' If this variable exists with a value of 'gst', 'gawk' switches to using the hash function from GNU Smalltalk for managing arrays. - This function may be marginally faster than the standard function. + With a value of 'fnv1a', 'gawk' uses the FNV1-A hash function + (http://www.isthe.com/chongo/tech/comp/fnv/index.html). These + functions may be marginally faster than the standard function. 'AWKREADFUNC' If this variable exists, 'gawk' switches to reading source files @@ -6970,8 +6973,8 @@ width. Here is a list of the format-control letters: On systems supporting IEEE 754 floating-point format, values representing negative infinity are formatted as '-inf' or '-infinity', and positive infinity as 'inf' or 'infinity'. The - special "not a number" value formats as '-nan' or 'nan' (*note Math - Definitions::). + special "not a number" value formats as '-nan' or 'nan' (*note + Strange values::). '%F' Like '%f', but the infinity and "not a number" values are spelled @@ -12863,7 +12866,7 @@ brackets ([ ]): 'log(X)' Return the natural logarithm of X, if X is positive; otherwise, - return 'NaN' ("not a number") on IEEE 754 systems. Additionally, + return NaN ("not a number") on IEEE 754 systems. Additionally, 'gawk' prints a warning message when 'x' is negative. 'rand()' @@ -24246,18 +24249,10 @@ material here: another number and infinity produce infinity. "NaN" - "Not a number."(1) A special value that results from attempting a - calculation that has no answer as a real number. In such a case, - programs can either receive a floating-point exception, or get - 'NaN' back as the result. The IEEE 754 standard recommends that - systems return 'NaN'. Some examples: - - 'sqrt(-1)' - This makes sense in the range of complex numbers, but not in - the range of real numbers, so the result is 'NaN'. - - 'log(-8)' - -8 is out of the domain of 'log()', so the result is 'NaN'. + "Not a number." A special value that results from attempting a + calculation that has no answer as a real number. *Note Strange + values::, for more information about infinity and not-a-number + values. "Normalized" How the significand (see later in this list) is usually stored. @@ -24316,11 +24311,6 @@ Table 16.3: Basic IEEE format values NOTE: The precision numbers include the implied leading one that gives them one extra bit of significand. - ---------- Footnotes ---------- - - (1) Thanks to Michael Brennan for this description, which we have -paraphrased, and for the examples. - File: gawk.info, Node: MPFR features, Next: FP Math Caution, Prev: Math Definitions, Up: Arbitrary Precision Arithmetic @@ -24413,6 +24403,7 @@ be sure of the number of significant decimal places in the final result. * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. File: gawk.info, Node: Inexact representation, Next: Comparing FP Values, Up: Inexactness of computations @@ -24477,7 +24468,7 @@ values with a delta, you should be sure to use 'difference < abs(delta)' in case someone passes in a negative delta value. -File: gawk.info, Node: Errors accumulate, Prev: Comparing FP Values, Up: Inexactness of computations +File: gawk.info, Node: Errors accumulate, Next: Strange values, Prev: Comparing FP Values, Up: Inexactness of computations 16.4.1.3 Errors Accumulate .......................... @@ -24525,6 +24516,64 @@ representations yield an unexpected result: -| 4 +File: gawk.info, Node: Strange values, Prev: Errors accumulate, Up: Inexactness of computations + +16.4.1.4 Floating Point Values They Didn't Talk About In School +............................................................... + +Both IEEE 754 floating-point hardware, and MPFR, support two kinds of +values that you probably didn't learn about in school. The first is +"infinity", a special value, that can be either negative or positive, +and which is either smaller than any other value (negative infinity), or +larger than any other value (positive infinity). When such values are +generated, 'gawk' prints them as either '-inf' or '+inf', respectively. +It accepts those strings as data input and converts them to the proper +floating-point values internally. + + Infinity values of the same sign compare as equal to each other. +Otherwise, operations (addition, subtraction, etc.) involving another +number and infinity produce mathematically reasonable results. + + The second kind of value is "not a number", or NaN for short.(1) +This is a special value that results from attempting a calculation that +has no answer as a real number. In such a case, programs can either +receive a floating-point exception, or get NaN back as the result. The +IEEE 754 standard recommends that systems return NaN. Some examples: + +'sqrt(-1)' + This makes sense in the range of complex numbers, but not in the + range of real numbers, so the result is NaN. + +'log(-8)' + -8 is out of the domain of 'log()', so the result is NaN. + + NaN values are strange. In particular, they cannot be compared with +other floating point values; any such comparison, except for "is not +equal to", returns false. NaN values are so much unequal to other +values that even comparing two identical NaN values with '!=' returns +true! + + NaN values can also be signed, although it depends upon the +implementation as to which sign you get for any operation that returns a +NaN. For example, on some systems, 'sqrt(-1)' returns a negative NaN. On +others, it returns a positive NaN. + + When such values are generated, 'gawk' prints them as either '-nan' +or '+nan', respectively. Here too, 'gawk' accepts those strings as data +input and converts them to the proper floating-point values internally. + + If you want to dive more deeply into this topic, you can find test +programs in C, 'awk' and Python in the directory +'awklib/eg/test-programs' in the 'gawk' distribution. These programs +enable comparison among programming languages as to how they handle NaN +and infinity values. + + ---------- Footnotes ---------- + + (1) Thanks to Michael Brennan for this description, which we have +paraphrased, and for the examples. + + File: gawk.info, Node: Getting Accuracy, Next: Try To Round, Prev: Inexactness of computations, Up: FP Math Caution 16.4.2 Getting the Accuracy You Need @@ -38067,603 +38116,604 @@ Index Tag Table: Node: Top1200 -Node: Foreword344780 -Node: Foreword449222 -Node: Preface50754 -Ref: Preface-Footnote-153613 -Ref: Preface-Footnote-253722 -Ref: Preface-Footnote-353956 -Node: History54098 -Node: Names56450 -Ref: Names-Footnote-157554 -Node: This Manual57701 -Ref: This Manual-Footnote-164340 -Node: Conventions64440 -Node: Manual History66809 -Ref: Manual History-Footnote-169806 -Ref: Manual History-Footnote-269847 -Node: How To Contribute69921 -Node: Acknowledgments70847 -Node: Getting Started75784 -Node: Running gawk78223 -Node: One-shot79413 -Node: Read Terminal80676 -Node: Long82669 -Node: Executable Scripts84182 -Ref: Executable Scripts-Footnote-186815 -Node: Comments86918 -Node: Quoting89402 -Node: DOS Quoting94928 -Node: Sample Data Files96984 -Node: Very Simple99579 -Node: Two Rules105681 -Node: More Complex107566 -Node: Statements/Lines109898 -Ref: Statements/Lines-Footnote-1114382 -Node: Other Features114647 -Node: When115583 -Ref: When-Footnote-1117337 -Node: Intro Summary117402 -Node: Invoking Gawk118286 -Node: Command Line119800 -Node: Options120598 -Ref: Options-Footnote-1138512 -Ref: Options-Footnote-2138743 -Node: Other Arguments138768 -Node: Naming Standard Input142779 -Node: Environment Variables143989 -Node: AWKPATH Variable144547 -Ref: AWKPATH Variable-Footnote-1147959 -Ref: AWKPATH Variable-Footnote-2147993 -Node: AWKLIBPATH Variable148364 -Ref: AWKLIBPATH Variable-Footnote-1150061 -Node: Other Environment Variables150436 -Node: Exit Status154257 -Node: Include Files154934 -Node: Loading Shared Libraries158624 -Node: Obsolete160052 -Node: Undocumented160744 -Node: Invoking Summary161041 -Node: Regexp163882 -Node: Regexp Usage165336 -Node: Escape Sequences167373 -Node: Regexp Operators173614 -Node: Regexp Operator Details174099 -Ref: Regexp Operator Details-Footnote-1181463 -Node: Interval Expressions181610 -Ref: Interval Expressions-Footnote-1183031 -Node: Bracket Expressions183129 -Ref: table-char-classes185605 -Node: Leftmost Longest188931 -Node: Computed Regexps190234 -Node: GNU Regexp Operators193661 -Node: Case-sensitivity197398 -Ref: Case-sensitivity-Footnote-1200264 -Ref: Case-sensitivity-Footnote-2200499 -Node: Regexp Summary200607 -Node: Reading Files202073 -Node: Records204342 -Node: awk split records205417 -Node: gawk split records210117 -Ref: gawk split records-Footnote-1215191 -Node: Fields215228 -Node: Nonconstant Fields217969 -Ref: Nonconstant Fields-Footnote-1220205 -Node: Changing Fields220409 -Node: Field Separators226440 -Node: Default Field Splitting229138 -Node: Regexp Field Splitting230256 -Node: Single Character Fields233933 -Node: Command Line Field Separator234993 -Node: Full Line Fields238211 -Ref: Full Line Fields-Footnote-1239733 -Ref: Full Line Fields-Footnote-2239779 -Node: Field Splitting Summary239880 -Node: Constant Size241954 -Node: Fixed width data242686 -Node: Skipping intervening246153 -Node: Allowing trailing data246951 -Node: Fields with fixed data247988 -Node: Splitting By Content249506 -Ref: Splitting By Content-Footnote-1253289 -Node: More CSV253452 -Node: Testing field creation255044 -Node: Multiple Line256669 -Node: Getline262946 -Node: Plain Getline265415 -Node: Getline/Variable267988 -Node: Getline/File269139 -Node: Getline/Variable/File270527 -Ref: Getline/Variable/File-Footnote-1272132 -Node: Getline/Pipe272220 -Node: Getline/Variable/Pipe274924 -Node: Getline/Coprocess276059 -Node: Getline/Variable/Coprocess277326 -Node: Getline Notes278068 -Node: Getline Summary280865 -Ref: table-getline-variants281289 -Node: Read Timeout282037 -Ref: Read Timeout-Footnote-1285943 -Node: Retrying Input286001 -Node: Command-line directories287200 -Node: Input Summary288106 -Node: Input Exercises291278 -Node: Printing291712 -Node: Print293546 -Node: Print Examples295003 -Node: Output Separators297783 -Node: OFMT299800 -Node: Printf301156 -Node: Basic Printf301941 -Node: Control Letters303515 -Node: Format Modifiers308679 -Node: Printf Examples314694 -Node: Redirection317180 -Node: Special FD324021 -Ref: Special FD-Footnote-1327189 -Node: Special Files327263 -Node: Other Inherited Files327880 -Node: Special Network328881 -Node: Special Caveats329741 -Node: Close Files And Pipes330690 -Ref: table-close-pipe-return-values337597 -Ref: Close Files And Pipes-Footnote-1338410 -Ref: Close Files And Pipes-Footnote-2338558 -Node: Nonfatal338710 -Node: Output Summary341048 -Node: Output Exercises342270 -Node: Expressions342949 -Node: Values344137 -Node: Constants344815 -Node: Scalar Constants345506 -Ref: Scalar Constants-Footnote-1348016 -Node: Nondecimal-numbers348266 -Node: Regexp Constants351267 -Node: Using Constant Regexps351793 -Node: Standard Regexp Constants352415 -Node: Strong Regexp Constants355603 -Node: Variables358615 -Node: Using Variables359272 -Node: Assignment Options361182 -Node: Conversion363653 -Node: Strings And Numbers364177 -Ref: Strings And Numbers-Footnote-1367240 -Node: Locale influences conversions367349 -Ref: table-locale-affects370107 -Node: All Operators370725 -Node: Arithmetic Ops371354 -Node: Concatenation374070 -Ref: Concatenation-Footnote-1376917 -Node: Assignment Ops377024 -Ref: table-assign-ops382015 -Node: Increment Ops383328 -Node: Truth Values and Conditions386788 -Node: Truth Values387862 -Node: Typing and Comparison388910 -Node: Variable Typing389730 -Ref: Variable Typing-Footnote-1396193 -Ref: Variable Typing-Footnote-2396265 -Node: Comparison Operators396342 -Ref: table-relational-ops396761 -Node: POSIX String Comparison400256 -Ref: POSIX String Comparison-Footnote-1401951 -Ref: POSIX String Comparison-Footnote-2402090 -Node: Boolean Ops402174 -Ref: Boolean Ops-Footnote-1406656 -Node: Conditional Exp406748 -Node: Function Calls408484 -Node: Precedence412361 -Node: Locales416020 -Node: Expressions Summary417652 -Node: Patterns and Actions420225 -Node: Pattern Overview421345 -Node: Regexp Patterns423022 -Node: Expression Patterns423564 -Node: Ranges427345 -Node: BEGIN/END430453 -Node: Using BEGIN/END431214 -Ref: Using BEGIN/END-Footnote-1433968 -Node: I/O And BEGIN/END434074 -Node: BEGINFILE/ENDFILE436387 -Node: Empty439618 -Node: Using Shell Variables439935 -Node: Action Overview442209 -Node: Statements444534 -Node: If Statement446382 -Node: While Statement447877 -Node: Do Statement449905 -Node: For Statement451053 -Node: Switch Statement454224 -Node: Break Statement456665 -Node: Continue Statement458757 -Node: Next Statement460584 -Node: Nextfile Statement462967 -Node: Exit Statement465656 -Node: Built-in Variables468059 -Node: User-modified469192 -Node: Auto-set476959 -Ref: Auto-set-Footnote-1493766 -Ref: Auto-set-Footnote-2493972 -Node: ARGC and ARGV494028 -Node: Pattern Action Summary498241 -Node: Arrays500671 -Node: Array Basics502000 -Node: Array Intro502844 -Ref: figure-array-elements504819 -Ref: Array Intro-Footnote-1507523 -Node: Reference to Elements507651 -Node: Assigning Elements510115 -Node: Array Example510606 -Node: Scanning an Array512365 -Node: Controlling Scanning515387 -Ref: Controlling Scanning-Footnote-1521843 -Node: Numeric Array Subscripts522159 -Node: Uninitialized Subscripts524343 -Node: Delete525962 -Ref: Delete-Footnote-1528714 -Node: Multidimensional528771 -Node: Multiscanning531866 -Node: Arrays of Arrays533457 -Node: Arrays Summary538225 -Node: Functions540318 -Node: Built-in541356 -Node: Calling Built-in542437 -Node: Numeric Functions544433 -Ref: Numeric Functions-Footnote-1548461 -Ref: Numeric Functions-Footnote-2549109 -Ref: Numeric Functions-Footnote-3549157 -Node: String Functions549429 -Ref: String Functions-Footnote-1573570 -Ref: String Functions-Footnote-2573698 -Ref: String Functions-Footnote-3573946 -Node: Gory Details574033 -Ref: table-sub-escapes575824 -Ref: table-sub-proposed577343 -Ref: table-posix-sub578706 -Ref: table-gensub-escapes580247 -Ref: Gory Details-Footnote-1581070 -Node: I/O Functions581224 -Ref: table-system-return-values587678 -Ref: I/O Functions-Footnote-1589758 -Ref: I/O Functions-Footnote-2589906 -Node: Time Functions590026 -Ref: Time Functions-Footnote-1600697 -Ref: Time Functions-Footnote-2600765 -Ref: Time Functions-Footnote-3600923 -Ref: Time Functions-Footnote-4601034 -Ref: Time Functions-Footnote-5601146 -Ref: Time Functions-Footnote-6601373 -Node: Bitwise Functions601639 -Ref: table-bitwise-ops602233 -Ref: Bitwise Functions-Footnote-1608296 -Ref: Bitwise Functions-Footnote-2608469 -Node: Type Functions608660 -Node: I18N Functions611523 -Node: User-defined613174 -Node: Definition Syntax613986 -Ref: Definition Syntax-Footnote-1619680 -Node: Function Example619751 -Ref: Function Example-Footnote-1622673 -Node: Function Calling622695 -Node: Calling A Function623283 -Node: Variable Scope624241 -Node: Pass By Value/Reference627235 -Node: Function Caveats629879 -Ref: Function Caveats-Footnote-1631926 -Node: Return Statement632046 -Node: Dynamic Typing635025 -Node: Indirect Calls635955 -Ref: Indirect Calls-Footnote-1646207 -Node: Functions Summary646335 -Node: Library Functions649040 -Ref: Library Functions-Footnote-1652647 -Ref: Library Functions-Footnote-2652790 -Node: Library Names652961 -Ref: Library Names-Footnote-1656628 -Ref: Library Names-Footnote-2656851 -Node: General Functions656937 -Node: Strtonum Function658040 -Node: Assert Function661062 -Node: Round Function664388 -Node: Cliff Random Function665928 -Node: Ordinal Functions666944 -Ref: Ordinal Functions-Footnote-1670007 -Ref: Ordinal Functions-Footnote-2670259 -Node: Join Function670469 -Ref: Join Function-Footnote-1672239 -Node: Getlocaltime Function672439 -Node: Readfile Function676181 -Node: Shell Quoting678158 -Node: Data File Management679559 -Node: Filetrans Function680191 -Node: Rewind Function684287 -Node: File Checking686196 -Ref: File Checking-Footnote-1687530 -Node: Empty Files687731 -Node: Ignoring Assigns689710 -Node: Getopt Function691260 -Ref: Getopt Function-Footnote-1706471 -Node: Passwd Functions706671 -Ref: Passwd Functions-Footnote-1715510 -Node: Group Functions715598 -Ref: Group Functions-Footnote-1723496 -Node: Walking Arrays723703 -Node: Library Functions Summary726711 -Node: Library Exercises728117 -Node: Sample Programs728582 -Node: Running Examples729352 -Node: Clones730080 -Node: Cut Program731304 -Node: Egrep Program741444 -Node: Id Program750445 -Node: Split Program760392 -Ref: Split Program-Footnote-1770282 -Node: Tee Program770455 -Node: Uniq Program773245 -Node: Wc Program780833 -Node: Bytes vs. Characters781220 -Node: Using extensions782768 -Node: wc program783522 -Node: Miscellaneous Programs788387 -Node: Dupword Program789600 -Node: Alarm Program791630 -Node: Translate Program796485 -Ref: Translate Program-Footnote-1801050 -Node: Labels Program801320 -Ref: Labels Program-Footnote-1804671 -Node: Word Sorting804755 -Node: History Sorting808827 -Node: Extract Program811052 -Node: Simple Sed819106 -Node: Igawk Program822180 -Ref: Igawk Program-Footnote-1836511 -Ref: Igawk Program-Footnote-2836713 -Ref: Igawk Program-Footnote-3836835 -Node: Anagram Program836950 -Node: Signature Program840012 -Node: Programs Summary841259 -Node: Programs Exercises842473 -Ref: Programs Exercises-Footnote-1846603 -Node: Advanced Features846689 -Node: Nondecimal Data848756 -Node: Array Sorting850347 -Node: Controlling Array Traversal851047 -Ref: Controlling Array Traversal-Footnote-1859415 -Node: Array Sorting Functions859533 -Ref: Array Sorting Functions-Footnote-1864624 -Node: Two-way I/O864820 -Ref: Two-way I/O-Footnote-1872541 -Ref: Two-way I/O-Footnote-2872728 -Node: TCP/IP Networking872810 -Node: Profiling875928 -Node: Extension Philosophy885237 -Node: Advanced Features Summary886716 -Node: Internationalization888731 -Node: I18N and L10N890211 -Node: Explaining gettext890898 -Ref: Explaining gettext-Footnote-1896790 -Ref: Explaining gettext-Footnote-2896975 -Node: Programmer i18n897140 -Ref: Programmer i18n-Footnote-1902089 -Node: Translator i18n902138 -Node: String Extraction902932 -Ref: String Extraction-Footnote-1904064 -Node: Printf Ordering904150 -Ref: Printf Ordering-Footnote-1906936 -Node: I18N Portability907000 -Ref: I18N Portability-Footnote-1909456 -Node: I18N Example909519 -Ref: I18N Example-Footnote-1912794 -Ref: I18N Example-Footnote-2912867 -Node: Gawk I18N912976 -Node: I18N Summary913625 -Node: Debugger914966 -Node: Debugging915966 -Node: Debugging Concepts916407 -Node: Debugging Terms918216 -Node: Awk Debugging920791 -Ref: Awk Debugging-Footnote-1921736 -Node: Sample Debugging Session921868 -Node: Debugger Invocation922402 -Node: Finding The Bug923788 -Node: List of Debugger Commands930262 -Node: Breakpoint Control931595 -Node: Debugger Execution Control935289 -Node: Viewing And Changing Data938651 -Node: Execution Stack942192 -Node: Debugger Info943829 -Node: Miscellaneous Debugger Commands947900 -Node: Readline Support952962 -Node: Limitations953858 -Node: Debugging Summary956412 -Node: Namespaces957691 -Node: Global Namespace958802 -Node: Qualified Names960200 -Node: Default Namespace961199 -Node: Changing The Namespace961940 -Node: Naming Rules963554 -Node: Internal Name Management965402 -Node: Namespace Example966444 -Node: Namespace And Features969006 -Node: Namespace Summary970441 -Node: Arbitrary Precision Arithmetic971918 -Node: Computer Arithmetic973405 -Ref: table-numeric-ranges977171 -Ref: table-floating-point-ranges977664 -Ref: Computer Arithmetic-Footnote-1978322 -Node: Math Definitions978379 -Ref: table-ieee-formats981695 -Ref: Math Definitions-Footnote-1982298 -Node: MPFR features982403 -Node: FP Math Caution984121 -Ref: FP Math Caution-Footnote-1985193 -Node: Inexactness of computations985562 -Node: Inexact representation986522 -Node: Comparing FP Values987882 -Node: Errors accumulate989123 -Node: Getting Accuracy990556 -Node: Try To Round993266 -Node: Setting precision994165 -Ref: table-predefined-precision-strings994862 -Node: Setting the rounding mode996692 -Ref: table-gawk-rounding-modes997066 -Ref: Setting the rounding mode-Footnote-11000997 -Node: Arbitrary Precision Integers1001176 -Ref: Arbitrary Precision Integers-Footnote-11004351 -Node: Checking for MPFR1004500 -Node: POSIX Floating Point Problems1005974 -Ref: POSIX Floating Point Problems-Footnote-11010259 -Node: Floating point summary1010297 -Node: Dynamic Extensions1012487 -Node: Extension Intro1014040 -Node: Plugin License1015306 -Node: Extension Mechanism Outline1016103 -Ref: figure-load-extension1016542 -Ref: figure-register-new-function1018107 -Ref: figure-call-new-function1019199 -Node: Extension API Description1021261 -Node: Extension API Functions Introduction1022974 -Ref: table-api-std-headers1024810 -Node: General Data Types1029059 -Ref: General Data Types-Footnote-11037689 -Node: Memory Allocation Functions1037988 -Ref: Memory Allocation Functions-Footnote-11042489 -Node: Constructor Functions1042588 -Node: API Ownership of MPFR and GMP Values1046054 -Node: Registration Functions1047367 -Node: Extension Functions1048067 -Node: Exit Callback Functions1053389 -Node: Extension Version String1054639 -Node: Input Parsers1055302 -Node: Output Wrappers1068023 -Node: Two-way processors1072535 -Node: Printing Messages1074800 -Ref: Printing Messages-Footnote-11075971 -Node: Updating ERRNO1076124 -Node: Requesting Values1076863 -Ref: table-value-types-returned1077600 -Node: Accessing Parameters1078536 -Node: Symbol Table Access1079773 -Node: Symbol table by name1080285 -Ref: Symbol table by name-Footnote-11083309 -Node: Symbol table by cookie1083437 -Ref: Symbol table by cookie-Footnote-11087622 -Node: Cached values1087686 -Ref: Cached values-Footnote-11091222 -Node: Array Manipulation1091375 -Ref: Array Manipulation-Footnote-11092466 -Node: Array Data Types1092503 -Ref: Array Data Types-Footnote-11095161 -Node: Array Functions1095253 -Node: Flattening Arrays1099751 -Node: Creating Arrays1106727 -Node: Redirection API1111494 -Node: Extension API Variables1114327 -Node: Extension Versioning1115038 -Ref: gawk-api-version1115467 -Node: Extension GMP/MPFR Versioning1117198 -Node: Extension API Informational Variables1118826 -Node: Extension API Boilerplate1119899 -Node: Changes from API V11123873 -Node: Finding Extensions1125445 -Node: Extension Example1126004 -Node: Internal File Description1126802 -Node: Internal File Ops1130882 -Ref: Internal File Ops-Footnote-11142232 -Node: Using Internal File Ops1142372 -Ref: Using Internal File Ops-Footnote-11144755 -Node: Extension Samples1145029 -Node: Extension Sample File Functions1146558 -Node: Extension Sample Fnmatch1154207 -Node: Extension Sample Fork1155694 -Node: Extension Sample Inplace1156912 -Node: Extension Sample Ord1160538 -Node: Extension Sample Readdir1161374 -Ref: table-readdir-file-types1162263 -Node: Extension Sample Revout1163330 -Node: Extension Sample Rev2way1163919 -Node: Extension Sample Read write array1164659 -Node: Extension Sample Readfile1166601 -Node: Extension Sample Time1167696 -Node: Extension Sample API Tests1169448 -Node: gawkextlib1169940 -Node: Extension summary1172858 -Node: Extension Exercises1176560 -Node: Language History1177802 -Node: V7/SVR3.11179458 -Node: SVR41181610 -Node: POSIX1183044 -Node: BTL1184425 -Node: POSIX/GNU1185154 -Node: Feature History1190932 -Node: Common Extensions1207251 -Node: Ranges and Locales1208534 -Ref: Ranges and Locales-Footnote-11213150 -Ref: Ranges and Locales-Footnote-21213177 -Ref: Ranges and Locales-Footnote-31213412 -Node: Contributors1213635 -Node: History summary1219632 -Node: Installation1221012 -Node: Gawk Distribution1221956 -Node: Getting1222440 -Node: Extracting1223403 -Node: Distribution contents1225041 -Node: Unix Installation1231521 -Node: Quick Installation1232203 -Node: Shell Startup Files1234617 -Node: Additional Configuration Options1235706 -Node: Configuration Philosophy1238021 -Node: Non-Unix Installation1240390 -Node: PC Installation1240850 -Node: PC Binary Installation1241688 -Node: PC Compiling1242123 -Node: PC Using1243240 -Node: Cygwin1246793 -Node: MSYS1248017 -Node: VMS Installation1248619 -Node: VMS Compilation1249410 -Ref: VMS Compilation-Footnote-11250639 -Node: VMS Dynamic Extensions1250697 -Node: VMS Installation Details1252382 -Node: VMS Running1254635 -Node: VMS GNV1258914 -Node: VMS Old Gawk1259649 -Node: Bugs1260120 -Node: Bug address1260783 -Node: Usenet1263765 -Node: Maintainers1264769 -Node: Other Versions1265954 -Node: Installation summary1273819 -Node: Notes1275028 -Node: Compatibility Mode1275822 -Node: Additions1276604 -Node: Accessing The Source1277529 -Node: Adding Code1278966 -Node: New Ports1285185 -Node: Derived Files1289560 -Ref: Derived Files-Footnote-11295220 -Ref: Derived Files-Footnote-21295255 -Ref: Derived Files-Footnote-31295853 -Node: Future Extensions1295967 -Node: Implementation Limitations1296625 -Node: Extension Design1297835 -Node: Old Extension Problems1298979 -Ref: Old Extension Problems-Footnote-11300497 -Node: Extension New Mechanism Goals1300554 -Ref: Extension New Mechanism Goals-Footnote-11303918 -Node: Extension Other Design Decisions1304107 -Node: Extension Future Growth1306220 -Node: Notes summary1306826 -Node: Basic Concepts1307984 -Node: Basic High Level1308665 -Ref: figure-general-flow1308947 -Ref: figure-process-flow1309632 -Ref: Basic High Level-Footnote-11312933 -Node: Basic Data Typing1313118 -Node: Glossary1316446 -Node: Copying1348331 -Node: GNU Free Documentation License1385874 -Node: Index1410994 +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 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index 7b6cc71e..e87a1e84 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -924,6 +924,7 @@ particular records in a file and perform operations upon them. * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. * Getting Accuracy:: Getting more accuracy takes some work. * Try To Round:: Add digits and round. * Setting precision:: How to set the precision. @@ -3140,11 +3141,12 @@ column means that the person is a friend. An @samp{R} means that the person is a relative: @example -@c system if test ! -d eg ; then mkdir eg ; fi -@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi -@c system if test ! -d eg/data ; then mkdir eg/data ; fi -@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi -@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg ; then mkdir eg ; fi +@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi +@c system if test ! -d eg/data ; then mkdir eg/data ; fi +@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi +@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg/test-programs ; then mkdir eg/test-programs ; fi @c file eg/data/mail-list Amelia 555-5553 amelia.zodiacusque@@gmail.com F Anthony 555-3412 anthony.asserturo@@hotmail.com A @@ -4844,7 +4846,10 @@ blocksize, which is usually the filesystem's I/O blocksize.) If this variable exists with a value of @samp{gst}, @command{gawk} switches to using the hash function from GNU Smalltalk for managing arrays. -This function may be marginally faster than the standard function. +With a value of @samp{fnv1a}, @command{gawk} uses the +@uref{http://www.isthe.com/chongo/tech/comp/fnv/index.html, +FNV1-A hash function}. +These functions may be marginally faster than the standard function. @item AWKREADFUNC If this variable exists, @command{gawk} switches to reading source @@ -10199,7 +10204,7 @@ infinity are formatted as and positive infinity as @samp{inf} or @samp{infinity}. The special ``not a number'' value formats as @samp{-nan} or @samp{nan} -(@pxref{Math Definitions}). +(@pxref{Strange values}). @item @code{%F} Like @samp{%f}, but the infinity and ``not a number'' values are spelled @@ -18435,7 +18440,7 @@ compatibility mode (@pxref{Options}). @cindexawkfunc{log} @cindex logarithm Return the natural logarithm of @var{x}, if @var{x} is positive; -otherwise, return @code{NaN} (``not a number'') on IEEE 754 systems. +otherwise, return NaN (``not a number'') on IEEE 754 systems. Additionally, @command{gawk} prints a warning message when @code{x} is negative. @@ -33781,21 +33786,9 @@ A special value representing infinity. Operations involving another number and infinity produce infinity. @item NaN -``Not a number.''@footnote{Thanks to Michael Brennan for this description, -which we have paraphrased, and for the examples.} A special value that -results from attempting a calculation that has no answer as a real number. -In such a case, programs can either receive a floating-point exception, -or get @code{NaN} back as the result. The IEEE 754 standard recommends -that systems return @code{NaN}. Some examples: - -@table @code -@item sqrt(-1) -This makes sense in the range of complex numbers, but not in the -range of real numbers, so the result is @code{NaN}. - -@item log(-8) -@minus{}8 is out of the domain of @code{log()}, so the result is @code{NaN}. -@end table +``Not a number.'' A special value that results from attempting a +calculation that has no answer as a real number. @xref{Strange values}, +for more information about infinity and not-a-number values. @item Normalized How the significand (see later in this list) is usually stored. The @@ -33964,6 +33957,7 @@ decimal places in the final result. * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. @end menu @node Inexact representation @@ -34085,6 +34079,242 @@ $ @kbd{gawk 'BEGIN @{} @print{} 4 @end example +@node Strange values +@subsubsection Floating Point Values They Didn't Talk About In School + +Both IEEE 754 floating-point hardware, and MPFR, support two kinds of +values that you probably didn't learn about in school. The first is +@dfn{infinity}, a special value, that can be either negative or positive, +and which is either smaller than any other value (negative infinity), +or larger than any other value (positive infinity). When such values +are generated, @command{gawk} prints them as either @samp{-inf} or +@samp{+inf}, respectively. It accepts those strings as data input and +converts them to the proper floating-point values internally. + +Infinity values of the same sign compare as equal to each other. +Otherwise, operations (addition, subtraction, etc.) involving another +number and infinity produce mathematically reasonable results. + +The second kind of value is ``not a number'', or NaN for +short.@footnote{Thanks to Michael Brennan for this description, which we +have paraphrased, and for the examples.} This is a special value that results +from attempting a calculation that has no answer as a real number. +In such a case, programs can either receive a floating-point exception, +or get NaN back as the result. The IEEE 754 standard recommends +that systems return NaN. Some examples: + +@table @code +@item sqrt(-1) +@iftex +The @math{\sqrt{-1}} +@end iftex +@ifnottex +This +@end ifnottex +makes sense in the range of complex numbers, but not in the +range of real numbers, so the result is NaN. + +@item log(-8) +@minus{}8 is out of the domain of @code{log()}, so the result is NaN. +@end table + +NaN values are strange. In particular, they cannot be compared with other +floating point values; any such comparison, except for ``is not equal +to'', returns false. NaN values are so much unequal to other values that +even comparing two identical NaN values with @code{!=} returns true! + +NaN values can also be signed, although it depends upon the implementation +as to which sign you get for any operation that returns a NaN. For +example, on some systems, @code{sqrt(-1)} returns a negative NaN. On +others, it returns a positive NaN. + +When such values are generated, @command{gawk} prints them as either +@samp{-nan} or @samp{+nan}, respectively. Here too, @command{gawk} +accepts those strings as data input and converts them to the proper +floating-point values internally. + +If you want to dive more deeply into this topic, you can find +test programs in C, @command{awk} and Python in the directory +@file{awklib/eg/test-programs} in the @command{gawk} distribution. +These programs enable comparison among programming languages as to how +they handle NaN and infinity values. + +@ignore +@c file eg/test-programs/gen-float-table.awk +function eq(left, right) +@{ + return left == right +@} + +function ne(left, right) +@{ + return left != right +@} + +function lt(left, right) +@{ + return left < right +@} + +function le(left, right) +@{ + return left <= right +@} + +function gt(left, right) +@{ + return left > right +@} + +function ge(left, right) +@{ + return left >= right +@} + +BEGIN @{ + nan = sqrt(-1) + inf = -log(0) + split("== != < <= > >=", names) + names[3] = names[3] " " + names[5] = names[5] " " + split("eq ne lt le gt ge", funcs) + + compare[1] = 2.0 + compare[2] = values[1] = -sqrt(-1.0) # nan + compare[3] = values[2] = sqrt(-1.0) # -nan + compare[4] = values[3] = -log(0.0) # inf + compare[5] = values[4] = log(0.0) # -inf + + for (i = 1; i in values; i++) @{ + for (j = 1; j in compare; j++) @{ + for (k = 1; k in names; k++) @{ + the_func = funcs[k] + printf("%g %s %g -> %s\n", + values[i], + names[k], + compare[j], + @@the_func(values[i], compare[j]) ? + "True" : "False"); + @} + printf("\n"); + @} + @} +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.c +#include <stdio.h> +#include <math.h> +#include <stdbool.h> + +#define def_func(name, op) \ + bool name(double left, double right) @{ \ + return left op right; \ + @} + +def_func(eq, ==) +def_func(ne, !=) +def_func(lt, <) +def_func(le, <=) +def_func(gt, >) +def_func(ge, >=) + +struct @{ + const char *name; + bool (*func)(double left, double right); +@} functions[] = @{ + @{ "==", eq @}, + @{ "!=", ne @}, + @{ "< ", lt @}, + @{ "<=", le @}, + @{ "> ", gt @}, + @{ ">=", ge @}, + @{ 0, 0 @} +@}; + +int main() +@{ + double values[] = @{ + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + double compare[] = @{ 2.0, + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + + int i, j, k; + + for (i = 0; i < 4; i++) @{ + for (j = 0; j < 5; j++) @{ + for (k = 0; functions[k].name != NULL; k++) @{ + printf("%g %s %g -> %s\n", values[i], + functions[k].name, + compare[j], + functions[k].func(values[i], compare[j]) ? "True" : "False"); + @} + printf("\n"); + @} + @} + + return 0; +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.py +from math import * + +nan = float('NaN') +inf = float('Inf') + +def eq(left, right): + return left == right + +def ne(left, right): + return left != right + +def lt(left, right): + return left < right + +def le(left, right): + return left <= right + +def gt(left, right): + return left > right + +def ge(left, right): + return left >= right + +func_map = { + "==": eq, + "!=": ne, + "< ": lt, + "<=": le, + "> ": gt, + ">=": ge, +} + +compare = [2.0, nan, -nan, inf, -inf] +values = [nan, -nan, inf, -inf] + +for i in range(len(values)): + for j in range(len(compare)): + for op in func_map: + print("%g %s %g -> %s" % + (values[i], op, compare[j], func_map[op](values[i], compare[j]))) + + print("") +@c endfile +@end ignore + @node Getting Accuracy @subsection Getting the Accuracy You Need diff --git a/doc/gawktexi.in b/doc/gawktexi.in index adc90c51..95606cf3 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -919,6 +919,7 @@ particular records in a file and perform operations upon them. * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. * Getting Accuracy:: Getting more accuracy takes some work. * Try To Round:: Add digits and round. * Setting precision:: How to set the precision. @@ -3050,11 +3051,12 @@ column means that the person is a friend. An @samp{R} means that the person is a relative: @example -@c system if test ! -d eg ; then mkdir eg ; fi -@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi -@c system if test ! -d eg/data ; then mkdir eg/data ; fi -@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi -@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg ; then mkdir eg ; fi +@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi +@c system if test ! -d eg/data ; then mkdir eg/data ; fi +@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi +@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg/test-programs ; then mkdir eg/test-programs ; fi @c file eg/data/mail-list Amelia 555-5553 amelia.zodiacusque@@gmail.com F Anthony 555-3412 anthony.asserturo@@hotmail.com A @@ -4710,7 +4712,10 @@ blocksize, which is usually the filesystem's I/O blocksize.) If this variable exists with a value of @samp{gst}, @command{gawk} switches to using the hash function from GNU Smalltalk for managing arrays. -This function may be marginally faster than the standard function. +With a value of @samp{fnv1a}, @command{gawk} uses the +@uref{http://www.isthe.com/chongo/tech/comp/fnv/index.html, +FNV1-A hash function}. +These functions may be marginally faster than the standard function. @item AWKREADFUNC If this variable exists, @command{gawk} switches to reading source @@ -9668,7 +9673,7 @@ infinity are formatted as and positive infinity as @samp{inf} or @samp{infinity}. The special ``not a number'' value formats as @samp{-nan} or @samp{nan} -(@pxref{Math Definitions}). +(@pxref{Strange values}). @item @code{%F} Like @samp{%f}, but the infinity and ``not a number'' values are spelled @@ -17576,7 +17581,7 @@ compatibility mode (@pxref{Options}). @cindexawkfunc{log} @cindex logarithm Return the natural logarithm of @var{x}, if @var{x} is positive; -otherwise, return @code{NaN} (``not a number'') on IEEE 754 systems. +otherwise, return NaN (``not a number'') on IEEE 754 systems. Additionally, @command{gawk} prints a warning message when @code{x} is negative. @@ -32663,21 +32668,9 @@ A special value representing infinity. Operations involving another number and infinity produce infinity. @item NaN -``Not a number.''@footnote{Thanks to Michael Brennan for this description, -which we have paraphrased, and for the examples.} A special value that -results from attempting a calculation that has no answer as a real number. -In such a case, programs can either receive a floating-point exception, -or get @code{NaN} back as the result. The IEEE 754 standard recommends -that systems return @code{NaN}. Some examples: - -@table @code -@item sqrt(-1) -This makes sense in the range of complex numbers, but not in the -range of real numbers, so the result is @code{NaN}. - -@item log(-8) -@minus{}8 is out of the domain of @code{log()}, so the result is @code{NaN}. -@end table +``Not a number.'' A special value that results from attempting a +calculation that has no answer as a real number. @xref{Strange values}, +for more information about infinity and not-a-number values. @item Normalized How the significand (see later in this list) is usually stored. The @@ -32846,6 +32839,7 @@ decimal places in the final result. * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. @end menu @node Inexact representation @@ -32967,6 +32961,242 @@ $ @kbd{gawk 'BEGIN @{} @print{} 4 @end example +@node Strange values +@subsubsection Floating Point Values They Didn't Talk About In School + +Both IEEE 754 floating-point hardware, and MPFR, support two kinds of +values that you probably didn't learn about in school. The first is +@dfn{infinity}, a special value, that can be either negative or positive, +and which is either smaller than any other value (negative infinity), +or larger than any other value (positive infinity). When such values +are generated, @command{gawk} prints them as either @samp{-inf} or +@samp{+inf}, respectively. It accepts those strings as data input and +converts them to the proper floating-point values internally. + +Infinity values of the same sign compare as equal to each other. +Otherwise, operations (addition, subtraction, etc.) involving another +number and infinity produce mathematically reasonable results. + +The second kind of value is ``not a number'', or NaN for +short.@footnote{Thanks to Michael Brennan for this description, which we +have paraphrased, and for the examples.} This is a special value that results +from attempting a calculation that has no answer as a real number. +In such a case, programs can either receive a floating-point exception, +or get NaN back as the result. The IEEE 754 standard recommends +that systems return NaN. Some examples: + +@table @code +@item sqrt(-1) +@iftex +The @math{\sqrt{-1}} +@end iftex +@ifnottex +This +@end ifnottex +makes sense in the range of complex numbers, but not in the +range of real numbers, so the result is NaN. + +@item log(-8) +@minus{}8 is out of the domain of @code{log()}, so the result is NaN. +@end table + +NaN values are strange. In particular, they cannot be compared with other +floating point values; any such comparison, except for ``is not equal +to'', returns false. NaN values are so much unequal to other values that +even comparing two identical NaN values with @code{!=} returns true! + +NaN values can also be signed, although it depends upon the implementation +as to which sign you get for any operation that returns a NaN. For +example, on some systems, @code{sqrt(-1)} returns a negative NaN. On +others, it returns a positive NaN. + +When such values are generated, @command{gawk} prints them as either +@samp{-nan} or @samp{+nan}, respectively. Here too, @command{gawk} +accepts those strings as data input and converts them to the proper +floating-point values internally. + +If you want to dive more deeply into this topic, you can find +test programs in C, @command{awk} and Python in the directory +@file{awklib/eg/test-programs} in the @command{gawk} distribution. +These programs enable comparison among programming languages as to how +they handle NaN and infinity values. + +@ignore +@c file eg/test-programs/gen-float-table.awk +function eq(left, right) +@{ + return left == right +@} + +function ne(left, right) +@{ + return left != right +@} + +function lt(left, right) +@{ + return left < right +@} + +function le(left, right) +@{ + return left <= right +@} + +function gt(left, right) +@{ + return left > right +@} + +function ge(left, right) +@{ + return left >= right +@} + +BEGIN @{ + nan = sqrt(-1) + inf = -log(0) + split("== != < <= > >=", names) + names[3] = names[3] " " + names[5] = names[5] " " + split("eq ne lt le gt ge", funcs) + + compare[1] = 2.0 + compare[2] = values[1] = -sqrt(-1.0) # nan + compare[3] = values[2] = sqrt(-1.0) # -nan + compare[4] = values[3] = -log(0.0) # inf + compare[5] = values[4] = log(0.0) # -inf + + for (i = 1; i in values; i++) @{ + for (j = 1; j in compare; j++) @{ + for (k = 1; k in names; k++) @{ + the_func = funcs[k] + printf("%g %s %g -> %s\n", + values[i], + names[k], + compare[j], + @@the_func(values[i], compare[j]) ? + "True" : "False"); + @} + printf("\n"); + @} + @} +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.c +#include <stdio.h> +#include <math.h> +#include <stdbool.h> + +#define def_func(name, op) \ + bool name(double left, double right) @{ \ + return left op right; \ + @} + +def_func(eq, ==) +def_func(ne, !=) +def_func(lt, <) +def_func(le, <=) +def_func(gt, >) +def_func(ge, >=) + +struct @{ + const char *name; + bool (*func)(double left, double right); +@} functions[] = @{ + @{ "==", eq @}, + @{ "!=", ne @}, + @{ "< ", lt @}, + @{ "<=", le @}, + @{ "> ", gt @}, + @{ ">=", ge @}, + @{ 0, 0 @} +@}; + +int main() +@{ + double values[] = @{ + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + double compare[] = @{ 2.0, + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + + int i, j, k; + + for (i = 0; i < 4; i++) @{ + for (j = 0; j < 5; j++) @{ + for (k = 0; functions[k].name != NULL; k++) @{ + printf("%g %s %g -> %s\n", values[i], + functions[k].name, + compare[j], + functions[k].func(values[i], compare[j]) ? "True" : "False"); + @} + printf("\n"); + @} + @} + + return 0; +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.py +from math import * + +nan = float('NaN') +inf = float('Inf') + +def eq(left, right): + return left == right + +def ne(left, right): + return left != right + +def lt(left, right): + return left < right + +def le(left, right): + return left <= right + +def gt(left, right): + return left > right + +def ge(left, right): + return left >= right + +func_map = { + "==": eq, + "!=": ne, + "< ": lt, + "<=": le, + "> ": gt, + ">=": ge, +} + +compare = [2.0, nan, -nan, inf, -inf] +values = [nan, -nan, inf, -inf] + +for i in range(len(values)): + for j in range(len(compare)): + for op in func_map: + print("%g %s %g -> %s" % + (values[i], op, compare[j], func_map[op](values[i], compare[j]))) + + print("") +@c endfile +@end ignore + @node Getting Accuracy @subsection Getting the Accuracy You Need diff --git a/doc/it/ChangeLog b/doc/it/ChangeLog index 863eef47..df98dfbd 100644 --- a/doc/it/ChangeLog +++ b/doc/it/ChangeLog @@ -1,3 +1,40 @@ +2021-04-06 Antonio Giovanni Colombo <azc100@gmail.com> + + * gawktexi.in: Updated. + +2021-04-01 Antonio Giovanni Colombo <azc100@gmail.com> + Marco Curreli <marcocurreli@tiscali.it> + + * gawktexi.in: Updated. + * gendocs.sh: Added. + * gendocs_template: Added. + * genera_formati.sh: Added. + +2021-03-21 Antonio Giovanni Colombo <azc100@gmail.com> + + * gawktexi.in: Updated. + +2021-03-20 Antonio Giovanni Colombo <azc100@gmail.com> + + * texinfo.tex: Updated. + +2021-02-01 Antonio Giovanni Colombo <azc100@gmail.com> + + * gawktexi.in: Updated. + +2021-01-25 Antonio Giovanni Colombo <azc100@gmail.com> + + * gawktexi.in: Updated. + * texinfo.tex: Updated. + +2021-01-22 Antonio Giovanni Colombo <azc100@gmail.com> + + * gawktexi.in: Updated. + +2020-11-20 Antonio Giovanni Colombo <azc100@gmail.com> + + * gawktexi.in: Updated. + 2020-11-01 Antonio Giovanni Colombo <azc100@gmail.com> * texinfo.tex: Updated. diff --git a/doc/it/gawktexi.in b/doc/it/gawktexi.in index fe7c6b29..0edb44e9 100644..100755 --- a/doc/it/gawktexi.in +++ b/doc/it/gawktexi.in @@ -56,7 +56,7 @@ @c applies to and all the info about who's publishing this edition @c These apply across the board. -@set UPDATE-MONTH Settembre 2020 +@set UPDATE-MONTH Gennaio 2021 @set VERSION 5.1 @set PATCHLEVEL 0 @@ -76,6 +76,7 @@ @iftex @set DOCUMENT libro @set CHAPTER capitolo +@set CHAPTERS capitoli @set APPENDIX appendice @set SECTION sezione @set SECTIONS sezioni @@ -93,6 +94,7 @@ @ifinfo @set DOCUMENT File Info @set CHAPTER nodo principale +@set CHAPTERS nodi principali @set APPENDIX nodo principale @set SECTION nodo secondario @set SECTIONS nodi secondari @@ -105,6 +107,7 @@ @ifhtml @set DOCUMENT Documento @set CHAPTER capitolo +@set CHAPTERS capitoli @set APPENDIX appendice @set SECTION sezione @set SECTIONS sezioni @@ -117,6 +120,7 @@ @ifdocbook @set DOCUMENT libro @set CHAPTER capitolo +@set CHAPTERS capitoli @set APPENDIX appendice @set SECTION sezione @set SECTIONS sezioni @@ -129,6 +133,7 @@ @ifxml @set DOCUMENT libro @set CHAPTER capitolo +@set CHAPTERS capitoli @set APPENDIX appendice @set SECTION sezione @set SECTIONS sezioni @@ -141,6 +146,7 @@ @ifplaintext @set DOCUMENT libro @set CHAPTER capitolo +@set CHAPTERS capitoli @set APPENDIX appendice @set SECTION sezione @set SECTIONS sezioni @@ -309,7 +315,7 @@ Some comments on the layout for TeX. Tel.: +1-617-542-5942 Fax: +1-617-542-2652 Email: <email>gnu@@gnu.org</email> URL: <ulink url="https://www.gnu.org">https://www.gnu.org/</ulink></literallayout> -<literallayout class="normal">Copyright © 1989, 1991, 1992, 1993, 1996–2005, 2007, 2009–2020 +<literallayout class="normal">Copyright © 1989, 1991, 1992, 1993, 1996–2005, 2007, 2009–2021 Free Software Foundation, Inc. All Rights Reserved. </literallayout> @@ -331,7 +337,7 @@ Italian Linux Documentation Project (ILDP) Email: <emailildp@@pluto.it URL: <ulink url="http://www.pluto.it/ildp">http://www.pluto.it/ildp/</ulink></literallayout> -<literallayout class="normal">Copyright © 2016–2020 +<literallayout class="normal">Copyright © 2016–2021 Free Software Foundation, Inc. All Rights Reserved. </literallayout> @@ -339,7 +345,7 @@ All Rights Reserved. @ifnotdocbook @iftex -Copyright @copyright{} 1989, 1991, 1992, 1993, 1996--2005, 2007, 2009--2020 @* +Copyright @copyright{} 1989, 1991, 1992, 1993, 1996--2005, 2007, 2009--2021 @* Free Software Foundation, Inc. @end iftex @end ifnotdocbook @@ -687,7 +693,7 @@ Copyright dell'edizione italiana @copyright{} 2016 -- Free Software Foundation, * Separazione in base al contenuto:: Definire campi dal loro contenuto. * File CSV:: Ancora sui file CSV. * Controllare la creazione di campi:: Controllare come @command{gawk} sta - dividendo i record. + suddividendo i record. * Righe multiple:: Record su righe multiple * Getline:: Richiedere input usando @code{getline}. * Getline semplice:: Usare @code{getline} senza argomenti. @@ -968,6 +974,9 @@ Copyright dell'edizione italiana @copyright{} 2016 -- Free Software Foundation, * Programma tee:: Il programma di utilit@`a @command{tee}. * Programma uniq:: Il programma di utilit@`a @command{uniq}. * Programma wc:: Il programma di utilit@`a @command{wc}. +* Byte vs. Caratteri:: Moderni insiemi di caratteri. +* Usare le estensioni:: Una breve introduzione alle estensioni. +* Programmma @command{wc}:: Codice per @file{wc.awk}. * Programmi vari:: Alcuni interessanti programmi in @command{awk} * Programma dupword:: Trovare parole duplicate in un @@ -1005,6 +1014,7 @@ Copyright dell'edizione italiana @copyright{} 2016 -- Free Software Foundation, programmazione di rete. * Profilare:: Profilare i propri programmi @command{awk}. +* Filosofia delle estensioni:: Cosa dovrebbe essere incluso e cosa no. * Sommario funzionalit@`a avanzate:: Sommario funzionalit@`a avanzate. * I18N e L10N:: Internazionalizzazione e localiz. * Utilizzare @command{gettext}:: Come funziona GNU @code{gettext}. @@ -1033,7 +1043,7 @@ Copyright dell'edizione italiana @copyright{} 2016 -- Free Software Foundation, * Controllo dei breakpoint:: Controllo dei punti d'interruzione. * Controllo esecuzione debugger:: Controllo di esecuzione. * Vedere e modificare dati:: Vedere e modificare dati. -* Stack di esecuzione:: Lavorare con lo @dfn{stack}. +* Stack di esecuzione:: Lavorare con lo @dfn{Stack}. * Informazioni sul debugger:: Ottenere informazioni sullo stato del programma e del debugger. * Comandi vari del debugger:: Comandi vari del debugger. @@ -1065,13 +1075,14 @@ Copyright dell'edizione italiana @copyright{} 2016 -- Free Software Foundation, esattamente. * Confronti tra valori in VM:: Come confrontare valori in virgola mobile. * Gli errori si sommano:: Gli errori diventano sempre maggiori. +* Valori strani:: Un cenno riguardo ai valori infiniti e a NaN [``non @`e un numero'']. * Ottenere la precisione:: Ottenere la precisione voluta. * Tentare di arrotondare:: Tentare di aggiungere bit di precisione e arrotondare. * Impostare la precisione:: Impostare la precisione. * Impostare modo di arrotondare:: Impostare la modalit@`a di arrotondamento. -* Controllare disponibilit@`a MPFR:: Come controllare se MPFR @`e disponibile. +* Controllare disponibilit@`a MPFR:: Come controllare se MPFR @`e disponibile. * Interi a precisione arbitraria:: Aritmetica dei numeri interi a precisione arbitraria con @command{gawk}. * Problemi virgola mobile POSIX:: Confronto tra standard e uso corrente. @@ -1084,8 +1095,8 @@ Copyright dell'edizione italiana @copyright{} 2016 -- Free Software Foundation, * Intro funzioni estensione API:: Introduzione alle funzioni dell'API. * Tipi di dati generali:: I tipi di dati. * Funzioni di allocazione memoria:: Funzioni per allocare memoria. -* API e gestione valori MPFR e GMP:: Gestione valori MPFR e GMP. * Funzioni di costruzione:: Funzioni per creare valori. +* API e gestione valori MPFR e GMP:: Gestione valori MPFR e GMP. * Funzioni di registrazione:: Funzioni per registrare cose con @command{gawk}. * Funzioni di estensione:: Registrare funzioni di estensione. @@ -3259,7 +3270,7 @@ Le ``shell'' nei sistemi Microsoft Windows usano il carattere doppio apice per protezione, e rendono difficile o impossibile inserire un carattere doppio apice letterale in uno @dfn{script} scritto su una riga di comando. L'esempio che segue, per il quale ringraziamo Jeroen Brink, mostra come -proteggere i doppi apici, con questo script di una sola riga, che stampa +proteggere i doppi apici, con questo @dfn{script} di una sola riga, che stampa tutte le righe di un file, racchiudendole tra doppi apici: @example @@ -3338,11 +3349,12 @@ persona @`e un amico [Friend]. Una @samp{R} vuol dire che quella persona @`e un parente [Relative]: @example -@c system if test ! -d eg ; then mkdir eg ; fi -@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi -@c system if test ! -d eg/data ; then mkdir eg/data ; fi -@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi -@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg ; then mkdir eg ; fi +@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi +@c system if test ! -d eg/data ; then mkdir eg/data ; fi +@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi +@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg/test-programs ; then mkdir eg/test-programs ; fi @c file eg/data/mail-list Amelia 555-5553 amelia.zodiacusque@@gmail.com F Anthony 555-3412 anthony.asserturo@@hotmail.com A @@ -3689,7 +3701,7 @@ anno). Come gi@`a visto sopra, l'output di @w{@samp{ls -l}} elenca la lista dei file contenuti in una directory, compresa la lunghezza di ogni -file la data in cui il file @`e stato modificato per l'ultima volta. +file e la data in cui il file @`e stato modificato per l'ultima volta. Il primo campo contiene le autorizzazioni di lettura-scrittura, il secondo campo contiene il numero di @dfn{link} di quel file e il terzo campo identifica il proprietario del file. @@ -3698,7 +3710,7 @@ Il quinto campo contiene la dimensione del file, in byte. Il sesto, settimo e ottavo campo contengono il mese, il giorno e l'ora, rispettivamente, in cui il file @`e stato modificato l'ultima volta. -Finalmente il nono campo contiene il valore @value{FN}. +Infine, il nono campo contiene il valore @value{FN}. @c @cindex automatic initialization @cindex inizializzazione @subentry automatica @@ -3937,7 +3949,7 @@ e buttati via. Poich@'e i programmi @command{awk} sono interpretati, si pu@`o evitare la (normalmente laboriosa) parte di compilazione nel ciclo tipico dello sviluppo software, ossia edita-compila-prova-correggi. -@cindex BWK @command{awk} @seeentry{Brian Kernighan @subentry @command{awk} di} +@cindex BWK @command{awk} @seeentry{Brian Kernighan, @command{awk} di} @cindex Brian Kernighan @subentry @command{awk} di In @command{awk} sono stati scritti programmi complessi, compreso un assembler completo, pluri-piattaforma per @@ -4429,7 +4441,7 @@ informazioni. @cindex codice-byte interno @subentry tracciatura del Stampa i nomi del codice-byte generato internamente, nell'ordine in cui sono incontrati durante l'esecuzione del programma. -Questa trace @`e stampata sullo standard error. +Questa tracciatura @`e stampata sullo standard error. Ogni ``codice operativo'' @`e preceduto da un segno @code{+} nell'output. @@ -4534,7 +4546,7 @@ Forza l'uso del carattere di separazione decimale della localizzazione quando analizza i dati in input (@pxref{Localizzazioni}). -@cindex stampa elegante +@cindex stampa-elegante @item @option{-o}[@var{file}] @itemx @option{--pretty-print}[@code{=}@var{file}] @cindex @option{-o} (opzione) @@ -5018,7 +5030,7 @@ variabile non esiste, o se ha un come valore la stringa nulla, @command{gawk} usa un percorso di default (descritto tra poco). La funzionalit@`a del percorso di ricerca @`e particolarmente utile per costruire -librerie di funzioni di @command{awk}. I file di libreria possono essere messi +librerie di funzioni di @command{awk}. Le librerie di file possono essere messe in una directory standard inclusa nel percorso di ricerca e richiamati sulla riga di comando con un @value{FN} breve. Altrimenti, si dovrebbe scrivere l'intero @value{FN} per @@ -5026,7 +5038,7 @@ ciascun file. Usando l'opzione @option{-i}, o l'opzione @option{-f}, i programmi di @command{awk} scritti sulla riga di comando possono usare le funzionalit@`a -contenute nei file di libreria di @command{awk} +contenute nelle librerie di file di @command{awk} @iftex (@pxrefil{Funzioni di libreria}). @end iftex @@ -5192,7 +5204,11 @@ del filesystem). @item AWK_HASH Se questa variabile @`e impostata con un valore di @samp{gst}, @command{gawk} usa la funzione hash di GNU Smalltalk per gestire i vettori. -Questa funzione pu@`o essere leggermente pi@`u veloce della funzione standard. +Se invece ha per valore @samp{fnv1a}, @command{gawk} usa la funzione hash +@uref{http://www.isthe.com/chongo/tech/comp/fnv/index.html, +FNV1-A}. +Queste funzioni possono essere leggermente pi@`u veloci della funzione standard. + @item AWKREADFUNC Se questa variabile esiste, @command{gawk} legge i file sorgenti una riga per volta, anzich@'e a blocchi. Questa variabile @`e presente @@ -5386,7 +5402,7 @@ possono includere queste ``librerie'' usando il percorso completo dei file, o impostando opportunamente la variabile d'ambiente @env{AWKPATH} e quindi usando @code{@@include} con la sola parte del percorso completo che designa il file. Naturalmente, -si possono tenere i file di libreria in pi@`u di una directory; +si possono tenere le librerie di file in pi@`u di una directory; pi@`u @`e complesso l'ambiente di lavoro, pi@`u directory possono essere necessarie per organizzare i file da includere. @@ -6314,6 +6330,47 @@ nella @dfn{regexp}. Per esempio, @code{/+/} individua un semplice segno pi@`u. Tuttavia, molte altre versioni di @command{awk} trattano una tale notazione come un errore di sintassi. +@sidebar E se la @dfn{regexp} è vuota? +@cindex vuote @subentry @dfn{regexps} +@cindex @dfn{regexp} @subentry vuote +Viene qui descritto un uso avanzato delle @dfn{regexp}. +Pu@`o essere saltato in una prima lettura. + +Si può specificare una costante @dfn{regexp} vuota (@samp{//}) in ogni +posto in cui ci si aspetta di trova una @dfn{regexp}. +Può servire a qualcosa farlo? A cosa corrisponde? + +Ha senso farlo. Corrisponde alla stringa vuota (invisibile), +all'inizio e alla fine di una stringa di caratteri, come pure +alla stringa vuota tra un carattere e l'altro. Lo si vede bene +con la funzione @code{gsub()}, che si usa per fare delle sostituzioni +globali (@pxref{Funzioni per stringhe}). L'uso normale di @code{gsub()} +è del tipo: + +@example +$ @kbd{awk '} +> @kbd{BEGIN @{} +> @kbd{ x = "ABC_CBA"} +> @kbd{ gsub(/B/, "bb", x)} +> @kbd{ print x} +> @kbd{@}'} +@print{} AbbC_CbbA +@end example + +Possiamo usare @code{gsub()} per verificare dove sono situate le stringhe +vuote che corrispondono alla @dfn{regexp} vuote: + +@example +$ @kbd{awk '} +> @kbd{BEGIN @{} +> @kbd{ x = "ABC"} +> @kbd{ gsub(//, "x", x)} +> @kbd{ print x} +> @kbd{@}'} +@print{} xAxBxCx +@end example +@end sidebar + @node Espressioni di intervallo @subsection Alcune note sulle espressioni di intervallo @@ -6384,7 +6441,7 @@ che occupano un unico byte (caratteri il cui valore stia nell'intervallo 0--256). Per individuare un intervallo di caratteri in cui i punti di inizio e fine dell'intervello abbiano valori maggiori di 256, occorre immettere direttamente -le codifiche multi-byte dei caratteri in questione. +le codifiche multibyte dei caratteri in questione. @cindex @code{\} (barra inversa) @subentry in espressioni tra parentesi quadre @cindex barra inversa (@code{\}) @subentry in espressioni tra parentesi quadre @@ -6523,7 +6580,7 @@ sono equivalenti). Queste sequenze sono: @cindex espressioni @subentry tra parentesi quadre @subentry elementi di collazione @cindex elementi @subentry di collazione @item elementi di collazione -Elementi di collazione multi-byte racchiusi fra +Elementi di collazione multibyte racchiusi fra @samp{[.} e @samp{.]}. Per esempio, se @samp{ch} @`e un elemento di collazione, @samp{[[.ch.]]} @`e una @dfn{regexp} che individua questo elemento di collazione, mentre @samp{[ch]} @`e una @dfn{regexp} che individua le lettere @@ -7096,7 +7153,7 @@ getline (@pxref{Getline}). * Dimensione costante:: Leggere campi di larghezza costante. * Separazione in base al contenuto:: Definire campi dal loro contenuto. * Controllare la creazione di campi:: Controllare come @command{gawk} sta - dividendo i record. + suddividendo i record. * Righe multiple:: Leggere record che sono su pi@`u righe. * Getline:: Leggere file sotto il controllo del programma, usando la funzione @@ -7274,23 +7331,6 @@ in questione non viene trattato come tale, ma viene usato letteralmente. Ci@`o viene fatto per compatibilit@`a all'indietro sia con il comando Unix @command{awk} che con lo standard POSIX. -Quando si usano caratteri normali come separatore di record, -c'@`e un caso insolito che capita quando @command{gawk} -@`e reso completamente conforme a POSIX (@pxref{Opzioni}). -In quel caso, la seguente (estrema) @dfn{pipeline} stampa un sorprendente -@samp{1}: - -@example -$ echo | gawk --posix 'BEGIN @{ RS = "a" @} ; @{ print NF @}' -@print{} 1 -@end example - -C'@`e un solo campo, consistente in un ritorno a capo. Il valore della -variabile predefinita @code{NF} @`e il numero di campi nel record corrente. -(Normalmente @command{gawk} tratta il ritorno a capo come uno spazio -vuoto, stampando @samp{0} come risultato. Anche molte altre versioni di -@command{awk} agiscono in questo modo.) - @cindex angolo buio @subentry file in input Il raggiungimento della fine di un file in input fa terminare il record di input corrente, anche se l'ultimo carattere nel file non @`e il carattere in @@ -7387,7 +7427,7 @@ particolare se il testo di input che potrebbe avere una corrispondenza con la parte finale @`e piuttosto lungo. @command{gawk} cerca di evitare questo problema, ma al momento non ci sono garanzie che questo funzioni sempre. -@quotation NOTA +@sidebar Avvertenze per quando si usano espressioni regolari come @code{RS} Si ricordi che in @command{awk}, i metacaratteri di ancoraggio @samp{^} e @samp{$} trovano l'inizio e la fine di una @emph{stringa}, e non l'inizio e la fine di una @emph{riga}. Come risultato, qualcosa come @@ -7395,7 +7435,15 @@ fine di una @emph{riga}. Come risultato, qualcosa come Questo perch@'e @command{gawk} vede il file in input come un'unica lunga stringa in cui possono essere presenti dei caratteri di ritorno a capo. @`E meglio perci@`o evitare metacaratteri di ancoraggio nel valore di @code{RS}. -@end quotation + +La suddivisione in campi usando espressioni regolari funziona in maniera +differente rispetto a quando la si usa con le funzioni @code{sub()}, @code{gsub()}, e +@code{gensub()} (@pxref{Funzioni per stringhe}). Tali funzioni consentono +che un'espressione regolare sia soddisfatta da una stringa nulla; +la suddivisione in campi non lo consente. Quindi, per esempio, +@samp{RS = "()"} @emph{non} divide un record in campi di un carattere +ciascuno. +@end sidebar @cindex @command{gawk} @subentry variabile @subentry @code{RT} in @cindex @code{RT} (variabile) @@ -8034,6 +8082,15 @@ $ @kbd{echo 'xxAA xxBxx C' |} @print{} -->C<-- @end example +Inoltre, +la suddivisione in campi usando espressioni regolari funziona in maniera +differente rispetto a quando la si usa con le funzioni @code{sub()}, @code{gsub()}, e +@code{gensub()} (@pxref{Funzioni per stringhe}). Tali funzioni consentono +che un'espressione regolare sia soddisfatta da una stringa nulla; +La suddivisione in campi non lo consente. Quindi, per esempio, +@samp{RS = "()"} @emph{non} divide un record in campi di un carattere +ciascuno. + @node Campi di un solo carattere @subsection Fare di ogni carattere un campo separato @@ -8592,6 +8649,10 @@ parole, @code{FS} definisce cosa un campo @emph{non @`e}, invece di cosa Tuttavia, ci sono casi in cui effettivamente si ha bisogno di definire i campi in base a cosa essi sono, e non in base a cosa non sono. +@cindex dati CSV (valori separati da virgole) @subentry analizzare con @code{FPAT} +@cindex CSV (valori separati da virgole) come dati @subentry analizzare con @code{FPAT} +@cindex Comma Separated Values (CSV) come dati @subentry analizzare con @code{FPAT} +@cindex valori separati da virgole (CSV) come dati @subentry analizzare con @code{FPAT} Il caso pi@`u emblematico @`e quello dei dati cosiddetti @dfn{comma-separated value} (CSV). Molti fogli elettronici, per esempio, possono esportare i dati in file di testo, dove ogni record termina con un ritorno a capo e i campi @@ -8710,7 +8771,7 @@ FPAT = "([^,]*)|(\"[^\"]+\")" @c Per email from Ed Morton <mortoneccc@comcast.net> @c @c WONTFIX: 10/2020 -@c This is too much work. FPAT and CSV files are very flakey and +@c This is too much work. FPAT and CSV files are very flaky and @c fragile. Doing something like this is merely inviting trouble. Come per @code{FS}, la variabile @code{IGNORECASE} @@ -8789,8 +8850,20 @@ $ @kbd{gawk -v fpat=2 -f test-csv.awk sample.csv} @print{} NF = 3 <p><><s> @end example +@cindex Collado, Manuel +@cindex @code{CSVMODE}, libreria per @command{gawk} +@cindex libreria @code{CSVMODE} per @command{gawk} +@cindex dati CSV (valori separati da virgole) @subentry analizzare con libreria @code{CSVMODE} +@cindex CSV (valori separati da virgole) come dati @subentry analizzare con libreria @code{CSVMODE} +@cindex valori separati da virgole (CSV) come dati @subentry analizzare con libreria @code{CSVMODE} +In generale, usare @code{FPAT} per effettuare l'analisi di dati in formato CSV +@`e come utilizzare un lenzuolo troppo corto. Rimane sempre un angolo che non +@`e coperto. Si raccomanda, in alternativa, di usare la libreria @code{CSVMODE} +messa a disposizione da Manuel Collado. Vedere: +@uref{http://mcollado.z15.es/xgawk/, @code{CSVMODE} libreria per @command{gawk}}. + @node Controllare la creazione di campi -@section Controllare come @command{gawk} sta dividendo i record +@section Controllare come @command{gawk} sta suddividendo i record @cindex @command{gawk} @subentry separazione in campi e Come visto sopra, @command{gawk} fornisce tre metodi indipendenti per @@ -10473,9 +10546,9 @@ dallo standard IEEE 754, il valore infinito negativo @`e rappresentato come @samp{-inf} o @samp{-infinity}, e l'infinito positivo come @samp{inf} o @samp{infinity}. -Il valore speciale ``not a number'' [non @`e un numero] viene scritto come +Il valore speciale ``not a number'' ["non @`e un numero"] viene scritto come @samp{-nan} o @samp{nan} -(@pxref{Definizioni matematiche}). +(@pxref{Valori strani}). @item @code{%F} Come @samp{%f}, ma i valori di infinito e di ``not a number'' sono scritti @@ -13160,16 +13233,18 @@ Per avere la massima portabilit@`a, non usare l'operatore @samp{**=}. @sidebar Ambiguit@`a sintattiche tra @samp{/=} e le espressioni regolari @cindex angolo buio @subentry costanti @dfn{regexp} @subentry operatore @code{/=} e -@cindex @code{/} (barra) @subentry operatore @code{/=} @subentry vs. costante @dfn{regexp} @code{/=@dots{}/} -@cindex barra (@code{/}) @subentry operatore @code{/=} @subentry vs. costante @dfn{regexp} @code{/=@dots{}/} +@cindex @code{/} (barra) @subentry operatore @code{/=} @subentry vs.@: costante @dfn{regexp} @code{/=@dots{}/} +@cindex barra (@code{/}) @subentry operatore @code{/=} @subentry vs.@: costante @dfn{regexp} @code{/=@dots{}/} @cindex @dfn{regexp} @subentry costanti @subentry @code{/=@dots{}/}, operatore @code{/=} e @c derived from email from "Nelson H. F. Beebe" <beebe@math.utah.edu> @c Date: Mon, 1 Sep 1997 13:38:35 -0600 (MDT) -@cindex angolo buio @subentry operatore @code{/=} vs. costante @dfn{regexp} @code{/=@dots{}/} -@cindex ambiguit@`a sintattica: operatore @code{/=} vs. costante @dfn{regexp} @code{/=@dots{}/} -@cindex sintattica @subentry ambiguit@`a: operatore @code{/=} vs. costante @dfn{regexp} @code{/=@dots{}/} +@cindex angolo buio @subentry operatore @code{/=} vs.@: costante @dfn{regexp} @code{/=@dots{}/} +@cindex ambiguit@`a sintattica: operatore @code{/=} vs.@: costante @dfn{regexp} @code{/=@dots{}/} +@cindex sintattica @subentry ambiguit@`a: operatore @code{/=} vs.@: costante @dfn{regexp} @code{/=@dots{}/} +@cindex @code{/=} (uguale) @subentry operatore vs.@: @code{/=@dots{}/} costante @dfn{regexp} +@cindex uguale (@code{/=}) @subentry operatore vs.@: @code{/=@dots{}/} costante @dfn{regexp} C'@`e un'ambiguit@`a sintattica tra l'operatore di assegnamento @code{/=} e le costanti @dfn{regexp} il cui primo carattere sia @samp{=}. @value{DARKCORNER} @@ -14996,12 +15071,13 @@ Ci@`o non @`e pi@`u obbligatorio, ma @`e una buona idea continuare a seguire que modello per migliorare l'organizzazione e la leggibilit@`a del programma. Regole multiple @code{BEGIN} ed @code{END} sono utili per scrivere funzioni -di libreria, poich@'e ogni file di libreria pu@`o avere la sua propria regola -@code{BEGIN} e/o @code{END} per fare la propria inizializzazione e/o pulizia. +di libreria, poich@'e ogni file di una libreria pu@`o avere la sua propria +regola @code{BEGIN} e/o @code{END} per fare la propria inizializzazione e/o +pulizia. L'ordine in cui le funzioni di libreria sono menzionate nella riga dei comandi determina l'ordine in cui le rispettive regole @code{BEGIN} ed @code{END} sono eseguite. Per questo motivi, occorre prestare attenzione nello scrivere tali -regole nei file di libreria, in modo che non sia importante +regole nelle librerie di file, in modo che non sia importante l'ordine in cui tali regole vengono eseguite. @xref{Opzioni} per maggiori informazioni sull'uso di funzioni di libreria. @iftex @@ -15127,11 +15203,11 @@ I codici delle regole @code{BEGINFILE} sono eseguiti subito prima che @`e impostata al nome del file corrente e @code{FNR} @`e impostata a zero. Prima della @value{PVERSION} 5.1.1 di @command{gawk}, per un difetto di -implementazione, @code{$0} e i campi del record mantenevano, nelle regole +implementazione, @code{$0} e i campi del record mantenevano nelle regole @code{BEGINFILE} il valore che avevano in precedenza. A partire dalla @value{PVERSION} 5.1.1, sia @code{$0} che i campi del record sono impostati alla stringa nulla, poich@'e nessun record @`e -ancora stato letto dal file in procinto di essere elaborato. +ancora stato letto dal file che sta per essere di essere elaborato. La regola @code{BEGINFILE} d@`a la possibilit@`a di eseguire due compiti che sarebbe difficile o impossibile effettuare altrimenti: @@ -15194,7 +15270,7 @@ modalit@`a compatibile (@pxref{Opzioni}), non sono regole speciali. @node Vuoto @subsection Il criterio di ricerca vuoto -@cindex vuoto @subentry criterio di ricerca +@cindex vuoti @subentry criteri di ricerca @cindex criteri di ricerca @subentry vuoti Un criterio di ricerca vuoto (cio@`e omesso) corrisponde a @emph{ogni} record in input. Per esempio, il programma: @@ -16060,16 +16136,17 @@ risultato. In @command{gawk}, l'esecuzione di @code{nextfile} produce ulteriori effetti: le eventuali regole @code{ENDFILE} sono eseguite se @command{gawk} non -si trova correntemente all'interno di una regola @code{END} o -@code{BEGINFILE}; @code{ARGIND} @`e +si trova correntemente all'interno di una regola @code{END}, +@code{ARGIND} @`e incrementato e le eventuali regole @code{BEGINFILE} sono eseguite. (@code{ARGIND} non @`e stato ancora trattato. @xref{Variabili predefinite}.) -In @command{gawk}, @code{nextfile} @`e utile all'interno di una regola +C'@`e un ulteriore caso speciale di utilizzo in @command{gawk}. +@code{nextfile} @`e utile all'interno di una regola @code{BEGINFILE} per evitare di elaborare un file che altrimenti causerebbe un errore fatale in @command{gawk}. -In questo caso, le regole @code{ENDFILE} non vengono eseguite. +In questo caso speciale, le regole @code{ENDFILE} non vengono eseguite. @xref{BEGINFILE/ENDFILE}. Sebbene possa sembrare che @samp{close(FILENAME)} ottenga lo stesso @@ -19051,8 +19128,8 @@ modalit@`a compatibile (@pxref{Opzioni}). @cindexawkfunc{log} @cindex logaritmo Restituisce il logaritmo naturale di @var{x}, se @var{x} @`e positivo; -altrimenti, restituisce @code{NaN} (``not a number'') sui sistemi che -implementano lo standard IEEE 754. +altrimenti, restituisce NaN (``not a number'',[``non @`e un numero'']) +sui sistemi che implementano lo standard IEEE 754. Inoltre, @command{gawk} stampa un messaggio di avvertimento qualora @code{x} sia negativo. @@ -26199,13 +26276,13 @@ possono essere separati da virgole, e intervalli di caratteri possono essere separated da trattini. La lista @samp{1-8,15,22-35} specifica i caratteri da 1 a 8, 15, e da 22 a 35. -@item -f @var{lista} -Usare @var{lista} come lista di campi da ritagliare. - @item -d @var{delimitatore} Usare @var{delimitatore} come carattere che separa i campi invece del carattere TAB. +@item -f @var{lista} +Usare @var{lista} come lista di campi da ritagliare. + @item -s Evita la stampa di righe che non contengono il delimitatore di campo. @end table @@ -26216,6 +26293,12 @@ di libreria @code{getopt()} e la funzione di libreria @code{join()} (@pxref{Funzione join}). +La versione POSIX corrente del comando @command{cut} prevede opzioni +per ritagliare dei campi che possono essere sia byte che caratteri +[possibilmente multibyte]. Questa versione non tenta di implementare +tali opzioni, poich@'e @command{awk} lavora esclusivamente in termini +di caratteri. + Il programma inizia con un commento che descrive le opzioni, le funzioni di libreria necessarie, e una funzione @code{sintassi()} che stampa un messaggio ed esce. @code{sintassi()} @`e chiamato se si specificano degli @@ -26237,9 +26320,9 @@ argomenti non validi: @c file eg/prog/cut.awk # Opzioni: +# -c lista Ritagliare caratteri # -f lista Ritagliare campi # -d c Carattere di delimitazione di campo -# -c lista Ritagliare caratteri # # -s Sopprimere righe che non contengono il delimitatore # @@ -26315,7 +26398,7 @@ un semplice spazio (@code{@w{" "}}) come valore per @code{FS} @`e sbagliato: @command{awk} separerebbe i campi con serie di spazi, TAB, e/o ritorni a capo, mentre devono essere separati solo da uno spazio. Per far questo, salviamo il carattere di spazio originale nella variabile -@code{fs} per un uso futuro; dopo aver impostato @code{FS} a @code{"[ ]"} non +@code{fs} per un uso futuro; dopo aver impostato @code{FS} a @code{@w{"[ ]"}} non @`e possibile usarlo direttamente per vedere se il carattere delimitatore di campo @`e nella stringa. @@ -26595,11 +26678,11 @@ da implementare con @command{gawk}; basta usare la variabile predefinita # -e l'argomento @`e un'espressione regolare # -i ignora maiuscolo/minuscolo # -l stampa solo nomi file -# -n aggiungi numeri linea in output +# -n aggiungi numeri riga in output # -q quieto - usa solo il codice di ritorno # -s silenzioso - non stampa messaggi di errore -# -v inverte test, successo se espression non trovata -# -x l'intera linea deve corrispondere +# -v inverte test, successo se espressione non viene trovata +# -x l'intera riga deve corrispondere # # Richiede la funzione getopt() # Usa IGNORECASE, BEGINFILE ed ENDFILE @@ -26633,14 +26716,17 @@ BEGIN @{ @noindent Si noti il commento relativo alla chiamata del programma: -Poich@'e parecchie opzioni possono essere sepcificate anche per -@command{gawk}, occorre immettere @option{--} per far s@`@{dotless{i}} che +Poich@'e parecchie opzioni possono essere specificate anche per +@command{gawk}, occorre immettere @option{--} per far s@`{@dotless{i}} che @command{gawk} non prosegua nell'analisi delle opzioni. Nel seguito c'@`e il codice che gestisce il comportamento specifico di -@command{egrep}. Se non @`e fornito esplicitamente alcun criterio di ricerca -tramite l'opzione @option{-e}, si usa il primo argomento sulla riga di -comando che non sia un'opzione. +@command{egrep}. @command{egrep} utilizza il primo argomento sulla +riga di comando che non sia un'opzione se non @`e fornito esplicitamente +alcun criterio di ricerca tramite l'opzione @option{-e}. +Se il criterio di ricerca @`e la stringa nulla, ci@`o significa che non +@`e stato fornito alcun criterio, quindi @`e necessario stampare un +messaggio di errore e terminare il programma. Gli argomenti della riga di comando di @command{awk} fino ad @code{ARGV[Optind]} vengono cancellati, in modo che @command{awk} non tenti di elaborarli come file. Se @@ -26694,12 +26780,12 @@ BEGINFILE @{ La regola @code{ENDFILE} viene eseguita alla fine dell'elaborazione di ogni file. Genera dell'output solo quando l'utente richiede un -contatore del numero di righe che sono state trovate corrispondere. +contatore del numero di righe corrispondenti che sono state trovate. La variabile @code{non_stampare} @`e vera qualora si chieda di impostare solo il codice di ritorno. La variabile @code{conta_e_basta} @`e vera qualora si chieda solo -il numero delle righe che sono state trovare corrispondere. +il numero delle righe corrispondenti che sono state trovate. @command{egrep} quindi stampa il contatore delle corrispondenze trovate solo se sia la stampa che il conteggio righe sono richieste. Il formato dell'output dev'essere adattato, a seconda del numero di @@ -26734,9 +26820,9 @@ verificando i valori delle variabili @code{RSTART} e @code{RLENGTH}. Se questi indicano che la corrispondenza non coincide con l'intera riga, la variabile @code{corrisponde} @`e impostata a zero (falsa). -Se l'utente chiede invece le righe che @emph{non} corrispondono, -il senso di @code{corrisponde} @`e invertito, usando l'operatore @samp{!}. -@code{contatore_file} @`e incrementato con il valore di +Se l'utente chiede invece le righe che non corrispondono, si inverte +il senso di @code{corrisponde}, usando l'operatore @samp{!}. +Poi, @code{contatore_file} @`e incrementato con il valore di @code{corrisponde}, che vale uno o zero, a seconda che la corrispondenza sia stata trovata oppure no. Se la riga non corrisponde, l'istruzione @code{next} passa ad esaminare il record successivo. @@ -26855,14 +26941,14 @@ Usa la funzione di libreria @code{getopt()} (@pxref{Funzione getopt}), le funzioni di libreria del database che descrive gli utenti (@pxref{Funzioni Passwd}), -Usa le funzioni di libreria che riguardano il database degli utenti +le funzioni di libreria che riguardano il database degli utenti (@pxref{Funzioni Passwd}) e le funzioni di libreria che riguardano il database dei gruppi (@pxref{Funzioni Group}). Il programma @`e abbastanza semplice. Tutto il lavoro @`e svolto nella regola @code{BEGIN}. -Inizia com dei commenti di spiegazioni, una lista di opzioni e infine +Inizia con dei commenti di spiegazione, una lista di opzioni e infine una funzione @code{sintassi()} function: @cindex @code{id.awk} (programma) @@ -26939,7 +27025,7 @@ BEGIN @{ @end example Il passo successivo @`e quello di controllare che non siano state -specificate opzioni mutualmente esclusive. +specificate opzioni mutuamente esclusive. Le opzioni @option{-G} e @option{-r} sono di questo tipo. Inoltre, non @`e possibile specificare pi@`u di un nome utente sulla riga di comando: @@ -26958,7 +27044,7 @@ dal vettore @code{PROCINFO} dell'utente corrente, oppure dal database degli utenti e delle password, per un utente il cui nome sia stato specificato nella riga di comando. -In quest'ultimo caos, viene impostato il flag @code{real_ids_only}, +In quest'ultimo caso, viene impostato il flag @code{real_ids_only}, poich@'e non @`e possibile stampare informazioni riguardo agli ID di utente e di gruppo effettivi: @@ -27075,9 +27161,9 @@ Una logica simile viene seguita per l'opzione @option{-u} @end example A questo punto non abbiamo ancora finito, e quindi stampiamo -l'output normale, di default, a riguardo dell'utente corrente -o dell'utente che era stato specificato sulla riga di comando. -Iniziamo a stmpare l'user ID reale: +l'output normale, di default, relative all'utente corrente +o all'utente che era stato specificato sulla riga di comando. +Iniziamo a stampare l'user ID reale: @example @c file eg/prog/id.awk @@ -27256,7 +27342,7 @@ ogni file dovrebbe essere lungo (al massimo) @var{N} byte. Se si specifica la lettera @samp{k}, il numero @var{N} viene moltiplicato per 1.024, ossia diviene il numero di kilobyte. Se si specifica la lettera @samp{m}, il numero @var{N} viene -moltiplicato per 1.048.576 (@math{1.024 @value{PER} 1.024}) +moltiplicato per 1.048.576 (@math{1.024 @value{VOLTE} 1.024}) ossia diviene il numero di megabyte. (Quest'opzione @`e mutuamente esclusiva con l'opzione @option{-l}). @@ -27285,7 +27371,9 @@ Ecco un'implementazione di @command{split} in @command{awk}. Viene utilizzata la funzione @code{getopt()} presentata in @ref{Funzione getopt}. Il programma inizia con un commento descrittivo e poi con la -funzione @code{sintassi()} che ne descrive le opzioni: +funzione @code{sintassi()} che ne descrive le opzioni. La variabile +@code{comune} permettere di avere delle righe brevi nella funzione, +in modo che sia stampata in maniera elegante nella pagina: @cindex @code{split.awk} (programma) @cindex programma @subentry @code{split.awk} @@ -27306,10 +27394,11 @@ funzione @code{sintassi()} che ne descrive le opzioni: @c endfile @end ignore @c file eg/prog/split.awk -function sintassi() +function sintassi( comune) @{ - print("Uso: split [-l contatore] [-a lunghezza-suffisso] [file [nome-output-file]]") > "/dev/stderr" - print(" split [-b N[k|m]] [-a lunghezza-suffisso] [file [nome-output-file]]") > "/dev/stderr" + common = "[-a lunghezza-suffisso] [file [nome-output-file]]" + printf("Uso: split [-l contatore] %s\n", comune) > "/dev/stderr" + printf(" split [-b N[k|m]] %s\n", comune) > "/dev/stderr" exit 1 @} @c endfile @@ -27402,7 +27491,7 @@ passare da @samp{abz} ad @samp{aca}. @item Si deve poter determinare se abbiamo utilizzato tutti i prefissi, -in modo che, nel caso ci siano ulteriori dati (da suddividere) si +in modo che, nel caso ci siano ulteriori dati (da suddividere), si possa stampare un messaggio di errore e terminare il programma. Il trucco @`e di gestire una tale situazione @emph{dopo} aver usato l'ultimo suffisso disponibile, e non quando viene generato l'ultimo @@ -27801,7 +27890,8 @@ spiegazione delle opzioni e del loro significato, sotto forma di commenti: function sintassi() @{ - print("Uso: uniq [-udc [-f campi]] [-s caratteri] [ in [ out ]]") > "/dev/stderr" + print("Uso: uniq [-udc [-f campi] [-s caratteri]] " \ + "[ in [ out ]]") > "/dev/stderr" exit 1 @} @@ -28063,14 +28153,14 @@ Klingon e il linguaggio degli elfi di J.R.R.@: Tolkien). Per risparmiare spazio nei file, i @dfn{code points} Unicode sono @dfn{codificati}, e la rappresentazione di ogni carattere pu@`o richiedere da uno a quattro byte nel file. UTF-8 @`e verosimilmente la pi@`u diffusa -fra queste codifiche multi-byte (@dfn{multibyte encodings}). +fra queste codifiche multibyte (@dfn{multibyte encodings}). Lo standard POSIX richiede che @command{awk} gestisca dei caratteri, non dei byte. Per questo motivo, in @command{gawk}, le funzioni @code{length()}, @code{substr()}, @code{split()}, @code{match()} e le altre funzioni di manipolazione di stringhe (@pxref{Funzioni per stringhe}) funzionano tutte elaborando dei caratteri, -come definiti dall'insieme di caratteri locale [a una determinata lingua] +come definiti dall'insieme di caratteri localizzati [a una determinata lingua] e non elaborando dei byte. (Incidentalmente, non tutte le implementazioni di @command{awk} si comportano cos@`{@dotless{i}}). @@ -28090,8 +28180,8 @@ possono anche essere dei codici scritti nei linguaggi C o C++. Per quanto riguarda @file{wc.awk}, @`e sufficiente sapere che l'estensione viene caricata con la direttiva @code{@@load}, e la funzione ulteriore che dovr@`a essere -usata si chiama @code{mbs_length()}. Questa funzione restiuisce il numero -di byte in una stringa, e non il numero di caratteri. +usata si chiama @code{mbs_length()}. Questa funzione restituisce il numero +di byte in una stringa, non il numero di caratteri. L'estensione @code{"mbs"} fa parte del progetto @code{gawkextlib}. @xref{gawkextlib} for ulteriori informazioni. @@ -28110,23 +28200,23 @@ standard input. Se ci sono pi@`u file, stampa anche il contatore totale di tutti i file. Le opzioni e il loro significato sono i seguenti: @table @code -@item -l -Conta solo le righe. - -@item -w -Conta solo le parole. -Una ``parola'' @`e una sequenza contigua di caratteri non bianchi, separata da -spazi e/o TAB. Fortunatamente, questo @`e il modo normale in cui @command{awk} -separa i campi nei suoi record in input. - @item -c Conta solo i byte. Un tempo, la lettera @samp{c} di questa opzione stava per ``caratteri.'' Ma, come spiegato pi@`u sopra, byte e carattere non sono pi@`u sinonimi tra loro. +@item -l +Conta solo le righe. + @item -m Conta solo caratteri. + +@item -w +Conta solo le parole. +Una ``parola'' @`e una sequenza contigua di caratteri non bianchi, separata da +spazi e/o TAB. Fortunatamente, questo @`e il modo normale in cui @command{awk} +separa i campi nei suoi record in input. @end table L'implementazione di @command{wc} in @command{awk} @`e particolarmente @@ -29365,7 +29455,7 @@ La riga @`e poi stampata nel file di output: gsub("@@`o","ò",riga) gsub("@@`u","ù",riga) # riga contiene ancora caratteri @@? - if (index(riga, "@@") == 0) { + if (index(riga, "@@") == 0) @{ print riga > file_corrente continue @} @@ -30618,6 +30708,7 @@ tratta della capacit@`a di aggiungere dinamicamente nuove funzioni predefinite a processo. * Reti TCP/IP:: Usare @command{gawk} per programmazione di rete. * Profilare:: Profilare i propri programmi @command{awk}. +* Filosofia delle estensioni:: Cosa dovrebbe essere incluso e cosa no. * Sommario funzionalit@`a avanzate:: Sommario delle funzionalit@`a avanzate. @end menu @@ -31828,7 +31919,7 @@ alfabetico. La versione profilata del proprio programma potrebbe non apparire esattamente come quella scritta durante la stesura del programma. Questo perch@'e -@command{gawk} crea la versione profilata facendo una ``stampa elegante'' della +@command{gawk} crea la versione profilata facendo una ``stampa-elegante'' della sua rappresentazione interna del programma. Un vantaggio di ci@`o @`e che @command{gawk} pu@`o produrre una rappresentazione standard. Inoltre, cose come: @@ -31923,9 +32014,9 @@ tastiera. Il segnale @code{INT} @`e generato dalle combinazioni di tasti @kbd{Ctrl-c} o @kbd{Ctrl-BREAK}, mentre il segnale @code{QUIT} @`e generato dalla combinazione di tasti @kbd{Ctrl-\}. -@cindex stampa elegante +@cindex stampa-elegante Infine, @command{gawk} accetta anche un'altra opzione, @option{--pretty-print}. -Quando viene chiamato in questo modo, @command{gawk} fa una ``stampa elegante'' +Quando viene chiamato in questo modo, @command{gawk} fa una ``stampa-elegante'' del programma nel file @file{awkprof.out}, senza conteggi sull'esecuzione. @quotation NOTA @@ -31933,10 +32024,10 @@ Una volta, l'opzione @option{--pretty-print} eseguiva anche il programma. Ora non pi@`u. @end quotation -@cindex profilazione @subentry differenza rispetto alla stampa elegante -@cindex stampa elegante @subentry differenza rispetto alla profilazione +@cindex profilazione @subentry differenza rispetto alla ``stampa-elegante'' +@cindex stampa-elegante @subentry differenza rispetto alla profilazione C'@`e una differenza significativa tra l'output creato durante la profilazione, -e quello creato durante la stampa elegante. L'output della stampa elegante +e quello creato durante la ``stampa-elegante''. L'output della ``stampa-elegante'' preserva i commenti originali che erano nel programma, anche se la loro posizione pu@`o non corrispondere esattamente alle posizioni originali che avevano nel codice sorgente. Tuttavia, nessun commento dovrebbe andare @@ -31948,23 +32039,83 @@ in maniera perfetta. Comunque, per una precisa scelta progettuale, l'output della profilazione @emph{omette} i commenti del programma originale. Questo permette di concentrarsi sui dati del conteggio di esecuzione ed evita la tentazione di -usare il profilatore per creare una stampa elegante. +usare il profilatore per creare una ``stampa-elegante''. Oltre a ci@`o, l'output stampato in modo elegante non ha l'indentazione iniziale -che ha l'output della profilazione. Questo rende agevole la stampa elegante +che ha l'output della profilazione. Questo rende agevole la ``stampa-elegante'' del proprio codice una volta completato lo sviluppo, usando poi il risultato come versione finale del programma. Poich@'e la rappresentazione interna del programma @`e formattata per essere aderente al programma @command{awk} in questione, la profilazione -e la stampa elegante (opzione @option{--pretty-print}) disabilitano +e la ``stampa-elegante'' (opzione @option{--pretty-print}) disabilitano automaticamente le optimizzazioni di default di @command{gawk}. -La profilazione e la stampa elegante mantengono anche il formato originale +La profilazione e la ``stampa-elegante'' mantengono anche il formato originale delle costanti numeriche; se sono stati usati dei valori ottali o esadecimali nel codice sorgente, questi compariranno nell'output nello stesso formato con cui sono stati inseriti. +@node Filosofia delle estensioni +@section Funzionalit@`a incluse @dfn{versus} estensioni + +Come descritto sin qui e nei successivi @value{CHAPTERS}, +@command{gawk} ha numerose estensioni ulteriori, +rispetto a quelle presenti nel comando @command{awk} standard. +Queste sono state sviluppate col passare del tempo. +Pi@`u recentemente, l'attenzione si @`e spostata sull'uso +del meccanismo delle estensioni (@pxref{Estensioni dinamiche}) +per aggiungere ulteriori funzionalit@`a. +@ifnotinfo +Questa @value{SECTION} +@end ifnotinfo +@ifinfo +Questo @value{SECTION} +@end ifinfo +tratta della ``filosofia ispiratrice'' riguardo a ci@`o che dovrebbe +essere aggiunto all'interprete come funzionalit@`a interna, +rispetto a quello che dovrebbe essere reso disponibile tramite +estensioni. + +Ci sono parecchi obiettivi: + +@enumerate 1 +@item +Conservare il comando @command{awk}; non dovrebbe divenire irriconoscibile +anche se i programmi scritti per esso verranno eseguito usando solo +@command{gawk}. + +@item +Non aumentare le dimensioni del nucleo del programma, a meno che ci@`o +sia assolutamente indispensabile. + +@item +Aggiungere nuove funzionalit@`a o tramite @dfn{script} +(opzione @option{-f}, direttiva @code{@@include}) +o in un'estensione caricabile scritta in C o C++ +(opzione @option{-l}, direttiva @code{@@load}). + +@item +Estendere il nucleo dell'interpretatore solo se qualche funzionalit@`a: + +@c sublist +@enumerate A +@item +@`E veramente desiderabile. +@item +Non si pu@`o ottenere tramite dei file di libreria o estensioni caricabili. +@item +Pu@`o essere aggiunta al nucleo senza troppe difficolt@`a. +@end enumerate +@end enumerate + +Combinare dei moduli con dei file @command{awk} @`e una tecnica efficace. +Lo si pu@`o vedere in alcuni degli esempi di estensione. + +Il caricamento di estensioni e librerie di file non dovrebbe essere +fatto automaticamente, perch@'e questo richiede un consumo di risorse +che molti utenti non desiderano, o di cui non hanno bisogno. + @node Sommario funzionalit@`a avanzate @section Sommario @@ -32012,9 +32163,14 @@ profilazione @command{gawk} scrive il profilo, includendo lo @dfn{stack} della chiamata alla funzione e prosegue nell'elaborazione. @item -Si pu@`o anche fare solo una ``stampa elegante'' del programma. +Si pu@`o anche fare solo una ``stampa-elegante'' del programma. +@item +Nuove funzionalit@`a dovrebbero essere sviluppate usando, se possibile, +il meccanismo delle estensioni; si dovrebbero aggiungere al nucleo +dell'interpretatore solo come ultima risorsa. @end itemize + @node Internazionalizzazione @chapter Internazionalizzazione con @command{gawk} @@ -33579,7 +33735,7 @@ argomenti. * Controllo dei breakpoint:: Controllo dei punti d'interruzione. * Controllo esecuzione debugger:: Controllo di esecuzione. * Vedere e modificare dati:: Vedere e modificare dati. -* Stack di esecuzione:: Lavorare con lo @dfn{stack}. +* Stack di esecuzione:: Lavorare con lo @dfn{Stack}. * Informazioni sul debugger:: Ottenere informazioni sullo stato del programma e del debugger. * Comandi vari del debugger:: Comandi vari del debugger. @@ -34016,8 +34172,8 @@ argomenti) dalla lista dei punti d'osservazione. @end table -@node @dfn{Stack} di esecuzione -@subsection Lavorare con lo @dfn{stack} +@node Stack di esecuzione +@subsection Lavorare con lo @dfn{Stack} Ogni volta che si esegue un programma che contiene chiamate di funzione, @command{gawk} mantiene una pila contenente la lista delle chiamate di funzione @@ -35079,10 +35235,10 @@ Questo interagisce con altre importanti funzionalit@`a di @command{gawk}. @cindex spazio-dei-nomi @subentry interazione con la profilazione -@cindex spazio-dei-nomi @subentry interazione con la stampa elegante +@cindex spazio-dei-nomi @subentry interazione con la ``stampa-elegante'' @cindex profilazione @subentry interazione con spazio-dei-nomi -@cindex stampa elegante @subentry interazione con spazio-dei-nomi -La profilazione e la stampa elegante (@pxref{Profilare}) sono state +@cindex stampa-elegante @subentry interazione con spazio-dei-nomi +La profilazione e la ``stampa-elegante'' (@pxref{Profilare}) sono state migliorate per trattare gli spazi-dei-nomi e le regole per assegnare nomi in uno spazio-dei-nomi @ref{Regole per i nomi}. In particolare, l'output tiene insieme le funzioni che appartengono @@ -35143,7 +35299,7 @@ disponibile la potenza e la flessibilit@`a necessarie. @item Altre parti di @command{gawk} sono state estese come necessario per integrare gli spazi-dei-nomi nel loro funzionamento. -Questo vale soprattutto per la profilazione / stampa elegante +Questo vale soprattutto per la profilazione / ``stampa-elegante'' (@pxref{Profilare}) e per le funzionalit@`a relative alle estensioni (@pxref{Estensioni dinamiche}). @@ -35366,23 +35522,10 @@ Come i numeri vanno arrotondati, per eccesso o per difetto, quando necessario. Maggiori dettagli verranno forniti in seguito. @item NaN -``Not a number'' (Non un Numero).@footnote{Grazie a Michael -Brennan per questa descrizione, che abbiamo parafrasato, e per gli esempi.} Un -valore speciale che risulta da un calcolo che non ha risposta come numero -reale. In tal caso, i programmi possono o ricevere un'eccezione di virgola -mobile, o restituire @code{NaN} come risultato. Lo standard IEEE 754 -consiglia che i sistemi restituiscano @code{NaN}. Alcuni esempi: - -@table @code -@item sqrt(-1) -La radice quadrata di @minus{}1 ha senso nell'insieme dei numeri complessi, -ma non nell'insieme dei numeri reali, -per cui il risultato @`e @code{NaN}. - -@item log(-8) -Il logaritmo di @minus{}8 @`e fuori dal dominio di @code{log()}, -per cui il risultato @`e @code{NaN}. -@end table +``Not a number'' (``non @`e un numero''). Un valore speciale +che risulta da un calcolo che non ha come risposta un numero +reale. @xref{Valori strani}, per maggiori informazioni riguardo +ai valori infiniti e ai valori ``non-un-numero''. @item Normalizzato (formato) Come la mantissa (vedi oltre in questa lista) @`e usualmente memorizzata. Il @@ -35534,8 +35677,8 @@ ottenere ulteriori informazioni, e non basarsi solo su quanto qui detto. * Ottenere la precisione:: Ottenere pi@`u precisione richiede qualche sforzo. * Tentare di arrotondare:: Aggiungere cifre di precisione e arrotondare. -* Impostare la precisione:: Come impostare la precisione. -* Impostare modo di arrotondare:: Impostare le modalit@`a di arrotondamento. +* Impostare la precisione:: Impostare la precisione. +* Impostare modo di arrotondare:: Impostare la modalit@`a di arrotondamento. @end menu @node Inesattezza nei calcoli @@ -35556,6 +35699,7 @@ il numero di cifre decimali esatte nel risultato finale. * Rappresentazioni inesatte:: I numeri non sono rappresentati esattamente. * Confronti tra valori in VM:: Come confrontare valori in virgola mobile. * Gli errori si sommano:: Gli errori diventano sempre maggiori. +* Valori strani:: Valori in virgola mobile non spiegati a scuola. @end menu @node Rappresentazioni inesatte @@ -35682,6 +35826,257 @@ $ @kbd{gawk 'BEGIN @{} @print{} 4 @end example +@node Valori strani +@subsubsection Valori in virgola mobile non spiegati a scuola + +Sia l'hardware che implementa lo standard per i numeri in virgola +mobili IEEE 754, che la libreria matematica MPFR, prevedono due +tipi di valori di cui probabilmente non vi hanno parlato a scuola. +Il primo @`e il valore @dfn{infinity} (``infinito''), un valore speciale +che pu@`o avere un segno sia negativo che positivo, e che @`e pi@`u +piccolo di ogni altro valore (infinito negativo), o maggiore di ogni +altro valore (infinito positivo). Quando vengono generati tali valori +@command{gawk} li stampa come @samp{-inf} o @samp{+inf}, rispettivamente. +@command{gawk} accetta queste stringhe come dati in input, e li converte +internamente all'appropriato valore in virgola mobile. + +Valori di infinito che abbiano lo stesso segno risultano uguali +quando sono confrontati fra loro. +Per il resto, altre operazioni (addizione, sottrazione, etc.) +che hanno come operando un infinito e un altro numero producono +risultati matematicamente ragionevoli. + +Il secondo tipo di valore @`e ``not a number'' [``non @`e un numero''] +scritto in forma abbreviata come NaN.@footnote{Grazie a Michael Brennan +per questa descrizione, che abbiamo parafrasato, e per gli esempi.} + +Questo @`e un valore speciale che risulta da un calcolo che non ha come +risposta un numero reale. In tal caso, i programmi possono o ricevere +un’eccezione di virgola mobile, o restituire NaN come risultato. +Lo standard IEEE 754 consiglia che i sistemi restituiscano NaN. +Alcuni esempi: + +@table @code +@item sqrt(-1) +@iftex +La funzione @math{\sqrt{-1}} +@end iftex +@ifnottex +Questa funzione +@end ifnottex +ha senso nell'insieme dei numeri complessi, +ma non nell'insieme dei numeri reali, +per cui il risultato @`e @code{NaN}. + +@item log(-8) +Il logaritmo di @minus{}8 @`e fuori dal dominio di @code{log()}, +per cui il risultato @`e @code{NaN}. +@end table + +I valori Nan sono strani. In particolare, non possono essere confrontati +con altri numeri in virgola mobile; ogni confronto di questo tipo, eccetto +quello ``non uguale a'', restituisce il valore ``falso''. +I valori NaN sono talmente differenti da altri valori che perfino il +confronto di due valori NaN identici fra loro con @code{!=} restituisce +il valore ``vero''! + +I valori NaN possono anche avere un segno (positivo o negativo), +anche se dipende dall'implementazione quale segno viene restituito +da qualsiasi operazione il cui risultato sia un valore NaN. +Per esempio, su alcuni sistemi la funzione @code{sqrt(-1)} +restituisce un NaN negativo. Su altri sistemi il NaN restituito +@`e invece positivo. + +Quando tali valori vengono generati, @command{gawk} li stampa +come @samp{-nan} o @samp{+nan}, rispettivamente. Anche per +questi valori, @command{gawk} accetta queste stringhe come +dati in input e le converte internamente ai valori loro +assegnati come numeri in virgola mobile. + +Se si desidera approfondire ulteriormente questo argomento, si possono +trovare programmi di test scritti in C, @command{awk} e Python +nella directory @file{awklib/eg/test-programs} disponibile +nella distribuzione di @command{gawk}. +Tali programmi permettono un confronto tra i linguaggi di +programmazione, riguardo al modo con cui vengono trattati +i valori di infinito e quelli NaN. + +@ignore +@c file eg/test-programs/gen-float-table.awk +function eq(left, right) +@{ + return left == right +@} + +function ne(left, right) +@{ + return left != right +@} + +function lt(left, right) +@{ + return left < right +@} + +function le(left, right) +@{ + return left <= right +@} + +function gt(left, right) +@{ + return left > right +@} + +function ge(left, right) +@{ + return left >= right +@} + +BEGIN @{ + nan = sqrt(-1) + inf = -log(0) + split("== != < <= > >=", names) + names[3] = names[3] " " + names[5] = names[5] " " + split("eq ne lt le gt ge", funcs) + + compare[1] = 2.0 + compare[2] = values[1] = -sqrt(-1.0) # nan + compare[3] = values[2] = sqrt(-1.0) # -nan + compare[4] = values[3] = -log(0.0) # inf + compare[5] = values[4] = log(0.0) # -inf + + for (i = 1; i in values; i++) @{ + for (j = 1; j in compare; j++) @{ + for (k = 1; k in names; k++) @{ + the_func = funcs[k] + printf("%g %s %g -> %s\n", + values[i], + names[k], + compare[j], + @@the_func(values[i], compare[j]) ? + "True" : "False"); + @} + printf("\n"); + @} + @} +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.c +#include <stdio.h> +#include <math.h> +#include <stdbool.h> + +#define def_func(name, op) \ + bool name(double left, double right) @{ \ + return left op right; \ + @} + +def_func(eq, ==) +def_func(ne, !=) +def_func(lt, <) +def_func(le, <=) +def_func(gt, >) +def_func(ge, >=) + +struct @{ + const char *name; + bool (*func)(double left, double right); +@} functions[] = @{ + @{ "==", eq @}, + @{ "!=", ne @}, + @{ "< ", lt @}, + @{ "<=", le @}, + @{ "> ", gt @}, + @{ ">=", ge @}, + @{ 0, 0 @} +@}; + +int main() +@{ + double values[] = @{ + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + double compare[] = @{ 2.0, + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + + int i, j, k; + + for (i = 0; i < 4; i++) @{ + for (j = 0; j < 5; j++) @{ + for (k = 0; functions[k].name != NULL; k++) @{ + printf("%g %s %g -> %s\n", values[i], + functions[k].name, + compare[j], + functions[k].func(values[i], compare[j]) ? "True" : "False"); + @} + printf("\n"); + @} + @} + + return 0; +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.py +from math import * + +nan = float('NaN') +inf = float('Inf') + +def eq(left, right): + return left == right + +def ne(left, right): + return left != right + +def lt(left, right): + return left < right + +def le(left, right): + return left <= right + +def gt(left, right): + return left > right + +def ge(left, right): + return left >= right + +func_map = { + "==": eq, + "!=": ne, + "< ": lt, + "<=": le, + "> ": gt, + ">=": ge, +} + +compare = [2.0, nan, -nan, inf, -inf] +values = [nan, -nan, inf, -inf] + +for i in range(len(values)): + for j in range(len(compare)): + for op in func_map: + print("%g %s %g -> %s" % + (values[i], op, compare[j], func_map[op](values[i], compare[j]))) + + print("") +@c endfile +@end ignore + @node Ottenere la precisione @subsection Ottenere la precisione voluta @@ -37369,8 +37764,8 @@ restituiti sono di tipo @code{mpfr_ptr} e @code{mpz_ptr} rispettivamente, e si dovrebbero assegnare in maniera appropriata questi codici di ritorno prima di assegnare i risultati a variabili del tipo corretto. -La memoria allocata da queste funzioni dovrebbe essere liberata a fine -utilizzo, richiamando @code{gawk_free()}. +La memoria allocata da queste funzioni dovrebbe essere liberata dopo il +loro uso, richiamando @code{gawk_free()}. @node Funzioni di costruzione @subsection Funzioni per creare valori @@ -38023,7 +38418,7 @@ I campi sono: @table @code @item awk_bool_t use_chars; Impostare ad @code{awk_true} se le lunghezze di campo sono specificate in -unit@`a di caratteri potenzialmente multi-byte, oppure impostarlo a +unit@`a di caratteri potenzialmente multibyte, oppure impostarlo a @code{awk_false} se le lunghezze sono espresse in numero di byte. L'efficienza del programma sar@`a maggiore utilizzando la dimensione in byte. @@ -42555,7 +42950,7 @@ con @option{--}. @item L'opzione @option{--source} per combinare codice sorgente immesso nella riga -di comando e codice sorgente proveniente da file di libreria. +di comando e codice sorgente proveniente da librerie di file. @end itemize @end itemize @@ -43057,7 +43452,7 @@ L'opzione @option{-D} attiva il debugger. @item Le opzioni @option{-i} e @option{--include} -caricano dei file di libreria @command{awk}. +caricano delle librerie di file @command{awk}. @item Le opzioni @option{-l} e @option{--load} caricano estensioni dinamiche @@ -43105,7 +43500,7 @@ La funzione @code{getline} ridiretta @`e stata resa possibile all'interno di @item Il comando @code{where} @`e stato aggiunto al debugger -(@pxref{@dfn{Stack} di esecuzione}). +(@pxref{Stack di esecuzione}). @item Il supporto per Ultrix @`e stato rimosso. @@ -44390,7 +44785,7 @@ Il codice sorgente di @command{gawk}, in generale, cerca di aderire, nei limiti del possibile, a degli standard formali. Ci@`o significa che @command{gawk} usa routine di libreria che sono specificate nello standard ISO C e nello standard POSIX per le interfacce dei sistemi operativi. Il codice sorgente di -@command{gawk} richiede l'uso di un compilatore ISO C (standard 1990). +@command{gawk} richiede l'uso di un compilatore ISO C (standard 1999). Molti sistemi Unix non aderiscono completamente n@'e allo standard ISO n@'e a quello POSIX. La sottodirectory @file{missing_d} nella distribuzione di @@ -45411,6 +45806,10 @@ il sito @url{https://sourceforge.net/projects/awka}. Il progetto sembra essere stato congelato; non ci sono state modifiche nel codice sorgente dal 2001 circa. +@item Resuscitare Awka +Questo progetto, disponibile nel sito @uref{https://github.com/noyesno/awka}, +si propone di fissare bug in @command{awka} e di aggiungere nuove funzionalit@`a. + @cindex Beebe, Nelson H.F.@: @cindex @command{pawk} (versione con profilazione di Brian Kernighan @command{awk}) @cindex codice sorgente @subentry @command{pawk} @@ -45464,6 +45863,17 @@ il progetto mette a disposizione questa implementazione. Si possono vedere i singoli file in @uref{https://github.com/joyent/illumos-joyent/blob/master/usr/src/cmd/awk_xpg4}. +@cindex @command{frawk} +@cindex sorgente @subentry codice @subentry @command{frawk} +@cindex codice sorgente @subentry @command{frawk} +@item @command{frawk} +Questo @`e un linguaggio per scrivere programmi corti. +``In prima approssimazione, @`e un'implementazione del linguaggio AWK; +molti comuni programmi @command{awk} producono un output equivalente +quando passati a @command{frawk}.'' Comunque, ha anche numerose e +importanti funzionalit@`a ulteriori. Il codice sorgente @`e disponibile +sul sito @uref{https://github.com/ezrosent/frawk}. + @cindex @command{goawk} @cindex Go @subentry implementazione di @command{awk} @cindex sorgente @subentry @command{goawk} @@ -45490,7 +45900,13 @@ essere un interprete completo, anche se, poich@'e usa funzionalit@`a di Java per l'I/O e per la ricerca di @dfn{regexp}, il linguaggio che supporta @`e differente da @command{awk} POSIX. Ulteriori informazioni sono disponibili sulla -@uref{https://jawk.sourceforge.net, pagina principale del progetto}. +@uref{http://jawk.sourceforge.net, pagina principale del progetto}. + +@item Hoijui's @command{jawk} +Questo progetto, disponibili sul sito +@uref{https://github.com/hoijui/Jawk}, +@`e un altro interpretatore di @command{awk} scritto in Java. +Usa i moderni strumenti di sviluppo software di Java. @item Libmawk @cindex @command{libmawk} (interpretatore) @@ -45504,7 +45920,6 @@ Questo @`e un interprete @command{awk} incorporabile, derivato da @cindex interpretatore @command{awk} incorporabile @subentry codice sorgente @cindex Neacsu, Mircea @item @command{awk} incorporabile di Mircea Neacsu -@item incorporabile, @command{awk}, di Mircea Neacsu Mircea Neacsu ha creato un interpretatore @command{awk} incorporabile, basato su BWK @command{awk}. @`E disponibile nel sito @uref{https://github.com/neacsum/awk}. @@ -45549,6 +45964,9 @@ Wikipedia} su @command{awk} per informazioni su ulteriori versioni. @end table +Un'interessante raccolta di funzioni di libreria @`e disponibile sul sito +@uref{https://github.com/e36freak/awk-libs}. + @node Sommario dell'installazione @appendixsec Sommario diff --git a/doc/it/gendocs.sh b/doc/it/gendocs.sh new file mode 100755 index 00000000..1872de9d --- /dev/null +++ b/doc/it/gendocs.sh @@ -0,0 +1,510 @@ +#!/bin/sh -e +# gendocs.sh -- generate a GNU manual in many formats. This script is +# mentioned in maintain.texi. See the help message below for usage details. + +scriptversion=2021-01-01.00 + +# Copyright 2003-2021 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +# Original author: Mohit Agarwal. +# Send bug reports and any other correspondence to bug-gnulib@gnu.org. +# +# The latest version of this script, and the companion template, is +# available from the Gnulib repository: +# +# https://git.savannah.gnu.org/cgit/gnulib.git/tree/build-aux/gendocs.sh +# https://git.savannah.gnu.org/cgit/gnulib.git/tree/doc/gendocs_template + +# TODO: +# - image importing was only implemented for HTML generated by +# makeinfo. But it should be simple enough to adjust. +# - images are not imported in the source tarball. All the needed +# formats (PDF, PNG, etc.) should be included. + +prog=`basename "$0"` +srcdir=`pwd` + +scripturl="https://git.savannah.gnu.org/cgit/gnulib.git/plain/build-aux/gendocs.sh" +templateurl="https://git.savannah.gnu.org/cgit/gnulib.git/plain/doc/gendocs_template" + +: ${SETLANG="env LANG= LC_MESSAGES= LC_ALL= LANGUAGE="} +: ${MAKEINFO="makeinfo"} +: ${TEXI2DVI="texi2dvi"} +: ${DOCBOOK2HTML="docbook2html"} +: ${DOCBOOK2PDF="docbook2pdf"} +: ${DOCBOOK2TXT="docbook2txt"} +: ${GENDOCS_TEMPLATE_DIR="."} +: ${PERL='perl'} +: ${TEXI2HTML="texi2html"} +unset CDPATH +unset use_texi2html + +MANUAL_TITLE= +PACKAGE= +EMAIL=webmasters@gnu.org # please override with --email +commonarg= # passed to all makeinfo/texi2html invcations. +dirargs= # passed to all tools (-I dir). +dirs= # -I directories. +htmlarg="--css-ref=/software/gnulib/manual.css -c TOP_NODE_UP_URL=/manual" +default_htmlarg=true +infoarg=--no-split +generate_ascii=true +generate_html=true +generate_info=true +generate_tex=true +outdir=manual +source_extra= +split=node +srcfile= +texarg="-t @finalout" + +version="gendocs.sh $scriptversion + +Copyright 2021 Free Software Foundation, Inc. +There is NO warranty. You may redistribute this software +under the terms of the GNU General Public License. +For more information about these matters, see the files named COPYING." + +usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE + +Generate output in various formats from PACKAGE.texinfo (or .texi or +.txi) source. See the GNU Maintainers document for a more extensive +discussion: + https://www.gnu.org/prep/maintain_toc.html + +Options: + --email ADR use ADR as contact in generated web pages; always give this. + + -s SRCFILE read Texinfo from SRCFILE, instead of PACKAGE.{texinfo|texi|txi} + -o OUTDIR write files into OUTDIR, instead of manual/. + -I DIR append DIR to the Texinfo search path. + --common ARG pass ARG in all invocations. + --html ARG pass ARG to makeinfo or texi2html for HTML targets, + instead of '$htmlarg'. + --info ARG pass ARG to makeinfo for Info, instead of --no-split. + --no-ascii skip generating the plain text output. + --no-html skip generating the html output. + --no-info skip generating the info output. + --no-tex skip generating the dvi and pdf output. + --source ARG include ARG in tar archive of sources. + --split HOW make split HTML by node, section, chapter; default node. + --tex ARG pass ARG to texi2dvi for DVI and PDF, instead of -t @finalout. + + --texi2html use texi2html to make HTML target, with all split versions. + --docbook convert through DocBook too (xml, txt, html, pdf). + + --help display this help and exit successfully. + --version display version information and exit successfully. + +Simple example: $prog --email bug-gnu-emacs@gnu.org emacs \"GNU Emacs Manual\" + +Typical sequence: + cd PACKAGESOURCE/doc + wget \"$scripturl\" + wget \"$templateurl\" + $prog --email BUGLIST MANUAL \"GNU MANUAL - One-line description\" + +Output will be in a new subdirectory \"manual\" (by default; +use -o OUTDIR to override). Move all the new files into your web CVS +tree, as explained in the Web Pages node of maintain.texi. + +Please use the --email ADDRESS option so your own bug-reporting +address will be used in the generated HTML pages. + +MANUAL-TITLE is included as part of the HTML <title> of the overall +manual/index.html file. It should include the name of the package being +documented. manual/index.html is created by substitution from the file +$GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the +generic template for your own purposes.) + +If you have several manuals, you'll need to run this script several +times with different MANUAL values, specifying a different output +directory with -o each time. Then write (by hand) an overall index.html +with links to them all. + +If a manual's Texinfo sources are spread across several directories, +first copy or symlink all Texinfo sources into a single directory. +(Part of the script's work is to make a tar.gz of the sources.) + +As implied above, by default monolithic Info files are generated. +If you want split Info, or other Info options, use --info to override. + +You can set the environment variables MAKEINFO, TEXI2DVI, TEXI2HTML, +and PERL to control the programs that get executed, and +GENDOCS_TEMPLATE_DIR to control where the gendocs_template file is +looked for. With --docbook, the environment variables DOCBOOK2HTML, +DOCBOOK2PDF, and DOCBOOK2TXT are also consulted. + +By default, makeinfo and texi2dvi are run in the default (English) +locale, since that's the language of most Texinfo manuals. If you +happen to have a non-English manual and non-English web site, see the +SETLANG setting in the source. + +Email bug reports or enhancement requests to bug-gnulib@gnu.org. +" + +while test $# -gt 0; do + case $1 in + -s) shift; srcfile=$1;; + -o) shift; outdir=$1;; + -I) shift; dirargs="$dirargs -I '$1'"; dirs="$dirs $1";; + --common) shift; commonarg=$1;; + --docbook) docbook=yes;; + --email) shift; EMAIL=$1;; + --html) shift; default_htmlarg=false; htmlarg=$1;; + --info) shift; infoarg=$1;; + --no-ascii) generate_ascii=false;; + --no-html) generate_ascii=false;; + --no-info) generate_info=false;; + --no-tex) generate_tex=false;; + --source) shift; source_extra=$1;; + --split) shift; split=$1;; + --tex) shift; texarg=$1;; + --texi2html) use_texi2html=1;; + + --help) echo "$usage"; exit 0;; + --version) echo "$version"; exit 0;; + -*) + echo "$0: Unknown option \`$1'." >&2 + echo "$0: Try \`--help' for more information." >&2 + exit 1;; + *) + if test -z "$PACKAGE"; then + PACKAGE=$1 + elif test -z "$MANUAL_TITLE"; then + MANUAL_TITLE=$1 + else + echo "$0: extra non-option argument \`$1'." >&2 + exit 1 + fi;; + esac + shift +done + +# makeinfo uses the dirargs, but texi2dvi doesn't. +commonarg=" $dirargs $commonarg" + +# For most of the following, the base name is just $PACKAGE +base=$PACKAGE + +if $default_htmlarg && test -n "$use_texi2html"; then + # The legacy texi2html doesn't support TOP_NODE_UP_URL + htmlarg="--css-ref=/software/gnulib/manual.css" +fi + +if test -n "$srcfile"; then + # but here, we use the basename of $srcfile + base=`basename "$srcfile"` + case $base in + *.txi|*.texi|*.texinfo) base=`echo "$base"|sed 's/\.[texinfo]*$//'`;; + esac + PACKAGE=$base +elif test -s "$srcdir/$PACKAGE.texinfo"; then + srcfile=$srcdir/$PACKAGE.texinfo +elif test -s "$srcdir/$PACKAGE.texi"; then + srcfile=$srcdir/$PACKAGE.texi +elif test -s "$srcdir/$PACKAGE.txi"; then + srcfile=$srcdir/$PACKAGE.txi +else + echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2 + exit 1 +fi + +if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then + echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2 + echo "$0: it is available from $templateurl." >&2 + exit 1 +fi + +# Function to return size of $1 in something resembling kilobytes. +calcsize() +{ + size=`ls -ksl $1 | awk '{print $1}'` + echo $size +} + +# copy_images OUTDIR HTML-FILE... +# ------------------------------- +# Copy all the images needed by the HTML-FILEs into OUTDIR. +# Look for them in . and the -I directories; this is simpler than what +# makeinfo supports with -I, but hopefully it will suffice. +copy_images() +{ + local odir + odir=$1 + shift + $PERL -n -e " +BEGIN { + \$me = '$prog'; + \$odir = '$odir'; + @dirs = qw(. $dirs); +} +" -e ' +/<img src="(.*?)"/g && ++$need{$1}; + +END { + #print "$me: @{[keys %need]}\n"; # for debugging, show images found. + FILE: for my $f (keys %need) { + for my $d (@dirs) { + if (-f "$d/$f") { + use File::Basename; + my $dest = dirname ("$odir/$f"); + # + use File::Path; + -d $dest || mkpath ($dest) + || die "$me: cannot mkdir $dest: $!\n"; + # + use File::Copy; + copy ("$d/$f", $dest) + || die "$me: cannot copy $d/$f to $dest: $!\n"; + next FILE; + } + } + die "$me: $ARGV: cannot find image $f\n"; + } +} +' -- "$@" || exit 1 +} + +case $outdir in + /*) abs_outdir=$outdir;; + *) abs_outdir=$srcdir/$outdir;; +esac + +echo "Making output for $srcfile" +echo " in `pwd`" +mkdir -p "$outdir/" + +# +if $generate_info; then + cmd="$SETLANG $MAKEINFO -o $PACKAGE.info $commonarg $infoarg \"$srcfile\"" + echo "Generating info... ($cmd)" + rm -f $PACKAGE.info* # get rid of any strays + eval "$cmd" + tar czf "$outdir/$PACKAGE.info.tar.gz" $PACKAGE.info* + ls -l "$outdir/$PACKAGE.info.tar.gz" + info_tgz_size=`calcsize "$outdir/$PACKAGE.info.tar.gz"` + # do not mv the info files, there's no point in having them available + # separately on the web. +fi # end info + +# +if $generate_tex; then + cmd="$SETLANG $TEXI2DVI $dirargs $texarg \"$srcfile\"" + printf "\nGenerating dvi... ($cmd)\n" + eval "$cmd" + # compress/finish dvi: + gzip -f -9 $PACKAGE.dvi + dvi_gz_size=`calcsize $PACKAGE.dvi.gz` + mv $PACKAGE.dvi.gz "$outdir/" + ls -l "$outdir/$PACKAGE.dvi.gz" + + cmd="$SETLANG $TEXI2DVI --pdf $dirargs $texarg \"$srcfile\"" + printf "\nGenerating pdf... ($cmd)\n" + eval "$cmd" + pdf_size=`calcsize $PACKAGE.pdf` + mv $PACKAGE.pdf "$outdir/" + ls -l "$outdir/$PACKAGE.pdf" +fi # end tex (dvi + pdf) + +# +if $generate_ascii; then + opt="-o $PACKAGE.txt --no-split --no-headers $commonarg" + cmd="$SETLANG $MAKEINFO $opt \"$srcfile\"" + printf "\nGenerating ascii... ($cmd)\n" + eval "$cmd" + ascii_size=`calcsize $PACKAGE.txt` + gzip -f -9 -c $PACKAGE.txt >"$outdir/$PACKAGE.txt.gz" + ascii_gz_size=`calcsize "$outdir/$PACKAGE.txt.gz"` + mv $PACKAGE.txt "$outdir/" + ls -l "$outdir/$PACKAGE.txt" "$outdir/$PACKAGE.txt.gz" +fi + +# + +if $generate_html; then +# Split HTML at level $1. Used for texi2html. +html_split() +{ + opt="--split=$1 --node-files $commonarg $htmlarg" + cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $opt \"$srcfile\"" + printf "\nGenerating html by $1... ($cmd)\n" + eval "$cmd" + split_html_dir=$PACKAGE.html + ( + cd ${split_html_dir} || exit 1 + ln -sf ${PACKAGE}.html index.html + tar -czf "$abs_outdir/${PACKAGE}.html_$1.tar.gz" -- *.html + ) + eval html_$1_tgz_size=`calcsize "$outdir/${PACKAGE}.html_$1.tar.gz"` + rm -f "$outdir"/html_$1/*.html + mkdir -p "$outdir/html_$1/" + mv ${split_html_dir}/*.html "$outdir/html_$1/" + rmdir ${split_html_dir} +} + +if test -z "$use_texi2html"; then + opt="--no-split --html -o $PACKAGE.html $commonarg $htmlarg" + cmd="$SETLANG $MAKEINFO $opt \"$srcfile\"" + printf "\nGenerating monolithic html... ($cmd)\n" + rm -rf $PACKAGE.html # in case a directory is left over + eval "$cmd" + html_mono_size=`calcsize $PACKAGE.html` + gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz" + html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"` + copy_images "$outdir/" $PACKAGE.html + mv $PACKAGE.html "$outdir/" + ls -l "$outdir/$PACKAGE.html" "$outdir/$PACKAGE.html.gz" + + # Before Texinfo 5.0, makeinfo did not accept a --split=HOW option, + # it just always split by node. So if we're splitting by node anyway, + # leave it out. + if test "x$split" = xnode; then + split_arg= + else + split_arg=--split=$split + fi + # + opt="--html -o $PACKAGE.html $split_arg $commonarg $htmlarg" + cmd="$SETLANG $MAKEINFO $opt \"$srcfile\"" + printf "\nGenerating html by $split... ($cmd)\n" + eval "$cmd" + split_html_dir=$PACKAGE.html + copy_images $split_html_dir/ $split_html_dir/*.html + ( + cd $split_html_dir || exit 1 + tar -czf "$abs_outdir/$PACKAGE.html_$split.tar.gz" -- * + ) + eval \ + html_${split}_tgz_size=`calcsize "$outdir/$PACKAGE.html_$split.tar.gz"` + rm -rf "$outdir/html_$split/" + mv $split_html_dir "$outdir/html_$split/" + du -s "$outdir/html_$split/" + ls -l "$outdir/$PACKAGE.html_$split.tar.gz" + +else # use texi2html: + opt="--output $PACKAGE.html $commonarg $htmlarg" + cmd="$SETLANG $TEXI2HTML $opt \"$srcfile\"" + printf "\nGenerating monolithic html with texi2html... ($cmd)\n" + rm -rf $PACKAGE.html # in case a directory is left over + eval "$cmd" + html_mono_size=`calcsize $PACKAGE.html` + gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz" + html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"` + mv $PACKAGE.html "$outdir/" + + html_split node + html_split chapter + html_split section +fi +fi # end html + +# +printf "\nMaking .tar.gz for sources...\n" +d=`dirname $srcfile` +( + cd "$d" + srcfiles=`ls -d *.texinfo *.texi *.txi *.eps $source_extra 2>/dev/null` || true + tar czfh "$abs_outdir/$PACKAGE.texi.tar.gz" $srcfiles + ls -l "$abs_outdir/$PACKAGE.texi.tar.gz" +) +texi_tgz_size=`calcsize "$outdir/$PACKAGE.texi.tar.gz"` + +# +# Do everything again through docbook. +if test -n "$docbook"; then + opt="-o - --docbook $commonarg" + cmd="$SETLANG $MAKEINFO $opt \"$srcfile\" >${srcdir}/$PACKAGE-db.xml" + printf "\nGenerating docbook XML... ($cmd)\n" + eval "$cmd" + docbook_xml_size=`calcsize $PACKAGE-db.xml` + gzip -f -9 -c $PACKAGE-db.xml >"$outdir/$PACKAGE-db.xml.gz" + docbook_xml_gz_size=`calcsize "$outdir/$PACKAGE-db.xml.gz"` + mv $PACKAGE-db.xml "$outdir/" + + split_html_db_dir=html_node_db + opt="$commonarg -o $split_html_db_dir" + cmd="$DOCBOOK2HTML $opt \"${outdir}/$PACKAGE-db.xml\"" + printf "\nGenerating docbook HTML... ($cmd)\n" + eval "$cmd" + ( + cd ${split_html_db_dir} || exit 1 + tar -czf "$abs_outdir/${PACKAGE}.html_node_db.tar.gz" -- *.html + ) + html_node_db_tgz_size=`calcsize "$outdir/${PACKAGE}.html_node_db.tar.gz"` + rm -f "$outdir"/html_node_db/*.html + mkdir -p "$outdir/html_node_db" + mv ${split_html_db_dir}/*.html "$outdir/html_node_db/" + rmdir ${split_html_db_dir} + + cmd="$DOCBOOK2TXT \"${outdir}/$PACKAGE-db.xml\"" + printf "\nGenerating docbook ASCII... ($cmd)\n" + eval "$cmd" + docbook_ascii_size=`calcsize $PACKAGE-db.txt` + mv $PACKAGE-db.txt "$outdir/" + + cmd="$DOCBOOK2PDF \"${outdir}/$PACKAGE-db.xml\"" + printf "\nGenerating docbook PDF... ($cmd)\n" + eval "$cmd" + docbook_pdf_size=`calcsize $PACKAGE-db.pdf` + mv $PACKAGE-db.pdf "$outdir/" +fi + +# +printf "\nMaking index.html for $PACKAGE...\n" +if test -z "$use_texi2html"; then + CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\ + /%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d" +else + # should take account of --split here. + CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d" +fi + +curdate=`$SETLANG date '+%B %d, %Y'` +sed \ + -e "s!%%TITLE%%!$MANUAL_TITLE!g" \ + -e "s!%%EMAIL%%!$EMAIL!g" \ + -e "s!%%PACKAGE%%!$PACKAGE!g" \ + -e "s!%%DATE%%!$curdate!g" \ + -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \ + -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \ + -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \ + -e "s!%%HTML_SECTION_TGZ_SIZE%%!$html_section_tgz_size!g" \ + -e "s!%%HTML_CHAPTER_TGZ_SIZE%%!$html_chapter_tgz_size!g" \ + -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \ + -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \ + -e "s!%%PDF_SIZE%%!$pdf_size!g" \ + -e "s!%%ASCII_SIZE%%!$ascii_size!g" \ + -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \ + -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \ + -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \ + -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \ + -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \ + -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \ + -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \ + -e "s,%%SCRIPTURL%%,$scripturl,g" \ + -e "s!%%SCRIPTNAME%%!$prog!g" \ + -e "$CONDS" \ +$GENDOCS_TEMPLATE_DIR/gendocs_template >"$outdir/index.html" + +echo "Done, see $outdir/ subdirectory for new files." + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-end: "$" +# End: diff --git a/doc/it/gendocs_template b/doc/it/gendocs_template new file mode 100755 index 00000000..cd9ac383 --- /dev/null +++ b/doc/it/gendocs_template @@ -0,0 +1,101 @@ +<!--#include virtual="/server/header.html" --> +<!-- Parent-Version: 1.78 --> + +<!-- +Copyright (C) 2006-2021 Free Software Foundation, Inc. + +Copying and distribution of this file, with or without modification, +are permitted in any medium without royalty provided the copyright +notice and this notice are preserved. This file is offered as-is, +without any warranty. +--> + +<title>%%TITLE%% - GNU Project - Free Software Foundation</title> +<!--#include virtual="/server/banner.html" --> +<h2>%%TITLE%%</h2> + +<address>Free Software Foundation</address> +<address>last updated %%DATE%%</address> + +<p>This manual (%%PACKAGE%%) is available in the following formats:</p> + +<ul> +<li><a href="%%PACKAGE%%.html">HTML + (%%HTML_MONO_SIZE%%K bytes)</a> - entirely on one web page.</li> +<li><a href="html_node/index.html">HTML</a> - with one web page per + node.</li> +%%IF HTML_SECTION%% +<li><a href="html_section/index.html">HTML</a> - with one web page per + section.</li> +%%ENDIF HTML_SECTION%% +%%IF HTML_CHAPTER%% +<li><a href="html_chapter/index.html">HTML</a> - with one web page per + chapter.</li> +%%ENDIF HTML_CHAPTER%% +<li><a href="%%PACKAGE%%.html.gz">HTML compressed + (%%HTML_MONO_GZ_SIZE%%K gzipped characters)</a> - entirely on + one web page.</li> +<li><a href="%%PACKAGE%%.html_node.tar.gz">HTML compressed + (%%HTML_NODE_TGZ_SIZE%%K gzipped tar file)</a> - + with one web page per node.</li> +%%IF HTML_SECTION%% +<li><a href="%%PACKAGE%%.html_section.tar.gz">HTML compressed + (%%HTML_SECTION_TGZ_SIZE%%K gzipped tar file)</a> - + with one web page per section.</li> +%%ENDIF HTML_SECTION%% +%%IF HTML_CHAPTER%% +<li><a href="%%PACKAGE%%.html_chapter.tar.gz">HTML compressed + (%%HTML_CHAPTER_TGZ_SIZE%%K gzipped tar file)</a> - + with one web page per chapter.</li> +%%ENDIF HTML_CHAPTER%% +<li><a href="%%PACKAGE%%.info.tar.gz">Info document + (%%INFO_TGZ_SIZE%%K bytes gzipped tar file)</a>.</li> +<li><a href="%%PACKAGE%%.txt">ASCII text + (%%ASCII_SIZE%%K bytes)</a>.</li> +<li><a href="%%PACKAGE%%.txt.gz">ASCII text compressed + (%%ASCII_GZ_SIZE%%K bytes gzipped)</a>.</li> +<li><a href="%%PACKAGE%%.dvi.gz">TeX dvi file + (%%DVI_GZ_SIZE%%K bytes gzipped)</a>.</li> +<li><a href="%%PACKAGE%%.pdf">PDF file + (%%PDF_SIZE%%K bytes)</a>.</li> +<li><a href="%%PACKAGE%%.texi.tar.gz">Texinfo source + (%%TEXI_TGZ_SIZE%%K bytes gzipped tar file).</a></li> +</ul> + +<p>You can <a href="https://shop.fsf.org/">buy printed copies of +some manuals</a> (among other items) from the Free Software Foundation; +this helps support FSF activities.</p> + +<p>(This page generated by the <a href="%%SCRIPTURL%%">%%SCRIPTNAME%% +script</a>.)</p> + +<!-- If needed, change the copyright block at the bottom. In general, + all pages on the GNU web server should have the section about + verbatim copying. Please do NOT remove this without talking + with the webmasters first. + Please make sure the copyright date is consistent with the document + and that it is like this: "2001, 2002", not this: "2001-2002". --> +</div><!-- for id="content", starts in the include above --> +<!--#include virtual="/server/footer.html" --> +<div id="footer"> +<div class="unprintable"> + +<p>Please send general FSF & GNU inquiries to +<a href="mailto:gnu@gnu.org"><gnu@gnu.org></a>. +There are also <a href="/contact/">other ways to contact</a> +the FSF. Broken links and other corrections or suggestions can be sent +to <a href="mailto:%%EMAIL%%"><%%EMAIL%%></a>.</p> +</div> + +<p>Copyright © 2020 Free Software Foundation, Inc.</p> + +<p>This page is licensed under a <a rel="license" +href="https://creativecommons.org/licenses/by-nd/3.0/us/">Creative +Commons Attribution-NoDerivs 3.0 United States License</a>.</p> + +<!--#include virtual="/server/bottom-notes.html" --> + +</div> +</div> +</body> +</html> diff --git a/doc/it/genera_formati.sh b/doc/it/genera_formati.sh new file mode 100755 index 00000000..66540f2e --- /dev/null +++ b/doc/it/genera_formati.sh @@ -0,0 +1,13 @@ +: +# questo script, eseguito in questa directory +# genera tutti i formati della documentazione gawk +# che si possono ricavare a partire +# da gawktexi.in, nella directory ./manual +# +# dapprima si prepara il file di input (gawk.texi) +# +awk -f sidebar.awk < gawktexi.in > gawk.texi +# +# poi si invoca lo script che genera i vari formati +# +./gendocs.sh gawk gawk diff --git a/doc/it/texinfo.tex b/doc/it/texinfo.tex index 68153132..b59c81cf 100644..100755 --- a/doc/it/texinfo.tex +++ b/doc/it/texinfo.tex @@ -3,9 +3,9 @@ % Load plain if necessary, i.e., if running under initex. \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi % -\def\texinfoversion{2020-10-24.12} +\def\texinfoversion{2021-02-20.11} % -% Copyright 1985, 1986, 1988, 1990-2020 Free Software Foundation, Inc. +% Copyright 1985, 1986, 1988, 1990-2021 Free Software Foundation, Inc. % % This texinfo.tex file is free software: you can redistribute it and/or % modify it under the terms of the GNU General Public License as @@ -248,7 +248,7 @@ \def\bigbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\bigskipamount \removelastskip\penalty-200\bigskip\fi\fi} -% Output routine +% Output routine % % For a final copy, take out the rectangles @@ -588,10 +588,9 @@ \fi } -% @end foo executes the definition of \Efoo. -% But first, it executes a specialized version of \checkenv -% -\parseargdef\end{% + +% @end foo calls \checkenv and executes the definition of \Efoo. +\parseargdef\end{ \if 1\csname iscond.#1\endcsname \else % The general wording of \badenverr may not be ideal. @@ -2689,8 +2688,6 @@ end \definetextfontsizexi -\message{markup,} - % Check if we are currently using a typewriter font. Since all the % Computer Modern typewriter fonts have zero interword stretch (and % shrink), and it is reasonable to expect all typewriter fonts to have @@ -2698,68 +2695,14 @@ end % \def\ifmonospace{\ifdim\fontdimen3\font=0pt } -% Markup style infrastructure. \defmarkupstylesetup\INITMACRO will -% define and register \INITMACRO to be called on markup style changes. -% \INITMACRO can check \currentmarkupstyle for the innermost -% style. - -\let\currentmarkupstyle\empty - -\def\setupmarkupstyle#1{% - \def\currentmarkupstyle{#1}% - \markupstylesetup -} - -\let\markupstylesetup\empty - -\def\defmarkupstylesetup#1{% - \expandafter\def\expandafter\markupstylesetup - \expandafter{\markupstylesetup #1}% - \def#1% -} - -% Markup style setup for left and right quotes. -\defmarkupstylesetup\markupsetuplq{% - \expandafter\let\expandafter \temp - \csname markupsetuplq\currentmarkupstyle\endcsname - \ifx\temp\relax \markupsetuplqdefault \else \temp \fi -} - -\defmarkupstylesetup\markupsetuprq{% - \expandafter\let\expandafter \temp - \csname markupsetuprq\currentmarkupstyle\endcsname - \ifx\temp\relax \markupsetuprqdefault \else \temp \fi -} - { \catcode`\'=\active \catcode`\`=\active -\gdef\markupsetuplqdefault{\let`\lq} -\gdef\markupsetuprqdefault{\let'\rq} - -\gdef\markupsetcodequoteleft{\let`\codequoteleft} -\gdef\markupsetcodequoteright{\let'\codequoteright} +\gdef\setcodequotes{\let`\codequoteleft \let'\codequoteright} +\gdef\setregularquotes{\let`\lq \let'\rq} } -\let\markupsetuplqcode \markupsetcodequoteleft -\let\markupsetuprqcode \markupsetcodequoteright -% -\let\markupsetuplqexample \markupsetcodequoteleft -\let\markupsetuprqexample \markupsetcodequoteright -% -\let\markupsetuplqkbd \markupsetcodequoteleft -\let\markupsetuprqkbd \markupsetcodequoteright -% -\let\markupsetuplqsamp \markupsetcodequoteleft -\let\markupsetuprqsamp \markupsetcodequoteright -% -\let\markupsetuplqverb \markupsetcodequoteleft -\let\markupsetuprqverb \markupsetcodequoteright -% -\let\markupsetuplqverbatim \markupsetcodequoteleft -\let\markupsetuprqverbatim \markupsetcodequoteright - % Allow an option to not use regular directed right quote/apostrophe % (char 0x27), but instead the undirected quote from cmtt (char 0x0d). % The undirected quote is ugly, so don't make it the default, but it @@ -2922,7 +2865,7 @@ end } % @samp. -\def\samp#1{{\setupmarkupstyle{samp}\lq\tclose{#1}\rq\null}} +\def\samp#1{{\setcodequotes\lq\tclose{#1}\rq\null}} % @indicateurl is \samp, that is, with quotes. \let\indicateurl=\samp @@ -2965,8 +2908,7 @@ end \global\let'=\rq \global\let`=\lq % default definitions % \global\def\code{\begingroup - \setupmarkupstyle{code}% - % The following should really be moved into \setupmarkupstyle handlers. + \setcodequotes \catcode\dashChar=\active \catcode\underChar=\active \ifallowcodebreaks \let-\codedash @@ -3120,7 +3062,7 @@ end \urefcatcodes % \global\def\urefcode{\begingroup - \setupmarkupstyle{code}% + \setcodequotes \urefcatcodes \let&\urefcodeamp \let.\urefcodedot @@ -3241,8 +3183,8 @@ end \def\kbdsub#1#2#3\par{% \def\one{#1}\def\three{#3}\def\threex{??}% \ifx\one\xkey\ifx\threex\three \key{#2}% - \else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi - \else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi + \else{\tclose{\kbdfont\setcodequotes\look}}\fi + \else{\tclose{\kbdfont\setcodequotes\look}}\fi } % definition of @key that produces a lozenge. Doesn't adjust to text size. @@ -3259,7 +3201,7 @@ end % monospace, don't change it; that way, we respect @kbdinputstyle. But % if it isn't monospace, then use \tt. % -\def\key#1{{\setupmarkupstyle{key}% +\def\key#1{{\setregularquotes \nohyphenation \ifmonospace\else\tt\fi #1}\null} @@ -3389,16 +3331,20 @@ end {\obeylines \globaldefs=1 \envdef\displaymath{% -\tex +\tex% \def\thisenv{\displaymath}% +\begingroup\let\end\displaymathend% $$% } -\def\Edisplaymath{$$ +\def\displaymathend{$$\endgroup\end}% + +\def\Edisplaymath{% \def\thisenv{\tex}% \end tex }} + % @inlinefmt{FMTNAME,PROCESSED-TEXT} and @inlineraw{FMTNAME,RAW-TEXT}. % Ignore unless FMTNAME == tex; then it is like @iftex and @tex, % except specified as a normal braced arg, so no newlines to worry about. @@ -7163,7 +7109,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% % But \@ or @@ will get a plain @ character. \envdef\tex{% - \setupmarkupstyle{tex}% + \setregularquotes \catcode `\\=0 \catcode `\{=1 \catcode `\}=2 \catcode `\$=3 \catcode `\&=4 \catcode `\#=6 \catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie @@ -7389,7 +7335,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% % If you want all examples etc. small: @set dispenvsize small. % If you want even small examples the full size: @set dispenvsize nosmall. % This affects the following displayed environments: -% @example, @display, @format, @lisp +% @example, @display, @format, @lisp, @verbatim % \def\smallword{small} \def\nosmallword{nosmall} @@ -7435,9 +7381,9 @@ might help (with 'rm \jobname.?? \jobname.??s')% % \maketwodispenvdef{lisp}{example}{% \nonfillstart - \tt\setupmarkupstyle{example}% + \tt\setcodequotes \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special. - \gobble % eat return + \parsearg\gobble } % @display/@smalldisplay: same as @lisp except keep current font. % @@ -7595,7 +7541,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \def\setupverb{% \tt % easiest (and conventionally used) font for verbatim \def\par{\leavevmode\endgraf}% - \setupmarkupstyle{verb}% + \setcodequotes \tabeightspaces % Respect line breaks, % print special symbols as themselves, and @@ -7636,7 +7582,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \tt % easiest (and conventionally used) font for verbatim \def\par{\egroup\leavevmode\box\verbbox\endgraf\starttabbox}% \tabexpand - \setupmarkupstyle{verbatim}% + \setcodequotes % Respect line breaks, % print special symbols as themselves, and % make each space count. @@ -8055,7 +8001,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% % leave the code in, but it's strange for @var to lead to typewriter. % Nowadays we recommend @code, since the difference between a ttsl hyphen % and a tt hyphen is pretty tiny. @code also disables ?` !`. - \def\var##1{{\setupmarkupstyle{var}\ttslanted{##1}}}% + \def\var##1{{\setregularquotes\ttslanted{##1}}}% #1% \sl\hyphenchar\font=45 } @@ -8164,11 +8110,18 @@ might help (with 'rm \jobname.?? \jobname.??s')% } \fi +\let\E=\expandafter + % Used at the time of macro expansion. % Argument is macro body with arguments substituted \def\scanmacro#1{% \newlinechar`\^^M - \def\xeatspaces{\eatspaces}% + % expand the expansion of \eatleadingcr twice to maybe remove a leading + % newline (and \else and \fi tokens), then call \eatspaces on the result. + \def\xeatspaces##1{% + \E\E\E\E\E\E\E\eatspaces\E\E\E\E\E\E\E{\eatleadingcr##1% + }}% + \def\xempty##1{}% % % Process the macro body under the current catcode regime. \scantokens{#1@comment}% @@ -8221,6 +8174,11 @@ might help (with 'rm \jobname.?? \jobname.??s')% \unbrace{\gdef\trim@@@ #1 } #2@{#1} } +{\catcode`\^^M=\other% +\gdef\eatleadingcr#1{\if\noexpand#1\noexpand^^M\else\E#1\fi}}% +% Warning: this won't work for a delimited argument +% or for an empty argument + % Trim a single trailing ^^M off a string. {\catcode`\^^M=\other \catcode`\Q=3% \gdef\eatcr #1{\eatcra #1Q^^MQ}% @@ -8387,6 +8345,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \let\hash\relax % \hash is redefined to `#' later to get it into definitions \let\xeatspaces\relax + \let\xempty\relax \parsemargdefxxx#1,;,% \ifnum\paramno<10\relax\else \paramno0\relax @@ -8398,9 +8357,11 @@ might help (with 'rm \jobname.?? \jobname.??s')% \else \let\next=\parsemargdefxxx \advance\paramno by 1 \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname - {\xeatspaces{\hash\the\paramno}}% + {\xeatspaces{\hash\the\paramno\noexpand\xempty{}}}% \edef\paramlist{\paramlist\hash\the\paramno,}% \fi\next} +% the \xempty{} is to give \eatleadingcr an argument in the case of an +% empty macro argument. % \parsemacbody, \parsermacbody % @@ -8989,7 +8950,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \else \ifhavexrefs % We (should) know the real title if we have the xref values. - \def\printedrefname{\refx{#1-title}{}}% + \def\printedrefname{\refx{#1-title}}% \else % Otherwise just copy the Info node name. \def\printedrefname{\ignorespaces #1}% @@ -9083,7 +9044,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% % If the user specified the print name (third arg) to the ref, % print it instead of our usual "Figure 1.2". \ifdim\wd\printedrefnamebox = 0pt - \refx{#1-snt}{}% + \refx{#1-snt}% \else \printedrefname \fi @@ -9118,28 +9079,30 @@ might help (with 'rm \jobname.?? \jobname.??s')% \else % Reference within this manual. % - % Only output a following space if the -snt ref is nonempty; for - % @unnumbered and @anchor, it won't be. - \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}% + % Only output a following space if the -snt ref is nonempty, as the ref + % will be empty for @unnumbered and @anchor. + \setbox2 = \hbox{\ignorespaces \refx{#1-snt}}% \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi % % output the `[mynode]' via the macro below so it can be overridden. \xrefprintnodename\printedrefname % - % But we always want a comma and a space: - ,\space - % - % output the `page 3'. - \turnoffactive \putwordpage\tie\refx{#1-pg}{}% - % Add a , if xref followed by a space - \if\space\noexpand\tokenafterxref ,% - \else\ifx\ \tokenafterxref ,% @TAB - \else\ifx\*\tokenafterxref ,% @* - \else\ifx\ \tokenafterxref ,% @SPACE - \else\ifx\ - \tokenafterxref ,% @NL - \else\ifx\tie\tokenafterxref ,% @tie - \fi\fi\fi\fi\fi\fi + \expandafter\ifx\csname SETtxiomitxrefpg\endcsname\relax + % But we always want a comma and a space: + ,\space + % + % output the `page 3'. + \turnoffactive \putwordpage\tie\refx{#1-pg}% + % Add a , if xref followed by a space + \if\space\noexpand\tokenafterxref ,% + \else\ifx\ \tokenafterxref ,% @TAB + \else\ifx\*\tokenafterxref ,% @* + \else\ifx\ \tokenafterxref ,% @SPACE + \else\ifx\ + \tokenafterxref ,% @NL + \else\ifx\tie\tokenafterxref ,% @tie + \fi\fi\fi\fi\fi\fi + \fi \fi\fi \fi \endlink @@ -9206,9 +9169,8 @@ might help (with 'rm \jobname.?? \jobname.??s')% \fi\fi\fi } -% \refx{NAME}{SUFFIX} - reference a cross-reference string named NAME. SUFFIX -% is output afterwards if non-empty. -\def\refx#1#2{% +% \refx{NAME} - reference a cross-reference string named NAME. +\def\refx#1{% \requireauxfile {% \indexnofonts @@ -9235,7 +9197,6 @@ might help (with 'rm \jobname.?? \jobname.??s')% % It's defined, so just use it. \thisrefX \fi - #2% Output the suffix in any case. } % This is the macro invoked by entries in the aux file. Define a control @@ -9345,10 +9306,10 @@ might help (with 'rm \jobname.?? \jobname.??s')% \catcode`\[=\other \catcode`\]=\other \catcode`\"=\other - \catcode`\_=\other - \catcode`\|=\other - \catcode`\<=\other - \catcode`\>=\other + \catcode`\_=\active + \catcode`\|=\active + \catcode`\<=\active + \catcode`\>=\active \catcode`\$=\other \catcode`\#=\other \catcode`\&=\other @@ -9569,7 +9530,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \def\imagexxx#1,#2,#3,#4,#5,#6\finish{\begingroup \catcode`\^^M = 5 % in case we're inside an example \normalturnoffactive % allow _ et al. in names - \def\xprocessmacroarg{\eatspaces}% in case we are being used via a macro + \makevalueexpandable % If the image is by itself, center it. \ifvmode \imagevmodetrue @@ -11622,7 +11583,7 @@ directory should work if nowhere else does.} \let> = \activegtr \let~ = \activetilde \let^ = \activehat - \markupsetuplqdefault \markupsetuprqdefault + \setregularquotes \let\b = \strong \let\i = \smartitalic % in principle, all other definitions in \tex have to be undone too. @@ -11681,8 +11642,7 @@ directory should work if nowhere else does.} @let|=@normalverticalbar @let~=@normaltilde @let\=@ttbackslash - @markupsetuplqdefault - @markupsetuprqdefault + @setregularquotes @unsepspaces } } @@ -11775,8 +11735,7 @@ directory should work if nowhere else does.} @c Do this last of all since we use ` in the previous @catcode assignments. @catcode`@'=@active @catcode`@`=@active -@markupsetuplqdefault -@markupsetuprqdefault +@setregularquotes @c Local variables: @c eval: (add-hook 'before-save-hook 'time-stamp) diff --git a/doc/wordlist b/doc/wordlist index 95ca8a75..be7655ec 100644 --- a/doc/wordlist +++ b/doc/wordlist @@ -321,6 +321,7 @@ NR NT NUMCUR NaN +NaNs Nachum Neacsu Neacsu's @@ -25,10 +25,8 @@ */ #include "awk.h" +#include <math.h> -extern double pow(double x, double y); -extern double modf(double x, double *yp); -extern double fmod(double x, double y); NODE **fcall_list = NULL; long fcall_count = 0; int currule = 0; @@ -1521,18 +1519,17 @@ eval_condition(NODE *t) return boolval(t); } -typedef enum { - SCALAR_EQ_NEQ, - SCALAR_RELATIONAL -} scalar_cmp_t; +static bool cmp_doubles(const NODE *t1, const NODE *t2, scalar_cmp_t comparison_type); +extern bool mpg_cmp_as_numbers(const NODE *t1, const NODE *t2, scalar_cmp_t comparison_type); /* cmp_scalars -- compare two nodes on the stack */ -static inline int +static bool cmp_scalars(scalar_cmp_t comparison_type) { NODE *t1, *t2; int di; + bool ret; t2 = POP_SCALAR(); t1 = TOP(); @@ -1540,12 +1537,91 @@ cmp_scalars(scalar_cmp_t comparison_type) DEREF(t2); fatal(_("attempt to use array `%s' in a scalar context"), array_vname(t1)); } - di = cmp_nodes(t1, t2, comparison_type == SCALAR_EQ_NEQ); + + if ((t1->flags & STRING) != 0 || (t2->flags & STRING) != 0) { + bool use_strcmp = (comparison_type == SCALAR_EQ || comparison_type == SCALAR_NEQ); + di = cmp_nodes(t1, t2, use_strcmp); + + switch (comparison_type) { + case SCALAR_EQ: + ret = (di == 0); + break; + case SCALAR_NEQ: + ret = (di != 0); + break; + case SCALAR_LT: + ret = (di < 0); + break; + case SCALAR_LE: + ret = (di <= 0); + break; + case SCALAR_GT: + ret = (di > 0); + break; + case SCALAR_GE: + ret = (di >= 0); + break; + } + } else { + fixtype(t1); + fixtype(t2); + +#ifdef HAVE_MPFR + if (do_mpfr) + ret = mpg_cmp_as_numbers(t1, t2, comparison_type); + else +#endif + ret = cmp_doubles(t1, t2, comparison_type); + } + DEREF(t1); DEREF(t2); - return di; + return ret; } + +/* cmp_doubles --- compare two doubles */ + +static bool +cmp_doubles(const NODE *t1, const NODE *t2, scalar_cmp_t comparison_type) +{ + /* + * This routine provides numeric comparisons that should work + * the same as in C. It should NOT be used for sorting. + */ + + bool t1_nan = isnan(t1->numbr); + bool t2_nan = isnan(t2->numbr); + int ret; + + if ((t1_nan || t2_nan) && comparison_type != SCALAR_NEQ) + return false; + + switch (comparison_type) { + case SCALAR_EQ: + ret = (t1->numbr == t2->numbr); + break; + case SCALAR_NEQ: + ret = (t1->numbr != t2->numbr); + break; + case SCALAR_LT: + ret = (t1->numbr < t2->numbr); + break; + case SCALAR_LE: + ret = (t1->numbr <= t2->numbr); + break; + case SCALAR_GT: + ret = (t1->numbr > t2->numbr); + break; + case SCALAR_GE: + ret = (t1->numbr >= t2->numbr); + break; + } + + return ret; +} + + /* op_assign --- assignment operators excluding = */ static void diff --git a/interpret.h b/interpret.h index 2ed4f01a..3525951c 100644 --- a/interpret.h +++ b/interpret.h @@ -482,37 +482,37 @@ uninitialized_scalar: break; case Op_equal: - r = node_Boolean[cmp_scalars(SCALAR_EQ_NEQ) == 0]; + r = node_Boolean[cmp_scalars(SCALAR_EQ)]; UPREF(r); REPLACE(r); break; case Op_notequal: - r = node_Boolean[cmp_scalars(SCALAR_EQ_NEQ) != 0]; + r = node_Boolean[cmp_scalars(SCALAR_NEQ)]; UPREF(r); REPLACE(r); break; case Op_less: - r = node_Boolean[cmp_scalars(SCALAR_RELATIONAL) < 0]; + r = node_Boolean[cmp_scalars(SCALAR_LT)]; UPREF(r); REPLACE(r); break; case Op_greater: - r = node_Boolean[cmp_scalars(SCALAR_RELATIONAL) > 0]; + r = node_Boolean[cmp_scalars(SCALAR_GT)]; UPREF(r); REPLACE(r); break; case Op_leq: - r = node_Boolean[cmp_scalars(SCALAR_RELATIONAL) <= 0]; + r = node_Boolean[cmp_scalars(SCALAR_LE)]; UPREF(r); REPLACE(r); break; case Op_geq: - r = node_Boolean[cmp_scalars(SCALAR_RELATIONAL) >= 0]; + r = node_Boolean[cmp_scalars(SCALAR_GE)]; UPREF(r); REPLACE(r); break; @@ -476,6 +476,50 @@ mpg_cmp(const NODE *t1, const NODE *t2) return cmp_awknums(t1, t2); } +/* mpg_cmp_as_numbers --- compare two numbers, similar to doubles */ + +bool +mpg_cmp_as_numbers(const NODE *t1, const NODE *t2, scalar_cmp_t comparison_type) +{ + /* + * This routine provides numeric comparisons that should work + * the same as in C. It should NOT be used for sorting. + */ + + bool t1_nan = mpfr_nan_p(t1->mpg_numbr); + bool t2_nan = mpfr_nan_p(t2->mpg_numbr); + int ret; + + // MPFR is different than native doubles... + if (t1_nan || t2_nan) + return comparison_type == SCALAR_NEQ; + + int di = mpg_cmp(t1, t2); + + switch (comparison_type) { + case SCALAR_EQ: + ret = (di == 0); + break; + case SCALAR_NEQ: + ret = (di != 0); + break; + case SCALAR_LT: + ret = (di < 0); + break; + case SCALAR_LE: + ret = (di <= 0); + break; + case SCALAR_GT: + ret = (di > 0); + break; + case SCALAR_GE: + ret = (di >= 0); + break; + } + + return ret; +} + /* * mpg_update_var --- update NR or FNR. @@ -370,7 +370,7 @@ int cmp_awknums(const NODE *t1, const NODE *t2) { /* - * This routine is also used to sort numeric array indices or values. + * This routine is used to sort numeric array indices or values. * For the purposes of sorting, NaN is considered greater than * any other value, and all NaN values are considered equivalent and equal. * This isn't in compliance with IEEE standard, but compliance w.r.t. NaN @@ -390,7 +390,6 @@ cmp_awknums(const NODE *t1, const NODE *t2) return 1; } - /* make_str_node --- make a string node */ NODE * diff --git a/str_array.c b/str_array.c index 84bd2f02..215a52fd 100644 --- a/str_array.c +++ b/str_array.c @@ -94,6 +94,7 @@ static void grow_table(NODE *symbol); static unsigned long gst_hash_string(const char *str, size_t len, unsigned long hsize, size_t *code); static unsigned long scramble(unsigned long x); +static unsigned long fnv1a_hash_string(const char *str, size_t len, unsigned long hsize, size_t *code); static unsigned long awk_hash(const char *s, size_t len, unsigned long hsize, size_t *code); unsigned long (*hash)(const char *s, size_t len, unsigned long hsize, size_t *code) = awk_hash; @@ -111,8 +112,13 @@ str_array_init(NODE *symbol ATTRIBUTE_UNUSED, NODE *subs ATTRIBUTE_UNUSED) /* check relevant environment variables */ if ((newval = getenv_long("STR_CHAIN_MAX")) > 0) STR_CHAIN_MAX = newval; - if ((val = getenv("AWK_HASH")) != NULL && strcmp(val, "gst") == 0) - hash = gst_hash_string; + + if ((val = getenv("AWK_HASH")) != NULL) { + if (strcmp(val, "gst") == 0) + hash = gst_hash_string; + else if (strcmp(val, "fnv1a") == 0) + hash = fnv1a_hash_string; + } } else null_array(symbol); @@ -772,6 +778,34 @@ scramble(unsigned long x) return x; } +/* fnv1a_hash_string --- fnv1a hash function */ + +/* + * FNV-1a hash function + * http://www.isthe.com/chongo/tech/comp/fnv/index.html + */ + +static unsigned long +fnv1a_hash_string(const char *str, size_t len, unsigned long hsize, size_t *code) +{ + /* FNV-1a */ + register unsigned ret = 2166136261U; + + while (len > 0) { + ret ^= (unsigned char) (*str++); + ret *= 16777619U; + len-- ; + } + + if (code != NULL) + *code = ret; + + if (ret >= hsize) + ret %= hsize; + + return ret; +} + /* env_remove --- for ENVIRON, remove value from real environment */ static NODE ** |