73 lines
2.0 KiB
Plaintext
73 lines
2.0 KiB
Plaintext
/** @page awk AWK
|
|
|
|
AWK Interpreter
|
|
|
|
@section awk_ext EXTENSION
|
|
Some language extensions are implemented and they can be enabled by setting the
|
|
corresponding options.
|
|
|
|
@subsection awk_ext_vardecl VARIABLE DECLARATION
|
|
|
|
#QSE_AWK_EXPLICIT enables variable declaration. Variables declared are accessed
|
|
directly bypassing the global named map that stores undeclared variables.
|
|
The keyword @b global introduces a global variable and the keyword @b local
|
|
introduces local variable. Local variable declaraion in a block must be
|
|
located before an expression or a statement appears.
|
|
|
|
@code
|
|
global g1, g2; #declares two global variables g1 and g2
|
|
|
|
BEGIN {
|
|
local a1, a2, a3; # declares three local variables
|
|
|
|
g1 = 300; a1 = 200;
|
|
|
|
{
|
|
local a1; # a1 here hides the a1 at the outer scope
|
|
local g1; # g1 here hides the global g1
|
|
a1 = 10; g1 = 5;
|
|
print a1, g1; # it prints 10 and 5
|
|
}
|
|
|
|
print a1, g1; # it prints 200 and 300
|
|
}
|
|
|
|
@endcode
|
|
|
|
However, turning on #QSE_AWK_EXPLICIT does not disable named variables.
|
|
To disable named variables, you must turn off #QSE_AWK_IMPLICIT.
|
|
|
|
@subsection awk_ext_include INCLUDE
|
|
|
|
The \@include directive inserts the contents of the object specified in the
|
|
following string, typically a file name, as if they appeared in the source
|
|
stream being processed. The directive can only be used at the outmost scope
|
|
where global variable declarations, @b BEGIN, @b END, and/or pattern-action
|
|
blocks appear. To use \@include, you must turn on #QSE_AWK_INCLUDE.
|
|
|
|
@code
|
|
@include "abc.awk"
|
|
BEGIN { func_in_abc (); }
|
|
@endcode
|
|
|
|
@subsection awk_ext_rwpipe TWO-WAY PIPE
|
|
|
|
The two-way pipe indicated by @b || is supproted, in addition to the one-way
|
|
pipe indicated by @b |. Turn on #QSE_AWK_RWPIPE to enable the two-way pipe.
|
|
|
|
@code
|
|
BEGIN {
|
|
print "15" || "sort";
|
|
print "14" || "sort";
|
|
print "13" || "sort";
|
|
print "12" || "sort";
|
|
print "11" || "sort";
|
|
#close the input as sort emits when the input is closed
|
|
close ("sort", "r");
|
|
while (("sort" || getline x) > 0) print "xx:", x;
|
|
}
|
|
@endcode
|
|
|
|
*/
|
|
|