Compiler/Simple file inclusion pre processor: Difference between revisions
Compiler/Simple file inclusion pre processor (view source)
Revision as of 14:38, 25 July 2021
, 2 years ago→{{header|AWK}}: Slight simplkfication and reduce unnecessary whitespace
(→{{header|AWK}}: Notes) |
m (→{{header|AWK}}: Slight simplkfication and reduce unnecessary whitespace) |
||
Line 476:
# the command line can specify:
# -v srcName=<source file path>
BEGIN {
srcName = srcName "";
} # BEGIN
{
if( $1 == "@include" )
{
Line 499 ⟶ 490:
{
# normal line
printf( "%s\n", $0 );
}
}
function includeFile( includeLine, fileName,
Line 512 ⟶ 498:
line )
{
# get the file name from the @include line
fileName = includeLine;
Line 518 ⟶ 503:
sub( / *$/, "", fileName );
sub( / *#.*$/, "", fileName );
if( fileName ~ /^"/ )
{
Line 525 ⟶ 509:
sub( /"$/, "", fileName );
gsub( /""/, "\"", fileName );
}
{
# have a source line
printf( "%s\n", line );
}
▲ ioStat = ( getline line < fileName );
if( ioStat < 0 )
{
# I/O error
printf( "@include %s # not found or I/O error\n", fileName );
}
close( fileName );
▲ ( srcName != "" ? srcName : FILENAME ) );
} # includeFile</lang>
|