eval "exec perl -S $0 $*"
     if $running_under_some_random_shell;
#
# reads CPP output and turns #line things into appropriate Haskell
# pragmas
#

$Cpp = 'gcc -E -xc -traditional';

open(INPIPE, "$Cpp @ARGV |") || die "Can't open C pre-processor pipe\n";

while (<INPIPE>) {

# line directives come in flavo[u]rs:
#   s/^#\s*line\s+\d+$/\{\-# LINE \-\}/;   IGNORE THIS ONE FOR NOW
    s/^#\s*line\s+(\d+)\s+(\".+\")$/\{\-# LINE \1 \2 \-\}/;
    s/^#\s*(\d+)\s+(\".*\").*/\{\-# LINE \1 \2 \-\}/;

    print $_;
}

close(INPIPE) || exit(1); # exit is so we reflect any errors.

exit(0);


    
