Compiler/Simple file inclusion pre processor: Difference between revisions
Content added Content deleted
(→{{header|AWK}}: Notes) |
m (→{{header|AWK}}: Slight simplkfication and reduce unnecessary whitespace) |
||
Line 476: | Line 476: | ||
# the command line can specify: |
# the command line can specify: |
||
# -v srcName=<source file path> |
# -v srcName=<source file path> |
||
BEGIN { |
BEGIN { |
||
FALSE = 0; |
|||
TRUE = 1; |
|||
srcName = srcName ""; |
srcName = srcName ""; |
||
} # BEGIN |
} # BEGIN |
||
{ |
{ |
||
if( $1 == "@include" ) |
if( $1 == "@include" ) |
||
{ |
{ |
||
Line 499: | Line 490: | ||
{ |
{ |
||
# normal line |
# normal line |
||
printf( "%s\n", |
printf( "%s\n", $0 ); |
||
} |
|||
$0 ); |
|||
} # if various lines;; |
|||
} |
} |
||
function includeFile( includeLine, fileName, |
function includeFile( includeLine, fileName, |
||
Line 512: | Line 498: | ||
line ) |
line ) |
||
{ |
{ |
||
# get the file name from the @include line |
# get the file name from the @include line |
||
fileName = includeLine; |
fileName = includeLine; |
||
Line 518: | Line 503: | ||
sub( / *$/, "", fileName ); |
sub( / *$/, "", fileName ); |
||
sub( / *#.*$/, "", fileName ); |
sub( / *#.*$/, "", fileName ); |
||
if( fileName ~ /^"/ ) |
if( fileName ~ /^"/ ) |
||
{ |
{ |
||
Line 525: | Line 509: | ||
sub( /"$/, "", fileName ); |
sub( /"$/, "", fileName ); |
||
gsub( /""/, "\"", fileName ); |
gsub( /""/, "\"", fileName ); |
||
} |
|||
printf( "#line 1 %s\n", fileName ); |
|||
⚫ | |||
printf( "#line 1 %s\n", |
|||
fileName ); |
|||
ioStat = ( getline line < fileName ); |
|||
while( ioStat > 0 ) |
|||
{ |
{ |
||
# have a source line |
# have a source line |
||
printf( "%s\n", |
printf( "%s\n", line ); |
||
} |
|||
line ); |
|||
⚫ | |||
} # while ioStat > 0 |
|||
if( ioStat < 0 ) |
if( ioStat < 0 ) |
||
{ |
{ |
||
# I/O error |
# I/O error |
||
printf( "@include %s # not found or I/O error\n", |
printf( "@include %s # not found or I/O error\n", fileName ); |
||
} |
|||
fileName ); |
|||
} # if ioStat < 0 |
|||
close( fileName ); |
close( fileName ); |
||
⚫ | |||
printf( "#line %d %s\n", |
|||
NR, |
|||
⚫ | |||
} # includeFile</lang> |
} # includeFile</lang> |