diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/ChangeLog | 44 | ||||
-rw-r--r-- | doc/Makefile.in | 11 | ||||
-rw-r--r-- | doc/awkcard.in | 56 | ||||
-rw-r--r-- | doc/gawk.1 | 187 | ||||
-rw-r--r-- | doc/gawk.info | 3026 | ||||
-rw-r--r-- | doc/gawk.texi | 1505 |
6 files changed, 3523 insertions, 1306 deletions
diff --git a/doc/ChangeLog b/doc/ChangeLog index 4d178867..7ea0c491 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -6,6 +6,46 @@ * texinfo.tex: Update to latest from automake 1.11.4. +2012-04-11 John Haque <j.eh@mchsi.com> + + * gawk.texi: Change RNDMODE to ROUNDMODE. + * gawk.1, awkcard.in: Ditto. + +2012-04-11 Arnold D. Robbins <arnold@skeeve.com> + + * gawk.texi: Change --arbitrary-precision to --bignum. + * gawk.1: Ditto. + * awkcard.in: Add --bignum, RNDMODE, PREC. + +2012-04-08 Arnold D. Robbins <arnold@skeeve.com> + + * gawk.texi: Editing on new chapter on arbitrary precision numbers. + +2012-03-31 John Haque <j.eh@mchsi.com> + + * gawk.texi, gawk.1: Add text on support for arbitrary precision + numbers. + +2012-02-06 Arnold D. Robbins <arnold@skeeve.com> + + * gawk.texi, gawk.1: And some minor edits thereunto. + +2012-02-03 John Haque <j.eh@mchsi.com> + + * gawk.texi, gawk.1: Add text on read timeout. + +2011-12-28 Arnold D. Robbins <arnold@skeeve.com> + + * awkcard.in, gawk.1: Minor edits after merge of executables. + +2011-12-21 John Haque <j.eh@mchsi.com> + + * gawk.texi: Updated sections on profiling and debugging + after merging the exes. Document new options --debug and + --load, and add a sub-section on loading extension library. + * gawk.1: Same. + * awkcard.in: Same. + 2012-03-28 Arnold D. Robbins <arnold@skeeve.com> * 4.0.1: Release tar ball made. @@ -39,6 +79,10 @@ Jeroen Schot <schot@A-Eskwadraat.nl>. * gawk.texi: Some minor fixes. +2011-08-31 John Haque <j.eh@mchsi.com> + + * gawk.texi: Updated gawk dynamic extension doc. + 2011-07-28 Arnold D. Robbins <arnold@skeeve.com> * gawk.texi (Gory Details): Restore text on historical behavior diff --git a/doc/Makefile.in b/doc/Makefile.in index beaad1f1..70c6abe3 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -84,11 +84,11 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/arch.m4 \ $(top_srcdir)/m4/isc-posix.m4 $(top_srcdir)/m4/lcmessage.m4 \ $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libsigsegv.m4 \ - $(top_srcdir)/m4/longlong.m4 $(top_srcdir)/m4/nls.m4 \ - $(top_srcdir)/m4/noreturn.m4 $(top_srcdir)/m4/po.m4 \ - $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/readline.m4 \ - $(top_srcdir)/m4/socket.m4 $(top_srcdir)/m4/ulonglong.m4 \ - $(top_srcdir)/configure.ac + $(top_srcdir)/m4/longlong.m4 $(top_srcdir)/m4/mpfr.m4 \ + $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/noreturn.m4 \ + $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ + $(top_srcdir)/m4/readline.m4 $(top_srcdir)/m4/socket.m4 \ + $(top_srcdir)/m4/ulonglong.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs @@ -180,6 +180,7 @@ INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ LDFLAGS = @LDFLAGS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ +LIBMPFR = @LIBMPFR@ LIBOBJS = @LIBOBJS@ LIBREADLINE = @LIBREADLINE@ LIBS = @LIBS@ diff --git a/doc/awkcard.in b/doc/awkcard.in index 22b4716f..b7d87691 100644 --- a/doc/awkcard.in +++ b/doc/awkcard.in @@ -26,7 +26,6 @@ .\" Strings to save typing .ds AK \*(FCawk\*(FR .ds GK \*(FCgawk\*(FR -.ds PK \*(FCpgawk\*(FR .ds NK Bell Labs \*(FCawk\*(FR .ds MK \*(FCmawk\*(FR .\" @@ -77,7 +76,7 @@ Pattern Elements 8 Printf Formats 14 Records 10 Regular Expressions 11 -Signals (\*(PK) 4 +Signals (\*(GK \*(FC\-\^\-profile\*(FR) 4 Special Filenames 12 String Functions 16 Time Functions (\*(GK) 17 @@ -254,6 +253,9 @@ their types and final values to If no \*(FIfile\*(FR is provided, \*(FCgawk\*(FR uses \*(FCawkvars.out\*(FR. +.TI "\*(FC\-D\*(FR[\*(FC\*(FIfile\*(FR], \*(FC\-\^\-debug\*(FR[\*(FC=\*(FIfile\*(FR] +Enable debugging of program. Optionally read stored commands +from \*(FIfile\*(FR. .TI "\*(FC-e '\*(FItext\*(FC'\*(FR, \*(FC\-\^\-source '\*(FItext\*(FC'\*(FR Use \*(FItext\*(FR as AWK program source code. .TI "\*(FC\-E \*(FIfile\*(FR, \*(FC\-\^\-exec \*(FIfile\*(FR @@ -269,6 +271,8 @@ for localization. .TI "\*(FC\-h\*(FR, \*(FC\-\^\-help\*(FR Print a short summary of the available options on \*(FCstdout\*(FR, then exit zero. +.TI "\*(FC\-l \*(FIlib\*(FR, \*(FC\-\^\-load \*(FIlib\*(FR +Load dynamic extension \*(FIlib\fP. .TI "\*(FC\-L \*(FR[\*(FC\*(FIvalue\*(FR], \*(FC\-\^\-lint\*(FR[\*(FC=\*(FIvalue\*(FR] Warn about dubious or non-portable constructs. If \*(FIvalue\*(FR is @@ -278,36 +282,31 @@ If \*(FIvalue\*(FR is \*(FCinvalid\*(FR, only issue warnings about things that are actually invalid (not fully implemented yet). +.TI "\*(FC\-M\*(FR, \*(FC\-\^\-bignum\*(FR +Enable arbitrary-precision arithmetic. .TI "\*(FC\-n\*(FR, \*(FC\-\^\-non\-decimal\-data\*(FR Recognize octal and hexadecimal values in input data. \*(FIUse this option with great caution!\*(FR .TI "\*(FC\-N\*(FR, \*(FC\-\^\-use\-lc\-numeric\*(FR Force use of the locale's decimal point character when parsing input data. +.TI "\*(FC\-o\*(FR[\*(FC\*(FIfile\*(FR], \*(FC\-\^\-pretty-print\*(FR[\*(FC=\*(FIfile\*(FR] +Output a pretty printed version of the program to \*(FIfile\*(FR +(default: \*(FCawkprof.out\*(FR). .TI "\*(FC\-O\*(FR, \*(FC\-\^\-optimize\*(FR Enable some internal optimizations. .TI "\*(FC\-p\*(FR[\*(FC\*(FIfile\*(FR], \*(FC\-\^\-profile\*(FR[\*(FC=\*(FIfile\*(FR] Send profiling data to \*(FIfile\*(FR (default: \*(FCawkprof.out\*(FR). -With \*(GK, -the profile is just a ``pretty printed'' version of the program. -With \*(PK, -the profile contains execution counts in the left margin +The profile contains execution counts in the left margin of each statement in the program. .TI "\*(FC\-P\*(FR, \*(FC\-\^\-posix\*(FR Disable common and GNU extensions. -.TI "\*(FC\-R \*(FIfile\*(FR, \*(FC\-\^\-command \*(FIfile\*(FR" -\*(FCdgawk\*(FR only. -Read stored debugger commands from \*(FIfile\*(FR. .TI "\*(FC\-r\*(FR, \*(FC\-\^\-re\-interval\*(FR -Enable \*(FIinterval expressions\*(FR in regular -expression matching (see \fHRegular -Expressions\fP below). Useful if -\*(FC\-\^\-traditional\*(FR is specified. -.TI "\*(FC\-S\*(FR, \*(FC\-\^\-sandbox\*(FR -Disable the \*(FCsystem()\*(FR function, -input redirection with \*(FCgetline\*(FR, -output redirection with \*(FCprint\*(FR and \*(FCprintf\*(FR, -and dynamic extensions loading.\*(CB +Enable \*(FIinterval expressions\*(FR.\*(CB +... in regular +... expression matching (see \fHRegular +... Expressions\fP below). Useful if +... \*(FC\-\^\-traditional\*(FR is specified .in -4n .EB "\s+2\f(HBCOMMAND LINE ARGUMENTS (\*(GK\f(HB)\*(FR\s0" @@ -319,6 +318,11 @@ and dynamic extensions loading.\*(CB .ES .fi .in +4n +.TI "\*(FC\-S\*(FR, \*(FC\-\^\-sandbox\*(FR +Disable the \*(FCsystem()\*(FR function, +input redirection with \*(FCgetline\*(FR, +output redirection with \*(FCprint\*(FR and \*(FCprintf\*(FR, +and dynamic extensions loading. .TI "\*(FC-t\*(FR, \*(FC\-\^\-lint\-old\*(FR Warn about constructs that are not portable to the original version of @@ -383,14 +387,14 @@ The options may be abbreviated using just the first letter, e.g., and so on.\*(CB .EB "\s+2\f(HBCOMMAND LINE ARGUMENTS (\*(MK\f(HB)\*(FR\s0" .sp .7 -.\" --- Signals (pgawk) +.\" --- Signals (gawk --profile) .ES .fi -\*(CD\*(PK accepts two signals. +\*(CD\*(GK accepts two signals while profiling. \*(FCSIGUSR1\fP dumps a profile and function call stack to the profile file. It then continues to run. \*(FCSIGHUP\fP is similar, but exits.\*(CB -.EB "\s+2\f(HBSIGNALS (\*(PK\f(HB)\*(FR\s0" +.EB "\s+2\f(HBSIGNALS (\*(GK \f(HB\-\^\-profile)\*(FR\s0" .\" --- Lines And Statements .ES @@ -609,7 +613,11 @@ T} \*(FCORS\fP T{ Output record separator, a newline by default. T} -\*(CB\*(FCPROCINFO\fP T{ +\*(CB\*(FCPREC\fP T{ +The working precision of arbitrary precision floating-point +numbers, 53 by default. +T} +\*(FCPROCINFO\fP T{ Elements of this array provide access to information about the running AWK program. See \*(AM for details.\*(CD @@ -618,6 +626,10 @@ T} Length of the string matched by \*(FCmatch()\*(FR; \-1 if no match. T} +\*(CB\*(FCROUNDMODE\fP T{ +The rounding mode to use for arbitrary precision arithmetic, +by default \*(FC"N"\fP.\*(CD +T} \*(FCRS\fP T{ Input record separator, a newline by default (see \fHRecords\fP above). @@ -33,30 +33,6 @@ gawk \- pattern scanning and processing language ] .I program-text file .\|.\|. -.sp -.B pgawk -[ \*(PX or \*(GN style options ] -.B \-f -.I program-file -[ -.B \-\^\- -] file .\|.\|. -.br -.B pgawk -[ \*(PX or \*(GN style options ] -[ -.B \-\^\- -] -.I program-text -file .\|.\|. -.sp -.B dgawk -[ \*(PX or \*(GN style options ] -.B \-f -.I program-file -[ -.B \-\^\- -] file .\|.\|. .SH DESCRIPTION .I Gawk is the \*(GN Project's implementation of the \*(AK programming language. @@ -84,27 +60,31 @@ and .B ARGV pre-defined \*(AK variables. .PP -.I Pgawk -is the profiling version of -.IR gawk . -It is identical in every way to -.IR gawk , -except that programs run more slowly, -and it automatically produces an execution profile in the file +When +.I gawk +is invoked with the +.B \-\^\-profile +option, it starts gathering profiling statistics +from the execution of the program. +.I Gawk +runs more slowly in this mode, and automatically produces an execution +profile in the file .B awkprof.out when done. See the .B \-\^\-profile option, below. .PP -.I Dgawk -is an -.I awk -debugger. Instead of running the program directly, it loads the +.I Gawk +also has an integrated debugger. An interactive debugging session can +be started by supplying the +.B \-\^\-debug +option to the command line. In this mode of execution, +.I gawk +loads the AWK source code and then prompts for debugging commands. -Unlike -.IR gawk " and " pgawk ", " dgawk -only processes AWK program source provided with the +.I Gawk +can only debug AWK program source provided with the .B \-f option. The debugger is documented in \*(EP. @@ -117,8 +97,8 @@ while long options start with \*(lq\-\^\-\*(rq. Long options are provided for both \*(GN-specific features and for \*(PX-mandated features. .PP -.IR Gawk - -specific options are typically used in long-option form. +.IR Gawk -specific +options are typically used in long-option form. Arguments to long options are either joined with the option by an .B = @@ -273,6 +253,18 @@ names like and so on.) .TP .PD 0 +\fB\-D\fR[\fIfile\fR] +.TP +.PD +\fB\-\^\-debug\fR[\fB=\fIfile\fR] +Enable debugging of \*(AK programs. +By default, the debugger reads commands interactively from the terminal. +The optional +.IR file +argument can be used to specify a file with a list +of commands for the debugger to execute non-interactively. +.TP +.PD 0 .BI "\-e " program-text .TP .PD @@ -331,6 +323,21 @@ the standard output. these options cause an immediate, successful exit.) .TP .PD 0 +.BI "\-l " lib +.TP +.PD +.BI \-\^\-load " lib" +Load a shared library +.IR lib . +This searches for the library using the +.B AWKPATH +environment variable. The suffix +.I .so +in the library name is optional, and +the library initialization routine is expected to be named +.BR dlload() . +.TP +.PD 0 .BR "\-L " [ \fIvalue\fR ] .TP .PD @@ -348,6 +355,16 @@ only warnings about things that are actually invalid are issued. (This is not fully implemented yet.) .TP .PD 0 +.B \-M +.TP +.PD +.B \-\^\-bignum +Force arbitrary precision arithmetic on numbers. This option has +no effect if +.I gawk +is not compiled to use the GNU MPFR and MP libraries. +.TP +.PD 0 .B \-n .TP .PD @@ -387,12 +404,28 @@ users. .. .TP .PD 0 +\fB\-o\fR[\fIfile\fR] +.TP +.PD +\fB\-\^\-pretty-print\fR[\fB=\fIfile\fR] +Output a pretty printed version of the program to +.IR file . +If no +.I file +is provided, +.I gawk +uses a file named +.B awkprof.out +in the current directory. +.TP +.PD 0 .B \-O .TP .PD .B \-\^\-optimize Enable optimizations upon the internal representation of the program. -Currently, this includes just simple constant-folding. The +Currently, this includes simple constant-folding, and tail call +elimination for recursive functions. The .I gawk maintainer hopes to add additional optimizations over time. .TP @@ -401,16 +434,11 @@ maintainer hopes to add additional optimizations over time. .TP .PD \fB\-\^\-profile\fR[\fB=\fIprof_file\fR] -Send profiling data to +Start a profiling session, and send the profiling data to .IR prof_file . The default is .BR awkprof.out . -When run with -.IR gawk , -the profile is just a \*(lqpretty printed\*(rq version of the program. -When run with -.IR pgawk , -the profile contains execution counts of each statement in the program +The profile contains execution counts of each statement in the program in the left margin and function call counts for each user-defined function. .TP .PD 0 @@ -482,15 +510,6 @@ They are enabled by default, but this option remains for use with .BR \-\^-traditional . .TP .PD 0 -.B \-R -.TP -.PD -.BI \-\^\-command " file" -.I Dgawk -only. Read stored debugger commands from -.IR file . -.TP -.PD 0 .BI \-S .TP .PD @@ -1022,6 +1041,10 @@ The output field separator, a space by default. .B ORS The output record separator, by default a newline. .TP +.B PREC +The working precision of arbitrary precision floating-point +numbers, 53 by default. +.TP .B PROCINFO The elements of this array provide access to information about the running \*(AK program. @@ -1120,11 +1143,48 @@ corresponding values of the two elements being compared. It should return a number less than, equal to, or greater than 0, depending on how the elements of the array are to be ordered. .TP +\fBPROCINFO["input", "READ_TIMEOUT"]\fP +specifies the timeout in milliseconds for reading data from +.IR input , +where +.I input +is a redirection string or a filename. A value of zero or +less than zero means no timeout. +.TP +\fBPROCINFO["mpfr_version"]\fP +the version of the GNU MPFR library used for arbitrary precision +number support in +.IR gawk . +.TP +\fBPROCINFO["gmp_version"]\fP +the version of the GNU MP library used for arbitrary precision +number support in +.IR gawk . +.TP +\fBPROCINFO["prec_max"]\fP +the maximum precision supported by the GNU MPFR library for +arbitrary precision floating-point numbers. +.TP +\fBPROCINFO["prec_min"]\fP +the minimum precision allowed by the GNU MPFR library for +arbitrary precision floating-point numbers. +.TP \fBPROCINFO["version"]\fP the version of .IR gawk . .RE .TP +.B ROUNDMODE +The rounding mode to use for arbitrary precision arithmetic on +numbers, by default \fB"N"\fR (IEEE-754 roundTiesToEven mode). +The accepted values are +\fB"N"\fR or \fB"n"\fR for roundTiesToEven, +\fB"U"\fR or \fB"u"\fR for roundTowardPositive, +\fB"D"\fR or \fB"d"\fR for roundTowardNegative, +\fB"Z"\fR or \fB"z"\fR for roundTowardZero, +and if your version of GNU MPFR library supports it, +\fB"A"\fR or \fB"a"\fR for roundTiesToAway. +.TP .B RS The input record separator, by default a newline. .TP @@ -3122,8 +3182,9 @@ Using this feature at the C level is not pretty, but it is unlikely to go away. Additional mechanisms may be added at some point. .SH SIGNALS -.I pgawk -accepts two signals. +The +.I gawk +profiler accepts two signals. .B SIGUSR1 causes it to dump a profile and function call stack to the profile file, which is either @@ -3133,7 +3194,7 @@ or whatever file was named with the option. It then continues to run. .B SIGHUP causes -.I pgawk +.I gawk to dump the profile and function call stack and then exit. .SH INTERNATIONALIZATION .PP @@ -3577,6 +3638,12 @@ and .B \-\^\-file options. .PP +The +.B GAWK_READ_TIMEOUT +environment variable can be used to specify a timeout +in milliseconds for reading input from a terminal, pipe +or two-way communication including sockets. +.PP For socket communication, two special environment variables can be used to control the number of retries .RB ( GAWK_SOCK_RETRIES ), and the interval between retries diff --git a/doc/gawk.info b/doc/gawk.info index a33027cd..bf279828 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -89,12 +89,14 @@ texts being (a) (see below), and with the Back-Cover Texts being (b) * Functions:: Built-in and user-defined functions. * Internationalization:: Getting `gawk' to speak your language. +* Arbitrary Precision Arithmetic:: Arbitrary precision arithmetic with + `gawk'. * Advanced Features:: Stuff for advanced users, specific to `gawk'. * Library Functions:: A Library of `awk' Functions. * Sample Programs:: Many `awk' programs with complete explanations. -* Debugger:: The `dgawk' debugger. +* Debugger:: The `gawk' debugger. * Language History:: The evolution of the `awk' language. * Installation:: Installing `gawk' under various @@ -196,6 +198,7 @@ texts being (a) (see below), and with the Back-Cover Texts being (b) * Getline Notes:: Important things to know about `getline'. * Getline Summary:: Summary of `getline' Variants. +* Read Timeout:: Reading input with a timeout. * Command line directories:: What happens if you put a directory on the command line. * Print:: The `print' statement. @@ -353,6 +356,21 @@ texts being (a) (see below), and with the Back-Cover Texts being (b) * I18N Portability:: `awk'-level portability issues. * I18N Example:: A simple i18n example. * Gawk I18N:: `gawk' is also internationalized. +* Floating-point Programming:: Effective floating-point programming. +* Floating-point Representation:: Binary floating-point representation. +* Floating-point Context:: Floating-point context. +* Rounding Mode:: Floating-point rounding mode. +* Arbitrary Precision Floats:: Arbitrary precision floating-point + arithmetic with `gawk'. +* Setting Precision:: Setting the working precision. +* Setting Rounding Mode:: Setting the rounding mode. +* Floating-point Constants:: Representing floating-point constants. +* Changing Precision:: Changing the precision of a number. +* Exact Arithmetic:: Exact arithmetic with floating-point numbers. +* Integer Programming:: Effective integer programming. +* Arbitrary Precision Integers:: Arbitrary precision integer + arithmetic with `gawk'. +* MPFR and GMP Libraries:: Information about the MPFR and GMP libraries. * Nondecimal Data:: Allowing nondecimal input data. * Array Sorting:: Facilities for controlling array traversal and sorting arrays. @@ -417,23 +435,23 @@ texts being (a) (see below), and with the Back-Cover Texts being (b) * Anagram Program:: Finding anagrams from a dictionary. * Signature Program:: People do amazing things with too much time on their hands. -* Debugging:: Introduction to `dgawk'. -* Debugging Concepts:: Debugging In General. +* Debugging:: Introduction to `gawk' Debugger. +* Debugging Concepts:: Debugging in General. * Debugging Terms:: Additional Debugging Concepts. * Awk Debugging:: Awk Debugging. -* Sample dgawk session:: Sample `dgawk' session. -* dgawk invocation:: `dgawk' Invocation. -* Finding The Bug:: Finding The Bug. -* List of Debugger Commands:: Main `dgawk' Commands. -* Breakpoint Control:: Control of breakpoints. -* Dgawk Execution Control:: Control of execution. -* Viewing And Changing Data:: Viewing and changing data. -* Dgawk Stack:: Dealing with the stack. -* Dgawk Info:: Obtaining information about the program and - the debugger state. -* Miscellaneous Dgawk Commands:: Miscellaneous Commands. +* Sample Debugging Session:: Sample Debugging Session. +* Debugger Invocation:: How to Start the Debugger. +* Finding The Bug:: Finding the Bug. +* List of Debugger Commands:: Main Commands. +* Breakpoint Control:: Control of Breakpoints. +* Debugger Execution Control:: Control of Execution. +* Viewing And Changing Data:: Viewing and Changing Data. +* Execution Stack:: Dealing with the Stack. +* Debugger Info:: Obtaining Information about the Program and + the Debugger State. +* Miscellaneous Debugger Commands:: Miscellaneous Commands. * Readline Support:: Readline Support. -* Dgawk Limitations:: Limitations and future plans. +* Limitations:: Limitations and Future Plans. * V7/SVR3.1:: The major changes between V7 and System V Release 3.1. * SVR4:: Minor changes between System V Releases 3.1 @@ -489,6 +507,7 @@ texts being (a) (see below), and with the Back-Cover Texts being (b) * Internals:: A brief look at some `gawk' internals. * Plugin License:: A note about licensing. +* Loading Extensions:: How to load dynamic extensions. * Sample Library:: A example of new functions. * Internal File Description:: What the new functions will do. * Internal File Ops:: The code for internal file operations. @@ -849,7 +868,7 @@ and profile your `awk' programs. sample `awk' programs. Reading them allows you to see `awk' solving real problems. - *note Debugger::, describes the `awk' debugger, `dgawk'. + *note Debugger::, describes the `awk' debugger. *note Language History::, describes how the `awk' language has evolved since its first release to present. It also describes how @@ -1100,10 +1119,12 @@ it is today. It has been and continues to be a pleasure working with this team of fine people. John Haque contributed the modifications to convert `gawk' into a -byte-code interpreter, including the debugger. Stephen Davies -contributed to the effort to bring the byte-code changes into the -mainstream code base. Efraim Yawitz contributed the initial text of -*note Debugger::. +byte-code interpreter, including the debugger, and the additional +modifications for support of arbitrary precision arithmetic. Stephen +Davies contributed to the effort to bring the byte-code changes into +the mainstream code base. Efraim Yawitz contributed the initial text +of *note Debugger::. John Haque contributed the initial text of *note +Arbitrary Precision Arithmetic::. I would like to thank Brian Kernighan for invaluable assistance during the testing and debugging of `gawk', and for ongoing help and @@ -2216,6 +2237,15 @@ The following list describes options mandated by the POSIX standard: particularly easy mistake to make with simple variable names like `i', `j', etc.) +`-D[FILE]' +`--debug=[FILE]' + Enable debugging of `awk' programs (*note Debugging::). By + default, the debugger reads commands interactively from the + terminal. The optional FILE argument allows you to specify a file + with a list of commands for the debugger to execute + non-interactively. No space is allowed between the `-D' and FILE, + if FILE is supplied. + `-e PROGRAM-TEXT' `--source PROGRAM-TEXT' Provide program source code in the PROGRAM-TEXT. This option @@ -2258,6 +2288,13 @@ The following list describes options mandated by the POSIX standard: Print a "usage" message summarizing the short and long style options that `gawk' accepts and then exit. +`-l LIB' +`--load LIB' + Load a shared library LIB. This searches for the library using the + `AWKPATH' environment variable. The suffix `.so' in the library + name is optional. The library initialization routine should be + named `dlload()'. + `-L [value]' `--lint[=value]' Warn about constructs that are dubious or nonportable to other @@ -2277,6 +2314,12 @@ The following list describes options mandated by the POSIX standard: inappropriate construct. As `awk' programs are usually short, doing so is not burdensome. +`-M' +`--bignum' + Force arbitrary precision arithmetic on numbers. This option has + no effect if `gawk' is not compiled to use the GNU MPFR and MP + libraries (*note Arbitrary Precision Arithmetic::). + `-n' `--non-decimal-data' Enable automatic interpretation of octal and hexadecimal values in @@ -2290,6 +2333,14 @@ The following list describes options mandated by the POSIX standard: Force the use of the locale's decimal point character when parsing numeric input data (*note Locales::). +`-o[FILE]' +`--pretty-print[=FILE]' + Enable pretty-printing of `awk' programs. By default, output + program is created in a file named `awkprof.out'. The optional + FILE argument allows you to specify a different file name for the + output. No space is allowed between the `-o' and FILE, if FILE is + supplied. + `-O' `--optimize' Enable some optimizations on the internal representation of the @@ -2305,10 +2356,9 @@ The following list describes options mandated by the POSIX standard: for the profile file. No space is allowed between the `-p' and FILE, if FILE is supplied. - When run with `gawk', the profile is just a "pretty printed" - version of the program. When run with `pgawk', the profile - contains execution counts for each statement in the program in the - left margin, and function call counts for each function. + The profile contains execution counts for each statement in the + program in the left margin, and function call counts for each + function. `-P' `--posix' @@ -2342,11 +2392,6 @@ The following list describes options mandated by the POSIX standard: remains both for backward compatibility, and for use in combination with the `--traditional' option. -`-R FILE' -`--command=FILE' - `dgawk' only. Read `dgawk' debugger options and commands from - FILE. *Note Dgawk Info::, for more information. - `-S' `--sandbox' Disable the `system()' function, input redirections with `getline', @@ -2611,6 +2656,10 @@ used by regular users. milliseconds. On systems that do not support the `usleep()' system call, the value is rounded up to an integral number of seconds. +`GAWK_READ_TIMEOUT' + Specifies the time, in milliseconds, for `gawk' to wait for input + before returning with an error. *Note Read Timeout::. + The environment variables in the following list are meant for use by the `gawk' developers for testing and tuning. They are subject to change. The variables are: @@ -3612,6 +3661,8 @@ have to be named on the `awk' command line (*note Getline::). * Multiple Line:: Reading multi-line records. * Getline:: Reading files under explicit program control using the `getline' function. +* Read Timeout:: Reading input with a timeout. + * Command line directories:: What happens if you put a directory on the command line. @@ -4799,7 +4850,7 @@ feature of `RS' does not apply. It does apply to the default field separator of a single space: `FS = " "'. -File: gawk.info, Node: Getline, Next: Command line directories, Prev: Multiple Line, Up: Reading Files +File: gawk.info, Node: Getline, Next: Read Timeout, Prev: Multiple Line, Up: Reading Files 4.9 Explicit Input with `getline' ================================= @@ -5224,9 +5275,101 @@ VAR Table 4.1: getline Variants and What They Set -File: gawk.info, Node: Command line directories, Prev: Getline, Up: Reading Files +File: gawk.info, Node: Read Timeout, Next: Command line directories, Prev: Getline, Up: Reading Files + +4.10 Reading Input With A Timeout +================================= + +You may specify a timeout in milliseconds for reading input from a +terminal, pipe or two-way communication including, TCP/IP sockets. This +can be done on a per input, command or connection basis, by setting a +special element in the `PROCINFO' array: + + PROCINFO["input_name", "READ_TIMEOUT"] = TIMEOUT IN MILLISECONDS + + When set, this will cause `gawk' to time out and return failure if +no data is available to read within the specified timeout period. For +example, a TCP client can decide to give up on receiving any response +from the server after a certain amount of time: + + Service = "/inet/tcp/0/localhost/daytime" + PROCINFO[Service, "READ_TIMEOUT"] = 100 + if ((Service |& getline) > 0) + print $0 + else if (ERRNO != "") + print ERRNO + + Here is how to read interactively from the terminal(1) without +waiting for more than five seconds: + + PROCINFO["/dev/stdin", "READ_TIMEOUT"] = 5000 + while ((getline < "/dev/stdin") > 0) + print $0 + + `gawk' will terminate the read operation if input does not arrive +after waiting for the timeout period, return failure and set the +`ERRNO' variable to an appropriate string value. A negative or zero +value for the timeout is the same as specifying no timeout at all. + + A timeout can also be set for reading from the terminal in the +implicit loop that reads input records and matches them against +patterns, like so: + + $ gawk 'BEGIN { PROCINFO["-", "READ_TIMEOUT"] = 5000 } + > { print "You entered: " $0 }' + gawk + -| You entered: gawk + + In this case, failure to respond within five seconds results in the +following error message: + + error--> gawk: cmd. line:2: (FILENAME=- FNR=1) fatal: error reading input file `-': Connection timed out + + The timeout can be set or changed at any time, and will take effect +on the next attempt to read from the input device. In the following +example, we start with a timeout value of one second, and progressively +reduce it by one-tenth of a second until we wait indefinitely for the +input to arrive: + + PROCINFO[Service, "READ_TIMEOUT"] = 1000 + while ((Service |& getline) > 0) { + print $0 + PROCINFO[S, "READ_TIMEOUT"] -= 100 + } + + NOTE: You should not assume that the read operation will block + exactly after the tenth record has been printed. It is possible + that `gawk' will read and buffer more than one record's worth of + data the first time. Because of this, changing the value of + timeout like in the above example is not very useful. + + If the `PROCINFO' element is not present and the environment +variable `GAWK_READ_TIMEOUT' exists, `gawk' uses its value to +initialize the timeout value. The exclusive use of the environment +variable to specify timeout has the disadvantage of not being able to +control it on a per command or connection basis. + + `gawk' considers a timeout event to be an error even though the +attempt to read from the underlying device may succeed in a later +attempt. This is a limitation, and it also means that you cannot use +this to multiplex input from two or more sources. + + Assigning a timeout value prevents read operations from blocking +indefinitely. But bear in mind that there are other ways `gawk' can +stall waiting for an input device to be ready. A network client can +sometimes take a long time to establish a connection before it can +start reading any data, or the attempt to open a FIFO special file for +reading can block indefinitely until some other process opens it for +writing. + + ---------- Footnotes ---------- -4.10 Directories On The Command Line + (1) This assumes that standard input is the keyboard + + +File: gawk.info, Node: Command line directories, Prev: Read Timeout, Up: Reading Files + +4.11 Directories On The Command Line ==================================== According to the POSIX standard, files named on the `awk' command line @@ -9185,6 +9328,15 @@ specific to `gawk' are marked with a pound sign (`#'). every `print' statement. Its default value is `"\n"', the newline character. (*Note Output Separators::.) +`PREC #' + The working precision of arbitrary precision floating-point + numbers, 53 by default (*note Setting Precision::). + +`ROUNDMODE #' + The rounding mode to use for arbitrary precision arithmetic on + numbers, by default `"N"' (`roundTiesToEven' in the IEEE-754 + standard) (*note Setting Rounding Mode::). + `RS' This is `awk''s input record separator. Its default value is a string containing a single newline character, which means that an @@ -9390,6 +9542,23 @@ with a pound sign (`#'). `PROCINFO["version"]' The version of `gawk'. + The following additional elements in the array are available to + provide information about the MPFR and GMP libraries if your + version of `gawk' supports arbitrary precision numbers (*note + Arbitrary Precision Arithmetic::): + + `PROCINFO["mpfr_version"]' + The version of the GNU MPFR library. + + `PROCINFO["gmp_version"]' + The version of the GNU MP library. + + `PROCINFO["prec_max"]' + The maximum precision supported by MPFR. + + `PROCINFO["prec_min"]' + The minimum precision required by MPFR. + On some systems, there may be elements in the array, `"group1"' through `"groupN"' for some N. N is the number of supplementary groups that the process has. Use the `in' operator to test for @@ -12903,7 +13072,7 @@ example, in the following case: `gawk' will look up the actual function to call only once. -File: gawk.info, Node: Internationalization, Next: Advanced Features, Prev: Functions, Up: Top +File: gawk.info, Node: Internationalization, Next: Arbitrary Precision Arithmetic, Prev: Functions, Up: Top 10 Internationalization with `gawk' *********************************** @@ -13483,9 +13652,745 @@ writing, the latest version of GNU `gettext' is version 0.18.1 usage messages, warnings, and fatal errors in the local language. -File: gawk.info, Node: Advanced Features, Next: Library Functions, Prev: Internationalization, Up: Top +File: gawk.info, Node: Arbitrary Precision Arithmetic, Next: Advanced Features, Prev: Internationalization, Up: Top + +11 Arbitrary Precision Arithmetic with `gawk' +********************************************* + + There's a credibility gap: We don't know how much of the + computer's answers to believe. Novice computer users solve this + problem by implicitly trusting in the computer as an infallible + authority; they tend to believe that all digits of a printed + answer are significant. Disillusioned computer users have just the + opposite approach; they are constantly afraid that their answers + are almost meaningless. + + Donald Knuth(1) + + This minor node decsribes how to use the arbitrary precision (also +known as "multiple precision" or "infinite precision") numeric +capabilites in `gawk' to produce maximally accurate results when you +need it. But first you should check if your version of `gawk' supports +arbitrary precision arithmetic. The easiest way to find out is to look +at the output of the following command: + + $ gawk --version + -| GNU Awk 4.1.0 (GNU MPFR 3.1.0, GNU MP 5.0.3) + -| Copyright (C) 1989, 1991-2012 Free Software Foundation. + ... + + `gawk' uses the GNU MPFR (http://www.mpfr.org) and GNU MP +(http://gmplib.org) (GMP) libraries for arbitrary precision arithmetic +on numbers. So if you do not see the names of these libraries in the +output, then your version of `gawk' does not support arbitrary +precision arithmetic. + + Even if you aren't interested in arbitrary precision arithmetic, you +may still benifit from knowing about how `gawk' handles numbers in +general, and the limitations of doing arithmetic with ordinary `gawk' +numbers. + +* Menu: + +* Floating-point Programming:: Effective Floating-point Programming. +* Floating-point Representation:: Binary Floating-point Representation. +* Floating-point Context:: Floating-point Context. +* Rounding Mode:: Floating-point Rounding Mode. +* Arbitrary Precision Floats:: Arbitrary Precision Floating-point + Arithmetic with `gawk'. +* Setting Precision:: Setting the Working Precision. +* Setting Rounding Mode:: Setting the Rounding Mode. +* Floating-point Constants:: Representing Floating-point Constants. +* Changing Precision:: Changing the Precision of a Number. +* Exact Arithmetic:: Exact Arithmetic with Floating-point Numbers. +* Integer Programming:: Effective Integer Programming. +* Arbitrary Precision Integers:: Arbitrary Precision Integer + Arithmetic with `gawk'. +* MPFR and GMP Libraries:: Information About the MPFR and GMP Libraries. + + ---------- Footnotes ---------- + + (1) Donald E. Knuth. `The Art of Computer Programming'. Volume 2, +`Seminumerical Algorithms', third edition, 1998, ISBN 0-201-89683-4, p. +229. + + +File: gawk.info, Node: Floating-point Programming, Next: Floating-point Representation, Up: Arbitrary Precision Arithmetic + +11.1 Effective Floating-point Programming +========================================= + +Numerical programming is an extensive area; if you need to develop +sophisticated numerical algorithms then `gawk' may not be the ideal +tool, and this documentation may not be sufficient. It might require a +book or two to communicate how to compute with ideal accuracy and +precision and the result often depends on the particular application. + + NOTE: A floating-point calculation's "accuracy" is how close it + comes to the real value. This is as opposed to the "precision", + which usually refers to the number of bits used to represent the + number (see the Wikipedia article + (http://en.wikipedia.org/wiki/Accuracy_and_precision) for more + information). + + Binary floating-point representations and arithmetic are inexact. +Simple values like 0.1 cannot be precisely represented using binary +floating-point numbers, and the limited precision of floating-point +numbers means that slight changes in the order of operations or the +precision of intermediate storage can change the result. To make +matters worse with arbitrary precision floating-point, you can set the +precision before starting a computation, but then you cannot be sure of +the number of significant decimal places in the final result. + + Sometimes you need to think more about what you really want and +what's really happening. Consider the two numbers in the following +example: + + x = 0.875 # 1/2 + 1/4 + 1/8 + y = 0.425 + + Unlike the number in `y', the number stored in `x' is exactly +representable in binary since it can be written as a finite sum of one +or more fractions whose denominators are all powers of two. When +`gawk' reads a floating-point number from program source, it +automatically rounds that number to whatever precision your machine +supports. If you try to print the numeric content of a variable using +an output format string of `"%.17g"', it may not produce the same +number as you assigned to it: + + $ gawk 'BEGIN { x = 0.875; y = 0.425 + > printf("%0.17g, %0.17g\n", x, y) }' + -| 0.875, 0.42499999999999999 + + Often the error is so small you do not even notice it, and if you do, +you can always specify how much precision you would like in your output. +Usually this is a format string like `"%.15g"', which when used in the +previous example, produces an output identical to the input. + + Because the underlying representation can be little bit off from the +exact value, comparing floats to see if they are equal is generally not +a good idea. Here is an example where it does not work like you expect: + + $ gawk 'BEGIN { print (0.1 + 12.2 == 12.3) }' + -| 0 + + The loss of accuracy during a single computation with floating-point +numbers usually isn't enough to worry about. However, if you compute a +value which is the result of a sequence of floating point operations, +the error can accumulate and greatly affect the computation itself. +Here is an attempt to compute the value of the constant pi using one of +its many series representations: + + BEGIN { + x = 1.0 / sqrt(3.0) + n = 6 + for (i = 1; i < 30; i++) { + n = n * 2.0 + x = (sqrt(x * x + 1) - 1) / x + printf("%.15f\n", n * x) + } + } + + When run, the early errors propagating through later computations +cause the loop to terminate prematurely after an attempt to divide by +zero. + + $ gawk -f pi.awk + -| 3.215390309173475 + -| 3.159659942097510 + -| 3.146086215131467 + -| 3.142714599645573 + ... + -| 3.224515243534819 + -| 2.791117213058638 + -| 0.000000000000000 + error--> gawk: pi.awk:6: fatal: division by zero attempted + + Here is one more example where the inaccuracies in internal +representations yield an unexpected result: + + $ gawk 'BEGIN { + > for (d = 1.1; d <= 1.5; d += 0.1) + > i++ + > print i + > }' + -| 4 + + Can computation using aribitrary precision help with the previous +examples? If you are impatient to know, see *note Exact Arithmetic::. + + Instead of aribitrary precision floating-point arithmetic, often all +you need is an adjustment of your logic or a different order for the +operations in your calculation. The stability and the accuracy of the +computation of the constant pi in the previous example can be enhanced +by using the following simple algebraic transformation: + + (sqrt(x * x + 1) - 1) / x = x / (sqrt(x * x + 1) + x) + + There is no need to be unduly suspicious about the results from +floating-point arithmetic. The lesson to remember is that +floating-point math is always more complex than the math using pencil +and paper. In order to take advantage of the power of computer +floating-point, you need to know its limitations and work within them. +For most casual use of floating-point arithmetic, you will often get +the expected result in the end if you simply round the display of your +final results to the correct number of significant decimal digits. +Avoid presenting numerical data in a manner that implies better +precision than is actually the case. + + +File: gawk.info, Node: Floating-point Representation, Next: Floating-point Context, Prev: Floating-point Programming, Up: Arbitrary Precision Arithmetic + +11.2 Binary Floating-point Representation +========================================= + +Although floating-point representations vary from machine to machine, +the most commonly encountered representation is that defined by the +IEEE 754 Standard. An IEEE-754 format value has three components: + + * a sign bit telling whether the number is positive or negative, + + * an "exponent" giving its order of magnitude, E, + + * and a "significand", S, specifying the actual digits of the number. + + The value of the number is then S * 2^E. The first bit of a +non-zero binary significand is always one, so the significand in an +IEEE-754 format only includes the fractional part, leaving the leading +one implicit. + + Three of the standard IEEE-754 types are 32-bit single precision, +64-bit double precision and 128-bit quadruple precision. The standard +also specifies extended precision formats to allow greater precisions +and larger exponent ranges. + + +File: gawk.info, Node: Floating-point Context, Next: Rounding Mode, Prev: Floating-point Representation, Up: Arbitrary Precision Arithmetic + +11.3 Floating-point Context +=========================== + +A floating-point context defines the environment for arithmetic +operations. It governs precision, sets rules for rounding and limits +range for exponents. The context has the following primary components: + +`precision' + Precision of the floating-point format in bits. + +`emax' + Maximum exponent allowed for this format. + +`emin' + Minimum exponent allowed for this format. + +`underflow behavior' + The format may or may not support gradual underflow. + +`rounding' + The rounding mode of this context. + + *note table-ieee-formats:: lists the precision and exponent field +values for the basic IEEE-754 binary formats: + +Name Total bits Precision emin emax +--------------------------------------------------------------------------- +Single 32 24 -126 +127 +Double 64 53 -1022 +1023 +Quadruple 128 113 -16382 +16383 + +Table 11.1: Basic IEEE Formats + + NOTE: The precision numbers include the implied leading one that + gives them one extra bit of significand. + + A floating-point context can also determine which signals are treated +as exceptions, and can set rules for arithmetic with special values. +Please consult the IEEE-754 standard or other resources for details. + + `gawk' ordinarily uses the hardware double precision representation +for numbers. On most systems, this is IEEE-754 floating-point format, +corresponding to 64-bit binary with 53 bits of precision. + + NOTE: In case an underflow occurs, the standard allows, but does + not require, the result from an arithmetic operation to be a + number smaller than the smallest nonzero normalized number. Such + numbers do not have as many significant digits as normal numbers, + and are called "denormals" or "subnormals". The alternative, + simply returning a zero, is called "flush to zero". The basic + IEEE-754 binary formats support subnormal numbers. + + +File: gawk.info, Node: Rounding Mode, Next: Arbitrary Precision Floats, Prev: Floating-point Context, Up: Arbitrary Precision Arithmetic + +11.4 Floating-point Rounding Mode +================================= + +The "rounding mode" specifies the behavior for the results of numerical +operations when discarding extra precision. Each rounding mode indicates +how the least significant returned digit of a rounded result is to be +calculated. The `ROUNDMODE' variable (*note Setting Rounding Mode::) +provides program level control over the rounding mode. *note +table-rounding-modes:: lists the IEEE-754 defined rounding modes: + +Rounding Mode IEEE Name `ROUNDMODE' +--------------------------------------------------------------------------- +Round to nearest, ties to even `roundTiesToEven' `"N"' or `"n"' +Round toward plus Infinity `roundTowardPositive' `"U"' or `"u"' +Round toward negative Infinity `roundTowardNegative' `"D"' or `"d"' +Round toward zero `roundTowardZero' `"Z"' or `"z"' +Round to nearest, ties away `roundTiesToAway' `"A"' or `"a"' +from zero + +Table 11.2: Rounding Modes + + The default mode `roundTiesToEven' is the most preferred, but the +least intuitive. This method does the obvious thing for most values, by +rounding them up or down to the nearest digit. For example, rounding +1.132 to two digits yields 1.13, and rounding 1.157 yields 1.16. + + However, when it comes to rounding a value that is exactly halfway +between, things do not work the way you probably learned in school. In +this case, the number is rounded to the nearest even digit. So +rounding 0.125 to two digits rounds down to 0.12, but rounding 0.6875 +to three digits rounds up to 0.688. You probably have already +encountered this rounding mode when using the `printf' routine to +format floating-point numbers. For example: -11 Advanced Features of `gawk' + BEGIN { + x = -4.5 + for (i = 1; i < 10; i++) { + x += 1.0 + printf("%4.1f => %2.0f\n", x, x) + } + } + +produces the following output when run(1): + + -3.5 => -4 + -2.5 => -2 + -1.5 => -2 + -0.5 => 0 + 0.5 => 0 + 1.5 => 2 + 2.5 => 2 + 3.5 => 4 + 4.5 => 4 + + The theory behind the rounding mode `roundTiesToEven' is that it +more or less evenly distributes upward and downward rounds of exact +halves, which might cause the round-off error to cancel itself out. +This is the default rounding mode used in IEEE-754 computing functions +and operators. + + The other rounding modes are rarely used. Round toward positive +infinity (`roundTowardPositive') and round toward negative infinity +(`roundTowardNegative') are often used to implement interval arithmetic, +where you adjust the rounding mode to calculate upper and lower bounds +for the range of output. The `roundTowardZero' mode can be used for +converting floating-point numbers to integers. The rounding mode +`roundTiesToAway' rounds the result to the nearest number and selects +the number with the larger magnitude if a tie occurs. + + Some numerical analysts will tell you that your choice of rounding +style has tremendous impact on the final outcome, and advise you to +wait until final output for any rounding. Instead, you can often +achieve this goal by setting the precision initially to some value +sufficiently larger than the final desired precision, so that the +accumulation of round-off error does not influence the outcome. If you +suspect that results from your computation are sensitive to +accumulation of round-off error, one way to be sure is to look for a +significant difference in output when you change the rounding mode. + + ---------- Footnotes ---------- + + (1) It is possible for the output to be completely different if the +C library in your system does not use the IEEE-754 even-rounding rule +to round halfway cases for `printf()'. + + +File: gawk.info, Node: Arbitrary Precision Floats, Next: Setting Precision, Prev: Rounding Mode, Up: Arbitrary Precision Arithmetic + +11.5 Arbitrary Precision Floating-point Arithmetic with `gawk' +============================================================== + +`gawk' uses the GNU MPFR library for arbitrary precision floating-point +arithmetic. The MPFR library provides precise control over precisions +and rounding modes, and gives correctly rounded reproducible +platform-independent results. With the command-line option `--bignum' +or `-M', all floating-point arithmetic operators and numeric functions +can yield results to any desired precision level supported by MPFR. +Two built-in variables `PREC' (*note Setting Precision::) and +`ROUNDMODE' (*note Setting Rounding Mode::) provide control over the +working precision and the rounding mode. The precision and the +rounding mode are set globally for every operation to follow. + + The default working precision for arbitrary precision floats is 53, +and the default value for `ROUNDMODE' is `"N"', which selects the +IEEE-754 `roundTiesToEven' (*note Rounding Mode::) rounding mode.(1) +`gawk' uses the default exponent range in MPFR (EMAX = 2^30 - 1, EMIN = +-EMAX) for all floating-point contexts. There is no explicit mechanism +to adjust the exponent range. MPFR does not implement subnormal +numbers by default, and this behavior cannot be changed in `gawk'. + + NOTE: When emulating an IEEE-754 format (*note Setting + Precision::), `gawk' internally adjusts the exponent range to the + value defined for the format and also performs computations needed + for gradual underflow (subnormal numbers). + + NOTE: MPFR numbers are variable-size entities, consuming only as + much space as needed to store the significant digits. Since the + performance using MPFR numbers pales in comparison to doing math + using the underlying machine types, you should consider using only + as much precision as needed by your program. + + ---------- Footnotes ---------- + + (1) The default precision is 53, since according to the MPFR +documentation, the library should be able to exactly reproduce all +computations with double-precision machine floating-point numbers +(`double' type in C), except the default exponent range is much wider +and subnormal numbers are not implemented. + + +File: gawk.info, Node: Setting Precision, Next: Setting Rounding Mode, Prev: Arbitrary Precision Floats, Up: Arbitrary Precision Arithmetic + +11.6 Setting the Working Precision +================================== + +`gawk' uses a global working precision; it does not keep track of the +precision or accuracy of individual numbers. Performing an arithmetic +operation or calling a built-in function rounds the result to the +current working precision. The default working precision is 53 which +can be modified using the built-in variable `PREC'. You can also set the +value to one of the following pre-defined case-insensitive strings to +emulate an IEEE-754 binary format: + +`PREC' IEEE-754 Binary Format +--------------------------------------------------- +`"half"' 16-bit half-precision. +`"single"' Basic 32-bit single precision. +`"double"' Basic 64-bit double precision. +`"quad"' Basic 128-bit quadruple precision. +`"oct"' 256-bit octuple precision. + + The following example illustrates the effects of changing precision +on arithmetic operations: + + $ gawk -M -vPREC=100 'BEGIN { x = 1.0e-400; print x + 0; \ + > PREC = "double"; print x + 0 }' + -| 1e-400 + -| 0 + + Binary and decimal precisions are related approximately according to +the formula: + + PREC = 3.322 * DPS + +Here, PREC denotes the binary precision (measured in bits) and DPS +(short for decimal places) is the decimal digits. We can easily +calculate how many decimal digits the 53-bit significand of an IEEE +double is equivalent to: 53 / 3.332 which is equal to about 15.95. But +what does 15.95 digits actually mean? It depends whether you are +concerned about how many digits you can rely on, or how many digits you +need. + + It is important to know how many bits it takes to uniquely identify +a double-precision value (the C type `double'). If you want to convert +from `double' to decimal and back to `double' (e.g., saving a `double' +representing an intermediate result to a file, and later reading it +back to restart the computation), then a few more decimal digits are +required. 17 digits is generally enough for a `double'. + + It can also be important to know what decimal numbers can be uniquely +represented with a `double'. If you want to convert from decimal to +`double' and back again, 15 digits is the most that you can get. Stated +differently, you should not present the numbers from your +floating-point computations with more than 15 significant digits in +them. + + Conversely, it takes a precision of 332 bits to hold an approximation +of constant pi that is accurate to 100 decimal places. You should +always add some extra bits in order to avoid the confusing round-off +issues that occur because numbers are stored internally in binary. + + +File: gawk.info, Node: Setting Rounding Mode, Next: Floating-point Constants, Prev: Setting Precision, Up: Arbitrary Precision Arithmetic + +11.7 Setting the Rounding Mode +============================== + +The built-in variable `ROUNDMODE' has the default value `"N"', which +selects the IEEE-754 rounding mode `roundTiesToEven'. The other +possible values for `ROUNDMODE' are `"U"' for rounding mode +`roundTowardPositive', `"D"' for `roundTowardNegative', and `"Z"' for +`roundTowardZero'. `gawk' also accepts `"A"' to select the IEEE-754 +mode `roundTiesToAway' if your version of the MPFR library supports it; +otherwise setting `ROUNDMODE' to this value has no effect. *Note +Rounding Mode::, for the meanings of the various rounding modes. + + Here is an example of how to change the default rounding behavior of +`printf''s output: + + $ gawk -M -vROUNDMODE="Z" 'BEGIN { printf("%.2f\n", 1.378) }' + -| 1.37 + + +File: gawk.info, Node: Floating-point Constants, Next: Changing Precision, Prev: Setting Rounding Mode, Up: Arbitrary Precision Arithmetic + +11.8 Representing Floating-point Constants +========================================== + +Be wary of floating-point constants! When reading a floating-point +constant from program source code, `gawk' uses the default precision, +unless overridden by an assignment to the special variable `PREC' on +the command line, to store it internally as a MPFR number. Changing +the precision using `PREC' in the program text does not change the +precision of a constant. If you need to represent a floating-point +constant at a higher precision than the default and cannot use a +command line assignment to `PREC', you should either specify the +constant as a string, or a rational number whenever possible. The +following example illustrates the differences among various ways to +print a floating-point constant: + + $ gawk -M 'BEGIN { PREC = 113; printf("%0.25f\n", 0.1) }' + -| 0.1000000000000000055511151 + $ gawk -M -vPREC = 113 'BEGIN { printf("%0.25f\n", 0.1) }' + -| 0.1000000000000000000000000 + $ gawk -M 'BEGIN { PREC = 113; printf("%0.25f\n", "0.1") }' + -| 0.1000000000000000000000000 + $ gawk -M 'BEGIN { PREC = 113; printf("%0.25f\n", 1/10) }' + -| 0.1000000000000000000000000 + + In the first case, the number is stored with the default precision +of 53. + + +File: gawk.info, Node: Changing Precision, Next: Exact Arithmetic, Prev: Floating-point Constants, Up: Arbitrary Precision Arithmetic + +11.9 Changing the Precision of a Number +======================================= + + The point is that in any variable-precision package, a decision is + made on how to treat numbers given as data, or arising in + intermediate results, which are represented in floating-point + format to a precision lower than working precision. Do we promote + them to full membership of the high-precision club, or do we treat + them and all their associates as second-class citizens? Sometimes + the first course is proper, sometimes the second, and it takes + careful analysis to tell which. + + Dirk Laurie(1) + + `gawk' does not implicitly modify the precision of any previously +computed results when the working precision is changed with an +assignment to `PREC'. The precision of a number is always the one that +was used at the time of its creation, and there is no way for the user +to explicitly change it afterwards. However, since the result of a +floating-point arithmetic operation is always an arbitrary precision +floating-point value--with a precision set by the value of `PREC'--one +of the following workarounds effectively accomplishes the desired +behavior: + + x = x + 0.0 + +or: + + x += 0.0 + + ---------- Footnotes ---------- + + (1) Dirk Laurie. `Variable-precision Arithmetic Considered Perilous +- A Detective Story'. Electronic Transactions on Numerical Analysis. +Volume 28, pp. 168-173, 2008. + + +File: gawk.info, Node: Exact Arithmetic, Next: Integer Programming, Prev: Changing Precision, Up: Arbitrary Precision Arithmetic + +11.10 Exact Arithmetic with Floating-point Numbers +================================================== + + CAUTION: Never depend on the exactness of floating-point + arithmetic, even for apparently simple expressions! + + Can arbitrary precision arithmetic give exact results? There are no +easy answers. The standard rules of algebra often do not apply when +using floating-point arithmetic. Among other things, the distributive +and associative laws do not hold completely, and order of operation may +be important for your computation. Rounding error, cumulative precision +loss and underflow are often troublesome. + + When `gawk' tests the expressions `0.1 + 12.2' and `12.3' for +equality using the machine double precision arithmetic, it decides that +they are not equal! (*Note Floating-point Programming::.) You can get +the result you want by increasing the precision; 56 in this case will +get the job done: + + $ gawk -M -vPREC=56 'BEGIN { print (0.1 + 12.2 == 12.3) }' + -| 1 + + If adding more bits is good, perhaps adding even more bits of +precision is better? Here is what happens if we use an even larger +value of `PREC': + + $ gawk -M -vPREC=201 'BEGIN { print (0.1 + 12.2 == 12.3) }' + -| 0 + + This is not a bug in `gawk' or in the MPFR library. It is easy to +forget that the finite number of bits used to store the value is often +just an approximation after proper rounding. The test for equality +succeeds if and only if _all_ bits in the two operands are exactly the +same. Since this is not necessarily true after floating-point +computations with a particular precision and effective rounding rule, a +straight test for equality may not work. + + So, don't assume that floating-point values can be compared for +equality. You should also exercise caution when using other forms of +comparisons. The standard way to compare between floating-point +numbers is to determine how much error (or "tolerance") you will allow +in a comparison and check to see if one value is within this error +range of the other. + + In applications where 15 or fewer decimal places suffice, hardware +double precision arithmetic can be adequate, and is usually much faster. +But you do need to keep in mind that every floating-point operation can +suffer a new rounding error with catastrophic consequences as +illustrated by our attempt to compute the value of the constant pi, +(*note Floating-point Programming::). Extra precision can greatly +enhance the stability and the accuracy of your computation in such +cases. + + Repeated addition is not necessarily equivalent to multiplication in +floating-point arithmetic. In the last example (*note Floating-point +Programming::), you may or may not succeed in getting the correct +result by choosing an arbitrarily large value for `PREC'. Reformulation +of the problem at hand is often the correct approach in such situations. + + +File: gawk.info, Node: Integer Programming, Next: Arbitrary Precision Integers, Prev: Exact Arithmetic, Up: Arbitrary Precision Arithmetic + +11.11 Effective Integer Programming +=================================== + +As has been mentioned already, `gawk' ordinarily uses hardware double +precision with 64-bit IEEE binary floating-point representation for +numbers on most systems. A large integer like 9007199254740997 has a +binary representation that, although finite, is more than 53 bits long; +it must also be rounded to 53 bits. The biggest integer that can be +stored in a C `double' is usually the same as the largest possible +value of a `double'. If your system `double' is an IEEE 64-bit +`double', this largest possible value is an integer and can be +represented precisely. What more should one know about integers? + + If you want to know what is the largest integer, such that it and +all smaller integers can be stored in 64-bit doubles without losing +precision, then the answer is 2^53. The next representable number is +the even number 2^53 + 2, meaning it is unlikely that you will be able +to make `gawk' print 2^53 + 1 in integer format. The range of integers +exactly representable by a 64-bit double is [-2^53, 2^53]. If you ever +see an integer outside this range in `gawk' using 64-bit doubles, you +have reason to be very suspicious about the accuracy of the output. +Here is a simple program with erroneous output: + + $ gawk 'BEGIN { i = 2^53 - 1; for (j = 0; j < 4; j++) print i + j }' + -| 9007199254740991 + -| 9007199254740992 + -| 9007199254740992 + -| 9007199254740994 + + The lesson is to not assume that any large integer printed by `gawk' +represents an exact result from your computation, especially if it wraps +around on your screen. + + +File: gawk.info, Node: Arbitrary Precision Integers, Next: MPFR and GMP Libraries, Prev: Integer Programming, Up: Arbitrary Precision Arithmetic + +11.12 Arbitrary Precision Integer Arithmetic with `gawk' +======================================================== + +If the option `--bignum' or `-M' is specified, `gawk' performs all +integer arithmetic using GMP arbitrary precision integers. Any number +that looks like an integer in a program source or data file is stored +as an arbitrary precision integer. The size of the integer is limited +only by your computer's memory. The current floating-point context has +no effect on operations involving integers. For example, the following +computes 5^4^3^2, the result of which is beyond the limits of ordinary +`gawk' numbers: + + $ gawk -M 'BEGIN { + > x = 5^4^3^2 + > print "# of digits =", length(x) + > print substr(x, 1, 20), "...", substr(x, length(x) - 19, 20) + > }' + -| # of digits = 183231 + -| 62060698786608744707 ... 92256259918212890625 + + If you were to compute the same value using arbitrary precision +floating-point values instead, the precision needed for correct output +(using the formula `prec = 3.322 * dps'), would be 3.322 x 183231, or +608693. + + The result from an arithmetic operation with an integer and a +floating-point value is a floating-point value with a precision equal +to the working precision. The following program calculates the eighth +term in Sylvester's sequence(1) using a recurrence: + + $ gawk -M 'BEGIN { + > s = 2.0 + > for (i = 1; i <= 7; i++) + > s = s * (s - 1) + 1 + > print s + > }' + -| 113423713055421845118910464 + + The output differs from the acutal number, +113423713055421844361000443, because the default precision of 53 is not +enough to represent the floating-point results exactly. You can either +increase the precision (100 is enough in this case), or replace the +floating-point constant `2.0' with an integer, to perform all +computations using integer arithmetic to get the correct output. + + It will sometimes be necessary for `gawk' to implicitly convert an +arbitrary precision integer into an arbitrary precision floating-point +value. This is primarily because the MPFR library does not always +provide the relevant interface to process arbitrary precision integers +or mixed-mode numbers as needed by an operation or function. In such a +case, the precision is set to the minimum value necessary for exact +conversion, and the working precision is not used for this purpose. If +this is not what you need or want, you can employ a subterfuge like +this: + + gawk -M 'BEGIN { n = 13; print (n + 0.0) % 2.0 }' + + You can avoid this issue altogether by specifying the number as a +float to begin with: + + gawk -M 'BEGIN { n = 13.0; print n % 2.0 }' + + Note that for the particular example above, there is unlikely to be a +reason for simply not using the following: + + gawk -M 'BEGIN { n = 13; print n % 2 }' + + ---------- Footnotes ---------- + + (1) Weisstein, Eric W. `Sylvester's Sequence'. From MathWorld-A +Wolfram Web Resource. +`http://mathworld.wolfram.com/SylvestersSequence.html' + + +File: gawk.info, Node: MPFR and GMP Libraries, Prev: Arbitrary Precision Integers, Up: Arbitrary Precision Arithmetic + +11.13 Information About the MPFR and GMP Libraries +================================================== + +There are a few elements available in the `PROCINFO' array to provide +information about the MPFR and GMP libraries. *Note Auto-set::, for +more information. + + +File: gawk.info, Node: Advanced Features, Next: Library Functions, Prev: Arbitrary Precision Arithmetic, Up: Top + +12 Advanced Features of `gawk' ****************************** Write documentation as if whoever reads it is a violent psychopath @@ -13518,7 +14423,7 @@ and likely to change, its description is relegated to an appendix. File: gawk.info, Node: Nondecimal Data, Next: Array Sorting, Up: Advanced Features -11.1 Allowing Nondecimal Input Data +12.1 Allowing Nondecimal Input Data =================================== If you run `gawk' with the `--non-decimal-data' option, you can have @@ -13560,7 +14465,7 @@ request it. File: gawk.info, Node: Array Sorting, Next: Two-way I/O, Prev: Nondecimal Data, Up: Advanced Features -11.2 Controlling Array Traversal and Array Sorting +12.2 Controlling Array Traversal and Array Sorting ================================================== `gawk' lets you control the order in which a `for (i in array)' loop @@ -13579,7 +14484,7 @@ to order the elements during sorting. File: gawk.info, Node: Controlling Array Traversal, Next: Array Sorting Functions, Up: Array Sorting -11.2.1 Controlling Array Traversal +12.2.1 Controlling Array Traversal ---------------------------------- By default, the order in which a `for (i in array)' loop scans an array @@ -13810,7 +14715,7 @@ the default. File: gawk.info, Node: Array Sorting Functions, Prev: Controlling Array Traversal, Up: Array Sorting -11.2.2 Sorting Array Values and Indices with `gawk' +12.2.2 Sorting Array Values and Indices with `gawk' --------------------------------------------------- In most `awk' implementations, sorting an array requires writing a @@ -13905,7 +14810,7 @@ extensions, they are not available in that case. File: gawk.info, Node: Two-way I/O, Next: TCP/IP Networking, Prev: Array Sorting, Up: Advanced Features -11.3 Two-Way Communications with Another Process +12.3 Two-Way Communications with Another Process ================================================ From: brennan@whidbey.com (Mike Brennan) @@ -14040,7 +14945,7 @@ regular pipes. File: gawk.info, Node: TCP/IP Networking, Next: Profiling, Prev: Two-way I/O, Up: Advanced Features -11.4 Using `gawk' for Network Programming +12.4 Using `gawk' for Network Programming ========================================= `EMISTERED': @@ -14117,29 +15022,26 @@ examples. File: gawk.info, Node: Profiling, Prev: TCP/IP Networking, Up: Advanced Features -11.5 Profiling Your `awk' Programs +12.5 Profiling Your `awk' Programs ================================== You may produce execution traces of your `awk' programs. This is done -with a specially compiled version of `gawk', called `pgawk' ("profiling -`gawk'"). - - `pgawk' is identical in every way to `gawk', except that when it has -finished running, it creates a profile of your program in a file named -`awkprof.out'. Because it is profiling, it also executes up to 45% +by passing the option `--profile' to `gawk'. When `gawk' has finished +running, it creates a profile of your program in a file named +`awkprof.out'. Because it is profiling, it also executes up to 45% slower than `gawk' normally does. As shown in the following example, the `--profile' option can be -used to change the name of the file where `pgawk' will write the -profile: +used to change the name of the file where `gawk' will write the profile: - pgawk --profile=myprog.prof -f myprog.awk data1 data2 + gawk --profile=myprog.prof -f myprog.awk data1 data2 -In the above example, `pgawk' places the profile in `myprog.prof' +In the above example, `gawk' places the profile in `myprog.prof' instead of in `awkprof.out'. Here is a sample session showing a simple `awk' program, its input -data, and the results from running `pgawk'. First, the `awk' program: +data, and the results from running `gawk' with the `--profile' option. +First, the `awk' program: BEGIN { print "First BEGIN rule" } @@ -14175,9 +15077,9 @@ data, and the results from running `pgawk'. First, the `awk' program: foo junk - Here is the `awkprof.out' that results from running `pgawk' on this -program and data (this example also illustrates that `awk' programmers -sometimes have to work late): + Here is the `awkprof.out' that results from running the `gawk' +profiler on this program and data (this example also illustrates that +`awk' programmers sometimes have to work late): # gawk profile, created Sun Aug 13 00:00:15 2000 @@ -14266,14 +15168,14 @@ output. They are as follows: redirection. Similarly, if the target of a redirection isn't a scalar, it gets parenthesized. - * `pgawk' supplies leading comments in front of the `BEGIN' and - `END' rules, the pattern/action rules, and the functions. + * `gawk' supplies leading comments in front of the `BEGIN' and `END' + rules, the pattern/action rules, and the functions. The profiled version of your program may not look exactly like what -you typed when you wrote it. This is because `pgawk' creates the +you typed when you wrote it. This is because `gawk' creates the profiled version by "pretty printing" its internal representation of -the program. The advantage to this is that `pgawk' can produce a +the program. The advantage to this is that `gawk' can produce a standard representation. The disadvantage is that all source-code comments are lost, as are the distinctions among multiple `BEGIN', `END', `BEGINFILE', and `ENDFILE' rules. Also, things such as: @@ -14288,21 +15190,23 @@ come out as: which is correct, but possibly surprising. - Besides creating profiles when a program has completed, `pgawk' can + Besides creating profiles when a program has completed, `gawk' can produce a profile while it is running. This is useful if your `awk' program goes into an infinite loop and you want to see what has been -executed. To use this feature, run `pgawk' in the background: +executed. To use this feature, run `gawk' with the `--profile' option +in the background: - $ pgawk -f myprog & + $ gawk --profile -f myprog & [1] 13992 The shell prints a job number and process ID number; in this case, -13992. Use the `kill' command to send the `USR1' signal to `pgawk': +13992. Use the `kill' command to send the `USR1' signal to `gawk': $ kill -USR1 13992 As usual, the profiled version of the program is written to -`awkprof.out', or to a different file if you use the `--profile' option. +`awkprof.out', or to a different file if one specified with the +`--profile' option. Along with the regular profile, as shown earlier, the profile includes a trace of any active functions: @@ -14314,29 +15218,29 @@ includes a trace of any active functions: # 1. foo # -- main -- - You may send `pgawk' the `USR1' signal as many times as you like. + You may send `gawk' the `USR1' signal as many times as you like. Each time, the profile and function call trace are appended to the output profile file. - If you use the `HUP' signal instead of the `USR1' signal, `pgawk' + If you use the `HUP' signal instead of the `USR1' signal, `gawk' produces the profile and the function call trace and then exits. - When `pgawk' runs on MS-Windows systems, it uses the `INT' and -`QUIT' signals for producing the profile and, in the case of the `INT' -signal, `pgawk' exits. This is because these systems don't support the -`kill' command, so the only signals you can deliver to a program are -those generated by the keyboard. The `INT' signal is generated by the + When `gawk' runs on MS-Windows systems, it uses the `INT' and `QUIT' +signals for producing the profile and, in the case of the `INT' signal, +`gawk' exits. This is because these systems don't support the `kill' +command, so the only signals you can deliver to a program are those +generated by the keyboard. The `INT' signal is generated by the `Ctrl-<C>' or `Ctrl-<BREAK>' key, while the `QUIT' signal is generated by the `Ctrl-<\>' key. - Finally, regular `gawk' also accepts the `--profile' option. When + Finally, `gawk' also accepts another option `--pretty-print'. When called this way, `gawk' "pretty prints" the program into `awkprof.out', without any execution counts. File: gawk.info, Node: Library Functions, Next: Sample Programs, Prev: Advanced Features, Up: Top -12 A Library of `awk' Functions +13 A Library of `awk' Functions ******************************* *note User-defined::, describes how to write your own `awk' functions. @@ -14408,7 +15312,7 @@ contents of the input record. File: gawk.info, Node: Library Names, Next: General Functions, Up: Library Functions -12.1 Naming Library Function Global Variables +13.1 Naming Library Function Global Variables ============================================= Due to the way the `awk' language evolved, variables are either @@ -14488,7 +15392,7 @@ verifying this. File: gawk.info, Node: General Functions, Next: Data File Management, Prev: Library Names, Up: Library Functions -12.2 General Programming +13.2 General Programming ======================== This minor node presents a number of functions that are of general @@ -14511,7 +15415,7 @@ programming use. File: gawk.info, Node: Strtonum Function, Next: Assert Function, Up: General Functions -12.2.1 Converting Strings To Numbers +13.2.1 Converting Strings To Numbers ------------------------------------ The `strtonum()' function (*note String Functions::) is a `gawk' @@ -14595,7 +15499,7 @@ be tested with `gawk' and the results compared to the built-in File: gawk.info, Node: Assert Function, Next: Round Function, Prev: Strtonum Function, Up: General Functions -12.2.2 Assertions +13.2.2 Assertions ----------------- When writing large programs, it is often useful to know that a @@ -14681,7 +15585,7 @@ rule always ends with an `exit' statement. File: gawk.info, Node: Round Function, Next: Cliff Random Function, Prev: Assert Function, Up: General Functions -12.2.3 Rounding Numbers +13.2.3 Rounding Numbers ----------------------- The way `printf' and `sprintf()' (*note Printf::) perform rounding @@ -14727,7 +15631,7 @@ might be useful if your `awk''s `printf' does unbiased rounding: File: gawk.info, Node: Cliff Random Function, Next: Ordinal Functions, Prev: Round Function, Up: General Functions -12.2.4 The Cliff Random Number Generator +13.2.4 The Cliff Random Number Generator ---------------------------------------- The Cliff random number generator @@ -14756,7 +15660,7 @@ might try using this function instead. File: gawk.info, Node: Ordinal Functions, Next: Join Function, Prev: Cliff Random Function, Up: General Functions -12.2.5 Translating Between Characters and Numbers +13.2.5 Translating Between Characters and Numbers ------------------------------------------------- One commercial implementation of `awk' supplies a built-in function, @@ -14854,7 +15758,7 @@ extensions, you can simplify `_ord_init' to loop from 0 to 255. File: gawk.info, Node: Join Function, Next: Gettimeofday Function, Prev: Ordinal Functions, Up: General Functions -12.2.6 Merging an Array into a String +13.2.6 Merging an Array into a String ------------------------------------- When doing string processing, it is often useful to be able to join all @@ -14901,7 +15805,7 @@ makes string operations more difficult than they really need to be. File: gawk.info, Node: Gettimeofday Function, Prev: Join Function, Up: General Functions -12.2.7 Managing the Time of Day +13.2.7 Managing the Time of Day ------------------------------- The `systime()' and `strftime()' functions described in *note Time @@ -14983,7 +15887,7 @@ optional timestamp value to use instead of the current time. File: gawk.info, Node: Data File Management, Next: Getopt Function, Prev: General Functions, Up: Library Functions -12.3 Data File Management +13.3 Data File Management ========================= This minor node presents functions that are useful for managing @@ -15000,7 +15904,7 @@ command-line data files. File: gawk.info, Node: Filetrans Function, Next: Rewind Function, Up: Data File Management -12.3.1 Noting Data File Boundaries +13.3.1 Noting Data File Boundaries ---------------------------------- The `BEGIN' and `END' rules are each executed exactly once at the @@ -15098,7 +16002,7 @@ it provides an easy way to do per-file cleanup processing. File: gawk.info, Node: Rewind Function, Next: File Checking, Prev: Filetrans Function, Up: Data File Management -12.3.2 Rereading the Current File +13.3.2 Rereading the Current File --------------------------------- Another request for a new built-in function was for a `rewind()' @@ -15140,7 +16044,7 @@ Nextfile Statement::). File: gawk.info, Node: File Checking, Next: Empty Files, Prev: Rewind Function, Up: Data File Management -12.3.3 Checking for Readable Data Files +13.3.3 Checking for Readable Data Files --------------------------------------- Normally, if you give `awk' a data file that isn't readable, it stops @@ -15169,7 +16073,7 @@ in the list). See also *note ARGC and ARGV::. File: gawk.info, Node: Empty Files, Next: Ignoring Assigns, Prev: File Checking, Up: Data File Management -12.3.4 Checking For Zero-length Files +13.3.4 Checking For Zero-length Files ------------------------------------- All known `awk' implementations silently skip over zero-length files. @@ -15226,7 +16130,7 @@ intervening value in `ARGV' is a variable assignment. File: gawk.info, Node: Ignoring Assigns, Prev: Empty Files, Up: Data File Management -12.3.5 Treating Assignments as File Names +13.3.5 Treating Assignments as File Names ----------------------------------------- Occasionally, you might not want `awk' to process command-line variable @@ -15269,7 +16173,7 @@ arguments are left alone. File: gawk.info, Node: Getopt Function, Next: Passwd Functions, Prev: Data File Management, Up: Library Functions -12.4 Processing Command-Line Options +13.4 Processing Command-Line Options ==================================== Most utilities on POSIX compatible systems take options on the command @@ -15562,7 +16466,7 @@ have left it alone, since using `substr()' is more portable. File: gawk.info, Node: Passwd Functions, Next: Group Functions, Prev: Getopt Function, Up: Library Functions -12.5 Reading the User Database +13.5 Reading the User Database ============================== The `PROCINFO' array (*note Built-in Variables::) provides access to @@ -15805,7 +16709,7 @@ network database. File: gawk.info, Node: Group Functions, Next: Walking Arrays, Prev: Passwd Functions, Up: Library Functions -12.6 Reading the Group Database +13.6 Reading the Group Database =============================== Much of the discussion presented in *note Passwd Functions::, applies @@ -16039,7 +16943,7 @@ very simple, relying on `awk''s associative arrays to do work. File: gawk.info, Node: Walking Arrays, Prev: Group Functions, Up: Library Functions -12.7 Traversing Arrays of Arrays +13.7 Traversing Arrays of Arrays ================================ *note Arrays of Arrays::, described how `gawk' provides arrays of @@ -16090,7 +16994,7 @@ value. Here is a main program to demonstrate: File: gawk.info, Node: Sample Programs, Next: Debugger, Prev: Library Functions, Up: Top -13 Practical `awk' Programs +14 Practical `awk' Programs *************************** *note Library Functions::, presents the idea that reading programs in a @@ -16110,7 +17014,7 @@ Library Functions::. File: gawk.info, Node: Running Examples, Next: Clones, Up: Sample Programs -13.1 Running the Example Programs +14.1 Running the Example Programs ================================= To run a given program, you would typically do something like this: @@ -16133,7 +17037,7 @@ OPTIONS are any command-line options for the program that start with a File: gawk.info, Node: Clones, Next: Miscellaneous Programs, Prev: Running Examples, Up: Sample Programs -13.2 Reinventing Wheels for Fun and Profit +14.2 Reinventing Wheels for Fun and Profit ========================================== This minor node presents a number of POSIX utilities implemented in @@ -16163,7 +17067,7 @@ programming for "real world" tasks. File: gawk.info, Node: Cut Program, Next: Egrep Program, Up: Clones -13.2.1 Cutting out Fields and Columns +14.2.1 Cutting out Fields and Columns ------------------------------------- The `cut' utility selects, or "cuts," characters or fields from its @@ -16422,7 +17326,7 @@ solution to the problem of picking the input line apart by characters. File: gawk.info, Node: Egrep Program, Next: Id Program, Prev: Cut Program, Up: Clones -13.2.2 Searching for Regular Expressions in Files +14.2.2 Searching for Regular Expressions in Files ------------------------------------------------- The `egrep' utility searches files for patterns. It uses regular @@ -16654,7 +17558,7 @@ the translated line, not the original. File: gawk.info, Node: Id Program, Next: Split Program, Prev: Egrep Program, Up: Clones -13.2.3 Printing out User Information +14.2.3 Printing out User Information ------------------------------------ The `id' utility lists a user's real and effective user ID numbers, @@ -16761,7 +17665,7 @@ body never executes. File: gawk.info, Node: Split Program, Next: Tee Program, Prev: Id Program, Up: Clones -13.2.4 Splitting a Large File into Pieces +14.2.4 Splitting a Large File into Pieces ----------------------------------------- The `split' program splits large text files into smaller pieces. Usage @@ -16869,7 +17773,7 @@ not relevant for what the program aims to demonstrate. File: gawk.info, Node: Tee Program, Next: Uniq Program, Prev: Split Program, Up: Clones -13.2.5 Duplicating Output into Multiple Files +14.2.5 Duplicating Output into Multiple Files --------------------------------------------- The `tee' program is known as a "pipe fitting." `tee' copies its @@ -16957,7 +17861,7 @@ N input records and M output files, the first method only executes N File: gawk.info, Node: Uniq Program, Next: Wc Program, Prev: Tee Program, Up: Clones -13.2.6 Printing Nonduplicated Lines of Text +14.2.6 Printing Nonduplicated Lines of Text ------------------------------------------- The `uniq' utility reads sorted lines of data on its standard input, @@ -17176,7 +18080,7 @@ line of input data: File: gawk.info, Node: Wc Program, Prev: Uniq Program, Up: Clones -13.2.7 Counting Things +14.2.7 Counting Things ---------------------- The `wc' (word count) utility counts lines, words, and characters in @@ -17321,7 +18225,7 @@ characters, not bytes. File: gawk.info, Node: Miscellaneous Programs, Prev: Clones, Up: Sample Programs -13.3 A Grab Bag of `awk' Programs +14.3 A Grab Bag of `awk' Programs ================================= This minor node is a large "grab bag" of miscellaneous programs. We @@ -17348,7 +18252,7 @@ hope you find them both interesting and enjoyable. File: gawk.info, Node: Dupword Program, Next: Alarm Program, Up: Miscellaneous Programs -13.3.1 Finding Duplicated Words in a Document +14.3.1 Finding Duplicated Words in a Document --------------------------------------------- A common error when writing large amounts of prose is to accidentally @@ -17396,7 +18300,7 @@ word, comparing it to the previous one: File: gawk.info, Node: Alarm Program, Next: Translate Program, Prev: Dupword Program, Up: Miscellaneous Programs -13.3.2 An Alarm Clock Program +14.3.2 An Alarm Clock Program ----------------------------- Nothing cures insomnia like a ringing alarm clock. @@ -17529,7 +18433,7 @@ necessary: File: gawk.info, Node: Translate Program, Next: Labels Program, Prev: Alarm Program, Up: Miscellaneous Programs -13.3.3 Transliterating Characters +14.3.3 Transliterating Characters --------------------------------- The system `tr' utility transliterates characters. For example, it is @@ -17655,7 +18559,7 @@ split each character in a string into separate array elements. File: gawk.info, Node: Labels Program, Next: Word Sorting, Prev: Translate Program, Up: Miscellaneous Programs -13.3.4 Printing Mailing Labels +14.3.4 Printing Mailing Labels ------------------------------ Here is a "real world"(1) program. This script reads lists of names and @@ -17762,7 +18666,7 @@ something done." File: gawk.info, Node: Word Sorting, Next: History Sorting, Prev: Labels Program, Up: Miscellaneous Programs -13.3.5 Generating Word-Usage Counts +14.3.5 Generating Word-Usage Counts ----------------------------------- When working with large amounts of text, it can be interesting to know @@ -17866,7 +18770,7 @@ operating system documentation for more information on how to use the File: gawk.info, Node: History Sorting, Next: Extract Program, Prev: Word Sorting, Up: Miscellaneous Programs -13.3.6 Removing Duplicates from Unsorted Text +14.3.6 Removing Duplicates from Unsorted Text --------------------------------------------- The `uniq' program (*note Uniq Program::), removes duplicate lines from @@ -17913,7 +18817,7 @@ seen. File: gawk.info, Node: Extract Program, Next: Simple Sed, Prev: History Sorting, Up: Miscellaneous Programs -13.3.7 Extracting Programs from Texinfo Source Files +14.3.7 Extracting Programs from Texinfo Source Files ---------------------------------------------------- The nodes *note Library Functions::, and *note Sample Programs::, are @@ -18113,7 +19017,7 @@ function. Consider how you might use it to simplify the code. File: gawk.info, Node: Simple Sed, Next: Igawk Program, Prev: Extract Program, Up: Miscellaneous Programs -13.3.8 A Simple Stream Editor +14.3.8 A Simple Stream Editor ----------------------------- The `sed' utility is a stream editor, a program that reads a stream of @@ -18194,7 +19098,7 @@ the single rule handles the printing scheme outlined above, using File: gawk.info, Node: Igawk Program, Next: Anagram Program, Prev: Simple Sed, Up: Miscellaneous Programs -13.3.9 An Easy Way to Use Library Functions +14.3.9 An Easy Way to Use Library Functions ------------------------------------------- In *note Include Files::, we saw how `gawk' provides a built-in @@ -18591,7 +19495,7 @@ can loop forever if the file exists but is empty. Caveat emptor. File: gawk.info, Node: Anagram Program, Next: Signature Program, Prev: Igawk Program, Up: Miscellaneous Programs -13.3.10 Finding Anagrams From A Dictionary +14.3.10 Finding Anagrams From A Dictionary ------------------------------------------ An interesting programming challenge is to search for "anagrams" in a @@ -18681,7 +19585,7 @@ otherwise the anagrams would appear in arbitrary order: File: gawk.info, Node: Signature Program, Prev: Anagram Program, Up: Miscellaneous Programs -13.3.11 And Now For Something Completely Different +14.3.11 And Now For Something Completely Different -------------------------------------------------- The following program was written by Davide Brini and is published on @@ -18708,45 +19612,46 @@ supplies the following copyright terms: File: gawk.info, Node: Debugger, Next: Language History, Prev: Sample Programs, Up: Top -14 `dgawk': The `awk' Debugger -****************************** +15 Debugging `awk' Programs +*************************** It would be nice if computer programs worked perfectly the first time they were run, but in real life, this rarely happens for programs of any complexity. Thus, most programming languages have facilities available for "debugging" programs, and now `awk' is no exception. - The `dgawk' debugger is purposely modeled after the GNU Debugger + The `gawk' debugger is purposely modeled after the GNU Debugger (GDB) (http://www.gnu.org/software/gdb/) command-line debugger. If you -are familiar with GDB, learning `dgawk' is easy. +are familiar with GDB, learning how to use `gawk' for debugging your +program is easy. * Menu: -* Debugging:: Introduction to `dgawk'. -* Sample dgawk session:: Sample `dgawk' session. -* List of Debugger Commands:: Main `dgawk' Commands. -* Readline Support:: Readline Support. -* Dgawk Limitations:: Limitations and future plans. +* Debugging:: Introduction to `gawk' debugger. +* Sample Debugging Session:: Sample debugging session. +* List of Debugger Commands:: Main debugger commands. +* Readline Support:: Readline support. +* Limitations:: Limitations and future plans. -File: gawk.info, Node: Debugging, Next: Sample dgawk session, Up: Debugger +File: gawk.info, Node: Debugging, Next: Sample Debugging Session, Up: Debugger -14.1 Introduction to `dgawk' -============================ +15.1 Introduction to `gawk' Debugger +==================================== This minor node introduces debugging in general and begins the discussion of debugging in `gawk'. * Menu: -* Debugging Concepts:: Debugging In General. +* Debugging Concepts:: Debugging in General. * Debugging Terms:: Additional Debugging Concepts. * Awk Debugging:: Awk Debugging. File: gawk.info, Node: Debugging Concepts, Next: Debugging Terms, Up: Debugging -14.1.1 Debugging In General +15.1.1 Debugging in General --------------------------- (If you have used debuggers in other languages, you may want to skip @@ -18786,13 +19691,12 @@ functional program that you or someone else wrote). File: gawk.info, Node: Debugging Terms, Next: Awk Debugging, Prev: Debugging Concepts, Up: Debugging -14.1.2 Additional Debugging Concepts +15.1.2 Additional Debugging Concepts ------------------------------------ Before diving in to the details, we need to introduce several important -concepts that apply to just about all debuggers, including `dgawk'. -The following list defines terms used throughout the rest of this -major node. +concepts that apply to just about all debuggers. The following list +defines terms used throughout the rest of this major node. "Stack Frame" Programs generally call functions during the course of their @@ -18810,11 +19714,11 @@ major node. needed to manage the call stack. This data area is termed a "stack frame". - `gawk' also follows this model, and `dgawk' gives you access to - the call stack and to each stack frame. You can see the call - stack, as well as from where each function on the stack was - invoked. Commands that print the call stack print information about - each stack frame (as detailed later on). + `gawk' also follows this model, and gives you access to the call + stack and to each stack frame. You can see the call stack, as well + as from where each function on the stack was invoked. Commands + that print the call stack print information about each stack frame + (as detailed later on). "Breakpoint" During debugging, you often wish to let the program run until it @@ -18839,7 +19743,7 @@ major node. File: gawk.info, Node: Awk Debugging, Prev: Debugging Terms, Up: Debugging -14.1.3 Awk Debugging +15.1.3 Awk Debugging -------------------- Debugging an `awk' program has some specific aspects that are not @@ -18859,54 +19763,57 @@ individual primitive instructions carried out by the higher-level `awk' commands. -File: gawk.info, Node: Sample dgawk session, Next: List of Debugger Commands, Prev: Debugging, Up: Debugger +File: gawk.info, Node: Sample Debugging Session, Next: List of Debugger Commands, Prev: Debugging, Up: Debugger -14.2 Sample `dgawk' session -=========================== +15.2 Sample Debugging Session +============================= -In order to illustrate the use of `dgawk', let's look at a sample -debugging session. We will use the `awk' implementation of the POSIX -`uniq' command described earlier (*note Uniq Program::) as our example. +In order to illustrate the use of `gawk' as a debugger, let's look at a +sample debugging session. We will use the `awk' implementation of the +POSIX `uniq' command described earlier (*note Uniq Program::) as our +example. * Menu: -* dgawk invocation:: `dgawk' Invocation. -* Finding The Bug:: Finding The Bug. +* Debugger Invocation:: How to Start the Debugger. +* Finding The Bug:: Finding the Bug. -File: gawk.info, Node: dgawk invocation, Next: Finding The Bug, Up: Sample dgawk session +File: gawk.info, Node: Debugger Invocation, Next: Finding The Bug, Up: Sample Debugging Session -14.2.1 `dgawk' Invocation -------------------------- +15.2.1 How to Start the Debugger +-------------------------------- -Starting `dgawk' is exactly like running `awk'. The file(s) containing -the program and any supporting code are given on the command line as -arguments to one or more `-f' options. (`dgawk' is not designed to -debug command-line programs, only programs contained in files.) In our -case, we call `dgawk' like this: +Starting the debugger is almost exactly like running `awk', except you +have to pass an additional option `--debug' or the corresponding short +option `-D'. The file(s) containing the program and any supporting +code are given on the command line as arguments to one or more `-f' +options. (`gawk' is not designed to debug command-line programs, only +programs contained in files.) In our case, we invoke the debugger like +this: - $ dgawk -f getopt.awk -f join.awk -f uniq.awk inputfile + $ gawk -D -f getopt.awk -f join.awk -f uniq.awk inputfile where both `getopt.awk' and `uniq.awk' are in `$AWKPATH'. (Experienced users of GDB or similar debuggers should note that this syntax is -slightly different from what they are used to. With `dgawk', the -arguments for running the program are given in the command line to the -debugger rather than as part of the `run' command at the debugger +slightly different from what they are used to. With `gawk' debugger, +the arguments for running the program are given in the command line to +the debugger rather than as part of the `run' command at the debugger prompt.) Instead of immediately running the program on `inputfile', as `gawk' -would ordinarily do, `dgawk' merely loads all the program source files, -compiles them internally, and then gives us a prompt: +would ordinarily do, the debugger merely loads all the program source +files, compiles them internally, and then gives us a prompt: - dgawk> + gawk> from which we can issue commands to the debugger. At this point, no code has been executed. -File: gawk.info, Node: Finding The Bug, Prev: dgawk invocation, Up: Sample dgawk session +File: gawk.info, Node: Finding The Bug, Prev: Debugger Invocation, Up: Sample Debugging Session -14.2.2 Finding The Bug +15.2.2 Finding the Bug ---------------------- Let's say that we are having a problem using (a faulty version of) @@ -18936,27 +19843,27 @@ for a breakpoint in `uniq.awk' is at the beginning of the function `are_equal()', which compares the current line with the previous one. To set the breakpoint, use the `b' (breakpoint) command: - dgawk> b are_equal + gawk> b are_equal -| Breakpoint 1 set at file `awklib/eg/prog/uniq.awk', line 64 The debugger tells us the file and line number where the breakpoint is. Now type `r' or `run' and the program runs until it hits the breakpoint for the first time: - dgawk> r + gawk> r -| Starting program: -| Stopping in Rule ... -| Breakpoint 1, are_equal(n, m, clast, cline, alast, aline) at `awklib/eg/prog/uniq.awk':64 -| 64 if (fcount == 0 && charcount == 0) - dgawk> + gawk> Now we can look at what's going on inside our program. First of all, let's see how we got to where we are. At the prompt, we type `bt' -(short for "backtrace"), and `dgawk' responds with a listing of the -current stack frames: +(short for "backtrace"), and the debugger responds with a listing of +the current stack frames: - dgawk> bt + gawk> bt -| #0 are_equal(n, m, clast, cline, alast, aline) at `awklib/eg/prog/uniq.awk':69 -| #1 in main() at `awklib/eg/prog/uniq.awk':89 @@ -18970,9 +19877,9 @@ the key to finding the source of the problem.) Now that we're in `are_equal()', we can start looking at the values of some variables. Let's say we type `p n' (`p' is short for "print"). We would expect to see the value of `n', a parameter to `are_equal()'. -Actually, `dgawk' gives us: +Actually, the debugger gives us: - dgawk> p n + gawk> p n -| n = untyped variable In this case, `n' is an uninitialized local variable, since the @@ -18980,13 +19887,13 @@ function was called without arguments (*note Function Calls::). A more useful variable to display might be the current record: - dgawk> p $0 + gawk> p $0 -| $0 = string ("gawk is a wonderful program!") This might be a bit puzzling at first since this is the second line of our test input above. Let's look at `NR': - dgawk> p NR + gawk> p NR -| NR = number (2) So we can see that `are_equal()' was only called for the second record @@ -19000,7 +19907,7 @@ for `NR == 1': OK, let's just check that that rule worked correctly: - dgawk> p last + gawk> p last -| last = string ("awk is a wonderful program!") Everything we have done so far has verified that the program has @@ -19009,7 +19916,7 @@ the problem must be inside this function. To investigate further, we must begin "stepping through" the lines of `are_equal()'. We start by typing `n' (for "next"): - dgawk> n + gawk> n -| 67 if (fcount > 0) { This tells us that `gawk' is now ready to execute line 67, which @@ -19025,15 +19932,15 @@ was false.) Continuing to step, we now get to the splitting of the current and last records: - dgawk> n + gawk> n -| 68 n = split(last, alast) - dgawk> n + gawk> n -| 69 m = split($0, aline) At this point, we should be curious to see what our records were split into, so we try to look: - dgawk> p n m alast aline + gawk> p n m alast aline -| n = number (5) -| m = number (5) -| alast = array, 5 elements @@ -19049,19 +19956,19 @@ want to see inside the array? The first choice would be to use subscripts: - dgawk> p alast[0] + gawk> p alast[0] -| "0" not in array `alast' Oops! - dgawk> p alast[1] + gawk> p alast[1] -| alast["1"] = string ("awk") - This would be kind of slow for a 100-member array, though, so -`dgawk' provides a shortcut (reminiscent of another language not to be + This would be kind of slow for a 100-member array, though, so `gawk' +provides a shortcut (reminiscent of another language not to be mentioned): - dgawk> p @alast + gawk> p @alast -| alast["1"] = string ("awk") -| alast["2"] = string ("is") -| alast["3"] = string ("a") @@ -19070,9 +19977,9 @@ mentioned): It looks like we got this far OK. Let's take another step or two: - dgawk> n + gawk> n -| 70 clast = join(alast, fcount, n) - dgawk> n + gawk> n -| 71 cline = join(aline, fcount, m) Well, here we are at our error (sorry to spoil the suspense). What @@ -19080,7 +19987,7 @@ we had in mind was to join the fields starting from the second one to make the virtual record to compare, and if the first field was numbered zero, this would work. Let's look at what we've got: - dgawk> p cline clast + gawk> p cline clast -| cline = string ("gawk is a wonderful program!") -| clast = string ("awk is a wonderful program!") @@ -19088,9 +19995,9 @@ zero, this would work. Let's look at what we've got: unaltered, input records. A little thinking (the human brain is still the best debugging tool), and we realize that we were off by one! - We get out of `dgawk': + We get out of the debugger: - dgawk> q + gawk> q -| The program is running. Exit anyway (y/n)? y Then we get into an editor: @@ -19101,12 +20008,13 @@ Then we get into an editor: and problem solved! -File: gawk.info, Node: List of Debugger Commands, Next: Readline Support, Prev: Sample dgawk session, Up: Debugger +File: gawk.info, Node: List of Debugger Commands, Next: Readline Support, Prev: Sample Debugging Session, Up: Debugger -14.3 Main `dgawk' Commands -========================== +15.3 Main Debugger Commands +=========================== -The `dgawk' command set can be divided into the following categories: +The `gawk' debugger command set can be divided into the following +categories: * Breakpoint control @@ -19122,26 +20030,26 @@ The `dgawk' command set can be divided into the following categories: Each of these are discussed in the following subsections. In the following descriptions, commands which may be abbreviated show the -abbreviation on a second description line. A `dgawk' command name may -also be truncated if that partial name is unambiguous. `dgawk' has the -built-in capability to automatically repeat the previous command when -just hitting <Enter>. This works for the commands `list', `next', +abbreviation on a second description line. A debugger command name may +also be truncated if that partial name is unambiguous. The debugger has +the built-in capability to automatically repeat the previous command +when just hitting <Enter>. This works for the commands `list', `next', `nexti', `step', `stepi' and `continue' executed without any argument. * Menu: -* Breakpoint Control:: Control of breakpoints. -* Dgawk Execution Control:: Control of execution. -* Viewing And Changing Data:: Viewing and changing data. -* Dgawk Stack:: Dealing with the stack. -* Dgawk Info:: Obtaining information about the program and - the debugger state. -* Miscellaneous Dgawk Commands:: Miscellaneous Commands. +* Breakpoint Control:: Control of Breakpoints. +* Debugger Execution Control:: Control of Execution. +* Viewing And Changing Data:: Viewing and Changing Data. +* Execution Stack:: Dealing with the Stack. +* Debugger Info:: Obtaining Information about the Program and + the Debugger State. +* Miscellaneous Debugger Commands:: Miscellaneous Commands. -File: gawk.info, Node: Breakpoint Control, Next: Dgawk Execution Control, Up: List of Debugger Commands +File: gawk.info, Node: Breakpoint Control, Next: Debugger Execution Control, Up: List of Debugger Commands -14.3.1 Control Of Breakpoints +15.3.1 Control of Breakpoints ----------------------------- As we saw above, the first thing you probably want to do in a debugging @@ -19169,10 +20077,10 @@ controlling breakpoints are: it from the breakpoint list using the `delete' command. With a breakpoint, you may also supply a condition. This is an - `awk' expression (enclosed in double quotes) that `dgawk' + `awk' expression (enclosed in double quotes) that the debugger evaluates whenever the breakpoint is reached. If the condition is - true, then `dgawk' stops execution and prompts for a command. - Otherwise, `dgawk' continues executing the program. + true, then the debugger stops execution and prompts for a command. + Otherwise, it continues executing the program. `clear' [[FILENAME`:']N | FUNCTION] Without any argument, delete any breakpoint at the next instruction @@ -19194,12 +20102,13 @@ controlling breakpoints are: `condition' N `"EXPRESSION"' Add a condition to existing breakpoint or watchpoint N. The - condition is an `awk' expression that `dgawk' evaluates whenever - the breakpoint or watchpoint is reached. If the condition is true, - then `dgawk' stops execution and prompts for a command. Otherwise, - `dgawk' continues executing the program. If the condition - expression is not specified, any existing condition is removed; - i.e., the breakpoint or watchpoint is made unconditional. + condition is an `awk' expression that the debugger evaluates + whenever the breakpoint or watchpoint is reached. If the condition + is true, then the debugger stops execution and prompts for a + command. Otherwise, the debugger continues executing the program. + If the condition expression is not specified, any existing + condition is removed; i.e., the breakpoint or watchpoint is made + unconditional. `delete' [N1 N2 ...] [N-M] `d' [N1 N2 ...] [N-M] @@ -19233,9 +20142,9 @@ controlling breakpoints are: arguments are the same as for `break'. -File: gawk.info, Node: Dgawk Execution Control, Next: Viewing And Changing Data, Prev: Breakpoint Control, Up: List of Debugger Commands +File: gawk.info, Node: Debugger Execution Control, Next: Viewing And Changing Data, Prev: Breakpoint Control, Up: List of Debugger Commands -14.3.2 Control of Execution +15.3.2 Control of Execution --------------------------- Now that your breakpoints are ready, you can start running the program @@ -19256,14 +20165,14 @@ execution of the program than we saw in our earlier example: `continue') terminates the list (an implicit `end'), and subsequent commands are ignored. For example: - dgawk> commands + gawk> commands > silent > printf "A silent breakpoint; i = %d\n", i > info locals > set i = 10 > continue > end - dgawk> + gawk> `continue' [COUNT] `c' [COUNT] @@ -19296,9 +20205,9 @@ execution of the program than we saw in our earlier example: `run' `r' - Start/restart execution of the program. When restarting, `dgawk' - retains the current breakpoints, watchpoints, command history, - automatic display variables, and debugger options. + Start/restart execution of the program. When restarting, the + debugger retains the current breakpoints, watchpoints, command + history, automatic display variables, and debugger options. `step' [COUNT] `s' [COUNT] @@ -19313,7 +20222,7 @@ execution of the program than we saw in our earlier example: Execute one (or COUNT) instruction(s), stepping inside function calls. (For illustration of what is meant by an "instruction" in `gawk', see the output shown under `dump' in *note Miscellaneous - Dgawk Commands::.) + Debugger Commands::.) `until' [[FILENAME`:']N | FUNCTION] `u' [[FILENAME`:']N | FUNCTION] @@ -19323,9 +20232,9 @@ execution of the program than we saw in our earlier example: current stack frame returns. -File: gawk.info, Node: Viewing And Changing Data, Next: Dgawk Stack, Prev: Dgawk Execution Control, Up: List of Debugger Commands +File: gawk.info, Node: Viewing And Changing Data, Next: Execution Stack, Prev: Debugger Execution Control, Up: List of Debugger Commands -14.3.3 Viewing and Changing Data +15.3.3 Viewing and Changing Data -------------------------------- The commands for viewing and changing variables inside of `gawk' are: @@ -19335,7 +20244,7 @@ The commands for viewing and changing variables inside of `gawk' are: of the variable or field is displayed each time the program stops. Each variable added to the list is identified by a unique number: - dgawk> display x + gawk> display x -| 10: x = 1 displays the assigned item number, the variable name and its @@ -19363,7 +20272,7 @@ AWK STATEMENTS Print the value of a `gawk' variable or field. Fields must be referenced by constants: - dgawk> print $3 + gawk> print $3 This prints the third field in the input record (if the specified field does not exist, it prints `Null field'). A variable can be @@ -19391,16 +20300,16 @@ AWK STATEMENTS `watch' VAR | `$'N [`"EXPRESSION"'] `w' VAR | `$'N [`"EXPRESSION"'] - Add variable VAR (or field `$N') to the watch list. `dgawk' then - stops whenever the value of the variable or field changes. Each - watched item is assigned a number which can be used to delete it - from the watch list using the `unwatch' command. + Add variable VAR (or field `$N') to the watch list. The debugger + then stops whenever the value of the variable or field changes. + Each watched item is assigned a number which can be used to delete + it from the watch list using the `unwatch' command. With a watchpoint, you may also supply a condition. This is an - `awk' expression (enclosed in double quotes) that `dgawk' + `awk' expression (enclosed in double quotes) that the debugger evaluates whenever the watchpoint is reached. If the condition is - true, then `dgawk' stops execution and prompts for a command. - Otherwise, `dgawk' continues executing the program. + true, then the debugger stops execution and prompts for a command. + Otherwise, `gawk' continues executing the program. `undisplay' [N] Remove item number N (or all items, if no argument) from the @@ -19412,9 +20321,9 @@ AWK STATEMENTS -File: gawk.info, Node: Dgawk Stack, Next: Dgawk Info, Prev: Viewing And Changing Data, Up: List of Debugger Commands +File: gawk.info, Node: Execution Stack, Next: Debugger Info, Prev: Viewing And Changing Data, Up: List of Debugger Commands -14.3.4 Dealing With The Stack +15.3.4 Dealing with the Stack ----------------------------- Whenever you run a program which contains any function calls, `gawk' @@ -19449,16 +20358,17 @@ are: frame. Then select and print the frame. -File: gawk.info, Node: Dgawk Info, Next: Miscellaneous Dgawk Commands, Prev: Dgawk Stack, Up: List of Debugger Commands +File: gawk.info, Node: Debugger Info, Next: Miscellaneous Debugger Commands, Prev: Execution Stack, Up: List of Debugger Commands -14.3.5 Obtaining Information About The Program and The Debugger State +15.3.5 Obtaining Information about the Program and the Debugger State --------------------------------------------------------------------- Besides looking at the values of variables, there is often a need to get other sorts of information about the state of your program and of the -debugging environment itself. `dgawk' has one command which provides -this information, appropriately called `info'. `info' is used with one -of a number of arguments that tell it exactly what you want to know: +debugging environment itself. The `gawk' debugger has one command which +provides this information, appropriately called `info'. `info' is used +with one of a number of arguments that tell it exactly what you want to +know: `info' WHAT `i' WHAT @@ -19486,10 +20396,10 @@ of a number of arguments that tell it exactly what you want to know: `source' The name of the current source file. Each time the program stops, the current source file is the file containing the - current instruction. When `dgawk' first starts, the current - source file is the first file included via the `-f' option. - The `list FILENAME:LINENO' command can be used at any time to - change the current source. + current instruction. When the debugger first starts, the + current source file is the first file included via the `-f' + option. The `list FILENAME:LINENO' command can be used at any + time to change the current source. `sources' List all program sources. @@ -19513,7 +20423,7 @@ from a file. The commands are: `history_size' The maximum number of lines to keep in the history file - `./.dgawk_history'. The default is 100. + `./.gawk_history'. The default is 100. `listsize' The number of lines that `list' prints. The default is 15. @@ -19524,14 +20434,14 @@ from a file. The commands are: standard output. `prompt' - The debugger prompt. The default is `dgawk> '. + The debugger prompt. The default is `gawk> '. `save_history [on | off]' - Save command history to file `./.dgawk_history'. The default + Save command history to file `./.gawk_history'. The default is `on'. `save_options [on | off]' - Save current options to file `./.dgawkrc' upon exit. The + Save current options to file `./.gawkrc' upon exit. The default is `on'. Options are read back in to the next session upon startup. @@ -19549,17 +20459,17 @@ from a file. The commands are: ignored; they do _not_ repeat the last command. You can't restart the program by having more than one `run' command in the file. Also, the list of commands may include additional `source' - commands; however, `dgawk' will not source the same file more than - once in order to avoid infinite recursion. + commands; however, the `gawk' debugger will not source the same + file more than once in order to avoid infinite recursion. In addition to, or instead of the `source' command, you can use - the `-R FILE' or `--command=FILE' command-line options to execute + the `-D FILE' or `--debug=FILE' command-line options to execute commands from a file non-interactively (*note Options::. -File: gawk.info, Node: Miscellaneous Dgawk Commands, Prev: Dgawk Info, Up: List of Debugger Commands +File: gawk.info, Node: Miscellaneous Debugger Commands, Prev: Debugger Info, Up: List of Debugger Commands -14.3.6 Miscellaneous Commands +15.3.6 Miscellaneous Commands ----------------------------- There are a few more commands which do not fit into the previous @@ -19573,7 +20483,7 @@ categories, as follows: partial dump of Davide Brini's obfuscated code (*note Signature Program::) demonstrates: - dgawk> dump + gawk> dump -| # BEGIN -| -| [ 2:0x89faef4] Op_rule : [in_rule = BEGIN] [source_file = brini.awk] @@ -19622,13 +20532,13 @@ categories, as follows: -| [ :0x89fa3b0] Op_after_beginfile : -| [ :0x89fa388] Op_no_op : -| [ :0x89fa3c4] Op_after_endfile : - dgawk> + gawk> `help' `h' - Print a list of all of the `dgawk' commands with a short summary - of their usage. `help COMMAND' prints the information about the - command COMMAND. + Print a list of all of the `gawk' debugger commands with a short + summary of their usage. `help COMMAND' prints the information + about the command COMMAND. `list' [`-' | `+' | N | FILENAME`:'N | N-M | FUNCTION] `l' [`-' | `+' | N | FILENAME`:'N | N-M | FUNCTION] @@ -19662,7 +20572,7 @@ categories, as follows: Exit the debugger. Debugging is great fun, but sometimes we all have to tend to other obligations in life, and sometimes we find the bug, and are free to go on to the next one! As we saw above, - if you are running a program, `dgawk' warns you if you + if you are running a program, the debugger warns you if you accidentally type `q' or `quit', to make sure you really want to quit. @@ -19677,12 +20587,12 @@ categories, as follows: -File: gawk.info, Node: Readline Support, Next: Dgawk Limitations, Prev: List of Debugger Commands, Up: Debugger +File: gawk.info, Node: Readline Support, Next: Limitations, Prev: List of Debugger Commands, Up: Debugger -14.4 Readline Support +15.4 Readline Support ===================== -If `dgawk' is compiled with the `readline' library, you can take +If `gawk' is compiled with the `readline' library, you can take advantage of that library's command completion and history expansion features. The following types of completion are available: @@ -19704,27 +20614,27 @@ Variable name completion -File: gawk.info, Node: Dgawk Limitations, Prev: Readline Support, Up: Debugger +File: gawk.info, Node: Limitations, Prev: Readline Support, Up: Debugger -14.5 Limitations and Future Plans +15.5 Limitations and Future Plans ================================= -We hope you find `dgawk' useful and enjoyable to work with, but as with -any program, especially in its early releases, it still has some -limitations. A few which are worth being aware of are: +We hope you find the `gawk' debugger useful and enjoyable to work with, +but as with any program, especially in its early releases, it still has +some limitations. A few which are worth being aware of are: - * At this point, `dgawk' does not give a detailed explanation of + * At this point, the debugger does not give a detailed explanation of what you did wrong when you type in something it doesn't like. Rather, it just responds `syntax error'. When you do figure out what your mistake was, though, you'll feel like a real guru. - * If you perused the dump of opcodes in *note Miscellaneous Dgawk + * If you perused the dump of opcodes in *note Miscellaneous Debugger Commands::, (or if you are already familiar with `gawk' internals), you will realize that much of the internal manipulation of data in `gawk', as in many interpreters, is done on a stack. `Op_push', `Op_pop', etc., are the "bread and butter" of most `gawk' code. - Unfortunately, as of now, `dgawk' does not allow you to examine - the stack's contents. + Unfortunately, as of now, the `gawk' debugger does not allow you + to examine the stack's contents. That is, the intermediate results of expression evaluation are on the stack, but cannot be printed. Rather, only variables which @@ -19737,13 +20647,15 @@ limitations. A few which are worth being aware of are: expressions to see if you got it right. As an `awk' programmer, you are expected to know what `/[^[:alnum:][:blank:]]/' means. - * `dgawk' is designed to be used by running a program (with all its - parameters) on the command line, as described in *note dgawk - invocation::. There is no way (as of now) to attach or "break in" - to a running program. This seems reasonable for a language which - is used mainly for quickly executing, short programs. + * The `gawk' debugger is designed to be used by running a program + (with all its parameters) on the command line, as described in + *note Debugger Invocation::. There is no way (as of now) to + attach or "break in" to a running program. This seems reasonable + for a language which is used mainly for quickly executing, short + programs. - * `dgawk' only accepts source supplied with the `-f' option. + * The `gawk' debugger only accepts source supplied with the `-f' + option. Look forward to a future release when these and other missing features may be added, and of course feel free to try to add them @@ -20319,7 +21231,7 @@ Info file, in approximate chronological order: Windows32 environments. (This is no longer supported) * John Haque reworked the `gawk' internals to use a byte-code engine, - providing the `dgawk' debugger for `awk' programs. + providing the `gawk' debugger for `awk' programs. * Efraim Yawitz contributed the original text for *note Debugger::. @@ -21336,9 +22248,10 @@ Unix `awk' `pawk' Nelson H.F. Beebe at the University of Utah has modified Brian Kernighan's `awk' to provide timing and profiling information. It - is different from `pgawk' (*note Profiling::), in that it uses - CPU-based profiling, not line-count profiling. You may find it at - either `ftp://ftp.math.utah.edu/pub/pawk/pawk-20030606.tar.gz' or + is different from `gawk' with the `--profile' option. (*note + Profiling::), in that it uses CPU-based profiling, not line-count + profiling. You may find it at either + `ftp://ftp.math.utah.edu/pub/pawk/pawk-20030606.tar.gz' or `http://www.math.utah.edu/pub/pawk/pawk-20030606.tar.gz'. Busybox Awk @@ -21735,6 +22648,7 @@ is necessary when reading this minor node. * Internals:: A brief look at some `gawk' internals. * Plugin License:: A note about licensing. +* Loading Extensions:: How to load dynamic extensions. * Sample Library:: A example of new functions. @@ -21779,16 +22693,9 @@ when writing extensions. The next minor node shows how they are used: is current. It may end up calling an internal `gawk' function. It also guarantees that the wide string is zero-terminated. -`size_t get_curfunc_arg_count(void)' - This function returns the actual number of parameters passed to - the current function. Inside the code of an extension this can be - used to determine the maximum index which is safe to use with - `get_actual_argument'. If this value is greater than `nargs', the - function was called incorrectly from the `awk' program. - `nargs' - Inside an extension function, this is the maximum number of - expected parameters, as set by the `make_builtin()' function. + Inside an extension function, this is the actual number of + parameters passed to the current function. `n->stptr' `n->stlen' @@ -21816,12 +22723,10 @@ when writing extensions. The next minor node shows how they are used: Clears the associative array pointed to by `n'. Make sure that `n->type == Node_var_array' first. -`NODE **assoc_lookup(NODE *symbol, NODE *subs, int reference)' +`NODE **assoc_lookup(NODE *symbol, NODE *subs)' Finds, and installs if necessary, array elements. `symbol' is the array, `subs' is the subscript. This is usually a value created - with `make_string()' (see below). `reference' should be `TRUE' if - it is an error to use the value before it is created. Typically, - `FALSE' is the correct value to use from extension functions. + with `make_string()' (see below). `NODE *make_string(char *s, size_t len)' Take a C string and turn it into a pointer to a `NODE' that can be @@ -21943,7 +22848,7 @@ function parameter. just blindly copy this code. -File: gawk.info, Node: Plugin License, Next: Sample Library, Prev: Internals, Up: Dynamic Extensions +File: gawk.info, Node: Plugin License, Next: Loading Extensions, Prev: Internals, Up: Dynamic Extensions C.3.2 Extension Licensing ------------------------- @@ -21960,9 +22865,54 @@ the symbol exists in the global scope. Something like this is enough: int plugin_is_GPL_compatible; -File: gawk.info, Node: Sample Library, Prev: Plugin License, Up: Dynamic Extensions +File: gawk.info, Node: Loading Extensions, Next: Sample Library, Prev: Plugin License, Up: Dynamic Extensions + +C.3.3 Loading a Dynamic Extension +--------------------------------- + +There are two ways to load a dynamically linked library. The first is +to use the builtin `extension()': + + extension(libname, init_func) + + where `libname' is the library to load, and `init_func' is the name +of the initialization or bootstrap routine to run once loaded. + + The second method for dynamic loading of a library is to use the +command line option `-l': + + $ gawk -l libname -f myprog + + This will work only if the initialization routine is named +`dlload()'. + + If you use `extension()', the library will be loaded at run time. +This means that the functions are available only to the rest of your +script. If you use the command line option `-l' instead, the library +will be loaded before `gawk' starts compiling the actual program. The +net effect is that you can use those functions anywhere in the program. + + `gawk' has a list of directories where it searches for libraries. +By default, the list includes directories that depend upon how gawk was +built and installed (*note AWKPATH Variable::). If you want `gawk' to +look for libraries in your private directory, you have to tell it. The +way to do it is to set the `AWKPATH' environment variable (*note +AWKPATH Variable::). `gawk' supplies the default suffix `.so' if it is +not present in the name of the library. If the name of your library is +`mylib.so', you can simply type + + $ gawk -l mylib -f myprog + + and `gawk' will do everything necessary to load in your library, and +then call your `dlload()' routine. + + You can always specify the library using an absolute pathname, in +which case `gawk' will not use `AWKPATH' to search for it. -C.3.3 Example: Directory and File Operation Built-ins + +File: gawk.info, Node: Sample Library, Prev: Loading Extensions, Up: Dynamic Extensions + +C.3.4 Example: Directory and File Operation Built-ins ----------------------------------------------------- Two useful functions that are not in `awk' are `chdir()' (so that an @@ -21979,7 +22929,7 @@ implements these functions for `gawk' in an external extension library. File: gawk.info, Node: Internal File Description, Next: Internal File Ops, Up: Sample Library -C.3.3.1 Using `chdir()' and `stat()' +C.3.4.1 Using `chdir()' and `stat()' .................................... This minor node shows how to use the new functions at the `awk' level @@ -22102,7 +23052,7 @@ Elements::): File: gawk.info, Node: Internal File Ops, Next: Using Internal File Ops, Prev: Internal File Description, Up: Sample Library -C.3.3.2 C Code for `chdir()' and `stat()' +C.3.4.2 C Code for `chdir()' and `stat()' ......................................... Here is the C code for these extensions. They were written for @@ -22123,7 +23073,7 @@ other POSIX-compliant systems:(1) NODE *newdir; int ret = -1; - if (do_lint && get_curfunc_arg_count() != 1) + if (do_lint && nargs != 1) lintwarn("chdir: called with incorrect number of arguments"); newdir = get_scalar_argument(0, FALSE); @@ -22180,7 +23130,7 @@ declarations and argument checking: char *pmode; /* printable mode */ char *type = "unknown"; - if (do_lint && get_curfunc_arg_count() > 2) + if (do_lint && nargs > 2) lintwarn("stat: called with too many arguments"); Then comes the actual work. First, the function gets the arguments. @@ -22207,15 +23157,15 @@ link. If there's an error, it sets `ERRNO' and returns: calls are shown here, since they all follow the same pattern: /* fill in the array */ - aptr = assoc_lookup(array, tmp = make_string("name", 4), FALSE); + aptr = assoc_lookup(array, tmp = make_string("name", 4)); *aptr = dupnode(file); unref(tmp); - aptr = assoc_lookup(array, tmp = make_string("mode", 4), FALSE); + aptr = assoc_lookup(array, tmp = make_string("mode", 4)); *aptr = make_number((AWKNUM) sbuf.st_mode); unref(tmp); - aptr = assoc_lookup(array, tmp = make_string("pmode", 5), FALSE); + aptr = assoc_lookup(array, tmp = make_string("pmode", 5)); pmode = format_mode(sbuf.st_mode); *aptr = make_string(pmode, strlen(pmode)); unref(tmp); @@ -22252,7 +23202,7 @@ version. File: gawk.info, Node: Using Internal File Ops, Prev: Internal File Ops, Up: Sample Library -C.3.3.3 Integrating the Extensions +C.3.4.3 Integrating the Extensions .................................. Now that the code is written, it must be possible to add it at runtime @@ -24690,8 +25640,8 @@ Index * ' (single quote): One-shot. (line 15) * ' (single quote), vs. apostrophe: Comments. (line 27) * ' (single quote), with double quotes: Quoting. (line 53) +* () (parentheses) <1>: Profiling. (line 138) * () (parentheses): Regexp Operators. (line 79) -* () (parentheses), pgawk program: Profiling. (line 141) * * (asterisk), * operator, as multiplication operator: Precedence. (line 55) * * (asterisk), * operator, as regexp operator: Regexp Operators. @@ -24721,73 +25671,78 @@ Index * - (hyphen), filenames beginning with: Options. (line 59) * - (hyphen), in bracket expressions: Bracket Expressions. (line 17) * --assign option: Options. (line 32) +* --bignum option: Options. (line 182) * --c option: Options. (line 78) * --characters-as-bytes option: Options. (line 68) -* --command option: Options. (line 231) * --copyright option: Options. (line 85) +* --debug option: Options. (line 105) * --disable-lint configuration option: Additional Configuration Options. (line 9) * --disable-nls configuration option: Additional Configuration Options. (line 24) * --dump-variables option <1>: Library Names. (line 45) * --dump-variables option: Options. (line 90) -* --exec option: Options. (line 113) +* --exec option: Options. (line 122) * --field-separator option: Options. (line 21) * --file option: Options. (line 25) * --gen-pot option <1>: String Extraction. (line 6) -* --gen-pot option: Options. (line 135) -* --help option: Options. (line 142) -* --L option: Options. (line 245) -* --lint option <1>: Options. (line 147) +* --gen-pot option: Options. (line 144) +* --help option: Options. (line 151) +* --L option: Options. (line 269) +* --lint option <1>: Options. (line 163) * --lint option: Command Line. (line 20) -* --lint-old option: Options. (line 245) +* --lint-old option: Options. (line 269) +* --load option: Options. (line 156) * --non-decimal-data option <1>: Nondecimal Data. (line 6) -* --non-decimal-data option: Options. (line 166) +* --non-decimal-data option: Options. (line 188) * --non-decimal-data option, strtonum() function and: Nondecimal Data. (line 36) -* --optimize option: Options. (line 179) -* --posix option: Options. (line 199) -* --posix option, --traditional option and: Options. (line 218) -* --profile option <1>: Profiling. (line 15) -* --profile option: Options. (line 186) -* --re-interval option: Options. (line 224) -* --sandbox option: Options. (line 236) +* --optimize option: Options. (line 209) +* --posix option: Options. (line 228) +* --posix option, --traditional option and: Options. (line 247) +* --pretty-print option: Options. (line 201) +* --profile option <1>: Profiling. (line 12) +* --profile option: Options. (line 216) +* --re-interval option: Options. (line 253) +* --sandbox option: Options. (line 260) * --sandbox option, disabling system() function: I/O Functions. (line 85) * --sandbox option, input redirection with getline: Getline. (line 19) * --sandbox option, output redirection with print, printf: Redirection. (line 6) -* --source option: Options. (line 105) +* --source option: Options. (line 114) * --traditional option: Options. (line 78) -* --traditional option, --posix option and: Options. (line 218) -* --use-lc-numeric option: Options. (line 174) -* --version option: Options. (line 250) +* --traditional option, --posix option and: Options. (line 247) +* --use-lc-numeric option: Options. (line 196) +* --version option: Options. (line 274) * --with-whiny-user-strftime configuration option: Additional Configuration Options. (line 29) * -b option: Options. (line 68) * -C option: Options. (line 85) +* -D option: Options. (line 105) * -d option: Options. (line 90) -* -E option: Options. (line 113) -* -e option: Options. (line 105) +* -E option: Options. (line 122) +* -e option: Options. (line 114) * -F option: Command Line Field Separator. (line 6) * -f option: Options. (line 25) * -F option: Options. (line 21) * -f option: Long. (line 12) -* -F option, -Ft sets FS to TAB: Options. (line 258) -* -f option, on command line: Options. (line 263) -* -g option: Options. (line 135) -* -h option: Options. (line 142) -* -l option: Options. (line 147) -* -N option: Options. (line 174) -* -n option: Options. (line 166) -* -O option: Options. (line 179) -* -P option: Options. (line 199) -* -p option: Options. (line 186) -* -R option: Options. (line 231) -* -r option: Options. (line 224) -* -S option: Options. (line 236) -* -V option: Options. (line 250) +* -F option, -Ft sets FS to TAB: Options. (line 282) +* -f option, on command line: Options. (line 287) +* -g option: Options. (line 144) +* -h option: Options. (line 151) +* -l option: Options. (line 156) +* -M option: Options. (line 182) +* -N option: Options. (line 196) +* -n option: Options. (line 188) +* -O option: Options. (line 209) +* -o option: Options. (line 201) +* -P option: Options. (line 228) +* -p option: Options. (line 216) +* -r option: Options. (line 253) +* -S option: Options. (line 260) +* -V option: Options. (line 274) * -v option: Options. (line 32) * -v option, variables, assigning: Assignment Options. (line 12) * -W option: Options. (line 46) @@ -24927,7 +25882,7 @@ Index (line 67) * advanced features, data files as single record: Records. (line 175) * advanced features, fixed-width data: Constant Size. (line 9) -* advanced features, FNR/NR variables: Auto-set. (line 207) +* advanced features, FNR/NR variables: Auto-set. (line 224) * advanced features, gawk: Advanced Features. (line 6) * advanced features, gawk, network programming: TCP/IP Networking. (line 6) @@ -24962,6 +25917,8 @@ Index * and Boolean-logic operator: Boolean Ops. (line 6) * and() function (gawk): Bitwise Functions. (line 39) * ANSI: Glossary. (line 35) +* arbitrary precision: Arbitrary Precision Arithmetic. + (line 6) * archeologists: Bugs. (line 6) * ARGC/ARGV variables <1>: ARGC and ARGV. (line 6) * ARGC/ARGV variables: Auto-set. (line 11) @@ -24976,18 +25933,18 @@ Index * arguments, command-line, invoking awk: Command Line. (line 6) * arguments, in function calls: Function Calls. (line 16) * arguments, processing: Getopt Function. (line 6) -* arguments, retrieving: Internals. (line 120) +* arguments, retrieving: Internals. (line 111) * arithmetic operators: Arithmetic Ops. (line 6) * arrays: Arrays. (line 6) * arrays, as parameters to functions: Pass By Value/Reference. (line 47) * arrays, associative: Array Intro. (line 50) -* arrays, associative, clearing: Internals. (line 75) +* arrays, associative, clearing: Internals. (line 68) * arrays, associative, library functions and: Library Names. (line 57) * arrays, deleting entire contents: Delete. (line 39) * arrays, elements, assigning: Assigning Elements. (line 6) * arrays, elements, deleting: Delete. (line 6) -* arrays, elements, installing: Internals. (line 79) +* arrays, elements, installing: Internals. (line 72) * arrays, elements, order of: Scanning an Array. (line 48) * arrays, elements, referencing: Reference to Elements. (line 6) @@ -25026,8 +25983,8 @@ Index * assignment operators, evaluation order: Assignment Ops. (line 111) * assignment operators, lvalues/rvalues: Assignment Ops. (line 32) * assignments as filenames: Ignoring Assigns. (line 6) -* assoc_clear() internal function: Internals. (line 75) -* assoc_lookup() internal function: Internals. (line 79) +* assoc_clear() internal function: Internals. (line 68) +* assoc_lookup() internal function: Internals. (line 72) * associative arrays: Array Intro. (line 50) * asterisk (*), * operator, as multiplication operator: Precedence. (line 55) @@ -25043,7 +26000,10 @@ Index * asterisk (*), *= operator: Assignment Ops. (line 129) * atan2() function: Numeric Functions. (line 11) * awf (amazingly workable formatter) program: Glossary. (line 25) +* awk debugging, enabling: Options. (line 105) +* awk enabling: Options. (line 201) * awk language, POSIX version: Assignment Ops. (line 136) +* awk profiling, enabling: Options. (line 216) * awk programs <1>: Two Rules. (line 6) * awk programs <2>: Executable Scripts. (line 6) * awk programs: Getting Started. (line 12) @@ -25059,7 +26019,6 @@ Index * awk programs, location of: Options. (line 25) * awk programs, one-line examples: Very Simple. (line 45) * awk programs, profiling: Profiling. (line 6) -* awk programs, profiling, enabling: Options. (line 186) * awk programs, running <1>: Long. (line 6) * awk programs, running: Running gawk. (line 6) * awk programs, running, from shell scripts: One-shot. (line 22) @@ -25099,7 +26058,7 @@ Index * AWKNUM internal type: Internals. (line 19) * AWKPATH environment variable <1>: PC Using. (line 11) * AWKPATH environment variable: AWKPATH Variable. (line 6) -* awkprof.out file: Profiling. (line 10) +* awkprof.out file: Profiling. (line 6) * awksed.awk program: Simple Sed. (line 25) * awkvars.out file: Options. (line 90) * b debugger command (alias for break): Breakpoint Control. (line 11) @@ -25153,12 +26112,13 @@ Index * backslash (\), in escape sequences, POSIX and: Escape Sequences. (line 113) * backslash (\), regexp constants: Computed Regexps. (line 28) -* backtrace debugger command: Dgawk Stack. (line 13) +* backtrace debugger command: Execution Stack. (line 13) * BBS-list file: Sample Data Files. (line 6) * Beebe, Nelson <1>: Other Versions. (line 69) * Beebe, Nelson: Acknowledgments. (line 60) -* BEGIN pattern <1>: BEGIN/END. (line 6) -* BEGIN pattern <2>: Field Separators. (line 44) +* BEGIN pattern <1>: Profiling. (line 62) +* BEGIN pattern <2>: BEGIN/END. (line 6) +* BEGIN pattern <3>: Field Separators. (line 44) * BEGIN pattern: Records. (line 29) * BEGIN pattern, assert() user-defined function and: Assert Function. (line 83) @@ -25173,7 +26133,6 @@ Index * BEGIN pattern, OFS/ORS variables, assigning values to: Output Separators. (line 20) * BEGIN pattern, operators and: Using BEGIN/END. (line 17) -* BEGIN pattern, pgawk program: Profiling. (line 65) * BEGIN pattern, print statement and: I/O And BEGIN/END. (line 16) * BEGIN pattern, pwcat program: Passwd Functions. (line 143) * BEGIN pattern, running awk programs and: Cut Program. (line 68) @@ -25202,8 +26161,8 @@ Index * Boolean expressions, as patterns: Expression Patterns. (line 41) * Boolean operators, See Boolean expressions: Boolean Ops. (line 6) * Bourne shell, quoting rules for: Quoting. (line 18) +* braces ({}): Profiling. (line 134) * braces ({}), actions and: Action Overview. (line 19) -* braces ({}), pgawk program: Profiling. (line 137) * braces ({}), statements, grouping: Statements. (line 10) * bracket expressions <1>: Bracket Expressions. (line 6) * bracket expressions: Regexp Operators. (line 55) @@ -25230,7 +26189,7 @@ Index * Broder, Alan J.: Contributors. (line 88) * Brown, Martin: Contributors. (line 82) * BSD-based operating systems: Glossary. (line 611) -* bt debugger command (alias for backtrace): Dgawk Stack. (line 13) +* bt debugger command (alias for backtrace): Execution Stack. (line 13) * Buening, Andreas <1>: Bugs. (line 71) * Buening, Andreas <2>: Contributors. (line 92) * Buening, Andreas: Acknowledgments. (line 60) @@ -25248,7 +26207,7 @@ Index * built-in variables, -v option, setting with: Options. (line 40) * built-in variables, conveying information: Auto-set. (line 6) * built-in variables, user-modifiable: User-modified. (line 6) -* Busybox Awk: Other Versions. (line 78) +* Busybox Awk: Other Versions. (line 79) * call by reference: Pass By Value/Reference. (line 47) * call by value: Pass By Value/Reference. @@ -25268,7 +26227,7 @@ Index * case sensitivity, regexps and <1>: User-modified. (line 82) * case sensitivity, regexps and: Case-sensitivity. (line 6) * case sensitivity, string comparisons and: User-modified. (line 82) -* CGI, awk scripts for: Options. (line 113) +* CGI, awk scripts for: Options. (line 122) * character lists, See bracket expressions: Regexp Operators. (line 55) * character sets (machine character encodings) <1>: Glossary. (line 141) * character sets (machine character encodings): Ordinal Functions. @@ -25298,7 +26257,7 @@ Index * close() function, two-way pipes and: Two-way I/O. (line 77) * Close, Diane <1>: Contributors. (line 21) * Close, Diane: Manual History. (line 41) -* close_func() input method: Internals. (line 160) +* close_func() input method: Internals. (line 151) * collating elements: Bracket Expressions. (line 69) * collating symbols: Bracket Expressions. (line 76) * Colombo, Antonio: Acknowledgments. (line 60) @@ -25322,7 +26281,7 @@ Index * command line, variables, assigning on: Assignment Options. (line 6) * command-line options, processing: Getopt Function. (line 6) * command-line options, string extraction: String Extraction. (line 6) -* commands debugger command: Dgawk Execution Control. +* commands debugger command: Debugger Execution Control. (line 10) * commenting: Comments. (line 6) * commenting, backslash continuation and: Statements/Lines. (line 76) @@ -25375,8 +26334,12 @@ Index (line 29) * configuration options, gawk: Additional Configuration Options. (line 6) +* constants, floating-point: Floating-point Constants. + (line 6) * constants, nondecimal: Nondecimal Data. (line 6) * constants, types of: Constants. (line 6) +* context, floating-point: Floating-point Context. + (line 6) * continue statement: Continue Statement. (line 6) * control statements: Statements. (line 6) * converting, case: String Functions. (line 522) @@ -25399,7 +26362,7 @@ Index * cos() function: Numeric Functions. (line 15) * counting: Wc Program. (line 6) * csh utility: Statements/Lines. (line 44) -* csh utility, POSIXLY_CORRECT environment variable: Options. (line 305) +* csh utility, POSIXLY_CORRECT environment variable: Options. (line 329) * csh utility, |& operator, comparison with: Two-way I/O. (line 44) * ctime() user-defined function: Function Example. (line 72) * currency symbols, localization: Explaining gettext. (line 103) @@ -25407,7 +26370,7 @@ Index (line 30) * cut utility: Cut Program. (line 6) * cut.awk program: Cut Program. (line 45) -* d debugger command (alias for delete): Breakpoint Control. (line 63) +* d debugger command (alias for delete): Breakpoint Control. (line 64) * d.c., See dark corner: Conventions. (line 38) * dark corner <1>: Glossary. (line 193) * dark corner <2>: Truth Values. (line 24) @@ -25431,7 +26394,7 @@ Index (line 47) * dark corner, FILENAME variable <1>: Auto-set. (line 92) * dark corner, FILENAME variable: Getline Notes. (line 19) -* dark corner, FNR/NR variables: Auto-set. (line 207) +* dark corner, FNR/NR variables: Auto-set. (line 224) * dark corner, format-control characters: Control Letters. (line 18) * dark corner, FS as null string: Single Character Fields. (line 20) @@ -25471,113 +26434,113 @@ Index (line 33) * deadlocks: Two-way I/O. (line 70) * debugger commands, b (break): Breakpoint Control. (line 11) -* debugger commands, backtrace: Dgawk Stack. (line 13) +* debugger commands, backtrace: Execution Stack. (line 13) * debugger commands, break: Breakpoint Control. (line 11) -* debugger commands, bt (backtrace): Dgawk Stack. (line 13) -* debugger commands, c (continue): Dgawk Execution Control. +* debugger commands, bt (backtrace): Execution Stack. (line 13) +* debugger commands, c (continue): Debugger Execution Control. (line 33) * debugger commands, clear: Breakpoint Control. (line 36) -* debugger commands, commands: Dgawk Execution Control. +* debugger commands, commands: Debugger Execution Control. (line 10) * debugger commands, condition: Breakpoint Control. (line 54) -* debugger commands, continue: Dgawk Execution Control. +* debugger commands, continue: Debugger Execution Control. (line 33) -* debugger commands, d (delete): Breakpoint Control. (line 63) -* debugger commands, delete: Breakpoint Control. (line 63) -* debugger commands, disable: Breakpoint Control. (line 68) +* debugger commands, d (delete): Breakpoint Control. (line 64) +* debugger commands, delete: Breakpoint Control. (line 64) +* debugger commands, disable: Breakpoint Control. (line 69) * debugger commands, display: Viewing And Changing Data. (line 8) -* debugger commands, down: Dgawk Stack. (line 21) -* debugger commands, dump: Miscellaneous Dgawk Commands. +* debugger commands, down: Execution Stack. (line 21) +* debugger commands, dump: Miscellaneous Debugger Commands. (line 9) -* debugger commands, e (enable): Breakpoint Control. (line 72) -* debugger commands, enable: Breakpoint Control. (line 72) -* debugger commands, end: Dgawk Execution Control. +* debugger commands, e (enable): Breakpoint Control. (line 73) +* debugger commands, enable: Breakpoint Control. (line 73) +* debugger commands, end: Debugger Execution Control. (line 10) * debugger commands, eval: Viewing And Changing Data. (line 23) -* debugger commands, f (frame): Dgawk Stack. (line 25) -* debugger commands, finish: Dgawk Execution Control. +* debugger commands, f (frame): Execution Stack. (line 25) +* debugger commands, finish: Debugger Execution Control. (line 39) -* debugger commands, frame: Dgawk Stack. (line 25) -* debugger commands, h (help): Miscellaneous Dgawk Commands. +* debugger commands, frame: Execution Stack. (line 25) +* debugger commands, h (help): Miscellaneous Debugger Commands. (line 68) -* debugger commands, help: Miscellaneous Dgawk Commands. +* debugger commands, help: Miscellaneous Debugger Commands. (line 68) -* debugger commands, i (info): Dgawk Info. (line 12) -* debugger commands, ignore: Breakpoint Control. (line 86) -* debugger commands, info: Dgawk Info. (line 12) -* debugger commands, l (list): Miscellaneous Dgawk Commands. +* debugger commands, i (info): Debugger Info. (line 13) +* debugger commands, ignore: Breakpoint Control. (line 87) +* debugger commands, info: Debugger Info. (line 13) +* debugger commands, l (list): Miscellaneous Debugger Commands. (line 74) -* debugger commands, list: Miscellaneous Dgawk Commands. +* debugger commands, list: Miscellaneous Debugger Commands. (line 74) -* debugger commands, n (next): Dgawk Execution Control. +* debugger commands, n (next): Debugger Execution Control. (line 43) -* debugger commands, next: Dgawk Execution Control. +* debugger commands, next: Debugger Execution Control. (line 43) -* debugger commands, nexti: Dgawk Execution Control. +* debugger commands, nexti: Debugger Execution Control. (line 49) -* debugger commands, ni (nexti): Dgawk Execution Control. +* debugger commands, ni (nexti): Debugger Execution Control. (line 49) -* debugger commands, o (option): Dgawk Info. (line 56) -* debugger commands, option: Dgawk Info. (line 56) +* debugger commands, o (option): Debugger Info. (line 57) +* debugger commands, option: Debugger Info. (line 57) * debugger commands, p (print): Viewing And Changing Data. (line 36) * debugger commands, print: Viewing And Changing Data. (line 36) * debugger commands, printf: Viewing And Changing Data. (line 54) -* debugger commands, q (quit): Miscellaneous Dgawk Commands. +* debugger commands, q (quit): Miscellaneous Debugger Commands. (line 101) -* debugger commands, quit: Miscellaneous Dgawk Commands. +* debugger commands, quit: Miscellaneous Debugger Commands. (line 101) -* debugger commands, r (run): Dgawk Execution Control. +* debugger commands, r (run): Debugger Execution Control. (line 62) -* debugger commands, return: Dgawk Execution Control. +* debugger commands, return: Debugger Execution Control. (line 54) -* debugger commands, run: Dgawk Execution Control. +* debugger commands, run: Debugger Execution Control. (line 62) -* debugger commands, s (step): Dgawk Execution Control. +* debugger commands, s (step): Debugger Execution Control. (line 68) * debugger commands, set: Viewing And Changing Data. (line 59) -* debugger commands, si (stepi): Dgawk Execution Control. +* debugger commands, si (stepi): Debugger Execution Control. (line 76) -* debugger commands, silent: Dgawk Execution Control. +* debugger commands, silent: Debugger Execution Control. (line 10) -* debugger commands, step: Dgawk Execution Control. +* debugger commands, step: Debugger Execution Control. (line 68) -* debugger commands, stepi: Dgawk Execution Control. +* debugger commands, stepi: Debugger Execution Control. (line 76) -* debugger commands, t (tbreak): Breakpoint Control. (line 89) -* debugger commands, tbreak: Breakpoint Control. (line 89) -* debugger commands, trace: Miscellaneous Dgawk Commands. +* debugger commands, t (tbreak): Breakpoint Control. (line 90) +* debugger commands, tbreak: Breakpoint Control. (line 90) +* debugger commands, trace: Miscellaneous Debugger Commands. (line 110) -* debugger commands, u (until): Dgawk Execution Control. +* debugger commands, u (until): Debugger Execution Control. (line 83) * debugger commands, undisplay: Viewing And Changing Data. (line 80) -* debugger commands, until: Dgawk Execution Control. +* debugger commands, until: Debugger Execution Control. (line 83) * debugger commands, unwatch: Viewing And Changing Data. (line 84) -* debugger commands, up: Dgawk Stack. (line 33) +* debugger commands, up: Execution Stack. (line 33) * debugger commands, w (watch): Viewing And Changing Data. (line 67) * debugger commands, watch: Viewing And Changing Data. (line 67) +* debugging awk programs: Debugger. (line 6) * debugging gawk, bug reports: Bugs. (line 9) -* decimal point character, locale specific: Options. (line 215) +* decimal point character, locale specific: Options. (line 244) * decrement operators: Increment Ops. (line 35) * default keyword: Switch Statement. (line 6) * Deifik, Scott <1>: Bugs. (line 70) * Deifik, Scott <2>: Contributors. (line 54) * Deifik, Scott: Acknowledgments. (line 60) -* delete debugger command: Breakpoint Control. (line 63) +* delete debugger command: Breakpoint Control. (line 64) * delete statement: Delete. (line 6) * deleting elements in arrays: Delete. (line 6) * deleting entire arrays: Delete. (line 39) -* dgawk: Debugger. (line 6) * differences between gawk and awk: String Functions. (line 196) * differences in awk and gawk, ARGC/ARGV variables: ARGC and ARGV. (line 88) @@ -25630,7 +26593,7 @@ Index * differences in awk and gawk, regular expressions: Case-sensitivity. (line 26) * differences in awk and gawk, RS/RT variables: Records. (line 167) -* differences in awk and gawk, RT variable: Auto-set. (line 196) +* differences in awk and gawk, RT variable: Auto-set. (line 213) * differences in awk and gawk, single-character fields: Single Character Fields. (line 6) * differences in awk and gawk, split() function: String Functions. @@ -25640,7 +26603,7 @@ Index * differences in awk and gawk, strtonum() function (gawk): String Functions. (line 404) * differences in awk and gawk, TEXTDOMAIN variable: User-modified. - (line 153) + (line 162) * differences in awk and gawk, trunc-mod operation: Arithmetic Ops. (line 66) * directories, changing: Sample Library. (line 6) @@ -25648,7 +26611,7 @@ Index (line 6) * directories, searching <1>: Igawk Program. (line 368) * directories, searching: AWKPATH Variable. (line 6) -* disable debugger command: Breakpoint Control. (line 68) +* disable debugger command: Breakpoint Control. (line 69) * display debugger command: Viewing And Changing Data. (line 8) * division: Arithmetic Ops. (line 44) @@ -25666,14 +26629,14 @@ Index * double quote (") <1>: Quoting. (line 37) * double quote ("): Read Terminal. (line 25) * double quote ("), regexp constants: Computed Regexps. (line 28) -* down debugger command: Dgawk Stack. (line 21) +* down debugger command: Execution Stack. (line 21) * Drepper, Ulrich: Acknowledgments. (line 52) * DuBois, John: Acknowledgments. (line 60) -* dump debugger command: Miscellaneous Dgawk Commands. +* dump debugger command: Miscellaneous Debugger Commands. (line 9) -* dupnode() internal function: Internals. (line 96) +* dupnode() internal function: Internals. (line 87) * dupword.awk program: Dupword Program. (line 31) -* e debugger command (alias for enable): Breakpoint Control. (line 72) +* e debugger command (alias for enable): Breakpoint Control. (line 73) * EBCDIC: Ordinal Functions. (line 45) * egrep utility <1>: Egrep Program. (line 6) * egrep utility: Bracket Expressions. (line 24) @@ -25689,9 +26652,10 @@ Index * empty pattern: Empty. (line 6) * empty strings, See null strings: Regexp Field Splitting. (line 43) -* enable debugger command: Breakpoint Control. (line 72) -* end debugger command: Dgawk Execution Control. +* enable debugger command: Breakpoint Control. (line 73) +* end debugger command: Debugger Execution Control. (line 10) +* END pattern <1>: Profiling. (line 62) * END pattern: BEGIN/END. (line 6) * END pattern, assert() user-defined function and: Assert Function. (line 75) @@ -25703,7 +26667,6 @@ Index * END pattern, next/nextfile statements and: I/O And BEGIN/END. (line 37) * END pattern, operators and: Using BEGIN/END. (line 17) -* END pattern, pgawk program: Profiling. (line 65) * END pattern, print statement and: I/O And BEGIN/END. (line 16) * ENDFILE pattern: BEGINFILE/ENDFILE. (line 6) * ENDFILE pattern, Boolean patterns and: Expression Patterns. (line 73) @@ -25712,7 +26675,7 @@ Index * endgrent() user-defined function: Group Functions. (line 218) * endpwent() function (C library): Passwd Functions. (line 210) * endpwent() user-defined function: Passwd Functions. (line 213) -* ENVIRON array <1>: Internals. (line 149) +* ENVIRON array <1>: Internals. (line 140) * ENVIRON array: Auto-set. (line 60) * environment variables: Auto-set. (line 60) * epoch, definition of: Glossary. (line 239) @@ -25721,7 +26684,7 @@ Index * equals sign (=), == operator: Comparison Operators. (line 11) * EREs (Extended Regular Expressions): Bracket Expressions. (line 24) -* ERRNO variable <1>: Internals. (line 139) +* ERRNO variable <1>: Internals. (line 130) * ERRNO variable <2>: TCP/IP Networking. (line 54) * ERRNO variable <3>: Auto-set. (line 72) * ERRNO variable <4>: BEGINFILE/ENDFILE. (line 26) @@ -25770,7 +26733,7 @@ Index (line 9) * expressions, selecting: Conditional Exp. (line 6) * Extended Regular Expressions (EREs): Bracket Expressions. (line 24) -* eXtensible Markup Language (XML): Internals. (line 160) +* eXtensible Markup Language (XML): Internals. (line 151) * extension() function (gawk): Using Internal File Ops. (line 15) * extensions, Brian Kernighan's awk <1>: Other Versions. (line 13) @@ -25795,7 +26758,7 @@ Index * extract.awk program: Extract Program. (line 78) * extraction, of marked strings (internationalization): String Extraction. (line 6) -* f debugger command (alias for frame): Dgawk Stack. (line 25) +* f debugger command (alias for frame): Execution Stack. (line 25) * false, logical: Truth Values. (line 6) * FDL (Free Documentation License): GNU Free Documentation License. (line 6) @@ -25862,7 +26825,7 @@ Index * files, /inet6/... (gawk): TCP/IP Networking. (line 6) * files, as single records: Records. (line 196) * files, awk programs in: Long. (line 6) -* files, awkprof.out: Profiling. (line 10) +* files, awkprof.out: Profiling. (line 6) * files, awkvars.out: Options. (line 90) * files, closing: I/O Functions. (line 10) * files, descriptors, See file descriptors: Special FD. (line 6) @@ -25891,7 +26854,7 @@ Index * files, portable object template: Explaining gettext. (line 30) * files, portable object, converting to message object files: I18N Example. (line 62) -* files, portable object, generating: Options. (line 135) +* files, portable object, generating: Options. (line 144) * files, processing, ARGIND variable and: Auto-set. (line 47) * files, reading: Rewind Function. (line 6) * files, reading, multiline records: Multiple Line. (line 6) @@ -25900,18 +26863,20 @@ Index * files, source, search path for: Igawk Program. (line 368) * files, splitting: Split Program. (line 6) * files, Texinfo, extracting programs from: Extract Program. (line 6) -* finish debugger command: Dgawk Execution Control. +* finish debugger command: Debugger Execution Control. (line 39) * Fish, Fred: Contributors. (line 51) * fixed-width data: Constant Size. (line 9) * flag variables <1>: Tee Program. (line 20) * flag variables: Boolean Ops. (line 67) +* floating-point numbers, arbitrary precision: Arbitrary Precision Arithmetic. + (line 6) * floating-point, numbers <1>: Unexpected Results. (line 6) * floating-point, numbers: Basic Data Typing. (line 21) * floating-point, numbers, AWKNUM internal type: Internals. (line 19) * FNR variable <1>: Auto-set. (line 102) * FNR variable: Records. (line 6) -* FNR variable, changing: Auto-set. (line 207) +* FNR variable, changing: Auto-set. (line 224) * for statement: For Statement. (line 6) * for statement, in arrays: Scanning an Array. (line 20) * force_number() internal function: Internals. (line 27) @@ -25935,7 +26900,7 @@ Index * FPAT variable <1>: User-modified. (line 45) * FPAT variable: Splitting By Content. (line 26) -* frame debugger command: Dgawk Stack. (line 25) +* frame debugger command: Execution Stack. (line 25) * Free Documentation License (FDL): GNU Free Documentation License. (line 6) * Free Software Foundation (FSF) <1>: Glossary. (line 301) @@ -25947,7 +26912,7 @@ Index * FS variable, --field-separator option and: Options. (line 21) * FS variable, as null string: Single Character Fields. (line 20) -* FS variable, as TAB character: Options. (line 211) +* FS variable, as TAB character: Options. (line 240) * FS variable, changing value of: Field Separators. (line 34) * FS variable, running awk programs and: Cut Program. (line 68) * FS variable, setting from command line: Command Line Field Separator. @@ -25992,20 +26957,21 @@ Index * functions, names of <1>: Definition Syntax. (line 20) * functions, names of: Arrays. (line 18) * functions, recursive: Definition Syntax. (line 73) -* functions, return values, setting: Internals. (line 139) +* functions, return values, setting: Internals. (line 130) * functions, string-translation: I18N Functions. (line 6) * functions, undefined: Pass By Value/Reference. (line 71) * functions, user-defined: User-defined. (line 6) * functions, user-defined, calling: Calling A Function. (line 6) -* functions, user-defined, counts: Profiling. (line 132) +* functions, user-defined, counts: Profiling. (line 129) * functions, user-defined, library of: Library Functions. (line 6) * functions, user-defined, next/nextfile statements and <1>: Nextfile Statement. (line 44) * functions, user-defined, next/nextfile statements and: Next Statement. (line 45) -* G-d: Acknowledgments. (line 81) +* G-d: Acknowledgments. (line 83) * Garfinkle, Scott: Contributors. (line 35) +* gawk program, dynamic profiling: Profiling. (line 171) * gawk, ARGIND variable in: Other Arguments. (line 12) * gawk, awk and <1>: This Manual. (line 14) * gawk, awk and: Preface. (line 23) @@ -26032,7 +26998,7 @@ Index (line 139) * gawk, ERRNO variable in: Getline. (line 19) * gawk, escape sequences: Escape Sequences. (line 125) -* gawk, extensions, disabling: Options. (line 199) +* gawk, extensions, disabling: Options. (line 228) * gawk, features, adding: Adding Code. (line 6) * gawk, features, advanced: Advanced Features. (line 6) * gawk, fflush() function in: I/O Functions. (line 44) @@ -26046,6 +27012,7 @@ Index (line 26) * gawk, function arguments and: Calling Built-in. (line 16) * gawk, functions, adding: Dynamic Extensions. (line 10) +* gawk, functions, loading: Loading Extensions. (line 6) * gawk, hexadecimal numbers and: Nondecimal-numbers. (line 42) * gawk, IGNORECASE variable in <1>: Array Sorting Functions. (line 81) @@ -26084,7 +27051,7 @@ Index * gawk, regular expressions, operators: GNU Regexp Operators. (line 6) * gawk, regular expressions, precedence: Regexp Operators. (line 161) -* gawk, RT variable in <1>: Auto-set. (line 196) +* gawk, RT variable in <1>: Auto-set. (line 213) * gawk, RT variable in <2>: Getline/Variable/File. (line 10) * gawk, RT variable in <3>: Multiple Line. (line 129) @@ -26093,10 +27060,10 @@ Index * gawk, source code, obtaining: Getting. (line 6) * gawk, splitting fields and: Constant Size. (line 87) * gawk, string-translation functions: I18N Functions. (line 6) -* gawk, TEXTDOMAIN variable in: User-modified. (line 153) +* gawk, TEXTDOMAIN variable in: User-modified. (line 162) * gawk, timestamps: Time Functions. (line 6) * gawk, uses for: Preface. (line 36) -* gawk, versions of, information about, printing: Options. (line 250) +* gawk, versions of, information about, printing: Options. (line 274) * gawk, VMS version of: VMS Installation. (line 6) * gawk, word-boundary operator: GNU Regexp Operators. (line 63) @@ -26106,12 +27073,11 @@ Index * gensub() function (gawk): Using Constant Regexps. (line 43) * gensub() function (gawk), escape processing: Gory Details. (line 6) -* get_actual_argument() internal function: Internals. (line 125) -* get_argument() internal function: Internals. (line 120) -* get_array_argument() internal macro: Internals. (line 136) -* get_curfunc_arg_count() internal function: Internals. (line 42) -* get_record() input method: Internals. (line 160) -* get_scalar_argument() internal macro: Internals. (line 133) +* get_actual_argument() internal function: Internals. (line 116) +* get_argument() internal function: Internals. (line 111) +* get_array_argument() internal macro: Internals. (line 127) +* get_record() input method: Internals. (line 151) +* get_scalar_argument() internal macro: Internals. (line 124) * getaddrinfo() function (C library): TCP/IP Networking. (line 38) * getgrent() function (C library): Group Functions. (line 6) * getgrent() user-defined function: Group Functions. (line 6) @@ -26149,6 +27115,8 @@ Index * gettext() function (C library): Explaining gettext. (line 62) * gettimeofday() user-defined function: Gettimeofday Function. (line 16) +* GMP: Arbitrary Precision Arithmetic. + (line 6) * GNITS mailing list: Acknowledgments. (line 52) * GNU awk, See gawk: Preface. (line 49) * GNU Free Documentation License: GNU Free Documentation License. @@ -26157,7 +27125,7 @@ Index * GNU Lesser General Public License: Glossary. (line 397) * GNU long options <1>: Options. (line 6) * GNU long options: Command Line. (line 13) -* GNU long options, printing list of: Options. (line 142) +* GNU long options, printing list of: Options. (line 151) * GNU Project <1>: Glossary. (line 319) * GNU Project: Manual History. (line 11) * GNU/Linux <1>: Glossary. (line 611) @@ -26176,7 +27144,7 @@ Index (line 43) * gsub() function, arguments of: String Functions. (line 462) * gsub() function, escape processing: Gory Details. (line 6) -* h debugger command (alias for help): Miscellaneous Dgawk Commands. +* h debugger command (alias for help): Miscellaneous Debugger Commands. (line 68) * Hankerson, Darrel <1>: Contributors. (line 61) * Hankerson, Darrel: Acknowledgments. (line 60) @@ -26185,13 +27153,13 @@ Index * Hartholz, Elaine: Acknowledgments. (line 38) * Hartholz, Marshall: Acknowledgments. (line 38) * Hasegawa, Isamu: Contributors. (line 94) -* help debugger command: Miscellaneous Dgawk Commands. +* help debugger command: Miscellaneous Debugger Commands. (line 68) * hexadecimal numbers: Nondecimal-numbers. (line 6) -* hexadecimal values, enabling interpretation of: Options. (line 166) +* hexadecimal values, enabling interpretation of: Options. (line 188) * histsort.awk program: History Sorting. (line 25) * Hughes, Phil: Acknowledgments. (line 43) -* HUP signal: Profiling. (line 204) +* HUP signal: Profiling. (line 203) * hyphen (-), - operator: Precedence. (line 52) * hyphen (-), -- (decrement/increment) operators: Precedence. (line 46) * hyphen (-), -- operator: Increment Ops. (line 48) @@ -26199,14 +27167,16 @@ Index * hyphen (-), -= operator: Assignment Ops. (line 129) * hyphen (-), filenames beginning with: Options. (line 59) * hyphen (-), in bracket expressions: Bracket Expressions. (line 17) -* i debugger command (alias for info): Dgawk Info. (line 12) +* i debugger command (alias for info): Debugger Info. (line 13) * id utility: Id Program. (line 6) * id.awk program: Id Program. (line 30) +* IEEE-754 format: Floating-point Representation. + (line 6) * if statement <1>: If Statement. (line 6) * if statement: Regexp Usage. (line 19) * if statement, actions, changing: Ranges. (line 25) * igawk.sh program: Igawk Program. (line 124) -* ignore debugger command: Breakpoint Control. (line 86) +* ignore debugger command: Breakpoint Control. (line 87) * IGNORECASE variable <1>: Array Sorting Functions. (line 81) * IGNORECASE variable <2>: String Functions. (line 29) @@ -26234,7 +27204,9 @@ Index * index() function: String Functions. (line 155) * indexing arrays: Array Intro. (line 50) * indirect function calls: Indirect Calls. (line 6) -* info debugger command: Dgawk Info. (line 12) +* infinite precision: Arbitrary Precision Arithmetic. + (line 6) +* info debugger command: Debugger Info. (line 13) * initialization, automatic: More Complex. (line 38) * input files: Reading Files. (line 6) * input files, closing: Close Files And Pipes. @@ -26259,47 +27231,48 @@ Index * insomnia, cure for: Alarm Program. (line 6) * installation, VMS: VMS Installation. (line 6) * installing gawk: Installation. (line 6) -* INT signal (MS-Windows): Profiling. (line 207) +* INT signal (MS-Windows): Profiling. (line 206) * int() function: Numeric Functions. (line 23) +* integer, arbitrary precision: Arbitrary Precision Integers. + (line 6) * integers: Basic Data Typing. (line 21) * integers, unsigned: Basic Data Typing. (line 30) * interacting with other programs: I/O Functions. (line 63) -* internal constant, INVALID_HANDLE: Internals. (line 160) -* internal function, assoc_clear(): Internals. (line 75) -* internal function, assoc_lookup(): Internals. (line 79) -* internal function, dupnode(): Internals. (line 96) +* internal constant, INVALID_HANDLE: Internals. (line 151) +* internal function, assoc_clear(): Internals. (line 68) +* internal function, assoc_lookup(): Internals. (line 72) +* internal function, dupnode(): Internals. (line 87) * internal function, force_number(): Internals. (line 27) * internal function, force_string(): Internals. (line 32) * internal function, force_wstring(): Internals. (line 37) -* internal function, get_actual_argument(): Internals. (line 125) -* internal function, get_argument(): Internals. (line 120) -* internal function, get_curfunc_arg_count(): Internals. (line 42) -* internal function, iop_alloc(): Internals. (line 160) -* internal function, make_builtin(): Internals. (line 106) -* internal function, make_number(): Internals. (line 91) -* internal function, make_string(): Internals. (line 86) -* internal function, register_deferred_variable(): Internals. (line 149) -* internal function, register_open_hook(): Internals. (line 160) -* internal function, unref(): Internals. (line 101) -* internal function, update_ERRNO(): Internals. (line 139) -* internal function, update_ERRNO_saved(): Internals. (line 144) -* internal macro, get_array_argument(): Internals. (line 136) -* internal macro, get_scalar_argument(): Internals. (line 133) -* internal structure, IOBUF: Internals. (line 160) +* internal function, get_actual_argument(): Internals. (line 116) +* internal function, get_argument(): Internals. (line 111) +* internal function, iop_alloc(): Internals. (line 151) +* internal function, make_builtin(): Internals. (line 97) +* internal function, make_number(): Internals. (line 82) +* internal function, make_string(): Internals. (line 77) +* internal function, register_deferred_variable(): Internals. (line 140) +* internal function, register_open_hook(): Internals. (line 151) +* internal function, unref(): Internals. (line 92) +* internal function, update_ERRNO(): Internals. (line 130) +* internal function, update_ERRNO_saved(): Internals. (line 135) +* internal macro, get_array_argument(): Internals. (line 127) +* internal macro, get_scalar_argument(): Internals. (line 124) +* internal structure, IOBUF: Internals. (line 151) * internal type, AWKNUM: Internals. (line 19) * internal type, NODE: Internals. (line 23) -* internal variable, nargs: Internals. (line 49) -* internal variable, stlen: Internals. (line 53) -* internal variable, stptr: Internals. (line 53) -* internal variable, type: Internals. (line 66) -* internal variable, vname: Internals. (line 71) -* internal variable, wstlen: Internals. (line 61) -* internal variable, wstptr: Internals. (line 61) +* internal variable, nargs: Internals. (line 42) +* internal variable, stlen: Internals. (line 46) +* internal variable, stptr: Internals. (line 46) +* internal variable, type: Internals. (line 59) +* internal variable, vname: Internals. (line 64) +* internal variable, wstlen: Internals. (line 54) +* internal variable, wstptr: Internals. (line 54) * internationalization <1>: I18N and L10N. (line 6) * internationalization: I18N Functions. (line 6) * internationalization, localization <1>: Internationalization. (line 13) -* internationalization, localization: User-modified. (line 153) +* internationalization, localization: User-modified. (line 162) * internationalization, localization, character classes: Bracket Expressions. (line 90) * internationalization, localization, gawk and: Internationalization. @@ -26314,10 +27287,10 @@ Index * interpreted programs <1>: Glossary. (line 361) * interpreted programs: Basic High Level. (line 14) * interval expressions: Regexp Operators. (line 116) -* INVALID_HANDLE internal constant: Internals. (line 160) +* INVALID_HANDLE internal constant: Internals. (line 151) * inventory-shipped file: Sample Data Files. (line 32) -* IOBUF internal structure: Internals. (line 160) -* iop_alloc() internal function: Internals. (line 160) +* IOBUF internal structure: Internals. (line 151) +* iop_alloc() internal function: Internals. (line 151) * isarray() function (gawk): Type Functions. (line 11) * ISO: Glossary. (line 372) * ISO 8859-1: Glossary. (line 141) @@ -26325,9 +27298,9 @@ Index * Jacobs, Andrew: Passwd Functions. (line 90) * Jaegermann, Michal <1>: Contributors. (line 46) * Jaegermann, Michal: Acknowledgments. (line 60) -* Java implementation of awk: Other Versions. (line 96) +* Java implementation of awk: Other Versions. (line 97) * Java programming language: Glossary. (line 380) -* jawk: Other Versions. (line 96) +* jawk: Other Versions. (line 97) * Jedi knights: Undocumented. (line 6) * join() user-defined function: Join Function. (line 18) * Kahrs, Ju"rgen <1>: Contributors. (line 70) @@ -26339,16 +27312,19 @@ Index * Kernighan, Brian <3>: Contributors. (line 12) * Kernighan, Brian <4>: BTL. (line 6) * Kernighan, Brian <5>: Concatenation. (line 6) -* Kernighan, Brian <6>: Acknowledgments. (line 75) +* Kernighan, Brian <6>: Acknowledgments. (line 77) * Kernighan, Brian <7>: Conventions. (line 34) * Kernighan, Brian: History. (line 17) -* kill command, dynamic profiling: Profiling. (line 182) +* kill command, dynamic profiling: Profiling. (line 180) * Knights, jedi: Undocumented. (line 6) +* Knuth, Donald: Arbitrary Precision Arithmetic. + (line 6) * Kwok, Conrad: Contributors. (line 35) -* l debugger command (alias for list): Miscellaneous Dgawk Commands. +* l debugger command (alias for list): Miscellaneous Debugger Commands. (line 74) * labels.awk program: Labels Program. (line 51) * languages, data-driven: Basic High Level. (line 83) +* Laurie, Dirk: Changing Precision. (line 6) * LC_ALL locale category: Explaining gettext. (line 120) * LC_COLLATE locale category: Explaining gettext. (line 93) * LC_CTYPE locale category: Explaining gettext. (line 97) @@ -26371,7 +27347,7 @@ Index * length() function: String Functions. (line 166) * Lesser General Public License (LGPL): Glossary. (line 397) * LGPL (Lesser General Public License): Glossary. (line 397) -* libmawk: Other Versions. (line 104) +* libmawk: Other Versions. (line 105) * libraries of awk functions: Library Functions. (line 6) * libraries of awk functions, assertions: Assert Function. (line 6) * libraries of awk functions, associative arrays and: Library Names. @@ -26409,20 +27385,22 @@ Index * lint checking, array subscripts: Uninitialized Subscripts. (line 43) * lint checking, empty programs: Command Line. (line 16) -* lint checking, issuing warnings: Options. (line 147) +* lint checking, issuing warnings: Options. (line 163) * lint checking, POSIXLY_CORRECT environment variable: Options. - (line 289) + (line 313) * lint checking, undefined functions: Pass By Value/Reference. (line 88) * LINT variable: User-modified. (line 98) * Linux <1>: Glossary. (line 611) * Linux <2>: I18N Example. (line 55) * Linux: Manual History. (line 28) -* list debugger command: Miscellaneous Dgawk Commands. +* list debugger command: Miscellaneous Debugger Commands. (line 74) +* loading extension: Loading Extensions. (line 6) +* loading, library: Options. (line 156) * local variables: Variable Scope. (line 6) * locale categories: Explaining gettext. (line 80) -* locale decimal point character: Options. (line 215) +* locale decimal point character: Options. (line 244) * locale, definition of: Locales. (line 6) * localization: I18N and L10N. (line 6) * localization, See internationalization, localization: I18N and L10N. @@ -26435,7 +27413,7 @@ Index * long options: Command Line. (line 13) * loops: While Statement. (line 6) * loops, continue statements and: For Statement. (line 64) -* loops, count for header: Profiling. (line 126) +* loops, count for header: Profiling. (line 123) * loops, exiting: Break Statement. (line 6) * loops, See Also while statement: While Statement. (line 6) * Lost In Space: Dynamic Extensions. (line 6) @@ -26444,9 +27422,9 @@ Index * lvalues/rvalues: Assignment Ops. (line 32) * mailing labels, printing: Labels Program. (line 6) * mailing list, GNITS: Acknowledgments. (line 52) -* make_builtin() internal function: Internals. (line 106) -* make_number() internal function: Internals. (line 91) -* make_string() internal function: Internals. (line 86) +* make_builtin() internal function: Internals. (line 97) +* make_number() internal function: Internals. (line 82) +* make_string() internal function: Internals. (line 77) * mark parity: Ordinal Functions. (line 45) * marked string extraction (internationalization): String Extraction. (line 6) @@ -26461,7 +27439,7 @@ Index * matching, null strings: Gory Details. (line 164) * mawk program: Other Versions. (line 35) * McPhee, Patrick: Contributors. (line 100) -* memory, releasing: Internals. (line 101) +* memory, releasing: Internals. (line 92) * message object files: Explaining gettext. (line 41) * message object files, converting from portable object files: I18N Example. (line 62) @@ -26473,8 +27451,12 @@ Index * mktime() function (gawk): Time Functions. (line 24) * modifiers, in format specifiers: Format Modifiers. (line 6) * monetary information, localization: Explaining gettext. (line 103) +* MPFR: Arbitrary Precision Arithmetic. + (line 6) * msgfmt utility: I18N Example. (line 62) -* n debugger command (alias for next): Dgawk Execution Control. +* multiple precision: Arbitrary Precision Arithmetic. + (line 6) +* n debugger command (alias for next): Debugger Execution Control. (line 43) * names, arrays/variables <1>: Library Names. (line 6) * names, arrays/variables: Arrays. (line 18) @@ -26483,14 +27465,14 @@ Index * namespace issues <1>: Library Names. (line 6) * namespace issues: Arrays. (line 18) * namespace issues, functions: Definition Syntax. (line 20) -* nargs internal variable: Internals. (line 49) +* nargs internal variable: Internals. (line 42) * nawk utility: Names. (line 17) * negative zero: Unexpected Results. (line 28) * NetBSD: Glossary. (line 611) * networks, programming: TCP/IP Networking. (line 6) * networks, support for: Special Network. (line 6) * newlines <1>: Boolean Ops. (line 67) -* newlines <2>: Options. (line 205) +* newlines <2>: Options. (line 234) * newlines: Statements/Lines. (line 6) * newlines, as field separators: Default Field Splitting. (line 6) @@ -26501,7 +27483,7 @@ Index * newlines, separating statements in actions <1>: Statements. (line 10) * newlines, separating statements in actions: Action Overview. (line 19) -* next debugger command: Dgawk Execution Control. +* next debugger command: Debugger Execution Control. (line 43) * next statement <1>: Next Statement. (line 6) * next statement: Boolean Ops. (line 85) @@ -26516,20 +27498,20 @@ Index (line 26) * nextfile statement, user-defined functions and: Nextfile Statement. (line 44) -* nexti debugger command: Dgawk Execution Control. +* nexti debugger command: Debugger Execution Control. (line 49) * NF variable <1>: Auto-set. (line 107) * NF variable: Fields. (line 33) * NF variable, decrementing: Changing Fields. (line 107) -* ni debugger command (alias for nexti): Dgawk Execution Control. +* ni debugger command (alias for nexti): Debugger Execution Control. (line 49) * noassign.awk program: Ignoring Assigns. (line 15) * NODE internal type: Internals. (line 23) -* nodes, duplicating: Internals. (line 96) +* nodes, duplicating: Internals. (line 87) * not Boolean-logic operator: Boolean Ops. (line 6) * NR variable <1>: Auto-set. (line 118) * NR variable: Records. (line 6) -* NR variable, changing: Auto-set. (line 207) +* NR variable, changing: Auto-set. (line 224) * null strings <1>: Basic Data Typing. (line 50) * null strings <2>: Truth Values. (line 6) * null strings <3>: Regexp Field Splitting. @@ -26546,7 +27528,7 @@ Index * number sign (#), #! (executable scripts), portability issues with: Executable Scripts. (line 6) * number sign (#), commenting: Comments. (line 6) -* numbers: Internals. (line 91) +* numbers: Internals. (line 82) * numbers, as array subscripts: Numeric Array Subscripts. (line 6) * numbers, as values of characters: Ordinal Functions. (line 6) @@ -26566,11 +27548,11 @@ Index * numeric, output format: OFMT. (line 6) * numeric, strings: Variable Typing. (line 6) * numeric, values: Internals. (line 27) -* o debugger command (alias for option): Dgawk Info. (line 56) +* o debugger command (alias for option): Debugger Info. (line 57) * oawk utility: Names. (line 17) * obsolete features: Obsolete. (line 6) * octal numbers: Nondecimal-numbers. (line 6) -* octal values, enabling interpretation of: Options. (line 166) +* octal values, enabling interpretation of: Options. (line 188) * OFMT variable <1>: User-modified. (line 115) * OFMT variable <2>: Conversion. (line 55) * OFMT variable: OFMT. (line 15) @@ -26579,7 +27561,7 @@ Index * OFS variable <2>: Output Separators. (line 6) * OFS variable: Changing Fields. (line 64) * OpenBSD: Glossary. (line 611) -* OpenSolaris: Other Versions. (line 86) +* OpenSolaris: Other Versions. (line 87) * operating systems, BSD-based: Manual History. (line 28) * operating systems, PC, gawk on: PC Using. (line 6) * operating systems, PC, gawk on, installing: PC Installation. @@ -26612,7 +27594,7 @@ Index (line 48) * operators, word-boundary (gawk): GNU Regexp Operators. (line 63) -* option debugger command: Dgawk Info. (line 56) +* option debugger command: Debugger Info. (line 57) * options, command-line <1>: Command Line Field Separator. (line 6) * options, command-line <2>: Options. (line 6) @@ -26623,7 +27605,7 @@ Index * options, deprecated: Obsolete. (line 6) * options, long <1>: Options. (line 6) * options, long: Command Line. (line 13) -* options, printing list of: Options. (line 142) +* options, printing list of: Options. (line 151) * OR bitwise operation: Bitwise Functions. (line 6) * or Boolean-logic operator: Boolean Ops. (line 6) * or() function (gawk): Bitwise Functions. (line 48) @@ -26649,15 +27631,15 @@ Index (line 36) * P1003.1 POSIX standard: Glossary. (line 454) * P1003.2 POSIX standard: Glossary. (line 454) -* parameters, number of: Internals. (line 49) +* parameters, number of: Internals. (line 42) +* parentheses () <1>: Profiling. (line 138) * parentheses (): Regexp Operators. (line 79) -* parentheses (), pgawk program: Profiling. (line 141) * password file: Passwd Functions. (line 16) * patsplit() function: String Functions. (line 293) * patterns: Patterns and Actions. (line 6) * patterns, comparison expressions as: Expression Patterns. (line 14) -* patterns, counts: Profiling. (line 113) +* patterns, counts: Profiling. (line 110) * patterns, default: Very Simple. (line 34) * patterns, empty: Empty. (line 6) * patterns, expressions as: Regexp Patterns. (line 6) @@ -26675,9 +27657,6 @@ Index * Perl: Future Extensions. (line 6) * Peters, Arno: Contributors. (line 85) * Peterson, Hal: Contributors. (line 40) -* pgawk program: Profiling. (line 6) -* pgawk program, awkprof.out file: Profiling. (line 10) -* pgawk program, dynamic profiling: Profiling. (line 174) * pipes, closing: Close Files And Pipes. (line 6) * pipes, input: Getline/Pipe. (line 6) @@ -26718,13 +27697,13 @@ Index * portability, NF variable, decrementing: Changing Fields. (line 115) * portability, operators: Increment Ops. (line 61) * portability, operators, not in POSIX awk: Precedence. (line 98) -* portability, POSIXLY_CORRECT environment variable: Options. (line 310) +* portability, POSIXLY_CORRECT environment variable: Options. (line 334) * portability, substr() function: String Functions. (line 512) * portable object files <1>: Translator i18n. (line 6) * portable object files: Explaining gettext. (line 36) * portable object files, converting to message object files: I18N Example. (line 62) -* portable object files, generating: Options. (line 135) +* portable object files, generating: Options. (line 144) * portable object template files: Explaining gettext. (line 30) * porting gawk: New Ports. (line 6) * positional specifiers, printf statement <1>: Printf Ordering. @@ -26768,11 +27747,13 @@ Index * POSIX awk, regular expressions and: Regexp Operators. (line 161) * POSIX awk, timestamps and: Time Functions. (line 6) * POSIX awk, | I/O operator and: Getline/Pipe. (line 52) -* POSIX mode: Options. (line 199) +* POSIX mode: Options. (line 228) * POSIX, awk and: Preface. (line 23) * POSIX, gawk extensions not included in: POSIX/GNU. (line 6) * POSIX, programs, implementing in awk: Clones. (line 6) -* POSIXLY_CORRECT environment variable: Options. (line 289) +* POSIXLY_CORRECT environment variable: Options. (line 313) +* PREC variable <1>: Setting Precision. (line 6) +* PREC variable: User-modified. (line 134) * precedence <1>: Precedence. (line 6) * precedence: Increment Ops. (line 61) * precedence, regexp operators: Regexp Operators. (line 156) @@ -26806,14 +27787,14 @@ Index * printf statement, sprintf() function and: Round Function. (line 6) * printf statement, syntax of: Basic Printf. (line 6) * printing: Printing. (line 6) -* printing, list of options: Options. (line 142) +* printing, list of options: Options. (line 151) * printing, mailing labels: Labels Program. (line 6) * printing, unduplicated lines of text: Uniq Program. (line 6) * printing, user information: Id Program. (line 6) * private variables: Library Names. (line 11) * processes, two-way communications with: Two-way I/O. (line 23) * processing data: Basic High Level. (line 6) -* PROCINFO array <1>: Internals. (line 149) +* PROCINFO array <1>: Internals. (line 140) * PROCINFO array <2>: Id Program. (line 15) * PROCINFO array <3>: Group Functions. (line 6) * PROCINFO array <4>: Passwd Functions. (line 6) @@ -26822,8 +27803,8 @@ Index * PROCINFO array <7>: Auto-set. (line 123) * PROCINFO array: Obsolete. (line 11) * profiling awk programs: Profiling. (line 6) -* profiling awk programs, dynamically: Profiling. (line 174) -* profiling gawk, See pgawk program: Profiling. (line 6) +* profiling awk programs, dynamically: Profiling. (line 171) +* profiling gawk: Profiling. (line 6) * program, definition of: Getting Started. (line 21) * programmers, attractiveness of: Two-way I/O. (line 6) * programming conventions, --non-decimal-data option: Nondecimal Data. @@ -26847,23 +27828,23 @@ Index * programming, basic steps: Basic High Level. (line 19) * programming, concepts: Basic Concepts. (line 6) * pwcat program: Passwd Functions. (line 23) -* q debugger command (alias for quit): Miscellaneous Dgawk Commands. +* q debugger command (alias for quit): Miscellaneous Debugger Commands. (line 101) -* QSE Awk: Other Versions. (line 108) +* QSE Awk: Other Versions. (line 109) * question mark (?) regexp operator <1>: GNU Regexp Operators. (line 59) * question mark (?) regexp operator: Regexp Operators. (line 111) * question mark (?), ?: operator: Precedence. (line 92) -* QuikTrim Awk: Other Versions. (line 112) -* quit debugger command: Miscellaneous Dgawk Commands. +* QuikTrim Awk: Other Versions. (line 113) +* quit debugger command: Miscellaneous Debugger Commands. (line 101) -* QUIT signal (MS-Windows): Profiling. (line 207) +* QUIT signal (MS-Windows): Profiling. (line 206) * quoting <1>: Comments. (line 27) * quoting <2>: Long. (line 26) * quoting: Read Terminal. (line 25) * quoting, rules for: Quoting. (line 6) * quoting, tricks for: Quoting. (line 71) -* r debugger command (alias for run): Dgawk Execution Control. +* r debugger command (alias for run): Debugger Execution Control. (line 62) * Rakitzis, Byron: History Sorting. (line 25) * rand() function: Numeric Functions. (line 34) @@ -26881,7 +27862,7 @@ Index * readable data files, checking: File Checking. (line 6) * readable.awk program: File Checking. (line 11) * recipe for a programming language: History. (line 6) -* record separators <1>: User-modified. (line 134) +* record separators <1>: User-modified. (line 143) * record separators: Records. (line 14) * record separators, changing: Records. (line 81) * record separators, regular expressions as: Records. (line 112) @@ -26909,8 +27890,8 @@ Index * regexp constants, slashes vs. quotes: Computed Regexps. (line 28) * regexp constants, vs. string constants: Computed Regexps. (line 38) * regexp, See regular expressions: Regexp. (line 6) -* register_deferred_variable() internal function: Internals. (line 149) -* register_open_hook() internal function: Internals. (line 160) +* register_deferred_variable() internal function: Internals. (line 140) +* register_open_hook() internal function: Internals. (line 151) * regular expressions: Regexp. (line 6) * regular expressions as field separators: Field Separators. (line 50) * regular expressions, anchors in: Regexp Operators. (line 22) @@ -26929,7 +27910,7 @@ Index (line 59) * regular expressions, gawk, command-line options: GNU Regexp Operators. (line 70) -* regular expressions, interval expressions and: Options. (line 224) +* regular expressions, interval expressions and: Options. (line 253) * regular expressions, leftmost longest match: Leftmost Longest. (line 6) * regular expressions, operators <1>: Regexp Operators. (line 6) @@ -26945,7 +27926,7 @@ Index * regular expressions, searching for: Egrep Program. (line 6) * relational operators, See comparison operators: Typing and Comparison. (line 9) -* return debugger command: Dgawk Execution Control. +* return debugger command: Debugger Execution Control. (line 54) * return statement, user-defined functions: Return Statement. (line 6) * return values, close() function: Close Files And Pipes. @@ -26963,7 +27944,7 @@ Index * right angle bracket (>), >> operator (I/O): Redirection. (line 50) * right shift, bitwise: Bitwise Functions. (line 32) * Ritchie, Dennis: Basic Data Typing. (line 74) -* RLENGTH variable: Auto-set. (line 183) +* RLENGTH variable: Auto-set. (line 200) * RLENGTH variable, match() function and: String Functions. (line 223) * Robbins, Arnold <1>: Future Extensions. (line 6) * Robbins, Arnold <2>: Bugs. (line 32) @@ -26974,23 +27955,27 @@ Index * Robbins, Arnold: Command Line Field Separator. (line 80) * Robbins, Bill: Getline/Pipe. (line 36) -* Robbins, Harry: Acknowledgments. (line 81) -* Robbins, Jean: Acknowledgments. (line 81) +* Robbins, Harry: Acknowledgments. (line 83) +* Robbins, Jean: Acknowledgments. (line 83) * Robbins, Miriam <1>: Passwd Functions. (line 90) * Robbins, Miriam <2>: Getline/Pipe. (line 36) -* Robbins, Miriam: Acknowledgments. (line 81) +* Robbins, Miriam: Acknowledgments. (line 83) * Robinson, Will: Dynamic Extensions. (line 6) * robot, the: Dynamic Extensions. (line 6) * Rommel, Kai Uwe: Contributors. (line 43) * round() user-defined function: Round Function. (line 16) +* rounding mode, floating-point: Rounding Mode. (line 6) * rounding numbers: Round Function. (line 6) -* RS variable <1>: User-modified. (line 134) +* ROUNDMODE variable <1>: Setting Rounding Mode. + (line 6) +* ROUNDMODE variable: User-modified. (line 138) +* RS variable <1>: User-modified. (line 143) * RS variable: Records. (line 20) * RS variable, multiline records and: Multiple Line. (line 17) * rshift() function (gawk): Bitwise Functions. (line 51) -* RSTART variable: Auto-set. (line 189) +* RSTART variable: Auto-set. (line 206) * RSTART variable, match() function and: String Functions. (line 223) -* RT variable <1>: Auto-set. (line 196) +* RT variable <1>: Auto-set. (line 213) * RT variable <2>: Getline/Variable/File. (line 10) * RT variable <3>: Multiple Line. (line 129) @@ -26998,12 +27983,12 @@ Index * Rubin, Paul <1>: Contributors. (line 16) * Rubin, Paul: History. (line 30) * rule, definition of: Getting Started. (line 21) -* run debugger command: Dgawk Execution Control. +* run debugger command: Debugger Execution Control. (line 62) * rvalues/lvalues: Assignment Ops. (line 32) -* s debugger command (alias for step): Dgawk Execution Control. +* s debugger command (alias for step): Debugger Execution Control. (line 68) -* sandbox mode: Options. (line 236) +* sandbox mode: Options. (line 260) * scalar values: Basic Data Typing. (line 13) * Schorr, Andrew: Acknowledgments. (line 60) * Schreiber, Bert: Acknowledgments. (line 38) @@ -27033,11 +28018,11 @@ Index * separators, field, FIELDWIDTHS variable and: User-modified. (line 35) * separators, field, FPAT variable and: User-modified. (line 45) * separators, field, POSIX and: Fields. (line 6) -* separators, for records <1>: User-modified. (line 134) +* separators, for records <1>: User-modified. (line 143) * separators, for records: Records. (line 14) * separators, for records, regular expressions as: Records. (line 112) * separators, for statements in actions: Action Overview. (line 19) -* separators, subscript: User-modified. (line 147) +* separators, subscript: User-modified. (line 156) * set debugger command: Viewing And Changing Data. (line 59) * shells, piping commands into: Redirection. (line 143) @@ -27049,7 +28034,7 @@ Index (line 6) * shift, bitwise: Bitwise Functions. (line 32) * short-circuit operators: Boolean Ops. (line 57) -* si debugger command (alias for stepi): Dgawk Execution Control. +* si debugger command (alias for stepi): Debugger Execution Control. (line 76) * side effects <1>: Increment Ops. (line 11) * side effects: Concatenation. (line 42) @@ -27064,15 +28049,15 @@ Index * side effects, FILENAME variable: Getline Notes. (line 19) * side effects, function calls: Function Calls. (line 54) * side effects, statements: Action Overview. (line 32) -* SIGHUP signal: Profiling. (line 204) -* SIGINT signal (MS-Windows): Profiling. (line 207) -* signals, HUP/SIGHUP: Profiling. (line 204) -* signals, INT/SIGINT (MS-Windows): Profiling. (line 207) -* signals, QUIT/SIGQUIT (MS-Windows): Profiling. (line 207) -* signals, USR1/SIGUSR1: Profiling. (line 182) -* SIGQUIT signal (MS-Windows): Profiling. (line 207) -* SIGUSR1 signal: Profiling. (line 182) -* silent debugger command: Dgawk Execution Control. +* SIGHUP signal: Profiling. (line 203) +* SIGINT signal (MS-Windows): Profiling. (line 206) +* signals, HUP/SIGHUP: Profiling. (line 203) +* signals, INT/SIGINT (MS-Windows): Profiling. (line 206) +* signals, QUIT/SIGQUIT (MS-Windows): Profiling. (line 206) +* signals, USR1/SIGUSR1: Profiling. (line 180) +* SIGQUIT signal (MS-Windows): Profiling. (line 206) +* SIGUSR1 signal: Profiling. (line 180) +* silent debugger command: Debugger Execution Control. (line 10) * sin() function: Numeric Functions. (line 75) * single precision floating-point: Basic Data Typing. (line 36) @@ -27085,7 +28070,7 @@ Index (line 6) * Skywalker, Luke: Undocumented. (line 6) * sleep utility: Alarm Program. (line 109) -* Solaris, POSIX-compliant awk: Other Versions. (line 86) +* Solaris, POSIX-compliant awk: Other Versions. (line 87) * sort function, arrays, sorting: Array Sorting Functions. (line 6) * sort utility: Word Sorting. (line 50) @@ -27094,17 +28079,17 @@ Index (line 93) * source code, awka: Other Versions. (line 55) * source code, Brian Kernighan's awk: Other Versions. (line 13) -* source code, Busybox Awk: Other Versions. (line 78) +* source code, Busybox Awk: Other Versions. (line 79) * source code, gawk: Gawk Distribution. (line 6) -* source code, jawk: Other Versions. (line 96) -* source code, libmawk: Other Versions. (line 104) +* source code, jawk: Other Versions. (line 97) +* source code, libmawk: Other Versions. (line 105) * source code, mawk: Other Versions. (line 35) -* source code, mixing: Options. (line 105) +* source code, mixing: Options. (line 114) * source code, pawk: Other Versions. (line 69) -* source code, QSE Awk: Other Versions. (line 108) -* source code, QuikTrim Awk: Other Versions. (line 112) -* source code, Solaris awk: Other Versions. (line 86) -* source code, xgawk: Other Versions. (line 119) +* source code, QSE Awk: Other Versions. (line 109) +* source code, QuikTrim Awk: Other Versions. (line 113) +* source code, Solaris awk: Other Versions. (line 87) +* source code, xgawk: Other Versions. (line 120) * source files, search path for: Igawk Program. (line 368) * sparse arrays: Array Intro. (line 71) * Spencer, Henry: Glossary. (line 12) @@ -27132,12 +28117,12 @@ Index * statements, compound, control statements and: Statements. (line 10) * statements, control, in actions: Statements. (line 6) * statements, multiple: Statements/Lines. (line 91) -* step debugger command: Dgawk Execution Control. +* step debugger command: Debugger Execution Control. (line 68) -* stepi debugger command: Dgawk Execution Control. +* stepi debugger command: Debugger Execution Control. (line 76) -* stlen internal variable: Internals. (line 53) -* stptr internal variable: Internals. (line 53) +* stlen internal variable: Internals. (line 46) +* stptr internal variable: Internals. (line 46) * stream editors <1>: Simple Sed. (line 6) * stream editors: Field Splitting Summary. (line 47) @@ -27148,7 +28133,7 @@ Index (line 6) * string operators: Concatenation. (line 9) * string-matching operators: Regexp Usage. (line 19) -* strings: Internals. (line 86) +* strings: Internals. (line 77) * strings, converting <1>: Bitwise Functions. (line 107) * strings, converting: Conversion. (line 6) * strings, converting, numbers to: User-modified. (line 28) @@ -27170,7 +28155,7 @@ Index (line 43) * sub() function, arguments of: String Functions. (line 462) * sub() function, escape processing: Gory Details. (line 6) -* subscript separators: User-modified. (line 147) +* subscript separators: User-modified. (line 156) * subscripts in arrays, multidimensional: Multi-dimensional. (line 10) * subscripts in arrays, multidimensional, scanning: Multi-scanning. (line 11) @@ -27178,7 +28163,7 @@ Index (line 6) * subscripts in arrays, uninitialized variables as: Uninitialized Subscripts. (line 6) -* SUBSEP variable: User-modified. (line 147) +* SUBSEP variable: User-modified. (line 156) * SUBSEP variable, multidimensional arrays: Multi-dimensional. (line 16) * substr() function: String Functions. (line 481) @@ -27188,8 +28173,8 @@ Index (line 148) * system() function: I/O Functions. (line 63) * systime() function (gawk): Time Functions. (line 64) -* t debugger command (alias for tbreak): Breakpoint Control. (line 89) -* tbreak debugger command: Breakpoint Control. (line 89) +* t debugger command (alias for tbreak): Breakpoint Control. (line 90) +* tbreak debugger command: Breakpoint Control. (line 90) * Tcl: Library Names. (line 57) * TCP/IP: TCP/IP Networking. (line 6) * TCP/IP, support for: Special Network. (line 6) @@ -27211,7 +28196,7 @@ Index * text, printing: Print. (line 22) * text, printing, unduplicated lines of: Uniq Program. (line 6) * TEXTDOMAIN variable <1>: Programmer i18n. (line 9) -* TEXTDOMAIN variable: User-modified. (line 153) +* TEXTDOMAIN variable: User-modified. (line 162) * TEXTDOMAIN variable, BEGIN pattern and: Programmer i18n. (line 60) * TEXTDOMAIN variable, portability and: I18N Portability. (line 20) * textdomain() function (C library): Explaining gettext. (line 27) @@ -27228,6 +28213,7 @@ Index * time, managing: Gettimeofday Function. (line 6) * time, retrieving: Time Functions. (line 17) +* timeout, reading input: Read Timeout. (line 6) * timestamps: Time Functions. (line 6) * timestamps, converting dates to: Time Functions. (line 74) * timestamps, formatted: Gettimeofday Function. @@ -27235,10 +28221,10 @@ Index * tolower() function: String Functions. (line 523) * toupper() function: String Functions. (line 529) * tr utility: Translate Program. (line 6) -* trace debugger command: Miscellaneous Dgawk Commands. +* trace debugger command: Miscellaneous Debugger Commands. (line 110) * translate.awk program: Translate Program. (line 55) -* troubleshooting, --non-decimal-data option: Options. (line 166) +* troubleshooting, --non-decimal-data option: Options. (line 188) * troubleshooting, == operator: Comparison Operators. (line 37) * troubleshooting, awk uses FS not IFS: Field Separators. (line 29) @@ -27278,8 +28264,8 @@ Index * trunc-mod operation: Arithmetic Ops. (line 66) * truth values: Truth Values. (line 6) * type conversion: Conversion. (line 21) -* type internal variable: Internals. (line 66) -* u debugger command (alias for until): Dgawk Execution Control. +* type internal variable: Internals. (line 59) +* u debugger command (alias for until): Debugger Execution Control. (line 83) * undefined functions: Pass By Value/Reference. (line 71) @@ -27304,23 +28290,23 @@ Index (line 72) * Unix, awk scripts and: Executable Scripts. (line 6) * UNIXROOT variable, on OS/2 systems: PC Using. (line 17) -* unref() internal function: Internals. (line 101) +* unref() internal function: Internals. (line 92) * unsigned integers: Basic Data Typing. (line 30) -* until debugger command: Dgawk Execution Control. +* until debugger command: Debugger Execution Control. (line 83) * unwatch debugger command: Viewing And Changing Data. (line 84) -* up debugger command: Dgawk Stack. (line 33) -* update_ERRNO() internal function: Internals. (line 139) -* update_ERRNO_saved() internal function: Internals. (line 144) +* up debugger command: Execution Stack. (line 33) +* update_ERRNO() internal function: Internals. (line 130) +* update_ERRNO_saved() internal function: Internals. (line 135) * user database, reading: Passwd Functions. (line 6) * user-defined, functions: User-defined. (line 6) -* user-defined, functions, counts: Profiling. (line 132) +* user-defined, functions, counts: Profiling. (line 129) * user-defined, variables: Variables. (line 6) * user-modifiable variables: User-modified. (line 6) * users, information about, printing: Id Program. (line 6) * users, information about, retrieving: Passwd Functions. (line 16) -* USR1 signal: Profiling. (line 182) +* USR1 signal: Profiling. (line 180) * values, numeric: Basic Data Typing. (line 13) * values, string: Basic Data Typing. (line 13) * variable typing: Typing and Comparison. @@ -27363,7 +28349,7 @@ Index * vertical bar (|), || operator <1>: Precedence. (line 89) * vertical bar (|), || operator: Boolean Ops. (line 57) * Vinschen, Corinna: Acknowledgments. (line 60) -* vname internal variable: Internals. (line 71) +* vname internal variable: Internals. (line 64) * w debugger command (alias for watch): Viewing And Changing Data. (line 67) * w utility: Constant Size. (line 22) @@ -27371,7 +28357,7 @@ Index * Wall, Larry <1>: Future Extensions. (line 6) * Wall, Larry: Array Intro. (line 6) * Wallin, Anders: Acknowledgments. (line 60) -* warnings, issuing: Options. (line 147) +* warnings, issuing: Options. (line 163) * watch debugger command: Viewing And Changing Data. (line 67) * wc utility: Wc Program. (line 6) @@ -27383,7 +28369,7 @@ Index * whitespace, as field separators: Default Field Splitting. (line 6) * whitespace, functions, calling: Calling Built-in. (line 10) -* whitespace, newlines as: Options. (line 205) +* whitespace, newlines as: Options. (line 234) * Williams, Kent: Contributors. (line 35) * Woehlke, Matthew: Contributors. (line 79) * Woods, John: Contributors. (line 28) @@ -27397,11 +28383,11 @@ Index * words, counting: Wc Program. (line 6) * words, duplicate, searching for: Dupword Program. (line 6) * words, usage counts, generating: Word Sorting. (line 6) -* wstlen internal variable: Internals. (line 61) -* wstptr internal variable: Internals. (line 61) -* xgawk: Other Versions. (line 119) +* wstlen internal variable: Internals. (line 54) +* wstptr internal variable: Internals. (line 54) +* xgawk: Other Versions. (line 120) * xgettext utility: String Extraction. (line 13) -* XML (eXtensible Markup Language): Internals. (line 160) +* XML (eXtensible Markup Language): Internals. (line 151) * XOR bitwise operation: Bitwise Functions. (line 6) * xor() function (gawk): Bitwise Functions. (line 54) * Yawitz, Efraim: Contributors. (line 106) @@ -27411,8 +28397,8 @@ Index * zero, negative vs. positive: Unexpected Results. (line 28) * zerofile.awk program: Empty Files. (line 21) * Zoulas, Christos: Contributors. (line 67) +* {} (braces): Profiling. (line 134) * {} (braces), actions and: Action Overview. (line 19) -* {} (braces), pgawk program: Profiling. (line 137) * {} (braces), statements, grouping: Statements. (line 10) * | (vertical bar): Regexp Operators. (line 69) * | (vertical bar), | operator (I/O) <1>: Precedence. (line 65) @@ -27439,416 +28425,440 @@ Index Tag Table: Node: Top1352 -Node: Foreword30282 -Node: Preface34627 -Ref: Preface-Footnote-137680 -Ref: Preface-Footnote-237786 -Node: History38018 -Node: Names40409 -Ref: Names-Footnote-141886 -Node: This Manual41958 -Ref: This Manual-Footnote-146905 -Node: Conventions47005 -Node: Manual History49139 -Ref: Manual History-Footnote-152409 -Ref: Manual History-Footnote-252450 -Node: How To Contribute52524 -Node: Acknowledgments53668 -Node: Getting Started57999 -Node: Running gawk60378 -Node: One-shot61564 -Node: Read Terminal62789 -Ref: Read Terminal-Footnote-164439 -Ref: Read Terminal-Footnote-264715 -Node: Long64886 -Node: Executable Scripts66262 -Ref: Executable Scripts-Footnote-168131 -Ref: Executable Scripts-Footnote-268233 -Node: Comments68780 -Node: Quoting71247 -Node: DOS Quoting75870 -Node: Sample Data Files76545 -Node: Very Simple79577 -Node: Two Rules84176 -Node: More Complex86323 -Ref: More Complex-Footnote-189253 -Node: Statements/Lines89338 -Ref: Statements/Lines-Footnote-193800 -Node: Other Features94065 -Node: When94993 -Node: Invoking Gawk97140 -Node: Command Line98525 -Node: Options99308 -Ref: Options-Footnote-1112745 -Node: Other Arguments112770 -Node: Naming Standard Input115428 -Node: Environment Variables116522 -Node: AWKPATH Variable116966 -Ref: AWKPATH Variable-Footnote-1119563 -Node: Other Environment Variables119823 -Node: Exit Status122163 -Node: Include Files122838 -Node: Obsolete126323 -Node: Undocumented127009 -Node: Regexp127250 -Node: Regexp Usage128639 -Node: Escape Sequences130665 -Node: Regexp Operators136428 -Ref: Regexp Operators-Footnote-1143808 -Ref: Regexp Operators-Footnote-2143955 -Node: Bracket Expressions144053 -Ref: table-char-classes145943 -Node: GNU Regexp Operators148466 -Node: Case-sensitivity152189 -Ref: Case-sensitivity-Footnote-1155157 -Ref: Case-sensitivity-Footnote-2155392 -Node: Leftmost Longest155500 -Node: Computed Regexps156701 -Node: Reading Files160111 -Node: Records162052 -Ref: Records-Footnote-1170726 -Node: Fields170763 -Ref: Fields-Footnote-1173796 -Node: Nonconstant Fields173882 -Node: Changing Fields176084 -Node: Field Separators182065 -Node: Default Field Splitting184694 -Node: Regexp Field Splitting185811 -Node: Single Character Fields189153 -Node: Command Line Field Separator190212 -Node: Field Splitting Summary193653 -Ref: Field Splitting Summary-Footnote-1196845 -Node: Constant Size196946 -Node: Splitting By Content201530 -Ref: Splitting By Content-Footnote-1205256 -Node: Multiple Line205296 -Ref: Multiple Line-Footnote-1211143 -Node: Getline211322 -Node: Plain Getline213550 -Node: Getline/Variable215639 -Node: Getline/File216780 -Node: Getline/Variable/File218102 -Ref: Getline/Variable/File-Footnote-1219701 -Node: Getline/Pipe219788 -Node: Getline/Variable/Pipe222348 -Node: Getline/Coprocess223455 -Node: Getline/Variable/Coprocess224698 -Node: Getline Notes225412 -Node: Getline Summary227354 -Ref: table-getline-variants227697 -Node: Command line directories228553 -Node: Printing229178 -Node: Print230809 -Node: Print Examples232146 -Node: Output Separators234930 -Node: OFMT236690 -Node: Printf238048 -Node: Basic Printf238954 -Node: Control Letters240493 -Node: Format Modifiers244305 -Node: Printf Examples250314 -Node: Redirection253029 -Node: Special Files260013 -Node: Special FD260546 -Ref: Special FD-Footnote-1264171 -Node: Special Network264245 -Node: Special Caveats265095 -Node: Close Files And Pipes265891 -Ref: Close Files And Pipes-Footnote-1272914 -Ref: Close Files And Pipes-Footnote-2273062 -Node: Expressions273212 -Node: Values274344 -Node: Constants275020 -Node: Scalar Constants275700 -Ref: Scalar Constants-Footnote-1276559 -Node: Nondecimal-numbers276741 -Node: Regexp Constants279800 -Node: Using Constant Regexps280275 -Node: Variables283330 -Node: Using Variables283985 -Node: Assignment Options285709 -Node: Conversion287581 -Ref: table-locale-affects292957 -Ref: Conversion-Footnote-1293581 -Node: All Operators293690 -Node: Arithmetic Ops294320 -Node: Concatenation296825 -Ref: Concatenation-Footnote-1299618 -Node: Assignment Ops299738 -Ref: table-assign-ops304726 -Node: Increment Ops306134 -Node: Truth Values and Conditions309604 -Node: Truth Values310687 -Node: Typing and Comparison311736 -Node: Variable Typing312525 -Ref: Variable Typing-Footnote-1316422 -Node: Comparison Operators316544 -Ref: table-relational-ops316954 -Node: POSIX String Comparison320503 -Ref: POSIX String Comparison-Footnote-1321459 -Node: Boolean Ops321597 -Ref: Boolean Ops-Footnote-1325675 -Node: Conditional Exp325766 -Node: Function Calls327498 -Node: Precedence331092 -Node: Locales334761 -Node: Patterns and Actions335850 -Node: Pattern Overview336904 -Node: Regexp Patterns338573 -Node: Expression Patterns339116 -Node: Ranges342801 -Node: BEGIN/END345767 -Node: Using BEGIN/END346529 -Ref: Using BEGIN/END-Footnote-1349260 -Node: I/O And BEGIN/END349366 -Node: BEGINFILE/ENDFILE351648 -Node: Empty354541 -Node: Using Shell Variables354857 -Node: Action Overview357142 -Node: Statements359499 -Node: If Statement361353 -Node: While Statement362852 -Node: Do Statement364896 -Node: For Statement366052 -Node: Switch Statement369204 -Node: Break Statement371301 -Node: Continue Statement373291 -Node: Next Statement375084 -Node: Nextfile Statement377474 -Node: Exit Statement380019 -Node: Built-in Variables382435 -Node: User-modified383530 -Ref: User-modified-Footnote-1391556 -Node: Auto-set391618 -Ref: Auto-set-Footnote-1400909 -Node: ARGC and ARGV401114 -Node: Arrays404965 -Node: Array Basics406470 -Node: Array Intro407296 -Node: Reference to Elements411614 -Node: Assigning Elements413884 -Node: Array Example414375 -Node: Scanning an Array416107 -Node: Controlling Scanning418421 -Ref: Controlling Scanning-Footnote-1423354 -Node: Delete423670 -Ref: Delete-Footnote-1426105 -Node: Numeric Array Subscripts426162 -Node: Uninitialized Subscripts428345 -Node: Multi-dimensional429973 -Node: Multi-scanning433067 -Node: Arrays of Arrays434658 -Node: Functions439303 -Node: Built-in440125 -Node: Calling Built-in441203 -Node: Numeric Functions443191 -Ref: Numeric Functions-Footnote-1447023 -Ref: Numeric Functions-Footnote-2447380 -Ref: Numeric Functions-Footnote-3447428 -Node: String Functions447697 -Ref: String Functions-Footnote-1471194 -Ref: String Functions-Footnote-2471323 -Ref: String Functions-Footnote-3471571 -Node: Gory Details471658 -Ref: table-sub-escapes473337 -Ref: table-sub-posix-92474691 -Ref: table-sub-proposed476034 -Ref: table-posix-sub477384 -Ref: table-gensub-escapes478930 -Ref: Gory Details-Footnote-1480137 -Ref: Gory Details-Footnote-2480188 -Node: I/O Functions480339 -Ref: I/O Functions-Footnote-1486994 -Node: Time Functions487141 -Ref: Time Functions-Footnote-1498033 -Ref: Time Functions-Footnote-2498101 -Ref: Time Functions-Footnote-3498259 -Ref: Time Functions-Footnote-4498370 -Ref: Time Functions-Footnote-5498482 -Ref: Time Functions-Footnote-6498709 -Node: Bitwise Functions498975 -Ref: table-bitwise-ops499533 -Ref: Bitwise Functions-Footnote-1503693 -Node: Type Functions503877 -Node: I18N Functions504347 -Node: User-defined505974 -Node: Definition Syntax506778 -Ref: Definition Syntax-Footnote-1511688 -Node: Function Example511757 -Node: Function Caveats514351 -Node: Calling A Function514772 -Node: Variable Scope515887 -Node: Pass By Value/Reference517862 -Node: Return Statement521302 -Node: Dynamic Typing524283 -Node: Indirect Calls525018 -Node: Internationalization534703 -Node: I18N and L10N536129 -Node: Explaining gettext536815 -Ref: Explaining gettext-Footnote-1541881 -Ref: Explaining gettext-Footnote-2542065 -Node: Programmer i18n542230 -Node: Translator i18n546430 -Node: String Extraction547223 -Ref: String Extraction-Footnote-1548184 -Node: Printf Ordering548270 -Ref: Printf Ordering-Footnote-1551054 -Node: I18N Portability551118 -Ref: I18N Portability-Footnote-1553567 -Node: I18N Example553630 -Ref: I18N Example-Footnote-1556265 -Node: Gawk I18N556337 -Node: Advanced Features556954 -Node: Nondecimal Data558467 -Node: Array Sorting560050 -Node: Controlling Array Traversal560747 -Node: Array Sorting Functions568984 -Ref: Array Sorting Functions-Footnote-1572658 -Ref: Array Sorting Functions-Footnote-2572751 -Node: Two-way I/O572945 -Ref: Two-way I/O-Footnote-1578377 -Node: TCP/IP Networking578447 -Node: Profiling581291 -Node: Library Functions588765 -Ref: Library Functions-Footnote-1591772 -Node: Library Names591943 -Ref: Library Names-Footnote-1595414 -Ref: Library Names-Footnote-2595634 -Node: General Functions595720 -Node: Strtonum Function596673 -Node: Assert Function599603 -Node: Round Function602929 -Node: Cliff Random Function604472 -Node: Ordinal Functions605488 -Ref: Ordinal Functions-Footnote-1608558 -Ref: Ordinal Functions-Footnote-2608810 -Node: Join Function609019 -Ref: Join Function-Footnote-1610790 -Node: Gettimeofday Function610990 -Node: Data File Management614705 -Node: Filetrans Function615337 -Node: Rewind Function619476 -Node: File Checking620863 -Node: Empty Files621957 -Node: Ignoring Assigns624187 -Node: Getopt Function625740 -Ref: Getopt Function-Footnote-1637044 -Node: Passwd Functions637247 -Ref: Passwd Functions-Footnote-1646222 -Node: Group Functions646310 -Node: Walking Arrays654394 -Node: Sample Programs655963 -Node: Running Examples656628 -Node: Clones657356 -Node: Cut Program658580 -Node: Egrep Program668425 -Ref: Egrep Program-Footnote-1676198 -Node: Id Program676308 -Node: Split Program679924 -Ref: Split Program-Footnote-1683443 -Node: Tee Program683571 -Node: Uniq Program686374 -Node: Wc Program693803 -Ref: Wc Program-Footnote-1698069 -Ref: Wc Program-Footnote-2698269 -Node: Miscellaneous Programs698361 -Node: Dupword Program699549 -Node: Alarm Program701580 -Node: Translate Program706329 -Ref: Translate Program-Footnote-1710716 -Ref: Translate Program-Footnote-2710944 -Node: Labels Program711078 -Ref: Labels Program-Footnote-1714449 -Node: Word Sorting714533 -Node: History Sorting718417 -Node: Extract Program720256 -Ref: Extract Program-Footnote-1727739 -Node: Simple Sed727867 -Node: Igawk Program730929 -Ref: Igawk Program-Footnote-1746086 -Ref: Igawk Program-Footnote-2746287 -Node: Anagram Program746425 -Node: Signature Program749493 -Node: Debugger750593 -Node: Debugging751504 -Node: Debugging Concepts751917 -Node: Debugging Terms753773 -Node: Awk Debugging756396 -Node: Sample dgawk session757288 -Node: dgawk invocation757780 -Node: Finding The Bug758962 -Node: List of Debugger Commands765448 -Node: Breakpoint Control766759 -Node: Dgawk Execution Control770395 -Node: Viewing And Changing Data773746 -Node: Dgawk Stack777083 -Node: Dgawk Info778543 -Node: Miscellaneous Dgawk Commands782491 -Node: Readline Support787919 -Node: Dgawk Limitations788757 -Node: Language History790946 -Node: V7/SVR3.1792458 -Node: SVR4794779 -Node: POSIX796221 -Node: BTL797229 -Node: POSIX/GNU797963 -Node: Common Extensions803114 -Node: Ranges and Locales804221 -Ref: Ranges and Locales-Footnote-1808825 -Node: Contributors809046 -Node: Installation813308 -Node: Gawk Distribution814202 -Node: Getting814686 -Node: Extracting815512 -Node: Distribution contents817204 -Node: Unix Installation822426 -Node: Quick Installation823043 -Node: Additional Configuration Options825005 -Node: Configuration Philosophy826482 -Node: Non-Unix Installation828824 -Node: PC Installation829282 -Node: PC Binary Installation830581 -Node: PC Compiling832429 -Node: PC Testing835373 -Node: PC Using836549 -Node: Cygwin840734 -Node: MSYS841734 -Node: VMS Installation842248 -Node: VMS Compilation842851 -Ref: VMS Compilation-Footnote-1843858 -Node: VMS Installation Details843916 -Node: VMS Running845551 -Node: VMS Old Gawk847158 -Node: Bugs847632 -Node: Other Versions851484 -Node: Notes856765 -Node: Compatibility Mode857457 -Node: Additions858240 -Node: Accessing The Source859052 -Node: Adding Code860477 -Node: New Ports866444 -Node: Dynamic Extensions870557 -Node: Internals871933 -Node: Plugin License881036 -Node: Sample Library881670 -Node: Internal File Description882356 -Node: Internal File Ops886071 -Ref: Internal File Ops-Footnote-1890852 -Node: Using Internal File Ops890992 -Node: Future Extensions893369 -Node: Basic Concepts895873 -Node: Basic High Level896630 -Ref: Basic High Level-Footnote-1900665 -Node: Basic Data Typing900850 -Node: Floating Point Issues905375 -Node: String Conversion Precision906458 -Ref: String Conversion Precision-Footnote-1908158 -Node: Unexpected Results908267 -Node: POSIX Floating Point Problems910093 -Ref: POSIX Floating Point Problems-Footnote-1913798 -Node: Glossary913836 -Node: Copying938812 -Node: GNU Free Documentation License976369 -Node: Index1001506 +Node: Foreword31559 +Node: Preface35904 +Ref: Preface-Footnote-138957 +Ref: Preface-Footnote-239063 +Node: History39295 +Node: Names41686 +Ref: Names-Footnote-143163 +Node: This Manual43235 +Ref: This Manual-Footnote-148173 +Node: Conventions48273 +Node: Manual History50407 +Ref: Manual History-Footnote-153677 +Ref: Manual History-Footnote-253718 +Node: How To Contribute53792 +Node: Acknowledgments54936 +Node: Getting Started59432 +Node: Running gawk61811 +Node: One-shot62997 +Node: Read Terminal64222 +Ref: Read Terminal-Footnote-165872 +Ref: Read Terminal-Footnote-266148 +Node: Long66319 +Node: Executable Scripts67695 +Ref: Executable Scripts-Footnote-169564 +Ref: Executable Scripts-Footnote-269666 +Node: Comments70213 +Node: Quoting72680 +Node: DOS Quoting77303 +Node: Sample Data Files77978 +Node: Very Simple81010 +Node: Two Rules85609 +Node: More Complex87756 +Ref: More Complex-Footnote-190686 +Node: Statements/Lines90771 +Ref: Statements/Lines-Footnote-195233 +Node: Other Features95498 +Node: When96426 +Node: Invoking Gawk98573 +Node: Command Line99958 +Node: Options100741 +Ref: Options-Footnote-1115098 +Node: Other Arguments115123 +Node: Naming Standard Input117781 +Node: Environment Variables118875 +Node: AWKPATH Variable119319 +Ref: AWKPATH Variable-Footnote-1121916 +Node: Other Environment Variables122176 +Node: Exit Status124668 +Node: Include Files125343 +Node: Obsolete128828 +Node: Undocumented129514 +Node: Regexp129755 +Node: Regexp Usage131144 +Node: Escape Sequences133170 +Node: Regexp Operators138933 +Ref: Regexp Operators-Footnote-1146313 +Ref: Regexp Operators-Footnote-2146460 +Node: Bracket Expressions146558 +Ref: table-char-classes148448 +Node: GNU Regexp Operators150971 +Node: Case-sensitivity154694 +Ref: Case-sensitivity-Footnote-1157662 +Ref: Case-sensitivity-Footnote-2157897 +Node: Leftmost Longest158005 +Node: Computed Regexps159206 +Node: Reading Files162616 +Node: Records164620 +Ref: Records-Footnote-1173294 +Node: Fields173331 +Ref: Fields-Footnote-1176364 +Node: Nonconstant Fields176450 +Node: Changing Fields178652 +Node: Field Separators184633 +Node: Default Field Splitting187262 +Node: Regexp Field Splitting188379 +Node: Single Character Fields191721 +Node: Command Line Field Separator192780 +Node: Field Splitting Summary196221 +Ref: Field Splitting Summary-Footnote-1199413 +Node: Constant Size199514 +Node: Splitting By Content204098 +Ref: Splitting By Content-Footnote-1207824 +Node: Multiple Line207864 +Ref: Multiple Line-Footnote-1213711 +Node: Getline213890 +Node: Plain Getline216106 +Node: Getline/Variable218195 +Node: Getline/File219336 +Node: Getline/Variable/File220658 +Ref: Getline/Variable/File-Footnote-1222257 +Node: Getline/Pipe222344 +Node: Getline/Variable/Pipe224904 +Node: Getline/Coprocess226011 +Node: Getline/Variable/Coprocess227254 +Node: Getline Notes227968 +Node: Getline Summary229910 +Ref: table-getline-variants230253 +Node: Read Timeout231109 +Ref: Read Timeout-Footnote-1234854 +Node: Command line directories234911 +Node: Printing235541 +Node: Print237172 +Node: Print Examples238509 +Node: Output Separators241293 +Node: OFMT243053 +Node: Printf244411 +Node: Basic Printf245317 +Node: Control Letters246856 +Node: Format Modifiers250668 +Node: Printf Examples256677 +Node: Redirection259392 +Node: Special Files266376 +Node: Special FD266909 +Ref: Special FD-Footnote-1270534 +Node: Special Network270608 +Node: Special Caveats271458 +Node: Close Files And Pipes272254 +Ref: Close Files And Pipes-Footnote-1279277 +Ref: Close Files And Pipes-Footnote-2279425 +Node: Expressions279575 +Node: Values280707 +Node: Constants281383 +Node: Scalar Constants282063 +Ref: Scalar Constants-Footnote-1282922 +Node: Nondecimal-numbers283104 +Node: Regexp Constants286163 +Node: Using Constant Regexps286638 +Node: Variables289693 +Node: Using Variables290348 +Node: Assignment Options292072 +Node: Conversion293944 +Ref: table-locale-affects299320 +Ref: Conversion-Footnote-1299944 +Node: All Operators300053 +Node: Arithmetic Ops300683 +Node: Concatenation303188 +Ref: Concatenation-Footnote-1305981 +Node: Assignment Ops306101 +Ref: table-assign-ops311089 +Node: Increment Ops312497 +Node: Truth Values and Conditions315967 +Node: Truth Values317050 +Node: Typing and Comparison318099 +Node: Variable Typing318888 +Ref: Variable Typing-Footnote-1322785 +Node: Comparison Operators322907 +Ref: table-relational-ops323317 +Node: POSIX String Comparison326866 +Ref: POSIX String Comparison-Footnote-1327822 +Node: Boolean Ops327960 +Ref: Boolean Ops-Footnote-1332038 +Node: Conditional Exp332129 +Node: Function Calls333861 +Node: Precedence337455 +Node: Locales341124 +Node: Patterns and Actions342213 +Node: Pattern Overview343267 +Node: Regexp Patterns344936 +Node: Expression Patterns345479 +Node: Ranges349164 +Node: BEGIN/END352130 +Node: Using BEGIN/END352892 +Ref: Using BEGIN/END-Footnote-1355623 +Node: I/O And BEGIN/END355729 +Node: BEGINFILE/ENDFILE358011 +Node: Empty360904 +Node: Using Shell Variables361220 +Node: Action Overview363505 +Node: Statements365862 +Node: If Statement367716 +Node: While Statement369215 +Node: Do Statement371259 +Node: For Statement372415 +Node: Switch Statement375567 +Node: Break Statement377664 +Node: Continue Statement379654 +Node: Next Statement381447 +Node: Nextfile Statement383837 +Node: Exit Statement386382 +Node: Built-in Variables388798 +Node: User-modified389893 +Ref: User-modified-Footnote-1398248 +Node: Auto-set398310 +Ref: Auto-set-Footnote-1408156 +Node: ARGC and ARGV408361 +Node: Arrays412212 +Node: Array Basics413717 +Node: Array Intro414543 +Node: Reference to Elements418861 +Node: Assigning Elements421131 +Node: Array Example421622 +Node: Scanning an Array423354 +Node: Controlling Scanning425668 +Ref: Controlling Scanning-Footnote-1430601 +Node: Delete430917 +Ref: Delete-Footnote-1433352 +Node: Numeric Array Subscripts433409 +Node: Uninitialized Subscripts435592 +Node: Multi-dimensional437220 +Node: Multi-scanning440314 +Node: Arrays of Arrays441905 +Node: Functions446550 +Node: Built-in447372 +Node: Calling Built-in448450 +Node: Numeric Functions450438 +Ref: Numeric Functions-Footnote-1454270 +Ref: Numeric Functions-Footnote-2454627 +Ref: Numeric Functions-Footnote-3454675 +Node: String Functions454944 +Ref: String Functions-Footnote-1478441 +Ref: String Functions-Footnote-2478570 +Ref: String Functions-Footnote-3478818 +Node: Gory Details478905 +Ref: table-sub-escapes480584 +Ref: table-sub-posix-92481938 +Ref: table-sub-proposed483281 +Ref: table-posix-sub484631 +Ref: table-gensub-escapes486177 +Ref: Gory Details-Footnote-1487384 +Ref: Gory Details-Footnote-2487435 +Node: I/O Functions487586 +Ref: I/O Functions-Footnote-1494241 +Node: Time Functions494388 +Ref: Time Functions-Footnote-1505280 +Ref: Time Functions-Footnote-2505348 +Ref: Time Functions-Footnote-3505506 +Ref: Time Functions-Footnote-4505617 +Ref: Time Functions-Footnote-5505729 +Ref: Time Functions-Footnote-6505956 +Node: Bitwise Functions506222 +Ref: table-bitwise-ops506780 +Ref: Bitwise Functions-Footnote-1510940 +Node: Type Functions511124 +Node: I18N Functions511594 +Node: User-defined513221 +Node: Definition Syntax514025 +Ref: Definition Syntax-Footnote-1518935 +Node: Function Example519004 +Node: Function Caveats521598 +Node: Calling A Function522019 +Node: Variable Scope523134 +Node: Pass By Value/Reference525109 +Node: Return Statement528549 +Node: Dynamic Typing531530 +Node: Indirect Calls532265 +Node: Internationalization541950 +Node: I18N and L10N543389 +Node: Explaining gettext544075 +Ref: Explaining gettext-Footnote-1549141 +Ref: Explaining gettext-Footnote-2549325 +Node: Programmer i18n549490 +Node: Translator i18n553690 +Node: String Extraction554483 +Ref: String Extraction-Footnote-1555444 +Node: Printf Ordering555530 +Ref: Printf Ordering-Footnote-1558314 +Node: I18N Portability558378 +Ref: I18N Portability-Footnote-1560827 +Node: I18N Example560890 +Ref: I18N Example-Footnote-1563525 +Node: Gawk I18N563597 +Node: Arbitrary Precision Arithmetic564214 +Ref: Arbitrary Precision Arithmetic-Footnote-1567089 +Node: Floating-point Programming567237 +Node: Floating-point Representation572507 +Node: Floating-point Context573611 +Ref: table-ieee-formats574446 +Node: Rounding Mode575816 +Ref: table-rounding-modes576443 +Ref: Rounding Mode-Footnote-1579566 +Node: Arbitrary Precision Floats579747 +Ref: Arbitrary Precision Floats-Footnote-1581788 +Node: Setting Precision582099 +Node: Setting Rounding Mode584857 +Node: Floating-point Constants585774 +Node: Changing Precision587193 +Ref: Changing Precision-Footnote-1588593 +Node: Exact Arithmetic588766 +Node: Integer Programming591779 +Node: Arbitrary Precision Integers593559 +Ref: Arbitrary Precision Integers-Footnote-1596583 +Node: MPFR and GMP Libraries596729 +Node: Advanced Features597114 +Node: Nondecimal Data598637 +Node: Array Sorting600220 +Node: Controlling Array Traversal600917 +Node: Array Sorting Functions609154 +Ref: Array Sorting Functions-Footnote-1612828 +Ref: Array Sorting Functions-Footnote-2612921 +Node: Two-way I/O613115 +Ref: Two-way I/O-Footnote-1618547 +Node: TCP/IP Networking618617 +Node: Profiling621461 +Node: Library Functions628915 +Ref: Library Functions-Footnote-1631922 +Node: Library Names632093 +Ref: Library Names-Footnote-1635564 +Ref: Library Names-Footnote-2635784 +Node: General Functions635870 +Node: Strtonum Function636823 +Node: Assert Function639753 +Node: Round Function643079 +Node: Cliff Random Function644622 +Node: Ordinal Functions645638 +Ref: Ordinal Functions-Footnote-1648708 +Ref: Ordinal Functions-Footnote-2648960 +Node: Join Function649169 +Ref: Join Function-Footnote-1650940 +Node: Gettimeofday Function651140 +Node: Data File Management654855 +Node: Filetrans Function655487 +Node: Rewind Function659626 +Node: File Checking661013 +Node: Empty Files662107 +Node: Ignoring Assigns664337 +Node: Getopt Function665890 +Ref: Getopt Function-Footnote-1677194 +Node: Passwd Functions677397 +Ref: Passwd Functions-Footnote-1686372 +Node: Group Functions686460 +Node: Walking Arrays694544 +Node: Sample Programs696113 +Node: Running Examples696778 +Node: Clones697506 +Node: Cut Program698730 +Node: Egrep Program708575 +Ref: Egrep Program-Footnote-1716348 +Node: Id Program716458 +Node: Split Program720074 +Ref: Split Program-Footnote-1723593 +Node: Tee Program723721 +Node: Uniq Program726524 +Node: Wc Program733953 +Ref: Wc Program-Footnote-1738219 +Ref: Wc Program-Footnote-2738419 +Node: Miscellaneous Programs738511 +Node: Dupword Program739699 +Node: Alarm Program741730 +Node: Translate Program746479 +Ref: Translate Program-Footnote-1750866 +Ref: Translate Program-Footnote-2751094 +Node: Labels Program751228 +Ref: Labels Program-Footnote-1754599 +Node: Word Sorting754683 +Node: History Sorting758567 +Node: Extract Program760406 +Ref: Extract Program-Footnote-1767889 +Node: Simple Sed768017 +Node: Igawk Program771079 +Ref: Igawk Program-Footnote-1786236 +Ref: Igawk Program-Footnote-2786437 +Node: Anagram Program786575 +Node: Signature Program789643 +Node: Debugger790743 +Node: Debugging791695 +Node: Debugging Concepts792128 +Node: Debugging Terms793984 +Node: Awk Debugging796581 +Node: Sample Debugging Session797473 +Node: Debugger Invocation797993 +Node: Finding The Bug799322 +Node: List of Debugger Commands805810 +Node: Breakpoint Control807144 +Node: Debugger Execution Control810808 +Node: Viewing And Changing Data814168 +Node: Execution Stack817524 +Node: Debugger Info818991 +Node: Miscellaneous Debugger Commands822972 +Node: Readline Support828417 +Node: Limitations829248 +Node: Language History831500 +Node: V7/SVR3.1833012 +Node: SVR4835333 +Node: POSIX836775 +Node: BTL837783 +Node: POSIX/GNU838517 +Node: Common Extensions843668 +Node: Ranges and Locales844775 +Ref: Ranges and Locales-Footnote-1849379 +Node: Contributors849600 +Node: Installation853861 +Node: Gawk Distribution854755 +Node: Getting855239 +Node: Extracting856065 +Node: Distribution contents857757 +Node: Unix Installation862979 +Node: Quick Installation863596 +Node: Additional Configuration Options865558 +Node: Configuration Philosophy867035 +Node: Non-Unix Installation869377 +Node: PC Installation869835 +Node: PC Binary Installation871134 +Node: PC Compiling872982 +Node: PC Testing875926 +Node: PC Using877102 +Node: Cygwin881287 +Node: MSYS882287 +Node: VMS Installation882801 +Node: VMS Compilation883404 +Ref: VMS Compilation-Footnote-1884411 +Node: VMS Installation Details884469 +Node: VMS Running886104 +Node: VMS Old Gawk887711 +Node: Bugs888185 +Node: Other Versions892037 +Node: Notes897352 +Node: Compatibility Mode898044 +Node: Additions898827 +Node: Accessing The Source899639 +Node: Adding Code901064 +Node: New Ports907031 +Node: Dynamic Extensions911144 +Node: Internals912584 +Node: Plugin License921103 +Node: Loading Extensions921741 +Node: Sample Library923551 +Node: Internal File Description924241 +Node: Internal File Ops927956 +Ref: Internal File Ops-Footnote-1932680 +Node: Using Internal File Ops932820 +Node: Future Extensions935197 +Node: Basic Concepts937701 +Node: Basic High Level938458 +Ref: Basic High Level-Footnote-1942493 +Node: Basic Data Typing942678 +Node: Floating Point Issues947203 +Node: String Conversion Precision948286 +Ref: String Conversion Precision-Footnote-1949986 +Node: Unexpected Results950095 +Node: POSIX Floating Point Problems951921 +Ref: POSIX Floating Point Problems-Footnote-1955626 +Node: Glossary955664 +Node: Copying980640 +Node: GNU Free Documentation License1018197 +Node: Index1043334 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index 83bd3b5d..8cd7e38e 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -79,9 +79,11 @@ @c some special symbols @iftex @set LEQ @math{@leq} +@set PI @math{@pi} @end iftex @ifnottex @set LEQ <= +@set PI @i{pi} @end ifnottex @ifnottex @@ -285,12 +287,14 @@ particular records in a file and perform operations upon them. * Functions:: Built-in and user-defined functions. * Internationalization:: Getting @command{gawk} to speak your language. +* Arbitrary Precision Arithmetic:: Arbitrary precision arithmetic with + @command{gawk}. * Advanced Features:: Stuff for advanced users, specific to @command{gawk}. * Library Functions:: A Library of @command{awk} Functions. * Sample Programs:: Many @command{awk} programs with complete explanations. -* Debugger:: The @code{dgawk} debugger. +* Debugger:: The @code{gawk} debugger. * Language History:: The evolution of the @command{awk} language. * Installation:: Installing @command{gawk} under various @@ -393,6 +397,7 @@ particular records in a file and perform operations upon them. * Getline Notes:: Important things to know about @code{getline}. * Getline Summary:: Summary of @code{getline} Variants. +* Read Timeout:: Reading input with a timeout. * Command line directories:: What happens if you put a directory on the command line. * Print:: The @code{print} statement. @@ -550,6 +555,21 @@ particular records in a file and perform operations upon them. * I18N Portability:: @command{awk}-level portability issues. * I18N Example:: A simple i18n example. * Gawk I18N:: @command{gawk} is also internationalized. +* Floating-point Programming:: Effective floating-point programming. +* Floating-point Representation:: Binary floating-point representation. +* Floating-point Context:: Floating-point context. +* Rounding Mode:: Floating-point rounding mode. +* Arbitrary Precision Floats:: Arbitrary precision floating-point + arithmetic with @command{gawk}. +* Setting Precision:: Setting the working precision. +* Setting Rounding Mode:: Setting the rounding mode. +* Floating-point Constants:: Representing floating-point constants. +* Changing Precision:: Changing the precision of a number. +* Exact Arithmetic:: Exact arithmetic with floating-point numbers. +* Integer Programming:: Effective integer programming. +* Arbitrary Precision Integers:: Arbitrary precision integer + arithmetic with @command{gawk}. +* MPFR and GMP Libraries:: Information about the MPFR and GMP libraries. * Nondecimal Data:: Allowing nondecimal input data. * Array Sorting:: Facilities for controlling array traversal and sorting arrays. @@ -614,23 +634,23 @@ particular records in a file and perform operations upon them. * Anagram Program:: Finding anagrams from a dictionary. * Signature Program:: People do amazing things with too much time on their hands. -* Debugging:: Introduction to @command{dgawk}. -* Debugging Concepts:: Debugging In General. +* Debugging:: Introduction to @command{gawk} Debugger. +* Debugging Concepts:: Debugging in General. * Debugging Terms:: Additional Debugging Concepts. * Awk Debugging:: Awk Debugging. -* Sample dgawk session:: Sample @command{dgawk} session. -* dgawk invocation:: @command{dgawk} Invocation. -* Finding The Bug:: Finding The Bug. -* List of Debugger Commands:: Main @command{dgawk} Commands. -* Breakpoint Control:: Control of breakpoints. -* Dgawk Execution Control:: Control of execution. -* Viewing And Changing Data:: Viewing and changing data. -* Dgawk Stack:: Dealing with the stack. -* Dgawk Info:: Obtaining information about the program and - the debugger state. -* Miscellaneous Dgawk Commands:: Miscellaneous Commands. +* Sample Debugging Session:: Sample Debugging Session. +* Debugger Invocation:: How to Start the Debugger. +* Finding The Bug:: Finding the Bug. +* List of Debugger Commands:: Main Commands. +* Breakpoint Control:: Control of Breakpoints. +* Debugger Execution Control:: Control of Execution. +* Viewing And Changing Data:: Viewing and Changing Data. +* Execution Stack:: Dealing with the Stack. +* Debugger Info:: Obtaining Information about the Program and + the Debugger State. +* Miscellaneous Debugger Commands:: Miscellaneous Commands. * Readline Support:: Readline Support. -* Dgawk Limitations:: Limitations and future plans. +* Limitations:: Limitations and Future Plans. * V7/SVR3.1:: The major changes between V7 and System V Release 3.1. * SVR4:: Minor changes between System V Releases 3.1 @@ -686,6 +706,7 @@ particular records in a file and perform operations upon them. * Internals:: A brief look at some @command{gawk} internals. * Plugin License:: A note about licensing. +* Loading Extensions:: How to load dynamic extensions. * Sample Library:: A example of new functions. * Internal File Description:: What the new functions will do. * Internal File Ops:: The code for internal file operations. @@ -1164,8 +1185,7 @@ provide many sample @command{awk} programs. Reading them allows you to see @command{awk} solving real problems. -@ref{Debugger}, describes the @command{awk} debugger, -@command{dgawk}. +@ref{Debugger}, describes the @command{awk} debugger. @ref{Language History}, describes how the @command{awk} language has evolved since @@ -1594,10 +1614,13 @@ has been and continues to be a pleasure working with this team of fine people. John Haque contributed the modifications to convert @command{gawk} -into a byte-code interpreter, including the debugger. Stephen Davies +into a byte-code interpreter, including the debugger, and the +additional modifications for support of arbitrary precision arithmetic. +Stephen Davies contributed to the effort to bring the byte-code changes into the mainstream code base. Efraim Yawitz contributed the initial text of @ref{Debugger}. +John Haque contributed the initial text of @ref{Arbitrary Precision Arithmetic}. @cindex Kernighan, Brian I would like to thank Brian Kernighan for invaluable assistance during the @@ -3103,6 +3126,19 @@ inadvertently use global variables that you meant to be local. (This is a particularly easy mistake to make with simple variable names like @code{i}, @code{j}, etc.) +@item -D@r{[}@var{file}@r{]} +@itemx --debug=@r{[}@var{file}@r{]} +@cindex @code{-D} option +@cindex @code{--debug} option +@cindex @command{awk} debugging, enabling +Enable debugging of @command{awk} programs +(@pxref{Debugging}). +By default, the debugger reads commands interactively from the terminal. +The optional @var{file} argument allows you to specify a file with a list +of commands for the debugger to execute non-interactively. +No space is allowed between the @option{-D} and @var{file}, if +@var{file} is supplied. + @item -e @var{program-text} @itemx --source @var{program-text} @cindex @code{-e} option @@ -3168,6 +3204,15 @@ for information about this option. Print a ``usage'' message summarizing the short and long style options that @command{gawk} accepts and then exit. +@item -l @var{lib} +@itemx --load @var{lib} +@cindex @code{-l} option +@cindex @code{--load} option +@cindex loading, library +Load a shared library @var{lib}. This searches for the library using the @env{AWKPATH} +environment variable. The suffix @samp{.so} in the library name is optional. +The library initialization routine should be named @code{dlload()}. + @item -L @r{[}value@r{]} @itemx --lint@r{[}=value@r{]} @cindex @code{-l} option @@ -3191,6 +3236,14 @@ when eliminating problems pointed out by @option{--lint}, you should take care to search for all occurrences of each inappropriate construct. As @command{awk} programs are usually short, doing so is not burdensome. +@item -M +@itemx --bignum +@cindex @code{-M} option +@cindex @code{--bignum} option +Force arbitrary precision arithmetic on numbers. This option has no effect +if @command{gawk} is not compiled to use the GNU MPFR and MP libraries +(@pxref{Arbitrary Precision Arithmetic}). + @item -n @itemx --non-decimal-data @cindex @code{-n} option @@ -3214,6 +3267,18 @@ Use with care. Force the use of the locale's decimal point character when parsing numeric input data (@pxref{Locales}). +@item -o@r{[}@var{file}@r{]} +@itemx --pretty-print@r{[}=@var{file}@r{]} +@cindex @code{-o} option +@cindex @code{--pretty-print} option +@cindex @command{awk} enabling +Enable pretty-printing of @command{awk} programs. +By default, output program is created in a file named @file{awkprof.out}. +The optional @var{file} argument allows you to specify a different +@value{FN} for the output. +No space is allowed between the @option{-o} and @var{file}, if +@var{file} is supplied. + @item -O @itemx --optimize @cindex @code{--optimize} option @@ -3226,7 +3291,7 @@ maintainer hopes to add more optimizations over time. @itemx --profile@r{[}=@var{file}@r{]} @cindex @code{-p} option @cindex @code{--profile} option -@cindex @command{awk} programs, profiling, enabling +@cindex @command{awk} profiling, enabling Enable profiling of @command{awk} programs (@pxref{Profiling}). By default, profiles are created in a file named @file{awkprof.out}. @@ -3235,10 +3300,8 @@ The optional @var{file} argument allows you to specify a different No space is allowed between the @option{-p} and @var{file}, if @var{file} is supplied. -When run with @command{gawk}, the profile is just a ``pretty printed'' version -of the program. When run with @command{pgawk}, the profile contains execution -counts for each statement in the program in the left margin, and function -call counts for each function. +The profile contains execution counts for each statement in the program +in the left margin, and function call counts for each function. @item -P @itemx --posix @@ -3302,14 +3365,6 @@ This is now @command{gawk}'s default behavior. Nevertheless, this option remains both for backward compatibility, and for use in combination with the @option{--traditional} option. -@item -R @var{file} -@itemx --command=@var{file} -@cindex @code{-R} option -@cindex @code{--command} option -@command{dgawk} only. -Read @command{dgawk} debugger options and commands from @var{file}. -@xref{Dgawk Info}, for more information. - @item -S @itemx --sandbox @cindex @code{-S} option @@ -3633,6 +3688,11 @@ Specifies the interval between connection retries, in milliseconds. On systems that do not support the @code{usleep()} system call, the value is rounded up to an integral number of seconds. + +@item GAWK_READ_TIMEOUT +Specifies the time, in milliseconds, for @command{gawk} to +wait for input before returning with an error. +@xref{Read Timeout}. @end table The environment variables in the following list are meant @@ -3706,7 +3766,7 @@ into smaller, more manageable pieces, and also lets you reuse common @command{aw code from various @command{awk} scripts. In other words, you can group together @command{awk} functions, used to carry out specific tasks, into external files. These files can be used just like function libraries, -using the @samp{@@include} keyword in conjunction with the @code{AWKPATH} +using the @samp{@@include} keyword in conjunction with the @env{AWKPATH} environment variable. Let's see an example. @@ -5119,6 +5179,8 @@ used with it do not have to be named on the @command{awk} command line * Multiple Line:: Reading multi-line records. * Getline:: Reading files under explicit program control using the @code{getline} function. +* Read Timeout:: Reading input with a timeout. + * Command line directories:: What happens if you put a directory on the command line. @end menu @@ -7197,6 +7259,110 @@ and whether the variant is standard or a @command{gawk} extension. @c ENDOFRANGE inex @c ENDOFRANGE infir +@node Read Timeout +@section Reading Input With A Timeout +@cindex timeout, reading input + +You may specify a timeout in milliseconds for reading input from a terminal, +pipe or two-way communication including, TCP/IP sockets. This can be done +on a per input, command or connection basis, by setting a special element +in the @code{PROCINFO} array: + +@example +PROCINFO["input_name", "READ_TIMEOUT"] = @var{timeout in milliseconds} +@end example + +When set, this will cause @command{gawk} to time out and return failure +if no data is available to read within the specified timeout period. +For example, a TCP client can decide to give up on receiving +any response from the server after a certain amount of time: + +@example +Service = "/inet/tcp/0/localhost/daytime" +PROCINFO[Service, "READ_TIMEOUT"] = 100 +if ((Service |& getline) > 0) + print $0 +else if (ERRNO != "") + print ERRNO +@end example + +Here is how to read interactively from the terminal@footnote{This assumes +that standard input is the keyboard} without waiting +for more than five seconds: + +@example +PROCINFO["/dev/stdin", "READ_TIMEOUT"] = 5000 +while ((getline < "/dev/stdin") > 0) + print $0 +@end example + +@command{gawk} will terminate the read operation if input does not +arrive after waiting for the timeout period, return failure +and set the @code{ERRNO} variable to an appropriate string value. +A negative or zero value for the timeout is the same as specifying +no timeout at all. + +A timeout can also be set for reading from the terminal in the implicit +loop that reads input records and matches them against patterns, +like so: + +@example +$ @kbd{ gawk 'BEGIN @{ PROCINFO["-", "READ_TIMEOUT"] = 5000 @}} +> @kbd{@{ print "You entered: " $0 @}'} +@kbd{gawk} +@print{} You entered: gawk +@end example + +In this case, failure to respond within five seconds results in the following +error message: + +@example +@error{} gawk: cmd. line:2: (FILENAME=- FNR=1) fatal: error reading input file `-': Connection timed out +@end example + +The timeout can be set or changed at any time, and will take effect on the +next attempt to read from the input device. In the following example, +we start with a timeout value of one second, and progressively +reduce it by one-tenth of a second until we wait indefinitely +for the input to arrive: + +@example +PROCINFO[Service, "READ_TIMEOUT"] = 1000 +while ((Service |& getline) > 0) @{ + print $0 + PROCINFO[S, "READ_TIMEOUT"] -= 100 +@} +@end example + +@quotation NOTE +You should not assume that the read operation will block +exactly after the tenth record has been printed. It is possible that +@command{gawk} will read and buffer more than one record's +worth of data the first time. Because of this, changing the value +of timeout like in the above example is not very useful. +@end quotation + +If the @code{PROCINFO} element is not present and the environment +variable @env{GAWK_READ_TIMEOUT} exists, +@command{gawk} uses its value to initialize the timeout value. +The exclusive use of the environment variable to specify timeout +has the disadvantage of not being able to control it +on a per command or connection basis. + +@command{gawk} considers a timeout event to be an error even though +the attempt to read from the underlying device may +succeed in a later attempt. This is a limitation, and it also +means that you cannot use this to multiplex input from +two or more sources. + +Assigning a timeout value prevents read operations from +blocking indefinitely. But bear in mind that there are other ways +@command{gawk} can stall waiting for an input device to be ready. +A network client can sometimes take a long time to establish +a connection before it can start reading any data, +or the attempt to open a FIFO special file for reading can block +indefinitely until some other process opens it for writing. + @node Command line directories @section Directories On The Command Line @cindex directories, command line @@ -12470,6 +12636,18 @@ This is the output record separator. It is output at the end of every @code{print} statement. Its default value is @code{"\n"}, the newline character. (@xref{Output Separators}.) +@cindex @code{PREC} variable +@item PREC # +The working precision of arbitrary precision floating-point numbers, +53 by default (@pxref{Setting Precision}). + +@cindex @code{ROUNDMODE} variable +@item ROUNDMODE # +The rounding mode to use for arbitrary precision arithmetic on +numbers, by default @code{"N"} (@samp{roundTiesToEven} in +the IEEE-754 standard) +(@pxref{Setting Rounding Mode}). + @cindex @code{RS} variable @cindex separators, for records @cindex record separators @@ -12753,6 +12931,25 @@ The value of the @code{getuid()} system call. The version of @command{gawk}. @end table +The following additional elements in the array +are available to provide information about the MPFR and GMP libraries +if your version of @command{gawk} supports arbitrary precision numbers +(@pxref{Arbitrary Precision Arithmetic}): + +@table @code +@item PROCINFO["mpfr_version"] +The version of the GNU MPFR library. + +@item PROCINFO["gmp_version"] +The version of the GNU MP library. + +@item PROCINFO["prec_max"] +The maximum precision supported by MPFR. + +@item PROCINFO["prec_min"] +The minimum precision required by MPFR. +@end table + On some systems, there may be elements in the array, @code{"group1"} through @code{"group@var{N}"} for some @var{N}. @var{N} is the number of supplementary groups that the process has. Use the @code{in} operator @@ -18171,6 +18368,863 @@ then @command{gawk} produces usage messages, warnings, and fatal errors in the local language. @c ENDOFRANGE inloc +@node Arbitrary Precision Arithmetic +@chapter Arbitrary Precision Arithmetic with @command{gawk} +@cindex arbitrary precision +@cindex multiple precision +@cindex infinite precision +@cindex floating-point numbers, arbitrary precision +@cindex MPFR +@cindex GMP + +@cindex Knuth, Donald +@quotation +@i{There's a credibility gap: We don't know how much of the computer's answers +to believe. Novice computer users solve this problem by implicitly trusting +in the computer as an infallible authority; they tend to believe that all +digits of a printed answer are significant. Disillusioned computer users have +just the opposite approach; they are constantly afraid that their answers +are almost meaningless.} + +Donald Knuth@footnote{Donald E.@: Knuth. +@cite{The Art of Computer Programming}. Volume 2, +@cite{Seminumerical Algorithms}, third edition, +1998, ISBN 0-201-89683-4, p.@: 229.} +@end quotation + +This @value{SECTION} decsribes how to use the arbitrary precision +(also known as @dfn{multiple precision} or @dfn{infinite precision}) numeric +capabilites in @command{gawk} to produce maximally accurate results +when you need it. But first you should check if your version of +@command{gawk} supports arbitrary precision arithmetic. +The easiest way to find out is to look at the output of +the following command: + +@example +$ @kbd{gawk --version} +@print{} GNU Awk 4.1.0 (GNU MPFR 3.1.0, GNU MP 5.0.3) +@print{} Copyright (C) 1989, 1991-2012 Free Software Foundation. +@dots{} +@end example + +@command{gawk} uses the +@uref{http://www.mpfr.org, GNU MPFR} +and +@uref{http://gmplib.org, GNU MP} (GMP) +libraries for arbitrary precision +arithmetic on numbers. So if you do not see the names of these libraries +in the output, then your version of @command{gawk} does not support +arbitrary precision arithmetic. + +Even if you aren't interested in arbitrary precision arithmetic, you +may still benifit from knowing about how @command{gawk} handles numbers +in general, and the limitations of doing arithmetic with ordinary +@command{gawk} numbers. + +@menu +* Floating-point Programming:: Effective Floating-point Programming. +* Floating-point Representation:: Binary Floating-point Representation. +* Floating-point Context:: Floating-point Context. +* Rounding Mode:: Floating-point Rounding Mode. +* Arbitrary Precision Floats:: Arbitrary Precision Floating-point + Arithmetic with @command{gawk}. +* Setting Precision:: Setting the Working Precision. +* Setting Rounding Mode:: Setting the Rounding Mode. +* Floating-point Constants:: Representing Floating-point Constants. +* Changing Precision:: Changing the Precision of a Number. +* Exact Arithmetic:: Exact Arithmetic with Floating-point Numbers. +* Integer Programming:: Effective Integer Programming. +* Arbitrary Precision Integers:: Arbitrary Precision Integer + Arithmetic with @command{gawk}. +* MPFR and GMP Libraries:: Information About the MPFR and GMP Libraries. +@end menu + +@node Floating-point Programming +@section Effective Floating-point Programming + +Numerical programming is an extensive area; if you need to develop +sophisticated numerical algorithms then @command{gawk} may not be +the ideal tool, and this documentation may not be sufficient. +@c FIXME: JOHN: Do you want to cite some actual books? +It might require a book or two to communicate how to compute +with ideal accuracy and precision +and the result often depends on the particular application. + +@quotation NOTE +A floating-point calculation's @dfn{accuracy} is how close it comes +to the real value. This is as opposed to the @dfn{precision}, which +usually refers to the number of bits used to represent the number +(see @uref{http://en.wikipedia.org/wiki/Accuracy_and_precision, +the Wikipedia article} for more information). +@end quotation + +Binary floating-point representations and arithmetic are inexact. +Simple values like 0.1 cannot be precisely represented using +binary floating-point numbers, and the limited precision of +floating-point numbers means that slight changes in +the order of operations or the precision of intermediate storage +can change the result. To make matters worse with arbitrary precision +floating-point, you can set the precision before starting a computation, +but then you cannot be sure of the number of significant decimal places +in the final result. + +Sometimes you need to think more about what you really want +and what's really happening. Consider the two numbers +in the following example: + +@example +x = 0.875 # 1/2 + 1/4 + 1/8 +y = 0.425 +@end example + +Unlike the number in @code{y}, the number stored in @code{x} +is exactly representable +in binary since it can be written as a finite sum of one or +more fractions whose denominators are all powers of two. +When @command{gawk} reads a floating-point number from +program source, it automatically rounds that number to whatever +precision your machine supports. If you try to print the numeric +content of a variable using an output format string of @code{"%.17g"}, +it may not produce the same number as you assigned to it: + +@example +$ @kbd{gawk 'BEGIN @{ x = 0.875; y = 0.425} +> @kbd{ printf("%0.17g, %0.17g\n", x, y) @}'} +@print{} 0.875, 0.42499999999999999 +@end example + +Often the error is so small you do not even notice it, and if you do, +you can always specify how much precision you would like in your output. +Usually this is a format string like @code{"%.15g"}, which when +used in the previous example, produces an output identical to the input. + +Because the underlying representation can be little bit off from the exact value, +comparing floats to see if they are equal is generally not a good idea. +Here is an example where it does not work like you expect: + +@example +$ @kbd{gawk 'BEGIN @{ print (0.1 + 12.2 == 12.3) @}'} +@print{} 0 +@end example + +The loss of accuracy during a single computation with floating-point numbers +usually isn't enough to worry about. However, if you compute a value +which is the result of a sequence of floating point operations, +the error can accumulate and greatly affect the computation itself. +Here is an attempt to compute the value of the constant +@value{PI} using one of its many series representations: + +@example +BEGIN @{ + x = 1.0 / sqrt(3.0) + n = 6 + for (i = 1; i < 30; i++) @{ + n = n * 2.0 + x = (sqrt(x * x + 1) - 1) / x + printf("%.15f\n", n * x) + @} +@} +@end example + +When run, the early errors propagating through later computations +cause the loop to terminate prematurely after an attempt to divide by zero. + +@example +$ @kbd{gawk -f pi.awk} +@print{} 3.215390309173475 +@print{} 3.159659942097510 +@print{} 3.146086215131467 +@print{} 3.142714599645573 +@dots{} +@print{} 3.224515243534819 +@print{} 2.791117213058638 +@print{} 0.000000000000000 +@error{} gawk: pi.awk:6: fatal: division by zero attempted +@end example + +Here is one more example where the inaccuracies in internal representations +yield an unexpected result: + +@example +$ @kbd{gawk 'BEGIN @{} +> @kbd{for (d = 1.1; d <= 1.5; d += 0.1)} +> @kbd{i++} +> @kbd{print i} +> @kbd{@}'} +@print{} 4 +@end example + +Can computation using aribitrary precision help with the previous examples? +If you are impatient to know, see +@ref{Exact Arithmetic}. + +Instead of aribitrary precision floating-point arithmetic, +often all you need is an adjustment of your logic +or a different order for the operations in your calculation. +The stability and the accuracy of the computation of the constant @value{PI} +in the previous example can be enhanced by using the following +simple algebraic transformation: + +@example +(sqrt(x * x + 1) - 1) / x = x / (sqrt(x * x + 1) + x) +@end example + +There is no need to be unduly suspicious about the results from +floating-point arithmetic. The lesson to remember is that +floating-point math is always more complex than the math using +pencil and paper. In order to take advantage of the power +of computer floating-point, you need to know its limitations +and work within them. For most casual use of floating-point arithmetic, +you will often get the expected result in the end if you simply round +the display of your final results to the correct number of significant +decimal digits. Avoid presenting numerical data in a manner that +implies better precision than is actually the case. + +@node Floating-point Representation +@section Binary Floating-point Representation +@cindex IEEE-754 format + +Although floating-point representations vary from machine to machine, +the most commonly encountered representation is that defined by the +IEEE 754 Standard. An IEEE-754 format value has three components: + +@itemize @bullet +@item +a sign bit telling whether the number is positive or negative, + +@item +an @dfn{exponent} giving its order of magnitude, @var{e}, + +@item +and a @dfn{significand}, @var{s}, +specifying the actual digits of the number. +@end itemize + +The value of the +number is then +@iftex +@math{s @cdot 2^e}. +@end iftex +@ifnottex +@var{s * 2^e}. +@end ifnottex +The first bit of a non-zero binary significand +is always one, so the significand in an IEEE-754 format only includes the +fractional part, leaving the leading one implicit. + +Three of the standard IEEE-754 types are 32-bit single precision, +64-bit double precision and 128-bit quadruple precision. +The standard also specifies extended precision formats +to allow greater precisions and larger exponent ranges. + +@node Floating-point Context +@section Floating-point Context +@cindex context, floating-point + +A floating-point context defines the environment for arithmetic operations. +It governs precision, sets rules for rounding and limits range for exponents. +The context has the following primary components: + +@table @code +@item precision +Precision of the floating-point format in bits. +@item emax +Maximum exponent allowed for this format. +@item emin +Minimum exponent allowed for this format. +@item underflow behavior +The format may or may not support gradual underflow. +@item rounding +The rounding mode of this context. +@end table + +@ref{table-ieee-formats} lists the precision and exponent +field values for the basic IEEE-754 binary formats: + +@float Table,table-ieee-formats +@caption{Basic IEEE Formats} +@multitable @columnfractions .20 .20 .20 .20 .20 +@headitem Name @tab Total bits @tab Precision @tab emin @tab emax +@item Single @tab 32 @tab 24 @tab @minus{}126 @tab +127 +@item Double @tab 64 @tab 53 @tab @minus{}1022 @tab +1023 +@item Quadruple @tab 128 @tab 113 @tab @minus{}16382 @tab +16383 +@end multitable +@end float + +@quotation NOTE +The precision numbers include the implied leading one that gives them +one extra bit of significand. +@end quotation + +A floating-point context can also determine which signals are treated +as exceptions, and can set rules for arithmetic with special values. +Please consult the IEEE-754 standard or other resources for details. + +@command{gawk} ordinarily uses the hardware double precision +representation for numbers. On most systems, this is IEEE-754 +floating-point format, corresponding to 64-bit binary with 53 bits +of precision. + +@quotation NOTE +In case an underflow occurs, the standard allows, but does not require, +the result from an arithmetic operation to be a number smaller than +the smallest nonzero normalized number. Such numbers do +not have as many significant digits as normal numbers, and are called +@dfn{denormals} or @dfn{subnormals}. The alternative, simply returning a zero, +is called @dfn{flush to zero}. The basic IEEE-754 binary formats +support subnormal numbers. +@end quotation + +@node Rounding Mode +@section Floating-point Rounding Mode +@cindex rounding mode, floating-point + +The @dfn{rounding mode} specifies the behavior for the results of numerical +operations when discarding extra precision. Each rounding mode indicates +how the least significant returned digit of a rounded result is to +be calculated. +The @code{ROUNDMODE} variable (@pxref{Setting Rounding Mode}) provides +program level control over the rounding mode. +@ref{table-rounding-modes} lists the IEEE-754 defined +rounding modes: + +@float Table,table-rounding-modes +@caption{Rounding Modes} +@multitable @columnfractions .45 .30 .25 +@headitem Rounding Mode @tab IEEE Name @tab @code{ROUNDMODE} +@item Round to nearest, ties to even @tab @code{roundTiesToEven} @tab @code{"N"} or @code{"n"} +@item Round toward plus Infinity @tab @code{roundTowardPositive} @tab @code{"U"} or @code{"u"} +@item Round toward negative Infinity @tab @code{roundTowardNegative} @tab @code{"D"} or @code{"d"} +@item Round toward zero @tab @code{roundTowardZero} @tab @code{"Z"} or @code{"z"} +@item Round to nearest, ties away from zero @tab @code{roundTiesToAway} @tab @code{"A"} or @code{"a"} +@end multitable +@end float + +The default mode @samp{roundTiesToEven} is the most preferred, +but the least intuitive. This method does the obvious thing for most values, +by rounding them up or down to the nearest digit. +For example, rounding 1.132 to two digits yields 1.13, +and rounding 1.157 yields 1.16. + +However, when it comes to rounding a value that is exactly halfway between, +things do not work the way you probably learned in school. +In this case, the number is rounded to the nearest even digit. +So rounding 0.125 to two digits rounds down to 0.12, +but rounding 0.6875 to three digits rounds up to 0.688. +You probably have already encountered this rounding mode when +using the @code{printf} routine to format floating-point numbers. +For example: + +@example +BEGIN @{ + x = -4.5 + for (i = 1; i < 10; i++) @{ + x += 1.0 + printf("%4.1f => %2.0f\n", x, x) + @} +@} +@end example + +@noindent +produces the following output when run@footnote{It +is possible for the output to be completely different if the +C library in your system does not use the IEEE-754 even-rounding +rule to round halfway cases for @code{printf()}.}: + +@example +-3.5 => -4 +-2.5 => -2 +-1.5 => -2 +-0.5 => 0 + 0.5 => 0 + 1.5 => 2 + 2.5 => 2 + 3.5 => 4 + 4.5 => 4 +@end example + +The theory behind the rounding mode @samp{roundTiesToEven} is that +it more or less evenly distributes upward and downward rounds +of exact halves, which might cause the round-off error +to cancel itself out. This is the default rounding mode used +in IEEE-754 computing functions and operators. + +The other rounding modes are rarely used. +Round toward positive infinity (@samp{roundTowardPositive}) +and round toward negative infinity (@samp{roundTowardNegative}) +are often used to implement interval arithmetic, +where you adjust the rounding mode to calculate upper and lower bounds +for the range of output. The @samp{roundTowardZero} +mode can be used for converting floating-point numbers to integers. +The rounding mode @samp{roundTiesToAway} rounds the result to the +nearest number and selects the number with the larger magnitude +if a tie occurs. + +Some numerical analysts will tell you that your choice of rounding style +has tremendous impact on the final outcome, and advise you to wait until +final output for any rounding. Instead, you can often achieve this goal by +setting the precision initially to some value sufficiently larger than +the final desired precision, so that the accumulation of round-off error +does not influence the outcome. +If you suspect that results from your computation are +sensitive to accumulation of round-off error, +one way to be sure is to look for a significant difference in output +when you change the rounding mode. + +@node Arbitrary Precision Floats +@section Arbitrary Precision Floating-point Arithmetic with @command{gawk} + +@command{gawk} uses the GNU MPFR library +for arbitrary precision floating-point arithmetic. The MPFR library +provides precise control over precisions and rounding modes, and gives +correctly rounded reproducible platform-independent results. With the +command-line option @option{--bignum} or @option{-M}, +all floating-point arithmetic operators and numeric functions can yield +results to any desired precision level supported by MPFR. +Two built-in +variables @code{PREC} +(@pxref{Setting Precision}) +and @code{ROUNDMODE} +(@pxref{Setting Rounding Mode}) +provide control over the working precision and the rounding mode. +The precision and the rounding mode are set globally for every operation +to follow. + +The default working precision for arbitrary precision floats is 53, +and the default value for @code{ROUNDMODE} is @code{"N"}, +which selects the IEEE-754 +@samp{roundTiesToEven} (@pxref{Rounding Mode}) rounding mode.@footnote{The +default precision is 53, since according to the MPFR documentation, +the library should be able to exactly reproduce all computations with +double-precision machine floating-point numbers (@code{double} type +in C), except the default exponent range is much wider and subnormal +numbers are not implemented.} +@command{gawk} uses the default exponent range in MPFR +@iftex +(@math{emax = 2^{30} - 1, emin = -emax}) +@end iftex +@ifnottex +(@var{emax} = 2^30 @minus{} 1, @var{emin} = @minus{}@var{emax}) +@end ifnottex +for all floating-point contexts. +There is no explicit mechanism to adjust the exponent range. +MPFR does not implement subnormal numbers by default, +and this behavior cannot be changed in @command{gawk}. + +@quotation NOTE +When emulating an IEEE-754 format (@pxref{Setting Precision}), +@command{gawk} internally adjusts the exponent range +to the value defined for the format and also performs computations needed for +gradual underflow (subnormal numbers). +@end quotation + +@quotation NOTE +MPFR numbers are variable-size entities, consuming only as much space as +needed to store the significant digits. Since the performance using MPFR +numbers pales in comparison to doing math using the underlying machine +types, you should consider using only as much precision as needed by +your program. +@end quotation + +@node Setting Precision +@section Setting the Working Precision +@cindex @code{PREC} variable + +@command{gawk} uses a global working precision; it does not keep track of +the precision or accuracy of individual numbers. Performing an arithmetic +operation or calling a built-in function rounds the result to the current +working precision. The default working precision is 53 which can be +modified using the built-in variable @code{PREC}. You can also set the +value to one of the following pre-defined case-insensitive strings +to emulate an IEEE-754 binary format: + +@multitable {@code{"double"}} {12345678901234567890123456789012345} +@headitem @code{PREC} @tab IEEE-754 Binary Format +@item @code{"half"} @tab 16-bit half-precision. +@item @code{"single"} @tab Basic 32-bit single precision. +@item @code{"double"} @tab Basic 64-bit double precision. +@item @code{"quad"} @tab Basic 128-bit quadruple precision. +@item @code{"oct"} @tab 256-bit octuple precision. +@end multitable + +The following example illustrates the effects of changing precision +on arithmetic operations: + +@example +$ @kbd{gawk -M -vPREC=100 'BEGIN @{ x = 1.0e-400; print x + 0; \} +> @kbd{PREC = "double"; print x + 0 @}'} +@print{} 1e-400 +@print{} 0 +@end example + +Binary and decimal precisions are related approximately according to the +formula: + +@iftex +@math{prec = 3.322 @cdot dps} +@end iftex +@ifnottex +@var{prec} = 3.322 * @var{dps} +@end ifnottex + +@noindent +Here, @var{prec} denotes the binary precision +(measured in bits) and @var{dps} (short for decimal places) +is the decimal digits. We can easily calculate how many decimal +digits the 53-bit significand of an IEEE double is equivalent to: +53 / 3.332 which is equal to about 15.95. +But what does 15.95 digits actually mean? It depends whether you are +concerned about how many digits you can rely on, or how many digits +you need. + +It is important to know how many bits it takes to uniquely identify +a double-precision value (the C type @code{double}). If you want to +convert from @code{double} to decimal and back to @code{double} (e.g., +saving a @code{double} representing an intermediate result to a file, and +later reading it back to restart the computation), then a few more decimal +digits are required. 17 digits is generally enough for a @code{double}. + +It can also be important to know what decimal numbers can be uniquely +represented with a @code{double}. If you want to convert +from decimal to @code{double} and back again, 15 digits is the most that +you can get. Stated differently, you should not present +the numbers from your floating-point computations with more than 15 +significant digits in them. + +Conversely, it takes a precision of 332 bits to hold an approximation +of constant @value{PI} that is accurate to 100 decimal places. +You should always add some extra bits in order to avoid the confusing round-off +issues that occur because numbers are stored internally in binary. + +@node Setting Rounding Mode +@section Setting the Rounding Mode +@cindex @code{ROUNDMODE} variable + +The built-in variable @code{ROUNDMODE} has the default value @code{"N"}, +which selects the IEEE-754 rounding mode @samp{roundTiesToEven}. +The other possible values for @code{ROUNDMODE} are @code{"U"} for rounding mode +@samp{roundTowardPositive}, @code{"D"} for @samp{roundTowardNegative}, +and @code{"Z"} for @samp{roundTowardZero}. +@command{gawk} also accepts @code{"A"} to select the IEEE-754 mode +@samp{roundTiesToAway} +if your version of the MPFR library supports it; otherwise setting +@code{ROUNDMODE} to this value has no effect. @xref{Rounding Mode}, +for the meanings of the various rounding modes. + +Here is an example of how to change the default rounding behavior of +@code{printf}'s output: + +@example +$ @kbd{gawk -M -vROUNDMODE="Z" 'BEGIN @{ printf("%.2f\n", 1.378) @}'} +@print{} 1.37 +@end example + +@node Floating-point Constants +@section Representing Floating-point Constants +@cindex constants, floating-point + +Be wary of floating-point constants! When reading a floating-point constant +from program source code, @command{gawk} uses the default precision, +unless overridden +by an assignment to the special variable @code{PREC} on the command +line, to store it internally as a MPFR number. +Changing the precision using @code{PREC} in the program text does +not change the precision of a constant. If you need to +represent a floating-point constant at a higher precision than the +default and cannot use a command line assignment to @code{PREC}, +you should either specify the constant as a string, or +a rational number whenever possible. The following example +illustrates the differences among various ways to +print a floating-point constant: + +@example +$ @kbd{gawk -M 'BEGIN @{ PREC = 113; printf("%0.25f\n", 0.1) @}'} +@print{} 0.1000000000000000055511151 +$ @kbd{gawk -M -vPREC = 113 'BEGIN @{ printf("%0.25f\n", 0.1) @}'} +@print{} 0.1000000000000000000000000 +$ @kbd{gawk -M 'BEGIN @{ PREC = 113; printf("%0.25f\n", "0.1") @}'} +@print{} 0.1000000000000000000000000 +$ @kbd{gawk -M 'BEGIN @{ PREC = 113; printf("%0.25f\n", 1/10) @}'} +@print{} 0.1000000000000000000000000 +@end example + +In the first case, the number is stored with the default precision of 53. + +@node Changing Precision +@section Changing the Precision of a Number + +@cindex Laurie, Dirk +@quotation +@i{The point is that in any variable-precision package, +a decision is made on how to treat numbers given as data, +or arising in intermediate results, which are represented in +floating-point format to a precision lower than working precision. +Do we promote them to full membership of the high-precision club, +or do we treat them and all their associates as second-class citizens? +Sometimes the first course is proper, sometimes the second, and it takes +careful analysis to tell which.} + +Dirk Laurie@footnote{Dirk Laurie. +@cite{Variable-precision Arithmetic Considered Perilous -- A Detective Story}. +Electronic Transactions on Numerical Analysis. Volume 28, pp. 168-173, 2008.} +@end quotation + +@command{gawk} does not implicitly modify the precision of any previously +computed results when the working precision is changed with an assignment +to @code{PREC}. The precision of a number is always the one that was +used at the time of its creation, and there is no way for the user +to explicitly change it afterwards. However, since the result of a +floating-point arithmetic operation is always an arbitrary precision +floating-point value---with a precision set by the value of @code{PREC}---one of the +following workarounds effectively accomplishes the desired behavior: + +@example +x = x + 0.0 +@end example + +@noindent +or: + +@example +x += 0.0 +@end example + +@node Exact Arithmetic +@section Exact Arithmetic with Floating-point Numbers + +@quotation CAUTION +Never depend on the exactness of floating-point arithmetic, +even for apparently simple expressions! +@end quotation + +Can arbitrary precision arithmetic give exact results? There are +no easy answers. The standard rules of algebra often do not apply +when using floating-point arithmetic. +Among other things, the distributive and associative laws +do not hold completely, and order of operation may be important +for your computation. Rounding error, cumulative precision loss +and underflow are often troublesome. + +When @command{gawk} tests the expressions @samp{0.1 + 12.2} and @samp{12.3} +for equality +using the machine double precision arithmetic, it decides that they +are not equal! +(@xref{Floating-point Programming}.) +You can get the result you want by increasing the precision; +56 in this case will get the job done: + +@example +$ @kbd{gawk -M -vPREC=56 'BEGIN @{ print (0.1 + 12.2 == 12.3) @}'} +@print{} 1 +@end example + +If adding more bits is good, perhaps adding even more bits of +precision is better? +Here is what happens if we use an even larger value of @code{PREC}: + +@example +$ @kbd{gawk -M -vPREC=201 'BEGIN @{ print (0.1 + 12.2 == 12.3) @}'} +@print{} 0 +@end example + +This is not a bug in @command{gawk} or in the MPFR library. +It is easy to forget that the finite number of bits used to store the value +is often just an approximation after proper rounding. +The test for equality succeeds if and only if @emph{all} bits in the two operands +are exactly the same. Since this is not necessarily true after floating-point +computations with a particular precision and effective rounding rule, +a straight test for equality may not work. + +So, don't assume that floating-point values can be compared for equality. +You should also exercise caution when using other forms of comparisons. +The standard way to compare between floating-point numbers is to determine +how much error (or @dfn{tolerance}) you will allow in a comparison and +check to see if one value is within this error range of the other. + +In applications where 15 or fewer decimal places suffice, +hardware double precision arithmetic can be adequate, and is usually much faster. +But you do need to keep in mind that every floating-point operation +can suffer a new rounding error with catastrophic consequences as illustrated +by our attempt to compute the value of the constant @value{PI}, +(@pxref{Floating-point Programming}). +Extra precision can greatly enhance the stability and the accuracy +of your computation in such cases. + +Repeated addition is not necessarily equivalent to multiplication +in floating-point arithmetic. In the last example +(@pxref{Floating-point Programming}), +you may or may not succeed in getting the correct result by choosing +an arbitrarily large value for @code{PREC}. Reformulation of +the problem at hand is often the correct approach in such situations. + + +@node Integer Programming +@section Effective Integer Programming + +As has been mentioned already, @command{gawk} ordinarily uses hardware double +precision with 64-bit IEEE binary floating-point representation +for numbers on most systems. A large integer like 9007199254740997 +has a binary representation that, although finite, is more than 53 bits long; +it must also be rounded to 53 bits. +The biggest integer that can be stored in a C @code{double} is usually the same +as the largest possible value of a @code{double}. If your system @code{double} +is an IEEE 64-bit @code{double}, this largest possible value is an integer and +can be represented precisely. What more should one know about integers? + +If you want to know what is the largest integer, such that it and +all smaller integers can be stored in 64-bit doubles without losing precision, +then the answer is +@iftex +@math{2^{53}}. +@end iftex +@ifnottex +2^53. +@end ifnottex +The next representable number is the even number +@iftex +@math{2^{53} + 2}, +@end iftex +@ifnottex +2^53 + 2, +@end ifnottex +meaning it is unlikely that you will be able to make +@command{gawk} print +@iftex +@math{2^{53} + 1} +@end iftex +@ifnottex +2^53 + 1 +@end ifnottex +in integer format. +The range of integers exactly representable by a 64-bit double +is +@iftex +@math{[-2^{53}, 2^{53}]}. +@end iftex +@ifnottex +[@minus{}2^53, 2^53]. +@end ifnottex +If you ever see an integer outside this range in @command{gawk} +using 64-bit doubles, you have reason to be very suspicious about +the accuracy of the output. Here is a simple program with erroneous output: + +@example +$ @kbd{gawk 'BEGIN @{ i = 2^53 - 1; for (j = 0; j < 4; j++) print i + j @}'} +@print{} 9007199254740991 +@print{} 9007199254740992 +@print{} 9007199254740992 +@print{} 9007199254740994 +@end example + +The lesson is to not assume that any large integer printed by @command{gawk} +represents an exact result from your computation, especially if it wraps +around on your screen. + +@node Arbitrary Precision Integers +@section Arbitrary Precision Integer Arithmetic with @command{gawk} +@cindex integer, arbitrary precision + +If the option @option{--bignum} or @option{-M} is specified, +@command{gawk} performs all +integer arithmetic using GMP arbitrary precision integers. +Any number that looks like an integer in a program source or data file +is stored as an arbitrary precision integer. +The size of the integer is limited only by your computer's memory. +The current floating-point context has no effect on operations involving integers. +For example, the following computes +@iftex +@math{5^{4^{3^{2}}}}, +@end iftex +@ifnottex +5^4^3^2, +@end ifnottex +the result of which is beyond the +limits of ordinary @command{gawk} numbers: + +@example +$ @kbd{gawk -M 'BEGIN @{} +> @kbd{x = 5^4^3^2} +> @kbd{print "# of digits =", length(x)} +> @kbd{print substr(x, 1, 20), "...", substr(x, length(x) - 19, 20)} +> @kbd{@}'} +@print{} # of digits = 183231 +@print{} 62060698786608744707 ... 92256259918212890625 +@end example + +If you were to compute the same value using arbitrary precision +floating-point values instead, the precision needed for correct output +(using the formula +@iftex +@math{prec = 3.322 @cdot dps}), +would be @math{3.322 @cdot 183231}, +@end iftex +@ifnottex +@samp{prec = 3.322 * dps}), +would be 3.322 x 183231, +@end ifnottex +or 608693. + +The result from an arithmetic operation with an integer and a floating-point value +is a floating-point value with a precision equal to the working precision. +The following program calculates the eighth term in +Sylvester's sequence@footnote{Weisstein, Eric W. +@cite{Sylvester's Sequence}. From MathWorld--A Wolfram Web Resource. +@url{http://mathworld.wolfram.com/SylvestersSequence.html}} +using a recurrence: + +@example +$ @kbd{gawk -M 'BEGIN @{} +> @kbd{s = 2.0} +> @kbd{for (i = 1; i <= 7; i++)} +> @kbd{s = s * (s - 1) + 1} +> @kbd{print s} +> @kbd{@}'} +@print{} 113423713055421845118910464 +@end example + +The output differs from the acutal number, 113423713055421844361000443, +because the default precision of 53 is not enough to represent the +floating-point results exactly. You can either increase the precision +(100 is enough in this case), or replace the floating-point constant +@code{2.0} with an integer, to perform all computations using integer +arithmetic to get the correct output. + +It will sometimes be necessary for @command{gawk} to implicitly convert an +arbitrary precision integer into an arbitrary precision floating-point value. +This is primarily because the MPFR library does not always provide the +relevant interface to process arbitrary precision integers or mixed-mode +numbers as needed by an operation or function. +In such a case, the precision is set to the minimum value necessary +for exact conversion, and the working precision is not used for this purpose. +If this is not what you need or want, you can employ a subterfuge +like this: + +@example +gawk -M 'BEGIN @{ n = 13; print (n + 0.0) % 2.0 @}' +@end example + +You can avoid this issue altogether by specifying the number as a float +to begin with: + +@example +gawk -M 'BEGIN @{ n = 13.0; print n % 2.0 @}' +@end example + +Note that for the particular example above, there is unlikely to be a +reason for simply not using the following: + +@example +gawk -M 'BEGIN @{ n = 13; print n % 2 @}' +@end example + + +@node MPFR and GMP Libraries +@section Information About the MPFR and GMP Libraries + +There are a few elements available in the @code{PROCINFO} array +to provide information about the MPFR and GMP libraries. +@xref{Auto-set}, for more information. + @node Advanced Features @chapter Advanced Features of @command{gawk} @cindex advanced features, network connections, See Also networks, connections @@ -18967,40 +20021,32 @@ extensive examples. @cindex @command{awk} programs, profiling @c STARTOFRANGE proawk @cindex profiling @command{awk} programs -@c STARTOFRANGE pgawk -@cindex @command{pgawk} program -@cindex profiling @command{gawk}, See @command{pgawk} program - -You may produce execution -traces of your @command{awk} programs. -This is done with a specially compiled version of @command{gawk}, -called @command{pgawk} (``profiling @command{gawk}''). - +@cindex profiling @command{gawk} @cindex @code{awkprof.out} file @cindex files, @code{awkprof.out} -@cindex @command{pgawk} program, @code{awkprof.out} file -@command{pgawk} is identical in every way to @command{gawk}, except that when -it has finished running, it creates a profile of your program in a file -named @file{awkprof.out}. -Because it is profiling, it also executes up to 45% slower than + +You may produce execution traces of your @command{awk} programs. +This is done by passing the option @option{--profile} to @command{gawk}. +When @command{gawk} has finished running, it creates a profile of your program in a file +named @file{awkprof.out}. Because it is profiling, it also executes up to 45% slower than @command{gawk} normally does. @cindex @code{--profile} option As shown in the following example, the @option{--profile} option can be used to change the name of the file -where @command{pgawk} will write the profile: +where @command{gawk} will write the profile: @example -pgawk --profile=myprog.prof -f myprog.awk data1 data2 +gawk --profile=myprog.prof -f myprog.awk data1 data2 @end example @noindent -In the above example, @command{pgawk} places the profile in +In the above example, @command{gawk} places the profile in @file{myprog.prof} instead of in @file{awkprof.out}. -Here is a sample -session showing a simple @command{awk} program, its input data, and the -results from running @command{pgawk}. First, the @command{awk} program: +Here is a sample session showing a simple @command{awk} program, its input data, and the +results from running @command{gawk} with the @option{--profile} option. +First, the @command{awk} program: @example BEGIN @{ print "First BEGIN rule" @} @@ -19040,12 +20086,12 @@ foo junk @end example -Here is the @file{awkprof.out} that results from running @command{pgawk} -on this program and data (this example also illustrates that @command{awk} +Here is the @file{awkprof.out} that results from running the @command{gawk} +profiler on this program and data (this example also illustrates that @command{awk} programmers sometimes have to work late): -@cindex @code{BEGIN} pattern, @command{pgawk} program -@cindex @code{END} pattern, @command{pgawk} program +@cindex @code{BEGIN} pattern +@cindex @code{END} pattern @example # gawk profile, created Sun Aug 13 00:00:15 2000 @@ -19137,15 +20183,15 @@ keyword indicates how many times the function was called. The counts next to the statements in the body show how many times those statements were executed. -@cindex @code{@{@}} (braces), @command{pgawk} program -@cindex braces (@code{@{@}}), @command{pgawk} program +@cindex @code{@{@}} (braces) +@cindex braces (@code{@{@}}) @item The layout uses ``K&R'' style with TABs. Braces are used everywhere, even when the body of an @code{if}, @code{else}, or loop is only a single statement. -@cindex @code{()} (parentheses), @command{pgawk} program -@cindex parentheses @code{()}, @command{pgawk} program +@cindex @code{()} (parentheses) +@cindex parentheses @code{()} @item Parentheses are used only where needed, as indicated by the structure of the program and the precedence rules. @@ -19168,16 +20214,16 @@ Similarly, if the target of a redirection isn't a scalar, it gets parenthesized. @item -@command{pgawk} supplies leading comments in +@command{gawk} supplies leading comments in front of the @code{BEGIN} and @code{END} rules, the pattern/action rules, and the functions. @end itemize The profiled version of your program may not look exactly like what you -typed when you wrote it. This is because @command{pgawk} creates the +typed when you wrote it. This is because @command{gawk} creates the profiled version by ``pretty printing'' its internal representation of -the program. The advantage to this is that @command{pgawk} can produce +the program. The advantage to this is that @command{gawk} can produce a standard representation. The disadvantage is that all source-code comments are lost, as are the distinctions among multiple @code{BEGIN}, @code{END}, @code{BEGINFILE}, and @code{ENDFILE} rules. Also, things such as: @@ -19199,15 +20245,16 @@ come out as: which is correct, but possibly surprising. @cindex profiling @command{awk} programs, dynamically -@cindex @command{pgawk} program, dynamic profiling +@cindex @command{gawk} program, dynamic profiling Besides creating profiles when a program has completed, -@command{pgawk} can produce a profile while it is running. +@command{gawk} can produce a profile while it is running. This is useful if your @command{awk} program goes into an infinite loop and you want to see what has been executed. -To use this feature, run @command{pgawk} in the background: +To use this feature, run @command{gawk} with the @option{--profile} +option in the background: @example -$ @kbd{pgawk -f myprog &} +$ @kbd{gawk --profile -f myprog &} [1] 13992 @end example @@ -19218,7 +20265,7 @@ $ @kbd{pgawk -f myprog &} @noindent The shell prints a job number and process ID number; in this case, 13992. Use the @command{kill} command to send the @code{USR1} signal -to @command{pgawk}: +to @command{gawk}: @example $ @kbd{kill -USR1 13992} @@ -19226,8 +20273,8 @@ $ @kbd{kill -USR1 13992} @noindent As usual, the profiled version of the program is written to -@file{awkprof.out}, or to a different file if you use the @option{--profile} -option. +@file{awkprof.out}, or to a different file if one specified with +the @option{--profile} option. Along with the regular profile, as shown earlier, the profile includes a trace of any active functions: @@ -19241,7 +20288,7 @@ includes a trace of any active functions: # -- main -- @end example -You may send @command{pgawk} the @code{USR1} signal as many times as you like. +You may send @command{gawk} the @code{USR1} signal as many times as you like. Each time, the profile and function call trace are appended to the output profile file. @@ -19249,7 +20296,7 @@ profile file. @cindex @code{SIGHUP} signal @cindex signals, @code{HUP}/@code{SIGHUP} If you use the @code{HUP} signal instead of the @code{USR1} signal, -@command{pgawk} produces the profile and the function call trace and then exits. +@command{gawk} produces the profile and the function call trace and then exits. @cindex @code{INT} signal (MS-Windows) @cindex @code{SIGINT} signal (MS-Windows) @@ -19257,21 +20304,20 @@ If you use the @code{HUP} signal instead of the @code{USR1} signal, @cindex @code{QUIT} signal (MS-Windows) @cindex @code{SIGQUIT} signal (MS-Windows) @cindex signals, @code{QUIT}/@code{SIGQUIT} (MS-Windows) -When @command{pgawk} runs on MS-Windows systems, it uses the +When @command{gawk} runs on MS-Windows systems, it uses the @code{INT} and @code{QUIT} signals for producing the profile and, in -the case of the @code{INT} signal, @command{pgawk} exits. This is +the case of the @code{INT} signal, @command{gawk} exits. This is because these systems don't support the @command{kill} command, so the only signals you can deliver to a program are those generated by the keyboard. The @code{INT} signal is generated by the @kbd{@value{CTL}-@key{C}} or @kbd{@value{CTL}-@key{BREAK}} key, while the @code{QUIT} signal is generated by the @kbd{@value{CTL}-@key{\}} key. -Finally, regular @command{gawk} also accepts the @option{--profile} option. +Finally, @command{gawk} also accepts another option @option{--pretty-print}. When called this way, @command{gawk} ``pretty prints'' the program into @file{awkprof.out}, without any execution counts. @c ENDOFRANGE advgaw @c ENDOFRANGE gawadv -@c ENDOFRANGE pgawk @c ENDOFRANGE awkp @c ENDOFRANGE proawk @@ -25153,41 +26199,41 @@ BEGIN { @c FIXME: Add more indexing. @node Debugger -@chapter @command{dgawk}: The @command{awk} Debugger -@cindex @command{dgawk} +@chapter Debugging @command{awk} Programs +@cindex debugging @command{awk} programs It would be nice if computer programs worked perfectly the first time they were run, but in real life, this rarely happens for programs of any complexity. Thus, most programming languages have facilities available for ``debugging'' programs, and now @command{awk} is no exception. -The @command{dgawk} debugger is purposely modeled after +The @command{gawk} debugger is purposely modeled after @uref{http://www.gnu.org/software/gdb/, the GNU Debugger (GDB)} command-line debugger. If you are familiar with GDB, learning -@command{dgawk} is easy. +how to use @command{gawk} for debugging your program is easy. @menu -* Debugging:: Introduction to @command{dgawk}. -* Sample dgawk session:: Sample @command{dgawk} session. -* List of Debugger Commands:: Main @command{dgawk} Commands. -* Readline Support:: Readline Support. -* Dgawk Limitations:: Limitations and future plans. +* Debugging:: Introduction to @command{gawk} debugger. +* Sample Debugging Session:: Sample debugging session. +* List of Debugger Commands:: Main debugger commands. +* Readline Support:: Readline support. +* Limitations:: Limitations and future plans. @end menu @node Debugging -@section Introduction to @command{dgawk} +@section Introduction to @command{gawk} Debugger This @value{SECTION} introduces debugging in general and begins the discussion of debugging in @command{gawk}. @menu -* Debugging Concepts:: Debugging In General. +* Debugging Concepts:: Debugging in General. * Debugging Terms:: Additional Debugging Concepts. * Awk Debugging:: Awk Debugging. @end menu @node Debugging Concepts -@subsection Debugging In General +@subsection Debugging in General (If you have used debuggers in other languages, you may want to skip ahead to the next section on the specific features of the @command{awk} @@ -25233,8 +26279,7 @@ functional program that you or someone else wrote). @subsection Additional Debugging Concepts Before diving in to the details, we need to introduce several -important concepts that apply to just about all debuggers, including -@command{dgawk}. +important concepts that apply to just about all debuggers. The following list defines terms used throughout the rest of this @value{CHAPTER}. @@ -25253,7 +26298,7 @@ that contains the function's parameters, local variables, and return value, as well as any other ``bookkeeping'' information needed to manage the call stack. This data area is termed a @dfn{stack frame}. -@command{gawk} also follows this model, and @command{dgawk} gives you +@command{gawk} also follows this model, and gives you access to the call stack and to each stack frame. You can see the call stack, as well as from where each function on the stack was invoked. Commands that print the call stack print information about @@ -25298,48 +26343,48 @@ each line of @command{awk} code. The debugger provides the opportunity to look at the individual primitive instructions carried out by the higher-level @command{awk} commands. -@node Sample dgawk session -@section Sample @command{dgawk} session +@node Sample Debugging Session +@section Sample Debugging Session -In order to illustrate the use of @command{dgawk}, let's look at a sample +In order to illustrate the use of @command{gawk} as a debugger, let's look at a sample debugging session. We will use the @command{awk} implementation of the POSIX @command{uniq} command described earlier (@pxref{Uniq Program}) as our example. @menu -* dgawk invocation:: @command{dgawk} Invocation. -* Finding The Bug:: Finding The Bug. +* Debugger Invocation:: How to Start the Debugger. +* Finding The Bug:: Finding the Bug. @end menu -@node dgawk invocation -@subsection @command{dgawk} Invocation +@node Debugger Invocation +@subsection How to Start the Debugger -Starting @command{dgawk} is exactly like running @command{awk}. The -file(s) containing the program and any supporting code are given on the -command line as arguments to one or more @option{-f} options. -(@command{dgawk} is not designed to debug command-line -programs, only programs contained in files.) In our case, -we call @command{dgawk} like this: +Starting the debugger is almost exactly like running @command{awk}, except you have to +pass an additional option @option{--debug} or the corresponding short option @option{-D}. +The file(s) containing the program and any supporting code are given on the command +line as arguments to one or more @option{-f} options. (@command{gawk} is not designed +to debug command-line programs, only programs contained in files.) In our case, +we invoke the debugger like this: @example -$ @kbd{dgawk -f getopt.awk -f join.awk -f uniq.awk inputfile} +$ @kbd{gawk -D -f getopt.awk -f join.awk -f uniq.awk inputfile} @end example @noindent where both @file{getopt.awk} and @file{uniq.awk} are in @env{$AWKPATH}. (Experienced users of GDB or similar debuggers should note that this syntax is slightly different from what they are used to. -With @command{dgawk}, the arguments for running the program are given +With @command{gawk} debugger, the arguments for running the program are given in the command line to the debugger rather than as part of the @code{run} command at the debugger prompt.) Instead of immediately running the program on @file{inputfile}, as -@command{gawk} would ordinarily do, @command{dgawk} merely loads all +@command{gawk} would ordinarily do, the debugger merely loads all the program source files, compiles them internally, and then gives us a prompt: @example -dgawk> +gawk> @end example @noindent @@ -25347,7 +26392,7 @@ from which we can issue commands to the debugger. At this point, no code has been executed. @node Finding The Bug -@subsection Finding The Bug +@subsection Finding the Bug Let's say that we are having a problem using (a faulty version of) @file{uniq.awk} in the ``field-skipping'' mode, and it doesn't seem to be @@ -25383,7 +26428,7 @@ a breakpoint in @file{uniq.awk} is at the beginning of the function the breakpoint, use the @code{b} (breakpoint) command: @example -dgawk> @kbd{b are_equal} +gawk> @kbd{b are_equal} @print{} Breakpoint 1 set at file `awklib/eg/prog/uniq.awk', line 64 @end example @@ -25392,22 +26437,22 @@ Now type @samp{r} or @samp{run} and the program runs until it hits the breakpoint for the first time: @example -dgawk> @kbd{r} +gawk> @kbd{r} @print{} Starting program: @print{} Stopping in Rule ... @print{} Breakpoint 1, are_equal(n, m, clast, cline, alast, aline) at `awklib/eg/prog/uniq.awk':64 @print{} 64 if (fcount == 0 && charcount == 0) -dgawk> +gawk> @end example Now we can look at what's going on inside our program. First of all, let's see how we got to where we are. At the prompt, we type @samp{bt} -(short for ``backtrace''), and @command{dgawk} responds with a +(short for ``backtrace''), and the debugger responds with a listing of the current stack frames: @example -dgawk> @kbd{bt} +gawk> @kbd{bt} @print{} #0 are_equal(n, m, clast, cline, alast, aline) at `awklib/eg/prog/uniq.awk':69 @print{} #1 in main() at `awklib/eg/prog/uniq.awk':89 @@ -25422,11 +26467,11 @@ the key to finding the source of the problem.) Now that we're in @code{are_equal()}, we can start looking at the values of some variables. Let's say we type @samp{p n} (@code{p} is short for ``print''). We would expect to see the value of -@code{n}, a parameter to @code{are_equal()}. Actually, @command{dgawk} +@code{n}, a parameter to @code{are_equal()}. Actually, the debugger gives us: @example -dgawk> @kbd{p n} +gawk> @kbd{p n} @print{} n = untyped variable @end example @@ -25437,7 +26482,7 @@ function was called without arguments (@pxref{Function Calls}). A more useful variable to display might be the current record: @example -dgawk> @kbd{p $0} +gawk> @kbd{p $0} @print{} $0 = string ("gawk is a wonderful program!") @end example @@ -25446,7 +26491,7 @@ This might be a bit puzzling at first since this is the second line of our test input above. Let's look at @code{NR}: @example -dgawk> @kbd{p NR} +gawk> @kbd{p NR} @print{} NR = number (2) @end example @@ -25465,7 +26510,7 @@ NR == 1 @{ OK, let's just check that that rule worked correctly: @example -dgawk> @kbd{p last} +gawk> @kbd{p last} @print{} last = string ("awk is a wonderful program!") @end example @@ -25476,7 +26521,7 @@ be inside this function. To investigate further, we must begin @samp{n} (for ``next''): @example -dgawk> @kbd{n} +gawk> @kbd{n} @print{} 67 if (fcount > 0) @{ @end example @@ -25496,9 +26541,9 @@ Continuing to step, we now get to the splitting of the current and last records: @example -dgawk> @kbd{n} +gawk> @kbd{n} @print{} 68 n = split(last, alast) -dgawk> @kbd{n} +gawk> @kbd{n} @print{} 69 m = split($0, aline) @end example @@ -25506,7 +26551,7 @@ At this point, we should be curious to see what our records were split into, so we try to look: @example -dgawk> @kbd{p n m alast aline} +gawk> @kbd{p n m alast aline} @print{} n = number (5) @print{} m = number (5) @print{} alast = array, 5 elements @@ -25525,7 +26570,7 @@ inside the array? The first choice would be to use subscripts: @example -dgawk> @kbd{p alast[0]} +gawk> @kbd{p alast[0]} @print{} "0" not in array `alast' @end example @@ -25533,16 +26578,16 @@ dgawk> @kbd{p alast[0]} Oops! @example -dgawk> @kbd{p alast[1]} +gawk> @kbd{p alast[1]} @print{} alast["1"] = string ("awk") @end example This would be kind of slow for a 100-member array, though, so -@command{dgawk} provides a shortcut (reminiscent of another language +@command{gawk} provides a shortcut (reminiscent of another language not to be mentioned): @example -dgawk> @kbd{p @@alast} +gawk> @kbd{p @@alast} @print{} alast["1"] = string ("awk") @print{} alast["2"] = string ("is") @print{} alast["3"] = string ("a") @@ -25554,9 +26599,9 @@ It looks like we got this far OK. Let's take another step or two: @example -dgawk> @kbd{n} +gawk> @kbd{n} @print{} 70 clast = join(alast, fcount, n) -dgawk> @kbd{n} +gawk> @kbd{n} @print{} 71 cline = join(aline, fcount, m) @end example @@ -25566,7 +26611,7 @@ the virtual record to compare, and if the first field was numbered zero, this would work. Let's look at what we've got: @example -dgawk> @kbd{p cline clast} +gawk> @kbd{p cline clast} @print{} cline = string ("gawk is a wonderful program!") @print{} clast = string ("awk is a wonderful program!") @end example @@ -25575,10 +26620,10 @@ Hey, those look pretty familiar! They're just our original, unaltered, input records. A little thinking (the human brain is still the best debugging tool), and we realize that we were off by one! -We get out of @command{dgawk}: +We get out of the debugger: @example -dgawk> @kbd{q} +gawk> @kbd{q} @print{} The program is running. Exit anyway (y/n)? @kbd{y} @end example @@ -25594,9 +26639,9 @@ cline = join(aline, fcount+1, m) and problem solved! @node List of Debugger Commands -@section Main @command{dgawk} Commands +@section Main Debugger Commands -The @command{dgawk} command set can be divided into the +The @command{gawk} debugger command set can be divided into the following categories: @itemize @bullet{} @@ -25623,24 +26668,24 @@ Miscellaneous Each of these are discussed in the following subsections. In the following descriptions, commands which may be abbreviated show the abbreviation on a second description line. -A @command{dgawk} command name may also be truncated if that partial -name is unambiguous. @command{dgawk} has the built-in capability to +A debugger command name may also be truncated if that partial +name is unambiguous. The debugger has the built-in capability to automatically repeat the previous command when just hitting @key{Enter}. This works for the commands @code{list}, @code{next}, @code{nexti}, @code{step}, @code{stepi} and @code{continue} executed without any argument. @menu -* Breakpoint Control:: Control of breakpoints. -* Dgawk Execution Control:: Control of execution. -* Viewing And Changing Data:: Viewing and changing data. -* Dgawk Stack:: Dealing with the stack. -* Dgawk Info:: Obtaining information about the program and - the debugger state. -* Miscellaneous Dgawk Commands:: Miscellaneous Commands. +* Breakpoint Control:: Control of Breakpoints. +* Debugger Execution Control:: Control of Execution. +* Viewing And Changing Data:: Viewing and Changing Data. +* Execution Stack:: Dealing with the Stack. +* Debugger Info:: Obtaining Information about the Program and + the Debugger State. +* Miscellaneous Debugger Commands:: Miscellaneous Commands. @end menu @node Breakpoint Control -@subsection Control Of Breakpoints +@subsection Control of Breakpoints As we saw above, the first thing you probably want to do in a debugging session is to get your breakpoints set up, since otherwise your program @@ -25675,10 +26720,10 @@ Each breakpoint is assigned a number which can be used to delete it from the breakpoint list using the @code{delete} command. With a breakpoint, you may also supply a condition. This is an -@command{awk} expression (enclosed in double quotes) that @command{dgawk} +@command{awk} expression (enclosed in double quotes) that the debugger evaluates whenever the breakpoint is reached. If the condition is true, -then @command{dgawk} stops execution and prompts for a command. Otherwise, -@command{dgawk} continues executing the program. +then the debugger stops execution and prompts for a command. Otherwise, +it continues executing the program. @cindex debugger commands, @code{clear} @cindex @code{clear} debugger command @@ -25704,10 +26749,10 @@ Delete breakpoint(s) set at entry to function @var{function}. @cindex @code{condition} debugger command @item @code{condition} @var{n} @code{"@var{expression}"} Add a condition to existing breakpoint or watchpoint @var{n}. The -condition is an @command{awk} expression that @command{dgawk} evaluates +condition is an @command{awk} expression that the debugger evaluates whenever the breakpoint or watchpoint is reached. If the condition is true, then -@command{dgawk} stops execution and prompts for a command. Otherwise, -@command{dgawk} continues executing the program. If the condition expression is +the debugger stops execution and prompts for a command. Otherwise, +the debugger continues executing the program. If the condition expression is not specified, any existing condition is removed; i.e., the breakpoint or watchpoint is made unconditional. @@ -25763,7 +26808,7 @@ Set a temporary breakpoint (enabled for only one stop). The arguments are the same as for @code{break}. @end table -@node Dgawk Execution Control +@node Debugger Execution Control @subsection Control of Execution Now that your breakpoints are ready, you can start running the program @@ -25792,14 +26837,14 @@ in the list that resumes execution (e.g., @code{continue}) terminates the list For example: @example -dgawk> @kbd{commands} +gawk> @kbd{commands} > @kbd{silent} > @kbd{printf "A silent breakpoint; i = %d\n", i} > @kbd{info locals} > @kbd{set i = 10} > @kbd{continue} > @kbd{end} -dgawk> +gawk> @end example @cindex debugger commands, @code{c} (@code{continue}) @@ -25849,7 +26894,7 @@ and the caller of that frame becomes the innermost frame. @cindex @code{r} debugger command (alias for @code{run}) @item @code{run} @itemx @code{r} -Start/restart execution of the program. When restarting, @command{dgawk} +Start/restart execution of the program. When restarting, the debugger retains the current breakpoints, watchpoints, command history, automatic display variables, and debugger options. @@ -25872,7 +26917,7 @@ stopping, unless it encounters a breakpoint or watchpoint. @itemx @code{si} [@var{count}] Execute one (or @var{count}) instruction(s), stepping inside function calls. (For illustration of what is meant by an ``instruction'' in @command{gawk}, -see the output shown under @code{dump} in @ref{Miscellaneous Dgawk Commands}.) +see the output shown under @code{dump} in @ref{Miscellaneous Debugger Commands}.) @cindex debugger commands, @code{u} (@code{until}) @cindex debugger commands, @code{until} @@ -25900,7 +26945,7 @@ The value of the variable or field is displayed each time the program stops. Each variable added to the list is identified by a unique number: @example -dgawk> @kbd{display x} +gawk> @kbd{display x} @print{} 10: x = 1 @end example @@ -25937,7 +26982,7 @@ Print the value of a @command{gawk} variable or field. Fields must be referenced by constants: @example -dgawk> @kbd{print $3} +gawk> @kbd{print $3} @end example @noindent @@ -25979,16 +27024,16 @@ You can also set special @command{awk} variables, such as @code{FS}, @item @code{watch} @var{var} | @code{$}@var{n} [@code{"@var{expression}"}] @itemx @code{w} @var{var} | @code{$}@var{n} [@code{"@var{expression}"}] Add variable @var{var} (or field @code{$@var{n}}) to the watch list. -@command{dgawk} then stops whenever +The debugger then stops whenever the value of the variable or field changes. Each watched item is assigned a number which can be used to delete it from the watch list using the @code{unwatch} command. With a watchpoint, you may also supply a condition. This is an -@command{awk} expression (enclosed in double quotes) that @command{dgawk} +@command{awk} expression (enclosed in double quotes) that the debugger evaluates whenever the watchpoint is reached. If the condition is true, -then @command{dgawk} stops execution and prompts for a command. Otherwise, -@command{dgawk} continues executing the program. +then the debugger stops execution and prompts for a command. Otherwise, +@command{gawk} continues executing the program. @cindex debugger commands, @code{undisplay} @cindex @code{undisplay} debugger command @@ -26004,8 +27049,8 @@ watch list. @end table -@node Dgawk Stack -@subsection Dealing With The Stack +@node Execution Stack +@subsection Dealing with the Stack Whenever you run a program which contains any function calls, @command{gawk} maintains a stack of all of the function calls leading up @@ -26049,12 +27094,12 @@ Move @var{count} (default 1) frames up the stack toward the outermost frame. Then select and print the frame. @end table -@node Dgawk Info -@subsection Obtaining Information About The Program and The Debugger State +@node Debugger Info +@subsection Obtaining Information about the Program and the Debugger State Besides looking at the values of variables, there is often a need to get other sorts of information about the state of your program and of the -debugging environment itself. @command{dgawk} has one command which +debugging environment itself. The @command{gawk} debugger has one command which provides this information, appropriately called @code{info}. @code{info} is used with one of a number of arguments that tell it exactly what you want to know: @@ -26092,7 +27137,7 @@ Local variables of the selected frame. @item source The name of the current source file. Each time the program stops, the current source file is the file containing the current instruction. -When @command{dgawk} first starts, the current source file is the first file +When the debugger first starts, the current source file is the first file included via the @option{-f} option. The @samp{list @var{filename}:@var{lineno}} command can be used at any time to change the current source. @@ -26128,7 +27173,7 @@ The available options are: @c nested table @table @code @item history_size -The maximum number of lines to keep in the history file @file{./.dgawk_history}. +The maximum number of lines to keep in the history file @file{./.gawk_history}. The default is 100. @item listsize @@ -26140,14 +27185,14 @@ to standard output. An empty string (@code{""}) resets output to standard output. @item prompt -The debugger prompt. The default is @samp{@w{dgawk> }}. +The debugger prompt. The default is @samp{@w{gawk> }}. @item save_history @r{[}on @r{|} off@r{]} -Save command history to file @file{./.dgawk_history}. +Save command history to file @file{./.gawk_history}. The default is @code{on}. @item save_options @r{[}on @r{|} off@r{]} -Save current options to file @file{./.dgawkrc} upon exit. +Save current options to file @file{./.gawkrc} upon exit. The default is @code{on}. Options are read back in to the next session upon startup. @@ -26167,16 +27212,16 @@ Empty lines are ignored; they do @emph{not} repeat the last command. You can't restart the program by having more than one @code{run} command in the file. Also, the list of commands may include additional -@code{source} commands; however, @command{dgawk} will not source the +@code{source} commands; however, the @command{gawk} debugger will not source the same file more than once in order to avoid infinite recursion. In addition to, or instead of the @code{source} command, you can use -the @option{-R @var{file}} or @option{--command=@var{file}} command-line +the @option{-D @var{file}} or @option{--debug=@var{file}} command-line options to execute commands from a file non-interactively (@pxref{Options}. @end table -@node Miscellaneous Dgawk Commands +@node Miscellaneous Debugger Commands @subsection Miscellaneous Commands There are a few more commands which do not fit into the @@ -26194,7 +27239,7 @@ partial dump of Davide Brini's obfuscated code (@pxref{Signature Program}) demonstrates: @smallexample -dgawk> @kbd{dump} +gawk> @kbd{dump} @print{} # BEGIN @print{} @print{} [ 2:0x89faef4] Op_rule : [in_rule = BEGIN] [source_file = brini.awk] @@ -26243,7 +27288,7 @@ dgawk> @kbd{dump} @print{} [ :0x89fa3b0] Op_after_beginfile : @print{} [ :0x89fa388] Op_no_op : @print{} [ :0x89fa3c4] Op_after_endfile : -dgawk> +gawk> @end smallexample @cindex debugger commands, @code{h} (@code{help}) @@ -26252,7 +27297,7 @@ dgawk> @cindex @code{h} debugger command (alias for @code{help}) @item @code{help} @itemx @code{h} -Print a list of all of the @command{dgawk} commands with a short +Print a list of all of the @command{gawk} debugger commands with a short summary of their usage. @samp{help @var{command}} prints the information about the command @var{command}. @@ -26299,7 +27344,7 @@ function @var{function}. This command may change the current source file. Exit the debugger. Debugging is great fun, but sometimes we all have to tend to other obligations in life, and sometimes we find the bug, and are free to go on to the next one! As we saw above, if you are -running a program, @command{dgawk} warns you if you accidentally type +running a program, the debugger warns you if you accidentally type @samp{q} or @samp{quit}, to make sure you really want to quit. @cindex debugger commands, @code{trace} @@ -26318,7 +27363,7 @@ fairly self-explanatory, and using @code{stepi} and @code{nexti} while @node Readline Support @section Readline Support -If @command{dgawk} is compiled with the @code{readline} library, you +If @command{gawk} is compiled with the @code{readline} library, you can take advantage of that library's command completion and history expansion features. The following types of completion are available: @@ -26350,28 +27395,28 @@ and @end table -@node Dgawk Limitations +@node Limitations @section Limitations and Future Plans -We hope you find @command{dgawk} useful and enjoyable to work with, +We hope you find the @command{gawk} debugger useful and enjoyable to work with, but as with any program, especially in its early releases, it still has some limitations. A few which are worth being aware of are: @itemize @bullet{} @item -At this point, @command{dgawk} does not give a detailed explanation of +At this point, the debugger does not give a detailed explanation of what you did wrong when you type in something it doesn't like. Rather, it just responds @samp{syntax error}. When you do figure out what your mistake was, though, you'll feel like a real guru. @item -If you perused the dump of opcodes in @ref{Miscellaneous Dgawk Commands}, +If you perused the dump of opcodes in @ref{Miscellaneous Debugger Commands}, (or if you are already familiar with @command{gawk} internals), you will realize that much of the internal manipulation of data in @command{gawk}, as in many interpreters, is done on a stack. @code{Op_push}, @code{Op_pop}, etc., are the ``bread and butter'' of -most @command{gawk} code. Unfortunately, as of now, @command{dgawk} -does not allow you to examine the stack's contents. +most @command{gawk} code. Unfortunately, as of now, the @command{gawk} +debugger does not allow you to examine the stack's contents. That is, the intermediate results of expression evaluation are on the stack, but cannot be printed. Rather, only variables which are defined @@ -26386,14 +27431,14 @@ programmer, you are expected to know what @code{/[^[:alnum:][:blank:]]/} means. @item -@command{dgawk} is designed to be used by running a program (with all its -parameters) on the command line, as described in @ref{dgawk invocation}. +The @command{gawk} debugger is designed to be used by running a program (with all its +parameters) on the command line, as described in @ref{Debugger Invocation}. There is no way (as of now) to attach or ``break in'' to a running program. This seems reasonable for a language which is used mainly for quickly executing, short programs. @item -@command{dgawk} only accepts source supplied with the @option{-f} option. +The @command{gawk} debugger only accepts source supplied with the @option{-f} option. @end itemize Look forward to a future release when these and other missing features may @@ -27302,7 +28347,7 @@ environments. @cindex Haque, John John Haque reworked the @command{gawk} internals to use a byte-code engine, -providing the @command{dgawk} debugger for @command{awk} programs. +providing the @command{gawk} debugger for @command{awk} programs. @item @cindex Yawitz, Efraim @@ -28572,7 +29617,7 @@ since approximately 2003. @item @command{pawk} Nelson H.F.@: Beebe at the University of Utah has modified Brian Kernighan's @command{awk} to provide timing and profiling information. -It is different from @command{pgawk} +It is different from @command{gawk} with the @option{--profile} option. (@pxref{Profiling}), in that it uses CPU-based profiling, not line-count profiling. You may find it at either @@ -29077,6 +30122,7 @@ When @option{--sandbox} is specified, extensions are disabled @menu * Internals:: A brief look at some @command{gawk} internals. * Plugin License:: A note about licensing. +* Loading Extensions:: How to load dynamic extensions. * Sample Library:: A example of new functions. @end menu @@ -29141,22 +30187,12 @@ macro guarantees that a @code{NODE}'s wide-string value is current. It may end up calling an internal @command{gawk} function. It also guarantees that the wide string is zero-terminated. -@cindex @code{get_curfunc_arg_count()} internal function -@cindex internal function, @code{get_curfunc_arg_count()} -@item size_t get_curfunc_arg_count(void) -This function returns the actual number of parameters passed -to the current function. Inside the code of an extension -this can be used to determine the maximum index which is -safe to use with @code{get_actual_argument}. If this value is -greater than @code{nargs}, the function was -called incorrectly from the @command{awk} program. - @cindex parameters@comma{} number of @cindex @code{nargs} internal variable @cindex internal variable, @code{nargs} @item nargs -Inside an extension function, this is the maximum number of -expected parameters, as set by the @code{make_builtin()} function. +Inside an extension function, this is the actual number of +parameters passed to the current function. @cindex @code{stptr} internal variable @cindex internal variable, @code{stptr} @@ -29202,13 +30238,10 @@ Make sure that @samp{n->type == Node_var_array} first. @cindex arrays, elements, installing @cindex @code{assoc_lookup()} internal function @cindex internal function, @code{assoc_lookup()} -@item NODE **assoc_lookup(NODE *symbol, NODE *subs, int reference) +@item NODE **assoc_lookup(NODE *symbol, NODE *subs) Finds, and installs if necessary, array elements. @code{symbol} is the array, @code{subs} is the subscript. This is usually a value created with @code{make_string()} (see below). -@code{reference} should be @code{TRUE} if it is an error to use the -value before it is created. Typically, @code{FALSE} is the -correct value to use from extension functions. @cindex strings @cindex @code{make_string()} internal function @@ -29400,6 +30433,56 @@ the symbol exists in the global scope. Something like this is enough: int plugin_is_GPL_compatible; @end example +@node Loading Extensions +@appendixsubsec Loading a Dynamic Extension +@cindex loading extension +@cindex @command{gawk}, functions, loading +There are two ways to load a dynamically linked library. The first is to use the +builtin @code{extension()}: + +@example +extension(libname, init_func) +@end example + +where @file{libname} is the library to load, and @samp{init_func} is the +name of the initialization or bootstrap routine to run once loaded. + +The second method for dynamic loading of a library is to use the +command line option @option{-l}: + +@example +$ @kbd{gawk -l libname -f myprog} +@end example + +This will work only if the initialization routine is named @code{dlload()}. + +If you use @code{extension()}, the library will be loaded +at run time. This means that the functions are available only to the rest of +your script. If you use the command line option @option{-l} instead, +the library will be loaded before @command{gawk} starts compiling the +actual program. The net effect is that you can use those functions +anywhere in the program. + +@command{gawk} has a list of directories where it searches for libraries. +By default, the list includes directories that depend upon how gawk was built +and installed (@pxref{AWKPATH Variable}). If you want @command{gawk} +to look for libraries in your private directory, you have to tell it. +The way to do it is to set the @env{AWKPATH} environment variable +(@pxref{AWKPATH Variable}). +@command{gawk} supplies the default suffix @samp{.so} if it is not +present in the name of the library. +If the name of your library is @file{mylib.so}, you can simply type + +@example +$ @kbd{gawk -l mylib -f myprog} +@end example + +and @command{gawk} will do everything necessary to load in your library, +and then call your @code{dlload()} routine. + +You can always specify the library using an absolute pathname, in which +case @command{gawk} will not use @env{AWKPATH} to search for it. + @node Sample Library @appendixsubsec Example: Directory and File Operation Built-ins @c STARTOFRANGE chdirg @@ -29592,7 +30675,7 @@ do_chdir(int nargs) NODE *newdir; int ret = -1; - if (do_lint && get_curfunc_arg_count() != 1) + if (do_lint && nargs != 1) lintwarn("chdir: called with incorrect number of arguments"); newdir = get_scalar_argument(0, FALSE); @@ -29665,7 +30748,7 @@ do_stat(int nargs) char *pmode; /* printable mode */ char *type = "unknown"; - if (do_lint && get_curfunc_arg_count() > 2) + if (do_lint && nargs > 2) lintwarn("stat: called with too many arguments"); @end example @@ -29699,15 +30782,15 @@ calls are shown here, since they all follow the same pattern: @example /* fill in the array */ - aptr = assoc_lookup(array, tmp = make_string("name", 4), FALSE); + aptr = assoc_lookup(array, tmp = make_string("name", 4)); *aptr = dupnode(file); unref(tmp); - aptr = assoc_lookup(array, tmp = make_string("mode", 4), FALSE); + aptr = assoc_lookup(array, tmp = make_string("mode", 4)); *aptr = make_number((AWKNUM) sbuf.st_mode); unref(tmp); - aptr = assoc_lookup(array, tmp = make_string("pmode", 5), FALSE); + aptr = assoc_lookup(array, tmp = make_string("pmode", 5)); pmode = format_mode(sbuf.st_mode); *aptr = make_string(pmode, strlen(pmode)); unref(tmp); |