Compiler/Simple file inclusion pre processor: Difference between revisions

→‎{{header|AWK}}: Use @include, as in GAWK
(Added AWK)
(→‎{{header|AWK}}: Use @include, as in GAWK)
Line 469:
=={{header|AWK}}==
AWK does not have file-inclusion as standard, however some implementations, particularly GNU Awk do provide file inclusion.
<br>This include pre-processor differs from GAWK syntax in that the include directive is ".include", not "@include" and ".include" can appear inside or outside functions. The file name can be quoted or not. Nested includes are not supported.
<br>The source can be a named file or read from stdin. If it is read from stdin, <code>-v sec=sourceName</code> can be specified on the AWK command line to name the file. The pre-processed source is writen to stdout.
<lang awk># include.awk: simple file inclusion pre-processor
Line 490:
{
 
if( $1 == ".@include" )
{
# must include a file
Line 512:
{
 
# get the file name from the .@include line
fileName = includeLine;
sub( /^ *.@include */, "", fileName );
sub( / *$/, "", fileName );
sub( / *#.*$/, "", fileName );
Line 544:
{
# I/O error
printf( ".@include %s # not found or I/O error\n",
fileName );
 
3,048

edits