diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2023-03-26 21:10:30 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2023-03-26 21:10:30 +0300 |
commit | 432c696182aa0bef176770903c7bdc2623d5e1e7 (patch) | |
tree | f783fd9b694dee6a58bdf638b4613c0e7f62d0c7 | |
parent | 29e74d75768f25cd6b0592d21c029436a57b18e7 (diff) | |
parent | c73b1c59e9b5da4874d95ca3484aa87891376ca3 (diff) | |
download | gawk-432c696182aa0bef176770903c7bdc2623d5e1e7.tar.gz |
Merge branch 'gawk-5.2-stable' into private/stable-int-max-fx
-rw-r--r-- | build-aux/ChangeLog | 4 | ||||
-rw-r--r-- | build-aux/texinfo.tex | 251 | ||||
-rw-r--r-- | doc/ChangeLog | 6 | ||||
-rw-r--r-- | doc/gawk.info | 695 | ||||
-rw-r--r-- | doc/gawk.texi | 55 | ||||
-rw-r--r-- | doc/gawktexi.in | 55 | ||||
-rw-r--r-- | doc/texinfo.tex | 251 | ||||
-rw-r--r-- | support/ChangeLog | 4 | ||||
-rw-r--r-- | support/dfa.c | 17 | ||||
-rw-r--r-- | support/verify.h | 18 |
10 files changed, 827 insertions, 529 deletions
diff --git a/build-aux/ChangeLog b/build-aux/ChangeLog index 3d2ebd28..3a8bca31 100644 --- a/build-aux/ChangeLog +++ b/build-aux/ChangeLog @@ -1,3 +1,7 @@ +2023-03-26 Arnold D. Robbins <arnold@skeeve.com> + + * texinfo.tex: Sync from GNULIB. + 2023-02-05 Arnold D. Robbins <arnold@skeeve.com> * ar-lib, compile, config.guess, config.rpath, config.sub, diff --git a/build-aux/texinfo.tex b/build-aux/texinfo.tex index 3cccf01d..204caf74 100644 --- a/build-aux/texinfo.tex +++ b/build-aux/texinfo.tex @@ -3,7 +3,7 @@ % Load plain if necessary, i.e., if running under initex. \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi % -\def\texinfoversion{2023-01-02.21} +\def\texinfoversion{2023-03-21.06} % % Copyright 1985, 1986, 1988, 1990-2023 Free Software Foundation, Inc. % @@ -2683,25 +2683,21 @@ end } \setregularquotes -% 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 -% works for pasting with more pdf viewers (at least evince), the -% lilypond developers report. xpdf does work with the regular 0x27. +% output for ' in @code +% in tt font hex 0D (undirected) or 27 (curly right quote) % \def\codequoteright{% \ifusingtt {\ifflagclear{txicodequoteundirected}% {\ifflagclear{codequoteundirected}% {'}% - {\char'15 }}% - {\char'15 }}% + {\char"0D }}% + {\char"0D }}% {'}% } -% and a similar option for the left quote char vs. a grave accent. -% Modern fonts display ASCII 0x60 as a grave accent, so some people like -% the code environments to do likewise. +% output for ` in @code +% in tt font hex 12 (grave accent) or 60 (curly left quote) % \relax disables Spanish ligatures ?` and !` of \tt font. % \def\codequoteleft{% @@ -2709,8 +2705,8 @@ end {\ifflagclear{txicodequotebacktick}% {\ifflagclear{codequotebacktick}% {\relax`}% - {\char'22 }}% - {\char'22 }}% + {\char"12 }}% + {\char"12 }}% {\relax`}% } @@ -2729,7 +2725,7 @@ end \errmessage{Unknown @codequoteundirected value `\temp', must be on|off}% \fi\fi } -% + \parseargdef\codequotebacktick{% \def\temp{#1}% \ifx\temp\onword @@ -2744,6 +2740,11 @@ end \fi\fi } +% Turn them on by default +\let\SETtxicodequoteundirected = t +\let\SETtxicodequotebacktick = t + + % [Knuth] pp. 380,381,391, disable Spanish ligatures ?` and !` of \tt font. \def\noligaturesquoteleft{\relax\lq} @@ -2929,10 +2930,6 @@ end \let-\dashnobreak \let_\realunder \fi - % Given -foo (with a single dash), we do not want to allow a break - % after the hyphen. - \global\let\codedashprev=\codedash - % \codex } % @@ -2942,21 +2939,30 @@ end % % Now, output a discretionary to allow a line break, unless % (a) the next character is a -, or - % (b) the preceding character is a -. + % (b) the preceding character is a -, or + % (c) we are at the start of the string. + % In both cases (b) and (c), \codedashnobreak should be set to \codedash. + % % E.g., given --posix, we do not want to allow a break after either -. % Given --foo-bar, we do want to allow a break between the - and the b. \ifx\next\codedash \else - \ifx\codedashprev\codedash + \ifx\codedashnobreak\codedash \else \discretionary{}{}{}\fi \fi % we need the space after the = for the case when \next itself is a % space token; it would get swallowed otherwise. As in @code{- a}. - \global\let\codedashprev= \next + \global\let\codedashnobreak= \next } } \def\normaldash{-} % -\def\codex #1{\tclose{#1}\endgroup} +\def\codex #1{\tclose{% + % Given -foo (with a single dash), we do not want to allow a break + % after the -. \codedashnobreak is set to the first character in + % @code. + \futurelet\codedashnobreak\relax + #1% +}\endgroup} \def\codeunder{% % this is all so @math{@code{var_name}+1} can work. In math mode, _ @@ -3950,33 +3956,23 @@ $$% \def\HEADINGSoff{{\globaldefs=1 \headingsoff}} % global setting -% When we turn headings on, set the page number to 1. +% Set the page number to 1. \def\pageone{ \global\pageno=1 \global\arabiccount = \pagecount } -% For double-sided printing, put current file name in lower left corner, -% chapter name on inside top of right hand pages, document -% title on inside top of left hand pages, and page numbers on outside top -% edge of all pages. -\def\HEADINGSdouble{% -\pageone -\HEADINGSdoublex -} \let\contentsalignmacro = \chappager -% For single-sided printing, chapter title goes across top left of page, -% page number on top right. -\def\HEADINGSsingle{% -\pageone -\HEADINGSsinglex -} % \def\HEADINGSon{\HEADINGSdouble} % defined by \CHAPPAGon -\def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex} +% For double-sided printing, put current file name in lower left corner, +% chapter name on inside top of right hand pages, document +% title on inside top of left hand pages, and page numbers on outside top +% edge of all pages. +\def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdouble} \let\HEADINGSdoubleafter=\HEADINGSafter -\def\HEADINGSdoublex{% +\def\HEADINGSdouble{% \global\evenfootline={\hfil} \global\oddfootline={\hfil} \global\evenheadline={\line{\folio\hfil\thistitle}} @@ -3986,8 +3982,10 @@ $$% \global\let\contentsalignmacro = \chapoddpage } -\def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex} -\def\HEADINGSsinglex{% +% For single-sided printing, chapter title goes across top left of page, +% page number on top right. +\def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsingle} +\def\HEADINGSsingle{% \global\evenfootline={\hfil} \global\oddfootline={\hfil} \global\evenheadline={\line{\thischapter\hfil\folio}} @@ -3999,7 +3997,6 @@ $$% % for @setchapternewpage off \def\HEADINGSsinglechapoff{% -\pageone \global\evenfootline={\hfil} \global\oddfootline={\hfil} \global\evenheadline={\line{\thischapter\hfil\folio}} @@ -4725,13 +4722,11 @@ $$% % except not \outer, so it can be used within macros and \if's. \edef\newwrite{\makecsname{ptexnewwrite}} -% \newindex {foo} defines an index named IX. +% \newindex {IX} defines an index named IX. % It automatically defines \IXindex such that % \IXindex ...rest of line... puts an entry in the index IX. % It also defines \IXindfile to be the number of the output channel for % the file that accumulates this index. The file's extension is IX. -% The name of an index should be no more than 2 characters long -% for the sake of vms. % \def\newindex#1{% \expandafter\chardef\csname#1indfile\endcsname=0 @@ -4989,7 +4984,7 @@ $$% \commondummyword\ampchar {\normalamp}% \commondummyword\atchar {\@}% \commondummyword\arrow {->}% - \commondummyword\backslashchar {}% + \commondummyword\backslashchar {\realbackslash}% \commondummyword\bullet {bullet}% \commondummyword\comma {,}% \commondummyword\copyright {copyright}% @@ -5089,9 +5084,6 @@ $$% % % We need to get rid of all macros, leaving only the arguments (if present). % Of course this is not nearly correct, but it is the best we can do for now. - % makeinfo does not expand macros in the argument to @deffn, which ends up - % writing an index entry, and texindex isn't prepared for an index sort entry - % that starts with \. % % Since macro invocations are followed by braces, we can just redefine them % to take a single TeX argument. The case of a macro invocation that @@ -7387,6 +7379,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \def\setupverb{% \tt \def\par{\leavevmode\endgraf}% + \parindent = 0pt \setcodequotes \tabeightspaces % Respect line breaks, @@ -7562,11 +7555,6 @@ might help (with 'rm \jobname.?? \jobname.??s')% \exdentamount=\defbodyindent } -\newtoks\defidx -\newtoks\deftext - -\def\useindex#1{\defidx={#1}\ignorespaces} - % Called as \printdefunline \deffooheader{text} % \def\printdefunline#1#2{% @@ -7574,10 +7562,6 @@ might help (with 'rm \jobname.?? \jobname.??s')% \plainfrenchspacing % call \deffooheader: #1#2 \endheader - % create the index entry - \defcharsdefault - \edef\temp{\noexpand\doind{\the\defidx}{\the\deftext}}% - \temp % common ending: \interlinepenalty = 10000 \advance\rightskip by 0pt plus 1fil\relax @@ -7592,6 +7576,24 @@ might help (with 'rm \jobname.?? \jobname.??s')% \def\Edefun{\endgraf\medbreak} +% @defblock, @defline do not automatically create index entries +\envdef\defblock{% + \startdefun +} +\let\Edefblock\Edefun + +\def\defline{% + \doingtypefnfalse + \parseargusing\activeparens{\printdefunline\deflineheader}% +} +\def\deflineheader#1 #2 #3\endheader{% + \printdefname{#1}{}{#2}\magicamp\defunargs{#3\unskip}% +} +\def\deftypeline{% + \doingtypefntrue + \parseargusing\activeparens{\printdefunline\deflineheader}% +} + % \makedefun{deffoo} (\deffooheader parameters) { (\deffooheader expansion) } % % Define \deffoo, \deffoox \Edeffoo and \deffooheader. @@ -7643,56 +7645,51 @@ might help (with 'rm \jobname.?? \jobname.??s')% \fi\fi } -\def\defind#1#2{ - \defidx={#1}% - \deftext={#2}% -} - % Untyped functions: % @deffn category name args \makedefun{deffn}#1 #2 #3\endheader{% - \defind{fn}{\code{#2}}% - \defname{#1}{}{#2}\magicamp\defunargs{#3\unskip}% + \doind{fn}{\code{#2}}% + \printdefname{#1}{}{#2}\magicamp\defunargs{#3\unskip}% } % @defop category class name args \makedefun{defop}#1 {\defopheaderx{#1\ \putwordon}} \def\defopheaderx#1#2 #3 #4\endheader{% - \defind{fn}{\code{#3}\space\putwordon\ \code{#2}}% - \defname{#1\ \code{#2}}{}{#3}\magicamp\defunargs{#4\unskip}% + \doind{fn}{\code{#3}\space\putwordon\ \code{#2}}% + \printdefname{#1\ \code{#2}}{}{#3}\magicamp\defunargs{#4\unskip}% } % Typed functions: % @deftypefn category type name args \makedefun{deftypefn}#1 #2 #3 #4\endheader{% - \defind{fn}{\code{#3}}% + \doind{fn}{\code{#3}}% \doingtypefntrue - \defname{#1}{#2}{#3}\defunargs{#4\unskip}% + \printdefname{#1}{#2}{#3}\defunargs{#4\unskip}% } % @deftypeop category class type name args \makedefun{deftypeop}#1 {\deftypeopheaderx{#1\ \putwordon}} \def\deftypeopheaderx#1#2 #3 #4 #5\endheader{% - \defind{fn}{\code{#4}\space\putwordon\ \code{#1\ \code{#2}}}% + \doind{fn}{\code{#4}\space\putwordon\ \code{#1\ \code{#2}}}% \doingtypefntrue - \defname{#1\ \code{#2}}{#3}{#4}\defunargs{#5\unskip}% + \printdefname{#1\ \code{#2}}{#3}{#4}\defunargs{#5\unskip}% } % Typed variables: % @deftypevr category type var args \makedefun{deftypevr}#1 #2 #3 #4\endheader{% - \defind{vr}{\code{#3}}% - \defname{#1}{#2}{#3}\defunargs{#4\unskip}% + \doind{vr}{\code{#3}}% + \printdefname{#1}{#2}{#3}\defunargs{#4\unskip}% } % @deftypecv category class type var args \makedefun{deftypecv}#1 {\deftypecvheaderx{#1\ \putwordof}} \def\deftypecvheaderx#1#2 #3 #4 #5\endheader{% - \defind{vr}{\code{#4}\space\putwordof\ \code{#2}}% - \defname{#1\ \code{#2}}{#3}{#4}\defunargs{#5\unskip}% + \doind{vr}{\code{#4}\space\putwordof\ \code{#2}}% + \printdefname{#1\ \code{#2}}{#3}{#4}\defunargs{#5\unskip}% } % Untyped variables: @@ -7708,8 +7705,8 @@ might help (with 'rm \jobname.?? \jobname.??s')% % @deftp category name args \makedefun{deftp}#1 #2 #3\endheader{% - \defind{tp}{\code{#2}}% - \defname{#1}{}{#2}\defunargs{#3\unskip}% + \doind{tp}{\code{#2}}% + \printdefname{#1}{}{#2}\defunargs{#3\unskip}% } % Remaining @defun-like shortcuts: @@ -7725,14 +7722,14 @@ might help (with 'rm \jobname.?? \jobname.??s')% \makedefun{defivar}{\defcvheaderx\putwordInstanceVariableof} \makedefun{deftypeivar}{\deftypecvheaderx\putwordInstanceVariableof} -% \defname, which formats the name of the @def (not the args). +% \printdefname, which formats the name of the @def (not the args). % #1 is the category, such as "Function". % #2 is the return type, if any. % #3 is the function name. % % We are followed by (but not passed) the arguments, if any. % -\def\defname#1#2#3{% +\def\printdefname#1#2#3{% \par % Get the values of \leftskip and \rightskip as they were outside the @def... \advance\leftskip by -\defbodyindent @@ -7857,7 +7854,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% % If we encounter &foo, then turn on ()-hacking afterwards \newif\ifampseen -\def\amprm#1 {\ampseentrue{\bf\ }} +\def\amprm#1 {\ampseentrue{\rm\ }} \def\parenfont{% \ifampseen @@ -8181,12 +8178,12 @@ might help (with 'rm \jobname.?? \jobname.??s')% % % We are in \macrobodyctxt, and the \xdef causes backslashshes in the macro % body to be transformed. -% Set \macrobody to the body of the macro, and call \defmacro. +% Set \macrobody to the body of the macro, and call \macrodef. % {\catcode`\ =\other\long\gdef\parsemacbody#1@end macro{% -\xdef\macrobody{\eatcr{#1}}\endgroup\defmacro}}% +\xdef\macrobody{\eatcr{#1}}\endgroup\macrodef}}% {\catcode`\ =\other\long\gdef\parsermacbody#1@end rmacro{% -\xdef\macrobody{\eatcr{#1}}\endgroup\defmacro}}% +\xdef\macrobody{\eatcr{#1}}\endgroup\macrodef}}% % Make @ a letter, so that we can make private-to-Texinfo macro names. \edef\texiatcatcode{\the\catcode`\@} @@ -8405,16 +8402,17 @@ might help (with 'rm \jobname.?? \jobname.??s')% % \xdef is used so that macro definitions will survive the file % they're defined in: @include reads the file inside a group. % -\def\defmacro{% +\def\macrodef{% \let\hash=##% convert placeholders to macro parameter chars \ifnum\paramno=1 - \def\xeatspaces##1{##1}% - % This removes the pair of braces around the argument. We don't - % use \eatspaces, because this can cause ends of lines to be lost - % when the argument to \eatspaces is read, leading to line-based - % commands like "@itemize" not being read correctly. + \long\def\xeatspaces##1{##1}% + % We don't use \xeatspaces for single-argument macros, because we + % want to keep ends of lines. This definition removes \xeatspaces + % when \macrobody is expanded below. \else - \let\xeatspaces\relax % suppress expansion + \def\xeatspaces{\string\xeatspaces}% + % This expands \xeatspaces as a sequence of character tokens, which + % stops \scantokens inserting an extra space after the control sequence. \fi \ifcase\paramno % 0 @@ -8580,6 +8578,75 @@ might help (with 'rm \jobname.?? \jobname.??s')% \fi \macnamexxx} +% @linemacro + +\parseargdef\linemacro{% + \getargs{#1}% now \macname is the macname and \argl the arglist + \ifx\argl\empty + \paramno=0 + \let\hash\relax + \def\paramlist{\hash 1\endlinemacro}% + \else + \expandafter\linegetparamlist\argl;% + \fi + \begingroup \macrobodyctxt \usembodybackslash + \parselinemacrobody +} + +% Build up \paramlist which will be used as the parameter text for the macro. +% At the end it will be like "#1 #2 #3\endlinemacro". +\def\linegetparamlist#1;{% + \paramno=0\def\paramlist{}% + \let\hash\relax + \linegetparamlistxxx#1,;,% +} +\def\linegetparamlistxxx#1,{% + \if#1;\let\next=\linegetparamlistxxxx + \else \let\next=\linegetparamlistxxx + \advance\paramno by 1 + \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname + {\hash\the\paramno}% + \edef\paramlist{\paramlist\hash\the\paramno\space}% + \fi\next} +\def\linegetparamlistxxxx{% + \expandafter\fixparamlist\paramlist\fixparamlist +} +% Replace final space token +\def\fixparamlist#1 \fixparamlist{% + \def\paramlist{#1\endlinemacro}% +} + +% Read the body of the macro, replacing backslash-surrounded variables +% +{\catcode`\ =\other\long\gdef\parselinemacrobody#1@end linemacro{% +\xdef\macrobody{#1}% +\endgroup +\linemacrodef +}} + +% Make the definition +\def\linemacrodef{% + \let\hash=##% + \expandafter\xdef\csname\the\macname\endcsname{% + \bgroup + \noexpand\parsearg + \expandafter\noexpand\csname\the\macname @@\endcsname + } + \expandafter\xdef\csname\the\macname @@\endcsname##1{% + \egroup + \expandafter\noexpand + \csname\the\macname @@@\endcsname##1\noexpand\endlinemacro + } + \expandafter\expandafter + \expandafter\xdef + \expandafter\expandafter\csname\the\macname @@@\endcsname\paramlist{% + \newlinechar=13 % split \macrobody into lines + \noexpand\scantokens{\macrobody}% + } +} + + + % @alias. % We need some trickery to remove the optional spaces around the equal % sign. Make them active and then expand them all to nothing. @@ -9571,8 +9638,8 @@ might help (with 'rm \jobname.?? \jobname.??s')% % \def\caption{\docaption\thiscaption} \def\shortcaption{\docaption\thisshortcaption} -\def\docaption{\checkenv\float \bgroup\scanctxt\defcaption} -\def\defcaption#1#2{\egroup \def#1{#2}} +\def\docaption{\checkenv\float \bgroup\scanctxt\docaptionz} +\def\docaptionz#1#2{\egroup \def#1{#2}} % The parameter is the control sequence identifying the counter we are % going to use. Create it if it doesn't exist and assign it to \floatno. diff --git a/doc/ChangeLog b/doc/ChangeLog index ba8e5041..8fe0a7ca 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2023-03-26 Arnold D. Robbins <arnold@skeeve.com> + + * texinfo.tex: Sync from GNULIB. + * gawktexi.in (Dynamic Typing): Add more explanation and another + example. + 2023-03-09 Arnold D. Robbins <arnold@skeeve.com> * gawkworkflow.texi (UPDATE-MONTH, EDITION): Updated. diff --git a/doc/gawk.info b/doc/gawk.info index 9a8c59e1..26c3e58e 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -15340,8 +15340,51 @@ Here is an annotated sample program: so ‘awk’ will not report the second error. If you comment out that call, though, then ‘awk’ does report the second error. - Usually, such things aren’t a big issue, but it’s worth being aware -of them. + Here is a more extreme example: + + BEGIN { + funky(a) + if (A == 0) + print "<" a ">" + else + print a[1] + } + + function funky(arr) + { + if (A == 0) + arr = 1 + else + arr[1] = 1 + } + + Here, the function uses its parameter differently depending upon the +value of the global variable ‘A’. If ‘A’ is zero, the parameter ‘arr’ +is treated as a scalar. Otherwise it’s treated as an array. + + There are two ways this program might behave. ‘awk’ could notice +that in the main program, ‘a’ is subscripted, and so mark it as an array +before the program even begins to run. BWK ‘awk’, ‘mawk’, and possibly +others do this: + + $ nawk -v A=0 -f funky.awk + error→ nawk: can't assign to a; it's an array name. + error→ source line number 11 + $ nawk -v A=1 -f funky.awk + ⊣ 1 + + Or ‘awk’ could wait until runtime to set the type of ‘a’. In this +case, since ‘a’ was never assigned used before being passed to the +function, how the function uses it forces the type to be resolved to +either scalar or array. ‘gawk’ and the MKS ‘awk’ do this: + + $ gawk -v A=0 -f funky.awk + ⊣ <> + $ gawk -v A=1 -f funky.awk + ⊣ 1 + + POSIX does not specify the correct behavior, so be aware that +different implementations work differently. File: gawk.info, Node: Indirect Calls, Next: Functions Summary, Prev: User-defined, Up: Functions @@ -39606,330 +39649,330 @@ Node: Function Caveats662110 Ref: Function Caveats-Footnote-1664205 Node: Return Statement664329 Node: Dynamic Typing667384 -Node: Indirect Calls668340 -Node: Functions Summary679499 -Node: Library Functions682276 -Ref: Library Functions-Footnote-1685824 -Ref: Library Functions-Footnote-2685967 -Node: Library Names686142 -Ref: Library Names-Footnote-1689936 -Ref: Library Names-Footnote-2690163 -Node: General Functions690259 -Node: Strtonum Function691453 -Node: Assert Function694535 -Node: Round Function697987 -Node: Cliff Random Function699565 -Node: Ordinal Functions700598 -Ref: Ordinal Functions-Footnote-1703707 -Ref: Ordinal Functions-Footnote-2703959 -Node: Join Function704173 -Ref: Join Function-Footnote-1705976 -Node: Getlocaltime Function706180 -Node: Readfile Function709954 -Node: Shell Quoting711983 -Node: Isnumeric Function713439 -Node: Data File Management714851 -Node: Filetrans Function715483 -Node: Rewind Function719777 -Node: File Checking721756 -Ref: File Checking-Footnote-1723128 -Node: Empty Files723335 -Node: Ignoring Assigns725402 -Node: Getopt Function726976 -Ref: Getopt Function-Footnote-1742810 -Node: Passwd Functions743022 -Ref: Passwd Functions-Footnote-1752204 -Node: Group Functions752292 -Ref: Group Functions-Footnote-1760430 -Node: Walking Arrays760643 -Node: Library Functions Summary763691 -Node: Library Exercises765115 -Node: Sample Programs765602 -Node: Running Examples766384 -Node: Clones767136 -Node: Cut Program768408 -Node: Egrep Program778849 -Node: Id Program788166 -Node: Split Program798280 -Ref: Split Program-Footnote-1808515 -Node: Tee Program808702 -Node: Uniq Program811611 -Node: Wc Program819476 -Node: Bytes vs. Characters819871 -Node: Using extensions821473 -Node: wc program822253 -Node: Miscellaneous Programs827259 -Node: Dupword Program828488 -Node: Alarm Program830551 -Node: Translate Program835464 -Ref: Translate Program-Footnote-1840205 -Node: Labels Program840483 -Ref: Labels Program-Footnote-1843924 -Node: Word Sorting844016 -Node: History Sorting848210 -Node: Extract Program850485 -Node: Simple Sed858754 -Node: Igawk Program861970 -Ref: Igawk Program-Footnote-1877217 -Ref: Igawk Program-Footnote-2877423 -Ref: Igawk Program-Footnote-3877553 -Node: Anagram Program877680 -Node: Signature Program880776 -Node: Programs Summary882028 -Node: Programs Exercises883286 -Ref: Programs Exercises-Footnote-1887602 -Node: Advanced Features887688 -Node: Nondecimal Data890182 -Node: Boolean Typed Values891812 -Node: Array Sorting893787 -Node: Controlling Array Traversal894516 -Ref: Controlling Array Traversal-Footnote-1903023 -Node: Array Sorting Functions903145 -Ref: Array Sorting Functions-Footnote-1909264 -Node: Two-way I/O909472 -Ref: Two-way I/O-Footnote-1917467 -Ref: Two-way I/O-Footnote-2917658 -Node: TCP/IP Networking917740 -Node: Profiling920920 -Node: Persistent Memory930630 -Ref: Persistent Memory-Footnote-1939588 -Node: Extension Philosophy939719 -Node: Advanced Features Summary941254 -Node: Internationalization943524 -Node: I18N and L10N945230 -Node: Explaining gettext945925 -Ref: Explaining gettext-Footnote-1952078 -Ref: Explaining gettext-Footnote-2952273 -Node: Programmer i18n952438 -Ref: Programmer i18n-Footnote-1957551 -Node: Translator i18n957600 -Node: String Extraction958436 -Ref: String Extraction-Footnote-1959614 -Node: Printf Ordering959712 -Ref: Printf Ordering-Footnote-1962574 -Node: I18N Portability962642 -Ref: I18N Portability-Footnote-1965216 -Node: I18N Example965287 -Ref: I18N Example-Footnote-1968687 -Ref: I18N Example-Footnote-2968763 -Node: Gawk I18N968880 -Node: I18N Summary969536 -Node: Debugger970937 -Node: Debugging971961 -Node: Debugging Concepts972410 -Node: Debugging Terms974236 -Node: Awk Debugging976849 -Ref: Awk Debugging-Footnote-1977826 -Node: Sample Debugging Session977966 -Node: Debugger Invocation978518 -Node: Finding The Bug980147 -Node: List of Debugger Commands986833 -Node: Breakpoint Control988210 -Node: Debugger Execution Control992042 -Node: Viewing And Changing Data995522 -Node: Execution Stack999260 -Node: Debugger Info1000941 -Node: Miscellaneous Debugger Commands1005240 -Node: Readline Support1010493 -Node: Limitations1011439 -Node: Debugging Summary1014083 -Node: Namespaces1015386 -Node: Global Namespace1016513 -Node: Qualified Names1017958 -Node: Default Namespace1018993 -Node: Changing The Namespace1019768 -Node: Naming Rules1021462 -Node: Internal Name Management1023377 -Node: Namespace Example1024447 -Node: Namespace And Features1027030 -Node: Namespace Summary1028487 -Node: Arbitrary Precision Arithmetic1030000 -Node: Computer Arithmetic1031519 -Ref: table-numeric-ranges1035336 -Ref: table-floating-point-ranges1035834 -Ref: Computer Arithmetic-Footnote-11036493 -Node: Math Definitions1036552 -Ref: table-ieee-formats1039597 -Node: MPFR features1040171 -Node: MPFR On Parole1040624 -Ref: MPFR On Parole-Footnote-11041468 -Node: MPFR Intro1041627 -Node: FP Math Caution1043317 -Ref: FP Math Caution-Footnote-11044391 -Node: Inexactness of computations1044768 -Node: Inexact representation1045799 -Node: Comparing FP Values1047182 -Node: Errors accumulate1048440 -Node: Strange values1049907 -Ref: Strange values-Footnote-11052573 -Node: Getting Accuracy1052678 -Node: Try To Round1055415 -Node: Setting precision1056322 -Ref: table-predefined-precision-strings1057027 -Node: Setting the rounding mode1058912 -Ref: table-gawk-rounding-modes1059294 -Ref: Setting the rounding mode-Footnote-11063352 -Node: Arbitrary Precision Integers1063535 -Ref: Arbitrary Precision Integers-Footnote-11066747 -Node: Checking for MPFR1066903 -Node: POSIX Floating Point Problems1068393 -Ref: POSIX Floating Point Problems-Footnote-11073257 -Node: Floating point summary1073295 -Node: Dynamic Extensions1075559 -Node: Extension Intro1077158 -Node: Plugin License1078466 -Node: Extension Mechanism Outline1079279 -Ref: figure-load-extension1079730 -Ref: figure-register-new-function1081315 -Ref: figure-call-new-function1082425 -Node: Extension API Description1084549 -Node: Extension API Functions Introduction1086278 -Ref: table-api-std-headers1088176 -Node: General Data Types1092640 -Ref: General Data Types-Footnote-11101808 -Node: Memory Allocation Functions1102123 -Ref: Memory Allocation Functions-Footnote-11106848 -Node: Constructor Functions1106947 -Node: API Ownership of MPFR and GMP Values1110852 -Node: Registration Functions1112413 -Node: Extension Functions1113117 -Node: Exit Callback Functions1118693 -Node: Extension Version String1120012 -Node: Input Parsers1120707 -Node: Output Wrappers1135351 -Node: Two-way processors1140199 -Node: Printing Messages1142560 -Ref: Printing Messages-Footnote-11143774 -Node: Updating ERRNO1143929 -Node: Requesting Values1144728 -Ref: table-value-types-returned1145481 -Node: Accessing Parameters1146590 -Node: Symbol Table Access1147874 -Node: Symbol table by name1148390 -Ref: Symbol table by name-Footnote-11151601 -Node: Symbol table by cookie1151733 -Ref: Symbol table by cookie-Footnote-11156014 -Node: Cached values1156078 -Ref: Cached values-Footnote-11159722 -Node: Array Manipulation1159879 -Ref: Array Manipulation-Footnote-11160982 -Node: Array Data Types1161019 -Ref: Array Data Types-Footnote-11163841 -Node: Array Functions1163941 -Node: Flattening Arrays1168970 -Node: Creating Arrays1176022 -Node: Redirection API1180872 -Node: Extension API Variables1183893 -Node: Extension Versioning1184618 -Ref: gawk-api-version1185055 -Node: Extension GMP/MPFR Versioning1186843 -Node: Extension API Informational Variables1188549 -Node: Extension API Boilerplate1189710 -Node: Changes from API V11193846 -Node: Finding Extensions1195480 -Node: Extension Example1196055 -Node: Internal File Description1196879 -Node: Internal File Ops1201203 -Ref: Internal File Ops-Footnote-11212761 -Node: Using Internal File Ops1212909 -Ref: Using Internal File Ops-Footnote-11215340 -Node: Extension Samples1215618 -Node: Extension Sample File Functions1217187 -Node: Extension Sample Fnmatch1225325 -Node: Extension Sample Fork1226920 -Node: Extension Sample Inplace1228196 -Node: Extension Sample Ord1231868 -Node: Extension Sample Readdir1232744 -Ref: table-readdir-file-types1233641 -Node: Extension Sample Revout1234779 -Node: Extension Sample Rev2way1235376 -Node: Extension Sample Read write array1236128 -Node: Extension Sample Readfile1239402 -Node: Extension Sample Time1240533 -Node: Extension Sample API Tests1242823 -Node: gawkextlib1243331 -Node: Extension summary1246367 -Node: Extension Exercises1250225 -Node: Language History1251503 -Node: V7/SVR3.11253217 -Node: SVR41255567 -Node: POSIX1257099 -Node: BTL1258524 -Node: POSIX/GNU1259293 -Node: Feature History1265824 -Node: Common Extensions1284942 -Node: Ranges and Locales1286311 -Ref: Ranges and Locales-Footnote-11291112 -Ref: Ranges and Locales-Footnote-21291139 -Ref: Ranges and Locales-Footnote-31291378 -Node: Contributors1291601 -Node: History summary1297806 -Node: Installation1299252 -Node: Gawk Distribution1300216 -Node: Getting1300708 -Node: Extracting1301707 -Node: Distribution contents1303419 -Node: Unix Installation1311499 -Node: Quick Installation1312321 -Node: Compiling with MPFR1314867 -Node: Shell Startup Files1315573 -Node: Additional Configuration Options1316730 -Node: Configuration Philosophy1319117 -Node: Compiling from Git1321619 -Node: Building the Documentation1322178 -Node: Non-Unix Installation1323590 -Node: PC Installation1324066 -Node: PC Binary Installation1324939 -Node: PC Compiling1325844 -Node: PC Using1327022 -Node: Cygwin1330750 -Node: MSYS1332006 -Node: OpenVMS Installation1332638 -Node: OpenVMS Compilation1333319 -Ref: OpenVMS Compilation-Footnote-11334802 -Node: OpenVMS Dynamic Extensions1334864 -Node: OpenVMS Installation Details1336500 -Node: OpenVMS Running1338935 -Node: OpenVMS GNV1343072 -Node: Bugs1343827 -Node: Bug definition1344751 -Node: Bug address1348402 -Node: Usenet1351993 -Node: Performance bugs1353224 -Node: Asking for help1356242 -Node: Maintainers1358233 -Node: Other Versions1359260 -Node: Installation summary1368192 -Node: Notes1369576 -Node: Compatibility Mode1370386 -Node: Additions1371208 -Node: Accessing The Source1372153 -Node: Adding Code1373688 -Node: New Ports1380824 -Node: Derived Files1385334 -Ref: Derived Files-Footnote-11391181 -Ref: Derived Files-Footnote-21391216 -Ref: Derived Files-Footnote-31391833 -Node: Future Extensions1391947 -Node: Implementation Limitations1392619 -Node: Extension Design1393861 -Node: Old Extension Problems1395025 -Ref: Old Extension Problems-Footnote-11396601 -Node: Extension New Mechanism Goals1396662 -Ref: Extension New Mechanism Goals-Footnote-11400158 -Node: Extension Other Design Decisions1400359 -Node: Extension Future Growth1402558 -Node: Notes summary1403182 -Node: Basic Concepts1404395 -Node: Basic High Level1405080 -Ref: figure-general-flow1405362 -Ref: figure-process-flow1406069 -Ref: Basic High Level-Footnote-11409470 -Node: Basic Data Typing1409659 -Node: Glossary1413077 -Node: Copying1446199 -Node: GNU Free Documentation License1483960 -Node: Index1509283 +Node: Indirect Calls669660 +Node: Functions Summary680819 +Node: Library Functions683596 +Ref: Library Functions-Footnote-1687144 +Ref: Library Functions-Footnote-2687287 +Node: Library Names687462 +Ref: Library Names-Footnote-1691256 +Ref: Library Names-Footnote-2691483 +Node: General Functions691579 +Node: Strtonum Function692773 +Node: Assert Function695855 +Node: Round Function699307 +Node: Cliff Random Function700885 +Node: Ordinal Functions701918 +Ref: Ordinal Functions-Footnote-1705027 +Ref: Ordinal Functions-Footnote-2705279 +Node: Join Function705493 +Ref: Join Function-Footnote-1707296 +Node: Getlocaltime Function707500 +Node: Readfile Function711274 +Node: Shell Quoting713303 +Node: Isnumeric Function714759 +Node: Data File Management716171 +Node: Filetrans Function716803 +Node: Rewind Function721097 +Node: File Checking723076 +Ref: File Checking-Footnote-1724448 +Node: Empty Files724655 +Node: Ignoring Assigns726722 +Node: Getopt Function728296 +Ref: Getopt Function-Footnote-1744130 +Node: Passwd Functions744342 +Ref: Passwd Functions-Footnote-1753524 +Node: Group Functions753612 +Ref: Group Functions-Footnote-1761750 +Node: Walking Arrays761963 +Node: Library Functions Summary765011 +Node: Library Exercises766435 +Node: Sample Programs766922 +Node: Running Examples767704 +Node: Clones768456 +Node: Cut Program769728 +Node: Egrep Program780169 +Node: Id Program789486 +Node: Split Program799600 +Ref: Split Program-Footnote-1809835 +Node: Tee Program810022 +Node: Uniq Program812931 +Node: Wc Program820796 +Node: Bytes vs. Characters821191 +Node: Using extensions822793 +Node: wc program823573 +Node: Miscellaneous Programs828579 +Node: Dupword Program829808 +Node: Alarm Program831871 +Node: Translate Program836784 +Ref: Translate Program-Footnote-1841525 +Node: Labels Program841803 +Ref: Labels Program-Footnote-1845244 +Node: Word Sorting845336 +Node: History Sorting849530 +Node: Extract Program851805 +Node: Simple Sed860074 +Node: Igawk Program863290 +Ref: Igawk Program-Footnote-1878537 +Ref: Igawk Program-Footnote-2878743 +Ref: Igawk Program-Footnote-3878873 +Node: Anagram Program879000 +Node: Signature Program882096 +Node: Programs Summary883348 +Node: Programs Exercises884606 +Ref: Programs Exercises-Footnote-1888922 +Node: Advanced Features889008 +Node: Nondecimal Data891502 +Node: Boolean Typed Values893132 +Node: Array Sorting895107 +Node: Controlling Array Traversal895836 +Ref: Controlling Array Traversal-Footnote-1904343 +Node: Array Sorting Functions904465 +Ref: Array Sorting Functions-Footnote-1910584 +Node: Two-way I/O910792 +Ref: Two-way I/O-Footnote-1918787 +Ref: Two-way I/O-Footnote-2918978 +Node: TCP/IP Networking919060 +Node: Profiling922240 +Node: Persistent Memory931950 +Ref: Persistent Memory-Footnote-1940908 +Node: Extension Philosophy941039 +Node: Advanced Features Summary942574 +Node: Internationalization944844 +Node: I18N and L10N946550 +Node: Explaining gettext947245 +Ref: Explaining gettext-Footnote-1953398 +Ref: Explaining gettext-Footnote-2953593 +Node: Programmer i18n953758 +Ref: Programmer i18n-Footnote-1958871 +Node: Translator i18n958920 +Node: String Extraction959756 +Ref: String Extraction-Footnote-1960934 +Node: Printf Ordering961032 +Ref: Printf Ordering-Footnote-1963894 +Node: I18N Portability963962 +Ref: I18N Portability-Footnote-1966536 +Node: I18N Example966607 +Ref: I18N Example-Footnote-1970007 +Ref: I18N Example-Footnote-2970083 +Node: Gawk I18N970200 +Node: I18N Summary970856 +Node: Debugger972257 +Node: Debugging973281 +Node: Debugging Concepts973730 +Node: Debugging Terms975556 +Node: Awk Debugging978169 +Ref: Awk Debugging-Footnote-1979146 +Node: Sample Debugging Session979286 +Node: Debugger Invocation979838 +Node: Finding The Bug981467 +Node: List of Debugger Commands988153 +Node: Breakpoint Control989530 +Node: Debugger Execution Control993362 +Node: Viewing And Changing Data996842 +Node: Execution Stack1000580 +Node: Debugger Info1002261 +Node: Miscellaneous Debugger Commands1006560 +Node: Readline Support1011813 +Node: Limitations1012759 +Node: Debugging Summary1015403 +Node: Namespaces1016706 +Node: Global Namespace1017833 +Node: Qualified Names1019278 +Node: Default Namespace1020313 +Node: Changing The Namespace1021088 +Node: Naming Rules1022782 +Node: Internal Name Management1024697 +Node: Namespace Example1025767 +Node: Namespace And Features1028350 +Node: Namespace Summary1029807 +Node: Arbitrary Precision Arithmetic1031320 +Node: Computer Arithmetic1032839 +Ref: table-numeric-ranges1036656 +Ref: table-floating-point-ranges1037154 +Ref: Computer Arithmetic-Footnote-11037813 +Node: Math Definitions1037872 +Ref: table-ieee-formats1040917 +Node: MPFR features1041491 +Node: MPFR On Parole1041944 +Ref: MPFR On Parole-Footnote-11042788 +Node: MPFR Intro1042947 +Node: FP Math Caution1044637 +Ref: FP Math Caution-Footnote-11045711 +Node: Inexactness of computations1046088 +Node: Inexact representation1047119 +Node: Comparing FP Values1048502 +Node: Errors accumulate1049760 +Node: Strange values1051227 +Ref: Strange values-Footnote-11053893 +Node: Getting Accuracy1053998 +Node: Try To Round1056735 +Node: Setting precision1057642 +Ref: table-predefined-precision-strings1058347 +Node: Setting the rounding mode1060232 +Ref: table-gawk-rounding-modes1060614 +Ref: Setting the rounding mode-Footnote-11064672 +Node: Arbitrary Precision Integers1064855 +Ref: Arbitrary Precision Integers-Footnote-11068067 +Node: Checking for MPFR1068223 +Node: POSIX Floating Point Problems1069713 +Ref: POSIX Floating Point Problems-Footnote-11074577 +Node: Floating point summary1074615 +Node: Dynamic Extensions1076879 +Node: Extension Intro1078478 +Node: Plugin License1079786 +Node: Extension Mechanism Outline1080599 +Ref: figure-load-extension1081050 +Ref: figure-register-new-function1082635 +Ref: figure-call-new-function1083745 +Node: Extension API Description1085869 +Node: Extension API Functions Introduction1087598 +Ref: table-api-std-headers1089496 +Node: General Data Types1093960 +Ref: General Data Types-Footnote-11103128 +Node: Memory Allocation Functions1103443 +Ref: Memory Allocation Functions-Footnote-11108168 +Node: Constructor Functions1108267 +Node: API Ownership of MPFR and GMP Values1112172 +Node: Registration Functions1113733 +Node: Extension Functions1114437 +Node: Exit Callback Functions1120013 +Node: Extension Version String1121332 +Node: Input Parsers1122027 +Node: Output Wrappers1136671 +Node: Two-way processors1141519 +Node: Printing Messages1143880 +Ref: Printing Messages-Footnote-11145094 +Node: Updating ERRNO1145249 +Node: Requesting Values1146048 +Ref: table-value-types-returned1146801 +Node: Accessing Parameters1147910 +Node: Symbol Table Access1149194 +Node: Symbol table by name1149710 +Ref: Symbol table by name-Footnote-11152921 +Node: Symbol table by cookie1153053 +Ref: Symbol table by cookie-Footnote-11157334 +Node: Cached values1157398 +Ref: Cached values-Footnote-11161042 +Node: Array Manipulation1161199 +Ref: Array Manipulation-Footnote-11162302 +Node: Array Data Types1162339 +Ref: Array Data Types-Footnote-11165161 +Node: Array Functions1165261 +Node: Flattening Arrays1170290 +Node: Creating Arrays1177342 +Node: Redirection API1182192 +Node: Extension API Variables1185213 +Node: Extension Versioning1185938 +Ref: gawk-api-version1186375 +Node: Extension GMP/MPFR Versioning1188163 +Node: Extension API Informational Variables1189869 +Node: Extension API Boilerplate1191030 +Node: Changes from API V11195166 +Node: Finding Extensions1196800 +Node: Extension Example1197375 +Node: Internal File Description1198199 +Node: Internal File Ops1202523 +Ref: Internal File Ops-Footnote-11214081 +Node: Using Internal File Ops1214229 +Ref: Using Internal File Ops-Footnote-11216660 +Node: Extension Samples1216938 +Node: Extension Sample File Functions1218507 +Node: Extension Sample Fnmatch1226645 +Node: Extension Sample Fork1228240 +Node: Extension Sample Inplace1229516 +Node: Extension Sample Ord1233188 +Node: Extension Sample Readdir1234064 +Ref: table-readdir-file-types1234961 +Node: Extension Sample Revout1236099 +Node: Extension Sample Rev2way1236696 +Node: Extension Sample Read write array1237448 +Node: Extension Sample Readfile1240722 +Node: Extension Sample Time1241853 +Node: Extension Sample API Tests1244143 +Node: gawkextlib1244651 +Node: Extension summary1247687 +Node: Extension Exercises1251545 +Node: Language History1252823 +Node: V7/SVR3.11254537 +Node: SVR41256887 +Node: POSIX1258419 +Node: BTL1259844 +Node: POSIX/GNU1260613 +Node: Feature History1267144 +Node: Common Extensions1286262 +Node: Ranges and Locales1287631 +Ref: Ranges and Locales-Footnote-11292432 +Ref: Ranges and Locales-Footnote-21292459 +Ref: Ranges and Locales-Footnote-31292698 +Node: Contributors1292921 +Node: History summary1299126 +Node: Installation1300572 +Node: Gawk Distribution1301536 +Node: Getting1302028 +Node: Extracting1303027 +Node: Distribution contents1304739 +Node: Unix Installation1312819 +Node: Quick Installation1313641 +Node: Compiling with MPFR1316187 +Node: Shell Startup Files1316893 +Node: Additional Configuration Options1318050 +Node: Configuration Philosophy1320437 +Node: Compiling from Git1322939 +Node: Building the Documentation1323498 +Node: Non-Unix Installation1324910 +Node: PC Installation1325386 +Node: PC Binary Installation1326259 +Node: PC Compiling1327164 +Node: PC Using1328342 +Node: Cygwin1332070 +Node: MSYS1333326 +Node: OpenVMS Installation1333958 +Node: OpenVMS Compilation1334639 +Ref: OpenVMS Compilation-Footnote-11336122 +Node: OpenVMS Dynamic Extensions1336184 +Node: OpenVMS Installation Details1337820 +Node: OpenVMS Running1340255 +Node: OpenVMS GNV1344392 +Node: Bugs1345147 +Node: Bug definition1346071 +Node: Bug address1349722 +Node: Usenet1353313 +Node: Performance bugs1354544 +Node: Asking for help1357562 +Node: Maintainers1359553 +Node: Other Versions1360580 +Node: Installation summary1369512 +Node: Notes1370896 +Node: Compatibility Mode1371706 +Node: Additions1372528 +Node: Accessing The Source1373473 +Node: Adding Code1375008 +Node: New Ports1382144 +Node: Derived Files1386654 +Ref: Derived Files-Footnote-11392501 +Ref: Derived Files-Footnote-21392536 +Ref: Derived Files-Footnote-31393153 +Node: Future Extensions1393267 +Node: Implementation Limitations1393939 +Node: Extension Design1395181 +Node: Old Extension Problems1396345 +Ref: Old Extension Problems-Footnote-11397921 +Node: Extension New Mechanism Goals1397982 +Ref: Extension New Mechanism Goals-Footnote-11401478 +Node: Extension Other Design Decisions1401679 +Node: Extension Future Growth1403878 +Node: Notes summary1404502 +Node: Basic Concepts1405715 +Node: Basic High Level1406400 +Ref: figure-general-flow1406682 +Ref: figure-process-flow1407389 +Ref: Basic High Level-Footnote-11410790 +Node: Basic Data Typing1410979 +Node: Glossary1414397 +Node: Copying1447519 +Node: GNU Free Documentation License1485280 +Node: Index1510603 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index 6ce9db35..a745dca2 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -21987,8 +21987,59 @@ a fatal error, so @command{awk} will not report the second error. If you comment out that call, though, then @command{awk} does report the second error. -Usually, such things aren't a big issue, but it's worth -being aware of them. +Here is a more extreme example: + +@example +BEGIN @{ + funky(a) + if (A == 0) + print "<" a ">" + else + print a[1] +@} + +function funky(arr) +@{ + if (A == 0) + arr = 1 + else + arr[1] = 1 +@} +@end example + +Here, the function uses its parameter differently depending upon the +value of the global variable @code{A}. If @code{A} is zero, the +parameter @code{arr} is treated as a scalar. Otherwise it's treated +as an array. + +There are two ways this program might behave. @command{awk} could notice +that in the main program, @code{a} is subscripted, and so mark it as +an array before the program even begins to run. BWK @code{awk}, @code{mawk}, +and possibly others do this: + +@example +$ @kbd{nawk -v A=0 -f funky.awk} +@error{} nawk: can't assign to a; it's an array name. +@error{} source line number 11 +$ @kbd{nawk -v A=1 -f funky.awk} +@print{} 1 +@end example + +Or @command{awk} could wait until runtime to set the type of @code{a}. +In this case, since @code{a} was never assigned used before being +passed to the function, how the function uses it forces the type to +be resolved to either scalar or array. @command{gawk} +and the MKS @command{awk} do this: + +@example +$ @kbd{gawk -v A=0 -f funky.awk} +@print{} <> +$ @kbd{gawk -v A=1 -f funky.awk } +@print{} 1 +@end example + +POSIX does not specify the correct behavior, so be aware that different +implementations work differently. @node Indirect Calls @section Indirect Function Calls diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 30bf38c5..5fb7a0f8 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -20972,8 +20972,59 @@ a fatal error, so @command{awk} will not report the second error. If you comment out that call, though, then @command{awk} does report the second error. -Usually, such things aren't a big issue, but it's worth -being aware of them. +Here is a more extreme example: + +@example +BEGIN @{ + funky(a) + if (A == 0) + print "<" a ">" + else + print a[1] +@} + +function funky(arr) +@{ + if (A == 0) + arr = 1 + else + arr[1] = 1 +@} +@end example + +Here, the function uses its parameter differently depending upon the +value of the global variable @code{A}. If @code{A} is zero, the +parameter @code{arr} is treated as a scalar. Otherwise it's treated +as an array. + +There are two ways this program might behave. @command{awk} could notice +that in the main program, @code{a} is subscripted, and so mark it as +an array before the program even begins to run. BWK @code{awk}, @code{mawk}, +and possibly others do this: + +@example +$ @kbd{nawk -v A=0 -f funky.awk} +@error{} nawk: can't assign to a; it's an array name. +@error{} source line number 11 +$ @kbd{nawk -v A=1 -f funky.awk} +@print{} 1 +@end example + +Or @command{awk} could wait until runtime to set the type of @code{a}. +In this case, since @code{a} was never assigned used before being +passed to the function, how the function uses it forces the type to +be resolved to either scalar or array. @command{gawk} +and the MKS @command{awk} do this: + +@example +$ @kbd{gawk -v A=0 -f funky.awk} +@print{} <> +$ @kbd{gawk -v A=1 -f funky.awk } +@print{} 1 +@end example + +POSIX does not specify the correct behavior, so be aware that different +implementations work differently. @node Indirect Calls @section Indirect Function Calls diff --git a/doc/texinfo.tex b/doc/texinfo.tex index 3cccf01d..204caf74 100644 --- a/doc/texinfo.tex +++ b/doc/texinfo.tex @@ -3,7 +3,7 @@ % Load plain if necessary, i.e., if running under initex. \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi % -\def\texinfoversion{2023-01-02.21} +\def\texinfoversion{2023-03-21.06} % % Copyright 1985, 1986, 1988, 1990-2023 Free Software Foundation, Inc. % @@ -2683,25 +2683,21 @@ end } \setregularquotes -% 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 -% works for pasting with more pdf viewers (at least evince), the -% lilypond developers report. xpdf does work with the regular 0x27. +% output for ' in @code +% in tt font hex 0D (undirected) or 27 (curly right quote) % \def\codequoteright{% \ifusingtt {\ifflagclear{txicodequoteundirected}% {\ifflagclear{codequoteundirected}% {'}% - {\char'15 }}% - {\char'15 }}% + {\char"0D }}% + {\char"0D }}% {'}% } -% and a similar option for the left quote char vs. a grave accent. -% Modern fonts display ASCII 0x60 as a grave accent, so some people like -% the code environments to do likewise. +% output for ` in @code +% in tt font hex 12 (grave accent) or 60 (curly left quote) % \relax disables Spanish ligatures ?` and !` of \tt font. % \def\codequoteleft{% @@ -2709,8 +2705,8 @@ end {\ifflagclear{txicodequotebacktick}% {\ifflagclear{codequotebacktick}% {\relax`}% - {\char'22 }}% - {\char'22 }}% + {\char"12 }}% + {\char"12 }}% {\relax`}% } @@ -2729,7 +2725,7 @@ end \errmessage{Unknown @codequoteundirected value `\temp', must be on|off}% \fi\fi } -% + \parseargdef\codequotebacktick{% \def\temp{#1}% \ifx\temp\onword @@ -2744,6 +2740,11 @@ end \fi\fi } +% Turn them on by default +\let\SETtxicodequoteundirected = t +\let\SETtxicodequotebacktick = t + + % [Knuth] pp. 380,381,391, disable Spanish ligatures ?` and !` of \tt font. \def\noligaturesquoteleft{\relax\lq} @@ -2929,10 +2930,6 @@ end \let-\dashnobreak \let_\realunder \fi - % Given -foo (with a single dash), we do not want to allow a break - % after the hyphen. - \global\let\codedashprev=\codedash - % \codex } % @@ -2942,21 +2939,30 @@ end % % Now, output a discretionary to allow a line break, unless % (a) the next character is a -, or - % (b) the preceding character is a -. + % (b) the preceding character is a -, or + % (c) we are at the start of the string. + % In both cases (b) and (c), \codedashnobreak should be set to \codedash. + % % E.g., given --posix, we do not want to allow a break after either -. % Given --foo-bar, we do want to allow a break between the - and the b. \ifx\next\codedash \else - \ifx\codedashprev\codedash + \ifx\codedashnobreak\codedash \else \discretionary{}{}{}\fi \fi % we need the space after the = for the case when \next itself is a % space token; it would get swallowed otherwise. As in @code{- a}. - \global\let\codedashprev= \next + \global\let\codedashnobreak= \next } } \def\normaldash{-} % -\def\codex #1{\tclose{#1}\endgroup} +\def\codex #1{\tclose{% + % Given -foo (with a single dash), we do not want to allow a break + % after the -. \codedashnobreak is set to the first character in + % @code. + \futurelet\codedashnobreak\relax + #1% +}\endgroup} \def\codeunder{% % this is all so @math{@code{var_name}+1} can work. In math mode, _ @@ -3950,33 +3956,23 @@ $$% \def\HEADINGSoff{{\globaldefs=1 \headingsoff}} % global setting -% When we turn headings on, set the page number to 1. +% Set the page number to 1. \def\pageone{ \global\pageno=1 \global\arabiccount = \pagecount } -% For double-sided printing, put current file name in lower left corner, -% chapter name on inside top of right hand pages, document -% title on inside top of left hand pages, and page numbers on outside top -% edge of all pages. -\def\HEADINGSdouble{% -\pageone -\HEADINGSdoublex -} \let\contentsalignmacro = \chappager -% For single-sided printing, chapter title goes across top left of page, -% page number on top right. -\def\HEADINGSsingle{% -\pageone -\HEADINGSsinglex -} % \def\HEADINGSon{\HEADINGSdouble} % defined by \CHAPPAGon -\def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex} +% For double-sided printing, put current file name in lower left corner, +% chapter name on inside top of right hand pages, document +% title on inside top of left hand pages, and page numbers on outside top +% edge of all pages. +\def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdouble} \let\HEADINGSdoubleafter=\HEADINGSafter -\def\HEADINGSdoublex{% +\def\HEADINGSdouble{% \global\evenfootline={\hfil} \global\oddfootline={\hfil} \global\evenheadline={\line{\folio\hfil\thistitle}} @@ -3986,8 +3982,10 @@ $$% \global\let\contentsalignmacro = \chapoddpage } -\def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex} -\def\HEADINGSsinglex{% +% For single-sided printing, chapter title goes across top left of page, +% page number on top right. +\def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsingle} +\def\HEADINGSsingle{% \global\evenfootline={\hfil} \global\oddfootline={\hfil} \global\evenheadline={\line{\thischapter\hfil\folio}} @@ -3999,7 +3997,6 @@ $$% % for @setchapternewpage off \def\HEADINGSsinglechapoff{% -\pageone \global\evenfootline={\hfil} \global\oddfootline={\hfil} \global\evenheadline={\line{\thischapter\hfil\folio}} @@ -4725,13 +4722,11 @@ $$% % except not \outer, so it can be used within macros and \if's. \edef\newwrite{\makecsname{ptexnewwrite}} -% \newindex {foo} defines an index named IX. +% \newindex {IX} defines an index named IX. % It automatically defines \IXindex such that % \IXindex ...rest of line... puts an entry in the index IX. % It also defines \IXindfile to be the number of the output channel for % the file that accumulates this index. The file's extension is IX. -% The name of an index should be no more than 2 characters long -% for the sake of vms. % \def\newindex#1{% \expandafter\chardef\csname#1indfile\endcsname=0 @@ -4989,7 +4984,7 @@ $$% \commondummyword\ampchar {\normalamp}% \commondummyword\atchar {\@}% \commondummyword\arrow {->}% - \commondummyword\backslashchar {}% + \commondummyword\backslashchar {\realbackslash}% \commondummyword\bullet {bullet}% \commondummyword\comma {,}% \commondummyword\copyright {copyright}% @@ -5089,9 +5084,6 @@ $$% % % We need to get rid of all macros, leaving only the arguments (if present). % Of course this is not nearly correct, but it is the best we can do for now. - % makeinfo does not expand macros in the argument to @deffn, which ends up - % writing an index entry, and texindex isn't prepared for an index sort entry - % that starts with \. % % Since macro invocations are followed by braces, we can just redefine them % to take a single TeX argument. The case of a macro invocation that @@ -7387,6 +7379,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \def\setupverb{% \tt \def\par{\leavevmode\endgraf}% + \parindent = 0pt \setcodequotes \tabeightspaces % Respect line breaks, @@ -7562,11 +7555,6 @@ might help (with 'rm \jobname.?? \jobname.??s')% \exdentamount=\defbodyindent } -\newtoks\defidx -\newtoks\deftext - -\def\useindex#1{\defidx={#1}\ignorespaces} - % Called as \printdefunline \deffooheader{text} % \def\printdefunline#1#2{% @@ -7574,10 +7562,6 @@ might help (with 'rm \jobname.?? \jobname.??s')% \plainfrenchspacing % call \deffooheader: #1#2 \endheader - % create the index entry - \defcharsdefault - \edef\temp{\noexpand\doind{\the\defidx}{\the\deftext}}% - \temp % common ending: \interlinepenalty = 10000 \advance\rightskip by 0pt plus 1fil\relax @@ -7592,6 +7576,24 @@ might help (with 'rm \jobname.?? \jobname.??s')% \def\Edefun{\endgraf\medbreak} +% @defblock, @defline do not automatically create index entries +\envdef\defblock{% + \startdefun +} +\let\Edefblock\Edefun + +\def\defline{% + \doingtypefnfalse + \parseargusing\activeparens{\printdefunline\deflineheader}% +} +\def\deflineheader#1 #2 #3\endheader{% + \printdefname{#1}{}{#2}\magicamp\defunargs{#3\unskip}% +} +\def\deftypeline{% + \doingtypefntrue + \parseargusing\activeparens{\printdefunline\deflineheader}% +} + % \makedefun{deffoo} (\deffooheader parameters) { (\deffooheader expansion) } % % Define \deffoo, \deffoox \Edeffoo and \deffooheader. @@ -7643,56 +7645,51 @@ might help (with 'rm \jobname.?? \jobname.??s')% \fi\fi } -\def\defind#1#2{ - \defidx={#1}% - \deftext={#2}% -} - % Untyped functions: % @deffn category name args \makedefun{deffn}#1 #2 #3\endheader{% - \defind{fn}{\code{#2}}% - \defname{#1}{}{#2}\magicamp\defunargs{#3\unskip}% + \doind{fn}{\code{#2}}% + \printdefname{#1}{}{#2}\magicamp\defunargs{#3\unskip}% } % @defop category class name args \makedefun{defop}#1 {\defopheaderx{#1\ \putwordon}} \def\defopheaderx#1#2 #3 #4\endheader{% - \defind{fn}{\code{#3}\space\putwordon\ \code{#2}}% - \defname{#1\ \code{#2}}{}{#3}\magicamp\defunargs{#4\unskip}% + \doind{fn}{\code{#3}\space\putwordon\ \code{#2}}% + \printdefname{#1\ \code{#2}}{}{#3}\magicamp\defunargs{#4\unskip}% } % Typed functions: % @deftypefn category type name args \makedefun{deftypefn}#1 #2 #3 #4\endheader{% - \defind{fn}{\code{#3}}% + \doind{fn}{\code{#3}}% \doingtypefntrue - \defname{#1}{#2}{#3}\defunargs{#4\unskip}% + \printdefname{#1}{#2}{#3}\defunargs{#4\unskip}% } % @deftypeop category class type name args \makedefun{deftypeop}#1 {\deftypeopheaderx{#1\ \putwordon}} \def\deftypeopheaderx#1#2 #3 #4 #5\endheader{% - \defind{fn}{\code{#4}\space\putwordon\ \code{#1\ \code{#2}}}% + \doind{fn}{\code{#4}\space\putwordon\ \code{#1\ \code{#2}}}% \doingtypefntrue - \defname{#1\ \code{#2}}{#3}{#4}\defunargs{#5\unskip}% + \printdefname{#1\ \code{#2}}{#3}{#4}\defunargs{#5\unskip}% } % Typed variables: % @deftypevr category type var args \makedefun{deftypevr}#1 #2 #3 #4\endheader{% - \defind{vr}{\code{#3}}% - \defname{#1}{#2}{#3}\defunargs{#4\unskip}% + \doind{vr}{\code{#3}}% + \printdefname{#1}{#2}{#3}\defunargs{#4\unskip}% } % @deftypecv category class type var args \makedefun{deftypecv}#1 {\deftypecvheaderx{#1\ \putwordof}} \def\deftypecvheaderx#1#2 #3 #4 #5\endheader{% - \defind{vr}{\code{#4}\space\putwordof\ \code{#2}}% - \defname{#1\ \code{#2}}{#3}{#4}\defunargs{#5\unskip}% + \doind{vr}{\code{#4}\space\putwordof\ \code{#2}}% + \printdefname{#1\ \code{#2}}{#3}{#4}\defunargs{#5\unskip}% } % Untyped variables: @@ -7708,8 +7705,8 @@ might help (with 'rm \jobname.?? \jobname.??s')% % @deftp category name args \makedefun{deftp}#1 #2 #3\endheader{% - \defind{tp}{\code{#2}}% - \defname{#1}{}{#2}\defunargs{#3\unskip}% + \doind{tp}{\code{#2}}% + \printdefname{#1}{}{#2}\defunargs{#3\unskip}% } % Remaining @defun-like shortcuts: @@ -7725,14 +7722,14 @@ might help (with 'rm \jobname.?? \jobname.??s')% \makedefun{defivar}{\defcvheaderx\putwordInstanceVariableof} \makedefun{deftypeivar}{\deftypecvheaderx\putwordInstanceVariableof} -% \defname, which formats the name of the @def (not the args). +% \printdefname, which formats the name of the @def (not the args). % #1 is the category, such as "Function". % #2 is the return type, if any. % #3 is the function name. % % We are followed by (but not passed) the arguments, if any. % -\def\defname#1#2#3{% +\def\printdefname#1#2#3{% \par % Get the values of \leftskip and \rightskip as they were outside the @def... \advance\leftskip by -\defbodyindent @@ -7857,7 +7854,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% % If we encounter &foo, then turn on ()-hacking afterwards \newif\ifampseen -\def\amprm#1 {\ampseentrue{\bf\ }} +\def\amprm#1 {\ampseentrue{\rm\ }} \def\parenfont{% \ifampseen @@ -8181,12 +8178,12 @@ might help (with 'rm \jobname.?? \jobname.??s')% % % We are in \macrobodyctxt, and the \xdef causes backslashshes in the macro % body to be transformed. -% Set \macrobody to the body of the macro, and call \defmacro. +% Set \macrobody to the body of the macro, and call \macrodef. % {\catcode`\ =\other\long\gdef\parsemacbody#1@end macro{% -\xdef\macrobody{\eatcr{#1}}\endgroup\defmacro}}% +\xdef\macrobody{\eatcr{#1}}\endgroup\macrodef}}% {\catcode`\ =\other\long\gdef\parsermacbody#1@end rmacro{% -\xdef\macrobody{\eatcr{#1}}\endgroup\defmacro}}% +\xdef\macrobody{\eatcr{#1}}\endgroup\macrodef}}% % Make @ a letter, so that we can make private-to-Texinfo macro names. \edef\texiatcatcode{\the\catcode`\@} @@ -8405,16 +8402,17 @@ might help (with 'rm \jobname.?? \jobname.??s')% % \xdef is used so that macro definitions will survive the file % they're defined in: @include reads the file inside a group. % -\def\defmacro{% +\def\macrodef{% \let\hash=##% convert placeholders to macro parameter chars \ifnum\paramno=1 - \def\xeatspaces##1{##1}% - % This removes the pair of braces around the argument. We don't - % use \eatspaces, because this can cause ends of lines to be lost - % when the argument to \eatspaces is read, leading to line-based - % commands like "@itemize" not being read correctly. + \long\def\xeatspaces##1{##1}% + % We don't use \xeatspaces for single-argument macros, because we + % want to keep ends of lines. This definition removes \xeatspaces + % when \macrobody is expanded below. \else - \let\xeatspaces\relax % suppress expansion + \def\xeatspaces{\string\xeatspaces}% + % This expands \xeatspaces as a sequence of character tokens, which + % stops \scantokens inserting an extra space after the control sequence. \fi \ifcase\paramno % 0 @@ -8580,6 +8578,75 @@ might help (with 'rm \jobname.?? \jobname.??s')% \fi \macnamexxx} +% @linemacro + +\parseargdef\linemacro{% + \getargs{#1}% now \macname is the macname and \argl the arglist + \ifx\argl\empty + \paramno=0 + \let\hash\relax + \def\paramlist{\hash 1\endlinemacro}% + \else + \expandafter\linegetparamlist\argl;% + \fi + \begingroup \macrobodyctxt \usembodybackslash + \parselinemacrobody +} + +% Build up \paramlist which will be used as the parameter text for the macro. +% At the end it will be like "#1 #2 #3\endlinemacro". +\def\linegetparamlist#1;{% + \paramno=0\def\paramlist{}% + \let\hash\relax + \linegetparamlistxxx#1,;,% +} +\def\linegetparamlistxxx#1,{% + \if#1;\let\next=\linegetparamlistxxxx + \else \let\next=\linegetparamlistxxx + \advance\paramno by 1 + \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname + {\hash\the\paramno}% + \edef\paramlist{\paramlist\hash\the\paramno\space}% + \fi\next} +\def\linegetparamlistxxxx{% + \expandafter\fixparamlist\paramlist\fixparamlist +} +% Replace final space token +\def\fixparamlist#1 \fixparamlist{% + \def\paramlist{#1\endlinemacro}% +} + +% Read the body of the macro, replacing backslash-surrounded variables +% +{\catcode`\ =\other\long\gdef\parselinemacrobody#1@end linemacro{% +\xdef\macrobody{#1}% +\endgroup +\linemacrodef +}} + +% Make the definition +\def\linemacrodef{% + \let\hash=##% + \expandafter\xdef\csname\the\macname\endcsname{% + \bgroup + \noexpand\parsearg + \expandafter\noexpand\csname\the\macname @@\endcsname + } + \expandafter\xdef\csname\the\macname @@\endcsname##1{% + \egroup + \expandafter\noexpand + \csname\the\macname @@@\endcsname##1\noexpand\endlinemacro + } + \expandafter\expandafter + \expandafter\xdef + \expandafter\expandafter\csname\the\macname @@@\endcsname\paramlist{% + \newlinechar=13 % split \macrobody into lines + \noexpand\scantokens{\macrobody}% + } +} + + + % @alias. % We need some trickery to remove the optional spaces around the equal % sign. Make them active and then expand them all to nothing. @@ -9571,8 +9638,8 @@ might help (with 'rm \jobname.?? \jobname.??s')% % \def\caption{\docaption\thiscaption} \def\shortcaption{\docaption\thisshortcaption} -\def\docaption{\checkenv\float \bgroup\scanctxt\defcaption} -\def\defcaption#1#2{\egroup \def#1{#2}} +\def\docaption{\checkenv\float \bgroup\scanctxt\docaptionz} +\def\docaptionz#1#2{\egroup \def#1{#2}} % The parameter is the control sequence identifying the counter we are % going to use. Create it if it doesn't exist and assign it to \floatno. diff --git a/support/ChangeLog b/support/ChangeLog index 681809ba..7be12deb 100644 --- a/support/ChangeLog +++ b/support/ChangeLog @@ -1,3 +1,7 @@ +2023-03-26 Arnold D. Robbins <arnold@skeeve.com> + + * dfa.c, verify.h: Sync from GNULIB. + 2023-02-05 Arnold D. Robbins <arnold@skeeve.com> * cdefs.h, dfa.c, dfa.h, dynarray.h, flexmember.h, idx.h, diff --git a/support/dfa.c b/support/dfa.c index 211e1ed1..d54aab40 100644 --- a/support/dfa.c +++ b/support/dfa.c @@ -67,7 +67,10 @@ c_isdigit (char c) #ifndef FALLTHROUGH # if 201710L < __STDC_VERSION__ # define FALLTHROUGH [[__fallthrough__]] -# elif (__GNUC__ >= 7) || (__clang_major__ >= 10) +# elif ((__GNUC__ >= 7) \ + || (defined __apple_build_version__ \ + ? __apple_build_version__ >= 12000000 \ + : __clang_major__ >= 10)) # define FALLTHROUGH __attribute__ ((__fallthrough__)) # else # define FALLTHROUGH ((void) 0) @@ -1199,8 +1202,13 @@ lex (struct dfa *dfa) On the plus side, this avoids having a duplicate of the main switch inside the backslash case. On the minus side, it means that just about every case tests the backslash flag. */ - for (int i = 0; i < 2; ++i) + for (int i = 0; ; i++) { + /* This loop should consume at most a backslash and some other + character. */ + if (2 <= i) + abort (); + if (! dfa->lex.left) return dfa->lex.lasttok = END; int c = fetch_wc (dfa); @@ -1588,11 +1596,6 @@ lex (struct dfa *dfa) return dfa->lex.lasttok = c; } } - - /* The above loop should consume at most a backslash - and some other character. */ - abort (); - return END; /* keeps pedantic compilers happy. */ } static void diff --git a/support/verify.h b/support/verify.h index f0b3fc58..c7002432 100644 --- a/support/verify.h +++ b/support/verify.h @@ -285,14 +285,16 @@ template <int w> # define _GL_HAS_BUILTIN_TRAP 0 #endif -#if defined __clang_major__ && __clang_major__ < 5 -# define _GL_HAS_BUILTIN_UNREACHABLE 0 -#elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__) -# define _GL_HAS_BUILTIN_UNREACHABLE 1 -#elif defined __has_builtin -# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable) -#else -# define _GL_HAS_BUILTIN_UNREACHABLE 0 +#ifndef _GL_HAS_BUILTIN_UNREACHABLE +# if defined __clang_major__ && __clang_major__ < 5 +# define _GL_HAS_BUILTIN_UNREACHABLE 0 +# elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__) +# define _GL_HAS_BUILTIN_UNREACHABLE 1 +# elif defined __has_builtin +# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable) +# else +# define _GL_HAS_BUILTIN_UNREACHABLE 0 +# endif #endif /* Each of these macros verifies that its argument R is nonzero. To |