#!/usr/bin/perl
print <<HTML;
<html><head>
<style type="text/css">
div {
border: 1px solid black;
margin: 2 0 2 15;
padding: 2px;
font-family: sans-serif, fixed, monospace;
font-size: 12px;
}
</style>
<title>GCC/MSCL Include Depths Map</title>
</head><body><div>
HTML
@istack = ();
$GNU = 0;
$stylecheck = 0;
$leftout = 0;
while(<STDIN>)
{
$line = $_;
chomp($line);chomp($line);
$line =~ s/\r//g;
$line =~ s/\</\<\;/g;
$line =~ s/\>/\>\;/g;
if (!$stylecheck)
{
if($line =~ /\#line/)
{
$GNU = 0;
$stylecheck = 1;
}
elsif($line =~ /\#\s/)
{
$GNU = 1;
$stylecheck = 1;
}
else
{
die("UNABLE TO DETECT COMPILER FLAVOR!\n");
}
}
if ($GNU)
{
while(<STDIN>)
{
$line = $_;
chomp($line);chomp($line);
$line =~ s/\</\<\;/g;
$line =~ s/\>/\>\;/g;
$line =~ s/\r//g;
if($line =~ /\# \d+ "[^"]+\s?(.+)/)
{
$flags = $1;
if($flags =~ /1/)
{
print "<div><b>$line</b><br>\n";
}
if($flags =~ /2/)
{
print "<em>$line</em></div>\n";
}
}
else
{
if(length($line)>=1)
{
print $line;
print "<br>\n";
}
}
}
}
else
{
if($line =~ /^\s*\#line (\d+) "([^"]+)/)
{
$lineno = $1;
$include = $2;
if ($lineno == 1)
{
$leftout = 0;
push(@istack,$include);
print "<div><b>$line</b><br>\n";
}
elsif ($istack[$#istack] eq $include)
{
if(!$leftout)
{
$leftout = 1;
print "<strong>[...]</strong><br>";
}
}
elsif ($istack[$#istack-1] eq $include)
{
$leftout = 0;
$pinclude = pop(@istack);
print "<em>$pinclude</em></div>$line<br>\n";
}
else
{
die("unexpected #line directive, something went wrong:\n$line\n");
}
}
else
{
$line =~ s/^\s+//;
if(length($line)>=1)
{
$leftout = 0;
print $line;
print "<br>";
}
}
}
}
print <<HTML;
</div></body>
</html>
HTML