Compiler/Simple file inclusion pre processor: Difference between revisions
Content added Content deleted
(Added AWK) |
(→{{header|AWK}}: Use @include, as in GAWK) |
||
Line 469: | Line 469: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
AWK does not have file-inclusion as standard, however some implementations, particularly GNU Awk do provide file inclusion. |
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 |
<br>This include pre-processor differs from GAWK syntax in that the include directive 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. |
<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 |
<lang awk># include.awk: simple file inclusion pre-processor |
||
Line 490: | Line 490: | ||
{ |
{ |
||
if( $1 == " |
if( $1 == "@include" ) |
||
{ |
{ |
||
# must include a file |
# must include a file |
||
Line 512: | Line 512: | ||
{ |
{ |
||
# get the file name from the |
# get the file name from the @include line |
||
fileName = includeLine; |
fileName = includeLine; |
||
sub( /^ * |
sub( /^ *@include */, "", fileName ); |
||
sub( / *$/, "", fileName ); |
sub( / *$/, "", fileName ); |
||
sub( / *#.*$/, "", fileName ); |
sub( / *#.*$/, "", fileName ); |
||
Line 544: | Line 544: | ||
{ |
{ |
||
# I/O error |
# I/O error |
||
printf( " |
printf( "@include %s # not found or I/O error\n", |
||
fileName ); |
fileName ); |
||