mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
Add several improvements, among others: Options, index page, link style...
git-svn-id: svn://svn.cc65.org/cc65/trunk@560 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
35e22de2c2
commit
a07a8f5328
@ -34,16 +34,40 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
use strict 'vars';
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
# Modules
|
||||||
|
use Getopt::Long;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------#
|
#-----------------------------------------------------------------------------#
|
||||||
# Variables #
|
# Variables #
|
||||||
# ----------------------------------------------------------------------------#
|
# ----------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%Files = (); # List of all files.
|
# Global variables
|
||||||
%Exports = (); # List of exported symbol. Value is html tag.
|
my %Files = (); # List of all files.
|
||||||
%Labels = (); # List of all labels
|
my $FileCount = 0; # Number of input files
|
||||||
$LabelNum = 0; # Counter to generate unique labels
|
my %Exports = (); # List of exported symbols.
|
||||||
|
my %Imports = (); # List of imported symbols.
|
||||||
|
my %Labels = (); # List of all labels
|
||||||
|
my $LabelNum = 0; # Counter to generate unique labels
|
||||||
|
|
||||||
|
# Command line options
|
||||||
|
my $BGColor = "#FFFFFF"; # Background color
|
||||||
|
my $Debug = 0; # No debugging
|
||||||
|
my $Help = 0; # Help flag
|
||||||
|
my $IndexCols = 6; # Columns in the file listing
|
||||||
|
my $IndexTitle = "Index"; # Title of index page
|
||||||
|
my $IndexName = "index.html"; # Name of index page
|
||||||
|
my $IndexPage = 0; # Create an index page
|
||||||
|
my $LinkStyle = 0; # Default link style
|
||||||
|
my $ReplaceExt = 0; # Replace extension instead of appending
|
||||||
|
my $TextColor = "#000000"; # Text color
|
||||||
|
my $Verbose = 0; # Be quiet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -55,10 +79,17 @@ $LabelNum = 0; # Counter to generate unique labels
|
|||||||
|
|
||||||
# Terminate with an error
|
# Terminate with an error
|
||||||
sub Abort {
|
sub Abort {
|
||||||
print "@_\n";
|
print STDERR "ca65html: @_\n";
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Print a message if verbose is true
|
||||||
|
sub Gabble {
|
||||||
|
if ($Verbose) {
|
||||||
|
print "ca65html: @_\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Generate a label and return it
|
# Generate a label and return it
|
||||||
sub GenLabel {
|
sub GenLabel {
|
||||||
# Generate the label
|
# Generate the label
|
||||||
@ -69,43 +100,61 @@ sub GenLabel {
|
|||||||
sub GetOutName {
|
sub GetOutName {
|
||||||
|
|
||||||
# Input name is parameter
|
# Input name is parameter
|
||||||
local $InName = @_[0];
|
my $InName = $_[0];
|
||||||
|
|
||||||
# Create the output file name from the input file name
|
# Create the output file name from the input file name
|
||||||
if ($InName =~ /^(.+)\.([^\.\/]*)$/) {
|
if ($ReplaceExt && $InName =~ /^(.+)\.([^\.\/]*)$/) {
|
||||||
return "$1.html";
|
return "$1.html";
|
||||||
} else {
|
} else {
|
||||||
return "$InName.html";
|
return "$InName.html";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Remove illegal characters from a string
|
||||||
|
sub Cleanup {
|
||||||
|
my $S = shift (@_);
|
||||||
|
$S =~ s/&/&/g;
|
||||||
|
$S =~ s/</</g;
|
||||||
|
$S =~ s/>/>/g;
|
||||||
|
$S =~ s/\"/"/g;
|
||||||
|
return $S;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------#
|
||||||
|
# Document header and footer #
|
||||||
|
# ----------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Print the document header
|
# Print the document header
|
||||||
sub DocHeader {
|
sub DocHeader {
|
||||||
local $OUT = shift (@_);
|
my $OUT = shift (@_);
|
||||||
local $Asm = shift (@_);
|
my $Asm = shift (@_);
|
||||||
print $OUT <<"EOF";
|
print $OUT <<"EOF";
|
||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html-40/loose.dtd">
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html-40/loose.dtd">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>SDSL Traffic</title>
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||||
|
<meta name="GENERATOR" content="ca65html">
|
||||||
|
<title>$Asm</title>
|
||||||
</head>
|
</head>
|
||||||
|
<body bgcolor="$BGColor" text="$TextColor" link="#0000d0" vlink="#000060" alink="#00d0d0">
|
||||||
<body bgcolor="#FFFFFF" text="#000000" 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><p><br><p>
|
||||||
<pre>
|
<pre>
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# Print the document footer
|
# Print the document footer
|
||||||
sub DocFooter {
|
sub DocFooter {
|
||||||
local $OUT = shift (@_);
|
my $OUT = shift (@_);
|
||||||
local $Name = shift (@_);
|
my $Name = shift (@_);
|
||||||
|
|
||||||
# Get the current date and time
|
# Get the current date and time
|
||||||
$Today = localtime;
|
my $Today = localtime;
|
||||||
|
|
||||||
print $OUT <<"EOF";
|
print $OUT <<"EOF";
|
||||||
</pre>
|
</pre>
|
||||||
@ -118,7 +167,6 @@ sub DocFooter {
|
|||||||
$Name; generated on $Today by ca65html<br>
|
$Name; generated on $Today by ca65html<br>
|
||||||
<a href=\"mailto:uz\@cc65.org\">uz\@cc65.org</a>
|
<a href=\"mailto:uz\@cc65.org\">uz\@cc65.org</a>
|
||||||
</address>
|
</address>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
EOF
|
EOF
|
||||||
@ -126,14 +174,87 @@ EOF
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Remove illegal characters from a string
|
#-----------------------------------------------------------------------------#
|
||||||
sub Cleanup {
|
# File list management #
|
||||||
local $S = shift (@_);
|
# ----------------------------------------------------------------------------#
|
||||||
$S =~ s/&/&/g;
|
|
||||||
$S =~ s/</</g;
|
|
||||||
$S =~ s/>/>/g;
|
|
||||||
$S =~ s/\"/"/g;
|
sub AddFile {
|
||||||
return $S;
|
|
||||||
|
# Argument is file to add
|
||||||
|
my $FileName = $_[0];
|
||||||
|
|
||||||
|
# Remove a path name if we have one
|
||||||
|
$FileName =~ /^(.*?)([^\/]*)$/;
|
||||||
|
my $Path = $1;
|
||||||
|
my $Name = $2;
|
||||||
|
|
||||||
|
# Check if we have the file already
|
||||||
|
if (exists ($Files{$Name})) {
|
||||||
|
Gabble ("File \"$FileName\" already known");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check with the full pathname. If we don't find it, search in the current
|
||||||
|
# directory
|
||||||
|
if (-f $FileName && -r $FileName) {
|
||||||
|
$Files{$Name} = $FileName;
|
||||||
|
$FileCount++;
|
||||||
|
} elsif (-f $Name && -r $Name) {
|
||||||
|
$Files{$Name} = $Name;
|
||||||
|
$FileCount++;
|
||||||
|
} else {
|
||||||
|
Abort ("$FileName not found or not readable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------#
|
||||||
|
# Referencing and defining labels #
|
||||||
|
# ----------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Get a label reference
|
||||||
|
sub RefLabel {
|
||||||
|
|
||||||
|
# Arguments are: Filename, identifier, item that should be tagged
|
||||||
|
my $FileName = $_[0];
|
||||||
|
my $Id = $_[1];
|
||||||
|
my $Item = $_[2];
|
||||||
|
|
||||||
|
# Search for the identifier in the list of labels
|
||||||
|
if (exists ($Labels{$FileName}{$Id})) {
|
||||||
|
# It is a label (in this file)
|
||||||
|
return sprintf ("<a href=\"#%s\">%s</a>", $Labels{$FileName}{$Id}, $Item);
|
||||||
|
} elsif (exists ($Imports{$FileName}{$Id})) {
|
||||||
|
# It is an import. If LinkStyle is 1, or if the file exporting the
|
||||||
|
# identifier is not visible, we link to the .import statement in the
|
||||||
|
# current file. Otherwise we link directly to the referenced symbol
|
||||||
|
# in the file that exports it.
|
||||||
|
if ($LinkStyle == 1 or not exists ($Exports{$Id})) {
|
||||||
|
return sprintf ("<a href=\"#%s\">%s</a>", $Imports{$FileName}{$Id}, $Item);
|
||||||
|
} else {
|
||||||
|
# Get the filename from the export
|
||||||
|
my $Label;
|
||||||
|
($FileName, $Label) = split (/#/, $Exports{$Id});
|
||||||
|
if (not defined ($Labels{$FileName}{$Id})) {
|
||||||
|
# This may currently happen because we don't see .include
|
||||||
|
# statements, so we may have an export but no definition.
|
||||||
|
# Link to the .export statement instead
|
||||||
|
$Label = $Exports{$Id};
|
||||||
|
} else {
|
||||||
|
# Link to the definition in the file
|
||||||
|
$Label = sprintf ("%s#%s", $FileName, $Labels{$FileName}{$Id});
|
||||||
|
}
|
||||||
|
return sprintf ("<a href=\"%s\">%s</a>", $Label, $Item);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
# The symbol is unknown, return as is
|
||||||
|
return $Item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -148,20 +269,21 @@ sub Cleanup {
|
|||||||
sub Process1 {
|
sub Process1 {
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
local $Line;
|
my $Line;
|
||||||
local $Id;
|
my $Id;
|
||||||
|
|
||||||
# Filename is parameter
|
# Filename is parameter
|
||||||
local $InName = shift(@_);
|
my $InName = shift(@_);
|
||||||
|
|
||||||
# Create the output file name from the input file name
|
# Create the output file name from the input file name
|
||||||
local $OutName = GetOutName ($InName);
|
my $OutName = GetOutName ($InName);
|
||||||
|
|
||||||
# Current cheap local label prefix is empty
|
# Current cheap local label prefix is empty
|
||||||
local $CheapPrefix = "";
|
my $CheapPrefix = "";
|
||||||
|
|
||||||
# Open a the input file
|
# Open a the input file
|
||||||
open (INPUT, "<$InName") or Abort ("Cannot open $InName");
|
my $FileName = $Files{$InName}; # Includes path if needed
|
||||||
|
open (INPUT, "<$FileName") or Abort ("Cannot open $FileName: $!");
|
||||||
|
|
||||||
# Read and process all lines from the file
|
# Read and process all lines from the file
|
||||||
while ($Line = <INPUT>) {
|
while ($Line = <INPUT>) {
|
||||||
@ -184,26 +306,35 @@ sub Process1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Remember the label
|
# Remember the label
|
||||||
$Labels{$InName}{$Id} = GenLabel();
|
$Labels{$OutName}{$Id} = GenLabel();
|
||||||
|
|
||||||
# Check for an import statement
|
# Check for an import statement
|
||||||
} elsif ($Line =~ /^\s*(\.import|\.importzp|.proc)\s+(.*?)(\s*)(;.*$|$)/) {
|
} elsif ($Line =~ /^\s*(\.import|\.importzp)\s+(.*?)(\s*)(;.*$|$)/) {
|
||||||
|
|
||||||
# Split into a list of identifiers
|
# Split into a list of identifiers
|
||||||
local @Ids = split (/\s*,\s*/, $2);
|
my @Ids = split (/\s*,\s*/, $2);
|
||||||
for my $Id (@Ids) {
|
for $Id (@Ids) {
|
||||||
$Labels{$InName}{$Id} = GenLabel();
|
$Imports{$OutName}{$Id} = GenLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for an export statement
|
# Check for an export statement
|
||||||
} elsif ($Line =~ /^\s*(\.export|\.exportzp)\s+(.*?)(\s*)(;.*$|$)/) {
|
} elsif ($Line =~ /^\s*(\.export|\.exportzp)\s+(.*?)(\s*)(;.*$|$)/) {
|
||||||
|
|
||||||
# Split into a list of identifiers
|
# Split into a list of identifiers
|
||||||
local @Ids = split (/\s*,\s*/, $2);
|
my @Ids = split (/\s*,\s*/, $2);
|
||||||
for my $Id (@Ids) {
|
for $Id (@Ids) {
|
||||||
$Exports{$Id} = sprintf ("%s#%s", $OutName, GenLabel());
|
$Exports{$Id} = sprintf ("%s#%s", $OutName, GenLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check for a .proc statement
|
||||||
|
} elsif ($Line =~ /^\s*\.proc\s+([_a-zA-Z][_\w]*)?.*$/) {
|
||||||
|
|
||||||
|
# Do we have an id?
|
||||||
|
$Id = $1;
|
||||||
|
if ($Id ne "") {
|
||||||
|
$Labels{$OutName}{$Id} = GenLabel();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,13 +345,10 @@ sub Process1 {
|
|||||||
|
|
||||||
|
|
||||||
# Pass1: Read all files for the first time.
|
# Pass1: Read all files for the first time.
|
||||||
sub Pass1 {
|
sub Pass1 () {
|
||||||
|
|
||||||
# List of new files we found
|
|
||||||
local @NewFiles = ();
|
|
||||||
|
|
||||||
# Walk over the files
|
# Walk over the files
|
||||||
for my $InName (@_) {
|
for my $InName (keys (%Files)) {
|
||||||
|
|
||||||
# Process one file
|
# Process one file
|
||||||
Process1 ($InName);
|
Process1 ($InName);
|
||||||
@ -240,34 +368,36 @@ sub Pass1 {
|
|||||||
sub Process2 {
|
sub Process2 {
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
local $Base;
|
my $Base;
|
||||||
local $Ext;
|
my $Ext;
|
||||||
local $Line;
|
my $Line;
|
||||||
local $OutLine;
|
my $OutLine;
|
||||||
local $Id;
|
my $Id;
|
||||||
local $Label;
|
my $Label;
|
||||||
local $Operand;
|
my $Operand;
|
||||||
local $Comment;
|
my $Comment;
|
||||||
|
|
||||||
# Input file is parameter
|
# Input file is parameter
|
||||||
local $InName = shift(@_);
|
my $InName = shift(@_);
|
||||||
|
|
||||||
# Create the output file name from the input file name
|
# Create the output file name from the input file name
|
||||||
local $OutName = GetOutName ($InName);
|
my $OutName = GetOutName ($InName);
|
||||||
|
|
||||||
# Current cheap local label prefix is empty
|
# Current cheap local label prefix is empty
|
||||||
local $CheapPrefix = "";
|
my $CheapPrefix = "";
|
||||||
|
|
||||||
# Open a the input file
|
# Open a the input file
|
||||||
open (INPUT, "<$InName") or Abort ("Cannot open $InName");
|
my $FileName = $Files{$InName}; # Includes path if needed
|
||||||
|
open (INPUT, "<$FileName") or Abort ("Cannot open $FileName: $!");
|
||||||
|
|
||||||
# Open the output file and print the HTML header
|
# Open the output file and print the HTML header
|
||||||
open (OUTPUT, ">$OutName") or Abort ("Cannot open $OutName");
|
open (OUTPUT, ">$OutName") or Abort ("Cannot open $OutName: $!");
|
||||||
DocHeader (OUTPUT, $InName);
|
DocHeader (OUTPUT, $InName);
|
||||||
|
|
||||||
# The instructions that will have hyperlinks if a label is used
|
# The instructions that will have hyperlinks if a label is used
|
||||||
local $Ins = "adc|add|and|bcc|bcs|beq|bit|bmi|bne|bpl|bcv|bvs|cmp|cpx|cpy|dec|".
|
my $Ins = "adc|add|and|bcc|bcs|beq|bit|bmi|bne|bpl|bcv|bra|bvs|".
|
||||||
"eor|inc|jmp|jsr|lda|ldx|ldy|ora|rol|sbc|sta|stx|sty|sub|";
|
"cmp|cpx|cpy|dec|eor|inc|jmp|jsr|lda|ldx|ldy|ora|rol|".
|
||||||
|
"sbc|sta|stx|sty|sub|";
|
||||||
|
|
||||||
# Read the input file, replacing references by hyperlinks and mark
|
# Read the input file, replacing references by hyperlinks and mark
|
||||||
# labels as link targets.
|
# labels as link targets.
|
||||||
@ -295,7 +425,7 @@ sub Process2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Get the label for the id
|
# Get the label for the id
|
||||||
$Label = $Labels{$InName}{$Id};
|
$Label = $Labels{$OutName}{$Id};
|
||||||
|
|
||||||
# Print the label with a tag
|
# Print the label with a tag
|
||||||
$OutLine .= sprintf ("<a name=\"%s\">%s%s</a>%s%s", $Label, $1, $2, $3, $4);
|
$OutLine .= sprintf ("<a name=\"%s\">%s%s</a>%s%s", $Label, $1, $2, $3, $4);
|
||||||
@ -326,7 +456,7 @@ sub Process2 {
|
|||||||
$Line = $2;
|
$Line = $2;
|
||||||
|
|
||||||
# Variable to assemble HTML representation
|
# Variable to assemble HTML representation
|
||||||
local $Item = $Id;
|
my $Item = $Id;
|
||||||
|
|
||||||
# If we have an export for this import, add a link to this
|
# If we have an export for this import, add a link to this
|
||||||
# export definition
|
# export definition
|
||||||
@ -336,8 +466,8 @@ sub Process2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Make this import a link target
|
# Make this import a link target
|
||||||
if (exists ($Labels{$InName}{$Id})) {
|
if (exists ($Imports{$OutName}{$Id})) {
|
||||||
$Label = $Labels{$InName}{$1};
|
$Label = $Imports{$OutName}{$1};
|
||||||
$Item = sprintf ("<a name=\"%s\">%s</a>", $Label, $Item);
|
$Item = sprintf ("<a name=\"%s\">%s</a>", $Label, $Item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,12 +501,12 @@ sub Process2 {
|
|||||||
$Line = $2;
|
$Line = $2;
|
||||||
|
|
||||||
# Variable to assemble HTML representation
|
# Variable to assemble HTML representation
|
||||||
local $Item = $Id;
|
my $Item = $Id;
|
||||||
|
|
||||||
# If we have a definition for this export in this file, add
|
# If we have a definition for this export in this file, add
|
||||||
# a link to the definition.
|
# a link to the definition.
|
||||||
if (exists ($Labels{$InName}{$1})) {
|
if (exists ($Labels{$OutName}{$1})) {
|
||||||
$Label = $Labels{$InName}{$1};
|
$Label = $Labels{$OutName}{$1};
|
||||||
$Item = sprintf ("<a href=\"#%s\">%s</a>", $Label, $Item);
|
$Item = sprintf ("<a href=\"#%s\">%s</a>", $Label, $Item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,8 +543,8 @@ sub Process2 {
|
|||||||
|
|
||||||
# Print all identifiers if there are any
|
# Print all identifiers if there are any
|
||||||
while ($Line =~ /^([_a-zA-Z][_\w]*)(.*)$/) {
|
while ($Line =~ /^([_a-zA-Z][_\w]*)(.*)$/) {
|
||||||
if (exists ($Labels{$InName}{$1})) {
|
if (exists ($Labels{$OutName}{$1})) {
|
||||||
$Label = $Labels{$InName}{$1};
|
$Label = $Labels{$OutName}{$1};
|
||||||
$OutLine .= sprintf ("<a href=\"#%s\">%s</a>", $Label, $1);
|
$OutLine .= sprintf ("<a href=\"#%s\">%s</a>", $Label, $1);
|
||||||
} else {
|
} else {
|
||||||
$OutLine .= "$1";
|
$OutLine .= "$1";
|
||||||
@ -431,6 +561,24 @@ sub Process2 {
|
|||||||
# Add an remainder if there is one
|
# Add an remainder if there is one
|
||||||
$OutLine .= Cleanup ($Line);
|
$OutLine .= Cleanup ($Line);
|
||||||
|
|
||||||
|
# Handle .proc
|
||||||
|
} elsif ($Line =~ /^(\.proc\s+)([_a-zA-Z][_\w]*)?(.*)$/) {
|
||||||
|
|
||||||
|
# Do we have an identifier?
|
||||||
|
if ($2 ne "") {
|
||||||
|
# Get the label for the id
|
||||||
|
$Label = $Labels{$OutName}{$2};
|
||||||
|
|
||||||
|
# Print the label with a tag
|
||||||
|
$OutLine .= sprintf ("%s<a name=\"%s\">%s</a>", $1, $Label, $2);
|
||||||
|
|
||||||
|
# Use the remainder for line
|
||||||
|
$Line = $3;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Cleanup the remainder and add it
|
||||||
|
$OutLine .= Cleanup ($Line);
|
||||||
|
|
||||||
# Check for any legal instruction
|
# Check for any legal instruction
|
||||||
} elsif ($Line =~ /^($Ins)(\s+)(.*?)(\s*)(;.*$|$)/) {
|
} elsif ($Line =~ /^($Ins)(\s+)(.*?)(\s*)(;.*$|$)/) {
|
||||||
|
|
||||||
@ -454,13 +602,8 @@ sub Process2 {
|
|||||||
$Id = $3;
|
$Id = $3;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Do we have a label for this id?
|
# Get the reference to this label if we find it
|
||||||
if (exists ($Labels{$InName}{$Id})) {
|
$Operand = Cleanup($1) . RefLabel($OutName, $Id, $2 . $3) . Cleanup($4);
|
||||||
$Label = $Labels{$InName}{$Id};
|
|
||||||
$Operand = sprintf ("%s<a href=\"#%s\">%s%s</a>%s",
|
|
||||||
Cleanup($1), $Label, $2, $3, Cleanup ($4));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Reassemble and print the line
|
# Reassemble and print the line
|
||||||
@ -488,10 +631,10 @@ sub Process2 {
|
|||||||
|
|
||||||
|
|
||||||
# Pass2: Read all files the second time.
|
# Pass2: Read all files the second time.
|
||||||
sub Pass2 {
|
sub Pass2 () {
|
||||||
|
|
||||||
# Walk over the files
|
# Walk over the files
|
||||||
for my $InName (@_) {
|
for my $InName (keys (%Files)) {
|
||||||
|
|
||||||
# Process one file
|
# Process one file
|
||||||
Process2 ($InName);
|
Process2 ($InName);
|
||||||
@ -501,20 +644,195 @@ sub Pass2 {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------
|
#-----------------------------------------------------------------------------#
|
||||||
# Code
|
# Create an index page #
|
||||||
# ----------------------------------------------------------
|
# ----------------------------------------------------------------------------#
|
||||||
|
|
||||||
# Get the arguments
|
|
||||||
#if ($#ARGV != 0) {
|
|
||||||
# printf STDERR "Usage: %s asm-file\n", $ARGV[0];
|
|
||||||
# exit (1);
|
|
||||||
#}
|
|
||||||
|
|
||||||
#
|
|
||||||
Pass1 (@ARGV);
|
|
||||||
Pass2 (@ARGV);
|
|
||||||
|
|
||||||
|
# Print a list of all files
|
||||||
|
sub FileIndex {
|
||||||
|
|
||||||
|
# File is argument
|
||||||
|
my $INDEX = $_[0];
|
||||||
|
|
||||||
|
# Print the file list in a table
|
||||||
|
print $INDEX "<h2>Files</h2><p>\n";
|
||||||
|
print $INDEX "<table border=\"0\" width=\"100%\">\n";
|
||||||
|
my $Count = 0;
|
||||||
|
for my $File (sort (keys (%Files))) {
|
||||||
|
|
||||||
|
#
|
||||||
|
if (($Count % $IndexCols) == 0) {
|
||||||
|
print $INDEX "<tr>\n";
|
||||||
|
}
|
||||||
|
printf $INDEX "<td><a href=\"%s\">%s</a></td>\n", GetOutName ($File), $File;
|
||||||
|
if (($Count % $IndexCols) == $IndexCols-1) {
|
||||||
|
print $INDEX "</tr>\n";
|
||||||
|
}
|
||||||
|
$Count++;
|
||||||
|
}
|
||||||
|
if (($Count % $IndexCols) != 0) {
|
||||||
|
print $INDEX "</tr>\n";
|
||||||
|
}
|
||||||
|
print $INDEX "</table><p><br><p>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Print a list of all exports
|
||||||
|
sub ExportIndex {
|
||||||
|
|
||||||
|
# File is argument
|
||||||
|
my $INDEX = $_[0];
|
||||||
|
|
||||||
|
# Print the file list in a table
|
||||||
|
print $INDEX "<h2>Exports</h2><p>\n";
|
||||||
|
print $INDEX "<table border=\"0\" width=\"100%\">\n";
|
||||||
|
my $Count = 0;
|
||||||
|
for my $Export (sort (keys (%Exports))) {
|
||||||
|
|
||||||
|
# Get the export
|
||||||
|
my $File;
|
||||||
|
my $Label;
|
||||||
|
($File, $Label) = split (/#/, $Exports{$Export});
|
||||||
|
|
||||||
|
# The label is the label of the export statement. If we can find the
|
||||||
|
# actual label, use this instead.
|
||||||
|
if (exists ($Labels{$File}{$Export})) {
|
||||||
|
$Label = $Labels{$File}{$Export};
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
if (($Count % $IndexCols) == 0) {
|
||||||
|
print $INDEX "<tr>\n";
|
||||||
|
}
|
||||||
|
printf $INDEX "<td><a href=\"%s#%s\">%s</a></td>\n", $File, $Label, $Export;
|
||||||
|
if (($Count % $IndexCols) == $IndexCols-1) {
|
||||||
|
print $INDEX "</tr>\n";
|
||||||
|
}
|
||||||
|
$Count++;
|
||||||
|
}
|
||||||
|
if (($Count % $IndexCols) != 0) {
|
||||||
|
print $INDEX "</tr>\n";
|
||||||
|
}
|
||||||
|
print $INDEX "</table><p><br><p>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sub CreateIndex {
|
||||||
|
|
||||||
|
# Open the index page file
|
||||||
|
open (INDEX, ">$IndexName") or Abort ("Cannot open $IndexName: $!");
|
||||||
|
|
||||||
|
# Print the header
|
||||||
|
print INDEX <<"EOF";
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html-40/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
|
||||||
|
FileIndex (INDEX);
|
||||||
|
ExportIndex (INDEX);
|
||||||
|
|
||||||
|
# Print the document footer
|
||||||
|
my $Today = localtime;
|
||||||
|
print INDEX <<"EOF";
|
||||||
|
<p><br><p>
|
||||||
|
<hr size=1 noshade>
|
||||||
|
<address>
|
||||||
|
<a href="http://validator.w3.org/check/referer"><img border=0
|
||||||
|
src="http://validator.w3.org/images/vh40"
|
||||||
|
alt="Valid HTML 4.0!" height="31" width="88" align=right></a>
|
||||||
|
$IndexName; generated on $Today by ca65html<br>
|
||||||
|
<a href=\"mailto:uz\@cc65.org\">uz\@cc65.org</a>
|
||||||
|
</address>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Close the index file
|
||||||
|
close (INDEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------#
|
||||||
|
# Print usage information #
|
||||||
|
# ----------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sub Usage {
|
||||||
|
print "Usage: ca65html [options] file ...\n";
|
||||||
|
print "Options:\n";
|
||||||
|
print "\t--bgcolor c\tUse background color c instead of $BGColor\n";
|
||||||
|
print "\t--help\t\tThis text\n";
|
||||||
|
print "\t--indexcols n\tUse n columns on index page (default $IndexCols)\n";
|
||||||
|
print "\t--indexname f\tUse name f for the index file instead of $IndexName\n";
|
||||||
|
print "\t--indexpage\tCreate an index page\n";
|
||||||
|
print "\t--indextitle t\tUse t as the index title instead of $IndexTitle\n";
|
||||||
|
print "\t--linkstyle s\tUse the given link style\n";
|
||||||
|
print "\t--replaceext\tReplace source extension instead of appending .html\n";
|
||||||
|
print "\t--textcolor c\tUse text color c instead of $TextColor\n";
|
||||||
|
print "\t--verbose\tBe more verbose\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------#
|
||||||
|
# Main #
|
||||||
|
# ----------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Get program options
|
||||||
|
GetOptions ("bgcolor=s" => \$BGColor,
|
||||||
|
"debug!" => \$Debug,
|
||||||
|
"help" => \$Help,
|
||||||
|
"indexcols=i" => \$IndexCols,
|
||||||
|
"indexname=s" => \$IndexName,
|
||||||
|
"indexpage" => \$IndexPage,
|
||||||
|
"indextitle=s" => \$IndexTitle,
|
||||||
|
"linkstyle=i" => \$LinkStyle,
|
||||||
|
"replaceext" => \$ReplaceExt,
|
||||||
|
"textcolor=s" => \$TextColor,
|
||||||
|
"verbose!" => \$Verbose,
|
||||||
|
"<>" => \&AddFile);
|
||||||
|
|
||||||
|
# Check some arguments
|
||||||
|
if ($IndexCols <= 0 || $IndexCols >= 20) {
|
||||||
|
Abort ("Invalid value for --indexcols option");
|
||||||
|
}
|
||||||
|
|
||||||
|
# Print help if requested
|
||||||
|
if ($Help) {
|
||||||
|
Usage ();
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if we have input files given
|
||||||
|
if ($FileCount == 0) {
|
||||||
|
Abort ("No input files");
|
||||||
|
}
|
||||||
|
|
||||||
|
# Convert the documents
|
||||||
|
Pass1 ();
|
||||||
|
Pass2 ();
|
||||||
|
|
||||||
|
# Generate an index page if requested
|
||||||
|
if ($IndexPage) {
|
||||||
|
CreateIndex ();
|
||||||
|
}
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
exit 0;
|
exit 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user