1
0
mirror of https://github.com/cc65/cc65.git synced 2025-03-04 00:30:35 +00:00
git-svn-id: svn://svn.cc65.org/cc65/trunk@2522 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2003-10-13 11:17:31 +00:00
parent 1bdcc16827
commit d041d01cc2

View File

@ -87,7 +87,7 @@ my $LineLabels = 0; # Add a HTML label to each line
my $LineNumbers = 0; # Add line numbers to the output my $LineNumbers = 0; # Add line numbers to the output
my $LinkStyle = 0; # Default link style my $LinkStyle = 0; # Default link style
my $ReplaceExt = 0; # Replace extension instead of appending my $ReplaceExt = 0; # Replace extension instead of appending
my $StringColor = "#666666"; # Color for strings my $StringColor = "#6169C1"; # Color for strings
my $TextColor = "#000000"; # Text color my $TextColor = "#000000"; # Text color
my $Verbose = 0; # Be quiet my $Verbose = 0; # Be quiet
@ -180,8 +180,12 @@ sub StripPath {
sub DocHeader { sub DocHeader {
my $OUT = shift (@_); my $OUT = shift (@_);
my $Asm = shift (@_); my $Asm = shift (@_);
if (not $Colorize) {
# Colorization generates invalid HTML. Common browsers display it
# correctly, but we don't claim it adheres to some standard ...
print $OUT "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";
}
print $OUT <<"EOF"; print $OUT <<"EOF";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@ -191,8 +195,7 @@ sub DocHeader {
<body bgcolor="$BGColor" text="$TextColor" link="#0000d0" vlink="#000060" alink="#00d0d0"> <body bgcolor="$BGColor" text="$TextColor" link="#0000d0" vlink="#000060" alink="#00d0d0">
<p><br><p> <p><br><p>
<center><h1>$Asm</h1></center> <center><h1>$Asm</h1></center>
<hr><p><br><p> <hr size="1" noshade><p><br><p>
<pre>
EOF EOF
} }
@ -204,18 +207,18 @@ sub DocFooter {
# Get the current date and time # Get the current date and time
my $Today = localtime; my $Today = localtime;
print $OUT <<"EOF"; # Print
</pre> print $OUT "<p><br><p>\n";
<p><br><p> print $OUT "<hr size=\"1\" noshade>\n";
<hr size=1 noshade> print $OUT "<address>\n";
<address> if (not $Colorize) {
<a href="http://validator.w3.org/check/referer"><img border="0" src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88" align=right></a> print $OUT "<a href=\"http://validator.w3.org/check/referer\"><img border=\"0\" src=\"http://www.w3.org/Icons/valid-html401\" alt=\"Valid HTML 4.01!\" height=\"31\" width=\"88\" align=\"right\"></a>\n";
$Name; generated on $Today by ca65html<br> }
<a href=\"mailto:uz\@cc65.org\">uz\@cc65.org</a> print $OUT "$Name; generated on $Today by ca65html<br>\n";
</address> print $OUT "<a href=\"mailto:uz&#64;cc65.org\">uz&#64;cc65.org</a>\n";
</body> print $OUT "</address>\n";
</html> print $OUT "</body>\n";
EOF print $OUT "</html>\n";
} }
@ -470,6 +473,7 @@ sub Process2 {
my $Label; my $Label;
my $Operand; my $Operand;
my $Comment; my $Comment;
my $Trailer;
# Input file is parameter # Input file is parameter
my $InName = shift(@_); my $InName = shift(@_);
@ -487,6 +491,7 @@ sub Process2 {
# Open the output file and print the HTML header # Open the output file and print the HTML header
open (OUTPUT, ">$HTMLDir$OutName") or Abort ("Cannot open $OutName: $!"); open (OUTPUT, ">$HTMLDir$OutName") or Abort ("Cannot open $OutName: $!");
DocHeader (OUTPUT, $InName); DocHeader (OUTPUT, $InName);
print OUTPUT "<pre>\n";
# Keep the user happy # Keep the user happy
Gabble ("$FileName => $OutName"); Gabble ("$FileName => $OutName");
@ -537,8 +542,46 @@ sub Process2 {
$OutLine .= sprintf ("%6d: ", $LineNo); $OutLine .= sprintf ("%6d: ", $LineNo);
} }
# Check for a label. If we have one, process it and remove it # Cut off a comment from the input line. Beware: We have to check for
# from the line # strings, since these may contain a semicolon that is no comment
# start. A perl guru would probably write all this in one line...
my $L = $Line;
$Line = "";
$Comment = "";
while ($L ne "") {
if ($L =~ /^([^\"\';]+)(.*)$/) {
$Line .= $1;
$L = $2;
}
if ($L =~ /^;/) {
# The remainder is a comment
$Comment = $L;
last;
} elsif ($L =~ /^(\"[^\"]*\")(.*)$/) {
$Line .= $1;
$L = $2;
} elsif ($L =~ /^(\'[^\']*\')(.*)$/) {
$Line .= $1;
$L = $2;
} elsif ($L =~ /^[\"\']/) {
# Line with invalid syntax - there's a string start but
# no string end.
Abort (sprintf ("Invalid input at %s(%d)", $FileName, $LineNo));
}
}
# Remove trailing whitespace and move it together with the comment
# into the $Trailer variable.
if ($Line =~ /^(.*?)(\s*)$/) {
$Line = $1;
$Trailer = $2;
} else {
$Trailer = "";
}
$Trailer .= ColorizeComment (Cleanup ($Comment));
# Check for a label at the start of the line. If we have one, process
# it and remove it from the line
if ($Line =~ /^\s*?(\@?)([_a-zA-Z][_\w]*)(\s*)(:|=)(.*)$/) { if ($Line =~ /^\s*?(\@?)([_a-zA-Z][_\w]*)(\s*)(:|=)(.*)$/) {
# Is this a local label? # Is this a local label?
@ -573,7 +616,7 @@ sub Process2 {
if ($Line =~ /^(\.import|\.importzp)(\s+)(.*)$/) { if ($Line =~ /^(\.import|\.importzp)(\s+)(.*)$/) {
# Print any fixed stuff from the line and remove it # Print any fixed stuff from the line and remove it
$OutLine .= ColorizeCtrl ($1) . $2; $OutLine .= $1 . $2;
$Line = $3; $Line = $3;
# Print all identifiers if there are any # Print all identifiers if there are any
@ -622,7 +665,7 @@ sub Process2 {
} elsif ($Line =~ /^(\.export|\.exportzp)(\s+)(.*)$/) { } elsif ($Line =~ /^(\.export|\.exportzp)(\s+)(.*)$/) {
# Print the command the and white space # Print the command the and white space
$OutLine .= ColorizeCtrl ($1) . $2; $OutLine .= $1 . $2;
$Line = $3; $Line = $3;
# Print all identifiers if there are any # Print all identifiers if there are any
@ -674,7 +717,7 @@ sub Process2 {
} elsif ($Line =~ /^(\.addr|\.word)(\s+)(.*)$/) { } elsif ($Line =~ /^(\.addr|\.word)(\s+)(.*)$/) {
# Print the command the and white space # Print the command the and white space
$OutLine .= ColorizeCtrl ($1) . $2; $OutLine .= "$1$2";
$Line = $3; $Line = $3;
# Print all identifiers if there are any # Print all identifiers if there are any
@ -706,32 +749,29 @@ sub Process2 {
$Label = $Labels{$OutName}{$3}; $Label = $Labels{$OutName}{$3};
# Print the label with a tag # Print the label with a tag
$OutLine .= sprintf ("%s%s<a name=\"%s\">%s</a>%s", $OutLine .= "$1$2<a name=\"$Label\">$3</a>";
ColorizeCtrl ($1), $2, $Label, $3, Cleanup ($4));
} else { } else {
# Print the label # Print the label
$OutLine .= ColorizeCtrl ($1) . $2 . $3 . Cleanup ($4); $OutLine .= "$1$2$3";
} }
# Add the remainder
$OutLine .= Cleanup ($4);
# Handle .include # Handle .include
} elsif ($Line =~ /^(\.include)(\s+)\"((?:[^\"]+?|\\\")+)\"(\s*)(;.*$|$)/) { } elsif ($Line =~ /^(\.include)(\s+)\"((?:[^\"]+?|\\\")+)(\".*)$/) {
# Add the fixed stuff to the output line # Add the fixed stuff to the output line
$OutLine .= ColorizeCtrl ($1) . $2 . "\""; $OutLine .= "$1$2&quot;";
# Get the filename into a named variable # Get the filename into a named variable
my $FileName = $3; my $FileName = Cleanup ($3);
# Remember the remainder
$Line = "\"$4$5";
# Get the name without a path # Get the name without a path
my $Name = StripPath ($FileName); my $Name = StripPath ($3);
# We don't need FileName any longer as is, so clean it up
$FileName = Cleanup ($FileName);
# If the include file is among the list of our files, add a link, # If the include file is among the list of our files, add a link,
# otherwise just add the name as is. # otherwise just add the name as is.
@ -742,38 +782,38 @@ sub Process2 {
} }
# Add the remainder # Add the remainder
$OutLine .= Cleanup ($Line); $OutLine .= Cleanup ($4);
# Handle .dbg line # Handle .dbg line
} elsif ($CRefs && $Line =~ /^(\.dbg)(\s+)(.*)$/) { } elsif ($CRefs && $Line =~ /^(\.dbg)(\s+)(.*)$/) {
# Add the fixed stuff to the output line # Add the fixed stuff to the output line
$OutLine .= ColorizeCtrl ($1) . $2; $OutLine .= "$1$2";
# Remember the remainder # Remember the remainder
$Line = $3; $Line = $3;
# Check for the type of the .dbg directive # Check for the type of the .dbg directive
if ($Line =~ /^(line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*$)/) { if ($Line =~ /^(line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*)$/) {
# Add the fixed stuff to the output line # Add the fixed stuff to the output line
$OutLine .= $1 . "\""; $OutLine .= "$1&quot;";
# Get the filename and line number into named variables # Get the filename and line number into named variables
my $FileName = $2; my $DbgFile = $2;
my $LineNo = $4; my $DbgLine = $4;
# Remember the remainder # Remember the remainder
$Line = "\"$3$4$5"; $Line = "\"$3$4$5";
# Get the name without a path # Get the name without a path
my $Name = StripPath ($FileName); my $Name = StripPath ($DbgFile);
# We don't need FileName any longer as is, so clean it up # We don't need FileName any longer as is, so clean it up
$FileName = Cleanup ($FileName); $DbgFile = Cleanup ($DbgFile);
# Add a link to the source file # Add a link to the source file
$OutLine .= sprintf ("<a href=\"%s.html#line%d\">%s</a>", $Name, $LineNo, $FileName); $OutLine .= sprintf ("<a href=\"%s.html#line%d\">%s</a>", $Name, $DbgLine, $DbgFile);
# Add the remainder # Add the remainder
$OutLine .= Cleanup ($Line); $OutLine .= Cleanup ($Line);
@ -781,14 +821,14 @@ sub Process2 {
} elsif ($Line =~ /^(file,\s*)\"((?:[^\"]+?|\\\")+)\"(.*)$/) { } elsif ($Line =~ /^(file,\s*)\"((?:[^\"]+?|\\\")+)\"(.*)$/) {
# Get the filename into a named variables # Get the filename into a named variables
my $FileName = Cleanup ($2); my $DbgFile = Cleanup ($2);
# Get the name without a path # Get the name without a path
my $Name = Cleanup (StripPath ($2)); my $Name = Cleanup (StripPath ($2));
# Add the fixed stuff to the output line # Add the fixed stuff to the output line
$OutLine .= sprintf ("%s\"<a href=\"%s.html\">%s</a>\"%s", $OutLine .= sprintf ("%s\"<a href=\"%s.html\">%s</a>\"%s",
$1, $Name, $FileName, $3); $1, $Name, $DbgFile, $3);
} else { } else {
@ -800,7 +840,7 @@ sub Process2 {
} elsif ($CRefs && $Line =~ /^(\.dbg)(\s+line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*$)/) { } elsif ($CRefs && $Line =~ /^(\.dbg)(\s+line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*$)/) {
# Add the fixed stuff to the output line # Add the fixed stuff to the output line
$OutLine .= ColorizeCtrl ($1) . $2 . "\""; $OutLine .= "$1$2&quot;";
# Get the filename and line number into named variables # Get the filename and line number into named variables
my $FileName = $3; my $FileName = $3;
@ -822,14 +862,13 @@ sub Process2 {
$OutLine .= Cleanup ($Line); $OutLine .= Cleanup ($Line);
# Check for instructions with labels # Check for instructions with labels
} elsif ($Line =~ /^($LabelIns)(\s+)(.*?)(\s*)(;.*$|$)/) { } elsif ($Line =~ /^($LabelIns)(\s+)(.*)$/) {
# Print the instruction and white space # Print the instruction and white space
$OutLine .= ColorizeKeyword ($1) . $2; $OutLine .= ColorizeKeyword ($1) . $2;
# Remember the remaining parts # Remember the remaining parts
$Operand = $3; $Operand = $3;
$Comment = Cleanup ("$4$5");
# Check for the first identifier in the operand and replace it # Check for the first identifier in the operand and replace it
# by a hyperlink # by a hyperlink
@ -849,26 +888,13 @@ sub Process2 {
} }
# Reassemble and print the line # Reassemble and print the line
$OutLine .= $Operand . ColorizeComment ($Comment); $OutLine .= $Operand;
# Check for all other instructions # Check for all other instructions
} elsif ($Line =~ /^($AllIns)(\s+.*?\s*|\s*)(;.*$|$)/) { } elsif ($Line =~ /^($AllIns)(.*)$/) {
# Colorize and print # Colorize and print
$OutLine .= ColorizeKeyword ($1) . Cleanup ($2) . ColorizeComment (Cleanup ($3)); $OutLine .= ColorizeKeyword ($1) . Cleanup ($2);
# Check for a comment line
} elsif ($Line =~ /^(\s*)(;.*)$/) {
# Colorize and print
$OutLine .= $1 . ColorizeComment (Cleanup ($2));
# Check for a keyword
} elsif ($Line =~ /^(\s*)(\.[_a-zA-Z][_\w]*)(.*?)(;.*$|$)/) {
# Colorize and print
$OutLine .= $1 . ColorizeCtrl ($2) . Cleanup ($3) .
ColorizeComment (Cleanup ($4));
} else { } else {
@ -877,11 +903,18 @@ sub Process2 {
} }
# Colorize all keywords
$OutLine =~ s/(?<![\w;])\.[_a-zA-Z][_\w]*/ColorizeCtrl ($&)/ge;
# Add the trailer
$OutLine .= $Trailer;
# Print the result # Print the result
print OUTPUT "$OutLine\n"; print OUTPUT "$OutLine\n";
} }
# Print the HTML footer # Print the HTML footer
print OUTPUT "</pre>\n";
DocFooter (OUTPUT, $OutName); DocFooter (OUTPUT, $OutName);
# Close the files # Close the files
@ -989,19 +1022,7 @@ sub CreateIndex {
open (INDEX, ">$HTMLDir$IndexName") or Abort ("Cannot open $IndexName: $!"); open (INDEX, ">$HTMLDir$IndexName") or Abort ("Cannot open $IndexName: $!");
# Print the header # Print the header
print INDEX <<"EOF"; DocHeader (INDEX, $IndexTitle, 0);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content=\"text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="ca65html">
<title>$IndexTitle</title>
</head>
<body bgcolor="$BGColor" text="$TextColor" link="#0000d0" vlink="#000060" alink="#00d0d0">
<p><br><p>
<center><h1>$IndexTitle</h1></center>
<hr><p><br><p>
EOF
# Print the file list in a table # Print the file list in a table
FileIndex (INDEX); FileIndex (INDEX);
@ -1025,9 +1046,11 @@ EOF
sub Usage { sub Usage {
print "Usage: ca65html [options] file ...\n"; print "Usage: ca65html [options] file ...\n";
print "Options:\n"; print "Options:\n";
print " --bgcolor color Use background color c instead of $BGColor\n"; print " --bgcolor c Use background color c instead of $BGColor\n";
print " --colorize Colorize the output\n"; print " --colorize Colorize the output (generates non standard HTML)\n";
print " --commentcolor c Use color c for comments instead of $CommentColor\n";
print " --crefs Generate references to the C source file(s)\n"; print " --crefs Generate references to the C source file(s)\n";
print " --ctrlcolor c Use color c for directives instead of $CtrlColor\n";
print " --cvttabs Convert tabs to spaces in the output\n"; print " --cvttabs Convert tabs to spaces in the output\n";
print " --help This text\n"; print " --help This text\n";
print " --htmldir dir Specify directory for HTML files\n"; print " --htmldir dir Specify directory for HTML files\n";
@ -1035,10 +1058,11 @@ sub Usage {
print " --indexname file Use file for the index file instead of $IndexName\n"; print " --indexname file Use file for the index file instead of $IndexName\n";
print " --indexpage Create an index page\n"; print " --indexpage Create an index page\n";
print " --indextitle title Use title as the index title instead of $IndexTitle\n"; print " --indextitle title Use title as the index title instead of $IndexTitle\n";
print " --keywordcolor c Use color c for keywords instead of $KeywordColor\n";
print " --linenumbers Add line numbers to the output\n"; print " --linenumbers Add line numbers to the output\n";
print " --linkstyle style Use the given link style\n"; print " --linkstyle style Use the given link style\n";
print " --replaceext Replace source extension instead of appending .html\n"; print " --replaceext Replace source extension instead of appending .html\n";
print " --textcolor color Use text color c instead of $TextColor\n"; print " --textcolor c Use text color c instead of $TextColor\n";
print " --verbose Be more verbose\n"; print " --verbose Be more verbose\n";
} }
@ -1053,7 +1077,9 @@ sub Usage {
# Get program options # Get program options
GetOptions ("bgcolor=s" => \$BGColor, GetOptions ("bgcolor=s" => \$BGColor,
"colorize" => \$Colorize, "colorize" => \$Colorize,
"commentcolor=s" => \$CommentColor,
"crefs" => \$CRefs, "crefs" => \$CRefs,
"ctrlcolor=s" => \$CtrlColor,
"cvttabs" => \$CvtTabs, "cvttabs" => \$CvtTabs,
"debug!" => \$Debug, "debug!" => \$Debug,
"help" => \$Help, "help" => \$Help,
@ -1062,6 +1088,7 @@ GetOptions ("bgcolor=s" => \$BGColor,
"indexname=s" => \$IndexName, "indexname=s" => \$IndexName,
"indexpage" => \$IndexPage, "indexpage" => \$IndexPage,
"indextitle=s" => \$IndexTitle, "indextitle=s" => \$IndexTitle,
"keywordcolor=s" => \$KeywordColor,
"linelabels" => \$LineLabels, "linelabels" => \$LineLabels,
"linenumbers" => \$LineNumbers, "linenumbers" => \$LineNumbers,
"linkstyle=i" => \$LinkStyle, "linkstyle=i" => \$LinkStyle,