aboutsummaryrefslogtreecommitdiffstats
path: root/doc/gawk.info
diff options
context:
space:
mode:
Diffstat (limited to 'doc/gawk.info')
-rw-r--r--doc/gawk.info11698
1 files changed, 8244 insertions, 3454 deletions
diff --git a/doc/gawk.info b/doc/gawk.info
index 9ce4b602..8378fd94 100644
--- a/doc/gawk.info
+++ b/doc/gawk.info
@@ -87,20 +87,24 @@ texts being (a) (see below), and with the Back-Cover Texts being (b)
* Arrays:: The description and use of arrays. Also
includes array-oriented control statements.
* Functions:: Built-in and user-defined functions.
+* Library Functions:: A Library of `awk' Functions.
+* Sample Programs:: Many `awk' programs with complete
+ explanations.
* Internationalization:: Getting `gawk' to speak your
language.
* 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.
+* Arbitrary Precision Arithmetic:: Arbitrary precision arithmetic with
+ `gawk'.
+* Dynamic Extensions:: Adding new built-in functions to
+ `gawk'.
* Language History:: The evolution of the `awk'
language.
* Installation:: Installing `gawk' under various
operating systems.
-* Notes:: Notes about `gawk' extensions and
- possible future work.
+* Notes:: Notes about adding things to `gawk'
+ and possible future work.
* Basic Concepts:: A very quick introduction to programming
concepts.
* Glossary:: An explanation of some unfamiliar terms.
@@ -109,399 +113,532 @@ texts being (a) (see below), and with the Back-Cover Texts being (b)
* GNU Free Documentation License:: The license for this Info file.
* Index:: Concept and Variable Index.
-* History:: The history of `gawk' and
- `awk'.
-* Names:: What name to use to find `awk'.
-* This Manual:: Using this Info file. Includes
- sample input files that you can use.
-* Conventions:: Typographical Conventions.
-* Manual History:: Brief history of the GNU project and this
- Info file.
-* How To Contribute:: Helping to save the world.
-* Acknowledgments:: Acknowledgments.
-* Running gawk:: How to run `gawk' programs;
- includes command-line syntax.
-* One-shot:: Running a short throwaway `awk'
- program.
-* Read Terminal:: Using no input files (input from terminal
- instead).
-* Long:: Putting permanent `awk' programs in
- files.
-* Executable Scripts:: Making self-contained `awk'
- programs.
-* Comments:: Adding documentation to `gawk'
- programs.
-* Quoting:: More discussion of shell quoting issues.
-* DOS Quoting:: Quoting in Windows Batch Files.
-* Sample Data Files:: Sample data files for use in the
- `awk' programs illustrated in this
- Info file.
-* Very Simple:: A very simple example.
-* Two Rules:: A less simple one-line example using two
- rules.
-* More Complex:: A more complex example.
-* Statements/Lines:: Subdividing or combining statements into
- lines.
-* Other Features:: Other Features of `awk'.
-* When:: When to use `gawk' and when to use
- other things.
-* Command Line:: How to run `awk'.
-* Options:: Command-line options and their meanings.
-* Other Arguments:: Input file names and variable assignments.
-* Naming Standard Input:: How to specify standard input with other
- files.
-* Environment Variables:: The environment variables `gawk'
- uses.
-* AWKPATH Variable:: Searching directories for `awk'
- programs.
-* Other Environment Variables:: The environment variables.
-* Exit Status:: `gawk''s exit status.
-* Include Files:: Including other files into your program.
-* Obsolete:: Obsolete Options and/or features.
-* Undocumented:: Undocumented Options and Features.
-* Regexp Usage:: How to Use Regular Expressions.
-* Escape Sequences:: How to write nonprinting characters.
-* Regexp Operators:: Regular Expression Operators.
-* Bracket Expressions:: What can go between `[...]'.
-* GNU Regexp Operators:: Operators specific to GNU software.
-* Case-sensitivity:: How to do case-insensitive matching.
-* Leftmost Longest:: How much text matches.
-* Computed Regexps:: Using Dynamic Regexps.
-* Records:: Controlling how data is split into records.
-* Fields:: An introduction to fields.
-* Nonconstant Fields:: Nonconstant Field Numbers.
-* Changing Fields:: Changing the Contents of a Field.
-* Field Separators:: The field separator and how to change it.
-* Default Field Splitting:: How fields are normally separated.
-* Regexp Field Splitting:: Using regexps as the field separator.
-* Single Character Fields:: Making each character a separate field.
-* Command Line Field Separator:: Setting `FS' from the command-line.
-* Field Splitting Summary:: Some final points and a summary table.
-* Constant Size:: Reading constant width data.
-* Splitting By Content:: Defining Fields By Content
-* Multiple Line:: Reading multi-line records.
-* Getline:: Reading files under explicit program
- control using the `getline' function.
-* Plain Getline:: Using `getline' with no arguments.
-* Getline/Variable:: Using `getline' into a variable.
-* Getline/File:: Using `getline' from a file.
-* Getline/Variable/File:: Using `getline' into a variable from a
- file.
-* Getline/Pipe:: Using `getline' from a pipe.
-* Getline/Variable/Pipe:: Using `getline' into a variable from a
- pipe.
-* Getline/Coprocess:: Using `getline' from a coprocess.
-* Getline/Variable/Coprocess:: Using `getline' into a variable from a
- coprocess.
-* Getline Notes:: Important things to know about
- `getline'.
-* Getline Summary:: Summary of `getline' Variants.
-* Command line directories:: What happens if you put a directory on the
- command line.
-* Print:: The `print' statement.
-* Print Examples:: Simple examples of `print' statements.
-* Output Separators:: The output separators and how to change
- them.
-* OFMT:: Controlling Numeric Output With
- `print'.
-* Printf:: The `printf' statement.
-* Basic Printf:: Syntax of the `printf' statement.
-* Control Letters:: Format-control letters.
-* Format Modifiers:: Format-specification modifiers.
-* Printf Examples:: Several examples.
-* Redirection:: How to redirect output to multiple files
- and pipes.
-* Special Files:: File name interpretation in `gawk'.
- `gawk' allows access to inherited
- file descriptors.
-* Special FD:: Special files for I/O.
-* Special Network:: Special files for network communications.
-* Special Caveats:: Things to watch out for.
-* Close Files And Pipes:: Closing Input and Output Files and Pipes.
-* Values:: Constants, Variables, and Regular
- Expressions.
-* Constants:: String, numeric and regexp constants.
-* Scalar Constants:: Numeric and string constants.
-* Nondecimal-numbers:: What are octal and hex numbers.
-* Regexp Constants:: Regular Expression constants.
-* Using Constant Regexps:: When and how to use a regexp constant.
-* Variables:: Variables give names to values for later
- use.
-* Using Variables:: Using variables in your programs.
-* Assignment Options:: Setting variables on the command-line and a
- summary of command-line syntax. This is an
- advanced method of input.
-* Conversion:: The conversion of strings to numbers and
- vice versa.
-* All Operators:: `gawk''s operators.
-* Arithmetic Ops:: Arithmetic operations (`+', `-',
- etc.)
-* Concatenation:: Concatenating strings.
-* Assignment Ops:: Changing the value of a variable or a
- field.
-* Increment Ops:: Incrementing the numeric value of a
- variable.
-* Truth Values and Conditions:: Testing for true and false.
-* Truth Values:: What is ``true'' and what is ``false''.
-* Typing and Comparison:: How variables acquire types and how this
- affects comparison of numbers and strings
- with `<', etc.
-* Variable Typing:: String type versus numeric type.
-* Comparison Operators:: The comparison operators.
-* POSIX String Comparison:: String comparison with POSIX rules.
-* Boolean Ops:: Combining comparison expressions using
- boolean operators `||' (``or''),
- `&&' (``and'') and `!' (``not'').
-* Conditional Exp:: Conditional expressions select between two
- subexpressions under control of a third
- subexpression.
-* Function Calls:: A function call is an expression.
-* Precedence:: How various operators nest.
-* Locales:: How the locale affects things.
-* Pattern Overview:: What goes into a pattern.
-* Regexp Patterns:: Using regexps as patterns.
-* Expression Patterns:: Any expression can be used as a pattern.
-* Ranges:: Pairs of patterns specify record ranges.
-* BEGIN/END:: Specifying initialization and cleanup
- rules.
-* Using BEGIN/END:: How and why to use BEGIN/END rules.
-* I/O And BEGIN/END:: I/O issues in BEGIN/END rules.
-* BEGINFILE/ENDFILE:: Two special patterns for advanced control.
-* Empty:: The empty pattern, which matches every
- record.
-* Using Shell Variables:: How to use shell variables with
- `awk'.
-* Action Overview:: What goes into an action.
-* Statements:: Describes the various control statements in
- detail.
-* If Statement:: Conditionally execute some `awk'
- statements.
-* While Statement:: Loop until some condition is satisfied.
-* Do Statement:: Do specified action while looping until
- some condition is satisfied.
-* For Statement:: Another looping statement, that provides
- initialization and increment clauses.
-* Switch Statement:: Switch/case evaluation for conditional
- execution of statements based on a value.
-* Break Statement:: Immediately exit the innermost enclosing
- loop.
-* Continue Statement:: Skip to the end of the innermost enclosing
- loop.
-* Next Statement:: Stop processing the current input record.
-* Nextfile Statement:: Stop processing the current file.
-* Exit Statement:: Stop execution of `awk'.
-* Built-in Variables:: Summarizes the built-in variables.
-* User-modified:: Built-in variables that you change to
- control `awk'.
-* Auto-set:: Built-in variables where `awk'
- gives you information.
-* ARGC and ARGV:: Ways to use `ARGC' and `ARGV'.
-* Array Basics:: The basics of arrays.
-* Array Intro:: Introduction to Arrays
-* Reference to Elements:: How to examine one element of an array.
-* Assigning Elements:: How to change an element of an array.
-* Array Example:: Basic Example of an Array
-* Scanning an Array:: A variation of the `for' statement. It
- loops through the indices of an array's
- existing elements.
-* Controlling Scanning:: Controlling the order in which arrays are
- scanned.
-* Delete:: The `delete' statement removes an
- element from an array.
-* Numeric Array Subscripts:: How to use numbers as subscripts in
- `awk'.
-* Uninitialized Subscripts:: Using Uninitialized variables as
- subscripts.
-* Multi-dimensional:: Emulating multidimensional arrays in
- `awk'.
-* Multi-scanning:: Scanning multidimensional arrays.
-* Arrays of Arrays:: True multidimensional arrays.
-* Built-in:: Summarizes the built-in functions.
-* Calling Built-in:: How to call built-in functions.
-* Numeric Functions:: Functions that work with numbers, including
- `int()', `sin()' and
- `rand()'.
-* String Functions:: Functions for string manipulation, such as
- `split()', `match()' and
- `sprintf()'.
-* Gory Details:: More than you want to know about `\'
- and `&' with `sub()',
- `gsub()', and `gensub()'.
-* I/O Functions:: Functions for files and shell commands.
-* Time Functions:: Functions for dealing with timestamps.
-* Bitwise Functions:: Functions for bitwise operations.
-* Type Functions:: Functions for type information.
-* I18N Functions:: Functions for string translation.
-* User-defined:: Describes User-defined functions in detail.
-* Definition Syntax:: How to write definitions and what they
- mean.
-* Function Example:: An example function definition and what it
- does.
-* Function Caveats:: Things to watch out for.
-* Calling A Function:: Don't use spaces.
-* Variable Scope:: Controlling variable scope.
-* Pass By Value/Reference:: Passing parameters.
-* Return Statement:: Specifying the value a function returns.
-* Dynamic Typing:: How variable types can change at runtime.
-* Indirect Calls:: Choosing the function to call at runtime.
-* I18N and L10N:: Internationalization and Localization.
-* Explaining gettext:: How GNU `gettext' works.
-* Programmer i18n:: Features for the programmer.
-* Translator i18n:: Features for the translator.
-* String Extraction:: Extracting marked strings.
-* Printf Ordering:: Rearranging `printf' arguments.
-* I18N Portability:: `awk'-level portability issues.
-* I18N Example:: A simple i18n example.
-* Gawk I18N:: `gawk' is also internationalized.
-* Nondecimal Data:: Allowing nondecimal input data.
-* Array Sorting:: Facilities for controlling array traversal
- and sorting arrays.
-* Controlling Array Traversal:: How to use PROCINFO["sorted_in"].
-* Array Sorting Functions:: How to use `asort()' and
- `asorti()'.
-* Two-way I/O:: Two-way communications with another
- process.
-* TCP/IP Networking:: Using `gawk' for network
- programming.
-* Profiling:: Profiling your `awk' programs.
-* Library Names:: How to best name private global variables
- in library functions.
-* General Functions:: Functions that are of general use.
-* Strtonum Function:: A replacement for the built-in
- `strtonum()' function.
-* Assert Function:: A function for assertions in `awk'
- programs.
-* Round Function:: A function for rounding if `sprintf()'
- does not do it correctly.
-* Cliff Random Function:: The Cliff Random Number Generator.
-* Ordinal Functions:: Functions for using characters as numbers
- and vice versa.
-* Join Function:: A function to join an array into a string.
-* Gettimeofday Function:: A function to get formatted times.
-* Data File Management:: Functions for managing command-line data
- files.
-* Filetrans Function:: A function for handling data file
- transitions.
-* Rewind Function:: A function for rereading the current file.
-* File Checking:: Checking that data files are readable.
-* Empty Files:: Checking for zero-length files.
-* Ignoring Assigns:: Treating assignments as file names.
-* Getopt Function:: A function for processing command-line
- arguments.
-* Passwd Functions:: Functions for getting user information.
-* Group Functions:: Functions for getting group information.
-* Walking Arrays:: A function to walk arrays of arrays.
-* Running Examples:: How to run these examples.
-* Clones:: Clones of common utilities.
-* Cut Program:: The `cut' utility.
-* Egrep Program:: The `egrep' utility.
-* Id Program:: The `id' utility.
-* Split Program:: The `split' utility.
-* Tee Program:: The `tee' utility.
-* Uniq Program:: The `uniq' utility.
-* Wc Program:: The `wc' utility.
-* Miscellaneous Programs:: Some interesting `awk' programs.
-* Dupword Program:: Finding duplicated words in a document.
-* Alarm Program:: An alarm clock.
-* Translate Program:: A program similar to the `tr'
- utility.
-* Labels Program:: Printing mailing labels.
-* Word Sorting:: A program to produce a word usage count.
-* History Sorting:: Eliminating duplicate entries from a
- history file.
-* Extract Program:: Pulling out programs from Texinfo source
- files.
-* Simple Sed:: A Simple Stream Editor.
-* Igawk Program:: A wrapper for `awk' that includes
- files.
-* 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 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.
-* Readline Support:: Readline Support.
-* Dgawk 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
- and 4.
-* POSIX:: New features from the POSIX standard.
-* BTL:: New features from Brian Kernighan's version
- of `awk'.
-* POSIX/GNU:: The extensions in `gawk' not in
- POSIX `awk'.
-* Common Extensions:: Common Extensions Summary.
-* Ranges and Locales:: How locales used to affect regexp ranges.
-* Contributors:: The major contributors to `gawk'.
-* Gawk Distribution:: What is in the `gawk' distribution.
-* Getting:: How to get the distribution.
-* Extracting:: How to extract the distribution.
-* Distribution contents:: What is in the distribution.
-* Unix Installation:: Installing `gawk' under various
- versions of Unix.
-* Quick Installation:: Compiling `gawk' under Unix.
-* Additional Configuration Options:: Other compile-time options.
-* Configuration Philosophy:: How it's all supposed to work.
-* Non-Unix Installation:: Installation on Other Operating Systems.
-* PC Installation:: Installing and Compiling `gawk' on
- MS-DOS and OS/2.
-* PC Binary Installation:: Installing a prepared distribution.
-* PC Compiling:: Compiling `gawk' for MS-DOS,
- Windows32, and OS/2.
-* PC Testing:: Testing `gawk' on PC systems.
-* PC Using:: Running `gawk' on MS-DOS, Windows32
- and OS/2.
-* Cygwin:: Building and running `gawk' for
- Cygwin.
-* MSYS:: Using `gawk' In The MSYS
- Environment.
-* VMS Installation:: Installing `gawk' on VMS.
-* VMS Compilation:: How to compile `gawk' under VMS.
-* VMS Installation Details:: How to install `gawk' under VMS.
-* VMS Running:: How to run `gawk' under VMS.
-* VMS Old Gawk:: An old version comes with some VMS systems.
-* Bugs:: Reporting Problems and Bugs.
-* Other Versions:: Other freely available `awk'
- implementations.
-* Compatibility Mode:: How to disable certain `gawk'
- extensions.
-* Additions:: Making Additions To `gawk'.
-* Accessing The Source:: Accessing the Git repository.
-* Adding Code:: Adding code to the main body of
- `gawk'.
-* New Ports:: Porting `gawk' to a new operating
- system.
-* Dynamic Extensions:: Adding new built-in functions to
- `gawk'.
-* Internals:: A brief look at some `gawk'
- internals.
-* Plugin License:: A note about licensing.
-* 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.
-* Using Internal File Ops:: How to use an external extension.
-* Future Extensions:: New features that may be implemented one
- day.
-* Basic High Level:: The high level view.
-* Basic Data Typing:: A very quick intro to data types.
-* Floating Point Issues:: Stuff to know about floating-point numbers.
-* String Conversion Precision:: The String Value Can Lie.
-* Unexpected Results:: Floating Point Numbers Are Not Abstract
- Numbers.
-* POSIX Floating Point Problems:: Standards Versus Existing Practice.
+* History:: The history of `gawk' and
+ `awk'.
+* Names:: What name to use to find
+ `awk'.
+* This Manual:: Using this Info file. Includes
+ sample input files that you can use.
+* Conventions:: Typographical Conventions.
+* Manual History:: Brief history of the GNU project and
+ this Info file.
+* How To Contribute:: Helping to save the world.
+* Acknowledgments:: Acknowledgments.
+* Running gawk:: How to run `gawk' programs;
+ includes command-line syntax.
+* One-shot:: Running a short throwaway
+ `awk' program.
+* Read Terminal:: Using no input files (input from
+ terminal instead).
+* Long:: Putting permanent `awk'
+ programs in files.
+* Executable Scripts:: Making self-contained `awk'
+ programs.
+* Comments:: Adding documentation to `gawk'
+ programs.
+* Quoting:: More discussion of shell quoting
+ issues.
+* DOS Quoting:: Quoting in Windows Batch Files.
+* Sample Data Files:: Sample data files for use in the
+ `awk' programs illustrated in
+ this Info file.
+* Very Simple:: A very simple example.
+* Two Rules:: A less simple one-line example using
+ two rules.
+* More Complex:: A more complex example.
+* Statements/Lines:: Subdividing or combining statements
+ into lines.
+* Other Features:: Other Features of `awk'.
+* When:: When to use `gawk' and when to
+ use other things.
+* Command Line:: How to run `awk'.
+* Options:: Command-line options and their
+ meanings.
+* Other Arguments:: Input file names and variable
+ assignments.
+* Naming Standard Input:: How to specify standard input with
+ other files.
+* Environment Variables:: The environment variables
+ `gawk' uses.
+* AWKPATH Variable:: Searching directories for
+ `awk' programs.
+* AWKLIBPATH Variable:: Searching directories for
+ `awk' shared libraries.
+* Other Environment Variables:: The environment variables.
+* Exit Status:: `gawk''s exit status.
+* Include Files:: Including other files into your
+ program.
+* Loading Shared Libraries:: Loading shared libraries into your
+ program.
+* Obsolete:: Obsolete Options and/or features.
+* Undocumented:: Undocumented Options and Features.
+* Regexp Usage:: How to Use Regular Expressions.
+* Escape Sequences:: How to write nonprinting characters.
+* Regexp Operators:: Regular Expression Operators.
+* Bracket Expressions:: What can go between `[...]'.
+* GNU Regexp Operators:: Operators specific to GNU software.
+* Case-sensitivity:: How to do case-insensitive matching.
+* Leftmost Longest:: How much text matches.
+* Computed Regexps:: Using Dynamic Regexps.
+* Records:: Controlling how data is split into
+ records.
+* Fields:: An introduction to fields.
+* Nonconstant Fields:: Nonconstant Field Numbers.
+* Changing Fields:: Changing the Contents of a Field.
+* Field Separators:: The field separator and how to change
+ it.
+* Default Field Splitting:: How fields are normally separated.
+* Regexp Field Splitting:: Using regexps as the field separator.
+* Single Character Fields:: Making each character a separate
+ field.
+* Command Line Field Separator:: Setting `FS' from the
+ command-line.
+* Field Splitting Summary:: Some final points and a summary table.
+* Constant Size:: Reading constant width data.
+* Splitting By Content:: Defining Fields By Content
+* Multiple Line:: Reading multi-line records.
+* Getline:: Reading files under explicit program
+ control using the `getline'
+ function.
+* Plain Getline:: Using `getline' with no
+ arguments.
+* Getline/Variable:: Using `getline' into a variable.
+* Getline/File:: Using `getline' from a file.
+* Getline/Variable/File:: Using `getline' into a variable
+ from a file.
+* Getline/Pipe:: Using `getline' from a pipe.
+* Getline/Variable/Pipe:: Using `getline' into a variable
+ from a pipe.
+* Getline/Coprocess:: Using `getline' from a coprocess.
+* Getline/Variable/Coprocess:: Using `getline' into a variable
+ from a coprocess.
+* 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.
+* Print Examples:: Simple examples of `print'
+ statements.
+* Output Separators:: The output separators and how to
+ change them.
+* OFMT:: Controlling Numeric Output With
+ `print'.
+* Printf:: The `printf' statement.
+* Basic Printf:: Syntax of the `printf' statement.
+* Control Letters:: Format-control letters.
+* Format Modifiers:: Format-specification modifiers.
+* Printf Examples:: Several examples.
+* Redirection:: How to redirect output to multiple
+ files and pipes.
+* Special Files:: File name interpretation in
+ `gawk'. `gawk' allows
+ access to inherited file descriptors.
+* Special FD:: Special files for I/O.
+* Special Network:: Special files for network
+ communications.
+* Special Caveats:: Things to watch out for.
+* Close Files And Pipes:: Closing Input and Output Files and
+ Pipes.
+* Values:: Constants, Variables, and Regular
+ Expressions.
+* Constants:: String, numeric and regexp constants.
+* Scalar Constants:: Numeric and string constants.
+* Nondecimal-numbers:: What are octal and hex numbers.
+* Regexp Constants:: Regular Expression constants.
+* Using Constant Regexps:: When and how to use a regexp constant.
+* Variables:: Variables give names to values for
+ later use.
+* Using Variables:: Using variables in your programs.
+* Assignment Options:: Setting variables on the command-line
+ and a summary of command-line syntax.
+ This is an advanced method of input.
+* Conversion:: The conversion of strings to numbers
+ and vice versa.
+* All Operators:: `gawk''s operators.
+* Arithmetic Ops:: Arithmetic operations (`+',
+ `-', etc.)
+* Concatenation:: Concatenating strings.
+* Assignment Ops:: Changing the value of a variable or a
+ field.
+* Increment Ops:: Incrementing the numeric value of a
+ variable.
+* Truth Values and Conditions:: Testing for true and false.
+* Truth Values:: What is ``true'' and what is
+ ``false''.
+* Typing and Comparison:: How variables acquire types and how
+ this affects comparison of numbers and
+ strings with `<', etc.
+* Variable Typing:: String type versus numeric type.
+* Comparison Operators:: The comparison operators.
+* POSIX String Comparison:: String comparison with POSIX rules.
+* Boolean Ops:: Combining comparison expressions using
+ boolean operators `||' (``or''),
+ `&&' (``and'') and `!'
+ (``not'').
+* Conditional Exp:: Conditional expressions select between
+ two subexpressions under control of a
+ third subexpression.
+* Function Calls:: A function call is an expression.
+* Precedence:: How various operators nest.
+* Locales:: How the locale affects things.
+* Pattern Overview:: What goes into a pattern.
+* Regexp Patterns:: Using regexps as patterns.
+* Expression Patterns:: Any expression can be used as a
+ pattern.
+* Ranges:: Pairs of patterns specify record
+ ranges.
+* BEGIN/END:: Specifying initialization and cleanup
+ rules.
+* Using BEGIN/END:: How and why to use BEGIN/END rules.
+* I/O And BEGIN/END:: I/O issues in BEGIN/END rules.
+* BEGINFILE/ENDFILE:: Two special patterns for advanced
+ control.
+* Empty:: The empty pattern, which matches every
+ record.
+* Using Shell Variables:: How to use shell variables with
+ `awk'.
+* Action Overview:: What goes into an action.
+* Statements:: Describes the various control
+ statements in detail.
+* If Statement:: Conditionally execute some
+ `awk' statements.
+* While Statement:: Loop until some condition is
+ satisfied.
+* Do Statement:: Do specified action while looping
+ until some condition is satisfied.
+* For Statement:: Another looping statement, that
+ provides initialization and increment
+ clauses.
+* Switch Statement:: Switch/case evaluation for conditional
+ execution of statements based on a
+ value.
+* Break Statement:: Immediately exit the innermost
+ enclosing loop.
+* Continue Statement:: Skip to the end of the innermost
+ enclosing loop.
+* Next Statement:: Stop processing the current input
+ record.
+* Nextfile Statement:: Stop processing the current file.
+* Exit Statement:: Stop execution of `awk'.
+* Built-in Variables:: Summarizes the built-in variables.
+* User-modified:: Built-in variables that you change to
+ control `awk'.
+* Auto-set:: Built-in variables where `awk'
+ gives you information.
+* ARGC and ARGV:: Ways to use `ARGC' and
+ `ARGV'.
+* Array Basics:: The basics of arrays.
+* Array Intro:: Introduction to Arrays
+* Reference to Elements:: How to examine one element of an
+ array.
+* Assigning Elements:: How to change an element of an array.
+* Array Example:: Basic Example of an Array
+* Scanning an Array:: A variation of the `for'
+ statement. It loops through the
+ indices of an array's existing
+ elements.
+* Controlling Scanning:: Controlling the order in which arrays
+ are scanned.
+* Delete:: The `delete' statement removes an
+ element from an array.
+* Numeric Array Subscripts:: How to use numbers as subscripts in
+ `awk'.
+* Uninitialized Subscripts:: Using Uninitialized variables as
+ subscripts.
+* Multi-dimensional:: Emulating multidimensional arrays in
+ `awk'.
+* Multi-scanning:: Scanning multidimensional arrays.
+* Arrays of Arrays:: True multidimensional arrays.
+* Built-in:: Summarizes the built-in functions.
+* Calling Built-in:: How to call built-in functions.
+* Numeric Functions:: Functions that work with numbers,
+ including `int()', `sin()'
+ and `rand()'.
+* String Functions:: Functions for string manipulation,
+ such as `split()', `match()'
+ and `sprintf()'.
+* Gory Details:: More than you want to know about
+ `\' and `&' with
+ `sub()', `gsub()', and
+ `gensub()'.
+* I/O Functions:: Functions for files and shell
+ commands.
+* Time Functions:: Functions for dealing with timestamps.
+* Bitwise Functions:: Functions for bitwise operations.
+* Type Functions:: Functions for type information.
+* I18N Functions:: Functions for string translation.
+* User-defined:: Describes User-defined functions in
+ detail.
+* Definition Syntax:: How to write definitions and what they
+ mean.
+* Function Example:: An example function definition and
+ what it does.
+* Function Caveats:: Things to watch out for.
+* Calling A Function:: Don't use spaces.
+* Variable Scope:: Controlling variable scope.
+* Pass By Value/Reference:: Passing parameters.
+* Return Statement:: Specifying the value a function
+ returns.
+* Dynamic Typing:: How variable types can change at
+ runtime.
+* Indirect Calls:: Choosing the function to call at
+ runtime.
+* Library Names:: How to best name private global
+ variables in library functions.
+* General Functions:: Functions that are of general use.
+* Strtonum Function:: A replacement for the built-in
+ `strtonum()' function.
+* Assert Function:: A function for assertions in
+ `awk' programs.
+* Round Function:: A function for rounding if
+ `sprintf()' does not do it
+ correctly.
+* Cliff Random Function:: The Cliff Random Number Generator.
+* Ordinal Functions:: Functions for using characters as
+ numbers and vice versa.
+* Join Function:: A function to join an array into a
+ string.
+* Getlocaltime Function:: A function to get formatted times.
+* Data File Management:: Functions for managing command-line
+ data files.
+* Filetrans Function:: A function for handling data file
+ transitions.
+* Rewind Function:: A function for rereading the current
+ file.
+* File Checking:: Checking that data files are readable.
+* Empty Files:: Checking for zero-length files.
+* Ignoring Assigns:: Treating assignments as file names.
+* Getopt Function:: A function for processing command-line
+ arguments.
+* Passwd Functions:: Functions for getting user
+ information.
+* Group Functions:: Functions for getting group
+ information.
+* Walking Arrays:: A function to walk arrays of arrays.
+* Running Examples:: How to run these examples.
+* Clones:: Clones of common utilities.
+* Cut Program:: The `cut' utility.
+* Egrep Program:: The `egrep' utility.
+* Id Program:: The `id' utility.
+* Split Program:: The `split' utility.
+* Tee Program:: The `tee' utility.
+* Uniq Program:: The `uniq' utility.
+* Wc Program:: The `wc' utility.
+* Miscellaneous Programs:: Some interesting `awk'
+ programs.
+* Dupword Program:: Finding duplicated words in a
+ document.
+* Alarm Program:: An alarm clock.
+* Translate Program:: A program similar to the `tr'
+ utility.
+* Labels Program:: Printing mailing labels.
+* Word Sorting:: A program to produce a word usage
+ count.
+* History Sorting:: Eliminating duplicate entries from a
+ history file.
+* Extract Program:: Pulling out programs from Texinfo
+ source files.
+* Simple Sed:: A Simple Stream Editor.
+* Igawk Program:: A wrapper for `awk' that
+ includes files.
+* Anagram Program:: Finding anagrams from a dictionary.
+* Signature Program:: People do amazing things with too much
+ time on their hands.
+* I18N and L10N:: Internationalization and Localization.
+* Explaining gettext:: How GNU `gettext' works.
+* Programmer i18n:: Features for the programmer.
+* Translator i18n:: Features for the translator.
+* String Extraction:: Extracting marked strings.
+* Printf Ordering:: Rearranging `printf' arguments.
+* I18N Portability:: `awk'-level portability
+ issues.
+* I18N Example:: A simple i18n example.
+* Gawk I18N:: `gawk' is also
+ internationalized.
+* Nondecimal Data:: Allowing nondecimal input data.
+* Array Sorting:: Facilities for controlling array
+ traversal and sorting arrays.
+* Controlling Array Traversal:: How to use PROCINFO["sorted_in"].
+* Array Sorting Functions:: How to use `asort()' and
+ `asorti()'.
+* Two-way I/O:: Two-way communications with another
+ process.
+* TCP/IP Networking:: Using `gawk' for network
+ programming.
+* Profiling:: Profiling your `awk' programs.
+* Debugging:: Introduction to `gawk'
+ debugger.
+* Debugging Concepts:: Debugging in General.
+* Debugging Terms:: Additional Debugging Concepts.
+* Awk Debugging:: Awk Debugging.
+* Sample Debugging Session:: Sample debugging session.
+* Debugger Invocation:: How to Start the Debugger.
+* Finding The Bug:: Finding the Bug.
+* List of Debugger Commands:: Main debugger 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.
+* Limitations:: Limitations and future plans.
+* General Arithmetic:: An introduction to computer
+ arithmetic.
+* Floating Point Issues:: Stuff to know about floating-point
+ numbers.
+* String Conversion Precision:: The String Value Can Lie.
+* Unexpected Results:: Floating Point Numbers Are Not
+ Abstract Numbers.
+* POSIX Floating Point Problems:: Standards Versus Existing Practice.
+* Integer Programming:: Effective integer programming.
+* 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.
+* Gawk and MPFR:: How `gawk' provides
+ arbitrary-precision arithmetic.
+* 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.
+* Arbitrary Precision Integers:: Arbitrary Precision Integer Arithmetic
+ with `gawk'.
+* Extension Intro:: What is an extension.
+* Plugin License:: A note about licensing.
+* Extension Design:: Design notes about the extension API.
+* Old Extension Problems:: Problems with the old mechanism.
+* Extension New Mechanism Goals:: Goals for the new mechanism.
+* Extension Other Design Decisions:: Some other design decisions.
+* Extension Mechanism Outline:: An outline of how it works.
+* Extension Future Growth:: Some room for future growth.
+* Extension API Description:: A full description of the API.
+* Extension API Functions Introduction:: Introduction to the API functions.
+* General Data Types:: The data types.
+* Requesting Values:: How to get a value.
+* Constructor Functions:: Functions for creating values.
+* Registration Functions:: Functions to register things with
+ `gawk'.
+* Extension Functions:: Registering extension functions.
+* Exit Callback Functions:: Registering an exit callback.
+* Extension Version String:: Registering a version string.
+* Input Parsers:: Registering an input parser.
+* Output Wrappers:: Registering an output wrapper.
+* Two-way processors:: Registering a two-way processor.
+* Printing Messages:: Functions for printing messages.
+* Updating `ERRNO':: Functions for updating `ERRNO'.
+* Accessing Parameters:: Functions for accessing parameters.
+* Symbol Table Access:: Functions for accessing global
+ variables.
+* Symbol table by name:: Accessing variables by name.
+* Symbol table by cookie:: Accessing variables by ``cookie''.
+* Cached values:: Creating and using cached values.
+* Array Manipulation:: Functions for working with arrays.
+* Array Data Types:: Data types for working with arrays.
+* Array Functions:: Functions for working with arrays.
+* Flattening Arrays:: How to flatten arrays.
+* Creating Arrays:: How to create and populate arrays.
+* Extension API Variables:: Variables provided by the API.
+* Extension Versioning:: API Version information.
+* Extension API Informational Variables:: Variables providing information about
+ `gawk''s invocation.
+* Extension API Boilerplate:: Boilerplate code for using the API.
+* Finding Extensions:: How `gawk' finds compiled
+ extensions.
+* Extension Example:: Example C code for an extension.
+* Internal File Description:: What the new functions will do.
+* Internal File Ops:: The code for internal file operations.
+* Using Internal File Ops:: How to use an external extension.
+* Extension Samples:: The sample extensions that ship with
+ `gawk'.
+* Extension Sample File Functions:: The file functions sample.
+* Extension Sample Fnmatch:: An interface to `fnmatch()'.
+* Extension Sample Fork:: An interface to `fork()' and
+ other process functions.
+* Extension Sample Ord:: Character to value to character
+ conversions.
+* Extension Sample Readdir:: An interface to `readdir()'.
+* Extension Sample Revout:: Reversing output sample output
+ wrapper.
+* Extension Sample Rev2way:: Reversing data sample two-way
+ processor.
+* Extension Sample Read write array:: Serializing an array to a file.
+* Extension Sample Readfile:: Reading an entire file into a string.
+* Extension Sample API Tests:: Tests for the API.
+* Extension Sample Time:: An interface to `gettimeofday()'
+ and `sleep()'.
+* gawkextlib:: The `gawkextlib' project.
+* V7/SVR3.1:: The major changes between V7 and
+ System V Release 3.1.
+* SVR4:: Minor changes between System V
+ Releases 3.1 and 4.
+* POSIX:: New features from the POSIX standard.
+* BTL:: New features from Brian Kernighan's
+ version of `awk'.
+* POSIX/GNU:: The extensions in `gawk' not
+ in POSIX `awk'.
+* Common Extensions:: Common Extensions Summary.
+* Ranges and Locales:: How locales used to affect regexp
+ ranges.
+* Contributors:: The major contributors to
+ `gawk'.
+* Gawk Distribution:: What is in the `gawk'
+ distribution.
+* Getting:: How to get the distribution.
+* Extracting:: How to extract the distribution.
+* Distribution contents:: What is in the distribution.
+* Unix Installation:: Installing `gawk' under
+ various versions of Unix.
+* Quick Installation:: Compiling `gawk' under Unix.
+* Additional Configuration Options:: Other compile-time options.
+* Configuration Philosophy:: How it's all supposed to work.
+* Non-Unix Installation:: Installation on Other Operating
+ Systems.
+* PC Installation:: Installing and Compiling
+ `gawk' on MS-DOS and OS/2.
+* PC Binary Installation:: Installing a prepared distribution.
+* PC Compiling:: Compiling `gawk' for MS-DOS,
+ Windows32, and OS/2.
+* PC Testing:: Testing `gawk' on PC systems.
+* PC Using:: Running `gawk' on MS-DOS,
+ Windows32 and OS/2.
+* Cygwin:: Building and running `gawk'
+ for Cygwin.
+* MSYS:: Using `gawk' In The MSYS
+ Environment.
+* VMS Installation:: Installing `gawk' on VMS.
+* VMS Compilation:: How to compile `gawk' under
+ VMS.
+* VMS Installation Details:: How to install `gawk' under
+ VMS.
+* VMS Running:: How to run `gawk' under VMS.
+* VMS Old Gawk:: An old version comes with some VMS
+ systems.
+* Bugs:: Reporting Problems and Bugs.
+* Other Versions:: Other freely available `awk'
+ implementations.
+* Compatibility Mode:: How to disable certain `gawk'
+ extensions.
+* Additions:: Making Additions To `gawk'.
+* Accessing The Source:: Accessing the Git repository.
+* Adding Code:: Adding code to the main body of
+ `gawk'.
+* New Ports:: Porting `gawk' to a new
+ operating system.
+* Derived Files:: Why derived files are kept in the
+ `git' repository.
+* Future Extensions:: New features that may be implemented
+ one day.
+* Implementation Limitations:: Some limitations of the implementation.
+* Basic High Level:: The high level view.
+* Basic Data Typing:: A very quick intro to data types.
To Miriam, for making me complete.
@@ -805,6 +942,12 @@ expert should find useful. In particular, the description of POSIX
`awk' and the example programs in *note Library Functions::, and in
*note Sample Programs::, should be of interest.
+ This Info file is split into several parts, as follows:
+
+ Part I describes the `awk' language and `gawk' program in detail.
+It starts with the basics, and continues through all of the features of
+`awk'. It contains the following chapters:
+
*note Getting Started::, provides the essentials you need to know to
begin using `awk'.
@@ -837,6 +980,21 @@ described, as well as sorting arrays in `gawk'. It also describes how
*note Functions::, describes the built-in functions `awk' and `gawk'
provide, as well as how to define your own functions.
+ Part II shows how to use `awk' and `gawk' for problem solving.
+There is lots of code here for you to read and learn from. It contains
+the following chapters:
+
+ *note Library Functions::, which provides a number of functions
+meant to be used from main `awk' programs.
+
+ *note Sample Programs::, which provides many sample `awk' programs.
+
+ Reading these two chapters allows you to see `awk' solving real
+problems.
+
+ Part III focuses on features specific to `gawk'. It contains the
+following chapters:
+
*note Internationalization::, describes special features in `gawk'
for translating program messages into different languages at runtime.
@@ -845,11 +1003,17 @@ advanced features. Of particular note are the abilities to have
two-way communications with another process, perform TCP/IP networking,
and profile your `awk' programs.
- *note Library Functions::, and *note Sample Programs::, provide many
-sample `awk' programs. Reading them allows you to see `awk' solving
-real problems.
+ *note Debugger::, describes the `awk' debugger.
+
+ *note Arbitrary Precision Arithmetic::, describes advanced
+arithmetic facilities provided by `gawk'.
+
+ *note Dynamic Extensions::, describes how to add new variables and
+functions to `gawk' by writing extensions in C.
- *note Debugger::, describes the `awk' debugger, `dgawk'.
+ Part IV provides the appendices, the Glossary, and two licenses that
+cover the `gawk' source code and this Info file, respectively. It
+contains the following appendices:
*note Language History::, describes how the `awk' language has
evolved since its first release to present. It also describes how
@@ -861,8 +1025,8 @@ non-POSIX systems. It also describes how to report bugs in `gawk' and
where to get other freely available `awk' implementations.
*note Notes::, describes how to disable `gawk''s extensions, as well
-as how to contribute new code to `gawk', how to write extension
-libraries, and some possible future directions for `gawk' development.
+as how to contribute new code to `gawk', and some possible future
+directions for `gawk' development.
*note Basic Concepts::, provides some very cursory background
material for those who are completely unfamiliar with computer
@@ -1100,10 +1264,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
@@ -2086,6 +2252,7 @@ this major node that don't interest you right now.
* Environment Variables:: The environment variables `gawk' uses.
* Exit Status:: `gawk''s exit status.
* Include Files:: Including other files into your program.
+* Loading Shared Libraries:: Loading shared libraries into your program.
* Obsolete:: Obsolete Options and/or features.
* Undocumented:: Undocumented Options and Features.
@@ -2143,6 +2310,20 @@ The following list describes options mandated by the POSIX standard:
`awk' program consists of the concatenation the contents of each
specified SOURCE-FILE.
+`-i SOURCE-FILE'
+`--include SOURCE-FILE'
+ Read `awk' source library from SOURCE-FILE. This option is
+ completely equivalent to using the `@include' directive inside
+ your program. This option is very similar to the `-f' option, but
+ there are two important differences. First, when `-i' is used,
+ the program source will not be loaded if it has been previously
+ loaded, whereas the `-f' will always load the file. Second,
+ because this option is intended to be used with code libraries, the
+ `awk' command does not recognize such files as constituting main
+ program input. Thus, after processing an `-i' argument, we still
+ expect to find the main source code via the `-f' option or on the
+ command-line.
+
`-v VAR=VAL'
`--assign VAR=VAL'
Set the variable VAR to the value VAL _before_ execution of the
@@ -2219,6 +2400,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
@@ -2261,6 +2451,15 @@ 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
+ `AWKLIBPATH' environment variable. The correct library suffix for
+ your platform will be supplied by default, so it need not be
+ specified in the library name. The library initialization routine
+ should be named `dl_load()'. An alternative is to use the `@load'
+ keyword inside the program to load a shared library.
+
`-L [value]'
`--lint[=value]'
Warn about constructs that are dubious or nonportable to other
@@ -2280,6 +2479,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
@@ -2293,6 +2498,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
@@ -2308,10 +2521,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'
@@ -2345,11 +2557,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',
@@ -2529,10 +2736,12 @@ A number of environment variables influence how `gawk' behaves.
* AWKPATH Variable:: Searching directories for `awk'
programs.
+* AWKLIBPATH Variable:: Searching directories for `awk' shared
+ libraries.
* Other Environment Variables:: The environment variables.

-File: gawk.info, Node: AWKPATH Variable, Next: Other Environment Variables, Up: Environment Variables
+File: gawk.info, Node: AWKPATH Variable, Next: AWKLIBPATH Variable, Up: Environment Variables
2.5.1 The `AWKPATH' Environment Variable
----------------------------------------
@@ -2541,9 +2750,9 @@ The previous minor node described how `awk' program files can be named
on the command-line with the `-f' option. In most `awk'
implementations, you must supply a precise path name for each program
file, unless the file is in the current directory. But in `gawk', if
-the file name supplied to the `-f' option does not contain a `/', then
-`gawk' searches a list of directories (called the "search path"), one
-by one, looking for a file with the specified name.
+the file name supplied to the `-f' or `-i' options does not contain a
+`/', then `gawk' searches a list of directories (called the "search
+path"), one by one, looking for a file with the specified name.
The search path is a string consisting of directory names separated by
colons. `gawk' gets its search path from the `AWKPATH' environment
@@ -2556,11 +2765,15 @@ standard directory in the default path and then specified on the
command line with a short file name. Otherwise, the full file name
would have to be typed for each file.
- By using both the `--source' and `-f' options, your command-line
-`awk' programs can use facilities in `awk' library files (*note Library
-Functions::). Path searching is not done if `gawk' is in compatibility
-mode. This is true for both `--traditional' and `--posix'. *Note
-Options::.
+ By using the `-i' option, or the `--source' and `-f' options, your
+command-line `awk' programs can use facilities in `awk' library files
+(*note Library Functions::). Path searching is not done if `gawk' is
+in compatibility mode. This is true for both `--traditional' and
+`--posix'. *Note Options::.
+
+ If the source code is not found after the initial search, the path
+is searched again after adding the default `.awk' suffix to the
+filename.
NOTE: To include the current directory in the path, either place
`.' explicitly in the path or write a null entry in the path. (A
@@ -2591,9 +2804,22 @@ the value of `$(datadir)' generated when `gawk' was configured. You
probably don't need to worry about this, though.

-File: gawk.info, Node: Other Environment Variables, Prev: AWKPATH Variable, Up: Environment Variables
+File: gawk.info, Node: AWKLIBPATH Variable, Next: Other Environment Variables, Prev: AWKPATH Variable, Up: Environment Variables
+
+2.5.2 The `AWKLIBPATH' Environment Variable
+-------------------------------------------
+
+The `AWKLIBPATH' environment variable is similar to the `AWKPATH'
+variable, but it is used to search for shared libraries specified with
+the `-l' option rather than for source files. If the library is not
+found, the path is searched again after adding the appropriate shared
+library suffix for the platform. For example, on GNU/Linux systems,
+the suffix `.so' is used.
-2.5.2 Other Environment Variables
+
+File: gawk.info, Node: Other Environment Variables, Prev: AWKLIBPATH Variable, Up: Environment Variables
+
+2.5.3 Other Environment Variables
---------------------------------
A number of other environment variables affect `gawk''s behavior, but
@@ -2614,6 +2840,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:
@@ -2668,7 +2898,7 @@ with the value of the C constant `EXIT_SUCCESS'. This is usually zero.
non-POSIX systems, this value may be mapped to `EXIT_FAILURE'.

-File: gawk.info, Node: Include Files, Next: Obsolete, Prev: Exit Status, Up: Invoking Gawk
+File: gawk.info, Node: Include Files, Next: Loading Shared Libraries, Prev: Exit Status, Up: Invoking Gawk
2.7 Including Other Files Into Your Program
===========================================
@@ -2682,7 +2912,8 @@ into smaller, more manageable pieces, and also lets you reuse common
together `awk' functions, used to carry out specific tasks, into
external files. These files can be used just like function libraries,
using the `@include' keyword in conjunction with the `AWKPATH'
-environment variable.
+environment variable. Note that source files may also be included
+using the `-i' option.
Let's see an example. We'll start with two (trivial) `awk' scripts,
namely `test1' and `test2'. Here is the `test1' script:
@@ -2764,9 +2995,41 @@ always searched first for source files, before searching in `AWKPATH',
and this also applies to files named with `@include'.

-File: gawk.info, Node: Obsolete, Next: Undocumented, Prev: Include Files, Up: Invoking Gawk
+File: gawk.info, Node: Loading Shared Libraries, Next: Obsolete, Prev: Include Files, Up: Invoking Gawk
-2.8 Obsolete Options and/or Features
+2.8 Loading Shared Libraries Into Your Program
+==============================================
+
+This minor node describes a feature that is specific to `gawk'.
+
+ The `@load' keyword can be used to read external `awk' shared
+libraries. This allows you to link in compiled code that may offer
+superior performance and/or give you access to extended capabilities
+not supported by the `awk' language. The `AWKLIBPATH' variable is used
+to search for the shared library. Using `@load' is completely
+equivalent to using the `-l' command-line option.
+
+ If the shared library is not initially found in `AWKLIBPATH', another
+search is conducted after appending the platform's default shared
+library suffix to the filename. For example, on GNU/Linux systems, the
+suffix `.so' is used.
+
+ $ gawk '@load "ordchr"; BEGIN {print chr(65)}'
+ -| A
+
+This is equivalent to the following example:
+
+ $ gawk -lordchr 'BEGIN {print chr(65)}'
+ -| A
+
+For command-line usage, the `-l' option is more convenient, but `@load'
+is useful for embedding inside an `awk' source file that requires
+access to a shared library.
+
+
+File: gawk.info, Node: Obsolete, Next: Undocumented, Prev: Loading Shared Libraries, Up: Invoking Gawk
+
+2.9 Obsolete Options and/or Features
====================================
This minor node describes features and/or command-line options from
@@ -2782,8 +3045,8 @@ worked. As of version 4.0, they are no longer interpreted specially by

File: gawk.info, Node: Undocumented, Prev: Obsolete, Up: Invoking Gawk
-2.9 Undocumented Options and Features
-=====================================
+2.10 Undocumented Options and Features
+======================================
Use the Source, Luke!
Obi-Wan
@@ -3615,6 +3878,7 @@ 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.
@@ -4807,7 +5071,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'
=================================
@@ -5233,7 +5497,8 @@ File: gawk.info, Node: Getline Summary, Prev: Getline Notes, Up: Getline
*note table-getline-variants:: summarizes the eight variants of
`getline', listing which built-in variables are set by each one, and
-whether the variant is standard or a `gawk' extension.
+whether the variant is standard or a `gawk' extension. Note: for each
+variant, `gawk' sets the `RT' built-in variable.
Variant Effect Standard /
Extension
@@ -5249,12 +5514,104 @@ COMMAND `|& getline' Sets `$0' and `NF' Extension
COMMAND `|& getline' Sets VAR Extension
VAR
-Table 4.1: getline Variants and What They Set
+Table 4.1: `getline' Variants and What They Set
+
+
+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 ----------
+
+ (1) This assumes that standard input is the keyboard

-File: gawk.info, Node: Command line directories, Prev: Getline, Up: Reading Files
+File: gawk.info, Node: Command line directories, Prev: Read Timeout, Up: Reading Files
-4.10 Directories On The Command Line
+4.11 Directories On The Command Line
====================================
According to the POSIX standard, files named on the `awk' command line
@@ -8329,10 +8686,10 @@ would otherwise be difficult or impossible to perform:
entirely. Otherwise, `gawk' exits with the usual fatal error.
* If you have written extensions that modify the record handling (by
- inserting an "open hook"), you can invoke them at this point,
+ inserting an "input parser"), you can invoke them at this point,
before `gawk' has started processing the file. (This is a _very_
- advanced feature, currently used only by the XMLgawk project
- (http://xmlgawk.sourceforge.net).)
+ advanced feature, currently used only by the `gawkextlib' project
+ (http://gawkextlib.sourceforge.net).)
The `ENDFILE' rule is called when `gawk' has finished processing the
last record in an input file. For the last input file, it will be
@@ -9216,6 +9573,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
@@ -9321,7 +9687,8 @@ with a pound sign (`#').
Some operating systems may not have environment variables. On
such systems, the `ENVIRON' array is empty (except for
- `ENVIRON["AWKPATH"]', *note AWKPATH Variable::).
+ `ENVIRON["AWKPATH"]', *note AWKPATH Variable:: and
+ `ENVIRON["AWKLIBPATH"]', *note AWKLIBPATH Variable::).
`ERRNO #'
If a system error occurs during a redirection for `getline',
@@ -9369,6 +9736,12 @@ with a pound sign (`#').
create or remove fields from the current record. *Note Changing
Fields::.
+`FUNCTAB #'
+ An array whose indices are the names of all the user-defined or
+ extension functions in the program. *NOTE*: The array values
+ cannot currently be used. Also, you may not use the `delete'
+ statement with the `FUNCTAB' array.
+
`NR'
The number of input records `awk' has processed since the
beginning of the program's execution (*note Records::). `NR' is
@@ -9391,6 +9764,32 @@ with a pound sign (`#').
effect, or `"FPAT"' if field matching with `FPAT' is in
effect.
+ `PROCINFO["identifiers"]'
+ A subarray, indexed by the names of all identifiers used in
+ the text of the AWK program. For each identifier, the value
+ of the element is one of the following:
+
+ `"array"'
+ The identifier is an array.
+
+ `"extension"'
+ The identifier is an extension function loaded via
+ `@load'.
+
+ `"scalar"'
+ The identifier is a scalar.
+
+ `"untyped"'
+ The identifier is untyped (could be used as a scalar or
+ array, `gawk' doesn't know yet).
+
+ `"user"'
+ The identifier is a user-defined function.
+
+ The values indicate what `gawk' knows about the identifiers
+ after it has finished parsing the program; they are _not_
+ updated while the program runs.
+
`PROCINFO["gid"]'
The value of the `getgid()' system call.
@@ -9421,6 +9820,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
@@ -9455,6 +9871,44 @@ with a pound sign (`#').
implementations, or if `gawk' is in compatibility mode (*note
Options::), it is not special.
+`SYMTAB #'
+ An array whose indices are the names of all currently defined
+ global variables and arrays in the program. The array may be used
+ for indirect access to read or write the value of a variable:
+
+ foo = 5
+ SYMTAB["foo"] = 4
+ print foo # prints 4
+
+ The `isarray()' function (*note Type Functions::) may be used to
+ test if an element in `SYMTAB' is an array. Also, you may not use
+ the `delete' statement with the `SYMTAB' array.
+
+ You may use an index for `SYMTAB' that is not a predefined
+ identifer:
+
+ SYMTAB["xxx"] = 5
+ print SYMTAB["xxx"]
+
+ This works as expected: in this case `SYMTAB' acts just like a
+ regular array. The only difference is that you can't then delete
+ `SYMTAB["xxx"]'.
+
+ The `SYMTAB' array is more interesting than it looks. Andrew Schorr
+ points out that it effectively gives `awk' data pointers. Consider
+ his example:
+
+ # Indirect multiply of any variable by amount, return result
+
+ function multiply(variable, amount)
+ {
+ return SYMTAB[variable] *= amount
+ }
+
+ NOTE: In order to avoid severe time-travel paradoxes(2),
+ neither `FUNCTAB' nor `SYMTAB' are available as elements
+ within the `SYMTAB' array.
+
Advanced Notes: Changing `NR' and `FNR'
---------------------------------------
@@ -9484,6 +9938,8 @@ file by resetting `NR' to zero when `FILENAME' changed.
to `"-"', even if there were data files to be processed. This behavior
was incorrect and should not be relied upon in your programs.
+ (2) Not to mention difficult implementation issues.
+

File: gawk.info, Node: ARGC and ARGV, Prev: Auto-set, Up: Built-in Variables
@@ -10494,7 +10950,7 @@ by creating an arbitrary index:
-| a

-File: gawk.info, Node: Functions, Next: Internationalization, Prev: Arrays, Up: Top
+File: gawk.info, Node: Functions, Next: Library Functions, Prev: Arrays, Up: Top
9 Functions
***********
@@ -11315,7 +11771,8 @@ literally. The interpretation of `\' and `&' then becomes as shown in
`\\\\&' `\\&' a literal `\', then the matched text
`\\\\\\&' `\\\&' a literal `\&'
-Table 9.2: 1992 POSIX Rules for sub and gsub Escape Sequence Processing
+Table 9.2: 1992 POSIX Rules for `sub()' and `gsub()' Escape Sequence
+Processing
This appears to solve the problem. Unfortunately, the phrasing of the
standard is unusual. It says, in effect, that `\' turns off the special
@@ -11344,7 +11801,7 @@ table-sub-proposed::.
`\\q' `\q' a literal `\q'
`\\\\' `\\' `\\'
-Table 9.3: Proposed rules for sub and backslash
+Table 9.3: Proposed Rules For `sub()' And Backslash
In a nutshell, at the runtime level, there are now three special
sequences of characters (`\\\&', `\\&' and `\&') whereas historically
@@ -11371,7 +11828,7 @@ rules are presented in *note table-posix-sub::.
`\\q' `\q' a literal `\q'
`\\\\' `\\' `\'
-Table 9.4: POSIX rules for `sub()' and `gsub()'
+Table 9.4: POSIX Rules For `sub()' And `gsub()'
The only case where the difference is noticeable is the last one:
`\\\\' is seen as `\\' and produces `\' instead of `\\'.
@@ -11381,7 +11838,7 @@ Table 9.4: POSIX rules for `sub()' and `gsub()'
follow the 1996 proposed rules, since that had been its behavior for
many years.
- When version 4.0.0, was released, the `gawk' maintainer made the
+ When version 4.0.0 was released, the `gawk' maintainer made the
POSIX rules the default, breaking well over a decade's worth of
backwards compatibility.(2) Needless to say, this was a bad idea, and
as of version 4.0.1, `gawk' resumed its historical behavior, and only
@@ -11403,7 +11860,7 @@ the `\' does not, as shown in *note table-gensub-escapes::.
`\\\\\\&' `\\\&' a literal `\&'
`\\q' `\q' a literal `q'
-Table 9.5: Escape Sequence Processing for `gensub()'
+Table 9.5: Escape Sequence Processing For `gensub()'
Because of the complexity of the lexical and runtime level processing
and the special cases for `sub()' and `gsub()', we recommend the use of
@@ -11977,8 +12434,9 @@ again with `10111001' and shift it left by three bits, you end up with
`11001000'. `gawk' provides built-in functions that implement the
bitwise operations just described. They are:
-`and(V1, V2)'
- Return the bitwise AND of the values provided by V1 and V2.
+`and(V1, V2 [, ...])'
+ Return the bitwise AND of the arguments. There must be at least
+ two.
`compl(VAL)'
Return the bitwise complement of VAL.
@@ -11986,14 +12444,15 @@ bitwise operations just described. They are:
`lshift(VAL, COUNT)'
Return the value of VAL, shifted left by COUNT bits.
-`or(V1, V2)'
- Return the bitwise OR of the values provided by V1 and V2.
+`or(V1, V2 [, ...])'
+ Return the bitwise OR of the arguments. There must be at least two.
`rshift(VAL, COUNT)'
Return the value of VAL, shifted right by COUNT bits.
-`xor(V1, V2)'
- Return the bitwise XOR of the values provided by V1 and V2.
+`xor(V1, V2 [, ...])'
+ Return the bitwise XOR of the arguments. There must be at least
+ two.
For all of these functions, first the double precision
floating-point value is converted to the widest C unsigned integer
@@ -12451,6 +12910,42 @@ that `i' is a local variable, not an argument):
foo's i=1
top's i=10
+ Besides scalar values (strings and numbers), you may also have local
+arrays. By using a parameter name as an array, `awk' treats it as an
+array, and it is local to the function. In addition, recursive calls
+create new arrays. Consider this example:
+
+ function some_func(p1, a)
+ {
+ if (p1++ > 3)
+ return
+
+ a[p1] = p1
+
+ some_func(p1)
+
+ printf("At level %d, index %d %s found in a\n",
+ p1, (p1 - 1), (p1 - 1) in a ? "is" : "is not")
+ printf("At level %d, index %d %s found in a\n",
+ p1, p1, p1 in a ? "is" : "is not")
+ print ""
+ }
+
+ BEGIN {
+ some_func(1)
+ }
+
+ When run, this program produces the following output:
+
+ At level 4, index 3 is not found in a
+ At level 4, index 4 is found in a
+
+ At level 3, index 2 is not found in a
+ At level 3, index 3 is found in a
+
+ At level 2, index 1 is not found in a
+ At level 2, index 2 is found in a
+

File: gawk.info, Node: Pass By Value/Reference, Prev: Variable Scope, Up: Function Caveats
@@ -12947,1440 +13442,9 @@ 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
-
-10 Internationalization with `gawk'
-***********************************
-
-Once upon a time, computer makers wrote software that worked only in
-English. Eventually, hardware and software vendors noticed that if
-their systems worked in the native languages of non-English-speaking
-countries, they were able to sell more systems. As a result,
-internationalization and localization of programs and software systems
-became a common practice.
-
- For many years, the ability to provide internationalization was
-largely restricted to programs written in C and C++. This major node
-describes the underlying library `gawk' uses for internationalization,
-as well as how `gawk' makes internationalization features available at
-the `awk' program level. Having internationalization available at the
-`awk' level gives software developers additional flexibility--they are
-no longer forced to write in C or C++ when internationalization is a
-requirement.
-
-* Menu:
-
-* I18N and L10N:: Internationalization and Localization.
-* Explaining gettext:: How GNU `gettext' works.
-* Programmer i18n:: Features for the programmer.
-* Translator i18n:: Features for the translator.
-* I18N Example:: A simple i18n example.
-* Gawk I18N:: `gawk' is also internationalized.
-
-
-File: gawk.info, Node: I18N and L10N, Next: Explaining gettext, Up: Internationalization
-
-10.1 Internationalization and Localization
-==========================================
-
-"Internationalization" means writing (or modifying) a program once, in
-such a way that it can use multiple languages without requiring further
-source-code changes. "Localization" means providing the data necessary
-for an internationalized program to work in a particular language.
-Most typically, these terms refer to features such as the language used
-for printing error messages, the language used to read responses, and
-information related to how numerical and monetary values are printed
-and read.
-
-
-File: gawk.info, Node: Explaining gettext, Next: Programmer i18n, Prev: I18N and L10N, Up: Internationalization
-
-10.2 GNU `gettext'
-==================
-
-The facilities in GNU `gettext' focus on messages; strings printed by a
-program, either directly or via formatting with `printf' or
-`sprintf()'.(1)
-
- When using GNU `gettext', each application has its own "text
-domain". This is a unique name, such as `kpilot' or `gawk', that
-identifies the application. A complete application may have multiple
-components--programs written in C or C++, as well as scripts written in
-`sh' or `awk'. All of the components use the same text domain.
-
- To make the discussion concrete, assume we're writing an application
-named `guide'. Internationalization consists of the following steps,
-in this order:
-
- 1. The programmer goes through the source for all of `guide''s
- components and marks each string that is a candidate for
- translation. For example, `"`-F': option required"' is a good
- candidate for translation. A table with strings of option names
- is not (e.g., `gawk''s `--profile' option should remain the same,
- no matter what the local language).
-
- 2. The programmer indicates the application's text domain (`"guide"')
- to the `gettext' library, by calling the `textdomain()' function.
-
- 3. Messages from the application are extracted from the source code
- and collected into a portable object template file (`guide.pot'),
- which lists the strings and their translations. The translations
- are initially empty. The original (usually English) messages
- serve as the key for lookup of the translations.
-
- 4. For each language with a translator, `guide.pot' is copied to a
- portable object file (`.po') and translations are created and
- shipped with the application. For example, there might be a
- `fr.po' for a French translation.
-
- 5. Each language's `.po' file is converted into a binary message
- object (`.mo') file. A message object file contains the original
- messages and their translations in a binary format that allows
- fast lookup of translations at runtime.
-
- 6. When `guide' is built and installed, the binary translation files
- are installed in a standard place.
-
- 7. For testing and development, it is possible to tell `gettext' to
- use `.mo' files in a different directory than the standard one by
- using the `bindtextdomain()' function.
-
- 8. At runtime, `guide' looks up each string via a call to
- `gettext()'. The returned string is the translated string if
- available, or the original string if not.
-
- 9. If necessary, it is possible to access messages from a different
- text domain than the one belonging to the application, without
- having to switch the application's default text domain back and
- forth.
-
- In C (or C++), the string marking and dynamic translation lookup are
-accomplished by wrapping each string in a call to `gettext()':
-
- printf("%s", gettext("Don't Panic!\n"));
-
- The tools that extract messages from source code pull out all
-strings enclosed in calls to `gettext()'.
-
- The GNU `gettext' developers, recognizing that typing `gettext(...)'
-over and over again is both painful and ugly to look at, use the macro
-`_' (an underscore) to make things easier:
-
- /* In the standard header file: */
- #define _(str) gettext(str)
-
- /* In the program text: */
- printf("%s", _("Don't Panic!\n"));
-
-This reduces the typing overhead to just three extra characters per
-string and is considerably easier to read as well.
-
- There are locale "categories" for different types of locale-related
-information. The defined locale categories that `gettext' knows about
-are:
-
-`LC_MESSAGES'
- Text messages. This is the default category for `gettext'
- operations, but it is possible to supply a different one
- explicitly, if necessary. (It is almost never necessary to supply
- a different category.)
-
-`LC_COLLATE'
- Text-collation information; i.e., how different characters and/or
- groups of characters sort in a given language.
-
-`LC_CTYPE'
- Character-type information (alphabetic, digit, upper- or
- lowercase, and so on). This information is accessed via the POSIX
- character classes in regular expressions, such as `/[[:alnum:]]/'
- (*note Regexp Operators::).
-
-`LC_MONETARY'
- Monetary information, such as the currency symbol, and whether the
- symbol goes before or after a number.
-
-`LC_NUMERIC'
- Numeric information, such as which characters to use for the
- decimal point and the thousands separator.(2)
-
-`LC_RESPONSE'
- Response information, such as how "yes" and "no" appear in the
- local language, and possibly other information as well.
-
-`LC_TIME'
- Time- and date-related information, such as 12- or 24-hour clock,
- month printed before or after the day in a date, local month
- abbreviations, and so on.
-
-`LC_ALL'
- All of the above. (Not too useful in the context of `gettext'.)
-
- ---------- Footnotes ----------
-
- (1) For some operating systems, the `gawk' port doesn't support GNU
-`gettext'. Therefore, these features are not available if you are
-using one of those operating systems. Sorry.
-
- (2) Americans use a comma every three decimal places and a period
-for the decimal point, while many Europeans do exactly the opposite:
-1,234.56 versus 1.234,56.
-
-
-File: gawk.info, Node: Programmer i18n, Next: Translator i18n, Prev: Explaining gettext, Up: Internationalization
-
-10.3 Internationalizing `awk' Programs
-======================================
-
-`gawk' provides the following variables and functions for
-internationalization:
-
-`TEXTDOMAIN'
- This variable indicates the application's text domain. For
- compatibility with GNU `gettext', the default value is
- `"messages"'.
-
-`_"your message here"'
- String constants marked with a leading underscore are candidates
- for translation at runtime. String constants without a leading
- underscore are not translated.
-
-`dcgettext(STRING [, DOMAIN [, CATEGORY]])'
- Return the translation of STRING in text domain DOMAIN for locale
- category CATEGORY. The default value for DOMAIN is the current
- value of `TEXTDOMAIN'. The default value for CATEGORY is
- `"LC_MESSAGES"'.
-
- If you supply a value for CATEGORY, it must be a string equal to
- one of the known locale categories described in *note Explaining
- gettext::. You must also supply a text domain. Use `TEXTDOMAIN'
- if you want to use the current domain.
-
- CAUTION: The order of arguments to the `awk' version of the
- `dcgettext()' function is purposely different from the order
- for the C version. The `awk' version's order was chosen to
- be simple and to allow for reasonable `awk'-style default
- arguments.
-
-`dcngettext(STRING1, STRING2, NUMBER [, DOMAIN [, CATEGORY]])'
- Return the plural form used for NUMBER of the translation of
- STRING1 and STRING2 in text domain DOMAIN for locale category
- CATEGORY. STRING1 is the English singular variant of a message,
- and STRING2 the English plural variant of the same message. The
- default value for DOMAIN is the current value of `TEXTDOMAIN'.
- The default value for CATEGORY is `"LC_MESSAGES"'.
-
- The same remarks about argument order as for the `dcgettext()'
- function apply.
-
-`bindtextdomain(DIRECTORY [, DOMAIN])'
- Change the directory in which `gettext' looks for `.mo' files, in
- case they will not or cannot be placed in the standard locations
- (e.g., during testing). Return the directory in which DOMAIN is
- "bound."
-
- The default DOMAIN is the value of `TEXTDOMAIN'. If DIRECTORY is
- the null string (`""'), then `bindtextdomain()' returns the
- current binding for the given DOMAIN.
-
- To use these facilities in your `awk' program, follow the steps
-outlined in *note Explaining gettext::, like so:
-
- 1. Set the variable `TEXTDOMAIN' to the text domain of your program.
- This is best done in a `BEGIN' rule (*note BEGIN/END::), or it can
- also be done via the `-v' command-line option (*note Options::):
-
- BEGIN {
- TEXTDOMAIN = "guide"
- ...
- }
-
- 2. Mark all translatable strings with a leading underscore (`_')
- character. It _must_ be adjacent to the opening quote of the
- string. For example:
-
- print _"hello, world"
- x = _"you goofed"
- printf(_"Number of users is %d\n", nusers)
-
- 3. If you are creating strings dynamically, you can still translate
- them, using the `dcgettext()' built-in function:
-
- message = nusers " users logged in"
- message = dcgettext(message, "adminprog")
- print message
-
- Here, the call to `dcgettext()' supplies a different text domain
- (`"adminprog"') in which to find the message, but it uses the
- default `"LC_MESSAGES"' category.
-
- 4. During development, you might want to put the `.mo' file in a
- private directory for testing. This is done with the
- `bindtextdomain()' built-in function:
-
- BEGIN {
- TEXTDOMAIN = "guide" # our text domain
- if (Testing) {
- # where to find our files
- bindtextdomain("testdir")
- # joe is in charge of adminprog
- bindtextdomain("../joe/testdir", "adminprog")
- }
- ...
- }
-
-
- *Note I18N Example::, for an example program showing the steps to
-create and use translations from `awk'.
-
-
-File: gawk.info, Node: Translator i18n, Next: I18N Example, Prev: Programmer i18n, Up: Internationalization
-
-10.4 Translating `awk' Programs
-===============================
-
-Once a program's translatable strings have been marked, they must be
-extracted to create the initial `.po' file. As part of translation, it
-is often helpful to rearrange the order in which arguments to `printf'
-are output.
-
- `gawk''s `--gen-pot' command-line option extracts the messages and
-is discussed next. After that, `printf''s ability to rearrange the
-order for `printf' arguments at runtime is covered.
-
-* Menu:
-
-* String Extraction:: Extracting marked strings.
-* Printf Ordering:: Rearranging `printf' arguments.
-* I18N Portability:: `awk'-level portability issues.
-
-
-File: gawk.info, Node: String Extraction, Next: Printf Ordering, Up: Translator i18n
-
-10.4.1 Extracting Marked Strings
---------------------------------
-
-Once your `awk' program is working, and all the strings have been
-marked and you've set (and perhaps bound) the text domain, it is time
-to produce translations. First, use the `--gen-pot' command-line
-option to create the initial `.pot' file:
-
- $ gawk --gen-pot -f guide.awk > guide.pot
-
- When run with `--gen-pot', `gawk' does not execute your program.
-Instead, it parses it as usual and prints all marked strings to
-standard output in the format of a GNU `gettext' Portable Object file.
-Also included in the output are any constant strings that appear as the
-first argument to `dcgettext()' or as the first and second argument to
-`dcngettext()'.(1) *Note I18N Example::, for the full list of steps to
-go through to create and test translations for `guide'.
-
- ---------- Footnotes ----------
-
- (1) The `xgettext' utility that comes with GNU `gettext' can handle
-`.awk' files.
-
-
-File: gawk.info, Node: Printf Ordering, Next: I18N Portability, Prev: String Extraction, Up: Translator i18n
-
-10.4.2 Rearranging `printf' Arguments
--------------------------------------
-
-Format strings for `printf' and `sprintf()' (*note Printf::) present a
-special problem for translation. Consider the following:(1)
-
- printf(_"String `%s' has %d characters\n",
- string, length(string)))
-
- A possible German translation for this might be:
-
- "%d Zeichen lang ist die Zeichenkette `%s'\n"
-
- The problem should be obvious: the order of the format
-specifications is different from the original! Even though `gettext()'
-can return the translated string at runtime, it cannot change the
-argument order in the call to `printf'.
-
- To solve this problem, `printf' format specifiers may have an
-additional optional element, which we call a "positional specifier".
-For example:
-
- "%2$d Zeichen lang ist die Zeichenkette `%1$s'\n"
-
- Here, the positional specifier consists of an integer count, which
-indicates which argument to use, and a `$'. Counts are one-based, and
-the format string itself is _not_ included. Thus, in the following
-example, `string' is the first argument and `length(string)' is the
-second:
-
- $ gawk 'BEGIN {
- > string = "Dont Panic"
- > printf _"%2$d characters live in \"%1$s\"\n",
- > string, length(string)
- > }'
- -| 10 characters live in "Dont Panic"
-
- If present, positional specifiers come first in the format
-specification, before the flags, the field width, and/or the precision.
-
- Positional specifiers can be used with the dynamic field width and
-precision capability:
-
- $ gawk 'BEGIN {
- > printf("%*.*s\n", 10, 20, "hello")
- > printf("%3$*2$.*1$s\n", 20, 10, "hello")
- > }'
- -| hello
- -| hello
-
- NOTE: When using `*' with a positional specifier, the `*' comes
- first, then the integer position, and then the `$'. This is
- somewhat counterintuitive.
-
- `gawk' does not allow you to mix regular format specifiers and those
-with positional specifiers in the same string:
-
- $ gawk 'BEGIN { printf _"%d %3$s\n", 1, 2, "hi" }'
- error--> gawk: cmd. line:1: fatal: must use `count$' on all formats or none
-
- NOTE: There are some pathological cases that `gawk' may fail to
- diagnose. In such cases, the output may not be what you expect.
- It's still a bad idea to try mixing them, even if `gawk' doesn't
- detect it.
-
- Although positional specifiers can be used directly in `awk'
-programs, their primary purpose is to help in producing correct
-translations of format strings into languages different from the one in
-which the program is first written.
-
- ---------- Footnotes ----------
-
- (1) This example is borrowed from the GNU `gettext' manual.
-
-
-File: gawk.info, Node: I18N Portability, Prev: Printf Ordering, Up: Translator i18n
-
-10.4.3 `awk' Portability Issues
--------------------------------
-
-`gawk''s internationalization features were purposely chosen to have as
-little impact as possible on the portability of `awk' programs that use
-them to other versions of `awk'. Consider this program:
-
- BEGIN {
- TEXTDOMAIN = "guide"
- if (Test_Guide) # set with -v
- bindtextdomain("/test/guide/messages")
- print _"don't panic!"
- }
-
-As written, it won't work on other versions of `awk'. However, it is
-actually almost portable, requiring very little change:
-
- * Assignments to `TEXTDOMAIN' won't have any effect, since
- `TEXTDOMAIN' is not special in other `awk' implementations.
-
- * Non-GNU versions of `awk' treat marked strings as the
- concatenation of a variable named `_' with the string following
- it.(1) Typically, the variable `_' has the null string (`""') as
- its value, leaving the original string constant as the result.
-
- * By defining "dummy" functions to replace `dcgettext()',
- `dcngettext()' and `bindtextdomain()', the `awk' program can be
- made to run, but all the messages are output in the original
- language. For example:
-
- function bindtextdomain(dir, domain)
- {
- return dir
- }
-
- function dcgettext(string, domain, category)
- {
- return string
- }
-
- function dcngettext(string1, string2, number, domain, category)
- {
- return (number == 1 ? string1 : string2)
- }
-
- * The use of positional specifications in `printf' or `sprintf()' is
- _not_ portable. To support `gettext()' at the C level, many
- systems' C versions of `sprintf()' do support positional
- specifiers. But it works only if enough arguments are supplied in
- the function call. Many versions of `awk' pass `printf' formats
- and arguments unchanged to the underlying C library version of
- `sprintf()', but only one format and argument at a time. What
- happens if a positional specification is used is anybody's guess.
- However, since the positional specifications are primarily for use
- in _translated_ format strings, and since non-GNU `awk's never
- retrieve the translated string, this should not be a problem in
- practice.
-
- ---------- Footnotes ----------
-
- (1) This is good fodder for an "Obfuscated `awk'" contest.
-
-
-File: gawk.info, Node: I18N Example, Next: Gawk I18N, Prev: Translator i18n, Up: Internationalization
-
-10.5 A Simple Internationalization Example
-==========================================
-
-Now let's look at a step-by-step example of how to internationalize and
-localize a simple `awk' program, using `guide.awk' as our original
-source:
-
- BEGIN {
- TEXTDOMAIN = "guide"
- bindtextdomain(".") # for testing
- print _"Don't Panic"
- print _"The Answer Is", 42
- print "Pardon me, Zaphod who?"
- }
-
-Run `gawk --gen-pot' to create the `.pot' file:
-
- $ gawk --gen-pot -f guide.awk > guide.pot
-
-This produces:
-
- #: guide.awk:4
- msgid "Don't Panic"
- msgstr ""
-
- #: guide.awk:5
- msgid "The Answer Is"
- msgstr ""
-
- This original portable object template file is saved and reused for
-each language into which the application is translated. The `msgid' is
-the original string and the `msgstr' is the translation.
-
- NOTE: Strings not marked with a leading underscore do not appear
- in the `guide.pot' file.
-
- Next, the messages must be translated. Here is a translation to a
-hypothetical dialect of English, called "Mellow":(1)
-
- $ cp guide.pot guide-mellow.po
- ADD TRANSLATIONS TO guide-mellow.po ...
-
-Following are the translations:
-
- #: guide.awk:4
- msgid "Don't Panic"
- msgstr "Hey man, relax!"
-
- #: guide.awk:5
- msgid "The Answer Is"
- msgstr "Like, the scoop is"
-
- The next step is to make the directory to hold the binary message
-object file and then to create the `guide.mo' file. The directory
-layout shown here is standard for GNU `gettext' on GNU/Linux systems.
-Other versions of `gettext' may use a different layout:
-
- $ mkdir en_US en_US/LC_MESSAGES
-
- The `msgfmt' utility does the conversion from human-readable `.po'
-file to machine-readable `.mo' file. By default, `msgfmt' creates a
-file named `messages'. This file must be renamed and placed in the
-proper directory so that `gawk' can find it:
-
- $ msgfmt guide-mellow.po
- $ mv messages en_US/LC_MESSAGES/guide.mo
-
- Finally, we run the program to test it:
-
- $ gawk -f guide.awk
- -| Hey man, relax!
- -| Like, the scoop is 42
- -| Pardon me, Zaphod who?
-
- If the three replacement functions for `dcgettext()', `dcngettext()'
-and `bindtextdomain()' (*note I18N Portability::) are in a file named
-`libintl.awk', then we can run `guide.awk' unchanged as follows:
-
- $ gawk --posix -f guide.awk -f libintl.awk
- -| Don't Panic
- -| The Answer Is 42
- -| Pardon me, Zaphod who?
-
- ---------- Footnotes ----------
-
- (1) Perhaps it would be better if it were called "Hippy." Ah, well.
-
-
-File: gawk.info, Node: Gawk I18N, Prev: I18N Example, Up: Internationalization
-
-10.6 `gawk' Can Speak Your Language
-===================================
-
-`gawk' itself has been internationalized using the GNU `gettext'
-package. (GNU `gettext' is described in complete detail in *note (GNU
-`gettext' utilities)Top:: gettext, GNU gettext tools.) As of this
-writing, the latest version of GNU `gettext' is version 0.18.1
-(ftp://ftp.gnu.org/gnu/gettext/gettext-0.18.1.tar.gz).
-
- If a translation of `gawk''s messages exists, then `gawk' produces
-usage messages, warnings, and fatal errors in the local language.
-
-
-File: gawk.info, Node: Advanced Features, Next: Library Functions, Prev: Internationalization, Up: Top
-
-11 Advanced Features of `gawk'
-******************************
-
- Write documentation as if whoever reads it is a violent psychopath
- who knows where you live.
- Steve English, as quoted by Peter Langston
-
- This major node discusses advanced features in `gawk'. It's a bit
-of a "grab bag" of items that are otherwise unrelated to each other.
-First, a command-line option allows `gawk' to recognize nondecimal
-numbers in input data, not just in `awk' programs. Then, `gawk''s
-special features for sorting arrays are presented. Next, two-way I/O,
-discussed briefly in earlier parts of this Info file, is described in
-full detail, along with the basics of TCP/IP networking. Finally,
-`gawk' can "profile" an `awk' program, making it possible to tune it
-for performance.
-
- *note Dynamic Extensions::, discusses the ability to dynamically add
-new built-in functions to `gawk'. As this feature is still immature
-and likely to change, its description is relegated to an appendix.
-
-* Menu:
-
-* Nondecimal Data:: Allowing nondecimal input data.
-* Array Sorting:: Facilities for controlling array traversal and
- sorting arrays.
-* Two-way I/O:: Two-way communications with another process.
-* TCP/IP Networking:: Using `gawk' for network programming.
-* Profiling:: Profiling your `awk' programs.
-
-
-File: gawk.info, Node: Nondecimal Data, Next: Array Sorting, Up: Advanced Features
-
-11.1 Allowing Nondecimal Input Data
-===================================
-
-If you run `gawk' with the `--non-decimal-data' option, you can have
-nondecimal constants in your input data:
-
- $ echo 0123 123 0x123 |
- > gawk --non-decimal-data '{ printf "%d, %d, %d\n",
- > $1, $2, $3 }'
- -| 83, 123, 291
-
- For this feature to work, write your program so that `gawk' treats
-your data as numeric:
-
- $ echo 0123 123 0x123 | gawk '{ print $1, $2, $3 }'
- -| 0123 123 0x123
-
-The `print' statement treats its expressions as strings. Although the
-fields can act as numbers when necessary, they are still strings, so
-`print' does not try to treat them numerically. You may need to add
-zero to a field to force it to be treated as a number. For example:
-
- $ echo 0123 123 0x123 | gawk --non-decimal-data '
- > { print $1, $2, $3
- > print $1 + 0, $2 + 0, $3 + 0 }'
- -| 0123 123 0x123
- -| 83 123 291
-
- Because it is common to have decimal data with leading zeros, and
-because using this facility could lead to surprising results, the
-default is to leave it disabled. If you want it, you must explicitly
-request it.
-
- CAUTION: _Use of this option is not recommended._ It can break old
- programs very badly. Instead, use the `strtonum()' function to
- convert your data (*note Nondecimal-numbers::). This makes your
- programs easier to write and easier to read, and leads to less
- surprising results.
-
-
-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
-==================================================
-
-`gawk' lets you control the order in which a `for (i in array)' loop
-traverses an array.
-
- In addition, two built-in functions, `asort()' and `asorti()', let
-you sort arrays based on the array values and indices, respectively.
-These two functions also provide control over the sorting criteria used
-to order the elements during sorting.
-
-* Menu:
-
-* Controlling Array Traversal:: How to use PROCINFO["sorted_in"].
-* Array Sorting Functions:: How to use `asort()' and `asorti()'.
-
-
-File: gawk.info, Node: Controlling Array Traversal, Next: Array Sorting Functions, Up: Array Sorting
-
-11.2.1 Controlling Array Traversal
-----------------------------------
-
-By default, the order in which a `for (i in array)' loop scans an array
-is not defined; it is generally based upon the internal implementation
-of arrays inside `awk'.
-
- Often, though, it is desirable to be able to loop over the elements
-in a particular order that you, the programmer, choose. `gawk' lets
-you do this.
-
- *note Controlling Scanning::, describes how you can assign special,
-pre-defined values to `PROCINFO["sorted_in"]' in order to control the
-order in which `gawk' will traverse an array during a `for' loop.
-
- In addition, the value of `PROCINFO["sorted_in"]' can be a function
-name. This lets you traverse an array based on any custom criterion.
-The array elements are ordered according to the return value of this
-function. The comparison function should be defined with at least four
-arguments:
-
- function comp_func(i1, v1, i2, v2)
- {
- COMPARE ELEMENTS 1 AND 2 IN SOME FASHION
- RETURN < 0; 0; OR > 0
- }
-
- Here, I1 and I2 are the indices, and V1 and V2 are the corresponding
-values of the two elements being compared. Either V1 or V2, or both,
-can be arrays if the array being traversed contains subarrays as values.
-(*Note Arrays of Arrays::, for more information about subarrays.) The
-three possible return values are interpreted as follows:
-
-`comp_func(i1, v1, i2, v2) < 0'
- Index I1 comes before index I2 during loop traversal.
-
-`comp_func(i1, v1, i2, v2) == 0'
- Indices I1 and I2 come together but the relative order with
- respect to each other is undefined.
-
-`comp_func(i1, v1, i2, v2) > 0'
- Index I1 comes after index I2 during loop traversal.
-
- Our first comparison function can be used to scan an array in
-numerical order of the indices:
-
- function cmp_num_idx(i1, v1, i2, v2)
- {
- # numerical index comparison, ascending order
- return (i1 - i2)
- }
-
- Our second function traverses an array based on the string order of
-the element values rather than by indices:
-
- function cmp_str_val(i1, v1, i2, v2)
- {
- # string value comparison, ascending order
- v1 = v1 ""
- v2 = v2 ""
- if (v1 < v2)
- return -1
- return (v1 != v2)
- }
-
- The third comparison function makes all numbers, and numeric strings
-without any leading or trailing spaces, come out first during loop
-traversal:
-
- function cmp_num_str_val(i1, v1, i2, v2, n1, n2)
- {
- # numbers before string value comparison, ascending order
- n1 = v1 + 0
- n2 = v2 + 0
- if (n1 == v1)
- return (n2 == v2) ? (n1 - n2) : -1
- else if (n2 == v2)
- return 1
- return (v1 < v2) ? -1 : (v1 != v2)
- }
-
- Here is a main program to demonstrate how `gawk' behaves using each
-of the previous functions:
-
- BEGIN {
- data["one"] = 10
- data["two"] = 20
- data[10] = "one"
- data[100] = 100
- data[20] = "two"
-
- f[1] = "cmp_num_idx"
- f[2] = "cmp_str_val"
- f[3] = "cmp_num_str_val"
- for (i = 1; i <= 3; i++) {
- printf("Sort function: %s\n", f[i])
- PROCINFO["sorted_in"] = f[i]
- for (j in data)
- printf("\tdata[%s] = %s\n", j, data[j])
- print ""
- }
- }
-
- Here are the results when the program is run:
-
- $ gawk -f compdemo.awk
- -| Sort function: cmp_num_idx Sort by numeric index
- -| data[two] = 20
- -| data[one] = 10 Both strings are numerically zero
- -| data[10] = one
- -| data[20] = two
- -| data[100] = 100
- -|
- -| Sort function: cmp_str_val Sort by element values as strings
- -| data[one] = 10
- -| data[100] = 100 String 100 is less than string 20
- -| data[two] = 20
- -| data[10] = one
- -| data[20] = two
- -|
- -| Sort function: cmp_num_str_val Sort all numeric values before all strings
- -| data[one] = 10
- -| data[two] = 20
- -| data[100] = 100
- -| data[10] = one
- -| data[20] = two
-
- Consider sorting the entries of a GNU/Linux system password file
-according to login name. The following program sorts records by a
-specific field position and can be used for this purpose:
-
- # sort.awk --- simple program to sort by field position
- # field position is specified by the global variable POS
-
- function cmp_field(i1, v1, i2, v2)
- {
- # comparison by value, as string, and ascending order
- return v1[POS] < v2[POS] ? -1 : (v1[POS] != v2[POS])
- }
-
- {
- for (i = 1; i <= NF; i++)
- a[NR][i] = $i
- }
-
- END {
- PROCINFO["sorted_in"] = "cmp_field"
- if (POS < 1 || POS > NF)
- POS = 1
- for (i in a) {
- for (j = 1; j <= NF; j++)
- printf("%s%c", a[i][j], j < NF ? ":" : "")
- print ""
- }
- }
-
- The first field in each entry of the password file is the user's
-login name, and the fields are separated by colons. Each record
-defines a subarray, with each field as an element in the subarray.
-Running the program produces the following output:
-
- $ gawk -vPOS=1 -F: -f sort.awk /etc/passwd
- -| adm:x:3:4:adm:/var/adm:/sbin/nologin
- -| apache:x:48:48:Apache:/var/www:/sbin/nologin
- -| avahi:x:70:70:Avahi daemon:/:/sbin/nologin
- ...
-
- The comparison should normally always return the same value when
-given a specific pair of array elements as its arguments. If
-inconsistent results are returned then the order is undefined. This
-behavior can be exploited to introduce random order into otherwise
-seemingly ordered data:
-
- function cmp_randomize(i1, v1, i2, v2)
- {
- # random order
- return (2 - 4 * rand())
- }
-
- As mentioned above, the order of the indices is arbitrary if two
-elements compare equal. This is usually not a problem, but letting the
-tied elements come out in arbitrary order can be an issue, especially
-when comparing item values. The partial ordering of the equal elements
-may change during the next loop traversal, if other elements are added
-or removed from the array. One way to resolve ties when comparing
-elements with otherwise equal values is to include the indices in the
-comparison rules. Note that doing this may make the loop traversal
-less efficient, so consider it only if necessary. The following
-comparison functions force a deterministic order, and are based on the
-fact that the indices of two elements are never equal:
-
- function cmp_numeric(i1, v1, i2, v2)
- {
- # numerical value (and index) comparison, descending order
- return (v1 != v2) ? (v2 - v1) : (i2 - i1)
- }
-
- function cmp_string(i1, v1, i2, v2)
- {
- # string value (and index) comparison, descending order
- v1 = v1 i1
- v2 = v2 i2
- return (v1 > v2) ? -1 : (v1 != v2)
- }
-
- A custom comparison function can often simplify ordered loop
-traversal, and the sky is really the limit when it comes to designing
-such a function.
-
- When string comparisons are made during a sort, either for element
-values where one or both aren't numbers, or for element indices handled
-as strings, the value of `IGNORECASE' (*note Built-in Variables::)
-controls whether the comparisons treat corresponding uppercase and
-lowercase letters as equivalent or distinct.
-
- Another point to keep in mind is that in the case of subarrays the
-element values can themselves be arrays; a production comparison
-function should use the `isarray()' function (*note Type Functions::),
-to check for this, and choose a defined sorting order for subarrays.
-
- All sorting based on `PROCINFO["sorted_in"]' is disabled in POSIX
-mode, since the `PROCINFO' array is not special in that case.
-
- As a side note, sorting the array indices before traversing the
-array has been reported to add 15% to 20% overhead to the execution
-time of `awk' programs. For this reason, sorted array traversal is not
-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'
----------------------------------------------------
-
-In most `awk' implementations, sorting an array requires writing a
-`sort()' function. While this can be educational for exploring
-different sorting algorithms, usually that's not the point of the
-program. `gawk' provides the built-in `asort()' and `asorti()'
-functions (*note String Functions::) for sorting arrays. For example:
-
- POPULATE THE ARRAY data
- n = asort(data)
- for (i = 1; i <= n; i++)
- DO SOMETHING WITH data[i]
-
- After the call to `asort()', the array `data' is indexed from 1 to
-some number N, the total number of elements in `data'. (This count is
-`asort()''s return value.) `data[1]' <= `data[2]' <= `data[3]', and so
-on. The comparison is based on the type of the elements (*note Typing
-and Comparison::). All numeric values come before all string values,
-which in turn come before all subarrays.
-
- An important side effect of calling `asort()' is that _the array's
-original indices are irrevocably lost_. As this isn't always
-desirable, `asort()' accepts a second argument:
-
- POPULATE THE ARRAY source
- n = asort(source, dest)
- for (i = 1; i <= n; i++)
- DO SOMETHING WITH dest[i]
-
- In this case, `gawk' copies the `source' array into the `dest' array
-and then sorts `dest', destroying its indices. However, the `source'
-array is not affected.
-
- `asort()' accepts a third string argument to control comparison of
-array elements. As with `PROCINFO["sorted_in"]', this argument may be
-one of the predefined names that `gawk' provides (*note Controlling
-Scanning::), or the name of a user-defined function (*note Controlling
-Array Traversal::).
-
- NOTE: In all cases, the sorted element values consist of the
- original array's element values. The ability to control
- comparison merely affects the way in which they are sorted.
-
- Often, what's needed is to sort on the values of the _indices_
-instead of the values of the elements. To do that, use the `asorti()'
-function. The interface is identical to that of `asort()', except that
-the index values are used for sorting, and become the values of the
-result array:
-
- { source[$0] = some_func($0) }
-
- END {
- n = asorti(source, dest)
- for (i = 1; i <= n; i++) {
- Work with sorted indices directly:
- DO SOMETHING WITH dest[i]
- ...
- Access original array via sorted indices:
- DO SOMETHING WITH source[dest[i]]
- }
- }
-
- Similar to `asort()', in all cases, the sorted element values
-consist of the original array's indices. The ability to control
-comparison merely affects the way in which they are sorted.
-
- Sorting the array by replacing the indices provides maximal
-flexibility. To traverse the elements in decreasing order, use a loop
-that goes from N down to 1, either over the elements or over the
-indices.(1)
-
- Copying array indices and elements isn't expensive in terms of
-memory. Internally, `gawk' maintains "reference counts" to data. For
-example, when `asort()' copies the first array to the second one, there
-is only one copy of the original array elements' data, even though both
-arrays use the values.
-
- Because `IGNORECASE' affects string comparisons, the value of
-`IGNORECASE' also affects sorting for both `asort()' and `asorti()'.
-Note also that the locale's sorting order does _not_ come into play;
-comparisons are based on character values only.(2) Caveat Emptor.
-
- ---------- Footnotes ----------
-
- (1) You may also use one of the predefined sorting names that sorts
-in decreasing order.
-
- (2) This is true because locale-based comparison occurs only when in
-POSIX compatibility mode, and since `asort()' and `asorti()' are `gawk'
-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
-================================================
-
- From: brennan@whidbey.com (Mike Brennan)
- Newsgroups: comp.lang.awk
- Subject: Re: Learn the SECRET to Attract Women Easily
- Date: 4 Aug 1997 17:34:46 GMT
- Message-ID: <5s53rm$eca@news.whidbey.com>
-
- On 3 Aug 1997 13:17:43 GMT, Want More Dates???
- <tracy78@kilgrona.com> wrote:
- >Learn the SECRET to Attract Women Easily
- >
- >The SCENT(tm) Pheromone Sex Attractant For Men to Attract Women
-
- The scent of awk programmers is a lot more attractive to women than
- the scent of perl programmers.
- --
- Mike Brennan
-
- It is often useful to be able to send data to a separate program for
-processing and then read the result. This can always be done with
-temporary files:
-
- # Write the data for processing
- tempfile = ("mydata." PROCINFO["pid"])
- while (NOT DONE WITH DATA)
- print DATA | ("subprogram > " tempfile)
- close("subprogram > " tempfile)
-
- # Read the results, remove tempfile when done
- while ((getline newdata < tempfile) > 0)
- PROCESS newdata APPROPRIATELY
- close(tempfile)
- system("rm " tempfile)
-
-This works, but not elegantly. Among other things, it requires that
-the program be run in a directory that cannot be shared among users;
-for example, `/tmp' will not do, as another user might happen to be
-using a temporary file with the same name.
-
- However, with `gawk', it is possible to open a _two-way_ pipe to
-another process. The second process is termed a "coprocess", since it
-runs in parallel with `gawk'. The two-way connection is created using
-the `|&' operator (borrowed from the Korn shell, `ksh'):(1)
-
- do {
- print DATA |& "subprogram"
- "subprogram" |& getline results
- } while (DATA LEFT TO PROCESS)
- close("subprogram")
-
- The first time an I/O operation is executed using the `|&' operator,
-`gawk' creates a two-way pipeline to a child process that runs the
-other program. Output created with `print' or `printf' is written to
-the program's standard input, and output from the program's standard
-output can be read by the `gawk' program using `getline'. As is the
-case with processes started by `|', the subprogram can be any program,
-or pipeline of programs, that can be started by the shell.
-
- There are some cautionary items to be aware of:
-
- * As the code inside `gawk' currently stands, the coprocess's
- standard error goes to the same place that the parent `gawk''s
- standard error goes. It is not possible to read the child's
- standard error separately.
-
- * I/O buffering may be a problem. `gawk' automatically flushes all
- output down the pipe to the coprocess. However, if the coprocess
- does not flush its output, `gawk' may hang when doing a `getline'
- in order to read the coprocess's results. This could lead to a
- situation known as "deadlock", where each process is waiting for
- the other one to do something.
-
- It is possible to close just one end of the two-way pipe to a
-coprocess, by supplying a second argument to the `close()' function of
-either `"to"' or `"from"' (*note Close Files And Pipes::). These
-strings tell `gawk' to close the end of the pipe that sends data to the
-coprocess or the end that reads from it, respectively.
-
- This is particularly necessary in order to use the system `sort'
-utility as part of a coprocess; `sort' must read _all_ of its input
-data before it can produce any output. The `sort' program does not
-receive an end-of-file indication until `gawk' closes the write end of
-the pipe.
-
- When you have finished writing data to the `sort' utility, you can
-close the `"to"' end of the pipe, and then start reading sorted data
-via `getline'. For example:
-
- BEGIN {
- command = "LC_ALL=C sort"
- n = split("abcdefghijklmnopqrstuvwxyz", a, "")
-
- for (i = n; i > 0; i--)
- print a[i] |& command
- close(command, "to")
-
- while ((command |& getline line) > 0)
- print "got", line
- close(command)
- }
-
- This program writes the letters of the alphabet in reverse order, one
-per line, down the two-way pipe to `sort'. It then closes the write
-end of the pipe, so that `sort' receives an end-of-file indication.
-This causes `sort' to sort the data and write the sorted data back to
-the `gawk' program. Once all of the data has been read, `gawk'
-terminates the coprocess and exits.
-
- As a side note, the assignment `LC_ALL=C' in the `sort' command
-ensures traditional Unix (ASCII) sorting from `sort'.
-
- You may also use pseudo-ttys (ptys) for two-way communication
-instead of pipes, if your system supports them. This is done on a
-per-command basis, by setting a special element in the `PROCINFO' array
-(*note Auto-set::), like so:
-
- command = "sort -nr" # command, save in convenience variable
- PROCINFO[command, "pty"] = 1 # update PROCINFO
- print ... |& command # start two-way pipe
- ...
-
-Using ptys avoids the buffer deadlock issues described earlier, at some
-loss in performance. If your system does not have ptys, or if all the
-system's ptys are in use, `gawk' automatically falls back to using
-regular pipes.
-
- ---------- Footnotes ----------
-
- (1) This is very different from the same operator in the C shell.
-
-
-File: gawk.info, Node: TCP/IP Networking, Next: Profiling, Prev: Two-way I/O, Up: Advanced Features
-
-11.4 Using `gawk' for Network Programming
-=========================================
-
- `EMISTERED':
- A host is a host from coast to coast,
- and no-one can talk to host that's close,
- unless the host that isn't close
- is busy hung or dead.
-
- In addition to being able to open a two-way pipeline to a coprocess
-on the same system (*note Two-way I/O::), it is possible to make a
-two-way connection to another process on another system across an IP
-network connection.
-
- You can think of this as just a _very long_ two-way pipeline to a
-coprocess. The way `gawk' decides that you want to use TCP/IP
-networking is by recognizing special file names that begin with one of
-`/inet/', `/inet4/' or `/inet6'.
-
- The full syntax of the special file name is
-`/NET-TYPE/PROTOCOL/LOCAL-PORT/REMOTE-HOST/REMOTE-PORT'. The
-components are:
-
-NET-TYPE
- Specifies the kind of Internet connection to make. Use `/inet4/'
- to force IPv4, and `/inet6/' to force IPv6. Plain `/inet/' (which
- used to be the only option) uses the system default, most likely
- IPv4.
-
-PROTOCOL
- The protocol to use over IP. This must be either `tcp', or `udp',
- for a TCP or UDP IP connection, respectively. The use of TCP is
- recommended for most applications.
-
-LOCAL-PORT
- The local TCP or UDP port number to use. Use a port number of `0'
- when you want the system to pick a port. This is what you should do
- when writing a TCP or UDP client. You may also use a well-known
- service name, such as `smtp' or `http', in which case `gawk'
- attempts to determine the predefined port number using the C
- `getaddrinfo()' function.
-
-REMOTE-HOST
- The IP address or fully-qualified domain name of the Internet host
- to which you want to connect.
-
-REMOTE-PORT
- The TCP or UDP port number to use on the given REMOTE-HOST.
- Again, use `0' if you don't care, or else a well-known service
- name.
-
- NOTE: Failure in opening a two-way socket will result in a
- non-fatal error being returned to the calling code. The value of
- `ERRNO' indicates the error (*note Auto-set::).
-
- Consider the following very simple example:
-
- BEGIN {
- Service = "/inet/tcp/0/localhost/daytime"
- Service |& getline
- print $0
- close(Service)
- }
-
- This program reads the current date and time from the local system's
-TCP `daytime' server. It then prints the results and closes the
-connection.
-
- Because this topic is extensive, the use of `gawk' for TCP/IP
-programming is documented separately. See *note (General
-Introduction)Top:: gawkinet, TCP/IP Internetworking with `gawk', for a
-much more complete introduction and discussion, as well as extensive
-examples.
-
-
-File: gawk.info, Node: Profiling, Prev: TCP/IP Networking, Up: Advanced Features
-
-11.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%
-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:
-
- pgawk --profile=myprog.prof -f myprog.awk data1 data2
-
-In the above example, `pgawk' 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:
-
- BEGIN { print "First BEGIN rule" }
-
- END { print "First END rule" }
-
- /foo/ {
- print "matched /foo/, gosh"
- for (i = 1; i <= 3; i++)
- sing()
- }
-
- {
- if (/foo/)
- print "if is true"
- else
- print "else is true"
- }
-
- BEGIN { print "Second BEGIN rule" }
-
- END { print "Second END rule" }
-
- function sing( dummy)
- {
- print "I gotta be me!"
- }
-
- Following is the input data:
-
- foo
- bar
- baz
- 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):
-
- # gawk profile, created Sun Aug 13 00:00:15 2000
-
- # BEGIN block(s)
-
- BEGIN {
- 1 print "First BEGIN rule"
- 1 print "Second BEGIN rule"
- }
-
- # Rule(s)
-
- 5 /foo/ { # 2
- 2 print "matched /foo/, gosh"
- 6 for (i = 1; i <= 3; i++) {
- 6 sing()
- }
- }
-
- 5 {
- 5 if (/foo/) { # 2
- 2 print "if is true"
- 3 } else {
- 3 print "else is true"
- }
- }
-
- # END block(s)
-
- END {
- 1 print "First END rule"
- 1 print "Second END rule"
- }
-
- # Functions, listed alphabetically
-
- 6 function sing(dummy)
- {
- 6 print "I gotta be me!"
- }
-
- This example illustrates many of the basic features of profiling
-output. They are as follows:
-
- * The program is printed in the order `BEGIN' rule, `BEGINFILE' rule,
- pattern/action rules, `ENDFILE' rule, `END' rule and functions,
- listed alphabetically. Multiple `BEGIN' and `END' rules are
- merged together, as are multiple `BEGINFILE' and `ENDFILE' rules.
-
- * Pattern-action rules have two counts. The first count, to the
- left of the rule, shows how many times the rule's pattern was
- _tested_. The second count, to the right of the rule's opening
- left brace in a comment, shows how many times the rule's action
- was _executed_. The difference between the two indicates how many
- times the rule's pattern evaluated to false.
-
- * Similarly, the count for an `if'-`else' statement shows how many
- times the condition was tested. To the right of the opening left
- brace for the `if''s body is a count showing how many times the
- condition was true. The count for the `else' indicates how many
- times the test failed.
-
- * The count for a loop header (such as `for' or `while') shows how
- many times the loop test was executed. (Because of this, you
- can't just look at the count on the first statement in a rule to
- determine how many times the rule was executed. If the first
- statement is a loop, the count is misleading.)
-
- * For user-defined functions, the count next to the `function'
- 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.
-
- * The layout uses "K&R" style with TABs. Braces are used
- everywhere, even when the body of an `if', `else', or loop is only
- a single statement.
-
- * Parentheses are used only where needed, as indicated by the
- structure of the program and the precedence rules. For example,
- `(3 + 5) * 4' means add three plus five, then multiply the total
- by four. However, `3 + 5 * 4' has no parentheses, and means `3 +
- (5 * 4)'.
-
- * Parentheses are used around the arguments to `print' and `printf'
- only when the `print' or `printf' statement is followed by a
- 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.
-
-
- The profiled version of your program may not look exactly like what
-you typed when you wrote it. This is because `pgawk' creates the
-profiled version by "pretty printing" its internal representation of
-the program. The advantage to this is that `pgawk' 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:
-
- /foo/
-
-come out as:
-
- /foo/ {
- print $0
- }
-
-which is correct, but possibly surprising.
-
- Besides creating profiles when a program has completed, `pgawk' 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:
-
- $ pgawk -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':
-
- $ 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.
-
- Along with the regular profile, as shown earlier, the profile
-includes a trace of any active functions:
-
- # Function Call Stack:
-
- # 3. baz
- # 2. bar
- # 1. foo
- # -- main --
-
- You may send `pgawk' 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'
-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
-`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
-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
+File: gawk.info, Node: Library Functions, Next: Sample Programs, Prev: Functions, Up: Top
-12 A Library of `awk' Functions
+10 A Library of `awk' Functions
*******************************
*note User-defined::, describes how to write your own `awk' functions.
@@ -14452,7 +13516,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
+10.1 Naming Library Function Global Variables
=============================================
Due to the way the `awk' language evolved, variables are either
@@ -14532,7 +13596,7 @@ verifying this.

File: gawk.info, Node: General Functions, Next: Data File Management, Prev: Library Names, Up: Library Functions
-12.2 General Programming
+10.2 General Programming
========================
This minor node presents a number of functions that are of general
@@ -14550,12 +13614,12 @@ programming use.
* Ordinal Functions:: Functions for using characters as numbers and
vice versa.
* Join Function:: A function to join an array into a string.
-* Gettimeofday Function:: A function to get formatted times.
+* Getlocaltime Function:: A function to get formatted times.

File: gawk.info, Node: Strtonum Function, Next: Assert Function, Up: General Functions
-12.2.1 Converting Strings To Numbers
+10.2.1 Converting Strings To Numbers
------------------------------------
The `strtonum()' function (*note String Functions::) is a `gawk'
@@ -14639,7 +13703,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
+10.2.2 Assertions
-----------------
When writing large programs, it is often useful to know that a
@@ -14725,7 +13789,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
+10.2.3 Rounding Numbers
-----------------------
The way `printf' and `sprintf()' (*note Printf::) perform rounding
@@ -14771,7 +13835,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
+10.2.4 The Cliff Random Number Generator
----------------------------------------
The Cliff random number generator
@@ -14800,7 +13864,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
+10.2.5 Translating Between Characters and Numbers
-------------------------------------------------
One commercial implementation of `awk' supplies a built-in function,
@@ -14896,9 +13960,9 @@ tests such as used here prohibitively expensive.
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
+File: gawk.info, Node: Join Function, Next: Getlocaltime Function, Prev: Ordinal Functions, Up: General Functions
-12.2.6 Merging an Array into a String
+10.2.6 Merging an Array into a String
-------------------------------------
When doing string processing, it is often useful to be able to join all
@@ -14943,9 +14007,9 @@ concatenation. The lack of an explicit operator for concatenation
makes string operations more difficult than they really need to be.

-File: gawk.info, Node: Gettimeofday Function, Prev: Join Function, Up: General Functions
+File: gawk.info, Node: Getlocaltime Function, Prev: Join Function, Up: General Functions
-12.2.7 Managing the Time of Day
+10.2.7 Managing the Time of Day
-------------------------------
The `systime()' and `strftime()' functions described in *note Time
@@ -14954,11 +14018,11 @@ with the time of day in human readable form. While `strftime()' is
extensive, the control formats are not necessarily easy to remember or
intuitively obvious when reading a program.
- The following function, `gettimeofday()', populates a user-supplied
+ The following function, `getlocaltime()', populates a user-supplied
array with preformatted time information. It returns a string with the
current time formatted in the same way as the `date' utility:
- # gettimeofday.awk --- get the time of day in a usable format
+ # getlocaltime.awk --- get the time of day in a usable format
# Returns a string in the format of output of date(1)
# Populates the array argument time with individual values:
@@ -14982,7 +14046,7 @@ current time formatted in the same way as the `date' utility:
# time["weeknum"] -- week number, Sunday first day
# time["altweeknum"] -- week number, Monday first day
- function gettimeofday(time, ret, now, i)
+ function getlocaltime(time, ret, now, i)
{
# get time once, avoids unnecessary system calls
now = systime()
@@ -15021,13 +14085,13 @@ current time formatted in the same way as the `date' utility:
The string indices are easier to use and read than the various
formats required by `strftime()'. The `alarm' program presented in
*note Alarm Program::, uses this function. A more general design for
-the `gettimeofday()' function would have allowed the user to supply an
+the `getlocaltime()' function would have allowed the user to supply an
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
+10.3 Data File Management
=========================
This minor node presents functions that are useful for managing
@@ -15044,7 +14108,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
+10.3.1 Noting Data File Boundaries
----------------------------------
The `BEGIN' and `END' rules are each executed exactly once at the
@@ -15142,7 +14206,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
+10.3.2 Rereading the Current File
---------------------------------
Another request for a new built-in function was for a `rewind()'
@@ -15184,7 +14248,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
+10.3.3 Checking for Readable Data Files
---------------------------------------
Normally, if you give `awk' a data file that isn't readable, it stops
@@ -15213,7 +14277,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
+10.3.4 Checking For Zero-length Files
-------------------------------------
All known `awk' implementations silently skip over zero-length files.
@@ -15270,7 +14334,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
+10.3.5 Treating Assignments as File Names
-----------------------------------------
Occasionally, you might not want `awk' to process command-line variable
@@ -15313,7 +14377,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
+10.4 Processing Command-Line Options
====================================
Most utilities on POSIX compatible systems take options on the command
@@ -15606,7 +14670,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
+10.5 Reading the User Database
==============================
The `PROCINFO' array (*note Built-in Variables::) provides access to
@@ -15849,7 +14913,7 @@ network database.

File: gawk.info, Node: Group Functions, Next: Walking Arrays, Prev: Passwd Functions, Up: Library Functions
-12.6 Reading the Group Database
+10.6 Reading the Group Database
===============================
Much of the discussion presented in *note Passwd Functions::, applies
@@ -16083,7 +15147,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
+10.7 Traversing Arrays of Arrays
================================
*note Arrays of Arrays::, described how `gawk' provides arrays of
@@ -16132,9 +15196,9 @@ value. Here is a main program to demonstrate:
-| a[3] = 3

-File: gawk.info, Node: Sample Programs, Next: Debugger, Prev: Library Functions, Up: Top
+File: gawk.info, Node: Sample Programs, Next: Internationalization, Prev: Library Functions, Up: Top
-13 Practical `awk' Programs
+11 Practical `awk' Programs
***************************
*note Library Functions::, presents the idea that reading programs in a
@@ -16154,7 +15218,7 @@ Library Functions::.

File: gawk.info, Node: Running Examples, Next: Clones, Up: Sample Programs
-13.1 Running the Example Programs
+11.1 Running the Example Programs
=================================
To run a given program, you would typically do something like this:
@@ -16177,7 +15241,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
+11.2 Reinventing Wheels for Fun and Profit
==========================================
This minor node presents a number of POSIX utilities implemented in
@@ -16207,7 +15271,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
+11.2.1 Cutting out Fields and Columns
-------------------------------------
The `cut' utility selects, or "cuts," characters or fields from its
@@ -16466,7 +15530,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
+11.2.2 Searching for Regular Expressions in Files
-------------------------------------------------
The `egrep' utility searches files for patterns. It uses regular
@@ -16698,7 +15762,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
+11.2.3 Printing out User Information
------------------------------------
The `id' utility lists a user's real and effective user ID numbers,
@@ -16805,7 +15869,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
+11.2.4 Splitting a Large File into Pieces
-----------------------------------------
The `split' program splits large text files into smaller pieces. Usage
@@ -16913,7 +15977,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
+11.2.5 Duplicating Output into Multiple Files
---------------------------------------------
The `tee' program is known as a "pipe fitting." `tee' copies its
@@ -17001,7 +16065,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
+11.2.6 Printing Nonduplicated Lines of Text
-------------------------------------------
The `uniq' utility reads sorted lines of data on its standard input,
@@ -17220,7 +16284,7 @@ line of input data:

File: gawk.info, Node: Wc Program, Prev: Uniq Program, Up: Clones
-13.2.7 Counting Things
+11.2.7 Counting Things
----------------------
The `wc' (word count) utility counts lines, words, and characters in
@@ -17365,7 +16429,7 @@ characters, not bytes.

File: gawk.info, Node: Miscellaneous Programs, Prev: Clones, Up: Sample Programs
-13.3 A Grab Bag of `awk' Programs
+11.3 A Grab Bag of `awk' Programs
=================================
This minor node is a large "grab bag" of miscellaneous programs. We
@@ -17392,7 +16456,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
+11.3.1 Finding Duplicated Words in a Document
---------------------------------------------
A common error when writing large amounts of prose is to accidentally
@@ -17440,7 +16504,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
+11.3.2 An Alarm Clock Program
-----------------------------
Nothing cures insomnia like a ringing alarm clock.
@@ -17452,8 +16516,8 @@ prints the message on the standard output. In addition, you can give it
the number of times to repeat the message as well as a delay between
repetitions.
- This program uses the `gettimeofday()' function from *note
-Gettimeofday Function::.
+ This program uses the `getlocaltime()' function from *note
+Getlocaltime Function::.
All the work is done in the `BEGIN' rule. The first part is argument
checking and setting of defaults: the delay, the count, and the message
@@ -17468,7 +16532,7 @@ Statement::), but the processing could be done with a series of
# alarm.awk --- set an alarm
#
- # Requires gettimeofday() library function
+ # Requires getlocaltime() library function
# usage: alarm time [ "message" [ count [ delay ] ] ]
BEGIN \
@@ -17524,7 +16588,7 @@ alarm:
minute = atime[2] + 0 # force numeric
# get current broken down time
- gettimeofday(now)
+ getlocaltime(now)
# if time given is 12-hour hours and it's after that
# hour, e.g., `alarm 5:30' at 9 a.m. means 5:30 p.m.,
@@ -17573,7 +16637,7 @@ necessary:

File: gawk.info, Node: Translate Program, Next: Labels Program, Prev: Alarm Program, Up: Miscellaneous Programs
-13.3.3 Transliterating Characters
+11.3.3 Transliterating Characters
---------------------------------
The system `tr' utility transliterates characters. For example, it is
@@ -17699,7 +16763,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
+11.3.4 Printing Mailing Labels
------------------------------
Here is a "real world"(1) program. This script reads lists of names and
@@ -17806,7 +16870,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
+11.3.5 Generating Word-Usage Counts
-----------------------------------
When working with large amounts of text, it can be interesting to know
@@ -17910,7 +16974,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
+11.3.6 Removing Duplicates from Unsorted Text
---------------------------------------------
The `uniq' program (*note Uniq Program::), removes duplicate lines from
@@ -17957,7 +17021,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
+11.3.7 Extracting Programs from Texinfo Source Files
----------------------------------------------------
The nodes *note Library Functions::, and *note Sample Programs::, are
@@ -18157,7 +17221,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
+11.3.8 A Simple Stream Editor
-----------------------------
The `sed' utility is a stream editor, a program that reads a stream of
@@ -18238,7 +17302,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
+11.3.9 An Easy Way to Use Library Functions
-------------------------------------------
In *note Include Files::, we saw how `gawk' provides a built-in
@@ -18635,7 +17699,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
+11.3.10 Finding Anagrams From A Dictionary
------------------------------------------
An interesting programming challenge is to search for "anagrams" in a
@@ -18725,7 +17789,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
+11.3.11 And Now For Something Completely Different
--------------------------------------------------
The following program was written by Davide Brini and is published on
@@ -18750,47 +17814,1478 @@ supplies the following copyright terms:
We leave it to you to determine what the program does.

-File: gawk.info, Node: Debugger, Next: Language History, Prev: Sample Programs, Up: Top
+File: gawk.info, Node: Internationalization, Next: Advanced Features, Prev: Sample Programs, Up: Top
+
+12 Internationalization with `gawk'
+***********************************
+
+Once upon a time, computer makers wrote software that worked only in
+English. Eventually, hardware and software vendors noticed that if
+their systems worked in the native languages of non-English-speaking
+countries, they were able to sell more systems. As a result,
+internationalization and localization of programs and software systems
+became a common practice.
+
+ For many years, the ability to provide internationalization was
+largely restricted to programs written in C and C++. This major node
+describes the underlying library `gawk' uses for internationalization,
+as well as how `gawk' makes internationalization features available at
+the `awk' program level. Having internationalization available at the
+`awk' level gives software developers additional flexibility--they are
+no longer forced to write in C or C++ when internationalization is a
+requirement.
+
+* Menu:
+
+* I18N and L10N:: Internationalization and Localization.
+* Explaining gettext:: How GNU `gettext' works.
+* Programmer i18n:: Features for the programmer.
+* Translator i18n:: Features for the translator.
+* I18N Example:: A simple i18n example.
+* Gawk I18N:: `gawk' is also internationalized.
+
+
+File: gawk.info, Node: I18N and L10N, Next: Explaining gettext, Up: Internationalization
+
+12.1 Internationalization and Localization
+==========================================
+
+"Internationalization" means writing (or modifying) a program once, in
+such a way that it can use multiple languages without requiring further
+source-code changes. "Localization" means providing the data necessary
+for an internationalized program to work in a particular language.
+Most typically, these terms refer to features such as the language used
+for printing error messages, the language used to read responses, and
+information related to how numerical and monetary values are printed
+and read.
+
+
+File: gawk.info, Node: Explaining gettext, Next: Programmer i18n, Prev: I18N and L10N, Up: Internationalization
+
+12.2 GNU `gettext'
+==================
+
+The facilities in GNU `gettext' focus on messages; strings printed by a
+program, either directly or via formatting with `printf' or
+`sprintf()'.(1)
+
+ When using GNU `gettext', each application has its own "text
+domain". This is a unique name, such as `kpilot' or `gawk', that
+identifies the application. A complete application may have multiple
+components--programs written in C or C++, as well as scripts written in
+`sh' or `awk'. All of the components use the same text domain.
+
+ To make the discussion concrete, assume we're writing an application
+named `guide'. Internationalization consists of the following steps,
+in this order:
+
+ 1. The programmer goes through the source for all of `guide''s
+ components and marks each string that is a candidate for
+ translation. For example, `"`-F': option required"' is a good
+ candidate for translation. A table with strings of option names
+ is not (e.g., `gawk''s `--profile' option should remain the same,
+ no matter what the local language).
+
+ 2. The programmer indicates the application's text domain (`"guide"')
+ to the `gettext' library, by calling the `textdomain()' function.
+
+ 3. Messages from the application are extracted from the source code
+ and collected into a portable object template file (`guide.pot'),
+ which lists the strings and their translations. The translations
+ are initially empty. The original (usually English) messages
+ serve as the key for lookup of the translations.
+
+ 4. For each language with a translator, `guide.pot' is copied to a
+ portable object file (`.po') and translations are created and
+ shipped with the application. For example, there might be a
+ `fr.po' for a French translation.
+
+ 5. Each language's `.po' file is converted into a binary message
+ object (`.mo') file. A message object file contains the original
+ messages and their translations in a binary format that allows
+ fast lookup of translations at runtime.
+
+ 6. When `guide' is built and installed, the binary translation files
+ are installed in a standard place.
+
+ 7. For testing and development, it is possible to tell `gettext' to
+ use `.mo' files in a different directory than the standard one by
+ using the `bindtextdomain()' function.
+
+ 8. At runtime, `guide' looks up each string via a call to
+ `gettext()'. The returned string is the translated string if
+ available, or the original string if not.
+
+ 9. If necessary, it is possible to access messages from a different
+ text domain than the one belonging to the application, without
+ having to switch the application's default text domain back and
+ forth.
+
+ In C (or C++), the string marking and dynamic translation lookup are
+accomplished by wrapping each string in a call to `gettext()':
+
+ printf("%s", gettext("Don't Panic!\n"));
+
+ The tools that extract messages from source code pull out all
+strings enclosed in calls to `gettext()'.
+
+ The GNU `gettext' developers, recognizing that typing `gettext(...)'
+over and over again is both painful and ugly to look at, use the macro
+`_' (an underscore) to make things easier:
+
+ /* In the standard header file: */
+ #define _(str) gettext(str)
+
+ /* In the program text: */
+ printf("%s", _("Don't Panic!\n"));
+
+This reduces the typing overhead to just three extra characters per
+string and is considerably easier to read as well.
+
+ There are locale "categories" for different types of locale-related
+information. The defined locale categories that `gettext' knows about
+are:
+
+`LC_MESSAGES'
+ Text messages. This is the default category for `gettext'
+ operations, but it is possible to supply a different one
+ explicitly, if necessary. (It is almost never necessary to supply
+ a different category.)
+
+`LC_COLLATE'
+ Text-collation information; i.e., how different characters and/or
+ groups of characters sort in a given language.
+
+`LC_CTYPE'
+ Character-type information (alphabetic, digit, upper- or
+ lowercase, and so on). This information is accessed via the POSIX
+ character classes in regular expressions, such as `/[[:alnum:]]/'
+ (*note Regexp Operators::).
-14 `dgawk': The `awk' Debugger
+`LC_MONETARY'
+ Monetary information, such as the currency symbol, and whether the
+ symbol goes before or after a number.
+
+`LC_NUMERIC'
+ Numeric information, such as which characters to use for the
+ decimal point and the thousands separator.(2)
+
+`LC_RESPONSE'
+ Response information, such as how "yes" and "no" appear in the
+ local language, and possibly other information as well.
+
+`LC_TIME'
+ Time- and date-related information, such as 12- or 24-hour clock,
+ month printed before or after the day in a date, local month
+ abbreviations, and so on.
+
+`LC_ALL'
+ All of the above. (Not too useful in the context of `gettext'.)
+
+ ---------- Footnotes ----------
+
+ (1) For some operating systems, the `gawk' port doesn't support GNU
+`gettext'. Therefore, these features are not available if you are
+using one of those operating systems. Sorry.
+
+ (2) Americans use a comma every three decimal places and a period
+for the decimal point, while many Europeans do exactly the opposite:
+1,234.56 versus 1.234,56.
+
+
+File: gawk.info, Node: Programmer i18n, Next: Translator i18n, Prev: Explaining gettext, Up: Internationalization
+
+12.3 Internationalizing `awk' Programs
+======================================
+
+`gawk' provides the following variables and functions for
+internationalization:
+
+`TEXTDOMAIN'
+ This variable indicates the application's text domain. For
+ compatibility with GNU `gettext', the default value is
+ `"messages"'.
+
+`_"your message here"'
+ String constants marked with a leading underscore are candidates
+ for translation at runtime. String constants without a leading
+ underscore are not translated.
+
+`dcgettext(STRING [, DOMAIN [, CATEGORY]])'
+ Return the translation of STRING in text domain DOMAIN for locale
+ category CATEGORY. The default value for DOMAIN is the current
+ value of `TEXTDOMAIN'. The default value for CATEGORY is
+ `"LC_MESSAGES"'.
+
+ If you supply a value for CATEGORY, it must be a string equal to
+ one of the known locale categories described in *note Explaining
+ gettext::. You must also supply a text domain. Use `TEXTDOMAIN'
+ if you want to use the current domain.
+
+ CAUTION: The order of arguments to the `awk' version of the
+ `dcgettext()' function is purposely different from the order
+ for the C version. The `awk' version's order was chosen to
+ be simple and to allow for reasonable `awk'-style default
+ arguments.
+
+`dcngettext(STRING1, STRING2, NUMBER [, DOMAIN [, CATEGORY]])'
+ Return the plural form used for NUMBER of the translation of
+ STRING1 and STRING2 in text domain DOMAIN for locale category
+ CATEGORY. STRING1 is the English singular variant of a message,
+ and STRING2 the English plural variant of the same message. The
+ default value for DOMAIN is the current value of `TEXTDOMAIN'.
+ The default value for CATEGORY is `"LC_MESSAGES"'.
+
+ The same remarks about argument order as for the `dcgettext()'
+ function apply.
+
+`bindtextdomain(DIRECTORY [, DOMAIN])'
+ Change the directory in which `gettext' looks for `.mo' files, in
+ case they will not or cannot be placed in the standard locations
+ (e.g., during testing). Return the directory in which DOMAIN is
+ "bound."
+
+ The default DOMAIN is the value of `TEXTDOMAIN'. If DIRECTORY is
+ the null string (`""'), then `bindtextdomain()' returns the
+ current binding for the given DOMAIN.
+
+ To use these facilities in your `awk' program, follow the steps
+outlined in *note Explaining gettext::, like so:
+
+ 1. Set the variable `TEXTDOMAIN' to the text domain of your program.
+ This is best done in a `BEGIN' rule (*note BEGIN/END::), or it can
+ also be done via the `-v' command-line option (*note Options::):
+
+ BEGIN {
+ TEXTDOMAIN = "guide"
+ ...
+ }
+
+ 2. Mark all translatable strings with a leading underscore (`_')
+ character. It _must_ be adjacent to the opening quote of the
+ string. For example:
+
+ print _"hello, world"
+ x = _"you goofed"
+ printf(_"Number of users is %d\n", nusers)
+
+ 3. If you are creating strings dynamically, you can still translate
+ them, using the `dcgettext()' built-in function:
+
+ message = nusers " users logged in"
+ message = dcgettext(message, "adminprog")
+ print message
+
+ Here, the call to `dcgettext()' supplies a different text domain
+ (`"adminprog"') in which to find the message, but it uses the
+ default `"LC_MESSAGES"' category.
+
+ 4. During development, you might want to put the `.mo' file in a
+ private directory for testing. This is done with the
+ `bindtextdomain()' built-in function:
+
+ BEGIN {
+ TEXTDOMAIN = "guide" # our text domain
+ if (Testing) {
+ # where to find our files
+ bindtextdomain("testdir")
+ # joe is in charge of adminprog
+ bindtextdomain("../joe/testdir", "adminprog")
+ }
+ ...
+ }
+
+
+ *Note I18N Example::, for an example program showing the steps to
+create and use translations from `awk'.
+
+
+File: gawk.info, Node: Translator i18n, Next: I18N Example, Prev: Programmer i18n, Up: Internationalization
+
+12.4 Translating `awk' Programs
+===============================
+
+Once a program's translatable strings have been marked, they must be
+extracted to create the initial `.po' file. As part of translation, it
+is often helpful to rearrange the order in which arguments to `printf'
+are output.
+
+ `gawk''s `--gen-pot' command-line option extracts the messages and
+is discussed next. After that, `printf''s ability to rearrange the
+order for `printf' arguments at runtime is covered.
+
+* Menu:
+
+* String Extraction:: Extracting marked strings.
+* Printf Ordering:: Rearranging `printf' arguments.
+* I18N Portability:: `awk'-level portability issues.
+
+
+File: gawk.info, Node: String Extraction, Next: Printf Ordering, Up: Translator i18n
+
+12.4.1 Extracting Marked Strings
+--------------------------------
+
+Once your `awk' program is working, and all the strings have been
+marked and you've set (and perhaps bound) the text domain, it is time
+to produce translations. First, use the `--gen-pot' command-line
+option to create the initial `.pot' file:
+
+ $ gawk --gen-pot -f guide.awk > guide.pot
+
+ When run with `--gen-pot', `gawk' does not execute your program.
+Instead, it parses it as usual and prints all marked strings to
+standard output in the format of a GNU `gettext' Portable Object file.
+Also included in the output are any constant strings that appear as the
+first argument to `dcgettext()' or as the first and second argument to
+`dcngettext()'.(1) *Note I18N Example::, for the full list of steps to
+go through to create and test translations for `guide'.
+
+ ---------- Footnotes ----------
+
+ (1) The `xgettext' utility that comes with GNU `gettext' can handle
+`.awk' files.
+
+
+File: gawk.info, Node: Printf Ordering, Next: I18N Portability, Prev: String Extraction, Up: Translator i18n
+
+12.4.2 Rearranging `printf' Arguments
+-------------------------------------
+
+Format strings for `printf' and `sprintf()' (*note Printf::) present a
+special problem for translation. Consider the following:(1)
+
+ printf(_"String `%s' has %d characters\n",
+ string, length(string)))
+
+ A possible German translation for this might be:
+
+ "%d Zeichen lang ist die Zeichenkette `%s'\n"
+
+ The problem should be obvious: the order of the format
+specifications is different from the original! Even though `gettext()'
+can return the translated string at runtime, it cannot change the
+argument order in the call to `printf'.
+
+ To solve this problem, `printf' format specifiers may have an
+additional optional element, which we call a "positional specifier".
+For example:
+
+ "%2$d Zeichen lang ist die Zeichenkette `%1$s'\n"
+
+ Here, the positional specifier consists of an integer count, which
+indicates which argument to use, and a `$'. Counts are one-based, and
+the format string itself is _not_ included. Thus, in the following
+example, `string' is the first argument and `length(string)' is the
+second:
+
+ $ gawk 'BEGIN {
+ > string = "Dont Panic"
+ > printf _"%2$d characters live in \"%1$s\"\n",
+ > string, length(string)
+ > }'
+ -| 10 characters live in "Dont Panic"
+
+ If present, positional specifiers come first in the format
+specification, before the flags, the field width, and/or the precision.
+
+ Positional specifiers can be used with the dynamic field width and
+precision capability:
+
+ $ gawk 'BEGIN {
+ > printf("%*.*s\n", 10, 20, "hello")
+ > printf("%3$*2$.*1$s\n", 20, 10, "hello")
+ > }'
+ -| hello
+ -| hello
+
+ NOTE: When using `*' with a positional specifier, the `*' comes
+ first, then the integer position, and then the `$'. This is
+ somewhat counterintuitive.
+
+ `gawk' does not allow you to mix regular format specifiers and those
+with positional specifiers in the same string:
+
+ $ gawk 'BEGIN { printf _"%d %3$s\n", 1, 2, "hi" }'
+ error--> gawk: cmd. line:1: fatal: must use `count$' on all formats or none
+
+ NOTE: There are some pathological cases that `gawk' may fail to
+ diagnose. In such cases, the output may not be what you expect.
+ It's still a bad idea to try mixing them, even if `gawk' doesn't
+ detect it.
+
+ Although positional specifiers can be used directly in `awk'
+programs, their primary purpose is to help in producing correct
+translations of format strings into languages different from the one in
+which the program is first written.
+
+ ---------- Footnotes ----------
+
+ (1) This example is borrowed from the GNU `gettext' manual.
+
+
+File: gawk.info, Node: I18N Portability, Prev: Printf Ordering, Up: Translator i18n
+
+12.4.3 `awk' Portability Issues
+-------------------------------
+
+`gawk''s internationalization features were purposely chosen to have as
+little impact as possible on the portability of `awk' programs that use
+them to other versions of `awk'. Consider this program:
+
+ BEGIN {
+ TEXTDOMAIN = "guide"
+ if (Test_Guide) # set with -v
+ bindtextdomain("/test/guide/messages")
+ print _"don't panic!"
+ }
+
+As written, it won't work on other versions of `awk'. However, it is
+actually almost portable, requiring very little change:
+
+ * Assignments to `TEXTDOMAIN' won't have any effect, since
+ `TEXTDOMAIN' is not special in other `awk' implementations.
+
+ * Non-GNU versions of `awk' treat marked strings as the
+ concatenation of a variable named `_' with the string following
+ it.(1) Typically, the variable `_' has the null string (`""') as
+ its value, leaving the original string constant as the result.
+
+ * By defining "dummy" functions to replace `dcgettext()',
+ `dcngettext()' and `bindtextdomain()', the `awk' program can be
+ made to run, but all the messages are output in the original
+ language. For example:
+
+ function bindtextdomain(dir, domain)
+ {
+ return dir
+ }
+
+ function dcgettext(string, domain, category)
+ {
+ return string
+ }
+
+ function dcngettext(string1, string2, number, domain, category)
+ {
+ return (number == 1 ? string1 : string2)
+ }
+
+ * The use of positional specifications in `printf' or `sprintf()' is
+ _not_ portable. To support `gettext()' at the C level, many
+ systems' C versions of `sprintf()' do support positional
+ specifiers. But it works only if enough arguments are supplied in
+ the function call. Many versions of `awk' pass `printf' formats
+ and arguments unchanged to the underlying C library version of
+ `sprintf()', but only one format and argument at a time. What
+ happens if a positional specification is used is anybody's guess.
+ However, since the positional specifications are primarily for use
+ in _translated_ format strings, and since non-GNU `awk's never
+ retrieve the translated string, this should not be a problem in
+ practice.
+
+ ---------- Footnotes ----------
+
+ (1) This is good fodder for an "Obfuscated `awk'" contest.
+
+
+File: gawk.info, Node: I18N Example, Next: Gawk I18N, Prev: Translator i18n, Up: Internationalization
+
+12.5 A Simple Internationalization Example
+==========================================
+
+Now let's look at a step-by-step example of how to internationalize and
+localize a simple `awk' program, using `guide.awk' as our original
+source:
+
+ BEGIN {
+ TEXTDOMAIN = "guide"
+ bindtextdomain(".") # for testing
+ print _"Don't Panic"
+ print _"The Answer Is", 42
+ print "Pardon me, Zaphod who?"
+ }
+
+Run `gawk --gen-pot' to create the `.pot' file:
+
+ $ gawk --gen-pot -f guide.awk > guide.pot
+
+This produces:
+
+ #: guide.awk:4
+ msgid "Don't Panic"
+ msgstr ""
+
+ #: guide.awk:5
+ msgid "The Answer Is"
+ msgstr ""
+
+ This original portable object template file is saved and reused for
+each language into which the application is translated. The `msgid' is
+the original string and the `msgstr' is the translation.
+
+ NOTE: Strings not marked with a leading underscore do not appear
+ in the `guide.pot' file.
+
+ Next, the messages must be translated. Here is a translation to a
+hypothetical dialect of English, called "Mellow":(1)
+
+ $ cp guide.pot guide-mellow.po
+ ADD TRANSLATIONS TO guide-mellow.po ...
+
+Following are the translations:
+
+ #: guide.awk:4
+ msgid "Don't Panic"
+ msgstr "Hey man, relax!"
+
+ #: guide.awk:5
+ msgid "The Answer Is"
+ msgstr "Like, the scoop is"
+
+ The next step is to make the directory to hold the binary message
+object file and then to create the `guide.mo' file. The directory
+layout shown here is standard for GNU `gettext' on GNU/Linux systems.
+Other versions of `gettext' may use a different layout:
+
+ $ mkdir en_US en_US/LC_MESSAGES
+
+ The `msgfmt' utility does the conversion from human-readable `.po'
+file to machine-readable `.mo' file. By default, `msgfmt' creates a
+file named `messages'. This file must be renamed and placed in the
+proper directory so that `gawk' can find it:
+
+ $ msgfmt guide-mellow.po
+ $ mv messages en_US/LC_MESSAGES/guide.mo
+
+ Finally, we run the program to test it:
+
+ $ gawk -f guide.awk
+ -| Hey man, relax!
+ -| Like, the scoop is 42
+ -| Pardon me, Zaphod who?
+
+ If the three replacement functions for `dcgettext()', `dcngettext()'
+and `bindtextdomain()' (*note I18N Portability::) are in a file named
+`libintl.awk', then we can run `guide.awk' unchanged as follows:
+
+ $ gawk --posix -f guide.awk -f libintl.awk
+ -| Don't Panic
+ -| The Answer Is 42
+ -| Pardon me, Zaphod who?
+
+ ---------- Footnotes ----------
+
+ (1) Perhaps it would be better if it were called "Hippy." Ah, well.
+
+
+File: gawk.info, Node: Gawk I18N, Prev: I18N Example, Up: Internationalization
+
+12.6 `gawk' Can Speak Your Language
+===================================
+
+`gawk' itself has been internationalized using the GNU `gettext'
+package. (GNU `gettext' is described in complete detail in *note (GNU
+`gettext' utilities)Top:: gettext, GNU gettext tools.) As of this
+writing, the latest version of GNU `gettext' is version 0.18.1
+(ftp://ftp.gnu.org/gnu/gettext/gettext-0.18.1.tar.gz).
+
+ If a translation of `gawk''s messages exists, then `gawk' produces
+usage messages, warnings, and fatal errors in the local language.
+
+
+File: gawk.info, Node: Advanced Features, Next: Debugger, Prev: Internationalization, Up: Top
+
+13 Advanced Features of `gawk'
******************************
+ Write documentation as if whoever reads it is a violent psychopath
+ who knows where you live.
+ Steve English, as quoted by Peter Langston
+
+ This major node discusses advanced features in `gawk'. It's a bit
+of a "grab bag" of items that are otherwise unrelated to each other.
+First, a command-line option allows `gawk' to recognize nondecimal
+numbers in input data, not just in `awk' programs. Then, `gawk''s
+special features for sorting arrays are presented. Next, two-way I/O,
+discussed briefly in earlier parts of this Info file, is described in
+full detail, along with the basics of TCP/IP networking. Finally,
+`gawk' can "profile" an `awk' program, making it possible to tune it
+for performance.
+
+ *note Dynamic Extensions::, discusses the ability to dynamically add
+new built-in functions to `gawk'. As this feature is still immature
+and likely to change, its description is relegated to an appendix.
+
+* Menu:
+
+* Nondecimal Data:: Allowing nondecimal input data.
+* Array Sorting:: Facilities for controlling array traversal and
+ sorting arrays.
+* Two-way I/O:: Two-way communications with another process.
+* TCP/IP Networking:: Using `gawk' for network programming.
+* Profiling:: Profiling your `awk' programs.
+
+
+File: gawk.info, Node: Nondecimal Data, Next: Array Sorting, Up: Advanced Features
+
+13.1 Allowing Nondecimal Input Data
+===================================
+
+If you run `gawk' with the `--non-decimal-data' option, you can have
+nondecimal constants in your input data:
+
+ $ echo 0123 123 0x123 |
+ > gawk --non-decimal-data '{ printf "%d, %d, %d\n",
+ > $1, $2, $3 }'
+ -| 83, 123, 291
+
+ For this feature to work, write your program so that `gawk' treats
+your data as numeric:
+
+ $ echo 0123 123 0x123 | gawk '{ print $1, $2, $3 }'
+ -| 0123 123 0x123
+
+The `print' statement treats its expressions as strings. Although the
+fields can act as numbers when necessary, they are still strings, so
+`print' does not try to treat them numerically. You may need to add
+zero to a field to force it to be treated as a number. For example:
+
+ $ echo 0123 123 0x123 | gawk --non-decimal-data '
+ > { print $1, $2, $3
+ > print $1 + 0, $2 + 0, $3 + 0 }'
+ -| 0123 123 0x123
+ -| 83 123 291
+
+ Because it is common to have decimal data with leading zeros, and
+because using this facility could lead to surprising results, the
+default is to leave it disabled. If you want it, you must explicitly
+request it.
+
+ CAUTION: _Use of this option is not recommended._ It can break old
+ programs very badly. Instead, use the `strtonum()' function to
+ convert your data (*note Nondecimal-numbers::). This makes your
+ programs easier to write and easier to read, and leads to less
+ surprising results.
+
+
+File: gawk.info, Node: Array Sorting, Next: Two-way I/O, Prev: Nondecimal Data, Up: Advanced Features
+
+13.2 Controlling Array Traversal and Array Sorting
+==================================================
+
+`gawk' lets you control the order in which a `for (i in array)' loop
+traverses an array.
+
+ In addition, two built-in functions, `asort()' and `asorti()', let
+you sort arrays based on the array values and indices, respectively.
+These two functions also provide control over the sorting criteria used
+to order the elements during sorting.
+
+* Menu:
+
+* Controlling Array Traversal:: How to use PROCINFO["sorted_in"].
+* Array Sorting Functions:: How to use `asort()' and `asorti()'.
+
+
+File: gawk.info, Node: Controlling Array Traversal, Next: Array Sorting Functions, Up: Array Sorting
+
+13.2.1 Controlling Array Traversal
+----------------------------------
+
+By default, the order in which a `for (i in array)' loop scans an array
+is not defined; it is generally based upon the internal implementation
+of arrays inside `awk'.
+
+ Often, though, it is desirable to be able to loop over the elements
+in a particular order that you, the programmer, choose. `gawk' lets
+you do this.
+
+ *note Controlling Scanning::, describes how you can assign special,
+pre-defined values to `PROCINFO["sorted_in"]' in order to control the
+order in which `gawk' will traverse an array during a `for' loop.
+
+ In addition, the value of `PROCINFO["sorted_in"]' can be a function
+name. This lets you traverse an array based on any custom criterion.
+The array elements are ordered according to the return value of this
+function. The comparison function should be defined with at least four
+arguments:
+
+ function comp_func(i1, v1, i2, v2)
+ {
+ COMPARE ELEMENTS 1 AND 2 IN SOME FASHION
+ RETURN < 0; 0; OR > 0
+ }
+
+ Here, I1 and I2 are the indices, and V1 and V2 are the corresponding
+values of the two elements being compared. Either V1 or V2, or both,
+can be arrays if the array being traversed contains subarrays as values.
+(*Note Arrays of Arrays::, for more information about subarrays.) The
+three possible return values are interpreted as follows:
+
+`comp_func(i1, v1, i2, v2) < 0'
+ Index I1 comes before index I2 during loop traversal.
+
+`comp_func(i1, v1, i2, v2) == 0'
+ Indices I1 and I2 come together but the relative order with
+ respect to each other is undefined.
+
+`comp_func(i1, v1, i2, v2) > 0'
+ Index I1 comes after index I2 during loop traversal.
+
+ Our first comparison function can be used to scan an array in
+numerical order of the indices:
+
+ function cmp_num_idx(i1, v1, i2, v2)
+ {
+ # numerical index comparison, ascending order
+ return (i1 - i2)
+ }
+
+ Our second function traverses an array based on the string order of
+the element values rather than by indices:
+
+ function cmp_str_val(i1, v1, i2, v2)
+ {
+ # string value comparison, ascending order
+ v1 = v1 ""
+ v2 = v2 ""
+ if (v1 < v2)
+ return -1
+ return (v1 != v2)
+ }
+
+ The third comparison function makes all numbers, and numeric strings
+without any leading or trailing spaces, come out first during loop
+traversal:
+
+ function cmp_num_str_val(i1, v1, i2, v2, n1, n2)
+ {
+ # numbers before string value comparison, ascending order
+ n1 = v1 + 0
+ n2 = v2 + 0
+ if (n1 == v1)
+ return (n2 == v2) ? (n1 - n2) : -1
+ else if (n2 == v2)
+ return 1
+ return (v1 < v2) ? -1 : (v1 != v2)
+ }
+
+ Here is a main program to demonstrate how `gawk' behaves using each
+of the previous functions:
+
+ BEGIN {
+ data["one"] = 10
+ data["two"] = 20
+ data[10] = "one"
+ data[100] = 100
+ data[20] = "two"
+
+ f[1] = "cmp_num_idx"
+ f[2] = "cmp_str_val"
+ f[3] = "cmp_num_str_val"
+ for (i = 1; i <= 3; i++) {
+ printf("Sort function: %s\n", f[i])
+ PROCINFO["sorted_in"] = f[i]
+ for (j in data)
+ printf("\tdata[%s] = %s\n", j, data[j])
+ print ""
+ }
+ }
+
+ Here are the results when the program is run:
+
+ $ gawk -f compdemo.awk
+ -| Sort function: cmp_num_idx Sort by numeric index
+ -| data[two] = 20
+ -| data[one] = 10 Both strings are numerically zero
+ -| data[10] = one
+ -| data[20] = two
+ -| data[100] = 100
+ -|
+ -| Sort function: cmp_str_val Sort by element values as strings
+ -| data[one] = 10
+ -| data[100] = 100 String 100 is less than string 20
+ -| data[two] = 20
+ -| data[10] = one
+ -| data[20] = two
+ -|
+ -| Sort function: cmp_num_str_val Sort all numeric values before all strings
+ -| data[one] = 10
+ -| data[two] = 20
+ -| data[100] = 100
+ -| data[10] = one
+ -| data[20] = two
+
+ Consider sorting the entries of a GNU/Linux system password file
+according to login name. The following program sorts records by a
+specific field position and can be used for this purpose:
+
+ # sort.awk --- simple program to sort by field position
+ # field position is specified by the global variable POS
+
+ function cmp_field(i1, v1, i2, v2)
+ {
+ # comparison by value, as string, and ascending order
+ return v1[POS] < v2[POS] ? -1 : (v1[POS] != v2[POS])
+ }
+
+ {
+ for (i = 1; i <= NF; i++)
+ a[NR][i] = $i
+ }
+
+ END {
+ PROCINFO["sorted_in"] = "cmp_field"
+ if (POS < 1 || POS > NF)
+ POS = 1
+ for (i in a) {
+ for (j = 1; j <= NF; j++)
+ printf("%s%c", a[i][j], j < NF ? ":" : "")
+ print ""
+ }
+ }
+
+ The first field in each entry of the password file is the user's
+login name, and the fields are separated by colons. Each record
+defines a subarray, with each field as an element in the subarray.
+Running the program produces the following output:
+
+ $ gawk -v POS=1 -F: -f sort.awk /etc/passwd
+ -| adm:x:3:4:adm:/var/adm:/sbin/nologin
+ -| apache:x:48:48:Apache:/var/www:/sbin/nologin
+ -| avahi:x:70:70:Avahi daemon:/:/sbin/nologin
+ ...
+
+ The comparison should normally always return the same value when
+given a specific pair of array elements as its arguments. If
+inconsistent results are returned then the order is undefined. This
+behavior can be exploited to introduce random order into otherwise
+seemingly ordered data:
+
+ function cmp_randomize(i1, v1, i2, v2)
+ {
+ # random order
+ return (2 - 4 * rand())
+ }
+
+ As mentioned above, the order of the indices is arbitrary if two
+elements compare equal. This is usually not a problem, but letting the
+tied elements come out in arbitrary order can be an issue, especially
+when comparing item values. The partial ordering of the equal elements
+may change during the next loop traversal, if other elements are added
+or removed from the array. One way to resolve ties when comparing
+elements with otherwise equal values is to include the indices in the
+comparison rules. Note that doing this may make the loop traversal
+less efficient, so consider it only if necessary. The following
+comparison functions force a deterministic order, and are based on the
+fact that the indices of two elements are never equal:
+
+ function cmp_numeric(i1, v1, i2, v2)
+ {
+ # numerical value (and index) comparison, descending order
+ return (v1 != v2) ? (v2 - v1) : (i2 - i1)
+ }
+
+ function cmp_string(i1, v1, i2, v2)
+ {
+ # string value (and index) comparison, descending order
+ v1 = v1 i1
+ v2 = v2 i2
+ return (v1 > v2) ? -1 : (v1 != v2)
+ }
+
+ A custom comparison function can often simplify ordered loop
+traversal, and the sky is really the limit when it comes to designing
+such a function.
+
+ When string comparisons are made during a sort, either for element
+values where one or both aren't numbers, or for element indices handled
+as strings, the value of `IGNORECASE' (*note Built-in Variables::)
+controls whether the comparisons treat corresponding uppercase and
+lowercase letters as equivalent or distinct.
+
+ Another point to keep in mind is that in the case of subarrays the
+element values can themselves be arrays; a production comparison
+function should use the `isarray()' function (*note Type Functions::),
+to check for this, and choose a defined sorting order for subarrays.
+
+ All sorting based on `PROCINFO["sorted_in"]' is disabled in POSIX
+mode, since the `PROCINFO' array is not special in that case.
+
+ As a side note, sorting the array indices before traversing the
+array has been reported to add 15% to 20% overhead to the execution
+time of `awk' programs. For this reason, sorted array traversal is not
+the default.
+
+
+File: gawk.info, Node: Array Sorting Functions, Prev: Controlling Array Traversal, Up: Array Sorting
+
+13.2.2 Sorting Array Values and Indices with `gawk'
+---------------------------------------------------
+
+In most `awk' implementations, sorting an array requires writing a
+`sort()' function. While this can be educational for exploring
+different sorting algorithms, usually that's not the point of the
+program. `gawk' provides the built-in `asort()' and `asorti()'
+functions (*note String Functions::) for sorting arrays. For example:
+
+ POPULATE THE ARRAY data
+ n = asort(data)
+ for (i = 1; i <= n; i++)
+ DO SOMETHING WITH data[i]
+
+ After the call to `asort()', the array `data' is indexed from 1 to
+some number N, the total number of elements in `data'. (This count is
+`asort()''s return value.) `data[1]' <= `data[2]' <= `data[3]', and so
+on. The comparison is based on the type of the elements (*note Typing
+and Comparison::). All numeric values come before all string values,
+which in turn come before all subarrays.
+
+ An important side effect of calling `asort()' is that _the array's
+original indices are irrevocably lost_. As this isn't always
+desirable, `asort()' accepts a second argument:
+
+ POPULATE THE ARRAY source
+ n = asort(source, dest)
+ for (i = 1; i <= n; i++)
+ DO SOMETHING WITH dest[i]
+
+ In this case, `gawk' copies the `source' array into the `dest' array
+and then sorts `dest', destroying its indices. However, the `source'
+array is not affected.
+
+ `asort()' accepts a third string argument to control comparison of
+array elements. As with `PROCINFO["sorted_in"]', this argument may be
+one of the predefined names that `gawk' provides (*note Controlling
+Scanning::), or the name of a user-defined function (*note Controlling
+Array Traversal::).
+
+ NOTE: In all cases, the sorted element values consist of the
+ original array's element values. The ability to control
+ comparison merely affects the way in which they are sorted.
+
+ Often, what's needed is to sort on the values of the _indices_
+instead of the values of the elements. To do that, use the `asorti()'
+function. The interface is identical to that of `asort()', except that
+the index values are used for sorting, and become the values of the
+result array:
+
+ { source[$0] = some_func($0) }
+
+ END {
+ n = asorti(source, dest)
+ for (i = 1; i <= n; i++) {
+ Work with sorted indices directly:
+ DO SOMETHING WITH dest[i]
+ ...
+ Access original array via sorted indices:
+ DO SOMETHING WITH source[dest[i]]
+ }
+ }
+
+ Similar to `asort()', in all cases, the sorted element values
+consist of the original array's indices. The ability to control
+comparison merely affects the way in which they are sorted.
+
+ Sorting the array by replacing the indices provides maximal
+flexibility. To traverse the elements in decreasing order, use a loop
+that goes from N down to 1, either over the elements or over the
+indices.(1)
+
+ Copying array indices and elements isn't expensive in terms of
+memory. Internally, `gawk' maintains "reference counts" to data. For
+example, when `asort()' copies the first array to the second one, there
+is only one copy of the original array elements' data, even though both
+arrays use the values.
+
+ Because `IGNORECASE' affects string comparisons, the value of
+`IGNORECASE' also affects sorting for both `asort()' and `asorti()'.
+Note also that the locale's sorting order does _not_ come into play;
+comparisons are based on character values only.(2) Caveat Emptor.
+
+ ---------- Footnotes ----------
+
+ (1) You may also use one of the predefined sorting names that sorts
+in decreasing order.
+
+ (2) This is true because locale-based comparison occurs only when in
+POSIX compatibility mode, and since `asort()' and `asorti()' are `gawk'
+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
+
+13.3 Two-Way Communications with Another Process
+================================================
+
+ From: brennan@whidbey.com (Mike Brennan)
+ Newsgroups: comp.lang.awk
+ Subject: Re: Learn the SECRET to Attract Women Easily
+ Date: 4 Aug 1997 17:34:46 GMT
+ Message-ID: <5s53rm$eca@news.whidbey.com>
+
+ On 3 Aug 1997 13:17:43 GMT, Want More Dates???
+ <tracy78@kilgrona.com> wrote:
+ >Learn the SECRET to Attract Women Easily
+ >
+ >The SCENT(tm) Pheromone Sex Attractant For Men to Attract Women
+
+ The scent of awk programmers is a lot more attractive to women than
+ the scent of perl programmers.
+ --
+ Mike Brennan
+
+ It is often useful to be able to send data to a separate program for
+processing and then read the result. This can always be done with
+temporary files:
+
+ # Write the data for processing
+ tempfile = ("mydata." PROCINFO["pid"])
+ while (NOT DONE WITH DATA)
+ print DATA | ("subprogram > " tempfile)
+ close("subprogram > " tempfile)
+
+ # Read the results, remove tempfile when done
+ while ((getline newdata < tempfile) > 0)
+ PROCESS newdata APPROPRIATELY
+ close(tempfile)
+ system("rm " tempfile)
+
+This works, but not elegantly. Among other things, it requires that
+the program be run in a directory that cannot be shared among users;
+for example, `/tmp' will not do, as another user might happen to be
+using a temporary file with the same name.
+
+ However, with `gawk', it is possible to open a _two-way_ pipe to
+another process. The second process is termed a "coprocess", since it
+runs in parallel with `gawk'. The two-way connection is created using
+the `|&' operator (borrowed from the Korn shell, `ksh'):(1)
+
+ do {
+ print DATA |& "subprogram"
+ "subprogram" |& getline results
+ } while (DATA LEFT TO PROCESS)
+ close("subprogram")
+
+ The first time an I/O operation is executed using the `|&' operator,
+`gawk' creates a two-way pipeline to a child process that runs the
+other program. Output created with `print' or `printf' is written to
+the program's standard input, and output from the program's standard
+output can be read by the `gawk' program using `getline'. As is the
+case with processes started by `|', the subprogram can be any program,
+or pipeline of programs, that can be started by the shell.
+
+ There are some cautionary items to be aware of:
+
+ * As the code inside `gawk' currently stands, the coprocess's
+ standard error goes to the same place that the parent `gawk''s
+ standard error goes. It is not possible to read the child's
+ standard error separately.
+
+ * I/O buffering may be a problem. `gawk' automatically flushes all
+ output down the pipe to the coprocess. However, if the coprocess
+ does not flush its output, `gawk' may hang when doing a `getline'
+ in order to read the coprocess's results. This could lead to a
+ situation known as "deadlock", where each process is waiting for
+ the other one to do something.
+
+ It is possible to close just one end of the two-way pipe to a
+coprocess, by supplying a second argument to the `close()' function of
+either `"to"' or `"from"' (*note Close Files And Pipes::). These
+strings tell `gawk' to close the end of the pipe that sends data to the
+coprocess or the end that reads from it, respectively.
+
+ This is particularly necessary in order to use the system `sort'
+utility as part of a coprocess; `sort' must read _all_ of its input
+data before it can produce any output. The `sort' program does not
+receive an end-of-file indication until `gawk' closes the write end of
+the pipe.
+
+ When you have finished writing data to the `sort' utility, you can
+close the `"to"' end of the pipe, and then start reading sorted data
+via `getline'. For example:
+
+ BEGIN {
+ command = "LC_ALL=C sort"
+ n = split("abcdefghijklmnopqrstuvwxyz", a, "")
+
+ for (i = n; i > 0; i--)
+ print a[i] |& command
+ close(command, "to")
+
+ while ((command |& getline line) > 0)
+ print "got", line
+ close(command)
+ }
+
+ This program writes the letters of the alphabet in reverse order, one
+per line, down the two-way pipe to `sort'. It then closes the write
+end of the pipe, so that `sort' receives an end-of-file indication.
+This causes `sort' to sort the data and write the sorted data back to
+the `gawk' program. Once all of the data has been read, `gawk'
+terminates the coprocess and exits.
+
+ As a side note, the assignment `LC_ALL=C' in the `sort' command
+ensures traditional Unix (ASCII) sorting from `sort'.
+
+ You may also use pseudo-ttys (ptys) for two-way communication
+instead of pipes, if your system supports them. This is done on a
+per-command basis, by setting a special element in the `PROCINFO' array
+(*note Auto-set::), like so:
+
+ command = "sort -nr" # command, save in convenience variable
+ PROCINFO[command, "pty"] = 1 # update PROCINFO
+ print ... |& command # start two-way pipe
+ ...
+
+Using ptys avoids the buffer deadlock issues described earlier, at some
+loss in performance. If your system does not have ptys, or if all the
+system's ptys are in use, `gawk' automatically falls back to using
+regular pipes.
+
+ ---------- Footnotes ----------
+
+ (1) This is very different from the same operator in the C shell.
+
+
+File: gawk.info, Node: TCP/IP Networking, Next: Profiling, Prev: Two-way I/O, Up: Advanced Features
+
+13.4 Using `gawk' for Network Programming
+=========================================
+
+ `EMISTERED':
+ A host is a host from coast to coast,
+ and no-one can talk to host that's close,
+ unless the host that isn't close
+ is busy hung or dead.
+
+ In addition to being able to open a two-way pipeline to a coprocess
+on the same system (*note Two-way I/O::), it is possible to make a
+two-way connection to another process on another system across an IP
+network connection.
+
+ You can think of this as just a _very long_ two-way pipeline to a
+coprocess. The way `gawk' decides that you want to use TCP/IP
+networking is by recognizing special file names that begin with one of
+`/inet/', `/inet4/' or `/inet6'.
+
+ The full syntax of the special file name is
+`/NET-TYPE/PROTOCOL/LOCAL-PORT/REMOTE-HOST/REMOTE-PORT'. The
+components are:
+
+NET-TYPE
+ Specifies the kind of Internet connection to make. Use `/inet4/'
+ to force IPv4, and `/inet6/' to force IPv6. Plain `/inet/' (which
+ used to be the only option) uses the system default, most likely
+ IPv4.
+
+PROTOCOL
+ The protocol to use over IP. This must be either `tcp', or `udp',
+ for a TCP or UDP IP connection, respectively. The use of TCP is
+ recommended for most applications.
+
+LOCAL-PORT
+ The local TCP or UDP port number to use. Use a port number of `0'
+ when you want the system to pick a port. This is what you should do
+ when writing a TCP or UDP client. You may also use a well-known
+ service name, such as `smtp' or `http', in which case `gawk'
+ attempts to determine the predefined port number using the C
+ `getaddrinfo()' function.
+
+REMOTE-HOST
+ The IP address or fully-qualified domain name of the Internet host
+ to which you want to connect.
+
+REMOTE-PORT
+ The TCP or UDP port number to use on the given REMOTE-HOST.
+ Again, use `0' if you don't care, or else a well-known service
+ name.
+
+ NOTE: Failure in opening a two-way socket will result in a
+ non-fatal error being returned to the calling code. The value of
+ `ERRNO' indicates the error (*note Auto-set::).
+
+ Consider the following very simple example:
+
+ BEGIN {
+ Service = "/inet/tcp/0/localhost/daytime"
+ Service |& getline
+ print $0
+ close(Service)
+ }
+
+ This program reads the current date and time from the local system's
+TCP `daytime' server. It then prints the results and closes the
+connection.
+
+ Because this topic is extensive, the use of `gawk' for TCP/IP
+programming is documented separately. See *note (General
+Introduction)Top:: gawkinet, TCP/IP Internetworking with `gawk', for a
+much more complete introduction and discussion, as well as extensive
+examples.
+
+
+File: gawk.info, Node: Profiling, Prev: TCP/IP Networking, Up: Advanced Features
+
+13.5 Profiling Your `awk' Programs
+==================================
+
+You may produce execution traces of your `awk' programs. This is done
+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 `gawk' will write the profile:
+
+ gawk --profile=myprog.prof -f myprog.awk data1 data2
+
+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 `gawk' with the `--profile' option.
+First, the `awk' program:
+
+ BEGIN { print "First BEGIN rule" }
+
+ END { print "First END rule" }
+
+ /foo/ {
+ print "matched /foo/, gosh"
+ for (i = 1; i <= 3; i++)
+ sing()
+ }
+
+ {
+ if (/foo/)
+ print "if is true"
+ else
+ print "else is true"
+ }
+
+ BEGIN { print "Second BEGIN rule" }
+
+ END { print "Second END rule" }
+
+ function sing( dummy)
+ {
+ print "I gotta be me!"
+ }
+
+ Following is the input data:
+
+ foo
+ bar
+ baz
+ foo
+ junk
+
+ 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
+
+ # BEGIN block(s)
+
+ BEGIN {
+ 1 print "First BEGIN rule"
+ 1 print "Second BEGIN rule"
+ }
+
+ # Rule(s)
+
+ 5 /foo/ { # 2
+ 2 print "matched /foo/, gosh"
+ 6 for (i = 1; i <= 3; i++) {
+ 6 sing()
+ }
+ }
+
+ 5 {
+ 5 if (/foo/) { # 2
+ 2 print "if is true"
+ 3 } else {
+ 3 print "else is true"
+ }
+ }
+
+ # END block(s)
+
+ END {
+ 1 print "First END rule"
+ 1 print "Second END rule"
+ }
+
+ # Functions, listed alphabetically
+
+ 6 function sing(dummy)
+ {
+ 6 print "I gotta be me!"
+ }
+
+ This example illustrates many of the basic features of profiling
+output. They are as follows:
+
+ * The program is printed in the order `BEGIN' rule, `BEGINFILE' rule,
+ pattern/action rules, `ENDFILE' rule, `END' rule and functions,
+ listed alphabetically. Multiple `BEGIN' and `END' rules are
+ merged together, as are multiple `BEGINFILE' and `ENDFILE' rules.
+
+ * Pattern-action rules have two counts. The first count, to the
+ left of the rule, shows how many times the rule's pattern was
+ _tested_. The second count, to the right of the rule's opening
+ left brace in a comment, shows how many times the rule's action
+ was _executed_. The difference between the two indicates how many
+ times the rule's pattern evaluated to false.
+
+ * Similarly, the count for an `if'-`else' statement shows how many
+ times the condition was tested. To the right of the opening left
+ brace for the `if''s body is a count showing how many times the
+ condition was true. The count for the `else' indicates how many
+ times the test failed.
+
+ * The count for a loop header (such as `for' or `while') shows how
+ many times the loop test was executed. (Because of this, you
+ can't just look at the count on the first statement in a rule to
+ determine how many times the rule was executed. If the first
+ statement is a loop, the count is misleading.)
+
+ * For user-defined functions, the count next to the `function'
+ 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.
+
+ * The layout uses "K&R" style with TABs. Braces are used
+ everywhere, even when the body of an `if', `else', or loop is only
+ a single statement.
+
+ * Parentheses are used only where needed, as indicated by the
+ structure of the program and the precedence rules. For example,
+ `(3 + 5) * 4' means add three plus five, then multiply the total
+ by four. However, `3 + 5 * 4' has no parentheses, and means `3 +
+ (5 * 4)'.
+
+ * Parentheses are used around the arguments to `print' and `printf'
+ only when the `print' or `printf' statement is followed by a
+ redirection. Similarly, if the target of a redirection isn't a
+ scalar, it gets parenthesized.
+
+ * `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 `gawk' creates the
+profiled version by "pretty printing" its internal representation of
+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:
+
+ /foo/
+
+come out as:
+
+ /foo/ {
+ print $0
+ }
+
+which is correct, but possibly surprising.
+
+ 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 `gawk' with the `--profile' option
+in the background:
+
+ $ 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 `gawk':
+
+ $ kill -USR1 13992
+
+As usual, the profiled version of the program is written to
+`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:
+
+ # Function Call Stack:
+
+ # 3. baz
+ # 2. bar
+ # 1. foo
+ # -- main --
+
+ 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, `gawk'
+produces the profile and the function call trace and then exits.
+
+ 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, `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: Debugger, Next: Arbitrary Precision Arithmetic, Prev: Advanced Features, Up: Top
+
+14 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'
-============================
+14.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
+14.1.1 Debugging in General
---------------------------
(If you have used debuggers in other languages, you may want to skip
@@ -18834,9 +19329,8 @@ File: gawk.info, Node: Debugging Terms, Next: Awk Debugging, Prev: Debugging
------------------------------------
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
@@ -18854,11 +19348,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
@@ -18903,54 +19397,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
-===========================
+14.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
--------------------------
+14.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
+14.2.2 Finding the Bug
----------------------
Let's say that we are having a problem using (a faulty version of)
@@ -18980,27 +19477,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
@@ -19014,9 +19511,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
@@ -19024,13 +19521,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
@@ -19044,7 +19541,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
@@ -19053,7 +19550,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
@@ -19069,15 +19566,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
@@ -19093,19 +19590,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")
@@ -19114,9 +19611,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
@@ -19124,7 +19621,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!")
@@ -19132,9 +19629,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:
@@ -19145,12 +19642,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
-==========================
+14.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
@@ -19166,26 +19664,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
+14.3.1 Control of Breakpoints
-----------------------------
As we saw above, the first thing you probably want to do in a debugging
@@ -19213,10 +19711,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
@@ -19238,12 +19736,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]
@@ -19277,7 +19776,7 @@ 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
---------------------------
@@ -19300,14 +19799,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]
@@ -19340,9 +19839,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]
@@ -19357,7 +19856,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]
@@ -19367,7 +19866,7 @@ 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
--------------------------------
@@ -19379,7 +19878,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
@@ -19407,7 +19906,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
@@ -19435,16 +19934,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
@@ -19456,9 +19955,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
+14.3.4 Dealing with the Stack
-----------------------------
Whenever you run a program which contains any function calls, `gawk'
@@ -19493,16 +19992,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
+14.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
@@ -19530,10 +20030,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.
@@ -19557,7 +20057,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.
@@ -19568,14 +20068,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.
@@ -19593,15 +20093,15 @@ 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
-----------------------------
@@ -19617,7 +20117,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]
@@ -19666,13 +20166,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]
@@ -19706,7 +20206,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.
@@ -19721,12 +20221,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
=====================
-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:
@@ -19748,27 +20248,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
=================================
-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
@@ -19781,20 +20281,4545 @@ 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
yourself!

-File: gawk.info, Node: Language History, Next: Installation, Prev: Debugger, Up: Top
+File: gawk.info, Node: Arbitrary Precision Arithmetic, Next: Dynamic Extensions, Prev: Debugger, Up: Top
+
+15 Arithmetic and 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 major node discusses issues that you may encounter when
+performing arithmetic. It begins by discussing some of the general
+attributes of computer arithmetic, along with how this can influence
+what you see when running `awk' programs. This discussion applies to
+all versions of `awk'.
+
+ Then the major node moves on to "arbitrary precision arithmetic", a
+feature which is specific to `gawk'.
+
+* Menu:
+
+* General Arithmetic:: An introduction to computer arithmetic.
+* Floating-point Programming:: Effective Floating-point Programming.
+* Gawk and MPFR:: How `gawk' provides
+ arbitrary-precision arithmetic.
+* Arbitrary Precision Floats:: Arbitrary Precision Floating-point Arithmetic
+ with `gawk'.
+* Arbitrary Precision Integers:: Arbitrary Precision Integer Arithmetic with
+ `gawk'.
+
+ ---------- 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: General Arithmetic, Next: Floating-point Programming, Up: Arbitrary Precision Arithmetic
+
+15.1 A General Description of Computer Arithmetic
+=================================================
+
+Within computers, there are two kinds of numeric values: "integers" and
+"floating-point". In school, integer values were referred to as
+"whole" numbers--that is, numbers without any fractional part, such as
+1, 42, or -17. The advantage to integer numbers is that they represent
+values exactly. The disadvantage is that their range is limited. On
+most systems, this range is -2,147,483,648 to 2,147,483,647. However,
+many systems now support a range from -9,223,372,036,854,775,808 to
+9,223,372,036,854,775,807.
+
+ Integer values come in two flavors: "signed" and "unsigned". Signed
+values may be negative or positive, with the range of values just
+described. Unsigned values are always positive. On most systems, the
+range is from 0 to 4,294,967,295. However, many systems now support a
+range from 0 to 18,446,744,073,709,551,615.
+
+ Floating-point numbers represent what are called "real" numbers;
+i.e., those that do have a fractional part, such as 3.1415927. The
+advantage to floating-point numbers is that they can represent a much
+larger range of values. The disadvantage is that there are numbers
+that they cannot represent exactly. `awk' uses "double precision"
+floating-point numbers, which can hold more digits than "single
+precision" floating-point numbers.
+
+ There a several important issues to be aware of, described next.
+
+* Menu:
+
+* Floating Point Issues:: Stuff to know about floating-point numbers.
+* Integer Programming:: Effective integer programming.
+
+
+File: gawk.info, Node: Floating Point Issues, Next: Integer Programming, Up: General Arithmetic
+
+15.1.1 Floating-Point Number Caveats
+------------------------------------
+
+This minor node describes some of the issues involved in using
+floating-point numbers.
+
+ There is a very nice paper on floating-point arithmetic
+(http://www.validlab.com/goldberg/paper.pdf) by David Goldberg, "What
+Every Computer Scientist Should Know About Floating-point Arithmetic,"
+`ACM Computing Surveys' *23*, 1 (1991-03), 5-48. This is worth reading
+if you are interested in the details, but it does require a background
+in computer science.
+
+* Menu:
+
+* String Conversion Precision:: The String Value Can Lie.
+* Unexpected Results:: Floating Point Numbers Are Not Abstract
+ Numbers.
+* POSIX Floating Point Problems:: Standards Versus Existing Practice.
+
+
+File: gawk.info, Node: String Conversion Precision, Next: Unexpected Results, Up: Floating Point Issues
+
+15.1.1.1 The String Value Can Lie
+.................................
+
+Internally, `awk' keeps both the numeric value (double precision
+floating-point) and the string value for a variable. Separately, `awk'
+keeps track of what type the variable has (*note Typing and
+Comparison::), which plays a role in how variables are used in
+comparisons.
+
+ It is important to note that the string value for a number may not
+reflect the full value (all the digits) that the numeric value actually
+contains. The following program (`values.awk') illustrates this:
+
+ {
+ sum = $1 + $2
+ # see it for what it is
+ printf("sum = %.12g\n", sum)
+ # use CONVFMT
+ a = "<" sum ">"
+ print "a =", a
+ # use OFMT
+ print "sum =", sum
+ }
+
+This program shows the full value of the sum of `$1' and `$2' using
+`printf', and then prints the string values obtained from both
+automatic conversion (via `CONVFMT') and from printing (via `OFMT').
+
+ Here is what happens when the program is run:
+
+ $ echo 3.654321 1.2345678 | awk -f values.awk
+ -| sum = 4.8888888
+ -| a = <4.88889>
+ -| sum = 4.88889
+
+ This makes it clear that the full numeric value is different from
+what the default string representations show.
+
+ `CONVFMT''s default value is `"%.6g"', which yields a value with at
+least six significant digits. For some applications, you might want to
+change it to specify more precision. On most modern machines, most of
+the time, 17 digits is enough to capture a floating-point number's
+value exactly.(1)
+
+ ---------- Footnotes ----------
+
+ (1) Pathological cases can require up to 752 digits (!), but we
+doubt that you need to worry about this.
+
+
+File: gawk.info, Node: Unexpected Results, Next: POSIX Floating Point Problems, Prev: String Conversion Precision, Up: Floating Point Issues
+
+15.1.1.2 Floating Point Numbers Are Not Abstract Numbers
+........................................................
+
+Unlike numbers in the abstract sense (such as what you studied in high
+school or college arithmetic), numbers stored in computers are limited
+in certain ways. They cannot represent an infinite number of digits,
+nor can they always represent things exactly. In particular,
+floating-point numbers cannot always represent values exactly. Here is
+an example:
+
+ $ awk '{ printf("%010d\n", $1 * 100) }'
+ 515.79
+ -| 0000051579
+ 515.80
+ -| 0000051579
+ 515.81
+ -| 0000051580
+ 515.82
+ -| 0000051582
+ Ctrl-d
+
+This shows that some values can be represented exactly, whereas others
+are only approximated. This is not a "bug" in `awk', but simply an
+artifact of how computers represent numbers.
+
+ NOTE: It cannot be emphasized enough that the behavior just
+ described is fundamental to modern computers. You will see this
+ kind of thing happen in _any_ programming language using hardware
+ floating-point numbers. It is _not_ a bug in `gawk', nor is it
+ something that can be "just fixed."
+
+ Another peculiarity of floating-point numbers on modern systems is
+that they often have more than one representation for the number zero!
+In particular, it is possible to represent "minus zero" as well as
+regular, or "positive" zero.
+
+ This example shows that negative and positive zero are distinct
+values when stored internally, but that they are in fact equal to each
+other, as well as to "regular" zero:
+
+ $ gawk 'BEGIN { mz = -0 ; pz = 0
+ > printf "-0 = %g, +0 = %g, (-0 == +0) -> %d\n", mz, pz, mz == pz
+ > printf "mz == 0 -> %d, pz == 0 -> %d\n", mz == 0, pz == 0
+ > }'
+ -| -0 = -0, +0 = 0, (-0 == +0) -> 1
+ -| mz == 0 -> 1, pz == 0 -> 1
+
+ It helps to keep this in mind should you process numeric data that
+contains negative zero values; the fact that the zero is negative is
+noted and can affect comparisons.
+
+
+File: gawk.info, Node: POSIX Floating Point Problems, Prev: Unexpected Results, Up: Floating Point Issues
+
+15.1.1.3 Standards Versus Existing Practice
+...........................................
+
+Historically, `awk' has converted any non-numeric looking string to the
+numeric value zero, when required. Furthermore, the original
+definition of the language and the original POSIX standards specified
+that `awk' only understands decimal numbers (base 10), and not octal
+(base 8) or hexadecimal numbers (base 16).
+
+ Changes in the language of the 2001 and 2004 POSIX standards can be
+interpreted to imply that `awk' should support additional features.
+These features are:
+
+ * Interpretation of floating point data values specified in
+ hexadecimal notation (`0xDEADBEEF'). (Note: data values, _not_
+ source code constants.)
+
+ * Support for the special IEEE 754 floating point values "Not A
+ Number" (NaN), positive Infinity ("inf") and negative Infinity
+ ("-inf"). In particular, the format for these values is as
+ specified by the ISO 1999 C standard, which ignores case and can
+ allow machine-dependent additional characters after the `nan' and
+ allow either `inf' or `infinity'.
+
+ The first problem is that both of these are clear changes to
+historical practice:
+
+ * The `gawk' maintainer feels that supporting hexadecimal floating
+ point values, in particular, is ugly, and was never intended by the
+ original designers to be part of the language.
+
+ * Allowing completely alphabetic strings to have valid numeric
+ values is also a very severe departure from historical practice.
+
+ The second problem is that the `gawk' maintainer feels that this
+interpretation of the standard, which requires a certain amount of
+"language lawyering" to arrive at in the first place, was not even
+intended by the standard developers. In other words, "we see how you
+got where you are, but we don't think that that's where you want to be."
+
+ Recognizing the above issues, but attempting to provide compatibility
+with the earlier versions of the standard, the 2008 POSIX standard
+added explicit wording to allow, but not require, that `awk' support
+hexadecimal floating point values and special values for "Not A Number"
+and infinity.
+
+ Although the `gawk' maintainer continues to feel that providing
+those features is inadvisable, nevertheless, on systems that support
+IEEE floating point, it seems reasonable to provide _some_ way to
+support NaN and Infinity values. The solution implemented in `gawk' is
+as follows:
+
+ * With the `--posix' command-line option, `gawk' becomes "hands
+ off." String values are passed directly to the system library's
+ `strtod()' function, and if it successfully returns a numeric
+ value, that is what's used.(1) By definition, the results are not
+ portable across different systems. They are also a little
+ surprising:
+
+ $ echo nanny | gawk --posix '{ print $1 + 0 }'
+ -| nan
+ $ echo 0xDeadBeef | gawk --posix '{ print $1 + 0 }'
+ -| 3735928559
+
+ * Without `--posix', `gawk' interprets the four strings `+inf',
+ `-inf', `+nan', and `-nan' specially, producing the corresponding
+ special numeric values. The leading sign acts a signal to `gawk'
+ (and the user) that the value is really numeric. Hexadecimal
+ floating point is not supported (unless you also use
+ `--non-decimal-data', which is _not_ recommended). For example:
+
+ $ echo nanny | gawk '{ print $1 + 0 }'
+ -| 0
+ $ echo +nan | gawk '{ print $1 + 0 }'
+ -| nan
+ $ echo 0xDeadBeef | gawk '{ print $1 + 0 }'
+ -| 0
+
+ `gawk' does ignore case in the four special values. Thus `+nan'
+ and `+NaN' are the same.
+
+ ---------- Footnotes ----------
+
+ (1) You asked for it, you got it.
+
+
+File: gawk.info, Node: Integer Programming, Prev: Floating Point Issues, Up: General Arithmetic
+
+15.1.2 Mixing Integers And Floating-point
+-----------------------------------------
+
+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 9,007,199,254,740,997 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: Floating-point Programming, Next: Gawk and MPFR, Prev: General Arithmetic, Up: Arbitrary Precision Arithmetic
+
+15.2 Understanding 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
+digesting a book or two to really internalize 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).
+
+ There are two options for doing floating-point calculations:
+hardware floating-point (as used by standard `awk' and the default for
+`gawk'), and "arbitrary-precision" floating-point, which is software
+based. From this point forward, this major node aims to provide enough
+information to understand both, and then will focus on `gawk''s
+facilities for the latter.(1)
+
+ 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, before you start to write any code, you should 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 a little bit off from
+the exact value, comparing floating-point values 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 an additional 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 arbitrary precision help with the previous
+examples? If you are impatient to know, see *note Exact Arithmetic::.
+
+ Instead of arbitrary 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) + 1)
+
+After making this, change the program does converge to pi in under 30
+iterations:
+
+ $ gawk -f /tmp/pi2.awk
+ -| 3.215390309173473
+ -| 3.159659942097501
+ -| 3.146086215131436
+ -| 3.142714599645370
+ -| 3.141873049979825
+ ...
+ -| 3.141592653589797
+ -| 3.141592653589797
+
+ There is no need to be unduly suspicious about the results from
+floating-point arithmetic. The lesson to remember is that
+floating-point arithmetic is always more complex than arithmetic 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.
+
+ As general advice, avoid presenting numerical data in a manner that
+implies better precision than is actually the case.
+
+* Menu:
+
+* Floating-point Representation:: Binary floating-point representation.
+* Floating-point Context:: Floating-point context.
+* Rounding Mode:: Floating-point rounding mode.
+
+ ---------- Footnotes ----------
+
+ (1) If you are interested in other tools that perform arbitrary
+precision arithmetic, you may want to investigate the POSIX `bc' tool.
+See the POSIX specification for it
+(http://pubs.opengroup.org/onlinepubs/009695399/utilities/bc.html), for
+more information.
+
+
+File: gawk.info, Node: Floating-point Representation, Next: Floating-point Context, Up: Floating-point Programming
+
+15.2.1 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", E, giving its order of magnitude.
+
+ * 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. The significand is stored in "normalized" format, which
+means that the first bit is always a one.
+
+ 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: Floating-point Programming
+
+15.2.2 Floating-point Context
+-----------------------------
+
+A floating-point "context" defines the environment for arithmetic
+operations. It governs precision, sets rules for rounding, and limits
+the 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 15.1: Basic IEEE Format Context Values
+
+ 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, Prev: Floating-point Context, Up: Floating-point Programming
+
+15.2.3 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. *note table-rounding-modes:: lists the IEEE-754 defined
+rounding modes:
+
+Rounding Mode IEEE Name
+--------------------------------------------------------------------------
+Round to nearest, ties to even `roundTiesToEven'
+Round toward plus Infinity `roundTowardPositive'
+Round toward negative Infinity `roundTowardNegative'
+Round toward zero `roundTowardZero'
+Round to nearest, ties away `roundTiesToAway'
+from zero
+
+Table 15.2: IEEE 754 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:
+
+ 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 avoid
+round-off error problems 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: Gawk and MPFR, Next: Arbitrary Precision Floats, Prev: Floating-point Programming, Up: Arbitrary Precision Arithmetic
+
+15.3 `gawk' + MPFR = Powerful Arithmetic
+========================================
+
+The rest of this major node describes how to use the arbitrary precision
+(also known as "multiple precision" or "infinite precision") numeric
+capabilities 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.
+
+ Additionally, 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: Arbitrary Precision Floats, Next: Arbitrary Precision Integers, Prev: Gawk and MPFR, Up: Arbitrary Precision Arithmetic
+
+15.4 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' and `ROUNDMODE', provide control over
+the working precision and the rounding mode (*note Setting Precision::,
+and *note Setting Rounding Mode::). The precision and the rounding
+mode are set globally for every operation to follow.
+
+ The default working precision for arbitrary precision floating-point
+values is 53, and the default value for `ROUNDMODE' is `"N"', which
+selects the IEEE-754 `roundTiesToEven' rounding mode (*note 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
+ arithmetic using the underlying machine types, you should consider
+ using only as much precision as needed by your program.
+
+* Menu:
+
+* 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.
+
+ ---------- 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, Up: Arbitrary Precision Floats
+
+15.4.1 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 -v PREC=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 the 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 Floats
+
+15.4.2 Setting the Rounding Mode
+--------------------------------
+
+The `ROUNDMODE' variable provides program level control over the
+rounding mode. The correspondence between `ROUNDMODE' and the IEEE
+rounding modes is shown in *note table-gawk-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 15.3: `gawk' Rounding Modes
+
+ `ROUNDMODE' has the default value `"N"', which selects the IEEE-754
+rounding mode `roundTiesToEven'. *note Table 15.3:
+table-gawk-rounding-modes, lists `"A"' to select the IEEE-754 mode
+`roundTiesToAway'. This is only available 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 -v ROUNDMODE="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 Floats
+
+15.4.3 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 as 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 -v PREC=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 Floats
+
+15.4.4 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, Prev: Changing Precision, Up: Arbitrary Precision Floats
+
+15.4.5 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 -v PREC=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 -v PREC=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 earlier 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 example in *note Floating-point
+Programming:::
+
+ $ gawk 'BEGIN {
+ > for (d = 1.1; d <= 1.5; d += 0.1)
+ > i++
+ > print i
+ > }'
+ -| 4
+
+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: Arbitrary Precision Integers, Prev: Arbitrary Precision Floats, Up: Arbitrary Precision Arithmetic
+
+15.5 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 actual number,
+113,423,713,055,421,844,361,000,443, 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
+floating-point value to begin with:
+
+ gawk -M 'BEGIN { n = 13.0; print n % 2.0 }'
+
+ Note that for the particular example above, there is likely best to
+just use 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: Dynamic Extensions, Next: Language History, Prev: Arbitrary Precision Arithmetic, Up: Top
+
+16 Writing Extensions for `gawk'
+********************************
+
+It is possible to add new built-in functions to `gawk' using
+dynamically loaded libraries. This facility is available on systems
+that support the C `dlopen()' and `dlsym()' functions. This major node
+describes how to create extensions using code written in C or C++.
+
+ If you don't know anything about C programming, you can safely skip
+this major node, although you may wish to review the documentation on
+the extensions that come with `gawk' (*note Extension Samples::), and
+the minor node on the `gawkextlib' project (*note gawkextlib::). The
+sample extensions are automatically built and installed when `gawk' is.
+
+ NOTE: When `--sandbox' is specified, extensions are disabled
+ (*note Options::).
+
+* Menu:
+
+* Extension Intro:: What is an extension.
+* Plugin License:: A note about licensing.
+* Extension Design:: Design notes about the extension API.
+* Extension API Description:: A full description of the API.
+* Extension Example:: Example C code for an extension.
+* Extension Samples:: The sample extensions that ship with
+ `gawk'.
+* gawkextlib:: The `gawkextlib' project.
+
+
+File: gawk.info, Node: Extension Intro, Next: Plugin License, Up: Dynamic Extensions
+
+16.1 Introduction
+=================
+
+An "extension" (sometimes called a "plug-in") is a piece of external
+compiled code that `gawk' can load at runtime to provide additional
+functionality, over and above the built-in capabilities described in
+the rest of this Info file.
+
+ Extensions are useful because they allow you (of course) to extend
+`gawk''s functionality. For example, they can provide access to system
+calls (such as `chdir()' to change directory) and to other C library
+routines that could be of use. As with most software, "the sky is the
+limit;" if you can imagine something that you might want to do and can
+write in C or C++, you can write an extension to do it!
+
+ Extensions are written in C or C++, using the "Application
+Programming Interface" (API) defined for this purpose by the `gawk'
+developers. The rest of this major node explains the design decisions
+behind the API, the facilities that it provides and how to use them,
+and presents a small sample extension. In addition, it documents the
+sample extensions included in the `gawk' distribution, and describes
+the `gawkextlib' project.
+
+
+File: gawk.info, Node: Plugin License, Next: Extension Design, Prev: Extension Intro, Up: Dynamic Extensions
+
+16.2 Extension Licensing
+========================
+
+Every dynamic extension should define the global symbol
+`plugin_is_GPL_compatible' to assert that it has been licensed under a
+GPL-compatible license. If this symbol does not exist, `gawk' emits a
+fatal error and exits when it tries to load your extension.
+
+ The declared type of the symbol should be `int'. It does not need
+to be in any allocated section, though. The code merely asserts that
+the symbol exists in the global scope. Something like this is enough:
+
+ int plugin_is_GPL_compatible;
+
+
+File: gawk.info, Node: Extension Design, Next: Extension API Description, Prev: Plugin License, Up: Dynamic Extensions
+
+16.3 Extension API Design
+=========================
+
+The first version of extensions for `gawk' was developed in the
+mid-1990s and released with `gawk' 3.1 in the late 1990s. The basic
+mechanisms and design remained unchanged for close to 15 years, until
+2012.
+
+ The old extension mechanism used data types and functions from
+`gawk' itself, with a "clever hack" to install extension functions.
+
+ `gawk' included some sample extensions, of which a few were really
+useful. However, it was clear from the outset that the extension
+mechanism was bolted onto the side and was not really thought out.
+
+* Menu:
+
+* Old Extension Problems:: Problems with the old mechanism.
+* Extension New Mechanism Goals:: Goals for the new mechanism.
+* Extension Other Design Decisions:: Some other design decisions.
+* Extension Mechanism Outline:: An outline of how it works.
+* Extension Future Growth:: Some room for future growth.
+
+
+File: gawk.info, Node: Old Extension Problems, Next: Extension New Mechanism Goals, Up: Extension Design
+
+16.3.1 Problems With The Old Mechanism
+--------------------------------------
+
+The old extension mechanism had several problems:
+
+ * It depended heavily upon `gawk' internals. Any time the `NODE'
+ structure(1) changed, an extension would have to be recompiled.
+ Furthermore, to really write extensions required understanding
+ something about `gawk''s internal functions. There was some
+ documentation in this Info file, but it was quite minimal.
+
+ * Being able to call into `gawk' from an extension required linker
+ facilities that are common on Unix-derived systems but that did
+ not work on Windows systems; users wanting extensions on Windows
+ had to statically link them into `gawk', even though Windows
+ supports dynamic loading of shared objects.
+
+ * The API would change occasionally as `gawk' changed; no
+ compatibility between versions was ever offered or planned for.
+
+ Despite the drawbacks, the `xgawk' project developers forked `gawk'
+and developed several significant extensions. They also enhanced
+`gawk''s facilities relating to file inclusion and shared object access.
+
+ A new API was desired for a long time, but only in 2012 did the
+`gawk' maintainer and the `xgawk' developers finally start working on
+it together. More information about the `xgawk' project is provided in
+*note gawkextlib::.
+
+ ---------- Footnotes ----------
+
+ (1) A critical central data structure inside `gawk'.
+
+
+File: gawk.info, Node: Extension New Mechanism Goals, Next: Extension Other Design Decisions, Prev: Old Extension Problems, Up: Extension Design
+
+16.3.2 Goals For A New Mechanism
+--------------------------------
+
+Some goals for the new API were:
+
+ * The API should be independent of `gawk' internals. Changes in
+ `gawk' internals should not be visible to the writer of an
+ extension function.
+
+ * The API should provide _binary_ compatibility across `gawk'
+ releases as long as the API itself does not change.
+
+ * The API should enable extensions written in C to have roughly the
+ same "appearance" to `awk'-level code as `awk' functions do. This
+ means that extensions should have:
+
+ - The ability to access function parameters.
+
+ - The ability to turn an undefined parameter into an array
+ (call by reference).
+
+ - The ability to create, access and update global variables.
+
+ - Easy access to all the elements of an array at once ("array
+ flattening") in order to loop over all the element in an easy
+ fashion for C code.
+
+ - The ability to create arrays (including `gawk''s true
+ multi-dimensional arrays).
+
+ Some additional important goals were:
+
+ * The API should use only features in ISO C 90, so that extensions
+ can be written using the widest range of C and C++ compilers. The
+ header should include the appropriate `#ifdef __cplusplus' and
+ `extern "C"' magic so that a C++ compiler could be used. (If
+ using C++, the runtime system has to be smart enough to call any
+ constructors and destructors, as `gawk' is a C program. As of this
+ writing, this has not been tested.)
+
+ * The API mechanism should not require access to `gawk''s symbols(1)
+ by the compile-time or dynamic linker, in order to enable creation
+ of extensions that also work on Windows.
+
+ During development, it became clear that there were other features
+that should be available to extensions, which were also subsequently
+provided:
+
+ * Extensions should have the ability to hook into `gawk''s I/O
+ redirection mechanism. In particular, the `xgawk' developers
+ provided a so-called "open hook" to take over reading records.
+ During development, this was generalized to allow extensions to
+ hook into input processing, output processing, and two-way I/O.
+
+ * An extension should be able to provide a "call back" function to
+ perform clean up actions when `gawk' exits.
+
+ * An extension should be able to provide a version string so that
+ `gawk''s `--version' option can provide information about
+ extensions as well.
+
+ ---------- Footnotes ----------
+
+ (1) The "symbols" are the variables and functions defined inside
+`gawk'. Access to these symbols by code external to `gawk' loaded
+dynamically at runtime is problematic on Windows.
+
+
+File: gawk.info, Node: Extension Other Design Decisions, Next: Extension Mechanism Outline, Prev: Extension New Mechanism Goals, Up: Extension Design
+
+16.3.3 Other Design Decisions
+-----------------------------
+
+As an arbitrary design decision, extensions can read the values of
+built-in variables and arrays (such as `ARGV' and `FS'), but cannot
+change them, with the exception of `PROCINFO'.
+
+ The reason for this is to prevent an extension function from
+affecting the flow of an `awk' program outside its control. While a
+real `awk' function can do what it likes, that is at the discretion of
+the programmer. An extension function should provide a service or make
+a C API available for use within `awk', and not mess with `FS' or
+`ARGC' and `ARGV'.
+
+ In addition, it becomes easy to start down a slippery slope. How
+much access to `gawk' facilities do extensions need? Do they need
+`getline'? What about calling `gsub()' or compiling regular
+expressions? What about calling into `awk' functions? (_That_ would be
+messy.)
+
+ In order to avoid these issues, the `gawk' developers chose to start
+with the simplest, most basic features that are still truly useful.
+
+ Another decision is that although `gawk' provides nice things like
+MPFR, and arrays indexed internally by integers, these features are not
+being brought out to the API in order to keep things simple and close to
+traditional `awk' semantics. (In fact, arrays indexed internally by
+integers are so transparent that they aren't even documented!)
+
+ Additionally, all functions in the API check that their pointer
+input parameters are not `NULL'. If they are, they return an error.
+(It is a good idea for extension code to verify that pointers received
+from `gawk' are not `NULL'. Such a thing should not happen, but the
+`gawk' developers are only human, and they have been known to
+occasionally make mistakes.)
+
+ With time, the API will undoubtedly evolve; the `gawk' developers
+expect this to be driven by user needs. For now, the current API seems
+to provide a minimal yet powerful set of features for creating
+extensions.
+
+
+File: gawk.info, Node: Extension Mechanism Outline, Next: Extension Future Growth, Prev: Extension Other Design Decisions, Up: Extension Design
+
+16.3.4 At A High Level How It Works
+-----------------------------------
+
+The requirement to avoid access to `gawk''s symbols is, at first
+glance, a difficult one to meet.
+
+ One design, apparently used by Perl and Ruby and maybe others, would
+be to make the mainline `gawk' code into a library, with the `gawk'
+utility a small C `main()' function linked against the library.
+
+ This seemed like the tail wagging the dog, complicating build and
+installation and making a simple copy of the `gawk' executable from one
+system to another (or one place to another on the same system!) into a
+chancy operation.
+
+ Pat Rankin suggested the solution that was adopted. Communication
+between `gawk' and an extension is two-way. First, when an extension
+is loaded, it is passed a pointer to a `struct' whose fields are
+function pointers. This is shown in *note load-extension::.
+
+ API
+ Struct
+ +---+
+ | |
+ +---+
+ +---------------| |
+ | +---+ dl_load(api_p, id);
+ | | | ___________________
+ | +---+ |
+ | +---------| | __________________ |
+ | | +---+ ||
+ | | | | ||
+ | | +---+ ||
+ | | +---| | ||
+ | | | +---+ \ || /
+ | | | \ /
+ v v v \/
++-------+-+---+-+---+-+------------------+--------------------+
+| |x| |x| |x| |OOOOOOOOOOOOOOOOOOOO|
+| |x| |x| |x| |OOOOOOOOOOOOOOOOOOOO|
+| |x| |x| |x| |OOOOOOOOOOOOOOOOOOOO|
++-------+-+---+-+---+-+------------------+--------------------+
+
+ gawk Main Program Address Space Extension
+Figure 16.1: Loading The Extension
+
+ The extension can call functions inside `gawk' through these
+function pointers, at runtime, without needing (link-time) access to
+`gawk''s symbols. One of these function pointers is to a function for
+"registering" new built-in functions. This is shown in *note
+load-new-function::.
+
+ register_ext_func({ "chdir", do_chdir, 1 });
+
+ +--------------------------------------------+
+ | |
+ V |
++-------+-+---+-+---+-+------------------+--------------+-+---+
+| |x| |x| |x| |OOOOOOOOOOOOOO|X|OOO|
+| |x| |x| |x| |OOOOOOOOOOOOOO|X|OOO|
+| |x| |x| |x| |OOOOOOOOOOOOOO|X|OOO|
++-------+-+---+-+---+-+------------------+--------------+-+---+
+
+ gawk Main Program Address Space Extension
+Figure 16.2: Loading The New Function
+
+ In the other direction, the extension registers its new functions
+with `gawk' by passing function pointers to the functions that provide
+the new feature (`do_chdir()', for example). `gawk' associates the
+function pointer with a name and can then call it, using a defined
+calling convention. This is shown in *note call-new-function::.
+
+ BEGIN {
+ chdir("/path") (*fnptr)(1);
+ }
+ +--------------------------------------------+
+ | |
+ | V
++-------+-+---+-+---+-+------------------+--------------+-+---+
+| |x| |x| |x| |OOOOOOOOOOOOOO|X|OOO|
+| |x| |x| |x| |OOOOOOOOOOOOOO|X|OOO|
+| |x| |x| |x| |OOOOOOOOOOOOOO|X|OOO|
++-------+-+---+-+---+-+------------------+--------------+-+---+
+
+ gawk Main Program Address Space Extension
+Figure 16.3: Calling The New Function
+
+ The `do_XXX()' function, in turn, then uses the function pointers in
+the API `struct' to do its work, such as updating variables or arrays,
+printing messages, setting `ERRNO', and so on.
+
+ Convenience macros in the `gawkapi.h' header file make calling
+through the function pointers look like regular function calls so that
+extension code is quite readable and understandable.
+
+ Although all of this sounds somewhat complicated, the result is that
+extension code is quite straightforward to write and to read. You can
+see this in the sample extensions `filefuncs.c' (*note Extension
+Example::) and also the `testext.c' code for testing the APIs.
+
+ Some other bits and pieces:
+
+ * The API provides access to `gawk''s `do_XXX' values, reflecting
+ command line options, like `do_lint', `do_profiling' and so on
+ (*note Extension API Variables::). These are informational: an
+ extension cannot affect these inside `gawk'. In addition,
+ attempting to assign to them produces a compile-time error.
+
+ * The API also provides major and minor version numbers, so that an
+ extension can check if the `gawk' it is loaded with supports the
+ facilities it was compiled with. (Version mismatches "shouldn't"
+ happen, but we all know how _that_ goes.) *Note Extension
+ Versioning::, for details.
+
+
+File: gawk.info, Node: Extension Future Growth, Prev: Extension Mechanism Outline, Up: Extension Design
+
+16.3.5 Room For Future Growth
+-----------------------------
+
+The API can later be expanded, in two ways:
+
+ * `gawk' passes an "extension id" into the extension when it first
+ loads the extension. The extension then passes this id back to
+ `gawk' with each function call. This mechanism allows `gawk' to
+ identify the extension calling into it, should it need to know.
+
+ * Similarly, the extension passes a "name space" into `gawk' when it
+ registers each extension function. This allows a future mechanism
+ for grouping extension functions and possibly avoiding name
+ conflicts.
+
+ Of course, as of this writing, no decisions have been made with
+respect to any of the above.
+
+
+File: gawk.info, Node: Extension API Description, Next: Extension Example, Prev: Extension Design, Up: Dynamic Extensions
+
+16.4 API Description
+====================
+
+This (rather large) minor node describes the API in detail.
+
+* Menu:
+
+* Extension API Functions Introduction:: Introduction to the API functions.
+* General Data Types:: The data types.
+* Requesting Values:: How to get a value.
+* Constructor Functions:: Functions for creating values.
+* Registration Functions:: Functions to register things with
+ `gawk'.
+* Printing Messages:: Functions for printing messages.
+* Updating `ERRNO':: Functions for updating `ERRNO'.
+* Accessing Parameters:: Functions for accessing parameters.
+* Symbol Table Access:: Functions for accessing global
+ variables.
+* Array Manipulation:: Functions for working with arrays.
+* Extension API Variables:: Variables provided by the API.
+* Extension API Boilerplate:: Boilerplate code for using the API.
+* Finding Extensions:: How `gawk' finds compiled
+ extensions.
+
+
+File: gawk.info, Node: Extension API Functions Introduction, Next: General Data Types, Up: Extension API Description
+
+16.4.1 Introduction
+-------------------
+
+Access to facilities within `gawk' are made available by calling
+through function pointers passed into your extension.
+
+ API function pointers are provided for the following kinds of
+operations:
+
+ * Registrations functions. You may register:
+ - extension functions,
+
+ - exit callbacks,
+
+ - a version string,
+
+ - input parsers,
+
+ - output wrappers,
+
+ - and two-way processors.
+ All of these are discussed in detail, later in this major node.
+
+ * Printing fatal, warning, and "lint" warning messages.
+
+ * Updating `ERRNO', or unsetting it.
+
+ * Accessing parameters, including converting an undefined parameter
+ into an array.
+
+ * Symbol table access: retrieving a global variable, creating one,
+ or changing one. This also includes the ability to create a scalar
+ variable that will be _constant_ within `awk' code.
+
+ * Creating and releasing cached values; this provides an efficient
+ way to use values for multiple variables and can be a big
+ performance win.
+
+ * Manipulating arrays:
+ - Retrieving, adding, deleting, and modifying elements
+
+ - Getting the count of elements in an array
+
+ - Creating a new array
+
+ - Clearing an array
+
+ - Flattening an array for easy C style looping over all its
+ indices and elements
+
+ Some points about using the API:
+
+ * The following types and/or macros and/or functions are referenced
+ in `gawkapi.h'. For correct use, you must therefore include the
+ corresponding standard header file _before_ including `gawkapi.h':
+
+ C Entity Header File
+ -----------------------------
+ `FILE' `<stdio.h>'
+ `NULL' `<stddef.h>'
+ `malloc()' `<stdlib.h>'
+ `memset()',`<string.h>'
+ `memcpy()'
+ `size_t' `<sys/types.h>'
+ `struct `<sys/stat.h>'
+ stat'
+
+ Due to portability concerns, especially to systems that are not
+ fully standards-compliant, it is your responsibility to include
+ the correct files in the correct way. This requirement is
+ necessary in order to keep `gawkapi.h' clean, instead of becoming
+ a portability hodge-podge as can be seen in the `gawk' source code.
+
+ To pass reasonable integer values for `ERRNO', you will also need
+ to include `<errno.h>'.
+
+ * The `gawkapi.h' file may be included more than once without ill
+ effect. Doing so, however, is poor coding practice.
+
+ * Although the API only uses ISO C 90 features, there is an
+ exception; the "constructor" functions use the `inline' keyword.
+ If your compiler does not support this keyword, you should either
+ place `-Dinline=''' on your command line, or use the GNU Autotools
+ and include a `config.h' file in your extensions.
+
+ * All pointers filled in by `gawk' are to memory managed by `gawk'
+ and should be treated by the extension as read-only. Memory for
+ _all_ strings passed into `gawk' from the extension _must_ come
+ from `malloc()' and is managed by `gawk' from then on.
+
+ * The API defines several simple structs that map values as seen
+ from `awk'. A value can be a `double', a string, or an array (as
+ in multidimensional arrays, or when creating a new array).
+ Strings maintain both pointer and length since embedded `NUL'
+ characters are allowed.
+
+ By intent, strings are maintained using the current multibyte
+ encoding (as defined by `LC_XXX' environment variables) and not
+ using wide characters. This matches how `gawk' stores strings
+ internally and also how characters are likely to be input and
+ output from files.
+
+ * When retrieving a value (such as a parameter or that of a global
+ variable or array element), the extension requests a specific type
+ (number, string, scalars, value cookie, array, or "undefined").
+ When the request is "undefined," the returned value will have the
+ real underlying type.
+
+ However, if the request and actual type don't match, the access
+ function returns "false" and fills in the type of the actual value
+ that is there, so that the extension can, e.g., print an error
+ message ("scalar passed where array expected").
+
+
+ While you may call the API functions by using the function pointers
+directly, the interface is not so pretty. To make extension code look
+more like regular code, the `gawkapi.h' header file defines several
+macros that you should use in your code. This minor node presents the
+macros as if they were functions.
+
+
+File: gawk.info, Node: General Data Types, Next: Requesting Values, Prev: Extension API Functions Introduction, Up: Extension API Description
+
+16.4.2 General Purpose Data Types
+---------------------------------
+
+ I have a true love/hate relationship with unions.
+ Arnold Robbins
+
+ That's the thing about unions: the compiler will arrange things so
+ they can accommodate both love and hate.
+ Chet Ramey
+
+ The extension API defines a number of simple types and structures
+for general purpose use. Additional, more specialized, data structures,
+are introduced in subsequent minor nodes, together with the functions
+that use them.
+
+`typedef void *awk_ext_id_t;'
+ A value of this type is received from `gawk' when an extension is
+ loaded. That value must then be passed back to `gawk' as the
+ first parameter of each API function.
+
+`#define awk_const ...'
+ This macro expands to `const' when compiling an extension, and to
+ nothing when compiling `gawk' itself. This makes certain fields
+ in the API data structures unwritable from extension code, while
+ allowing `gawk' to use them as it needs to.
+
+`typedef enum awk_bool {'
+
+` awk_false = 0,'
+
+` awk_true'
+
+`} awk_bool_t;'
+ A simple boolean type.
+
+`typedef struct awk_string {'
+` char *str; /* data */'
+` size_t len; /* length thereof, in chars */'
+`} awk_string_t;'
+ This represents a mutable string. `gawk' owns the memory pointed
+ to if it supplied the value. Otherwise, it takes ownership of the
+ memory pointed to. *Such memory must come from `malloc()'!*
+
+ As mentioned earlier, strings are maintained using the current
+ multibyte encoding.
+
+`typedef enum {'
+` AWK_UNDEFINED,'
+` AWK_NUMBER,'
+` AWK_STRING,'
+` AWK_ARRAY,'
+` AWK_SCALAR, /* opaque access to a variable */'
+` AWK_VALUE_COOKIE /* for updating a previously created value */'
+`} awk_valtype_t;'
+ This `enum' indicates the type of a value. It is used in the
+ following `struct'.
+
+`typedef struct awk_value {'
+` awk_valtype_t val_type;'
+` union {'
+` awk_string_t s;'
+` double d;'
+` awk_array_t a;'
+` awk_scalar_t scl;'
+` awk_value_cookie_t vc;'
+` } u;'
+`} awk_value_t;'
+ An "`awk' value." The `val_type' member indicates what kind of
+ value the `union' holds, and each member is of the appropriate
+ type.
+
+`#define str_value u.s'
+`#define num_value u.d'
+`#define array_cookie u.a'
+`#define scalar_cookie u.scl'
+`#define value_cookie u.vc'
+ These macros make accessing the fields of the `awk_value_t' more
+ readable.
+
+`typedef void *awk_scalar_t;'
+ Scalars can be represented as an opaque type. These values are
+ obtained from `gawk' and then passed back into it. This is
+ discussed in a general fashion below, and in more detail in *note
+ Symbol table by cookie::.
+
+`typedef void *awk_value_cookie_t;'
+ A "value cookie" is an opaque type representing a cached value.
+ This is also discussed in a general fashion below, and in more
+ detail in *note Cached values::.
+
+
+ Scalar values in `awk' are either numbers or strings. The
+`awk_value_t' struct represents values. The `val_type' member
+indicates what is in the `union'.
+
+ Representing numbers is easy--the API uses a C `double'. Strings
+require more work. Since `gawk' allows embedded `NUL' bytes in string
+values, a string must be represented as a pair containing a
+data-pointer and length. This is the `awk_string_t' type.
+
+ Identifiers (i.e., the names of global variables) can be associated
+with either scalar values or with arrays. In addition, `gawk' provides
+true arrays of arrays, where any given array element can itself be an
+array. Discussion of arrays is delayed until *note Array
+Manipulation::.
+
+ The various macros listed earlier make it easier to use the elements
+of the `union' as if they were fields in a `struct'; this is a common
+coding practice in C. Such code is easier to write and to read,
+however it remains _your_ responsibility to make sure that the
+`val_type' member correctly reflects the type of the value in the
+`awk_value_t'.
+
+ Conceptually, the first three members of the `union' (number, string,
+and array) are all that is needed for working with `awk' values.
+However, since the API provides routines for accessing and changing the
+value of global scalar variables only by using the variable's name,
+there is a performance penalty: `gawk' must find the variable each time
+it is accessed and changed. This turns out to be a real issue, not
+just a theoretical one.
+
+ Thus, if you know that your extension will spend considerable time
+reading and/or changing the value of one or more scalar variables, you
+can obtain a "scalar cookie"(1) object for that variable, and then use
+the cookie for getting the variable's value or for changing the
+variable's value. This is the `awk_scalar_t' type and `scalar_cookie'
+macro. Given a scalar cookie, `gawk' can directly retrieve or modify
+the value, as required, without having to first find it.
+
+ The `awk_value_cookie_t' type and `value_cookie' macro are similar.
+If you know that you wish to use the same numeric or string _value_ for
+one or more variables, you can create the value once, retaining a
+"value cookie" for it, and then pass in that value cookie whenever you
+wish to set the value of a variable. This saves both storage space
+within the running `gawk' process as well as the time needed to create
+the value.
+
+ ---------- Footnotes ----------
+
+ (1) See the "cookie" entry in the Jargon file
+(http://catb.org/jargon/html/C/cookie.html) for a definition of
+"cookie", and the "magic cookie" entry in the Jargon file
+(http://catb.org/jargon/html/M/magic-cookie.html) for a nice example.
+See also the entry for "Cookie" in the *note Glossary::.
+
+
+File: gawk.info, Node: Requesting Values, Next: Constructor Functions, Prev: General Data Types, Up: Extension API Description
+
+16.4.3 Requesting Values
+------------------------
+
+All of the functions that return values from `gawk' work in the same
+way. You pass in an `awk_valtype_t' value to indicate what kind of
+value you expect. If the actual value matches what you requested, the
+function returns true and fills in the `awk_value_t' result.
+Otherwise, the function returns false, and the `val_type' member
+indicates the type of the actual value. You may then print an error
+message, or reissue the request for the actual value type, as
+appropriate. This behavior is summarized in *note
+table-value-types-returned::.
+
+ Type of Actual Value:
+--------------------------------------------------------------------------
+
+ String Number Array Undefined
+------------------------------------------------------------------------------
+ String String String false false
+ Number Number if can Number false false
+ be converted,
+ else false
+Type Array false false Array false
+Requested: Scalar Scalar Scalar false false
+ Undefined String Number Array Undefined
+ Value false false false false
+ Cookie
+
+Table 16.1: Value Types Returned
+
+
+File: gawk.info, Node: Constructor Functions, Next: Registration Functions, Prev: Requesting Values, Up: Extension API Description
+
+16.4.4 Constructor Functions and Convenience Macros
+---------------------------------------------------
+
+The API provides a number of "constructor" functions for creating
+string and numeric values, as well as a number of convenience macros.
+This node presents them all as function prototypes, in the way that
+extension code would use them.
+
+`static inline awk_value_t *'
+`make_const_string(const char *string, size_t length, awk_value_t *result)'
+ This function creates a string value in the `awk_value_t' variable
+ pointed to by `result'. It expects `string' to be a C string
+ constant (or other string data), and automatically creates a
+ _copy_ of the data for storage in `result'. It returns `result'.
+
+`static inline awk_value_t *'
+`make_malloced_string(const char *string, size_t length, awk_value_t *result)'
+ This function creates a string value in the `awk_value_t' variable
+ pointed to by `result'. It expects `string' to be a `char *' value
+ pointing to data previously obtained from `malloc()'. The idea here
+ is that the data is passed directly to `gawk', which assumes
+ responsibility for it. It returns `result'.
+
+`static inline awk_value_t *'
+`make_null_string(awk_value_t *result)'
+ This specialized function creates a null string (the "undefined"
+ value) in the `awk_value_t' variable pointed to by `result'. It
+ returns `result'.
+
+`static inline awk_value_t *'
+`make_number(double num, awk_value_t *result)'
+ This function simply creates a numeric value in the `awk_value_t'
+ variable pointed to by `result'.
+
+ Two convenience macros may be used for allocating storage from
+`malloc()' and `realloc()'. If the allocation fails, they cause `gawk'
+to exit with a fatal error message. They should be used as if they were
+procedure calls that do not return a value.
+
+`emalloc(pointer, type, size, message)'
+ The arguments to this macro are as follows:
+ `pointer'
+ The pointer variable to point at the allocated storage.
+
+ `type'
+ The type of the pointer variable, used to create a cast for
+ the call to `malloc()'.
+
+ `size'
+ The total number of bytes to be allocated.
+
+ `message'
+ A message to be prefixed to the fatal error message.
+ Typically this is the name of the function using the macro.
+
+ For example, you might allocate a string value like so:
+
+ awk_value_t result;
+ char *message;
+ const char greet[] = "Don't Panic!";
+
+ emalloc(message, char *, sizeof(greet), "myfunc");
+ strcpy(message, greet);
+ make_malloced_string(message, strlen(message), & result);
+
+`erealloc(pointer, type, size, message)'
+ This is like `emalloc()', but it calls `realloc()', instead of
+ `malloc()'. The arguments are the same as for the `emalloc()'
+ macro.
+
+
+File: gawk.info, Node: Registration Functions, Next: Printing Messages, Prev: Constructor Functions, Up: Extension API Description
+
+16.4.5 Registration Functions
+-----------------------------
+
+This minor node describes the API functions for registering parts of
+your extension with `gawk'.
+
+* Menu:
+
+* Extension Functions:: Registering extension functions.
+* Exit Callback Functions:: Registering an exit callback.
+* Extension Version String:: Registering a version string.
+* Input Parsers:: Registering an input parser.
+* Output Wrappers:: Registering an output wrapper.
+* Two-way processors:: Registering a two-way processor.
+
+
+File: gawk.info, Node: Extension Functions, Next: Exit Callback Functions, Up: Registration Functions
+
+16.4.5.1 Registering An Extension Function
+..........................................
+
+Extension functions are described by the following record:
+
+ typedef struct awk_ext_func {
+ const char *name;
+ awk_value_t *(*function)(int num_actual_args, awk_value_t *result);
+ size_t num_expected_args;
+ } awk_ext_func_t;
+
+ The fields are:
+
+`const char *name;'
+ The name of the new function. `awk' level code calls the function
+ by this name. This is a regular C string.
+
+`awk_value_t *(*function)(int num_actual_args, awk_value_t *result);'
+ This is a pointer to the C function that provides the desired
+ functionality. The function must fill in the result with either a
+ number or a string. `awk' takes ownership of any string memory.
+ As mentioned earlier, string memory *must* come from `malloc()'.
+
+ The function must return the value of `result'. This is for the
+ convenience of the calling code inside `gawk'.
+
+`size_t num_expected_args;'
+ This is the number of arguments the function expects to receive.
+ Each extension function may decide what to do if the number of
+ arguments isn't what it expected. Following `awk' functions, it
+ is likely OK to ignore extra arguments.
+
+ Once you have a record representing your extension function, you
+register it with `gawk' using this API function:
+
+`awk_bool_t add_ext_func(const char *namespace, const awk_ext_func_t *func);'
+ This function returns true upon success, false otherwise. The
+ `namespace' parameter is currently not used; you should pass in an
+ empty string (`""'). The `func' pointer is the address of a
+ `struct' representing your function, as just described.
+
+
+File: gawk.info, Node: Exit Callback Functions, Next: Extension Version String, Prev: Extension Functions, Up: Registration Functions
+
+16.4.5.2 Registering An Exit Callback Function
+..............................................
+
+An "exit callback" function is a function that `gawk' calls before it
+exits. Such functions are useful if you have general "clean up" tasks
+that should be performed in your extension (such as closing data base
+connections or other resource deallocations). You can register such a
+function with `gawk' using the following function.
+
+`void awk_atexit(void (*funcp)(void *data, int exit_status),'
+` void *arg0);'
+ The parameters are:
+ `funcp'
+ A pointer to the function to be called before `gawk' exits.
+ The `data' parameter will be the original value of `arg0'.
+ The `exit_status' parameter is the exit status value that
+ `gawk' will pass to the `exit()' system call.
+
+ `arg0'
+ A pointer to private data which `gawk' saves in order to pass
+ to the function pointed to by `funcp'.
+
+ Exit callback functions are called in Last-In-First-Out (LIFO)
+order--that is, in the reverse order in which they are registered with
+`gawk'.
+
+
+File: gawk.info, Node: Extension Version String, Next: Input Parsers, Prev: Exit Callback Functions, Up: Registration Functions
+
+16.4.5.3 Registering An Extension Version String
+................................................
+
+You can register a version string which indicates the name and version
+of your extension, with `gawk', as follows:
+
+`void register_ext_version(const char *version);'
+ Register the string pointed to by `version' with `gawk'. `gawk'
+ does _not_ copy the `version' string, so it should not be changed.
+
+ `gawk' prints all registered extension version strings when it is
+invoked with the `--version' option.
+
+
+File: gawk.info, Node: Input Parsers, Next: Output Wrappers, Prev: Extension Version String, Up: Registration Functions
+
+16.4.5.4 Customized Input Parsers
+.................................
+
+By default, `gawk' reads text files as its input. It uses the value of
+`RS' to find the end of the record, and then uses `FS' (or
+`FIELDWIDTHS') to split it into fields (*note Reading Files::).
+Additionally, it sets the value of `RT' (*note Built-in Variables::).
+
+ If you want, you can provide your own custom input parser. An input
+parser's job is to return a record to the `gawk' record processing
+code, along with indicators for the value and length of the data to be
+used for `RT', if any.
+
+ To provide an input parser, you must first provide two functions
+(where XXX is a prefix name for your extension):
+
+`awk_bool_t XXX_can_take_file(const awk_input_buf_t *iobuf)'
+ This function examines the information available in `iobuf' (which
+ we discuss shortly). Based on the information there, it decides
+ if the input parser should be used for this file. If so, it
+ should return true. Otherwise, it should return false. It should
+ not change any state (variable values, etc.) within `gawk'.
+
+`awk_bool_t XXX_take_control_of(awk_input_buf_t *iobuf)'
+ When `gawk' decides to hand control of the file over to the input
+ parser, it calls this function. This function in turn must fill
+ in certain fields in the `awk_input_buf_t' structure, and ensure
+ that certain conditions are true. It should then return true. If
+ an error of some kind occurs, it should not fill in any fields,
+ and should return false; then `gawk' will not use the input parser.
+ The details are presented shortly.
+
+ Your extension should package these functions inside an
+`awk_input_parser_t', which looks like this:
+
+ typedef struct awk_input_parser {
+ const char *name; /* name of parser */
+ awk_bool_t (*can_take_file)(const awk_input_buf_t *iobuf);
+ awk_bool_t (*take_control_of)(awk_input_buf_t *iobuf);
+ awk_const struct awk_input_parser *awk_const next; /* for use by gawk */
+ } awk_input_parser_t;
+
+ The fields are:
+
+`const char *name;'
+ The name of the input parser. This is a regular C string.
+
+`awk_bool_t (*can_take_file)(const awk_input_buf_t *iobuf);'
+ A pointer to your `XXX_can_take_file()' function.
+
+`awk_bool_t (*take_control_of)(awk_input_buf_t *iobuf);'
+ A pointer to your `XXX_take_control_of()' function.
+
+`awk_const struct input_parser *awk_const next;'
+ This pointer is used by `gawk'. The extension cannot modify it.
+
+ The steps are as follows:
+
+ 1. Create a `static awk_input_parser_t' variable and initialize it
+ appropriately.
+
+ 2. When your extension is loaded, register your input parser with
+ `gawk' using the `register_input_parser()' API function (described
+ below).
+
+ An `awk_input_buf_t' looks like this:
+
+ typedef struct awk_input {
+ const char *name; /* filename */
+ int fd; /* file descriptor */
+ #define INVALID_HANDLE (-1)
+ void *opaque; /* private data for input parsers */
+ int (*get_record)(char **out, struct awk_input *iobuf,
+ int *errcode, char **rt_start, size_t *rt_len);
+ void (*close_func)(struct awk_input *iobuf);
+ struct stat sbuf; /* stat buf */
+ } awk_input_buf_t;
+
+ The fields can be divided into two categories: those for use
+(initially, at least) by `XXX_can_take_file()', and those for use by
+`XXX_take_control_of()'. The first group of fields and their uses are
+as follows:
+
+`const char *name;'
+ The name of the file.
+
+`int fd;'
+ A file descriptor for the file. If `gawk' was able to open the
+ file, then `fd' will _not_ be equal to `INVALID_HANDLE'.
+ Otherwise, it will.
+
+`struct stat sbuf;'
+ If file descriptor is valid, then `gawk' will have filled in this
+ structure via a call to the `fstat()' system call.
+
+ The `XXX_can_take_file()' function should examine these fields and
+decide if the input parser should be used for the file. The decision
+can be made based upon `gawk' state (the value of a variable defined
+previously by the extension and set by `awk' code), the name of the
+file, whether or not the file descriptor is valid, the information in
+the `struct stat', or any combination of the above.
+
+ Once `XXX_can_take_file()' has returned true, and `gawk' has decided
+to use your input parser, it calls `XXX_take_control_of()'. That
+function then fills in at least the `get_record' field of the
+`awk_input_buf_t'. It must also ensure that `fd' is not set to
+`INVALID_HANDLE'. All of the fields that may be filled by
+`XXX_take_control_of()' are as follows:
+
+`void *opaque;'
+ This is used to hold any state information needed by the input
+ parser for this file. It is "opaque" to `gawk'. The input parser
+ is not required to use this pointer.
+
+`int (*get_record)(char **out,'
+` struct awk_input *iobuf,'
+` int *errcode,'
+` char **rt_start,'
+` size_t *rt_len);'
+ This function pointer should point to a function that creates the
+ input records. Said function is the core of the input parser.
+ Its behavior is described below.
+
+`void (*close_func)(struct awk_input *iobuf);'
+ This function pointer should point to a function that does the
+ "tear down." It should release any resources allocated by
+ `XXX_take_control_of()'. It may also close the file. If it does
+ so, it should set the `fd' field to `INVALID_HANDLE'.
+
+ If `fd' is still not `INVALID_HANDLE' after the call to this
+ function, `gawk' calls the regular `close()' system call.
+
+ Having a "tear down" function is optional. If your input parser
+ does not need it, do not set this field. Then, `gawk' calls the
+ regular `close()' system call on the file descriptor, so it should
+ be valid.
+
+ The `XXX_get_record()' function does the work of creating input
+records. The parameters are as follows:
+
+`char **out'
+ This is a pointer to a `char *' variable which is set to point to
+ the record. `gawk' makes its own copy of the data, so the
+ extension must manage this storage.
+
+`struct awk_input *iobuf'
+ This is the `awk_input_buf_t' for the file. The fields should be
+ used for reading data (`fd') and for managing private state
+ (`opaque'), if any.
+
+`int *errcode'
+ If an error occurs, `*errcode' should be set to an appropriate
+ code from `<errno.h>'.
+
+`char **rt_start'
+`size_t *rt_len'
+ If the concept of a "record terminator" makes sense, then
+ `*rt_start' should be set to point to the data to be used for
+ `RT', and `*rt_len' should be set to the length of the data.
+ Otherwise, `*rt_len' should be set to zero. `gawk' makes its own
+ copy of this data, so the extension must manage the storage.
+
+ The return value is the length of the buffer pointed to by `*out',
+or `EOF' if end-of-file was reached or an error occurred.
+
+ It is guaranteed that `errcode' is a valid pointer, so there is no
+need to test for a `NULL' value. `gawk' sets `*errcode' to zero, so
+there is no need to set it unless an error occurs.
+
+ If an error does occur, the function should return `EOF' and set
+`*errcode' to a non-zero value. In that case, if `*errcode' does not
+equal -1, `gawk' automatically updates the `ERRNO' variable based on
+the value of `*errcode' (e.g., setting `*errcode = errno' should do the
+right thing).
+
+ `gawk' ships with a sample extension that reads directories,
+returning records for each entry in the directory (*note Extension
+Sample Readdir::). You may wish to use that code as a guide for writing
+your own input parser.
+
+ When writing an input parser, you should think about (and document)
+how it is expected to interact with `awk' code. You may want it to
+always be called, and take effect as appropriate (as the `readdir'
+extension does). Or you may want it to take effect based upon the
+value of an `awk' variable, as the XML extension from the `gawkextlib'
+project does (*note gawkextlib::). In the latter case, code in a
+`BEGINFILE' section can look at `FILENAME' and `ERRNO' to decide
+whether or not to activate an input parser (*note BEGINFILE/ENDFILE::).
+
+ You register your input parser with the following function:
+
+`void register_input_parser(awk_input_parser_t *input_parser);'
+ Register the input parser pointed to by `input_parser' with `gawk'.
+
+
+File: gawk.info, Node: Output Wrappers, Next: Two-way processors, Prev: Input Parsers, Up: Registration Functions
+
+16.4.5.5 Customized Output Wrappers
+...................................
+
+An "output wrapper" is the mirror image of an input parser. It allows
+an extension to take over the output to a file opened with the `>' or
+`>>' operators (*note Redirection::).
+
+ The output wrapper is very similar to the input parser structure:
+
+ typedef struct awk_output_wrapper {
+ const char *name; /* name of the wrapper */
+ awk_bool_t (*can_take_file)(const awk_output_buf_t *outbuf);
+ awk_bool_t (*take_control_of)(awk_output_buf_t *outbuf);
+ awk_const struct awk_output_wrapper *awk_const next; /* for use by gawk */
+ } awk_output_wrapper_t;
+
+ The members are as follows:
+
+`const char *name;'
+ This is the name of the output wrapper.
+
+`awk_bool_t (*can_take_file)(const awk_output_buf_t *outbuf);'
+ This points to a function that examines the information in the
+ `awk_output_buf_t' structure pointed to by `outbuf'. It should
+ return true if the output wrapper wants to take over the file, and
+ false otherwise. It should not change any state (variable values,
+ etc.) within `gawk'.
+
+`awk_bool_t (*take_control_of)(awk_output_buf_t *outbuf);'
+ The function pointed to by this field is called when `gawk'
+ decides to let the output wrapper take control of the file. It
+ should fill in appropriate members of the `awk_output_buf_t'
+ structure, as described below, and return true if successful,
+ false otherwise.
+
+`awk_const struct output_wrapper *awk_const next;'
+ This is for use by `gawk'.
+
+ The `awk_output_buf_t' structure looks like this:
+
+ typedef struct awk_output_buf {
+ const char *name; /* name of output file */
+ const char *mode; /* mode argument to fopen */
+ FILE *fp; /* stdio file pointer */
+ awk_bool_t redirected; /* true if a wrapper is active */
+ void *opaque; /* for use by output wrapper */
+ size_t (*gawk_fwrite)(const void *buf, size_t size, size_t count,
+ FILE *fp, void *opaque);
+ int (*gawk_fflush)(FILE *fp, void *opaque);
+ int (*gawk_ferror)(FILE *fp, void *opaque);
+ int (*gawk_fclose)(FILE *fp, void *opaque);
+ } awk_output_buf_t;
+
+ Here too, your extension will define `XXX_can_take_file()' and
+`XXX_take_control_of()' functions that examine and update data members
+in the `awk_output_buf_t'. The data members are as follows:
+
+`const char *name;'
+ The name of the output file.
+
+`const char *mode;'
+ The mode string (as would be used in the second argument to
+ `fopen()') with which the file was opened.
+
+`FILE *fp;'
+ The `FILE' pointer from `<stdio.h>'. `gawk' opens the file before
+ attempting to find an output wrapper.
+
+`awk_bool_t redirected;'
+ This field must be set to true by the `XXX_take_control_of()'
+ function.
+
+`void *opaque;'
+ This pointer is opaque to `gawk'. The extension should use it to
+ store a pointer to any private data associated with the file.
+
+`size_t (*gawk_fwrite)(const void *buf, size_t size, size_t count,'
+` FILE *fp, void *opaque);'
+`int (*gawk_fflush)(FILE *fp, void *opaque);'
+`int (*gawk_ferror)(FILE *fp, void *opaque);'
+`int (*gawk_fclose)(FILE *fp, void *opaque);'
+ These pointers should be set to point to functions that perform
+ the equivalent function as the `<stdio.h>' functions do, if
+ appropriate. `gawk' uses these function pointers for all output.
+ `gawk' initializes the pointers to point to internal, "pass
+ through" functions that just call the regular `<stdio.h>'
+ functions, so an extension only needs to redefine those functions
+ that are appropriate for what it does.
+
+ The `XXX_can_take_file()' function should make a decision based upon
+the `name' and `mode' fields, and any additional state (such as `awk'
+variable values) that is appropriate.
+
+ When `gawk' calls `XXX_take_control_of()', it should fill in the
+other fields, as appropriate, except for `fp', which it should just use
+normally.
+
+ You register your output wrapper with the following function:
+
+`void register_output_wrapper(awk_output_wrapper_t *output_wrapper);'
+ Register the output wrapper pointed to by `output_wrapper' with
+ `gawk'.
+
+
+File: gawk.info, Node: Two-way processors, Prev: Output Wrappers, Up: Registration Functions
+
+16.4.5.6 Customized Two-way Processors
+......................................
+
+A "two-way processor" combines an input parser and an output wrapper for
+two-way I/O with the `|&' operator (*note Redirection::). It makes
+identical use of the `awk_input_parser_t' and `awk_output_buf_t'
+structures as described earlier.
+
+ A two-way processor is represented by the following structure:
+
+ typedef struct awk_two_way_processor {
+ const char *name; /* name of the two-way processor */
+ awk_bool_t (*can_take_two_way)(const char *name);
+ awk_bool_t (*take_control_of)(const char *name,
+ awk_input_buf_t *inbuf,
+ awk_output_buf_t *outbuf);
+ awk_const struct awk_two_way_processor *awk_const next; /* for use by gawk */
+ } awk_two_way_processor_t;
+
+ The fields are as follows:
+
+`const char *name;'
+ The name of the two-way processor.
+
+`awk_bool_t (*can_take_two_way)(const char *name);'
+ This function returns true if it wants to take over two-way I/O
+ for this filename. It should not change any state (variable
+ values, etc.) within `gawk'.
+
+`awk_bool_t (*take_control_of)(const char *name,'
+` awk_input_buf_t *inbuf,'
+` awk_output_buf_t *outbuf);'
+ This function should fill in the `awk_input_buf_t' and
+ `awk_outut_buf_t' structures pointed to by `inbuf' and `outbuf',
+ respectively. These structures were described earlier.
+
+`awk_const struct two_way_processor *awk_const next;'
+ This is for use by `gawk'.
+
+ As with the input parser and output processor, you provide "yes I
+can take this" and "take over for this" functions,
+`XXX_can_take_two_way()' and `XXX_take_control_of()'.
+
+ You register your two-way processor with the following function:
+
+`void register_two_way_processor(awk_two_way_processor_t *two_way_processor);'
+ Register the two-way processor pointed to by `two_way_processor'
+ with `gawk'.
+
+
+File: gawk.info, Node: Printing Messages, Next: Updating `ERRNO', Prev: Registration Functions, Up: Extension API Description
+
+16.4.6 Printing Messages
+------------------------
+
+You can print different kinds of warning messages from your extension,
+as described below. Note that for these functions, you must pass in
+the extension id received from `gawk' when the extension was loaded.(1)
+
+`void fatal(awk_ext_id_t id, const char *format, ...);'
+ Print a message and then cause `gawk' to exit immediately.
+
+`void warning(awk_ext_id_t id, const char *format, ...);'
+ Print a warning message.
+
+`void lintwarn(awk_ext_id_t id, const char *format, ...);'
+ Print a "lint warning." Normally this is the same as printing a
+ warning message, but if `gawk' was invoked with `--lint=fatal',
+ then lint warnings become fatal error messages.
+
+ All of these functions are otherwise like the C `printf()' family of
+functions, where the `format' parameter is a string with literal
+characters and formatting codes intermixed.
+
+ ---------- Footnotes ----------
+
+ (1) Because the API uses only ISO C 90 features, it cannot make use
+of the ISO C 99 variadic macro feature to hide that parameter. More's
+the pity.
+
+
+File: gawk.info, Node: Updating `ERRNO', Next: Accessing Parameters, Prev: Printing Messages, Up: Extension API Description
+
+16.4.7 Updating `ERRNO'
+-----------------------
+
+The following functions allow you to update the `ERRNO' variable:
+
+`void update_ERRNO_int(int errno_val);'
+ Set `ERRNO' to the string equivalent of the error code in
+ `errno_val'. The value should be one of the defined error codes in
+ `<errno.h>', and `gawk' turns it into a (possibly translated)
+ string using the C `strerror()' function.
+
+`void update_ERRNO_string(const char *string);'
+ Set `ERRNO' directly to the string value of `ERRNO'. `gawk' makes
+ a copy of the value of `string'.
+
+`void unset_ERRNO();'
+ Unset `ERRNO'.
+
+
+File: gawk.info, Node: Accessing Parameters, Next: Symbol Table Access, Prev: Updating `ERRNO', Up: Extension API Description
+
+16.4.8 Accessing and Updating Parameters
+----------------------------------------
+
+Two functions give you access to the arguments (parameters) passed to
+your extension function. They are:
+
+`awk_bool_t get_argument(size_t count,'
+` awk_valtype_t wanted,'
+` awk_value_t *result);'
+ Fill in the `awk_value_t' structure pointed to by `result' with
+ the `count''th argument. Return true if the actual type matches
+ `wanted', false otherwise. In the latter case, `result->val_type'
+ indicates the actual type (*note Table 16.1:
+ table-value-types-returned.). Counts are zero based--the first
+ argument is numbered zero, the second one, and so on. `wanted'
+ indicates the type of value expected.
+
+`awk_bool_t set_argument(size_t count, awk_array_t array);'
+ Convert a parameter that was undefined into an array; this provides
+ call-by-reference for arrays. Return false if `count' is too big,
+ or if the argument's type is not undefined. *Note Array
+ Manipulation::, for more information on creating arrays.
+
+
+File: gawk.info, Node: Symbol Table Access, Next: Array Manipulation, Prev: Accessing Parameters, Up: Extension API Description
+
+16.4.9 Symbol Table Access
+--------------------------
+
+Two sets of routines provide access to global variables, and one set
+allows you to create and release cached values.
+
+* Menu:
+
+* Symbol table by name:: Accessing variables by name.
+* Symbol table by cookie:: Accessing variables by ``cookie''.
+* Cached values:: Creating and using cached values.
+
+
+File: gawk.info, Node: Symbol table by name, Next: Symbol table by cookie, Up: Symbol Table Access
+
+16.4.9.1 Variable Access and Update by Name
+...........................................
+
+The following routines provide the ability to access and update global
+`awk'-level variables by name. In compiler terminology, identifiers of
+different kinds are termed "symbols", thus the "sym" in the routines'
+names. The data structure which stores information about symbols is
+termed a "symbol table".
+
+`awk_bool_t sym_lookup(const char *name,'
+` awk_valtype_t wanted,'
+` awk_value_t *result);'
+ Fill in the `awk_value_t' structure pointed to by `result' with
+ the value of the variable named by the string `name', which is a
+ regular C string. `wanted' indicates the type of value expected.
+ Return true if the actual type matches `wanted', false otherwise
+ In the latter case, `result->val_type' indicates the actual type
+ (*note Table 16.1: table-value-types-returned.).
+
+`awk_bool_t sym_update(const char *name, awk_value_t *value);'
+ Update the variable named by the string `name', which is a regular
+ C string. The variable is added to `gawk''s symbol table if it is
+ not there. Return true if everything worked, false otherwise.
+
+ Changing types (scalar to array or vice versa) of an existing
+ variable is _not_ allowed, nor may this routine be used to update
+ an array. This routine cannot be used to update any of the
+ predefined variables (such as `ARGC' or `NF').
+
+`awk_bool_t sym_constant(const char *name, awk_value_t *value);'
+ Create a variable named by the string `name', which is a regular C
+ string, that has the constant value as given by `value'.
+ `awk'-level code cannot change the value of this variable.(1) The
+ extension may change the value of `name''s variable with
+ subsequent calls to this routine, and may also convert a variable
+ created by `sym_update()' into a constant. However, once a
+ variable becomes a constant, it cannot later be reverted into a
+ mutable variable.
+
+ ---------- Footnotes ----------
+
+ (1) There (currently) is no `awk'-level feature that provides this
+ability.
+
+
+File: gawk.info, Node: Symbol table by cookie, Next: Cached values, Prev: Symbol table by name, Up: Symbol Table Access
+
+16.4.9.2 Variable Access and Update by Cookie
+.............................................
+
+A "scalar cookie" is an opaque handle that provide access to a global
+variable or array. It is an optimization that avoids looking up
+variables in `gawk''s symbol table every time access is needed. This
+was discussed earlier, in *note General Data Types::.
+
+ The following functions let you work with scalar cookies.
+
+`awk_bool_t sym_lookup_scalar(awk_scalar_t cookie,'
+` awk_valtype_t wanted,'
+` awk_value_t *result);'
+ Retrieve the current value of a scalar cookie. Once you have
+ obtained a scalar_cookie using `sym_lookup()', you can use this
+ function to get its value more efficiently. Return false if the
+ value cannot be retrieved.
+
+`awk_bool_t sym_update_scalar(awk_scalar_t cookie, awk_value_t *value);'
+ Update the value associated with a scalar cookie. Return false if
+ the new value is not one of `AWK_STRING' or `AWK_NUMBER'. Here
+ too, the built-in variables may not be updated.
+
+ It is not obvious at first glance how to work with scalar cookies or
+what their raison de^tre really is. In theory, the `sym_lookup()' and
+`sym_update()' routines are all you really need to work with variables.
+For example, you might have code that looked up the value of a
+variable, evaluated a condition, and then possibly changed the value of
+the variable based on the result of that evaluation, like so:
+
+ /* do_magic --- do something really great */
+
+ static awk_value_t *
+ do_magic(int nargs, awk_value_t *result)
+ {
+ awk_value_t value;
+
+ if ( sym_lookup("MAGIC_VAR", AWK_NUMBER, & value)
+ && some_condition(value.num_value)) {
+ value.num_value += 42;
+ sym_update("MAGIC_VAR", & value);
+ }
+
+ return make_number(0.0, result);
+ }
+
+This code looks (and is) simple and straightforward. So what's the
+problem?
+
+ Consider what happens if `awk'-level code associated with your
+extension calls the `magic()' function (implemented in C by
+`do_magic()'), once per record, while processing hundreds of thousands
+or millions of records. The `MAGIC_VAR' variable is looked up in the
+symbol table once or twice per function call!
+
+ The symbol table lookup is really pure overhead; it is considerably
+more efficient to get a cookie that represents the variable, and use
+that to get the variable's value and update it as needed.(1)
+
+ Thus, the way to use cookies is as follows. First, install your
+extension's variable in `gawk''s symbol table using `sym_update()', as
+usual. Then get a scalar cookie for the variable using `sym_lookup()':
+
+ static awk_scalar_t magic_var_cookie; /* cookie for MAGIC_VAR */
+
+ static void
+ my_extension_init()
+ {
+ awk_value_t value;
+
+ /* install initial value */
+ sym_update("MAGIC_VAR", make_number(42.0, & value));
+
+ /* get cookie */
+ sym_lookup("MAGIC_VAR", AWK_SCALAR, & value);
+
+ /* save the cookie */
+ magic_var_cookie = value.scalar_cookie;
+ ...
+ }
+
+ Next, use the routines in this section for retrieving and updating
+the value through the cookie. Thus, `do_magic()' now becomes something
+like this:
+
+ /* do_magic --- do something really great */
+
+ static awk_value_t *
+ do_magic(int nargs, awk_value_t *result)
+ {
+ awk_value_t value;
+
+ if ( sym_lookup_scalar(magic_var_cookie, AWK_NUMBER, & value)
+ && some_condition(value.num_value)) {
+ value.num_value += 42;
+ sym_update_scalar(magic_var_cookie, & value);
+ }
+ ...
+
+ return make_number(0.0, result);
+ }
+
+ NOTE: The previous code omitted error checking for presentation
+ purposes. Your extension code should be more robust and carefully
+ check the return values from the API functions.
+
+ ---------- Footnotes ----------
+
+ (1) The difference is measurable and quite real. Trust us.
+
+
+File: gawk.info, Node: Cached values, Prev: Symbol table by cookie, Up: Symbol Table Access
+
+16.4.9.3 Creating and Using Cached Values
+.........................................
+
+The routines in this section allow you to create and release cached
+values. As with scalar cookies, in theory, cached values are not
+necessary. You can create numbers and strings using the functions in
+*note Constructor Functions::. You can then assign those values to
+variables using `sym_update()' or `sym_update_scalar()', as you like.
+
+ However, you can understand the point of cached values if you
+remember that _every_ string value's storage _must_ come from
+`malloc()'. If you have 20 variables, all of which have the same
+string value, you must create 20 identical copies of the string.(1)
+
+ It is clearly more efficient, if possible, to create a value once,
+and then tell `gawk' to reuse the value for multiple variables. That is
+what the routines in this section let you do. The functions are as
+follows:
+
+`awk_bool_t create_value(awk_value_t *value, awk_value_cookie_t *result);'
+ Create a cached string or numeric value from `value' for efficient
+ later assignment. Only `AWK_NUMBER' and `AWK_STRING' values are
+ allowed. Any other type is rejected. While `AWK_UNDEFINED' could
+ be allowed, doing so would result in inferior performance.
+
+`awk_bool_t release_value(awk_value_cookie_t vc);'
+ Release the memory associated with a value cookie obtained from
+ `create_value()'.
+
+ You use value cookies in a fashion similar to the way you use scalar
+cookies. In the extension initialization routine, you create the value
+cookie:
+
+ static awk_value_cookie_t answer_cookie; /* static value cookie */
+
+ static void
+ my_extension_init()
+ {
+ awk_value_t value;
+ char *long_string;
+ size_t long_string_len;
+
+ /* code from earlier */
+ ...
+ /* ... fill in long_string and long_string_len ... */
+ make_malloced_string(long_string, long_string_len, & value);
+ create_value(& value, & answer_cookie); /* create cookie */
+ ...
+ }
+
+ Once the value is created, you can use it as the value of any number
+of variables:
+
+ static awk_value_t *
+ do_magic(int nargs, awk_value_t *result)
+ {
+ awk_value_t new_value;
+
+ ... /* as earlier */
+
+ value.val_type = AWK_VALUE_COOKIE;
+ value.value_cookie = answer_cookie;
+ sym_update("VAR1", & value);
+ sym_update("VAR2", & value);
+ ...
+ sym_update("VAR100", & value);
+ ...
+ }
+
+Using value cookies in this way saves considerable storage, since all of
+`VAR1' through `VAR100' share the same value.
+
+ You might be wondering, "Is this sharing problematic? What happens
+if `awk' code assigns a new value to `VAR1', are all the others be
+changed too?"
+
+ That's a great question. The answer is that no, it's not a problem.
+Internally, `gawk' uses reference-counted strings. This means that many
+variables can share the same string, and `gawk' keeps track of the
+usage. When a variable's value changes, `gawk' simply decrements the
+reference count on the old value and updates the variable to use the
+new value.
+
+ Finally, as part of your clean up action (*note Exit Callback
+Functions::) you should release any cached values that you created,
+using `release_value()'.
+
+ ---------- Footnotes ----------
+
+ (1) Numeric values are clearly less problematic, requiring only a C
+`double' to store.
+
+
+File: gawk.info, Node: Array Manipulation, Next: Extension API Variables, Prev: Symbol Table Access, Up: Extension API Description
+
+16.4.10 Array Manipulation
+--------------------------
+
+The primary data structure(1) in `awk' is the associative array (*note
+Arrays::). Extensions need to be able to manipulate `awk' arrays. The
+API provides a number of data structures for working with arrays,
+functions for working with individual elements, and functions for
+working with arrays as a whole. This includes the ability to "flatten"
+an array so that it is easy for C code to traverse every element in an
+array. The array data structures integrate nicely with the data
+structures for values to make it easy to both work with and create true
+arrays of arrays (*note General Data Types::).
+
+* Menu:
+
+* Array Data Types:: Data types for working with arrays.
+* Array Functions:: Functions for working with arrays.
+* Flattening Arrays:: How to flatten arrays.
+* Creating Arrays:: How to create and populate arrays.
+
+ ---------- Footnotes ----------
+
+ (1) Okay, the only data structure.
+
+
+File: gawk.info, Node: Array Data Types, Next: Array Functions, Up: Array Manipulation
+
+16.4.10.1 Array Data Types
+..........................
+
+The data types associated with arrays are listed below.
+
+`typedef void *awk_array_t;'
+ If you request the value of an array variable, you get back an
+ `awk_array_t' value. This value is opaque(1) to the extension; it
+ uniquely identifies the array but can only be used by passing it
+ into API functions or receiving it from API functions. This is
+ very similar to way `FILE *' values are used with the `<stdio.h>'
+ library routines.
+
+`typedef struct awk_element {'
+` /* convenience linked list pointer, not used by gawk */'
+` struct awk_element *next;'
+` enum {'
+` AWK_ELEMENT_DEFAULT = 0, /* set by gawk */'
+` AWK_ELEMENT_DELETE = 1 /* set by extension if should be deleted */'
+` } flags;'
+` awk_value_t index;'
+` awk_value_t value;'
+`} awk_element_t;'
+ The `awk_element_t' is a "flattened" array element. `awk' produces
+ an array of these inside the `awk_flat_array_t' (see the next
+ item). Individual elements may be marked for deletion. New
+ elements must be added individually, one at a time, using the
+ separate API for that purpose. The fields are as follows:
+
+ `struct awk_element *next;'
+ This pointer is for the convenience of extension writers. It
+ allows an extension to create a linked list of new elements
+ that can then be added to an array in a loop that traverses
+ the list.
+
+ `enum { ... } flags;'
+ A set of flag values that convey information between `gawk'
+ and the extension. Currently there is only one:
+ `AWK_ELEMENT_DELETE'. Setting it causes `gawk' to delete the
+ element from the original array upon release of the flattened
+ array.
+
+ `index'
+ `value'
+ The index and value of the element, respectively. _All_
+ memory pointed to by `index' and `value' belongs to `gawk'.
+
+`typedef struct awk_flat_array {'
+` awk_const void *awk_const opaque1; /* private data for use by gawk */'
+` awk_const void *awk_const opaque2; /* private data for use by gawk */'
+` awk_const size_t count; /* how many elements */'
+` awk_element_t elements[1]; /* will be extended */'
+`} awk_flat_array_t;'
+ This is a flattened array. When an extension gets one of these
+ from `gawk', the `elements' array is of actual size `count'. The
+ `opaque1' and `opaque2' pointers are for use by `gawk'; therefore
+ they are marked `awk_const' so that the extension cannot modify
+ them.
+
+ ---------- Footnotes ----------
+
+ (1) It is also a "cookie," but the `gawk' developers did not wish to
+overuse this term.
+
+
+File: gawk.info, Node: Array Functions, Next: Flattening Arrays, Prev: Array Data Types, Up: Array Manipulation
+
+16.4.10.2 Array Functions
+.........................
+
+The following functions relate to individual array elements.
+
+`awk_bool_t get_element_count(awk_array_t a_cookie, size_t *count);'
+ For the array represented by `a_cookie', return in `*count' the
+ number of elements it contains. A subarray counts as a single
+ element. Return false if there is an error.
+
+`awk_bool_t get_array_element(awk_array_t a_cookie,'
+` const awk_value_t *const index,'
+` awk_valtype_t wanted,'
+` awk_value_t *result);'
+ For the array represented by `a_cookie', return in `*result' the
+ value of the element whose index is `index'. `wanted' specifies
+ the type of value you wish to retrieve. Return false if `wanted'
+ does not match the actual type or if `index' is not in the array
+ (*note Table 16.1: table-value-types-returned.).
+
+ The value for `index' can be numeric, in which case `gawk'
+ converts it to a string. Using non-integral values is possible, but
+ requires that you understand how such values are converted to
+ strings (*note Conversion::); thus using integral values is safest.
+
+ As with _all_ strings passed into `gawk' from an extension, the
+ string value of `index' must come from `malloc()', and `gawk'
+ releases the storage.
+
+`awk_bool_t set_array_element(awk_array_t a_cookie,'
+` const awk_value_t *const index,'
+` const awk_value_t *const value);'
+ In the array represented by `a_cookie', create or modify the
+ element whose index is given by `index'. The `ARGV' and `ENVIRON'
+ arrays may not be changed.
+
+`awk_bool_t set_array_element_by_elem(awk_array_t a_cookie,'
+` awk_element_t element);'
+ Like `set_array_element()', but take the `index' and `value' from
+ `element'. This is a convenience macro.
+
+`awk_bool_t del_array_element(awk_array_t a_cookie,'
+` const awk_value_t* const index);'
+ Remove the element with the given index from the array represented
+ by `a_cookie'. Return true if the element was removed, or false
+ if the element did not exist in the array.
+
+ The following functions relate to arrays as a whole:
+
+`awk_array_t create_array();'
+ Create a new array to which elements may be added. *Note Creating
+ Arrays::, for a discussion of how to create a new array and add
+ elements to it.
+
+`awk_bool_t clear_array(awk_array_t a_cookie);'
+ Clear the array represented by `a_cookie'. Return false if there
+ was some kind of problem, true otherwise. The array remains an
+ array, but after calling this function, it has no elements. This
+ is equivalent to using the `delete' statement (*note Delete::).
+
+`awk_bool_t flatten_array(awk_array_t a_cookie, awk_flat_array_t **data);'
+ For the array represented by `a_cookie', create an
+ `awk_flat_array_t' structure and fill it in. Set the pointer whose
+ address is passed as `data' to point to this structure. Return
+ true upon success, or false otherwise. *Note Flattening Arrays::,
+ for a discussion of how to flatten an array and work with it.
+
+`awk_bool_t release_flattened_array(awk_array_t a_cookie,'
+` awk_flat_array_t *data);'
+ When done with a flattened array, release the storage using this
+ function. You must pass in both the original array cookie, and
+ the address of the created `awk_flat_array_t' structure. The
+ function returns true upon success, false otherwise.
+
+
+File: gawk.info, Node: Flattening Arrays, Next: Creating Arrays, Prev: Array Functions, Up: Array Manipulation
+
+16.4.10.3 Working With All The Elements of an Array
+...................................................
+
+To "flatten" an array is create a structure that represents the full
+array in a fashion that makes it easy for C code to traverse the entire
+array. Test code in `extension/testext.c' does this, and also serves
+as a nice example to show how to use the APIs.
+
+ First, the `gawk' script that drives the test extension:
+
+ @load "testext"
+ BEGIN {
+ n = split("blacky rusty sophie raincloud lucky", pets)
+ printf("pets has %d elements\n", length(pets))
+ ret = dump_array_and_delete("pets", "3")
+ printf("dump_array_and_delete(pets) returned %d\n", ret)
+ if ("3" in pets)
+ printf("dump_array_and_delete() did NOT remove index \"3\"!\n")
+ else
+ printf("dump_array_and_delete() did remove index \"3\"!\n")
+ print ""
+ }
+
+This code creates an array with `split()' (*note String Functions::)
+and then calls `dump_and_delete()'. That function looks up the array
+whose name is passed as the first argument, and deletes the element at
+the index passed in the second argument. It then prints the return
+value and checks if the element was indeed deleted. Here is the C code
+that implements `dump_array_and_delete()'. It has been edited slightly
+for presentation.
+
+ The first part declares variables, sets up the default return value
+in `result', and checks that the function was called with the correct
+number of arguments:
+
+ static awk_value_t *
+ dump_array_and_delete(int nargs, awk_value_t *result)
+ {
+ awk_value_t value, value2, value3;
+ awk_flat_array_t *flat_array;
+ size_t count;
+ char *name;
+ int i;
+
+ assert(result != NULL);
+ make_number(0.0, result);
+
+ if (nargs != 2) {
+ printf("dump_array_and_delete: nargs not right "
+ "(%d should be 2)\n", nargs);
+ goto out;
+ }
+
+ The function then proceeds in steps, as follows. First, retrieve the
+name of the array, passed as the first argument. Then retrieve the
+array itself. If either operation fails, print error messages and
+return:
+
+ /* get argument named array as flat array and print it */
+ if (get_argument(0, AWK_STRING, & value)) {
+ name = value.str_value.str;
+ if (sym_lookup(name, AWK_ARRAY, & value2))
+ printf("dump_array_and_delete: sym_lookup of %s passed\n",
+ name);
+ else {
+ printf("dump_array_and_delete: sym_lookup of %s failed\n",
+ name);
+ goto out;
+ }
+ } else {
+ printf("dump_array_and_delete: get_argument(0) failed\n");
+ goto out;
+ }
+
+ For testing purposes and to make sure that the C code sees the same
+number of elements as the `awk' code, the second step is to get the
+count of elements in the array and print it:
+
+ if (! get_element_count(value2.array_cookie, & count)) {
+ printf("dump_array_and_delete: get_element_count failed\n");
+ goto out;
+ }
+
+ printf("dump_array_and_delete: incoming size is %lu\n",
+ (unsigned long) count);
+
+ The third step is to actually flatten the array, and then to double
+check that the count in the `awk_flat_array_t' is the same as the count
+just retrieved:
+
+ if (! flatten_array(value2.array_cookie, & flat_array)) {
+ printf("dump_array_and_delete: could not flatten array\n");
+ goto out;
+ }
+
+ if (flat_array->count != count) {
+ printf("dump_array_and_delete: flat_array->count (%lu)"
+ " != count (%lu)\n",
+ (unsigned long) flat_array->count,
+ (unsigned long) count);
+ goto out;
+ }
+
+ The fourth step is to retrieve the index of the element to be
+deleted, which was passed as the second argument. Remember that
+argument counts passed to `get_argument()' are zero-based, thus the
+second argument is numbered one:
+
+ if (! get_argument(1, AWK_STRING, & value3)) {
+ printf("dump_array_and_delete: get_argument(1) failed\n");
+ goto out;
+ }
+
+ The fifth step is where the "real work" is done. The function loops
+over every element in the array, printing the index and element values.
+In addition, upon finding the element with the index that is supposed
+to be deleted, the function sets the `AWK_ELEMENT_DELETE' bit in the
+`flags' field of the element. When the array is released, `gawk'
+traverses the flattened array, and deletes any element which have this
+flag bit set:
+
+ for (i = 0; i < flat_array->count; i++) {
+ printf("\t%s[\"%.*s\"] = %s\n",
+ name,
+ (int) flat_array->elements[i].index.str_value.len,
+ flat_array->elements[i].index.str_value.str,
+ valrep2str(& flat_array->elements[i].value));
+
+ if (strcmp(value3.str_value.str,
+ flat_array->elements[i].index.str_value.str)
+ == 0) {
+ flat_array->elements[i].flags |= AWK_ELEMENT_DELETE;
+ printf("dump_array_and_delete: marking element \"%s\" "
+ "for deletion\n",
+ flat_array->elements[i].index.str_value.str);
+ }
+ }
+
+ The sixth step is to release the flattened array. This tells `gawk'
+that the extension is no longer using the array, and that it should
+delete any elements marked for deletion. `gawk' also frees any storage
+that was allocated, so you should not use the pointer (`flat_array' in
+this code) once you have called `release_flattened_array()':
+
+ if (! release_flattened_array(value2.array_cookie, flat_array)) {
+ printf("dump_array_and_delete: could not release flattened array\n");
+ goto out;
+ }
+
+ Finally, since everything was successful, the function sets the
+return value to success, and returns:
+
+ make_number(1.0, result);
+ out:
+ return result;
+ }
+
+ Here is the output from running this part of the test:
+
+ pets has 5 elements
+ dump_array_and_delete: sym_lookup of pets passed
+ dump_array_and_delete: incoming size is 5
+ pets["1"] = "blacky"
+ pets["2"] = "rusty"
+ pets["3"] = "sophie"
+ dump_array_and_delete: marking element "3" for deletion
+ pets["4"] = "raincloud"
+ pets["5"] = "lucky"
+ dump_array_and_delete(pets) returned 1
+ dump_array_and_delete() did remove index "3"!
+
+
+File: gawk.info, Node: Creating Arrays, Prev: Flattening Arrays, Up: Array Manipulation
+
+16.4.10.4 How To Create and Populate Arrays
+...........................................
+
+Besides working with arrays created by `awk' code, you can create
+arrays and populate them as you see fit, and then `awk' code can access
+them and manipulate them.
+
+ There are two important points about creating arrays from extension
+code:
+
+ 1. You must install a new array into `gawk''s symbol table
+ immediately upon creating it. Once you have done so, you can then
+ populate the array.
+
+ Similarly, if installing a new array as a subarray of an existing
+ array, you must add the new array to its parent before adding any
+ elements to it.
+
+ Thus, the correct way to build an array is to work "top down."
+ Create the array, and immediately install it in `gawk''s symbol
+ table using `sym_update()', or install it as an element in a
+ previously existing array using `set_element()'. We show example
+ code shortly.
+
+ 2. Due to gawk internals, after using `sym_update()' to install an
+ array into `gawk', you have to retrieve the array cookie from the
+ value passed in to `sym_update()' before doing anything else with
+ it, like so:
+
+ awk_value_t index, value;
+ awk_array_t new_array;
+
+ make_const_string("an index", 8, & index);
+
+ new_array = create_array();
+ val.val_type = AWK_ARRAY;
+ val.array_cookie = new_array;
+
+ /* install array in the symbol table */
+ sym_update("array", & index, & val);
+
+ new_array = val.array_cookie; /* YOU MUST DO THIS */
+
+ If installing an array as a subarray, you must also retrieve the
+ value of the array cookie after the call to `set_element()'.
+
+ The following C code is a simple test extension to create an array
+with two regular elements and with a subarray. The leading `#include'
+directives and boilerplate variable declarations are omitted for
+brevity. The first step is to create a new array and then install it
+in the symbol table:
+
+ /* create_new_array --- create a named array */
+
+ static void
+ create_new_array()
+ {
+ awk_array_t a_cookie;
+ awk_array_t subarray;
+ awk_value_t index, value;
+
+ a_cookie = create_array();
+ value.val_type = AWK_ARRAY;
+ value.array_cookie = a_cookie;
+
+ if (! sym_update("new_array", & value))
+ printf("create_new_array: sym_update(\"new_array\") failed!\n");
+ a_cookie = value.array_cookie;
+
+Note how `a_cookie' is reset from the `array_cookie' field in the
+`value' structure.
+
+ The second step is to install two regular values into `new_array':
+
+ (void) make_const_string("hello", 5, & index);
+ (void) make_const_string("world", 5, & value);
+ if (! set_array_element(a_cookie, & index, & value)) {
+ printf("fill_in_array: set_array_element failed\n");
+ return;
+ }
+
+ (void) make_const_string("answer", 6, & index);
+ (void) make_number(42.0, & value);
+ if (! set_array_element(a_cookie, & index, & value)) {
+ printf("fill_in_array: set_array_element failed\n");
+ return;
+ }
+
+ The third step is to create the subarray and install it:
+
+ (void) make_const_string("subarray", 8, & index);
+ subarray = create_array();
+ value.val_type = AWK_ARRAY;
+ value.array_cookie = subarray;
+ if (! set_array_element(a_cookie, & index, & value)) {
+ printf("fill_in_array: set_array_element failed\n");
+ return;
+ }
+ subarray = value.array_cookie;
+
+ The final step is to populate the subarray with its own element:
+
+ (void) make_const_string("foo", 3, & index);
+ (void) make_const_string("bar", 3, & value);
+ if (! set_array_element(subarray, & index, & value)) {
+ printf("fill_in_array: set_array_element failed\n");
+ return;
+ }
+ }
+
+ Here is sample script that loads the extension and then dumps the
+array:
+
+ @load "subarray"
+
+ function dumparray(name, array, i)
+ {
+ for (i in array)
+ if (isarray(array[i]))
+ dumparray(name "[\"" i "\"]", array[i])
+ else
+ printf("%s[\"%s\"] = %s\n", name, i, array[i])
+ }
+
+ BEGIN {
+ dumparray("new_array", new_array);
+ }
+
+ Here is the result of running the script:
+
+ $ AWKLIBPATH=$PWD ./gawk -f subarray.awk
+ -| new_array["subarray"]["foo"] = bar
+ -| new_array["hello"] = world
+ -| new_array["answer"] = 42
+
+(*Note Finding Extensions::, for more information on the `AWKLIBPATH'
+environment variable.)
+
+
+File: gawk.info, Node: Extension API Variables, Next: Extension API Boilerplate, Prev: Array Manipulation, Up: Extension API Description
+
+16.4.11 API Variables
+---------------------
+
+The API provides two sets of variables. The first provides information
+about the version of the API (both with which the extension was
+compiled, and with which `gawk' was compiled). The second provides
+information about how `gawk' was invoked.
+
+* Menu:
+
+* Extension Versioning:: API Version information.
+* Extension API Informational Variables:: Variables providing information about
+ `gawk''s invocation.
+
+
+File: gawk.info, Node: Extension Versioning, Next: Extension API Informational Variables, Up: Extension API Variables
+
+16.4.11.1 API Version Constants and Variables
+.............................................
+
+The API provides both a "major" and a "minor" version number. The API
+versions are available at compile time as constants:
+
+`GAWK_API_MAJOR_VERSION'
+ The major version of the API.
+
+`GAWK_API_MINOR_VERSION'
+ The minor version of the API.
+
+ The minor version increases when new functions are added to the API.
+Such new functions are always added to the end of the API `struct'.
+
+ The major version increases (and the minor version is reset to zero)
+if any of the data types change size or member order, or if any of the
+existing functions change signature.
+
+ It could happen that an extension may be compiled against one version
+of the API but loaded by a version of `gawk' using a different version.
+For this reason, the major and minor API versions of the running `gawk'
+are included in the API `struct' as read-only constant integers:
+
+`api->major_version'
+ The major version of the running `gawk'.
+
+`api->minor_version'
+ The minor version of the running `gawk'.
+
+ It is up to the extension to decide if there are API
+incompatibilities. Typically a check like this is enough:
+
+ if (api->major_version != GAWK_API_MAJOR_VERSION
+ || api->minor_version < GAWK_API_MINOR_VERSION) {
+ fprintf(stderr, "foo_extension: version mismatch with gawk!\n");
+ fprintf(stderr, "\tmy version (%d, %d), gawk version (%d, %d)\n",
+ GAWK_API_MAJOR_VERSION, GAWK_API_MINOR_VERSION,
+ api->major_version, api->minor_version);
+ exit(1);
+ }
+
+ Such code is included in the boilerplate `dl_load_func()' macro
+provided in `gawkapi.h' (discussed later, in *note Extension API
+Boilerplate::).
+
+
+File: gawk.info, Node: Extension API Informational Variables, Prev: Extension Versioning, Up: Extension API Variables
+
+16.4.11.2 Informational Variables
+.................................
+
+The API provides access to several variables that describe whether the
+corresponding command-line options were enabled when `gawk' was
+invoked. The variables are:
+
+`do_lint'
+ This variable is true if `gawk' was invoked with `--lint' option
+ (*note Options::).
+
+`do_traditional'
+ This variable is true if `gawk' was invoked with `--traditional'
+ option.
+
+`do_profile'
+ This variable is true if `gawk' was invoked with `--profile'
+ option.
+
+`do_sandbox'
+ This variable is true if `gawk' was invoked with `--sandbox'
+ option.
+
+`do_debug'
+ This variable is true if `gawk' was invoked with `--debug' option.
+
+`do_mpfr'
+ This variable is true if `gawk' was invoked with `--bignum' option.
+
+ The value of `do_lint' can change if `awk' code modifies the `LINT'
+built-in variable (*note Built-in Variables::). The others should not
+change during execution.
+
+
+File: gawk.info, Node: Extension API Boilerplate, Next: Finding Extensions, Prev: Extension API Variables, Up: Extension API Description
+
+16.4.12 Boilerplate Code
+------------------------
+
+As mentioned earlier (*note Extension Mechanism Outline::), the function
+definitions as presented are really macros. To use these macros, your
+extension must provide a small amount of boilerplate code (variables and
+functions) towards the top of your source file, using pre-defined names
+as described below. The boilerplate needed is also provided in comments
+in the `gawkapi.h' header file:
+
+ /* Boiler plate code: */
+ int plugin_is_GPL_compatible;
+
+ static gawk_api_t *const api;
+ static awk_ext_id_t ext_id;
+ static const char *ext_version = NULL; /* or ... = "some string" */
+
+ static awk_ext_func_t func_table[] = {
+ { "name", do_name, 1 },
+ /* ... */
+ };
+
+ /* EITHER: */
+
+ static awk_bool_t (*init_func)(void) = NULL;
+
+ /* OR: */
+
+ static awk_bool_t
+ init_my_module(void)
+ {
+ ...
+ }
+
+ static awk_bool_t (*init_func)(void) = init_my_module;
+
+ dl_load_func(func_table, some_name, "name_space_in_quotes")
+
+ These variables and functions are as follows:
+
+`int plugin_is_GPL_compatible;'
+ This asserts that the extension is compatible with the GNU GPL
+ (*note Copying::). If your extension does not have this, `gawk'
+ will not load it (*note Plugin License::).
+
+`static gawk_api_t *const api;'
+ This global `static' variable should be set to point to the
+ `gawk_api_t' pointer that `gawk' passes to your `dl_load()'
+ function. This variable is used by all of the macros.
+
+`static awk_ext_id_t ext_id;'
+ This global static variable should be set to the `awk_ext_id_t'
+ value that `gawk' passes to your `dl_load()' function. This
+ variable is used by all of the macros.
+
+`static const char *ext_version = NULL; /* or ... = "some string" */'
+ This global `static' variable should be set either to `NULL', or
+ to point to a string giving the name and version of your extension.
+
+`static awk_ext_func_t func_table[] = { ... };'
+ This is an array of one or more `awk_ext_func_t' structures as
+ described earlier (*note Extension Functions::). It can then be
+ looped over for multiple calls to `add_ext_func()'.
+
+`static awk_bool_t (*init_func)(void) = NULL;'
+` OR'
+`static awk_bool_t init_my_module(void) { ... }'
+`static awk_bool_t (*init_func)(void) = init_my_module;'
+ If you need to do some initialization work, you should define a
+ function that does it (creates variables, opens files, etc.) and
+ then define the `init_func' pointer to point to your function.
+ The function should return `awk_false' upon failure, or `awk_true'
+ if everything goes well.
+
+ If you don't need to do any initialization, define the pointer and
+ initialize it to `NULL'.
+
+`dl_load_func(func_table, some_name, "name_space_in_quotes")'
+ This macro expands to a `dl_load()' function that performs all the
+ necessary initializations.
+
+ The point of the all the variables and arrays is to let the
+`dl_load()' function (from the `dl_load_func()' macro) do all the
+standard work. It does the following:
+
+ 1. Check the API versions. If the extension major version does not
+ match `gawk''s, or if the extension minor version is greater than
+ `gawk''s, it prints a fatal error message and exits.
+
+ 2. Load the functions defined in `func_table'. If any of them fails
+ to load, it prints a warning message but continues on.
+
+ 3. If the `init_func' pointer is not `NULL', call the function it
+ points to. If it returns `awk_false', print a warning message.
+
+ 4. If `ext_version' is not `NULL', register the version string with
+ `gawk'.
+
+
+File: gawk.info, Node: Finding Extensions, Prev: Extension API Boilerplate, Up: Extension API Description
+
+16.4.13 How `gawk' Finds Extensions
+-----------------------------------
+
+Compiled extensions have to be installed in a directory where `gawk'
+can find them. If `gawk' is configured and built in the default
+fashion, the directory in which to find extensions is
+`/usr/local/lib/gawk'. You can also specify a search path with a list
+of directories to search for compiled extensions. *Note AWKLIBPATH
+Variable::, for more information.
+
+
+File: gawk.info, Node: Extension Example, Next: Extension Samples, Prev: Extension API Description, Up: Dynamic Extensions
+
+16.5 Example: Some File Functions
+=================================
+
+ No matter where you go, there you are.
+ Buckaroo Bonzai
+
+ Two useful functions that are not in `awk' are `chdir()' (so that an
+`awk' program can change its directory) and `stat()' (so that an `awk'
+program can gather information about a file). This minor node
+implements these functions for `gawk' in an extension.
+
+* Menu:
+
+* Internal File Description:: What the new functions will do.
+* Internal File Ops:: The code for internal file operations.
+* Using Internal File Ops:: How to use an external extension.
+
+
+File: gawk.info, Node: Internal File Description, Next: Internal File Ops, Up: Extension Example
+
+16.5.1 Using `chdir()' and `stat()'
+-----------------------------------
+
+This minor node shows how to use the new functions at the `awk' level
+once they've been integrated into the running `gawk' interpreter.
+Using `chdir()' is very straightforward. It takes one argument, the new
+directory to change to:
+
+ @load "filefuncs"
+ ...
+ newdir = "/home/arnold/funstuff"
+ ret = chdir(newdir)
+ if (ret < 0) {
+ printf("could not change to %s: %s\n",
+ newdir, ERRNO) > "/dev/stderr"
+ exit 1
+ }
+ ...
+
+ The return value is negative if the `chdir()' failed, and `ERRNO'
+(*note Built-in Variables::) is set to a string indicating the error.
+
+ Using `stat()' is a bit more complicated. The C `stat()' function
+fills in a structure that has a fair amount of information. The right
+way to model this in `awk' is to fill in an associative array with the
+appropriate information:
+
+ file = "/home/arnold/.profile"
+ ret = stat(file, fdata)
+ if (ret < 0) {
+ printf("could not stat %s: %s\n",
+ file, ERRNO) > "/dev/stderr"
+ exit 1
+ }
+ printf("size of %s is %d bytes\n", file, fdata["size"])
+
+ The `stat()' function always clears the data array, even if the
+`stat()' fails. It fills in the following elements:
+
+`"name"'
+ The name of the file that was `stat()''ed.
+
+`"dev"'
+`"ino"'
+ The file's device and inode numbers, respectively.
+
+`"mode"'
+ The file's mode, as a numeric value. This includes both the file's
+ type and its permissions.
+
+`"nlink"'
+ The number of hard links (directory entries) the file has.
+
+`"uid"'
+`"gid"'
+ The numeric user and group ID numbers of the file's owner.
+
+`"size"'
+ The size in bytes of the file.
+
+`"blocks"'
+ The number of disk blocks the file actually occupies. This may not
+ be a function of the file's size if the file has holes.
+
+`"atime"'
+`"mtime"'
+`"ctime"'
+ The file's last access, modification, and inode update times,
+ respectively. These are numeric timestamps, suitable for
+ formatting with `strftime()' (*note Time Functions::).
+
+`"pmode"'
+ The file's "printable mode." This is a string representation of
+ the file's type and permissions, such as is produced by `ls
+ -l'--for example, `"drwxr-xr-x"'.
+
+`"type"'
+ A printable string representation of the file's type. The value
+ is one of the following:
+
+ `"blockdev"'
+ `"chardev"'
+ The file is a block or character device ("special file").
+
+ `"directory"'
+ The file is a directory.
+
+ `"fifo"'
+ The file is a named-pipe (also known as a FIFO).
+
+ `"file"'
+ The file is just a regular file.
+
+ `"socket"'
+ The file is an `AF_UNIX' ("Unix domain") socket in the
+ filesystem.
+
+ `"symlink"'
+ The file is a symbolic link.
+
+ Several additional elements may be present depending upon the
+operating system and the type of the file. You can test for them in
+your `awk' program by using the `in' operator (*note Reference to
+Elements::):
+
+`"blksize"'
+ The preferred block size for I/O to the file. This field is not
+ present on all POSIX-like systems in the C `stat' structure.
+
+`"linkval"'
+ If the file is a symbolic link, this element is the name of the
+ file the link points to (i.e., the value of the link).
+
+`"rdev"'
+`"major"'
+`"minor"'
+ If the file is a block or character device file, then these values
+ represent the numeric device number and the major and minor
+ components of that number, respectively.
+
+
+File: gawk.info, Node: Internal File Ops, Next: Using Internal File Ops, Prev: Internal File Description, Up: Extension Example
+
+16.5.2 C Code for `chdir()' and `stat()'
+----------------------------------------
+
+Here is the C code for these extensions.(1)
+
+ The file includes a number of standard header files, and then
+includes the `gawkapi.h' header file which provides the API definitions.
+Those are followed by the necessary variable declarations to make use
+of the API macros and boilerplate code (*note Extension API
+Boilerplate::).
+
+ #ifdef HAVE_CONFIG_H
+ #include <config.h>
+ #endif
+
+ #include <stdio.h>
+ #include <assert.h>
+ #include <errno.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <unistd.h>
+
+ #include <sys/types.h>
+ #include <sys/stat.h>
+
+ #include "gawkapi.h"
+
+ #include "gettext.h"
+ #define _(msgid) gettext(msgid)
+ #define N_(msgid) msgid
+
+ #include "gawkfts.h"
+ #include "stack.h"
+
+ static const gawk_api_t *api; /* for convenience macros to work */
+ static awk_ext_id_t *ext_id;
+ static awk_bool_t init_filefuncs(void);
+ static awk_bool_t (*init_func)(void) = init_filefuncs;
+ static const char *ext_version = "filefuncs extension: version 1.0";
+
+ int plugin_is_GPL_compatible;
+
+ By convention, for an `awk' function `foo()', the C function that
+implements it is called `do_foo()'. The function should have two
+arguments: the first is an `int' usually called `nargs', that
+represents the number of actual arguments for the function. The second
+is a pointer to an `awk_value_t', usually named `result'.
+
+ /* do_chdir --- provide dynamically loaded chdir() builtin for gawk */
+
+ static awk_value_t *
+ do_chdir(int nargs, awk_value_t *result)
+ {
+ awk_value_t newdir;
+ int ret = -1;
+
+ assert(result != NULL);
+
+ if (do_lint && nargs != 1)
+ lintwarn(ext_id,
+ _("chdir: called with incorrect number of arguments, "
+ "expecting 1"));
+
+ The `newdir' variable represents the new directory to change to,
+retrieved with `get_argument()'. Note that the first argument is
+numbered zero.
+
+ If the argument is retrieved successfully, the function calls the
+`chdir()' system call. If the `chdir()' fails, `ERRNO' is updated.
+
+ if (get_argument(0, AWK_STRING, & newdir)) {
+ ret = chdir(newdir.str_value.str);
+ if (ret < 0)
+ update_ERRNO_int(errno);
+ }
+
+ Finally, the function returns the return value to the `awk' level:
+
+ return make_number(ret, result);
+ }
+
+ The `stat()' extension is more involved. First comes a function
+that turns a numeric mode into a printable representation (e.g., 644
+becomes `-rw-r--r--'). This is omitted here for brevity:
+
+ /* format_mode --- turn a stat mode field into something readable */
+
+ static char *
+ format_mode(unsigned long fmode)
+ {
+ ...
+ }
+
+ Next comes a function for reading symbolic links, which is also
+omitted here for brevity:
+
+ /* read_symlink --- read a symbolic link into an allocated buffer.
+ ... */
+
+ static char *
+ read_symlink(const char *fname, size_t bufsize, ssize_t *linksize)
+ {
+ ...
+ }
+
+ Two helper functions simplify entering values in the array that will
+contain the result of the `stat()':
+
+ /* array_set --- set an array element */
+
+ static void
+ array_set(awk_array_t array, const char *sub, awk_value_t *value)
+ {
+ awk_value_t index;
+
+ set_array_element(array,
+ make_const_string(sub, strlen(sub), & index),
+ value);
+
+ }
+
+ /* array_set_numeric --- set an array element with a number */
+
+ static void
+ array_set_numeric(awk_array_t array, const char *sub, double num)
+ {
+ awk_value_t tmp;
+
+ array_set(array, sub, make_number(num, & tmp));
+ }
+
+ The following function does most of the work to fill in the
+`awk_array_t' result array with values obtained from a valid `struct
+stat'. It is done in a separate function to support the `stat()'
+function for `gawk' and also to support the `fts()' extension which is
+included in the same file but whose code is not shown here (*note
+Extension Sample File Functions::).
+
+ The first part of the function is variable declarations, including a
+table to map file types to strings:
+
+ /* fill_stat_array --- do the work to fill an array with stat info */
+
+ static int
+ fill_stat_array(const char *name, awk_array_t array, struct stat *sbuf)
+ {
+ char *pmode; /* printable mode */
+ const char *type = "unknown";
+ awk_value_t tmp;
+ static struct ftype_map {
+ unsigned int mask;
+ const char *type;
+ } ftype_map[] = {
+ { S_IFREG, "file" },
+ { S_IFBLK, "blockdev" },
+ { S_IFCHR, "chardev" },
+ { S_IFDIR, "directory" },
+ #ifdef S_IFSOCK
+ { S_IFSOCK, "socket" },
+ #endif
+ #ifdef S_IFIFO
+ { S_IFIFO, "fifo" },
+ #endif
+ #ifdef S_IFLNK
+ { S_IFLNK, "symlink" },
+ #endif
+ #ifdef S_IFDOOR /* Solaris weirdness */
+ { S_IFDOOR, "door" },
+ #endif /* S_IFDOOR */
+ };
+ int j, k;
+
+ The destination array is cleared, and then code fills in various
+elements based on values in the `struct stat':
+
+ /* empty out the array */
+ clear_array(array);
+
+ /* fill in the array */
+ array_set(array, "name", make_const_string(name, strlen(name),
+ & tmp));
+ array_set_numeric(array, "dev", sbuf->st_dev);
+ array_set_numeric(array, "ino", sbuf->st_ino);
+ array_set_numeric(array, "mode", sbuf->st_mode);
+ array_set_numeric(array, "nlink", sbuf->st_nlink);
+ array_set_numeric(array, "uid", sbuf->st_uid);
+ array_set_numeric(array, "gid", sbuf->st_gid);
+ array_set_numeric(array, "size", sbuf->st_size);
+ array_set_numeric(array, "blocks", sbuf->st_blocks);
+ array_set_numeric(array, "atime", sbuf->st_atime);
+ array_set_numeric(array, "mtime", sbuf->st_mtime);
+ array_set_numeric(array, "ctime", sbuf->st_ctime);
+
+ /* for block and character devices, add rdev,
+ major and minor numbers */
+ if (S_ISBLK(sbuf->st_mode) || S_ISCHR(sbuf->st_mode)) {
+ array_set_numeric(array, "rdev", sbuf->st_rdev);
+ array_set_numeric(array, "major", major(sbuf->st_rdev));
+ array_set_numeric(array, "minor", minor(sbuf->st_rdev));
+ }
+
+The latter part of the function makes selective additions to the
+destination array, depending upon the availability of certain members
+and/or the type of the file. It then returns zero, for success:
+
+ #ifdef HAVE_ST_BLKSIZE
+ array_set_numeric(array, "blksize", sbuf->st_blksize);
+ #endif /* HAVE_ST_BLKSIZE */
+
+ pmode = format_mode(sbuf->st_mode);
+ array_set(array, "pmode", make_const_string(pmode, strlen(pmode),
+ & tmp));
+
+ /* for symbolic links, add a linkval field */
+ if (S_ISLNK(sbuf->st_mode)) {
+ char *buf;
+ ssize_t linksize;
+
+ if ((buf = read_symlink(name, sbuf->st_size,
+ & linksize)) != NULL)
+ array_set(array, "linkval",
+ make_malloced_string(buf, linksize, & tmp));
+ else
+ warning(ext_id, _("stat: unable to read symbolic link `%s'"),
+ name);
+ }
+
+ /* add a type field */
+ type = "unknown"; /* shouldn't happen */
+ for (j = 0, k = sizeof(ftype_map)/sizeof(ftype_map[0]); j < k; j++) {
+ if ((sbuf->st_mode & S_IFMT) == ftype_map[j].mask) {
+ type = ftype_map[j].type;
+ break;
+ }
+ }
+
+ array_set(array, "type", make_const_string(type, strlen(type), &tmp));
+
+ return 0;
+ }
+
+ Finally, here is the `do_stat()' function. It starts with variable
+declarations and argument checking:
+
+ /* do_stat --- provide a stat() function for gawk */
+
+ static awk_value_t *
+ do_stat(int nargs, awk_value_t *result)
+ {
+ awk_value_t file_param, array_param;
+ char *name;
+ awk_array_t array;
+ int ret;
+ struct stat sbuf;
+ int (*statfunc)(const char *path, struct stat *sbuf) = lstat; /* default */
+
+ assert(result != NULL);
+
+ if (nargs != 2 && nargs != 3) {
+ if (do_lint)
+ lintwarn(ext_id, _("stat: called with wrong number of arguments"));
+ return make_number(-1, result);
+ }
+
+ The third argument to `stat()' was not discussed previously. This
+argument is optional. If present, it causes `stat()' to use the `stat()'
+system call instead of the `lstat()' system call.
+
+ Then comes the actual work. First, the function gets the arguments.
+Next, it gets the information for the file. The code use `lstat()'
+(instead of `stat()') to get the file information, in case the file is
+a symbolic link. If there's an error, it sets `ERRNO' and returns:
+
+ /* file is first arg, array to hold results is second */
+ if ( ! get_argument(0, AWK_STRING, & file_param)
+ || ! get_argument(1, AWK_ARRAY, & array_param)) {
+ warning(ext_id, _("stat: bad parameters"));
+ return make_number(-1, result);
+ }
+
+ if (nargs == 3) {
+ statfunc = stat;
+ }
+
+ name = file_param.str_value.str;
+ array = array_param.array_cookie;
+
+ /* always empty out the array */
+ clear_array(array);
+
+ /* stat the file, if error, set ERRNO and return */
+ ret = statfunc(name, & sbuf);
+ if (ret < 0) {
+ update_ERRNO_int(errno);
+ return make_number(ret, result);
+ }
+
+ The tedious work is done by `fill_stat_array()', shown earlier.
+When done, return the result from `fill_stat_array()':
+
+ ret = fill_stat_array(name, array, & sbuf);
+
+ return make_number(ret, result);
+ }
+
+ Finally, it's necessary to provide the "glue" that loads the new
+function(s) into `gawk'.
+
+ The `filefuncs' extension also provides an `fts()' function, which
+we omit here. For its sake there is an initialization function:
+
+ /* init_filefuncs --- initialization routine */
+
+ static awk_bool_t
+ init_filefuncs(void)
+ {
+ ...
+ }
+
+ We are almost done. We need an array of `awk_ext_func_t' structures
+for loading each function into `gawk':
+
+ static awk_ext_func_t func_table[] = {
+ { "chdir", do_chdir, 1 },
+ { "stat", do_stat, 2 },
+ { "fts", do_fts, 3 },
+ };
+
+ Each extension must have a routine named `dl_load()' to load
+everything that needs to be loaded. It is simplest to use the
+`dl_load_func()' macro in `gawkapi.h':
+
+ /* define the dl_load() function using the boilerplate macro */
+
+ dl_load_func(func_table, filefuncs, "")
+
+ And that's it! As an exercise, consider adding functions to
+implement system calls such as `chown()', `chmod()', and `umask()'.
+
+ ---------- Footnotes ----------
+
+ (1) This version is edited slightly for presentation. See
+`extension/filefuncs.c' in the `gawk' distribution for the complete
+version.
+
+
+File: gawk.info, Node: Using Internal File Ops, Prev: Internal File Ops, Up: Extension Example
+
+16.5.3 Integrating The Extensions
+---------------------------------
+
+Now that the code is written, it must be possible to add it at runtime
+to the running `gawk' interpreter. First, the code must be compiled.
+Assuming that the functions are in a file named `filefuncs.c', and IDIR
+is the location of the `gawkapi.h' header file, the following steps(1)
+create a GNU/Linux shared library:
+
+ $ gcc -fPIC -shared -DHAVE_CONFIG_H -c -O -g -IIDIR filefuncs.c
+ $ gcc -o filefuncs.so -shared filefuncs.o
+
+ Once the library exists, it is loaded by using the `@load' keyword.
+
+ # file testff.awk
+ @load "filefuncs"
+
+ BEGIN {
+ "pwd" | getline curdir # save current directory
+ close("pwd")
+
+ chdir("/tmp")
+ system("pwd") # test it
+ chdir(curdir) # go back
+
+ print "Info for testff.awk"
+ ret = stat("testff.awk", data)
+ print "ret =", ret
+ for (i in data)
+ printf "data[\"%s\"] = %s\n", i, data[i]
+ print "testff.awk modified:",
+ strftime("%m %d %y %H:%M:%S", data["mtime"])
+
+ print "\nInfo for JUNK"
+ ret = stat("JUNK", data)
+ print "ret =", ret
+ for (i in data)
+ printf "data[\"%s\"] = %s\n", i, data[i]
+ print "JUNK modified:", strftime("%m %d %y %H:%M:%S", data["mtime"])
+ }
+
+ The `AWKLIBPATH' environment variable tells `gawk' where to find
+shared libraries (*note Finding Extensions::). We set it to the
+current directory and run the program:
+
+ $ AWKLIBPATH=$PWD gawk -f testff.awk
+ -| /tmp
+ -| Info for testff.awk
+ -| ret = 0
+ -| data["blksize"] = 4096
+ -| data["mtime"] = 1350838628
+ -| data["mode"] = 33204
+ -| data["type"] = file
+ -| data["dev"] = 2053
+ -| data["gid"] = 1000
+ -| data["ino"] = 1719496
+ -| data["ctime"] = 1350838628
+ -| data["blocks"] = 8
+ -| data["nlink"] = 1
+ -| data["name"] = testff.awk
+ -| data["atime"] = 1350838632
+ -| data["pmode"] = -rw-rw-r--
+ -| data["size"] = 662
+ -| data["uid"] = 1000
+ -| testff.awk modified: 10 21 12 18:57:08
+ -|
+ -| Info for JUNK
+ -| ret = -1
+ -| JUNK modified: 01 01 70 02:00:00
+
+ ---------- Footnotes ----------
+
+ (1) In practice, you would probably want to use the GNU
+Autotools--Automake, Autoconf, Libtool, and Gettext--to configure and
+build your libraries. Instructions for doing so are beyond the scope of
+this Info file. *Note gawkextlib::, for WWW links to the tools.
+
+
+File: gawk.info, Node: Extension Samples, Next: gawkextlib, Prev: Extension Example, Up: Dynamic Extensions
+
+16.6 The Sample Extensions In The `gawk' Distribution
+=====================================================
+
+This minor node provides brief overviews of the sample extensions that
+come in the `gawk' distribution. Some of them are intended for
+production use, such the `filefuncs' and `readdir' extensions. Others
+mainly provide example code that shows how to use the extension API.
+
+* Menu:
+
+* Extension Sample File Functions:: The file functions sample.
+* Extension Sample Fnmatch:: An interface to `fnmatch()'.
+* Extension Sample Fork:: An interface to `fork()' and other
+ process functions.
+* Extension Sample Ord:: Character to value to character
+ conversions.
+* Extension Sample Readdir:: An interface to `readdir()'.
+* Extension Sample Revout:: Reversing output sample output wrapper.
+* Extension Sample Rev2way:: Reversing data sample two-way processor.
+* Extension Sample Read write array:: Serializing an array to a file.
+* Extension Sample Readfile:: Reading an entire file into a string.
+* Extension Sample API Tests:: Tests for the API.
+* Extension Sample Time:: An interface to `gettimeofday()'
+ and `sleep()'.
+
+
+File: gawk.info, Node: Extension Sample File Functions, Next: Extension Sample Fnmatch, Up: Extension Samples
+
+16.6.1 File Related Functions
+-----------------------------
+
+The `filefuncs' extension provides three different functions, as
+follows: The usage is:
+
+`@load "filefuncs"'
+ This is how you load the extension.
+
+`result = chdir("/some/directory")'
+ The `chdir()' function is a direct hook to the `chdir()' system
+ call to change the current directory. It returns zero upon
+ success or less than zero upon error. In the latter case it
+ updates `ERRNO'.
+
+`result = stat("/some/path", statdata [, follow])'
+ The `stat()' function provides a hook into the `stat()' system
+ call. It returns zero upon success or less than zero upon error.
+ In the latter case it updates `ERRNO'.
+
+ By default, it uses the `lstat()' system call. However, if passed
+ a third argument, it uses `stat()' instead.
+
+ In all cases, it clears the `statdata' array. When the call is
+ successful, `stat()' fills the `statdata' array with information
+ retrieved from the filesystem, as follows:
+
+ `statdata["name"]' The name of the file.
+ `statdata["dev"]' Corresponds to the `st_dev' field in
+ the `struct stat'.
+ `statdata["ino"]' Corresponds to the `st_ino' field in
+ the `struct stat'.
+ `statdata["mode"]' Corresponds to the `st_mode' field in
+ the `struct stat'.
+ `statdata["nlink"]' Corresponds to the `st_nlink' field in
+ the `struct stat'.
+ `statdata["uid"]' Corresponds to the `st_uid' field in
+ the `struct stat'.
+ `statdata["gid"]' Corresponds to the `st_gid' field in
+ the `struct stat'.
+ `statdata["size"]' Corresponds to the `st_size' field in
+ the `struct stat'.
+ `statdata["atime"]' Corresponds to the `st_atime' field in
+ the `struct stat'.
+ `statdata["mtime"]' Corresponds to the `st_mtime' field in
+ the `struct stat'.
+ `statdata["ctime"]' Corresponds to the `st_ctime' field in
+ the `struct stat'.
+ `statdata["rdev"]' Corresponds to the `st_rdev' field in
+ the `struct stat'. This element is
+ only present for device files.
+ `statdata["major"]' Corresponds to the `st_major' field in
+ the `struct stat'. This element is
+ only present for device files.
+ `statdata["minor"]' Corresponds to the `st_minor' field in
+ the `struct stat'. This element is
+ only present for device files.
+ `statdata["blksize"]' Corresponds to the `st_blksize' field
+ in the `struct stat'. if this field is
+ present on your system. (It is present
+ on all modern systems that we know of.)
+ `statdata["pmode"]' A human-readable version of the mode
+ value, such as printed by `ls'. For
+ example, `"-rwxr-xr-x"'.
+ `statdata["linkval"]' If the named file is a symbolic link,
+ this element will exist and its value
+ is the value of the symbolic link
+ (where the symbolic link points to).
+ `statdata["type"]' The type of the file as a string. One
+ of `"file"', `"blockdev"', `"chardev"',
+ `"directory"', `"socket"', `"fifo"',
+ `"symlink"', `"door"', or `"unknown"'.
+ Not all systems support all file types.
+
+`flags = or(FTS_PHYSICAL, ...)'
+`result = fts(pathlist, flags, filedata)'
+ Walk the file trees provided in `pathlist' and fill in the
+ `filedata' array as described below. `flags' is the bitwise OR of
+ several predefined constant values, also as described below.
+ Return zero if there were no errors, otherwise return -1.
+
+ The `fts()' function provides a hook to the C library `fts()'
+routines for traversing file hierarchies. Instead of returning data
+about one file at a time in a stream, it fills in a multi-dimensional
+array with data about each file and directory encountered in the
+requested hierarchies.
+
+ The arguments are as follows:
+
+`pathlist'
+ An array of filenames. The element values are used; the index
+ values are ignored.
+
+`flags'
+ This should be the bitwise OR of one or more of the following
+ predefined constant flag values. At least one of `FTS_LOGICAL' or
+ `FTS_PHYSICAL' must be provided; otherwise `fts()' returns an
+ error value and sets `ERRNO'. The flags are:
+
+ `FTS_LOGICAL'
+ Do a "logical" file traversal, where the information returned
+ for a symbolic link refers to the linked-to file, and not to
+ the symbolic link itself. This flag is mutually exclusive
+ with `FTS_PHYSICAL'.
+
+ `FTS_PHYSICAL'
+ Do a "physical" file traversal, where the information
+ returned for a symbolic link refers to the symbolic link
+ itself. This flag is mutually exclusive with `FTS_LOGICAL'.
+
+ `FTS_NOCHDIR'
+ As a performance optimization, the C library `fts()' routines
+ change directory as they traverse a file hierarchy. This
+ flag disables that optimization.
+
+ `FTS_COMFOLLOW'
+ Immediately follow a symbolic link named in `pathlist',
+ whether or not `FTS_LOGICAL' is set.
+
+ `FTS_SEEDOT'
+ By default, the `fts()' routines do not return entries for `.'
+ and `..'. This option causes entries for `..' to also be
+ included. (The extension always includes an entry for `.',
+ see below.)
+
+ `FTS_XDEV'
+ During a traversal, do not cross onto a different mounted
+ filesystem.
+
+`filedata'
+ The `filedata' array is first cleared. Then, `fts()' creates an
+ element in `filedata' for every element in `pathlist'. The index
+ is the name of the directory or file given in `pathlist'. The
+ element for this index is itself an array. There are two cases.
+
+ _The path is a file._
+ In this case, the array contains two or three elements:
+
+ `"path"'
+ The full path to this file, starting from the "root"
+ that was given in the `pathlist' array.
+
+ `"stat"'
+ This element is itself an array, containing the same
+ information as provided by the `stat()' function
+ described earlier for its `statdata' argument. The
+ element may not be present if the `stat()' system call
+ for the file failed.
+
+ `"error"'
+ If some kind of error was encountered, the array will
+ also contain an element named `"error"', which is a
+ string describing the error.
+
+ _The path is a directory._
+ In this case, the array contains one element for each entry
+ in the directory. If an entry is a file, that element is as
+ for files, just described. If the entry is a directory, that
+ element is (recursively), an array describing the
+ subdirectory. If `FTS_SEEDOT' was provided in the flags,
+ then there will also be an element named `".."'. This
+ element will be an array containing the data as provided by
+ `stat()'.
+
+ In addition, there will be an element whose index is `"."'.
+ This element is an array containing the same two or three
+ elements as for a file: `"path"', `"stat"', and `"error"'.
+
+ The `fts()' function returns zero if there were no errors.
+Otherwise it returns -1.
+
+ NOTE: The `fts()' extension does not exactly mimic the interface
+ of the C library `fts()' routines, choosing instead to provide an
+ interface that is based on associative arrays, which should be
+ more comfortable to use from an `awk' program. This includes the
+ lack of a comparison function, since `gawk' already provides
+ powerful array sorting facilities. While an `fts_read()'-like
+ interface could have been provided, this felt less natural than
+ simply creating a multi-dimensional array to represent the file
+ hierarchy and its information.
+
+ See `test/fts.awk' in the `gawk' distribution for an example.
+
+
+File: gawk.info, Node: Extension Sample Fnmatch, Next: Extension Sample Fork, Prev: Extension Sample File Functions, Up: Extension Samples
+
+16.6.2 Interface To `fnmatch()'
+-------------------------------
+
+This extension provides an interface to the C library `fnmatch()'
+function. The usage is:
+
+ @load "fnmatch"
+
+ result = fnmatch(pattern, string, flags)
+
+ The `fnmatch' extension adds a single function named `fnmatch()',
+one constant (`FNM_NOMATCH'), and an array of flag values named `FNM'.
+
+ The arguments to `fnmatch()' are:
+
+`pattern'
+ The filename wildcard to match.
+
+`string'
+ The filename string,
+
+`flag'
+ Either zero, or the bitwise OR of one or more of the flags in the
+ `FNM' array.
+
+ The return value is zero on success, `FNM_NOMATCH' if the string did
+not match the pattern, or a different non-zero value if an error
+occurred.
+
+ The flags are follows:
+
+`FNM["CASEFOLD"]' Corresponds to the `FNM_CASEFOLD' flag as defined in
+ `fnmatch()'.
+`FNM["FILE_NAME"]' Corresponds to the `FNM_FILE_NAME' flag as defined
+ in `fnmatch()'.
+`FNM["LEADING_DIR"]' Corresponds to the `FNM_LEADING_DIR' flag as defined
+ in `fnmatch()'.
+`FNM["NOESCAPE"]' Corresponds to the `FNM_NOESCAPE' flag as defined in
+ `fnmatch()'.
+`FNM["PATHNAME"]' Corresponds to the `FNM_PATHNAME' flag as defined in
+ `fnmatch()'.
+`FNM["PERIOD"]' Corresponds to the `FNM_PERIOD' flag as defined in
+ `fnmatch()'.
+
+ Here is an example:
+
+ @load "fnmatch"
+ ...
+ flags = or(FNM["PERIOD"], FNM["NOESCAPE"])
+ if (fnmatch("*.a", "foo.c", flags) == FNM_NOMATCH)
+ print "no match"
+
+
+File: gawk.info, Node: Extension Sample Fork, Next: Extension Sample Ord, Prev: Extension Sample Fnmatch, Up: Extension Samples
+
+16.6.3 Interface To `fork()', `wait()' and `waitpid()'
+------------------------------------------------------
+
+The `fork' extension adds three functions, as follows.
+
+`@load "fork"'
+ This is how you load the extension.
+
+`pid = fork()'
+ This function creates a new process. The return value is the zero
+ in the child and the process-id number of the child in the parent,
+ or -1 upon error. In the latter case, `ERRNO' indicates the
+ problem. In the child, `PROCINFO["pid"]' and `PROCINFO["ppid"]'
+ are updated to reflect the correct values.
+
+`ret = waitpid(pid)'
+ This function takes a numeric argument, which is the process-id to
+ wait for. The return value is that of the `waitpid()' system call.
+
+`ret = wait()'
+ This function waits for the first child to die. The return value
+ is that of the `wait()' system call.
+
+ There is no corresponding `exec()' function.
+
+ Here is an example:
+
+ @load "fork"
+ ...
+ if ((pid = fork()) == 0)
+ print "hello from the child"
+ else
+ print "hello from the parent"
+
+
+File: gawk.info, Node: Extension Sample Ord, Next: Extension Sample Readdir, Prev: Extension Sample Fork, Up: Extension Samples
+
+16.6.4 Character and Numeric values: `ord()' and `chr()'
+--------------------------------------------------------
+
+The `ordchr' extension adds two functions, named `ord()' and `chr()',
+as follows.
+
+`number = ord(string)'
+ Return the numeric value of the first character in `string'.
+
+`char = chr(number)'
+ Return the string whose first character is that represented by
+ `number'.
+
+ These functions are inspired by the Pascal language functions of the
+same name. Here is an example:
+
+ @load "ordchr"
+ ...
+ printf("The numeric value of 'A' is %d\n", ord("A"))
+ printf("The string value of 65 is %s\n", chr(65))
+
+
+File: gawk.info, Node: Extension Sample Readdir, Next: Extension Sample Revout, Prev: Extension Sample Ord, Up: Extension Samples
+
+16.6.5 Reading Directories
+--------------------------
+
+The `readdir' extension adds an input parser for directories. The
+usage is as follows:
+
+ @load "readdir"
+
+ When this extension is in use, instead of skipping directories named
+on the command line (or with `getline'), they are read, with each entry
+returned as a record.
+
+ The record consists of three fields. The first two are the inode
+number and the filename, separated by a forward slash character. On
+systems where the directory entry contains the file type, the record
+has a third field which is a single letter indicating the type of the
+file:
+
+Letter File Type
+--------------------------------------------------------------------------
+`b' Block device
+`c' Character device
+`d' Directory
+`f' Regular file
+`l' Symbolic link
+`p' Named pipe (FIFO)
+`s' Socket
+`u' Anything else (unknown)
+
+ On systems without the file type information, the third field is
+always `u'.
+
+ NOTE: On GNU/Linux systems, there are filesystems that don't
+ support the `d_type' entry (see the readdir(3) manual page), and
+ so the file type is always `u'. You can use the `filefuncs'
+ extension to call `stat()' in order to get correct type
+ information.
+
+ Here is an example:
+
+ @load "readdir"
+ ...
+ BEGIN { FS = "/" }
+ { print "file name is", $2 }
+
+
+File: gawk.info, Node: Extension Sample Revout, Next: Extension Sample Rev2way, Prev: Extension Sample Readdir, Up: Extension Samples
+
+16.6.6 Reversing Output
+-----------------------
+
+The `revoutput' extension adds a simple output wrapper that reverses
+the characters in each output line. It's main purpose is to show how to
+write an output wrapper, although it may be mildly amusing for the
+unwary. Here is an example:
+
+ @load "revoutput"
+
+ BEGIN {
+ REVOUT = 1
+ print "hello, world" > "/dev/stdout"
+ }
+
+ The output from this program is: `dlrow ,olleh'.
+
+
+File: gawk.info, Node: Extension Sample Rev2way, Next: Extension Sample Read write array, Prev: Extension Sample Revout, Up: Extension Samples
+
+16.6.7 Two-Way I/O Example
+--------------------------
+
+The `revtwoway' extension adds a simple two-way processor that reverses
+the characters in each line sent to it for reading back by the `awk'
+program. It's main purpose is to show how to write a two-way
+processor, although it may also be mildly amusing. The following
+example shows how to use it:
+
+ @load "revtwoway"
+
+ BEGIN {
+ cmd = "/magic/mirror"
+ print "hello, world" |& cmd
+ cmd |& getline result
+ print result
+ close(cmd)
+ }
+
+
+File: gawk.info, Node: Extension Sample Read write array, Next: Extension Sample Readfile, Prev: Extension Sample Rev2way, Up: Extension Samples
+
+16.6.8 Dumping and Restoring An Array
+-------------------------------------
+
+The `rwarray' extension adds two functions, named `writea()' and
+`reada()', as follows:
+
+`ret = writea(file, array)'
+ This function takes a string argument, which is the name of the
+ file to which dump the array, and the array itself as the second
+ argument. `writea()' understands multidimensional arrays. It
+ returns one on success, or zero upon failure.
+
+`ret = reada(file, array)'
+ `reada()' is the inverse of `writea()'; it reads the file named as
+ its first argument, filling in the array named as the second
+ argument. It clears the array first. Here too, the return value
+ is one on success and zero upon failure.
+
+ The array created by `reada()' is identical to that written by
+`writea()' in the sense that the contents are the same. However, due to
+implementation issues, the array traversal order of the recreated array
+is likely to be different from that of the original array. As array
+traversal order in `awk' is by default undefined, this is not
+(technically) a problem. If you need to guarantee a particular
+traversal order, use the array sorting features in `gawk' to do so
+(*note Array Sorting::).
+
+ The file contains binary data. All integral values are written in
+network byte order. However, double precision floating-point values
+are written as native binary data. Thus, arrays containing only string
+data can theoretically be dumped on systems with one byte order and
+restored on systems with a different one, but this has not been tried.
+
+ Here is an example:
+
+ @load "rwarray"
+ ...
+ ret = writea("arraydump.bin", array)
+ ...
+ ret = reada("arraydump.bin", array)
+
+
+File: gawk.info, Node: Extension Sample Readfile, Next: Extension Sample API Tests, Prev: Extension Sample Read write array, Up: Extension Samples
+
+16.6.9 Reading An Entire File
+-----------------------------
+
+The `readfile' extension adds a single function named `readfile()':
+
+`result = readfile("/some/path")'
+ The argument is the name of the file to read. The return value is
+ a string containing the entire contents of the requested file.
+ Upon error, the function returns the empty string and sets `ERRNO'.
+
+ Here is an example:
+
+ @load "readfile"
+ ...
+ contents = readfile("/path/to/file");
+ if (contents == "" && ERRNO != "") {
+ print("problem reading file", ERRNO) > "/dev/stderr"
+ ...
+ }
+
+
+File: gawk.info, Node: Extension Sample API Tests, Next: Extension Sample Time, Prev: Extension Sample Readfile, Up: Extension Samples
+
+16.6.10 API Tests
+-----------------
+
+The `testext' extension exercises parts of the extension API that are
+not tested by the other samples. The `extension/testext.c' file
+contains both the C code for the extension and `awk' test code inside C
+comments that run the tests. The testing framework extracts the `awk'
+code and runs the tests. See the source file for more information.
+
+
+File: gawk.info, Node: Extension Sample Time, Prev: Extension Sample API Tests, Up: Extension Samples
+
+16.6.11 Extension Time Functions
+--------------------------------
+
+These functions can be used by either invoking `gawk' with a
+command-line argument of `-l time' or by inserting `@load "time"' in
+your script.
+
+`the_time = gettimeofday()'
+ Return the time in seconds that has elapsed since 1970-01-01 UTC
+ as a floating point value. If the time is unavailable on this
+ platform, return -1 and set `ERRNO'. The returned time should
+ have sub-second precision, but the actual precision may vary based
+ on the platform. If the standard C `gettimeofday()' system call
+ is available on this platform, then it simply returns the value.
+ Otherwise, if on Windows, it tries to use
+ `GetSystemTimeAsFileTime()'.
+
+`result = sleep(SECONDS)'
+ Attempt to sleep for SECONDS seconds. If SECONDS is negative, or
+ the attempt to sleep fails, return -1 and set `ERRNO'. Otherwise,
+ return zero after sleeping for the indicated amount of time. Note
+ that SECONDS may be a floating-point (non-integral) value.
+ Implementation details: depending on platform availability, this
+ function tries to use `nanosleep()' or `select()' to implement the
+ delay.
+
+
+File: gawk.info, Node: gawkextlib, Prev: Extension Samples, Up: Dynamic Extensions
+
+16.7 The `gawkextlib' Project
+=============================
+
+The `gawkextlib' (http://sourceforge.net/projects/gawkextlib/) project
+provides a number of `gawk' extensions, including one for processing
+XML files. This is the evolution of the original `xgawk' (XML `gawk')
+project.
+
+ As of this writing, there are four extensions:
+
+ * XML parser extension, using the Expat
+ (http://expat.sourceforge.net) XML parsing library.
+
+ * PostgreSQL extension.
+
+ * GD graphics library extension.
+
+ * MPFR library extension. This provides access to a number of MPFR
+ functions which `gawk''s native MPFR support does not.
+
+ The `time' extension described earlier (*note Extension Sample
+Time::) was originally from this project but has been moved in to the
+main `gawk' distribution.
+
+ You can check out the code for the `gawkextlib' project using the
+GIT (http://git-scm.com) distributed source code control system. The
+command is as follows:
+
+ git clone git://git.code.sf.net/p/gawkextlib/code gawkextlib-code
+
+ You will need to have the Expat (http://expat.sourceforge.net) XML
+parser library installed in order to build and use the XML extension.
+
+ In addition, you must have the GNU Autotools installed (Autoconf
+(http://www.gnu.org/software/autoconf), Automake
+(http://www.gnu.org/software/automake), Libtool
+(http://www.gnu.org/software/libtool), and Gettext
+(http://www.gnu.org/software/gettext)).
+
+ The simple recipe for building and testing `gawkextlib' is as
+follows. First, build and install `gawk':
+
+ cd .../path/to/gawk/code
+ ./configure --prefix=/tmp/newgawk Install in /tmp/newgawk for now
+ make && make check Build and check that all is OK
+ make install Install gawk
+
+ Next, build `gawkextlib' and test it:
+
+ cd .../path/to/gawkextlib-code
+ ./update-autotools Generate configure, etc.
+ You may have to run this command twice
+ ./configure --with-gawk=/tmp/newgawk Configure, point at "installed" gawk
+ make && make check Build and check that all is OK
+
+ If you write an extension that you wish to share with other `gawk'
+users, please consider doing so through the `gawkextlib' project.
+
+
+File: gawk.info, Node: Language History, Next: Installation, Prev: Dynamic Extensions, Up: Top
Appendix A The Evolution of the `awk' Language
**********************************************
@@ -20084,9 +25109,6 @@ the current version of `gawk'.
- The `bindtextdomain()', `dcgettext()' and `dcngettext()'
functions for internationalization (*note Programmer i18n::).
- - The `extension()' built-in function and the ability to add
- new functions dynamically (*note Dynamic Extensions::).
-
- The `fflush()' function from Brian Kernighan's version of
`awk' (*note I/O Functions::).
@@ -20101,12 +25123,21 @@ the current version of `gawk'.
- The `AWKPATH' environment variable for specifying a path
search for the `-f' command-line option (*note Options::).
- - The ability to use GNU-style long-named options that start
- with `--' and the `--characters-as-bytes', `--compat',
- `--dump-variables', `--exec', `--gen-pot', `--lint',
- `--lint-old', `--non-decimal-data', `--posix', `--profile',
- `--re-interval', `--sandbox', `--source', `--traditional', and
- `--use-lc-numeric' options (*note Options::).
+ - The `AWKLIBPATH' environment variable for specifying a path
+ search for the `-l' command-line option (*note Options::).
+
+ - The `-b', `-c', `-C', `-d', `-D', `-e', `-E', `-g', `-h',
+ `-i', `-l', `-L', `-M', `-n', `-N', `-o', `-O', `-p', `-P',
+ `-r', `-S', `-t', and `-V' short options. Also, the ability
+ to use GNU-style long-named options that start with `--' and
+ the `--assign', `--bignum', `--characters-as-bytes',
+ `--copyright', `--debug', `--dump-variables', `--execle',
+ `--field-separator', `--file', `--gen-pot', `--help',
+ `--include', `--lint', `--lint-old', `--load',
+ `--non-decimal-data', `--optimize', `--posix',
+ `--pretty-print', `--profile', `--re-interval', `--sandbox',
+ `--source', `--traditional', `--use-lc-numeric', and
+ `--version' long options (*note Options::).
* Support for the following obsolete systems was removed from the
code and the documentation for `gawk' version 4.0:
@@ -20150,7 +25181,7 @@ Feature BWK Awk Mawk GNU Awk
`\x' Escape sequence X X X
`RS' as regexp X X
`FS' as null string X X X
-`/dev/stdin' special file X X X
+`/dev/stdin' special file X X
`/dev/stdout' special file X X X
`/dev/stderr' special file X X X
`**' and `**=' operators X X
@@ -20334,7 +25365,7 @@ Info file, in approximate chronological order:
various PC platforms.
* Christos Zoulas provided the `extension()' built-in function for
- dynamically adding new modules.
+ dynamically adding new modules. (This was removed at `gawk' 4.1.)
* Ju"rgen Kahrs contributed the initial version of the TCP/IP
networking code and documentation, and motivated the inclusion of
@@ -20370,7 +25401,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::.
@@ -20866,10 +25897,6 @@ not overwrite it!_ Instead enter the following commands at your prompt
The binary distribution may contain a separate file containing
additional or more detailed installation instructions.
- As of April, 2012, up to date `gawk' binaries for MS Windows are
-available from Eli Zaretskii's ports project
-(http://sourceforge.net/projects/ezwinports/files/).
-

File: gawk.info, Node: PC Compiling, Next: PC Testing, Prev: PC Binary Installation, Up: PC Installation
@@ -21392,9 +26419,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
@@ -21461,9 +26489,8 @@ and maintainers of `gawk'. Everything in it applies specifically to
* Compatibility Mode:: How to disable certain `gawk'
extensions.
* Additions:: Making Additions To `gawk'.
-* Dynamic Extensions:: Adding new built-in functions to
- `gawk'.
* Future Extensions:: New features that may be implemented one day.
+* Implementation Limitations:: Some limitations of the implementation.

File: gawk.info, Node: Compatibility Mode, Next: Additions, Up: Notes
@@ -21489,7 +26516,7 @@ for the casual user. It probably has not even been compiled into your
version of `gawk', since it slows down execution.

-File: gawk.info, Node: Additions, Next: Dynamic Extensions, Prev: Compatibility Mode, Up: Notes
+File: gawk.info, Node: Additions, Next: Future Extensions, Prev: Compatibility Mode, Up: Notes
C.2 Making Additions to `gawk'
==============================
@@ -21509,6 +26536,8 @@ as well as any considerations you should bear in mind.
`gawk'.
* New Ports:: Porting `gawk' to a new operating
system.
+* Derived Files:: Why derived files are kept in the
+ `git' repository.

File: gawk.info, Node: Accessing The Source, Next: Adding Code, Up: Additions
@@ -21536,8 +26565,8 @@ access the repository using:
git clone http://git.savannah.gnu.org/r/gawk.git
Once you have made changes, you can use `git diff' to produce a
-patch, and send that to the `gawk' maintainer; see *note Bugs:: for how
-to do that.
+patch, and send that to the `gawk' maintainer; see *note Bugs::, for
+how to do that.
Finally, if you cannot install Git (e.g., if it hasn't been ported
yet to your operating system), you can use the Git-CVS gateway to check
@@ -21545,6 +26574,10 @@ out a copy using CVS, as follows:
cvs -d:pserver:anonymous@pserver.git.sv.gnu.org:/gawk.git co -d gawk master
+ Note that this gateway is flakey; you may have better luck using a
+more modern version control system like Bazaar, that has a Git plug-in
+for working with Git repositories.
+

File: gawk.info, Node: Adding Code, Next: New Ports, Prev: Accessing The Source, Up: Additions
@@ -21620,9 +26653,9 @@ possible to include your changes:
of `switch' statements, instead of just the plain pointer or
character value.
- * Use the `TRUE', `FALSE' and `NULL' symbolic constants and the
- character constant `'\0'' where appropriate, instead of `1'
- and `0'.
+ * Use `true', `false' for `bool' values, the `NULL' symbolic
+ constant for pointer values, and the character constant
+ `'\0'' where appropriate, instead of `1' and `0'.
* Provide one-line descriptive comments for each function.
@@ -21658,9 +26691,10 @@ possible to include your changes:
7. Submit changes as unified diffs. Use `diff -u -r -N' to compare
the original `gawk' source tree with your version. I recommend
- using the GNU version of `diff'. Send the output produced by
- either run of `diff' to me when you submit your changes. (*Note
- Bugs::, for the electronic mail information.)
+ using the GNU version of `diff', or best of all, `git diff' or
+ `git format-patch'. Send the output produced by `diff' to me when
+ you submit your changes. (*Note Bugs::, for the electronic mail
+ information.)
Using this format makes it easy for me to apply your changes to the
master version of the `gawk' source code (using `patch'). If I
@@ -21677,7 +26711,7 @@ isn't possible for me to do that with a minimum of extra work, then I
probably will not.

-File: gawk.info, Node: New Ports, Prev: Adding Code, Up: Additions
+File: gawk.info, Node: New Ports, Next: Derived Files, Prev: Adding Code, Up: Additions
C.2.3 Porting `gawk' to a New Operating System
----------------------------------------------
@@ -21759,627 +26793,152 @@ code that is already there.
style and brace layout that suits your taste.

-File: gawk.info, Node: Dynamic Extensions, Next: Future Extensions, Prev: Additions, Up: Notes
-
-C.3 Adding New Built-in Functions to `gawk'
-===========================================
-
- Danger Will Robinson! Danger!!
- Warning! Warning!
- The Robot
-
- It is possible to add new built-in functions to `gawk' using
-dynamically loaded libraries. This facility is available on systems
-(such as GNU/Linux) that support the C `dlopen()' and `dlsym()'
-functions. This minor node describes how to write and use dynamically
-loaded extensions for `gawk'. Experience with programming in C or C++
-is necessary when reading this minor node.
-
- CAUTION: The facilities described in this minor node are very much
- subject to change in a future `gawk' release. Be aware that you
- may have to re-do everything, at some future time.
-
- If you have written your own dynamic extensions, be sure to
- recompile them for each new `gawk' release. There is no guarantee
- of binary compatibility between different releases, nor will there
- ever be such a guarantee.
-
- NOTE: When `--sandbox' is specified, extensions are disabled
- (*note Options::.
-
-* Menu:
-
-* Internals:: A brief look at some `gawk' internals.
-* Plugin License:: A note about licensing.
-* Sample Library:: A example of new functions.
-
-
-File: gawk.info, Node: Internals, Next: Plugin License, Up: Dynamic Extensions
-
-C.3.1 A Minimal Introduction to `gawk' Internals
-------------------------------------------------
+File: gawk.info, Node: Derived Files, Prev: New Ports, Up: Additions
-The truth is that `gawk' was not designed for simple extensibility.
-The facilities for adding functions using shared libraries work, but
-are something of a "bag on the side." Thus, this tour is brief and
-simplistic; would-be `gawk' hackers are encouraged to spend some time
-reading the source code before trying to write extensions based on the
-material presented here. Of particular note are the files `awk.h',
-`builtin.c', and `eval.c'. Reading `awkgram.y' in order to see how the
-parse tree is built would also be of use.
-
- With the disclaimers out of the way, the following types, structure
-members, functions, and macros are declared in `awk.h' and are of use
-when writing extensions. The next minor node shows how they are used:
-
-`AWKNUM'
- An `AWKNUM' is the internal type of `awk' floating-point numbers.
- Typically, it is a C `double'.
-
-`NODE'
- Just about everything is done using objects of type `NODE'. These
- contain both strings and numbers, as well as variables and arrays.
-
-`AWKNUM force_number(NODE *n)'
- This macro forces a value to be numeric. It returns the actual
- numeric value contained in the node. It may end up calling an
- internal `gawk' function.
-
-`void force_string(NODE *n)'
- This macro guarantees that a `NODE''s string value is current. It
- may end up calling an internal `gawk' function. It also
- guarantees that the string is zero-terminated.
-
-`void force_wstring(NODE *n)'
- Similarly, this macro guarantees that a `NODE''s wide-string value
- 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.
-
-`n->stptr'
-`n->stlen'
- The data and length of a `NODE''s string value, respectively. The
- string is _not_ guaranteed to be zero-terminated. If you need to
- pass the string value to a C library function, save the value in
- `n->stptr[n->stlen]', assign `'\0'' to it, call the routine, and
- then restore the value.
-
-`n->wstptr'
-`n->wstlen'
- The data and length of a `NODE''s wide-string value, respectively.
- Use `force_wstring()' to make sure these values are current.
-
-`n->type'
- The type of the `NODE'. This is a C `enum'. Values should be one
- of `Node_var', `Node_var_new', or `Node_var_array' for function
- parameters.
-
-`n->vname'
- The "variable name" of a node. This is not of much use inside
- externally written extensions.
-
-`void assoc_clear(NODE *n)'
- 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)'
- 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.
-
-`NODE *make_string(char *s, size_t len)'
- Take a C string and turn it into a pointer to a `NODE' that can be
- stored appropriately. This is permanent storage; understanding of
- `gawk' memory management is helpful.
-
-`NODE *make_number(AWKNUM val)'
- Take an `AWKNUM' and turn it into a pointer to a `NODE' that can
- be stored appropriately. This is permanent storage; understanding
- of `gawk' memory management is helpful.
-
-`NODE *dupnode(NODE *n)'
- Duplicate a node. In most cases, this increments an internal
- reference count instead of actually duplicating the entire `NODE';
- understanding of `gawk' memory management is helpful.
-
-`void unref(NODE *n)'
- This macro releases the memory associated with a `NODE' allocated
- with `make_string()' or `make_number()'. Understanding of `gawk'
- memory management is helpful.
-
-`void make_builtin(const char *name, NODE *(*func)(NODE *), int count)'
- Register a C function pointed to by `func' as new built-in
- function `name'. `name' is a regular C string. `count' is the
- maximum number of arguments that the function takes. The function
- should be written in the following manner:
-
- /* do_xxx --- do xxx function for gawk */
-
- NODE *
- do_xxx(int nargs)
- {
- ...
- }
-
-`NODE *get_argument(int i)'
- This function is called from within a C extension function to get
- the `i'-th argument from the function call. The first argument is
- argument zero.
-
-`NODE *get_actual_argument(int i,'
-` int optional, int wantarray);'
- This function retrieves a particular argument `i'. `wantarray' is
- `TRUE' if the argument should be an array, `FALSE' otherwise. If
- `optional' is `TRUE', the argument need not have been supplied.
- If it wasn't, the return value is `NULL'. It is a fatal error if
- `optional' is `TRUE' but the argument was not provided.
-
-`get_scalar_argument(i, opt)'
- This is a convenience macro that calls `get_actual_argument()'.
-
-`get_array_argument(i, opt)'
- This is a convenience macro that calls `get_actual_argument()'.
-
-`void update_ERRNO(void)'
- This function is called from within a C extension function to set
- the value of `gawk''s `ERRNO' variable, based on the current value
- of the C `errno' global variable. It is provided as a convenience.
-
-`void update_ERRNO_saved(int errno_saved)'
- This function is called from within a C extension function to set
- the value of `gawk''s `ERRNO' variable, based on the error value
- provided as the argument. It is provided as a convenience.
-
-`void register_deferred_variable(const char *name, NODE *(*load_func)(void))'
- This function is called to register a function to be called when a
- reference to an undefined variable with the given name is
- encountered. The callback function will never be called if the
- variable exists already, so, unless the calling code is running at
- program startup, it should first check whether a variable of the
- given name already exists. The argument function must return a
- pointer to a `NODE' containing the newly created variable. This
- function is used to implement the builtin `ENVIRON' and `PROCINFO'
- arrays, so you can refer to them for examples.
-
-`void register_open_hook(void *(*open_func)(IOBUF *))'
- This function is called to register a function to be called
- whenever a new data file is opened, leading to the creation of an
- `IOBUF' structure in `iop_alloc()'. After creating the new
- `IOBUF', `iop_alloc()' will call (in reverse order of
- registration, so the last function registered is called first)
- each open hook until one returns non-`NULL'. If any hook returns
- a non-`NULL' value, that value is assigned to the `IOBUF''s
- `opaque' field (which will presumably point to a structure
- containing additional state associated with the input processing),
- and no further open hooks are called.
-
- The function called will most likely want to set the `IOBUF''s
- `get_record' method to indicate that future input records should
- be retrieved by calling that method instead of using the standard
- `gawk' input processing.
-
- And the function will also probably want to set the `IOBUF''s
- `close_func' method to be called when the file is closed to clean
- up any state associated with the input.
-
- Finally, hook functions should be prepared to receive an `IOBUF'
- structure where the `fd' field is set to `INVALID_HANDLE', meaning
- that `gawk' was not able to open the file itself. In this case,
- the hook function must be able to successfully open the file and
- place a valid file descriptor there.
-
- Currently, for example, the hook function facility is used to
- implement the XML parser shared library extension. For more info,
- please look in `awk.h' and in `io.c'.
-
- An argument that is supposed to be an array needs to be handled with
-some extra code, in case the array being passed in is actually from a
-function parameter.
-
- The following boilerplate code shows how to do this:
-
- NODE *the_arg;
-
- /* assume need 3rd arg, 0-based */
- the_arg = get_array_argument(2, FALSE);
-
- Again, you should spend time studying the `gawk' internals; don't
-just blindly copy this code.
-
-
-File: gawk.info, Node: Plugin License, Next: Sample Library, Prev: Internals, Up: Dynamic Extensions
-
-C.3.2 Extension Licensing
--------------------------
-
-Every dynamic extension should define the global symbol
-`plugin_is_GPL_compatible' to assert that it has been licensed under a
-GPL-compatible license. If this symbol does not exist, `gawk' will
-emit a fatal error and exit.
-
- The declared type of the symbol should be `int'. It does not need
-to be in any allocated section, though. The code merely asserts that
-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
-
-C.3.3 Example: Directory and File Operation Built-ins
------------------------------------------------------
-
-Two useful functions that are not in `awk' are `chdir()' (so that an
-`awk' program can change its directory) and `stat()' (so that an `awk'
-program can gather information about a file). This minor node
-implements these functions for `gawk' in an external extension library.
-
-* Menu:
-
-* Internal File Description:: What the new functions will do.
-* Internal File Ops:: The code for internal file operations.
-* Using Internal File Ops:: How to use an external extension.
-
-
-File: gawk.info, Node: Internal File Description, Next: Internal File Ops, Up: Sample Library
-
-C.3.3.1 Using `chdir()' and `stat()'
-....................................
-
-This minor node shows how to use the new functions at the `awk' level
-once they've been integrated into the running `gawk' interpreter.
-Using `chdir()' is very straightforward. It takes one argument, the new
-directory to change to:
-
- ...
- newdir = "/home/arnold/funstuff"
- ret = chdir(newdir)
- if (ret < 0) {
- printf("could not change to %s: %s\n",
- newdir, ERRNO) > "/dev/stderr"
- exit 1
- }
- ...
-
- The return value is negative if the `chdir' failed, and `ERRNO'
-(*note Built-in Variables::) is set to a string indicating the error.
-
- Using `stat()' is a bit more complicated. The C `stat()' function
-fills in a structure that has a fair amount of information. The right
-way to model this in `awk' is to fill in an associative array with the
-appropriate information:
-
- file = "/home/arnold/.profile"
- fdata[1] = "x" # force `fdata' to be an array
- ret = stat(file, fdata)
- if (ret < 0) {
- printf("could not stat %s: %s\n",
- file, ERRNO) > "/dev/stderr"
- exit 1
- }
- printf("size of %s is %d bytes\n", file, fdata["size"])
-
- The `stat()' function always clears the data array, even if the
-`stat()' fails. It fills in the following elements:
-
-`"name"'
- The name of the file that was `stat()''ed.
-
-`"dev"'
-`"ino"'
- The file's device and inode numbers, respectively.
-
-`"mode"'
- The file's mode, as a numeric value. This includes both the file's
- type and its permissions.
-
-`"nlink"'
- The number of hard links (directory entries) the file has.
-
-`"uid"'
-`"gid"'
- The numeric user and group ID numbers of the file's owner.
-
-`"size"'
- The size in bytes of the file.
-
-`"blocks"'
- The number of disk blocks the file actually occupies. This may not
- be a function of the file's size if the file has holes.
-
-`"atime"'
-`"mtime"'
-`"ctime"'
- The file's last access, modification, and inode update times,
- respectively. These are numeric timestamps, suitable for
- formatting with `strftime()' (*note Built-in::).
-
-`"pmode"'
- The file's "printable mode." This is a string representation of
- the file's type and permissions, such as what is produced by `ls
- -l'--for example, `"drwxr-xr-x"'.
-
-`"type"'
- A printable string representation of the file's type. The value
- is one of the following:
-
- `"blockdev"'
- `"chardev"'
- The file is a block or character device ("special file").
-
- `"directory"'
- The file is a directory.
-
- `"fifo"'
- The file is a named-pipe (also known as a FIFO).
-
- `"file"'
- The file is just a regular file.
-
- `"socket"'
- The file is an `AF_UNIX' ("Unix domain") socket in the
- filesystem.
-
- `"symlink"'
- The file is a symbolic link.
-
- Several additional elements may be present depending upon the
-operating system and the type of the file. You can test for them in
-your `awk' program by using the `in' operator (*note Reference to
-Elements::):
-
-`"blksize"'
- The preferred block size for I/O to the file. This field is not
- present on all POSIX-like systems in the C `stat' structure.
-
-`"linkval"'
- If the file is a symbolic link, this element is the name of the
- file the link points to (i.e., the value of the link).
-
-`"rdev"'
-`"major"'
-`"minor"'
- If the file is a block or character device file, then these values
- represent the numeric device number and the major and minor
- components of that number, respectively.
-
-
-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()'
-.........................................
-
-Here is the C code for these extensions. They were written for
-GNU/Linux. The code needs some more work for complete portability to
-other POSIX-compliant systems:(1)
-
- #include "awk.h"
+C.2.4 Why Generated Files Are Kept In `git'
+-------------------------------------------
- #include <sys/sysmacros.h>
+If you look at the `gawk' source in the `git' repository, you will
+notice that it includes files that are automatically generated by GNU
+infrastructure tools, such as `Makefile.in' from `automake' and even
+`configure' from `autoconf'.
- int plugin_is_GPL_compatible;
+ This is different from many Free Software projects that do not store
+the derived files, because that keeps the repository less cluttered,
+and it is easier to see the substantive changes when comparing versions
+and trying to understand what changed between commits.
- /* do_chdir --- provide dynamically loaded chdir() builtin for gawk */
+ However, there are two reasons why the `gawk' maintainer likes to
+have everything in the repository.
- static NODE *
- do_chdir(int nargs)
- {
- NODE *newdir;
- int ret = -1;
+ First, because it is then easy to reproduce any given version
+completely, without relying upon the availability of (older, likely
+obsolete, and maybe even impossible to find) other tools.
- if (do_lint && get_curfunc_arg_count() != 1)
- lintwarn("chdir: called with incorrect number of arguments");
+ As an extreme example, if you ever even think about trying to
+compile, oh, say, the V7 `awk', you will discover that not only do you
+have to bootstrap the V7 `yacc' to do so, but you also need the V7
+`lex'. And the latter is pretty much impossible to bring up on a
+modern GNU/Linux system.(1)
- newdir = get_scalar_argument(0, FALSE);
+ (Or, let's say `gawk' 1.2 required `bison' whatever-it-was in 1989
+and that there was no `awkgram.c' file in the repository. Is there a
+guarantee that we could find that `bison' version? Or that _it_ would
+build?)
- The file includes the `"awk.h"' header file for definitions for the
-`gawk' internals. It includes `<sys/sysmacros.h>' for access to the
-`major()' and `minor'() macros.
+ If the repository has all the generated files, then it's easy to
+just check them out and build. (Or _easier_, depending upon how far
+back we go. `:-)')
- By convention, for an `awk' function `foo', the function that
-implements it is called `do_foo'. The function should take a `int'
-argument, usually called `nargs', that represents the number of defined
-arguments for the function. The `newdir' variable represents the new
-directory to change to, retrieved with `get_scalar_argument()'. Note
-that the first argument is numbered zero.
+ And that brings us to the second (and stronger) reason why all the
+files really need to be in `git'. It boils down to who do you cater
+to--the `gawk' developer(s), or the user who just wants to check out a
+version and try it out?
- This code actually accomplishes the `chdir()'. It first forces the
-argument to be a string and passes the string value to the `chdir()'
-system call. If the `chdir()' fails, `ERRNO' is updated.
+ The `gawk' maintainer wants it to be possible for any interested
+`awk' user in the world to just clone the repository, check out the
+branch of interest and build it. Without their having to have the
+correct version(s) of the autotools.(2) That is the point of the
+`bootstrap.sh' file. It touches the various other files in the right
+order such that
- (void) force_string(newdir);
- ret = chdir(newdir->stptr);
- if (ret < 0)
- update_ERRNO();
+ # The canonical incantation for building GNU software:
+ ./bootstrap.sh && ./configure && make
- Finally, the function returns the return value to the `awk' level:
+will _just work_.
- return make_number((AWKNUM) ret);
- }
+ This is extremely important for the `master' and `gawk-X.Y-stable'
+branches.
- The `stat()' built-in is more involved. First comes a function that
-turns a numeric mode into a printable representation (e.g., 644 becomes
-`-rw-r--r--'). This is omitted here for brevity:
+ Further, the `gawk' maintainer would argue that it's also important
+for the `gawk' developers. When he tried to check out the `xgawk'
+branch(3) to build it, he couldn't. (No `ltmain.sh' file, and he had no
+idea how to create it, and that was not the only problem.)
- /* format_mode --- turn a stat mode field into something readable */
+ He felt _extremely_ frustrated. With respect to that branch, the
+maintainer is no different than Jane User who wants to try to build
+`gawk-4.0-stable' or `master' from the repository.
- static char *
- format_mode(unsigned long fmode)
- {
- ...
- }
+ Thus, the maintainer thinks that it's not just important, but
+critical, that for any given branch, the above incantation _just works_.
- Next comes the `do_stat()' function. It starts with variable
-declarations and argument checking:
+ What are some of the consequences and/or actions to take?
- /* do_stat --- provide a stat() function for gawk */
+ 1. We don't mind that there are differing files in the different
+ branches as a result of different versions of the autotools.
- static NODE *
- do_stat(int nargs)
- {
- NODE *file, *array, *tmp;
- struct stat sbuf;
- int ret;
- NODE **aptr;
- char *pmode; /* printable mode */
- char *type = "unknown";
+ A. It's the maintainer's job to merge them and he will deal with
+ it.
- if (do_lint && get_curfunc_arg_count() > 2)
- lintwarn("stat: called with too many arguments");
+ B. He is really good at `git diff x y > /tmp/diff1 ; gvim
+ /tmp/diff1' to remove the diffs that aren't of interest in
+ order to review code. `:-)'
- Then comes the actual work. First, the function gets the arguments.
-Then, it always clears the array. The code use `lstat()' (instead of
-`stat()') to get the file information, in case the file is a symbolic
-link. If there's an error, it sets `ERRNO' and returns:
+ 2. It would certainly help if everyone used the same versions of the
+ GNU tools as he does, which in general are the latest released
+ versions of `automake', `autoconf', `bison', and `gettext'.
- /* file is first arg, array to hold results is second */
- file = get_scalar_argument(0, FALSE);
- array = get_array_argument(1, FALSE);
+ A. Installing from source is quite easy. It's how the maintainer
+ worked for years under Fedora. He had `/usr/local/bin' at
+ the front of hs `PATH' and just did:
- /* empty out the array */
- assoc_clear(array);
-
- /* lstat the file, if error, set ERRNO and return */
- (void) force_string(file);
- ret = lstat(file->stptr, & sbuf);
- if (ret < 0) {
- update_ERRNO();
- return make_number((AWKNUM) ret);
- }
-
- Now comes the tedious part: filling in the array. Only a few of the
-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 = dupnode(file);
- unref(tmp);
+ wget http://ftp.gnu.org/gnu/PACKAGE/PACKAGE-X.Y.Z.tar.gz
+ tar -xpzvf PACKAGE-X.Y.Z.tar.gz
+ cd PACKAGE-X.Y.Z
+ ./configure && make && make check
+ make install # as root
- aptr = assoc_lookup(array, tmp = make_string("mode", 4), FALSE);
- *aptr = make_number((AWKNUM) sbuf.st_mode);
- unref(tmp);
+ B. These days the maintainer uses Ubuntu 10.11 which is medium
+ current, but he is already doing the above for `autoconf' and
+ `bison'.
- aptr = assoc_lookup(array, tmp = make_string("pmode", 5), FALSE);
- pmode = format_mode(sbuf.st_mode);
- *aptr = make_string(pmode, strlen(pmode));
- unref(tmp);
- When done, return the `lstat()' return value:
+ Most of the above was originally written by the maintainer to other
+`gawk' developers. It raised the objection from one of the developers
+"... that anybody pulling down the source from `git' is not an end
+user."
- return make_number((AWKNUM) ret);
- }
+ However, this is not true. There are "power `awk' users" who can
+build `gawk' (using the magic incantation shown previously) but who
+can't program in C. Thus, the major branches should be kept buildable
+all the time.
- Finally, it's necessary to provide the "glue" that loads the new
-function(s) into `gawk'. By convention, each library has a routine
-named `dlload()' that does the job:
+ It was then suggested that there be a `cron' job to create nightly
+tarballs of "the source." Here, the problem is that there are source
+trees, corresponding to the various branches! So, nightly tar balls
+aren't the answer, especially as the repository can go for weeks
+without significant change being introduced.
- /* dlload --- load new builtins in this library */
+ Fortunately, the `git' server can meet this need. For any given
+branch named BRANCHNAME, use:
- NODE *
- dlload(NODE *tree, void *dl)
- {
- make_builtin("chdir", do_chdir, 1);
- make_builtin("stat", do_stat, 2);
- return make_number((AWKNUM) 0);
- }
+ wget http://git.savannah.gnu.org/cgit/gawk.git/snapshot/gawk-BRANCHNAME.tar.gz
- And that's it! As an exercise, consider adding functions to
-implement system calls such as `chown()', `chmod()', and `umask()'.
+to retrieve a snapshot of the given branch.
---------- Footnotes ----------
- (1) This version is edited slightly for presentation. See
-`extension/filefuncs.c' in the `gawk' distribution for the complete
-version.
+ (1) We tried. It was painful.
-
-File: gawk.info, Node: Using Internal File Ops, Prev: Internal File Ops, Up: Sample Library
-
-C.3.3.3 Integrating the Extensions
-..................................
-
-Now that the code is written, it must be possible to add it at runtime
-to the running `gawk' interpreter. First, the code must be compiled.
-Assuming that the functions are in a file named `filefuncs.c', and IDIR
-is the location of the `gawk' include files, the following steps create
-a GNU/Linux shared library:
-
- $ gcc -fPIC -shared -DHAVE_CONFIG_H -c -O -g -IIDIR filefuncs.c
- $ ld -o filefuncs.so -shared filefuncs.o
-
- Once the library exists, it is loaded by calling the `extension()'
-built-in function. This function takes two arguments: the name of the
-library to load and the name of a function to call when the library is
-first loaded. This function adds the new functions to `gawk'. It
-returns the value returned by the initialization function within the
-shared library:
-
- # file testff.awk
- BEGIN {
- extension("./filefuncs.so", "dlload")
-
- chdir(".") # no-op
-
- data[1] = 1 # force `data' to be an array
- print "Info for testff.awk"
- ret = stat("testff.awk", data)
- print "ret =", ret
- for (i in data)
- printf "data[\"%s\"] = %s\n", i, data[i]
- print "testff.awk modified:",
- strftime("%m %d %y %H:%M:%S", data["mtime"])
+ (2) There is one GNU program that is (in our opinion) severely
+difficult to bootstrap from the `git' repository. For example, on the
+author's old (but still working) PowerPC macintosh with Mac OS X 10.5,
+it was necessary to bootstrap a ton of software, starting with `git'
+itself, in order to try to work with the latest code. It's not
+pleasant, and especially on older systems, it's a big waste of time.
- print "\nInfo for JUNK"
- ret = stat("JUNK", data)
- print "ret =", ret
- for (i in data)
- printf "data[\"%s\"] = %s\n", i, data[i]
- print "JUNK modified:", strftime("%m %d %y %H:%M:%S", data["mtime"])
- }
+ Starting with the latest tarball was no picnic either. The
+maintainers had dropped `.gz' and `.bz2' files and only distribute
+`.tar.xz' files. It was necessary to bootstrap `xz' first!
- Here are the results of running the program:
-
- $ gawk -f testff.awk
- -| Info for testff.awk
- -| ret = 0
- -| data["size"] = 607
- -| data["ino"] = 14945891
- -| data["name"] = testff.awk
- -| data["pmode"] = -rw-rw-r--
- -| data["nlink"] = 1
- -| data["atime"] = 1293993369
- -| data["mtime"] = 1288520752
- -| data["mode"] = 33204
- -| data["blksize"] = 4096
- -| data["dev"] = 2054
- -| data["type"] = file
- -| data["gid"] = 500
- -| data["uid"] = 500
- -| data["blocks"] = 8
- -| data["ctime"] = 1290113572
- -| testff.awk modified: 10 31 10 12:25:52
- -|
- -| Info for JUNK
- -| ret = -1
- -| JUNK modified: 01 01 70 02:00:00
+ (3) A branch created by one of the other developers that did not
+include the generated files.

-File: gawk.info, Node: Future Extensions, Prev: Dynamic Extensions, Up: Notes
+File: gawk.info, Node: Future Extensions, Next: Implementation Limitations, Prev: Additions, Up: Notes
-C.4 Probable Future Extensions
+C.3 Probable Future Extensions
==============================
AWK is a language similar to PERL, only considerably more elegant.
@@ -22388,61 +26947,42 @@ C.4 Probable Future Extensions
Hey!
Larry Wall
- This minor node briefly lists extensions and possible improvements
-that indicate the directions we are currently considering for `gawk'.
-The file `FUTURES' in the `gawk' distribution lists these extensions as
-well.
-
- Following is a list of probable future changes visible at the `awk'
-language level:
-
-Loadable module interface
- It is not clear that the `awk'-level interface to the modules
- facility is as good as it should be. The interface needs to be
- redesigned, particularly taking namespace issues into account, as
- well as possibly including issues such as library search path order
- and versioning.
-
-`RECLEN' variable for fixed-length records
- Along with `FIELDWIDTHS', this would speed up the processing of
- fixed-length records. `PROCINFO["RS"]' would be `"RS"' or
- `"RECLEN"', depending upon which kind of record processing is in
- effect.
-
-Databases
- It may be possible to map a GDBM/NDBM/SDBM file into an `awk'
- array.
-
-More `lint' warnings
- There are more things that could be checked for portability.
+ The `TODO' file in the `gawk' Git repository lists possible future
+enhancements. Some of these relate to the source code, and others to
+possible new features. Please see that file for the list. *Note
+Additions::, if you are interested in tackling any of the projects
+listed there.
- Following is a list of probable improvements that will make `gawk''s
-source code easier to work with:
-
-Loadable module mechanics
- The current extension mechanism works (*note Dynamic Extensions::),
- but is rather primitive. It requires a fair amount of manual work
- to create and integrate a loadable module. Nor is the current
- mechanism as portable as might be desired. The GNU `libtool'
- package provides a number of features that would make using
- loadable modules much easier. `gawk' should be changed to use
- `libtool'.
-
-Loadable module internals
- The API to its internals that `gawk' "exports" should be revised.
- Too many things are needlessly exposed. A new API should be
- designed and implemented to make module writing easier.
+
+File: gawk.info, Node: Implementation Limitations, Prev: Future Extensions, Up: Notes
-Better array subscript management
- `gawk''s management of array subscript storage could use revamping,
- so that using the same value to index multiple arrays only stores
- one copy of the index value.
+C.4 Some Limitations of the Implementation
+==========================================
- Finally, the programs in the test suite could use documenting in
-this Info file.
+This following table describes limits of `gawk' on a Unix-like system
+(although it is variable even then). Other systems may have different
+limits.
- *Note Additions::, if you are interested in tackling any of these
-projects.
+Item Limit
+--------------------------------------------------------------------------
+Characters in a character 2^(number of bits per byte)
+class
+Length of input record `MAX_INT '
+Length of output record Unlimited
+Length of source line Unlimited
+Number of fields in a record `MAX_LONG'
+Number of file redirections Unlimited
+Number of input records in `MAX_LONG'
+one file
+Number of input records `MAX_LONG'
+total
+Number of pipe redirections min(number of processes per user, number
+ of open files)
+Numeric values Double-precision floating point (if not
+ using MPFR)
+Size of a field `MAX_INT '
+Size of a literal string `MAX_INT '
+Size of a printf string `MAX_INT '

File: gawk.info, Node: Basic Concepts, Next: Glossary, Prev: Notes, Up: Top
@@ -22461,7 +27001,6 @@ introductory texts that you should refer to instead.)
* Basic High Level:: The high level view.
* Basic Data Typing:: A very quick intro to data types.
-* Floating Point Issues:: Stuff to know about floating-point numbers.

File: gawk.info, Node: Basic High Level, Next: Basic Data Typing, Up: Basic Concepts
@@ -22470,12 +27009,13 @@ D.1 What a Program Does
=======================
At the most basic level, the job of a program is to process some input
-data and produce results.
+data and produce results. See *note figure-general-flow::.
- _______
- +------+ / \ +---------+
- | Data | -----> < Program > -----> | Results |
- +------+ \_______/ +---------+
+ _______
++------+ / \ +---------+
+| Data | -----> < Program > -----> | Results |
++------+ \_______/ +---------+
+Figure D.1: General Program Flow
The "program" in the figure can be either a compiled program(1)
(such as `ls'), or it may be "interpreted". In the latter case, a
@@ -22483,19 +27023,20 @@ machine-executable program such as `awk' reads your program, and then
uses the instructions in your program to process the data.
When you write a program, it usually consists of the following, very
-basic set of steps:
-
- ______
- +----------------+ / More \ No +----------+
- | Initialization | -------> < Data > -------> | Clean Up |
- +----------------+ ^ \ ? / +----------+
- | +--+-+
- | | Yes
- | |
- | V
- | +---------+
- +-----+ Process |
- +---------+
+basic set of steps, as shown in *note figure-process-flow:::
+
+ ______
++----------------+ / More \ No +----------+
+| Initialization | -------> < Data > -------> | Clean Up |
++----------------+ ^ \ ? / +----------+
+ | +--+-+
+ | | Yes
+ | |
+ | V
+ | +---------+
+ +-----+ Process |
+ +---------+
+Figure D.2: Basic Program Steps
Initialization
These are the things you do before actually starting to process
@@ -22560,7 +27101,7 @@ such as C, C++, or Ada, and then translated, or "compiled", into a form
that the computer can execute directly.

-File: gawk.info, Node: Basic Data Typing, Next: Floating Point Issues, Prev: Basic High Level, Up: Basic Concepts
+File: gawk.info, Node: Basic Data Typing, Prev: Basic High Level, Up: Basic Concepts
D.2 Data Values in a Computer
=============================
@@ -22580,34 +27121,10 @@ characters that comprise them. Individual variables, as well as
numeric and string variables, are referred to as "scalar" values.
Groups of values, such as arrays, are not scalars.
- Within computers, there are two kinds of numeric values: "integers"
-and "floating-point". In school, integer values were referred to as
-"whole" numbers--that is, numbers without any fractional part, such as
-1, 42, or -17. The advantage to integer numbers is that they represent
-values exactly. The disadvantage is that their range is limited. On
-most systems, this range is -2,147,483,648 to 2,147,483,647. However,
-many systems now support a range from -9,223,372,036,854,775,808 to
-9,223,372,036,854,775,807.
-
- Integer values come in two flavors: "signed" and "unsigned". Signed
-values may be negative or positive, with the range of values just
-described. Unsigned values are always positive. On most systems, the
-range is from 0 to 4,294,967,295. However, many systems now support a
-range from 0 to 18,446,744,073,709,551,615.
-
- Floating-point numbers represent what are called "real" numbers;
-i.e., those that do have a fractional part, such as 3.1415927. The
-advantage to floating-point numbers is that they can represent a much
-larger range of values. The disadvantage is that there are numbers
-that they cannot represent exactly. `awk' uses "double precision"
-floating-point numbers, which can hold more digits than "single
-precision" floating-point numbers. Floating-point issues are discussed
-more fully in *note Floating Point Issues::.
-
- At the very lowest level, computers store values as groups of binary
-digits, or "bits". Modern computers group bits into groups of eight,
-called "bytes". Advanced applications sometimes have to manipulate
-bits directly, and `gawk' provides functions for doing so.
+ *note General Arithmetic::, provided a basic introduction to numeric
+types (integer and floating-point) and how they are used in a computer.
+Please review that information, including a number of caveats that were
+presented.
While you are probably used to the idea of a number without a value
(i.e., zero), it takes a bit more getting used to the idea of
@@ -22628,6 +27145,11 @@ represents 1 times 8, plus 0 times 4, plus 1 times 2, plus 0 times 1,
or decimal 10. Octal and hexadecimal are discussed more in *note
Nondecimal-numbers::.
+ At the very lowest level, computers store values as groups of binary
+digits, or "bits". Modern computers group bits into groups of eight,
+called "bytes". Advanced applications sometimes have to manipulate
+bits directly, and `gawk' provides functions for doing so.
+
Programs are written in programming languages. Hundreds, if not
thousands, of programming languages exist. One of the most popular is
the C programming language. The C language had a very strong influence
@@ -22645,218 +27167,6 @@ In 1999, a revised ISO C standard was approved and released. Where it
makes sense, POSIX `awk' is compatible with 1999 ISO C.

-File: gawk.info, Node: Floating Point Issues, Prev: Basic Data Typing, Up: Basic Concepts
-
-D.3 Floating-Point Number Caveats
-=================================
-
-As mentioned earlier, floating-point numbers represent what are called
-"real" numbers, i.e., those that have a fractional part. `awk' uses
-double precision floating-point numbers to represent all numeric
-values. This minor node describes some of the issues involved in using
-floating-point numbers.
-
- There is a very nice paper on floating-point arithmetic
-(http://www.validlab.com/goldberg/paper.pdf) by David Goldberg, "What
-Every Computer Scientist Should Know About Floating-point Arithmetic,"
-`ACM Computing Surveys' *23*, 1 (1991-03), 5-48. This is worth reading
-if you are interested in the details, but it does require a background
-in computer science.
-
-* Menu:
-
-* String Conversion Precision:: The String Value Can Lie.
-* Unexpected Results:: Floating Point Numbers Are Not Abstract
- Numbers.
-* POSIX Floating Point Problems:: Standards Versus Existing Practice.
-
-
-File: gawk.info, Node: String Conversion Precision, Next: Unexpected Results, Up: Floating Point Issues
-
-D.3.1 The String Value Can Lie
-------------------------------
-
-Internally, `awk' keeps both the numeric value (double precision
-floating-point) and the string value for a variable. Separately, `awk'
-keeps track of what type the variable has (*note Typing and
-Comparison::), which plays a role in how variables are used in
-comparisons.
-
- It is important to note that the string value for a number may not
-reflect the full value (all the digits) that the numeric value actually
-contains. The following program (`values.awk') illustrates this:
-
- {
- sum = $1 + $2
- # see it for what it is
- printf("sum = %.12g\n", sum)
- # use CONVFMT
- a = "<" sum ">"
- print "a =", a
- # use OFMT
- print "sum =", sum
- }
-
-This program shows the full value of the sum of `$1' and `$2' using
-`printf', and then prints the string values obtained from both
-automatic conversion (via `CONVFMT') and from printing (via `OFMT').
-
- Here is what happens when the program is run:
-
- $ echo 3.654321 1.2345678 | awk -f values.awk
- -| sum = 4.8888888
- -| a = <4.88889>
- -| sum = 4.88889
-
- This makes it clear that the full numeric value is different from
-what the default string representations show.
-
- `CONVFMT''s default value is `"%.6g"', which yields a value with at
-least six significant digits. For some applications, you might want to
-change it to specify more precision. On most modern machines, most of
-the time, 17 digits is enough to capture a floating-point number's
-value exactly.(1)
-
- ---------- Footnotes ----------
-
- (1) Pathological cases can require up to 752 digits (!), but we
-doubt that you need to worry about this.
-
-
-File: gawk.info, Node: Unexpected Results, Next: POSIX Floating Point Problems, Prev: String Conversion Precision, Up: Floating Point Issues
-
-D.3.2 Floating Point Numbers Are Not Abstract Numbers
------------------------------------------------------
-
-Unlike numbers in the abstract sense (such as what you studied in high
-school or college math), numbers stored in computers are limited in
-certain ways. They cannot represent an infinite number of digits, nor
-can they always represent things exactly. In particular,
-floating-point numbers cannot always represent values exactly. Here is
-an example:
-
- $ awk '{ printf("%010d\n", $1 * 100) }'
- 515.79
- -| 0000051579
- 515.80
- -| 0000051579
- 515.81
- -| 0000051580
- 515.82
- -| 0000051582
- Ctrl-d
-
-This shows that some values can be represented exactly, whereas others
-are only approximated. This is not a "bug" in `awk', but simply an
-artifact of how computers represent numbers.
-
- Another peculiarity of floating-point numbers on modern systems is
-that they often have more than one representation for the number zero!
-In particular, it is possible to represent "minus zero" as well as
-regular, or "positive" zero.
-
- This example shows that negative and positive zero are distinct
-values when stored internally, but that they are in fact equal to each
-other, as well as to "regular" zero:
-
- $ gawk 'BEGIN { mz = -0 ; pz = 0
- > printf "-0 = %g, +0 = %g, (-0 == +0) -> %d\n", mz, pz, mz == pz
- > printf "mz == 0 -> %d, pz == 0 -> %d\n", mz == 0, pz == 0
- > }'
- -| -0 = -0, +0 = 0, (-0 == +0) -> 1
- -| mz == 0 -> 1, pz == 0 -> 1
-
- It helps to keep this in mind should you process numeric data that
-contains negative zero values; the fact that the zero is negative is
-noted and can affect comparisons.
-
-
-File: gawk.info, Node: POSIX Floating Point Problems, Prev: Unexpected Results, Up: Floating Point Issues
-
-D.3.3 Standards Versus Existing Practice
-----------------------------------------
-
-Historically, `awk' has converted any non-numeric looking string to the
-numeric value zero, when required. Furthermore, the original
-definition of the language and the original POSIX standards specified
-that `awk' only understands decimal numbers (base 10), and not octal
-(base 8) or hexadecimal numbers (base 16).
-
- Changes in the language of the 2001 and 2004 POSIX standard can be
-interpreted to imply that `awk' should support additional features.
-These features are:
-
- * Interpretation of floating point data values specified in
- hexadecimal notation (`0xDEADBEEF'). (Note: data values, _not_
- source code constants.)
-
- * Support for the special IEEE 754 floating point values "Not A
- Number" (NaN), positive Infinity ("inf") and negative Infinity
- ("-inf"). In particular, the format for these values is as
- specified by the ISO 1999 C standard, which ignores case and can
- allow machine-dependent additional characters after the `nan' and
- allow either `inf' or `infinity'.
-
- The first problem is that both of these are clear changes to
-historical practice:
-
- * The `gawk' maintainer feels that supporting hexadecimal floating
- point values, in particular, is ugly, and was never intended by the
- original designers to be part of the language.
-
- * Allowing completely alphabetic strings to have valid numeric
- values is also a very severe departure from historical practice.
-
- The second problem is that the `gawk' maintainer feels that this
-interpretation of the standard, which requires a certain amount of
-"language lawyering" to arrive at in the first place, was not even
-intended by the standard developers. In other words, "we see how you
-got where you are, but we don't think that that's where you want to be."
-
- The 2008 POSIX standard added explicit wording to allow, but not
-require, that `awk' support hexadecimal floating point values and
-special values for "Not A Number" and infinity.
-
- Although the `gawk' maintainer continues to feel that providing
-those features is inadvisable, nevertheless, on systems that support
-IEEE floating point, it seems reasonable to provide _some_ way to
-support NaN and Infinity values. The solution implemented in `gawk' is
-as follows:
-
- * With the `--posix' command-line option, `gawk' becomes "hands
- off." String values are passed directly to the system library's
- `strtod()' function, and if it successfully returns a numeric
- value, that is what's used.(1) By definition, the results are not
- portable across different systems. They are also a little
- surprising:
-
- $ echo nanny | gawk --posix '{ print $1 + 0 }'
- -| nan
- $ echo 0xDeadBeef | gawk --posix '{ print $1 + 0 }'
- -| 3735928559
-
- * Without `--posix', `gawk' interprets the four strings `+inf',
- `-inf', `+nan', and `-nan' specially, producing the corresponding
- special numeric values. The leading sign acts a signal to `gawk'
- (and the user) that the value is really numeric. Hexadecimal
- floating point is not supported (unless you also use
- `--non-decimal-data', which is _not_ recommended). For example:
-
- $ echo nanny | gawk '{ print $1 + 0 }'
- -| 0
- $ echo +nan | gawk '{ print $1 + 0 }'
- -| nan
- $ echo 0xDeadBeef | gawk '{ print $1 + 0 }'
- -| 0
-
- `gawk' does ignore case in the four special values. Thus `+nan'
- and `+NaN' are the same.
-
- ---------- Footnotes ----------
-
- (1) You asked for it, you got it.
-
-
File: gawk.info, Node: Glossary, Next: Copying, Prev: Basic Concepts, Up: Top
Glossary
@@ -23013,6 +27323,10 @@ CHEM
Brian Kernighan and Jon Bentley, and is available from
`http://netlib.sandia.gov/netlib/typesetting/chem.gz'.
+Cookie
+ A peculiar goodie, token, saying or remembrance produced by or
+ presented to a program. (With thanks to Doug McIlroy.)
+
Coprocess
A subordinate program with which two-way communications is
possible.
@@ -24750,14 +29064,14 @@ 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.
(line 87)
* * (asterisk), * operator, null strings, matching: Gory Details.
- (line 164)
+ (line 165)
* * (asterisk), ** operator <1>: Precedence. (line 49)
* * (asterisk), ** operator: Arithmetic Ops. (line 81)
* * (asterisk), **= operator <1>: Precedence. (line 95)
@@ -24778,79 +29092,86 @@ Index
* - (hyphen), -- operator: Increment Ops. (line 48)
* - (hyphen), -= operator <1>: Precedence. (line 95)
* - (hyphen), -= operator: Assignment Ops. (line 129)
-* - (hyphen), filenames beginning with: Options. (line 59)
+* - (hyphen), filenames beginning with: Options. (line 73)
* - (hyphen), in bracket expressions: Bracket Expressions. (line 17)
-* --assign option: Options. (line 32)
-* --c option: Options. (line 81)
-* --characters-as-bytes option: Options. (line 68)
-* --command option: Options. (line 234)
-* --copyright option: Options. (line 88)
+* --assign option: Options. (line 46)
+* --bignum option: Options. (line 201)
+* --c option: Options. (line 95)
+* --characters-as-bytes option: Options. (line 82)
+* --copyright option: Options. (line 102)
+* --debug option: Options. (line 122)
* --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 93)
-* --exec option: Options. (line 116)
+* --dump-variables option: Options. (line 107)
+* --exec option: Options. (line 139)
* --field-separator option: Options. (line 21)
* --file option: Options. (line 25)
* --gen-pot option <1>: String Extraction. (line 6)
-* --gen-pot option: Options. (line 138)
-* --help option: Options. (line 145)
-* --L option: Options. (line 248)
-* --lint option <1>: Options. (line 150)
+* --gen-pot option: Options. (line 161)
+* --help option: Options. (line 168)
+* --include option: Options. (line 32)
+* --L option: Options. (line 288)
+* --lint option <1>: Options. (line 182)
* --lint option: Command Line. (line 20)
-* --lint-old option: Options. (line 248)
+* --lint-old option: Options. (line 288)
+* --load option: Options. (line 173)
* --non-decimal-data option <1>: Nondecimal Data. (line 6)
-* --non-decimal-data option: Options. (line 169)
+* --non-decimal-data option: Options. (line 207)
* --non-decimal-data option, strtonum() function and: Nondecimal Data.
(line 36)
-* --optimize option: Options. (line 182)
-* --posix option: Options. (line 202)
-* --posix option, --traditional option and: Options. (line 221)
-* --profile option <1>: Profiling. (line 15)
-* --profile option: Options. (line 189)
-* --re-interval option: Options. (line 227)
-* --sandbox option: Options. (line 239)
+* --optimize option: Options. (line 228)
+* --posix option: Options. (line 247)
+* --posix option, --traditional option and: Options. (line 266)
+* --pretty-print option: Options. (line 220)
+* --profile option <1>: Profiling. (line 12)
+* --profile option: Options. (line 235)
+* --re-interval option: Options. (line 272)
+* --sandbox option: Options. (line 279)
* --sandbox option, disabling system() function: I/O Functions.
(line 94)
* --sandbox option, input redirection with getline: Getline. (line 19)
* --sandbox option, output redirection with print, printf: Redirection.
(line 6)
-* --source option: Options. (line 108)
-* --traditional option: Options. (line 81)
-* --traditional option, --posix option and: Options. (line 221)
-* --use-lc-numeric option: Options. (line 177)
-* --version option: Options. (line 253)
+* --source option: Options. (line 131)
+* --traditional option: Options. (line 95)
+* --traditional option, --posix option and: Options. (line 266)
+* --use-lc-numeric option: Options. (line 215)
+* --version option: Options. (line 293)
* --with-whiny-user-strftime configuration option: Additional Configuration Options.
(line 29)
-* -b option: Options. (line 68)
-* -C option: Options. (line 88)
-* -d option: Options. (line 93)
-* -E option: Options. (line 116)
-* -e option: Options. (line 108)
+* -b option: Options. (line 82)
+* -C option: Options. (line 102)
+* -D option: Options. (line 122)
+* -d option: Options. (line 107)
+* -E option: Options. (line 139)
+* -e option: Options. (line 131)
* -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 261)
-* -f option, on command line: Options. (line 266)
-* -g option: Options. (line 138)
-* -h option: Options. (line 145)
-* -l option: Options. (line 150)
-* -N option: Options. (line 177)
-* -n option: Options. (line 169)
-* -O option: Options. (line 182)
-* -P option: Options. (line 202)
-* -p option: Options. (line 189)
-* -R option: Options. (line 234)
-* -r option: Options. (line 227)
-* -S option: Options. (line 239)
-* -V option: Options. (line 253)
-* -v option: Options. (line 32)
+* -F option, -Ft sets FS to TAB: Options. (line 301)
+* -f option, on command line: Options. (line 306)
+* -g option: Options. (line 161)
+* -h option: Options. (line 168)
+* -i option: Options. (line 32)
+* -l option: Options. (line 173)
+* -M option: Options. (line 201)
+* -N option: Options. (line 215)
+* -n option: Options. (line 207)
+* -O option: Options. (line 228)
+* -o option: Options. (line 220)
+* -P option: Options. (line 247)
+* -p option: Options. (line 235)
+* -r option: Options. (line 272)
+* -S option: Options. (line 279)
+* -V option: Options. (line 293)
+* -v option: Options. (line 46)
* -v option, variables, assigning: Assignment Options. (line 12)
-* -W option: Options. (line 46)
+* -W option: Options. (line 60)
* . (period): Regexp Operators. (line 43)
* .mo files: Explaining gettext. (line 41)
* .mo files, converting from .po: I18N Example. (line 62)
@@ -24979,7 +29300,6 @@ Index
* Ada programming language: Glossary. (line 20)
* adding, features to gawk: Adding Code. (line 6)
* adding, fields: Changing Fields. (line 53)
-* adding, functions to gawk: Dynamic Extensions. (line 10)
* advanced features, buffering: I/O Functions. (line 107)
* advanced features, close() function: Close Files And Pipes.
(line 131)
@@ -24987,7 +29307,7 @@ Index
(line 67)
* advanced features, data files as single record: Records. (line 180)
* 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 295)
* advanced features, gawk: Advanced Features. (line 6)
* advanced features, gawk, network programming: TCP/IP Networking.
(line 6)
@@ -24997,7 +29317,7 @@ Index
(line 23)
* advanced features, network connections, See Also networks, connections: Advanced Features.
(line 6)
-* advanced features, null strings, matching: Gory Details. (line 164)
+* advanced features, null strings, matching: Gory Details. (line 165)
* advanced features, operators, precedence: Increment Ops. (line 61)
* advanced features, piping into sh: Redirection. (line 143)
* advanced features, regexp constants: Assignment Ops. (line 148)
@@ -25007,7 +29327,7 @@ Index
* Aho, Alfred: History. (line 17)
* alarm clock example program: Alarm Program. (line 9)
* alarm.awk program: Alarm Program. (line 29)
-* algorithms: Basic High Level. (line 66)
+* algorithms: Basic High Level. (line 68)
* Alpha (DEC): Manual History. (line 28)
* amazing awk assembler (aaa): Glossary. (line 12)
* amazingly workable formatter (awf): Glossary. (line 25)
@@ -25022,6 +29342,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)
@@ -25036,18 +29358,15 @@ 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)
* 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, 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, order of: Scanning an Array. (line 48)
* arrays, elements, referencing: Reference to Elements.
(line 6)
@@ -25086,15 +29405,13 @@ 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)
* associative arrays: Array Intro. (line 50)
* asterisk (*), * operator, as multiplication operator: Precedence.
(line 55)
* asterisk (*), * operator, as regexp operator: Regexp Operators.
(line 87)
* asterisk (*), * operator, null strings, matching: Gory Details.
- (line 164)
+ (line 165)
* asterisk (*), ** operator <1>: Precedence. (line 49)
* asterisk (*), ** operator: Arithmetic Ops. (line 81)
* asterisk (*), **= operator <1>: Precedence. (line 95)
@@ -25103,7 +29420,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 122)
+* awk enabling: Options. (line 220)
* awk language, POSIX version: Assignment Ops. (line 136)
+* awk profiling, enabling: Options. (line 235)
* awk programs <1>: Two Rules. (line 6)
* awk programs <2>: Executable Scripts. (line 6)
* awk programs: Getting Started. (line 12)
@@ -25119,7 +29439,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 189)
* awk programs, running <1>: Long. (line 6)
* awk programs, running: Running gawk. (line 6)
* awk programs, running, from shell scripts: One-shot. (line 22)
@@ -25154,14 +29473,13 @@ Index
* awk, versions of, See Also Brian Kernighan's awk <1>: Other Versions.
(line 13)
* awk, versions of, See Also Brian Kernighan's awk: BTL. (line 6)
-* awk.h file (internal): Internals. (line 15)
* awka compiler for awk: Other Versions. (line 55)
-* AWKNUM internal type: Internals. (line 19)
+* AWKLIBPATH environment variable: AWKLIBPATH Variable. (line 6)
* 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 93)
+* awkvars.out file: Options. (line 107)
* b debugger command (alias for break): Breakpoint Control. (line 11)
* backslash (\) <1>: Regexp Operators. (line 18)
* backslash (\) <2>: Quoting. (line 31)
@@ -25213,12 +29531,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)
@@ -25233,7 +29552,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)
@@ -25252,7 +29570,7 @@ Index
(line 33)
* BINMODE variable <1>: PC Using. (line 34)
* BINMODE variable: User-modified. (line 10)
-* bits2str() user-defined function: Bitwise Functions. (line 68)
+* bits2str() user-defined function: Bitwise Functions. (line 70)
* bitwise, complement: Bitwise Functions. (line 25)
* bitwise, operations: Bitwise Functions. (line 6)
* bitwise, shift: Bitwise Functions. (line 32)
@@ -25262,8 +29580,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)
@@ -25282,15 +29600,15 @@ Index
* break debugger command: Breakpoint Control. (line 11)
* break statement: Break Statement. (line 6)
* Brennan, Michael <1>: Other Versions. (line 6)
-* Brennan, Michael <2>: Simple Sed. (line 25)
-* Brennan, Michael <3>: Two-way I/O. (line 6)
+* Brennan, Michael <2>: Two-way I/O. (line 6)
+* Brennan, Michael <3>: Simple Sed. (line 25)
* Brennan, Michael: Delete. (line 56)
* Brian Kernighan's awk, extensions <1>: Other Versions. (line 13)
* Brian Kernighan's awk, extensions: BTL. (line 6)
* Broder, Alan J.: Contributors. (line 88)
* Brown, Martin: Contributors. (line 82)
-* BSD-based operating systems: Glossary. (line 615)
-* bt debugger command (alias for backtrace): Dgawk Stack. (line 13)
+* BSD-based operating systems: Glossary. (line 619)
+* 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)
@@ -25305,10 +29623,10 @@ Index
* built-in functions: Functions. (line 6)
* built-in functions, evaluation order: Calling Built-in. (line 30)
* built-in variables: Built-in Variables. (line 6)
-* built-in variables, -v option, setting with: Options. (line 40)
+* built-in variables, -v option, setting with: Options. (line 54)
* 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.
@@ -25328,7 +29646,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 116)
+* CGI, awk scripts for: Options. (line 139)
* 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.
@@ -25339,7 +29657,6 @@ Index
* characters, transliterating: Translate Program. (line 6)
* characters, values of as numbers: Ordinal Functions. (line 6)
* Chassell, Robert J.: Acknowledgments. (line 33)
-* chdir() function, implementing in gawk: Sample Library. (line 6)
* chem utility: Glossary. (line 151)
* chr() user-defined function: Ordinal Functions. (line 16)
* clear debugger command: Breakpoint Control. (line 36)
@@ -25358,7 +29675,6 @@ 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)
* collating elements: Bracket Expressions. (line 69)
* collating symbols: Bracket Expressions. (line 76)
* Colombo, Antonio: Acknowledgments. (line 60)
@@ -25378,11 +29694,11 @@ Index
(line 6)
* command line, options <2>: Options. (line 6)
* command line, options: Long. (line 12)
-* command line, options, end of: Options. (line 54)
+* command line, options, end of: Options. (line 68)
* 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)
@@ -25414,14 +29730,14 @@ Index
(line 60)
* compatibility mode (gawk), octal numbers: Nondecimal-numbers.
(line 60)
-* compatibility mode (gawk), specifying: Options. (line 81)
-* compiled programs <1>: Glossary. (line 161)
-* compiled programs: Basic High Level. (line 14)
+* compatibility mode (gawk), specifying: Options. (line 95)
+* compiled programs <1>: Glossary. (line 165)
+* compiled programs: Basic High Level. (line 15)
* compiling gawk for Cygwin: Cygwin. (line 6)
* compiling gawk for MS-DOS and MS-Windows: PC Compiling. (line 13)
* compiling gawk for VMS: VMS Compilation. (line 6)
* compiling gawk with EMX for OS/2: PC Compiling. (line 28)
-* compl() function (gawk): Bitwise Functions. (line 42)
+* compl() function (gawk): Bitwise Functions. (line 43)
* complement, bitwise: Bitwise Functions. (line 25)
* compound statements, control statements and: Statements. (line 10)
* concatenating: Concatenation. (line 9)
@@ -25435,22 +29751,27 @@ 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)
* converting, dates to timestamps: Time Functions. (line 74)
* converting, during subscripting: Numeric Array Subscripts.
(line 31)
-* converting, numbers to strings <1>: Bitwise Functions. (line 107)
+* converting, numbers to strings <1>: Bitwise Functions. (line 109)
* converting, numbers to strings: Conversion. (line 6)
-* converting, strings to numbers <1>: Bitwise Functions. (line 107)
+* converting, strings to numbers <1>: Bitwise Functions. (line 109)
* converting, strings to numbers: Conversion. (line 6)
* CONVFMT variable <1>: User-modified. (line 28)
* CONVFMT variable: Conversion. (line 29)
* CONVFMT variable, array subscripts and: Numeric Array Subscripts.
(line 6)
+* cookie: Glossary. (line 157)
* coprocesses <1>: Two-way I/O. (line 44)
* coprocesses: Redirection. (line 102)
* coprocesses, closing: Close Files And Pipes.
@@ -25459,7 +29780,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 308)
+* csh utility, POSIXLY_CORRECT environment variable: Options. (line 348)
* 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)
@@ -25467,9 +29788,9 @@ 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 <1>: Glossary. (line 197)
* dark corner <2>: Truth Values. (line 24)
* dark corner <3>: Assignment Ops. (line 148)
* dark corner: Conventions. (line 38)
@@ -25489,9 +29810,9 @@ Index
* dark corner, exit statement: Exit Statement. (line 30)
* dark corner, field separators: Field Splitting Summary.
(line 47)
-* dark corner, FILENAME variable <1>: Auto-set. (line 92)
+* dark corner, FILENAME variable <1>: Auto-set. (line 93)
* 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 295)
* dark corner, format-control characters: Control Letters. (line 18)
* dark corner, FS as null string: Single Character Fields.
(line 20)
@@ -25511,7 +29832,7 @@ Index
* dark corner, strings, storing: Records. (line 196)
* dark corner, value of ARGV[0]: Auto-set. (line 35)
* data, fixed-width: Constant Size. (line 9)
-* data-driven languages: Basic High Level. (line 83)
+* data-driven languages: Basic High Level. (line 85)
* database, group, reading: Group Functions. (line 6)
* database, users, reading: Passwd Functions. (line 6)
* date utility, GNU: Time Functions. (line 17)
@@ -25531,119 +29852,121 @@ 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 218)
+* decimal point character, locale specific: Options. (line 263)
* 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)
* differences in awk and gawk, ARGIND variable: Auto-set. (line 40)
* differences in awk and gawk, array elements, deleting: Delete.
(line 39)
+* differences in awk and gawk, AWKLIBPATH environment variable: AWKLIBPATH Variable.
+ (line 6)
* differences in awk and gawk, AWKPATH environment variable: AWKPATH Variable.
(line 6)
* differences in awk and gawk, BEGIN/END patterns: I/O And BEGIN/END.
@@ -25654,11 +29977,12 @@ Index
(line 23)
* differences in awk and gawk, close() function: Close Files And Pipes.
(line 81)
-* differences in awk and gawk, ERRNO variable: Auto-set. (line 72)
+* differences in awk and gawk, ERRNO variable: Auto-set. (line 73)
* differences in awk and gawk, error messages: Special FD. (line 16)
* differences in awk and gawk, FIELDWIDTHS variable: User-modified.
(line 35)
* differences in awk and gawk, FPAT variable: User-modified. (line 45)
+* differences in awk and gawk, FUNCTAB variable: Auto-set. (line 119)
* differences in awk and gawk, function arguments (gawk): Calling Built-in.
(line 16)
* differences in awk and gawk, getline command: Getline. (line 19)
@@ -25683,14 +30007,14 @@ Index
(line 6)
* differences in awk and gawk, print/printf statements: Format Modifiers.
(line 13)
-* differences in awk and gawk, PROCINFO array: Auto-set. (line 123)
+* differences in awk and gawk, PROCINFO array: Auto-set. (line 130)
* differences in awk and gawk, record separators: Records. (line 117)
* differences in awk and gawk, regexp constants: Using Constant Regexps.
(line 43)
* differences in awk and gawk, regular expressions: Case-sensitivity.
(line 26)
* differences in awk and gawk, RS/RT variables: Records. (line 172)
-* differences in awk and gawk, RT variable: Auto-set. (line 196)
+* differences in awk and gawk, RT variable: Auto-set. (line 246)
* differences in awk and gawk, single-character fields: Single Character Fields.
(line 6)
* differences in awk and gawk, split() function: String Functions.
@@ -25699,16 +30023,17 @@ Index
* differences in awk and gawk, strings, storing: Records. (line 192)
* differences in awk and gawk, strtonum() function (gawk): String Functions.
(line 404)
+* differences in awk and gawk, SYMTAB variable: Auto-set. (line 254)
* 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)
* directories, command line: Command line directories.
(line 6)
* directories, searching <1>: Igawk Program. (line 368)
+* directories, searching <2>: AWKLIBPATH Variable. (line 6)
* 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)
@@ -25722,18 +30047,17 @@ Index
* dollar sign ($), $ field operator: Fields. (line 19)
* dollar sign ($), incrementing fields and arrays: Increment Ops.
(line 30)
-* double precision floating-point: Basic Data Typing. (line 36)
+* double precision floating-point: General Arithmetic. (line 21)
* 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)
* 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)
@@ -25749,9 +30073,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)
@@ -25763,7 +30088,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)
@@ -25772,24 +30096,22 @@ 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: Auto-set. (line 60)
* environment variables: Auto-set. (line 60)
-* epoch, definition of: Glossary. (line 239)
+* epoch, definition of: Glossary. (line 243)
* equals sign (=), = operator: Assignment Ops. (line 6)
* equals sign (=), == operator <1>: Precedence. (line 65)
* equals sign (=), == operator: Comparison Operators.
(line 11)
* EREs (Extended Regular Expressions): Bracket Expressions. (line 24)
-* ERRNO variable <1>: Internals. (line 139)
-* ERRNO variable <2>: TCP/IP Networking. (line 54)
-* ERRNO variable <3>: Auto-set. (line 72)
-* ERRNO variable <4>: BEGINFILE/ENDFILE. (line 26)
-* ERRNO variable <5>: Close Files And Pipes.
+* ERRNO variable <1>: TCP/IP Networking. (line 54)
+* ERRNO variable <2>: Auto-set. (line 73)
+* ERRNO variable <3>: BEGINFILE/ENDFILE. (line 26)
+* ERRNO variable <4>: Close Files And Pipes.
(line 139)
* ERRNO variable: Getline. (line 19)
* error handling: Special FD. (line 16)
-* error handling, ERRNO variable and: Auto-set. (line 72)
+* error handling, ERRNO variable and: Auto-set. (line 73)
* error output: Special FD. (line 6)
* escape processing, gsub()/gensub()/sub() functions: Gory Details.
(line 6)
@@ -25830,9 +30152,6 @@ Index
(line 9)
* expressions, selecting: Conditional Exp. (line 6)
* Extended Regular Expressions (EREs): Bracket Expressions. (line 24)
-* eXtensible Markup Language (XML): Internals. (line 160)
-* extension() function (gawk): Using Internal File Ops.
- (line 15)
* extensions, Brian Kernighan's awk <1>: Other Versions. (line 13)
* extensions, Brian Kernighan's awk: BTL. (line 6)
* extensions, common, ** operator: Arithmetic Ops. (line 36)
@@ -25855,7 +30174,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)
@@ -25885,7 +30204,7 @@ Index
* field separators, regular expressions as: Field Separators. (line 50)
* field separators, See Also OFS: Changing Fields. (line 64)
* field separators, spaces as: Cut Program. (line 109)
-* fields <1>: Basic High Level. (line 71)
+* fields <1>: Basic High Level. (line 73)
* fields <2>: Fields. (line 6)
* fields: Reading Files. (line 14)
* fields, adding: Changing Fields. (line 53)
@@ -25904,7 +30223,7 @@ Index
* file names, distinguishing: Auto-set. (line 52)
* file names, in compatibility mode: Special Caveats. (line 9)
* file names, standard streams in gawk: Special FD. (line 46)
-* FILENAME variable <1>: Auto-set. (line 92)
+* FILENAME variable <1>: Auto-set. (line 93)
* FILENAME variable: Reading Files. (line 6)
* FILENAME variable, getline, setting with: Getline Notes. (line 19)
* filenames, assignments as: Ignoring Assigns. (line 6)
@@ -25922,12 +30241,11 @@ Index
* files, /inet6/... (gawk): TCP/IP Networking. (line 6)
* files, as single records: Records. (line 201)
* files, awk programs in: Long. (line 6)
-* files, awkprof.out: Profiling. (line 10)
-* files, awkvars.out: Options. (line 93)
+* files, awkprof.out: Profiling. (line 6)
+* files, awkvars.out: Options. (line 107)
* files, closing: I/O Functions. (line 10)
* files, descriptors, See file descriptors: Special FD. (line 6)
* files, group: Group Functions. (line 6)
-* files, information about, retrieving: Sample Library. (line 6)
* files, initialization and cleanup: Filetrans Function. (line 6)
* files, input, See input files: Read Terminal. (line 17)
* files, log, timestamps in: Time Functions. (line 6)
@@ -25951,7 +30269,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 138)
+* files, portable object, generating: Options. (line 161)
* files, processing, ARGIND variable and: Auto-set. (line 47)
* files, reading: Rewind Function. (line 6)
* files, reading, multiline records: Multiple Line. (line 6)
@@ -25960,23 +30278,21 @@ 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)
+* floating-point, numbers: General Arithmetic. (line 6)
+* FNR variable <1>: Auto-set. (line 103)
* FNR variable: Records. (line 6)
-* FNR variable, changing: Auto-set. (line 207)
+* FNR variable, changing: Auto-set. (line 295)
* for statement: For Statement. (line 6)
* for statement, in arrays: Scanning an Array. (line 20)
-* force_number() internal function: Internals. (line 27)
-* force_string() internal function: Internals. (line 32)
-* force_wstring() internal function: Internals. (line 37)
* format specifiers, mixing regular with positional specifiers: Printf Ordering.
(line 57)
* format specifiers, printf statement: Control Letters. (line 6)
@@ -25995,28 +30311,29 @@ 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)
+* Free Software Foundation (FSF) <1>: Glossary. (line 305)
* Free Software Foundation (FSF) <2>: Getting. (line 10)
* Free Software Foundation (FSF): Manual History. (line 6)
-* FreeBSD: Glossary. (line 615)
+* FreeBSD: Glossary. (line 619)
* FS variable <1>: User-modified. (line 56)
* FS variable: Field Separators. (line 14)
* 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 214)
+* FS variable, as TAB character: Options. (line 259)
* 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.
(line 6)
* FS, containing ^: Regexp Field Splitting.
(line 59)
-* FSF (Free Software Foundation) <1>: Glossary. (line 301)
+* FSF (Free Software Foundation) <1>: Glossary. (line 305)
* FSF (Free Software Foundation) <2>: Getting. (line 10)
* FSF (Free Software Foundation): Manual History. (line 6)
+* FUNCTAB array: Auto-set. (line 119)
* function calls: Function Calls. (line 6)
* function calls, indirect: Indirect Calls. (line 6)
* function pointers: Indirect Calls. (line 6)
@@ -26024,7 +30341,6 @@ Index
(line 47)
* functions, built-in <1>: Functions. (line 6)
* functions, built-in: Function Calls. (line 10)
-* functions, built-in, adding to gawk: Dynamic Extensions. (line 10)
* functions, built-in, evaluation order: Calling Built-in. (line 30)
* functions, defining: Definition Syntax. (line 6)
* functions, library: Library Functions. (line 6)
@@ -26042,7 +30358,7 @@ Index
(line 6)
* functions, library, managing data files: Data File Management.
(line 6)
-* functions, library, managing time: Gettimeofday Function.
+* functions, library, managing time: Getlocaltime Function.
(line 6)
* functions, library, merging arrays into strings: Join Function.
(line 6)
@@ -26052,20 +30368,20 @@ 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, 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 47)
* 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)
@@ -26086,13 +30402,13 @@ Index
* gawk, distribution: Distribution contents.
(line 6)
* gawk, ERRNO variable in <1>: TCP/IP Networking. (line 54)
-* gawk, ERRNO variable in <2>: Auto-set. (line 72)
+* gawk, ERRNO variable in <2>: Auto-set. (line 73)
* gawk, ERRNO variable in <3>: BEGINFILE/ENDFILE. (line 26)
* gawk, ERRNO variable in <4>: Close Files And Pipes.
(line 139)
* gawk, ERRNO variable in: Getline. (line 19)
* gawk, escape sequences: Escape Sequences. (line 125)
-* gawk, extensions, disabling: Options. (line 202)
+* gawk, extensions, disabling: Options. (line 247)
* gawk, features, adding: Adding Code. (line 6)
* gawk, features, advanced: Advanced Features. (line 6)
* gawk, field separators and: User-modified. (line 77)
@@ -26103,8 +30419,8 @@ Index
* gawk, FPAT variable in <1>: User-modified. (line 45)
* gawk, FPAT variable in: Splitting By Content.
(line 26)
+* gawk, FUNCTAB array in: Auto-set. (line 119)
* gawk, function arguments and: Calling Built-in. (line 16)
-* gawk, functions, adding: Dynamic Extensions. (line 10)
* gawk, hexadecimal numbers and: Nondecimal-numbers. (line 42)
* gawk, IGNORECASE variable in <1>: Array Sorting Functions.
(line 81)
@@ -26119,7 +30435,6 @@ Index
* gawk, implementation issues, limits: Getline Notes. (line 14)
* gawk, implementation issues, pipes: Redirection. (line 135)
* gawk, installing: Installation. (line 6)
-* gawk, internals: Internals. (line 6)
* gawk, internationalization and, See internationalization: Internationalization.
(line 13)
* gawk, interpreter, adding code to: Using Internal File Ops.
@@ -26135,7 +30450,7 @@ Index
* gawk, OS/2 version of: PC Using. (line 11)
* gawk, PROCINFO array in <1>: Two-way I/O. (line 116)
* gawk, PROCINFO array in <2>: Time Functions. (line 46)
-* gawk, PROCINFO array in: Auto-set. (line 123)
+* gawk, PROCINFO array in: Auto-set. (line 130)
* gawk, regexp constants and: Using Constant Regexps.
(line 28)
* gawk, regular expressions, case sensitivity: Case-sensitivity.
@@ -26143,7 +30458,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 246)
* gawk, RT variable in <2>: Getline/Variable/File.
(line 10)
* gawk, RT variable in <3>: Multiple Line. (line 129)
@@ -26152,25 +30467,20 @@ 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, SYMTAB array in: Auto-set. (line 254)
+* 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 253)
+* gawk, versions of, information about, printing: Options. (line 293)
* gawk, VMS version of: VMS Installation. (line 6)
* gawk, word-boundary operator: GNU Regexp Operators.
(line 63)
-* General Public License (GPL): Glossary. (line 310)
+* General Public License (GPL): Glossary. (line 314)
* General Public License, See GPL: Manual History. (line 11)
* gensub() function (gawk) <1>: String Functions. (line 86)
* 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)
* 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)
@@ -26195,6 +30505,8 @@ Index
* getline command, variants: Getline Summary. (line 6)
* getline statement, BEGINFILE/ENDFILE patterns and: BEGINFILE/ENDFILE.
(line 54)
+* getlocaltime() user-defined function: Getlocaltime Function.
+ (line 16)
* getopt() function (C library): Getopt Function. (line 15)
* getopt() user-defined function: Getopt Function. (line 108)
* getpwent() function (C library): Passwd Functions. (line 16)
@@ -26206,25 +30518,27 @@ Index
* gettext library: Explaining gettext. (line 6)
* gettext library, locale categories: Explaining gettext. (line 80)
* gettext() function (C library): Explaining gettext. (line 62)
-* gettimeofday() user-defined function: Gettimeofday Function.
- (line 16)
+* gettimeofday time extension function: Extension Sample Time.
+ (line 10)
+* 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.
(line 6)
-* GNU General Public License: Glossary. (line 310)
-* GNU Lesser General Public License: Glossary. (line 401)
+* GNU General Public License: Glossary. (line 314)
+* GNU Lesser General Public License: Glossary. (line 405)
* GNU long options <1>: Options. (line 6)
* GNU long options: Command Line. (line 13)
-* GNU long options, printing list of: Options. (line 145)
-* GNU Project <1>: Glossary. (line 319)
+* GNU long options, printing list of: Options. (line 168)
+* GNU Project <1>: Glossary. (line 323)
* GNU Project: Manual History. (line 11)
-* GNU/Linux <1>: Glossary. (line 615)
+* GNU/Linux <1>: Glossary. (line 619)
* GNU/Linux <2>: I18N Example. (line 55)
* GNU/Linux: Manual History. (line 28)
-* GPL (General Public License) <1>: Glossary. (line 310)
+* GPL (General Public License) <1>: Glossary. (line 314)
* GPL (General Public License): Manual History. (line 11)
-* GPL (General Public License), printing: Options. (line 88)
+* GPL (General Public License), printing: Options. (line 102)
* grcat program: Group Functions. (line 16)
* Grigera, Juan: Contributors. (line 58)
* group database, reading: Group Functions. (line 6)
@@ -26235,7 +30549,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)
@@ -26244,28 +30558,30 @@ 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 169)
+* hexadecimal values, enabling interpretation of: Options. (line 207)
* 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)
* hyphen (-), -= operator <1>: Precedence. (line 95)
* hyphen (-), -= operator: Assignment Ops. (line 129)
-* hyphen (-), filenames beginning with: Options. (line 59)
+* hyphen (-), filenames beginning with: Options. (line 73)
* 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)
@@ -26293,7 +30609,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.
@@ -26318,47 +30636,18 @@ 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)
-* integers: Basic Data Typing. (line 21)
-* integers, unsigned: Basic Data Typing. (line 30)
+* integer, arbitrary precision: Arbitrary Precision Integers.
+ (line 6)
+* integers: General Arithmetic. (line 6)
+* integers, unsigned: General Arithmetic. (line 15)
* interacting with other programs: I/O Functions. (line 72)
-* 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 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 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)
* 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.
@@ -26370,44 +30659,44 @@ Index
* internationalization, localization, portability and: I18N Portability.
(line 6)
* internationalizing a program: Explaining gettext. (line 6)
-* interpreted programs <1>: Glossary. (line 361)
-* interpreted programs: Basic High Level. (line 14)
+* interpreted programs <1>: Glossary. (line 365)
+* interpreted programs: Basic High Level. (line 15)
* interval expressions: Regexp Operators. (line 116)
-* INVALID_HANDLE internal constant: Internals. (line 160)
* inventory-shipped file: Sample Data Files. (line 32)
-* IOBUF internal structure: Internals. (line 160)
-* iop_alloc() internal function: Internals. (line 160)
* isarray() function (gawk): Type Functions. (line 11)
-* ISO: Glossary. (line 372)
+* ISO: Glossary. (line 376)
* ISO 8859-1: Glossary. (line 141)
* ISO Latin-1: Glossary. (line 141)
* 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 programming language: Glossary. (line 384)
-* jawk: Other Versions. (line 96)
+* Java implementation of awk: Other Versions. (line 97)
+* Java programming language: Glossary. (line 388)
+* 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)
* Kahrs, Ju"rgen: Acknowledgments. (line 60)
* Kasal, Stepan: Acknowledgments. (line 60)
* Kenobi, Obi-Wan: Undocumented. (line 6)
-* Kernighan, Brian <1>: Basic Data Typing. (line 74)
+* Kernighan, Brian <1>: Basic Data Typing. (line 55)
* Kernighan, Brian <2>: Other Versions. (line 13)
* 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)
+* languages, data-driven: Basic High Level. (line 85)
+* 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)
@@ -26428,9 +30717,9 @@ Index
* left shift, bitwise: Bitwise Functions. (line 32)
* leftmost longest match: Multiple Line. (line 26)
* length() function: String Functions. (line 166)
-* Lesser General Public License (LGPL): Glossary. (line 401)
-* LGPL (Lesser General Public License): Glossary. (line 401)
-* libmawk: Other Versions. (line 104)
+* Lesser General Public License (LGPL): Glossary. (line 405)
+* LGPL (Lesser General Public License): Glossary. (line 405)
+* 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.
@@ -26445,7 +30734,7 @@ Index
(line 6)
* libraries of awk functions, managing, data files: Data File Management.
(line 6)
-* libraries of awk functions, managing, time: Gettimeofday Function.
+* libraries of awk functions, managing, time: Getlocaltime Function.
(line 6)
* libraries of awk functions, merging arrays into strings: Join Function.
(line 6)
@@ -26468,20 +30757,21 @@ Index
* lint checking, array subscripts: Uninitialized Subscripts.
(line 43)
* lint checking, empty programs: Command Line. (line 16)
-* lint checking, issuing warnings: Options. (line 150)
+* lint checking, issuing warnings: Options. (line 182)
* lint checking, POSIXLY_CORRECT environment variable: Options.
- (line 292)
+ (line 332)
* lint checking, undefined functions: Pass By Value/Reference.
(line 88)
* LINT variable: User-modified. (line 98)
-* Linux <1>: Glossary. (line 615)
+* Linux <1>: Glossary. (line 619)
* 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, library: Options. (line 173)
* local variables: Variable Scope. (line 6)
* locale categories: Explaining gettext. (line 80)
-* locale decimal point character: Options. (line 218)
+* locale decimal point character: Options. (line 263)
* locale, definition of: Locales. (line 6)
* localization: I18N and L10N. (line 6)
* localization, See internationalization, localization: I18N and L10N.
@@ -26494,18 +30784,14 @@ 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)
* ls utility: More Complex. (line 15)
-* lshift() function (gawk): Bitwise Functions. (line 45)
+* lshift() function (gawk): Bitwise Functions. (line 46)
* 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)
* mark parity: Ordinal Functions. (line 45)
* marked string extraction (internationalization): String Extraction.
(line 6)
@@ -26517,10 +30803,9 @@ Index
* matching, expressions, See comparison expressions: Typing and Comparison.
(line 9)
* matching, leftmost longest: Multiple Line. (line 26)
-* matching, null strings: Gory Details. (line 164)
+* matching, null strings: Gory Details. (line 165)
* mawk program: Other Versions. (line 35)
* McPhee, Patrick: Contributors. (line 100)
-* memory, releasing: Internals. (line 101)
* message object files: Explaining gettext. (line 41)
* message object files, converting from portable object files: I18N Example.
(line 62)
@@ -26532,8 +30817,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)
@@ -26542,14 +30831,13 @@ 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)
* nawk utility: Names. (line 17)
-* negative zero: Unexpected Results. (line 28)
-* NetBSD: Glossary. (line 615)
+* negative zero: Unexpected Results. (line 34)
+* NetBSD: Glossary. (line 619)
* networks, programming: TCP/IP Networking. (line 6)
* networks, support for: Special Network. (line 6)
* newlines <1>: Boolean Ops. (line 67)
-* newlines <2>: Options. (line 208)
+* newlines <2>: Options. (line 253)
* newlines: Statements/Lines. (line 6)
* newlines, as field separators: Default Field Splitting.
(line 6)
@@ -26560,7 +30848,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)
@@ -26575,21 +30863,19 @@ Index
(line 26)
* nextfile statement, user-defined functions and: Nextfile Statement.
(line 47)
-* nexti debugger command: Dgawk Execution Control.
+* nexti debugger command: Debugger Execution Control.
(line 49)
-* NF variable <1>: Auto-set. (line 107)
+* NF variable <1>: Auto-set. (line 108)
* 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)
* not Boolean-logic operator: Boolean Ops. (line 6)
-* NR variable <1>: Auto-set. (line 118)
+* NR variable <1>: Auto-set. (line 125)
* NR variable: Records. (line 6)
-* NR variable, changing: Auto-set. (line 207)
-* null strings <1>: Basic Data Typing. (line 50)
+* NR variable, changing: Auto-set. (line 295)
+* null strings <1>: Basic Data Typing. (line 26)
* null strings <2>: Truth Values. (line 6)
* null strings <3>: Regexp Field Splitting.
(line 43)
@@ -26598,38 +30884,34 @@ Index
* null strings, as array subscripts: Uninitialized Subscripts.
(line 43)
* null strings, converting numbers to strings: Conversion. (line 21)
-* null strings, matching: Gory Details. (line 164)
+* null strings, matching: Gory Details. (line 165)
* null strings, quoting and: Quoting. (line 62)
* number sign (#), #! (executable scripts): Executable Scripts.
(line 6)
* number sign (#), #! (executable scripts), portability issues with: Executable Scripts.
(line 6)
* number sign (#), commenting: Comments. (line 6)
-* numbers: Internals. (line 91)
* numbers, as array subscripts: Numeric Array Subscripts.
(line 6)
* numbers, as values of characters: Ordinal Functions. (line 6)
* numbers, Cliff random: Cliff Random Function.
(line 6)
-* numbers, converting <1>: Bitwise Functions. (line 107)
+* numbers, converting <1>: Bitwise Functions. (line 109)
* numbers, converting: Conversion. (line 6)
* numbers, converting, to strings: User-modified. (line 28)
-* numbers, floating-point: Basic Data Typing. (line 21)
-* numbers, floating-point, AWKNUM internal type: Internals. (line 19)
+* numbers, floating-point: General Arithmetic. (line 6)
* numbers, hexadecimal: Nondecimal-numbers. (line 6)
-* numbers, NODE internal type: Internals. (line 23)
* numbers, octal: Nondecimal-numbers. (line 6)
* numbers, random: Numeric Functions. (line 64)
* numbers, rounding: Round Function. (line 6)
* numeric, constants: Scalar Constants. (line 6)
* 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 169)
+* octal values, enabling interpretation of: Options. (line 207)
* OFMT variable <1>: User-modified. (line 115)
* OFMT variable <2>: Conversion. (line 55)
* OFMT variable: OFMT. (line 15)
@@ -26637,8 +30919,8 @@ Index
* OFS variable <1>: User-modified. (line 124)
* OFS variable <2>: Output Separators. (line 6)
* OFS variable: Changing Fields. (line 64)
-* OpenBSD: Glossary. (line 615)
-* OpenSolaris: Other Versions. (line 86)
+* OpenBSD: Glossary. (line 619)
+* 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.
@@ -26671,21 +30953,21 @@ 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)
* options, command-line: Long. (line 12)
-* options, command-line, end of: Options. (line 54)
+* options, command-line, end of: Options. (line 68)
* options, command-line, invoking awk: Command Line. (line 6)
* options, command-line, processing: Getopt Function. (line 6)
* options, deprecated: Obsolete. (line 6)
* options, long <1>: Options. (line 6)
* options, long: Command Line. (line 13)
-* options, printing list of: Options. (line 145)
+* options, printing list of: Options. (line 168)
* OR bitwise operation: Bitwise Functions. (line 6)
* or Boolean-logic operator: Boolean Ops. (line 6)
-* or() function (gawk): Bitwise Functions. (line 48)
+* or() function (gawk): Bitwise Functions. (line 49)
* ord() user-defined function: Ordinal Functions. (line 16)
* order of evaluation, concatenation: Concatenation. (line 42)
* ORS variable <1>: User-modified. (line 129)
@@ -26706,17 +30988,16 @@ Index
* output, standard: Special FD. (line 6)
* p debugger command (alias for print): Viewing And Changing Data.
(line 36)
-* P1003.1 POSIX standard: Glossary. (line 458)
-* P1003.2 POSIX standard: Glossary. (line 458)
-* parameters, number of: Internals. (line 49)
+* P1003.1 POSIX standard: Glossary. (line 462)
+* P1003.2 POSIX standard: Glossary. (line 462)
+* 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)
@@ -26734,9 +31015,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)
@@ -26777,13 +31055,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 313)
+* portability, POSIXLY_CORRECT environment variable: Options. (line 353)
* 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 138)
+* portable object files, generating: Options. (line 161)
* portable object template files: Explaining gettext. (line 30)
* porting gawk: New Ports. (line 6)
* positional specifiers, printf statement <1>: Printf Ordering.
@@ -26791,7 +31069,7 @@ Index
* positional specifiers, printf statement: Format Modifiers. (line 13)
* positional specifiers, printf statement, mixing with regular formats: Printf Ordering.
(line 57)
-* positive zero: Unexpected Results. (line 28)
+* positive zero: Unexpected Results. (line 34)
* POSIX awk <1>: Assignment Ops. (line 136)
* POSIX awk: This Manual. (line 14)
* POSIX awk, ** operator and: Precedence. (line 98)
@@ -26827,11 +31105,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 202)
+* POSIX mode: Options. (line 247)
* 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 292)
+* POSIXLY_CORRECT environment variable: Options. (line 332)
+* 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)
@@ -26865,24 +31145,23 @@ 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 145)
+* printing, list of options: Options. (line 168)
* 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>: Two-way I/O. (line 116)
* PROCINFO array <2>: Id Program. (line 15)
* PROCINFO array <3>: Group Functions. (line 6)
* PROCINFO array <4>: Passwd Functions. (line 6)
-* PROCINFO array <5>: Two-way I/O. (line 116)
-* PROCINFO array <6>: Time Functions. (line 46)
-* PROCINFO array <7>: Auto-set. (line 123)
+* PROCINFO array <5>: Time Functions. (line 46)
+* PROCINFO array <6>: Auto-set. (line 130)
* 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.
@@ -26895,34 +31174,34 @@ Index
(line 10)
* programming conventions, functions, writing: Definition Syntax.
(line 55)
-* programming conventions, gawk internals: Internal File Ops. (line 33)
+* programming conventions, gawk internals: Internal File Ops. (line 45)
* programming conventions, private variable names: Library Names.
(line 23)
* programming language, recipe for: History. (line 6)
* Programming languages, Ada: Glossary. (line 20)
* programming languages, data-driven vs. procedural: Getting Started.
(line 12)
-* Programming languages, Java: Glossary. (line 384)
-* programming, basic steps: Basic High Level. (line 19)
+* Programming languages, Java: Glossary. (line 388)
+* programming, basic steps: Basic High Level. (line 20)
* 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)
@@ -26940,12 +31219,12 @@ 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 117)
* record separators, with multiline records: Multiple Line. (line 10)
-* records <1>: Basic High Level. (line 71)
+* records <1>: Basic High Level. (line 73)
* records: Reading Files. (line 14)
* records, multiline: Multiple Line. (line 6)
* records, printing: Print. (line 22)
@@ -26968,8 +31247,6 @@ 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)
* regular expressions: Regexp. (line 6)
* regular expressions as field separators: Field Separators. (line 50)
* regular expressions, anchors in: Regexp Operators. (line 22)
@@ -26988,7 +31265,7 @@ Index
(line 59)
* regular expressions, gawk, command-line options: GNU Regexp Operators.
(line 70)
-* regular expressions, interval expressions and: Options. (line 227)
+* regular expressions, interval expressions and: Options. (line 272)
* regular expressions, leftmost longest match: Leftmost Longest.
(line 6)
* regular expressions, operators <1>: Regexp Operators. (line 6)
@@ -27004,7 +31281,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.
@@ -27021,8 +31298,8 @@ Index
* right angle bracket (>), >> operator (I/O) <1>: Precedence. (line 65)
* 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)
+* Ritchie, Dennis: Basic Data Typing. (line 55)
+* RLENGTH variable: Auto-set. (line 233)
* RLENGTH variable, match() function and: String Functions. (line 223)
* Robbins, Arnold <1>: Future Extensions. (line 6)
* Robbins, Arnold <2>: Bugs. (line 32)
@@ -27033,23 +31310,25 @@ 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)
-* Robinson, Will: Dynamic Extensions. (line 6)
-* robot, the: Dynamic Extensions. (line 6)
+* Robbins, Miriam: Acknowledgments. (line 83)
* 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)
+* rshift() function (gawk): Bitwise Functions. (line 52)
+* RSTART variable: Auto-set. (line 239)
* RSTART variable, match() function and: String Functions. (line 223)
-* RT variable <1>: Auto-set. (line 196)
+* RT variable <1>: Auto-set. (line 246)
* RT variable <2>: Getline/Variable/File.
(line 10)
* RT variable <3>: Multiple Line. (line 129)
@@ -27057,12 +31336,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 239)
+* sandbox mode: Options. (line 279)
* scalar values: Basic Data Typing. (line 13)
* Schorr, Andrew: Acknowledgments. (line 60)
* Schreiber, Bert: Acknowledgments. (line 38)
@@ -27070,7 +31349,9 @@ Index
* search paths <1>: VMS Running. (line 29)
* search paths <2>: PC Using. (line 11)
* search paths <3>: Igawk Program. (line 368)
+* search paths <4>: AWKLIBPATH Variable. (line 6)
* search paths: AWKPATH Variable. (line 6)
+* search paths, for shared libraries: AWKLIBPATH Variable. (line 6)
* search paths, for source files <1>: VMS Running. (line 29)
* search paths, for source files <2>: PC Using. (line 11)
* search paths, for source files <3>: Igawk Program. (line 368)
@@ -27092,11 +31373,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 117)
* 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)
@@ -27108,7 +31389,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)
@@ -27123,18 +31404,18 @@ 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)
+* single precision floating-point: General Arithmetic. (line 21)
* single quote (') <1>: Quoting. (line 31)
* single quote (') <2>: Long. (line 33)
* single quote ('): One-shot. (line 15)
@@ -27143,8 +31424,12 @@ Index
* single-character fields: Single Character Fields.
(line 6)
* Skywalker, Luke: Undocumented. (line 6)
+* sleep: Extension Sample Time.
+ (line 6)
+* sleep time extension function: Extension Sample Time.
+ (line 20)
* 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)
@@ -27153,17 +31438,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 108)
+* source code, mixing: Options. (line 131)
* 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)
@@ -27179,7 +31464,7 @@ Index
* sqrt() function: Numeric Functions. (line 78)
* square brackets ([]): Regexp Operators. (line 55)
* srand() function: Numeric Functions. (line 82)
-* Stallman, Richard <1>: Glossary. (line 301)
+* Stallman, Richard <1>: Glossary. (line 305)
* Stallman, Richard <2>: Contributors. (line 24)
* Stallman, Richard <3>: Acknowledgments. (line 18)
* Stallman, Richard: Manual History. (line 6)
@@ -27187,16 +31472,13 @@ Index
* standard input <1>: Special FD. (line 6)
* standard input: Read Terminal. (line 6)
* standard output: Special FD. (line 6)
-* stat() function, implementing in gawk: Sample Library. (line 6)
* 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)
* stream editors <1>: Simple Sed. (line 6)
* stream editors: Field Splitting Summary.
(line 47)
@@ -27207,8 +31489,7 @@ Index
(line 6)
* string operators: Concatenation. (line 9)
* string-matching operators: Regexp Usage. (line 19)
-* strings: Internals. (line 86)
-* strings, converting <1>: Bitwise Functions. (line 107)
+* strings, converting <1>: Bitwise Functions. (line 109)
* strings, converting: Conversion. (line 6)
* strings, converting, numbers to: User-modified. (line 28)
* strings, empty, See null strings: Records. (line 107)
@@ -27216,7 +31497,6 @@ Index
* strings, for localization: Programmer i18n. (line 14)
* strings, length of: Scalar Constants. (line 20)
* strings, merging arrays into: Join Function. (line 6)
-* strings, NODE internal type: Internals. (line 23)
* strings, null: Regexp Field Splitting.
(line 43)
* strings, numeric: Variable Typing. (line 6)
@@ -27229,7 +31509,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)
@@ -27237,25 +31517,26 @@ 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)
* Sumner, Andrew: Other Versions. (line 55)
* switch statement: Switch Statement. (line 6)
+* SYMTAB array: Auto-set. (line 254)
* syntactic ambiguity: /= operator vs. /=.../ regexp constant: Assignment Ops.
(line 148)
* system() function: I/O Functions. (line 72)
* 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)
* tee utility: Tee Program. (line 6)
* tee.awk program: Tee Program. (line 26)
* terminating records: Records. (line 117)
-* testbits.awk program: Bitwise Functions. (line 68)
+* testbits.awk program: Bitwise Functions. (line 70)
* Texinfo <1>: Adding Code. (line 99)
* Texinfo <2>: Distribution contents.
(line 80)
@@ -27270,7 +31551,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)
@@ -27282,22 +31563,25 @@ Index
* tilde (~), ~ operator <5>: Computed Regexps. (line 6)
* tilde (~), ~ operator <6>: Case-sensitivity. (line 26)
* tilde (~), ~ operator: Regexp Usage. (line 19)
+* time: Extension Sample Time.
+ (line 6)
* time, alarm clock example program: Alarm Program. (line 9)
* time, localization and: Explaining gettext. (line 115)
-* time, managing: Gettimeofday Function.
+* time, managing: Getlocaltime 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.
+* timestamps, formatted: Getlocaltime Function.
(line 6)
* 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 169)
+* troubleshooting, --non-decimal-data option: Options. (line 207)
* troubleshooting, == operator: Comparison Operators.
(line 37)
* troubleshooting, awk uses FS not IFS: Field Separators. (line 29)
@@ -27329,7 +31613,7 @@ Index
* troubleshooting, substr() function: String Functions. (line 499)
* troubleshooting, system() function: I/O Functions. (line 94)
* troubleshooting, typographical errors, global variables: Options.
- (line 98)
+ (line 112)
* true, logical: Truth Values. (line 6)
* Trueman, David <1>: Contributors. (line 31)
* Trueman, David <2>: Acknowledgments. (line 47)
@@ -27337,8 +31621,7 @@ 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.
+* u debugger command (alias for until): Debugger Execution Control.
(line 83)
* undefined functions: Pass By Value/Reference.
(line 71)
@@ -27354,7 +31637,7 @@ Index
(line 6)
* uniq utility: Uniq Program. (line 6)
* uniq.awk program: Uniq Program. (line 65)
-* Unix: Glossary. (line 615)
+* Unix: Glossary. (line 619)
* Unix awk, backslashes in escape sequences: Escape Sequences.
(line 125)
* Unix awk, close() function and: Close Files And Pipes.
@@ -27363,23 +31646,20 @@ 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)
-* unsigned integers: Basic Data Typing. (line 30)
-* until debugger command: Dgawk Execution Control.
+* unsigned integers: General Arithmetic. (line 15)
+* 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)
* 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.
@@ -27389,7 +31669,7 @@ Index
* variables, assigning on command line: Assignment Options. (line 6)
* variables, built-in <1>: Built-in Variables. (line 6)
* variables, built-in: Using Variables. (line 20)
-* variables, built-in, -v option, setting with: Options. (line 40)
+* variables, built-in, -v option, setting with: Options. (line 54)
* variables, built-in, conveying information: Auto-set. (line 6)
* variables, flag: Boolean Ops. (line 67)
* variables, getline command into, using <1>: Getline/Variable/Coprocess.
@@ -27400,12 +31680,12 @@ Index
(line 6)
* variables, getline command into, using: Getline/Variable. (line 6)
* variables, global, for library functions: Library Names. (line 11)
-* variables, global, printing list of: Options. (line 93)
+* variables, global, printing list of: Options. (line 107)
* variables, initializing: Using Variables. (line 20)
* variables, local: Variable Scope. (line 6)
* variables, names of: Arrays. (line 18)
* variables, private: Library Names. (line 11)
-* variables, setting: Options. (line 32)
+* variables, setting: Options. (line 46)
* variables, shadowing: Definition Syntax. (line 61)
* variables, types of: Assignment Ops. (line 40)
* variables, types of, comparison expressions and: Typing and Comparison.
@@ -27422,7 +31702,6 @@ 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)
* w debugger command (alias for watch): Viewing And Changing Data.
(line 67)
* w utility: Constant Size. (line 22)
@@ -27430,7 +31709,7 @@ Index
* Wall, Larry <1>: Future Extensions. (line 6)
* Wall, Larry: Array Intro. (line 6)
* Wallin, Anders: Acknowledgments. (line 60)
-* warnings, issuing: Options. (line 150)
+* warnings, issuing: Options. (line 182)
* watch debugger command: Viewing And Changing Data.
(line 67)
* wc utility: Wc Program. (line 6)
@@ -27442,7 +31721,7 @@ Index
* whitespace, as field separators: Default Field Splitting.
(line 6)
* whitespace, functions, calling: Calling Built-in. (line 10)
-* whitespace, newlines as: Options. (line 208)
+* whitespace, newlines as: Options. (line 253)
* Williams, Kent: Contributors. (line 35)
* Woehlke, Matthew: Contributors. (line 79)
* Woods, John: Contributors. (line 28)
@@ -27456,22 +31735,19 @@ 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)
+* xgawk: Other Versions. (line 120)
* xgettext utility: String Extraction. (line 13)
-* XML (eXtensible Markup Language): Internals. (line 160)
* XOR bitwise operation: Bitwise Functions. (line 6)
-* xor() function (gawk): Bitwise Functions. (line 54)
+* xor() function (gawk): Bitwise Functions. (line 55)
* Yawitz, Efraim: Contributors. (line 106)
* Zaretskii, Eli <1>: Bugs. (line 70)
* Zaretskii, Eli <2>: Contributors. (line 56)
* Zaretskii, Eli: Acknowledgments. (line 60)
-* zero, negative vs. positive: Unexpected Results. (line 28)
+* zero, negative vs. positive: Unexpected Results. (line 34)
* 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)
@@ -27498,6 +31774,519 @@ Index

Tag Table:
Node: Top1352
+<<<<<<< HEAD
+Node: Foreword40138
+Node: Preface44483
+Ref: Preface-Footnote-147536
+Ref: Preface-Footnote-247642
+Node: History47874
+Node: Names50265
+Ref: Names-Footnote-151742
+Node: This Manual51814
+Ref: This Manual-Footnote-157720
+Node: Conventions57820
+Node: Manual History59954
+Ref: Manual History-Footnote-163224
+Ref: Manual History-Footnote-263265
+Node: How To Contribute63339
+Node: Acknowledgments64483
+Node: Getting Started68979
+Node: Running gawk71358
+Node: One-shot72544
+Node: Read Terminal73769
+Ref: Read Terminal-Footnote-175419
+Ref: Read Terminal-Footnote-275695
+Node: Long75866
+Node: Executable Scripts77242
+Ref: Executable Scripts-Footnote-179111
+Ref: Executable Scripts-Footnote-279213
+Node: Comments79760
+Node: Quoting82227
+Node: DOS Quoting86850
+Node: Sample Data Files87525
+Node: Very Simple90557
+Node: Two Rules95156
+Node: More Complex97303
+Ref: More Complex-Footnote-1100233
+Node: Statements/Lines100318
+Ref: Statements/Lines-Footnote-1104780
+Node: Other Features105045
+Node: When105973
+Node: Invoking Gawk108120
+Node: Command Line109581
+Node: Options110364
+Ref: Options-Footnote-1125762
+Node: Other Arguments125787
+Node: Naming Standard Input128445
+Node: Environment Variables129539
+Node: AWKPATH Variable130097
+Ref: AWKPATH Variable-Footnote-1132855
+Node: AWKLIBPATH Variable133115
+Node: Other Environment Variables133712
+Node: Exit Status136207
+Node: Include Files136882
+Node: Loading Shared Libraries140451
+Node: Obsolete141676
+Node: Undocumented142373
+Node: Regexp142616
+Node: Regexp Usage144005
+Node: Escape Sequences146031
+Node: Regexp Operators151794
+Ref: Regexp Operators-Footnote-1159174
+Ref: Regexp Operators-Footnote-2159321
+Node: Bracket Expressions159419
+Ref: table-char-classes161309
+Node: GNU Regexp Operators163832
+Node: Case-sensitivity167555
+Ref: Case-sensitivity-Footnote-1170523
+Ref: Case-sensitivity-Footnote-2170758
+Node: Leftmost Longest170866
+Node: Computed Regexps172067
+Node: Reading Files175477
+Node: Records177480
+Ref: Records-Footnote-1186404
+Node: Fields186441
+Ref: Fields-Footnote-1189474
+Node: Nonconstant Fields189560
+Node: Changing Fields191762
+Node: Field Separators197743
+Node: Default Field Splitting200372
+Node: Regexp Field Splitting201489
+Node: Single Character Fields204831
+Node: Command Line Field Separator205890
+Node: Field Splitting Summary209331
+Ref: Field Splitting Summary-Footnote-1212523
+Node: Constant Size212624
+Node: Splitting By Content217208
+Ref: Splitting By Content-Footnote-1220934
+Node: Multiple Line220974
+Ref: Multiple Line-Footnote-1226821
+Node: Getline227000
+Node: Plain Getline229216
+Node: Getline/Variable231305
+Node: Getline/File232446
+Node: Getline/Variable/File233768
+Ref: Getline/Variable/File-Footnote-1235367
+Node: Getline/Pipe235454
+Node: Getline/Variable/Pipe238014
+Node: Getline/Coprocess239121
+Node: Getline/Variable/Coprocess240364
+Node: Getline Notes241078
+Node: Getline Summary243865
+Ref: table-getline-variants244273
+Node: Read Timeout245131
+Ref: Read Timeout-Footnote-1248876
+Node: Command line directories248933
+Node: Printing249563
+Node: Print251194
+Node: Print Examples252531
+Node: Output Separators255315
+Node: OFMT257075
+Node: Printf258433
+Node: Basic Printf259339
+Node: Control Letters260878
+Node: Format Modifiers264690
+Node: Printf Examples270699
+Node: Redirection273414
+Node: Special Files280398
+Node: Special FD280931
+Ref: Special FD-Footnote-1284556
+Node: Special Network284630
+Node: Special Caveats285480
+Node: Close Files And Pipes286276
+Ref: Close Files And Pipes-Footnote-1293299
+Ref: Close Files And Pipes-Footnote-2293447
+Node: Expressions293597
+Node: Values294729
+Node: Constants295405
+Node: Scalar Constants296085
+Ref: Scalar Constants-Footnote-1296944
+Node: Nondecimal-numbers297126
+Node: Regexp Constants300185
+Node: Using Constant Regexps300660
+Node: Variables303715
+Node: Using Variables304370
+Node: Assignment Options306094
+Node: Conversion307966
+Ref: table-locale-affects313342
+Ref: Conversion-Footnote-1313966
+Node: All Operators314075
+Node: Arithmetic Ops314705
+Node: Concatenation317210
+Ref: Concatenation-Footnote-1320003
+Node: Assignment Ops320123
+Ref: table-assign-ops325111
+Node: Increment Ops326519
+Node: Truth Values and Conditions329989
+Node: Truth Values331072
+Node: Typing and Comparison332121
+Node: Variable Typing332910
+Ref: Variable Typing-Footnote-1336807
+Node: Comparison Operators336929
+Ref: table-relational-ops337339
+Node: POSIX String Comparison340888
+Ref: POSIX String Comparison-Footnote-1341844
+Node: Boolean Ops341982
+Ref: Boolean Ops-Footnote-1346060
+Node: Conditional Exp346151
+Node: Function Calls347883
+Node: Precedence351477
+Node: Locales355146
+Node: Patterns and Actions356235
+Node: Pattern Overview357289
+Node: Regexp Patterns358958
+Node: Expression Patterns359501
+Node: Ranges363186
+Node: BEGIN/END366152
+Node: Using BEGIN/END366914
+Ref: Using BEGIN/END-Footnote-1369645
+Node: I/O And BEGIN/END369751
+Node: BEGINFILE/ENDFILE372033
+Node: Empty374937
+Node: Using Shell Variables375253
+Node: Action Overview377538
+Node: Statements379895
+Node: If Statement381749
+Node: While Statement383248
+Node: Do Statement385292
+Node: For Statement386448
+Node: Switch Statement389600
+Node: Break Statement391697
+Node: Continue Statement393687
+Node: Next Statement395480
+Node: Nextfile Statement397870
+Node: Exit Statement400511
+Node: Built-in Variables402927
+Node: User-modified404022
+Ref: User-modified-Footnote-1412377
+Node: Auto-set412439
+Ref: Auto-set-Footnote-1424790
+Ref: Auto-set-Footnote-2424995
+Node: ARGC and ARGV425051
+Node: Arrays428902
+Node: Array Basics430407
+Node: Array Intro431233
+Node: Reference to Elements435551
+Node: Assigning Elements437821
+Node: Array Example438312
+Node: Scanning an Array440044
+Node: Controlling Scanning442358
+Ref: Controlling Scanning-Footnote-1447291
+Node: Delete447607
+Ref: Delete-Footnote-1450372
+Node: Numeric Array Subscripts450429
+Node: Uninitialized Subscripts452612
+Node: Multi-dimensional454240
+Node: Multi-scanning457334
+Node: Arrays of Arrays458925
+Node: Functions463570
+Node: Built-in464389
+Node: Calling Built-in465467
+Node: Numeric Functions467455
+Ref: Numeric Functions-Footnote-1471287
+Ref: Numeric Functions-Footnote-2471644
+Ref: Numeric Functions-Footnote-3471692
+Node: String Functions471961
+Ref: String Functions-Footnote-1495458
+Ref: String Functions-Footnote-2495587
+Ref: String Functions-Footnote-3495835
+Node: Gory Details495922
+Ref: table-sub-escapes497601
+Ref: table-sub-posix-92498955
+Ref: table-sub-proposed500306
+Ref: table-posix-sub501660
+Ref: table-gensub-escapes503205
+Ref: Gory Details-Footnote-1504412
+Ref: Gory Details-Footnote-2504463
+Node: I/O Functions504614
+Ref: I/O Functions-Footnote-1511719
+Node: Time Functions511866
+Ref: Time Functions-Footnote-1522758
+Ref: Time Functions-Footnote-2522826
+Ref: Time Functions-Footnote-3522984
+Ref: Time Functions-Footnote-4523095
+Ref: Time Functions-Footnote-5523207
+Ref: Time Functions-Footnote-6523434
+Node: Bitwise Functions523700
+Ref: table-bitwise-ops524258
+Ref: Bitwise Functions-Footnote-1528479
+Node: Type Functions528663
+Node: I18N Functions529133
+Node: User-defined530760
+Node: Definition Syntax531564
+Ref: Definition Syntax-Footnote-1536474
+Node: Function Example536543
+Node: Function Caveats539137
+Node: Calling A Function539558
+Node: Variable Scope540673
+Node: Pass By Value/Reference543636
+Node: Return Statement547076
+Node: Dynamic Typing550057
+Node: Indirect Calls550792
+Node: Library Functions560477
+Ref: Library Functions-Footnote-1563476
+Node: Library Names563647
+Ref: Library Names-Footnote-1567118
+Ref: Library Names-Footnote-2567338
+Node: General Functions567424
+Node: Strtonum Function568377
+Node: Assert Function571307
+Node: Round Function574633
+Node: Cliff Random Function576176
+Node: Ordinal Functions577192
+Ref: Ordinal Functions-Footnote-1580262
+Ref: Ordinal Functions-Footnote-2580514
+Node: Join Function580723
+Ref: Join Function-Footnote-1582494
+Node: Getlocaltime Function582694
+Node: Data File Management586409
+Node: Filetrans Function587041
+Node: Rewind Function591180
+Node: File Checking592567
+Node: Empty Files593661
+Node: Ignoring Assigns595891
+Node: Getopt Function597444
+Ref: Getopt Function-Footnote-1608748
+Node: Passwd Functions608951
+Ref: Passwd Functions-Footnote-1617926
+Node: Group Functions618014
+Node: Walking Arrays626098
+Node: Sample Programs627667
+Node: Running Examples628344
+Node: Clones629072
+Node: Cut Program630296
+Node: Egrep Program640141
+Ref: Egrep Program-Footnote-1647914
+Node: Id Program648024
+Node: Split Program651640
+Ref: Split Program-Footnote-1655159
+Node: Tee Program655287
+Node: Uniq Program658090
+Node: Wc Program665519
+Ref: Wc Program-Footnote-1669785
+Ref: Wc Program-Footnote-2669985
+Node: Miscellaneous Programs670077
+Node: Dupword Program671265
+Node: Alarm Program673296
+Node: Translate Program678045
+Ref: Translate Program-Footnote-1682432
+Ref: Translate Program-Footnote-2682660
+Node: Labels Program682794
+Ref: Labels Program-Footnote-1686165
+Node: Word Sorting686249
+Node: History Sorting690133
+Node: Extract Program691972
+Ref: Extract Program-Footnote-1699455
+Node: Simple Sed699583
+Node: Igawk Program702645
+Ref: Igawk Program-Footnote-1717802
+Ref: Igawk Program-Footnote-2718003
+Node: Anagram Program718141
+Node: Signature Program721209
+Node: Internationalization722309
+Node: I18N and L10N723741
+Node: Explaining gettext724427
+Ref: Explaining gettext-Footnote-1729493
+Ref: Explaining gettext-Footnote-2729677
+Node: Programmer i18n729842
+Node: Translator i18n734042
+Node: String Extraction734835
+Ref: String Extraction-Footnote-1735796
+Node: Printf Ordering735882
+Ref: Printf Ordering-Footnote-1738666
+Node: I18N Portability738730
+Ref: I18N Portability-Footnote-1741179
+Node: I18N Example741242
+Ref: I18N Example-Footnote-1743877
+Node: Gawk I18N743949
+Node: Advanced Features744566
+Node: Nondecimal Data746070
+Node: Array Sorting747653
+Node: Controlling Array Traversal748350
+Node: Array Sorting Functions756588
+Ref: Array Sorting Functions-Footnote-1760262
+Ref: Array Sorting Functions-Footnote-2760355
+Node: Two-way I/O760549
+Ref: Two-way I/O-Footnote-1765981
+Node: TCP/IP Networking766051
+Node: Profiling768895
+Node: Debugger776349
+Node: Debugging777317
+Node: Debugging Concepts777750
+Node: Debugging Terms779606
+Node: Awk Debugging782203
+Node: Sample Debugging Session783095
+Node: Debugger Invocation783615
+Node: Finding The Bug784944
+Node: List of Debugger Commands791432
+Node: Breakpoint Control792766
+Node: Debugger Execution Control796430
+Node: Viewing And Changing Data799790
+Node: Execution Stack803146
+Node: Debugger Info804613
+Node: Miscellaneous Debugger Commands808594
+Node: Readline Support814039
+Node: Limitations814870
+Node: Arbitrary Precision Arithmetic817122
+Ref: Arbitrary Precision Arithmetic-Footnote-1818764
+Node: General Arithmetic818912
+Node: Floating Point Issues820632
+Node: String Conversion Precision821513
+Ref: String Conversion Precision-Footnote-1823219
+Node: Unexpected Results823328
+Node: POSIX Floating Point Problems825481
+Ref: POSIX Floating Point Problems-Footnote-1829306
+Node: Integer Programming829344
+Node: Floating-point Programming831097
+Ref: Floating-point Programming-Footnote-1837406
+Node: Floating-point Representation837670
+Node: Floating-point Context838835
+Ref: table-ieee-formats839677
+Node: Rounding Mode841061
+Ref: table-rounding-modes841540
+Ref: Rounding Mode-Footnote-1844544
+Node: Gawk and MPFR844725
+Node: Arbitrary Precision Floats845967
+Ref: Arbitrary Precision Floats-Footnote-1848396
+Node: Setting Precision848707
+Node: Setting Rounding Mode851440
+Ref: table-gawk-rounding-modes851844
+Node: Floating-point Constants853024
+Node: Changing Precision854448
+Ref: Changing Precision-Footnote-1855848
+Node: Exact Arithmetic856022
+Node: Arbitrary Precision Integers859130
+Ref: Arbitrary Precision Integers-Footnote-1862130
+Node: Dynamic Extensions862277
+Node: Extension Intro863663
+Node: Plugin License864871
+Node: Extension Design865545
+Node: Old Extension Problems866616
+Ref: Old Extension Problems-Footnote-1868126
+Node: Extension New Mechanism Goals868183
+Ref: Extension New Mechanism Goals-Footnote-1870895
+Node: Extension Other Design Decisions871081
+Node: Extension Mechanism Outline873193
+Ref: load-extension874218
+Ref: load-new-function875696
+Ref: call-new-function876677
+Node: Extension Future Growth878671
+Node: Extension API Description879489
+Node: Extension API Functions Introduction880817
+Node: General Data Types885517
+Ref: General Data Types-Footnote-1891119
+Node: Requesting Values891418
+Ref: table-value-types-returned892149
+Node: Constructor Functions893103
+Node: Registration Functions896099
+Node: Extension Functions896784
+Node: Exit Callback Functions898616
+Node: Extension Version String899859
+Node: Input Parsers900509
+Node: Output Wrappers909096
+Node: Two-way processors913512
+Node: Printing Messages915642
+Ref: Printing Messages-Footnote-1916719
+Node: Updating `ERRNO'916871
+Node: Accessing Parameters917610
+Node: Symbol Table Access918840
+Node: Symbol table by name919352
+Ref: Symbol table by name-Footnote-1921522
+Node: Symbol table by cookie921602
+Ref: Symbol table by cookie-Footnote-1925731
+Node: Cached values925794
+Ref: Cached values-Footnote-1929237
+Node: Array Manipulation929328
+Ref: Array Manipulation-Footnote-1930426
+Node: Array Data Types930465
+Ref: Array Data Types-Footnote-1933168
+Node: Array Functions933260
+Node: Flattening Arrays937026
+Node: Creating Arrays943859
+Node: Extension API Variables948654
+Node: Extension Versioning949290
+Node: Extension API Informational Variables951191
+Node: Extension API Boilerplate952277
+Node: Finding Extensions956108
+Node: Extension Example956655
+Node: Internal File Description957393
+Node: Internal File Ops961081
+Ref: Internal File Ops-Footnote-1972528
+Node: Using Internal File Ops972668
+Ref: Using Internal File Ops-Footnote-1975021
+Node: Extension Samples975287
+Node: Extension Sample File Functions976730
+Node: Extension Sample Fnmatch985203
+Node: Extension Sample Fork986929
+Node: Extension Sample Ord988143
+Node: Extension Sample Readdir988919
+Node: Extension Sample Revout990423
+Node: Extension Sample Rev2way991016
+Node: Extension Sample Read write array991706
+Node: Extension Sample Readfile993589
+Node: Extension Sample API Tests994344
+Node: Extension Sample Time994869
+Node: gawkextlib996176
+Node: Language History998557
+Node: V7/SVR3.11000079
+Node: SVR41002400
+Node: POSIX1003842
+Node: BTL1004850
+Node: POSIX/GNU1005655
+Node: Common Extensions1011190
+Node: Ranges and Locales1012249
+Ref: Ranges and Locales-Footnote-11016867
+Ref: Ranges and Locales-Footnote-21016894
+Ref: Ranges and Locales-Footnote-31017154
+Node: Contributors1017375
+Node: Installation1021671
+Node: Gawk Distribution1022565
+Node: Getting1023049
+Node: Extracting1023875
+Node: Distribution contents1025567
+Node: Unix Installation1030789
+Node: Quick Installation1031406
+Node: Additional Configuration Options1033368
+Node: Configuration Philosophy1034845
+Node: Non-Unix Installation1037187
+Node: PC Installation1037645
+Node: PC Binary Installation1038944
+Node: PC Compiling1040792
+Node: PC Testing1043736
+Node: PC Using1044912
+Node: Cygwin1049097
+Node: MSYS1050097
+Node: VMS Installation1050611
+Node: VMS Compilation1051214
+Ref: VMS Compilation-Footnote-11052221
+Node: VMS Installation Details1052279
+Node: VMS Running1053914
+Node: VMS Old Gawk1055521
+Node: Bugs1055995
+Node: Other Versions1059847
+Node: Notes1065162
+Node: Compatibility Mode1065821
+Node: Additions1066604
+Node: Accessing The Source1067531
+Node: Adding Code1069134
+Node: New Ports1075176
+Node: Derived Files1079311
+Ref: Derived Files-Footnote-11084619
+Ref: Derived Files-Footnote-21084653
+Ref: Derived Files-Footnote-31085253
+Node: Future Extensions1085351
+Node: Implementation Limitations1085932
+Node: Basic Concepts1087159
+Node: Basic High Level1087840
+Ref: figure-general-flow1088111
+Ref: figure-process-flow1088710
+Ref: Basic High Level-Footnote-11091939
+Node: Basic Data Typing1092124
+Node: Glossary1095479
+Node: Copying1120790
+Node: GNU Free Documentation License1158347
+Node: Index1183484
+=======
Node: Foreword30282
Node: Preface34627
Ref: Preface-Footnote-137680
@@ -27911,5 +32700,6 @@ Node: Glossary916444
Node: Copying941619
Node: GNU Free Documentation License979176
Node: Index1004313
+>>>>>>> gawk-4.0-stable

End Tag Table