" unless (@ARGV == 1);
my @filenames = glob($ARGV[0]);
foreach my $filename (@filenames) {
open(IN, "$filename") || die ($!);
open(OUT, ">$filename.out.html") || die ($!);
my $keywords_color = "#0033FF";
my $important_words_color = "#FF6600";
my $single_line_comment_color = "#339999";
my $multi_line_comment_color = "#339966";
my $string_color = "#663366";
my $brace_color = "#FF0000";
my $number_color = "#3399FF";
my $floating_point_number_color = "#6699FF";
my $preprocessor_words_color = "#333333";
my $in_comment = 0;
my $in_string = 0;
my $line_number = 0;
my $debug = 0;
my $warnings = 1;
my @tokens = ();
print OUT "\n\n\t$filename\n\n";
while () {
$line_number++;
if ($warnings) {
if (length($_) > 80) {
print "Warning, line ", $line_number, " ", $filename,
" maybe too long (", length($_), " characters) to print:\n", $_;
}
}
@tokens = ();
chomp;
my $comment = "";
my $matches = 0;
do {
$matches = 0;
if (!$in_comment) {
if (m@(\s)*/\*@) {
print OUT "$&$'";
$_ = $`;
$in_comment = 1;
$matches++;
}
elsif (m@//@) {
$_ = $`;
$comment = "$&$'";
$matches++;
}
}
if (!$in_comment && !$in_string) {
if (m/\"/) {
push(@tokens, "$`", "", "$&");
$_ = $';
$in_string = 1;
$matches++;
}
}
if ($in_comment) {
if (m@(\s)*\*/@) {
$_ = $';
$in_comment = 0;
print OUT "$&$`";
$matches++;
}
}
if (!$in_comment && $in_string) {
if (m/\"/) {
$_ = $';
$in_string = 0;
push(@tokens, "$`$&", "");
$matches++;
}
}
} while ($matches > 0);
if (!$in_comment) {
foreach my $token (@tokens) {
if (m/^"/ || m/"$/) { # if token is start or end of string
# numbers here need whitespace before them, otherwise it messes with html tags
#$token =~ s/(\s)(\d+)(\.)(\d+)(\s|\b)/$1$2$3$4$5<\/font>/g;
#$token =~ s/(\s)(\d+)(\s|\b)/$1$2$3<\/font>/g;
foreach my $word (@keywords) {
$token =~ s/(\b)$word(\b)/$1$word$2<\/font>/g;
}
foreach my $word (@important_words) {
$token =~ s/(\b)$word(\b)/$1$word$2<\/font>/g;
}
$token =~ s/\(/\(<\/font>/g;
$token =~ s/\[/\[<\/font>/g;
$token =~ s/\{/\{<\/font>/g;
$token =~ s/\)/\)<\/font>/g;
$token =~ s/\]/\]<\/font>/g;
$token =~ s/\}/\}<\/font>/g;
}
print OUT $token;
}
foreach my $word (@keywords) {
s/(\b)$word(\b)/$1$word$2<\/font>/g;
}
foreach my $word (@common_important_words) {
s/^$word$/$word<\/font>/;
}
if (0) { # slow
foreach my $word (@important_words) {
s/(\b)$word(\b)/$1$word$2<\/font>/g;
}
}
s/(\s|-|\+)(\d+)(\.)(\d+)(\s|\b)/$1$2$3$4$5<\/font>/g;
s/(\s|-|\+)(\d+)(\s|\b)/$1$2$3<\/font>/g;
s/\(/\(<\/font>/g;
s/\[/\[<\/font>/g;
s/\{/\{<\/font>/g;
s/\)/\)<\/font>/g;
s/\]/\]<\/font>/g;
s/\}/\}<\/font>/g;
}
print OUT $_, $comment, "\n" || die($!);
}
print OUT "
\n\n