Compiler/Simple file inclusion pre processor: Difference between revisions

m
→‎{{header|AWK}}: Slight simplkfication and reduce unnecessary whitespace
m (→‎{{header|AWK}}: Slight simplkfication and reduce unnecessary whitespace)
Line 476:
# the command line can specify:
# -v srcName=<source file path>
 
 
BEGIN {
 
FALSE = 0;
TRUE = 1;
 
srcName = srcName "";
 
 
} # BEGIN
 
 
{
 
if( $1 == "@include" )
{
Line 499 ⟶ 490:
{
# normal line
printf( "%s\n", $0 );
}
$0 );
 
} # if various lines;;
 
}
 
 
 
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 );
}
 
}printf( "#line if1 fileName%s\n", ~ /^"/ fileName );
while( ( ioStat = ( getline line < fileName ); ) > 0 )
 
printf( "#line 1 %s\n",
fileName );
 
ioStat = ( getline line < fileName );
 
while( ioStat > 0 )
{
# have a source line
printf( "%s\n", line );
}
line );
ioStat = ( getline line < fileName );
 
} # while ioStat > 0
 
if( ioStat < 0 )
{
# I/O error
printf( "@include %s # not found or I/O error\n", fileName );
}
fileName );
 
} # if ioStat < 0
 
close( fileName );
printf( "#line %d %s\n", NR, ( srcName != "" ? srcName : FILENAME ) );
 
printf( "#line %d %s\n",
NR,
( srcName != "" ? srcName : FILENAME ) );
 
 
} # includeFile</lang>
3,038

edits