2 ###############################################################################
6 # Convert a ca65 source into HTML #
10 # (C) 2000-2007 Ullrich von Bassewitz #
12 # D-70794 Filderstadt #
13 # EMail: uz@cc65.org #
16 # This software is provided 'as-is', without any expressed or implied #
17 # warranty. In no event will the authors be held liable for any damages #
18 # arising from the use of this software. #
20 # Permission is granted to anyone to use this software for any purpose, #
21 # including commercial applications, and to alter it and redistribute it #
22 # freely, subject to the following restrictions: #
24 # 1. The origin of this software must not be misrepresented; you must not #
25 # claim that you wrote the original software. If you use this software #
26 # in a product, an acknowledgment in the product documentation would be #
27 # appreciated but is not required. #
28 # 2. Altered source versions must be plainly marked as such, and must not #
29 # be misrepresented as being the original software. #
30 # 3. This notice may not be removed or altered from any source #
33 ###############################################################################
37 # Things currently missing:
39 # - Scoping with .proc/.endproc, .scope/.endscope, .enum/.endenum,
40 # .struct/.endstruct, .union/endunion, .repeat/.endrep, .local
41 # - .global is ignored
42 # - .case is ignored, labels are always case-sensitive
43 # - .include handling (difficult)
44 # - The global namespace operator ::
57 #-----------------------------------------------------------------------------#
59 # ----------------------------------------------------------------------------#
64 my %Files = (); # List of all files.
65 my $FileCount = 0; # Number of input files
66 my %Exports = (); # List of exported symbols.
67 my %Imports = (); # List of imported symbols.
68 my %Labels = (); # List of all labels
69 my $LabelNum = 0; # Counter to generate unique labels
71 # Command line options
72 my $BGColor = "#FFFFFF"; # Background color
73 my $Colorize = 0; # Colorize the output
74 my $CommentColor = "#B22222"; # Color for comments
75 my $CRefs = 0; # Add references to the C file
76 my $CtrlColor = "#228B22"; # Color for control directives
77 my $CvtTabs = 0; # Convert tabs to spaces
78 my $TabSize = 8; # This is how god created them
79 my $Debug = 0; # No debugging
80 my $Help = 0; # Help flag
81 my $HTMLDir = ""; # Directory in which to create the files
82 my $IndexCols = 6; # Columns in the file listing
83 my $IndexTitle = "Index"; # Title of index page
84 my $IndexName = "index.html"; # Name of index page
85 my $IndexPage = 0; # Create an index page
86 my $KeywordColor = "#A020F0"; # Color for keywords
87 my $LineLabels = 0; # Add a HTML label to each line
88 my $LineNumbers = 0; # Add line numbers to the output
89 my $LinkStyle = 0; # Default link style
90 my $ReplaceExt = 0; # Replace extension instead of appending
91 my $StringColor = "#6169C1"; # Color for strings
92 my $TextColor = "#000000"; # Text color
93 my $Verbose = 0; # Be quiet
95 # Table used to convert the label number into names
96 my @NameTab = ('A' .. 'Z', '0' .. '9');
100 #-----------------------------------------------------------------------------#
102 # ----------------------------------------------------------------------------#
106 # Terminate with an error
108 print STDERR "ca65html: @_\n";
112 # Print a message if verbose is true
115 print "ca65html: @_\n";
119 # Generate a label and return it
124 my $Num = $LabelNum++;
127 for ($I = 0; $I < 4; $I++) {
128 $L = $NameTab[$Num % 36] . $L;
134 # Make an output file name from an input file name
137 # Input name is parameter
140 # Create the output file name from the input file name
141 if ($ReplaceExt && $InName =~ /^(.+)\.([^\.\/]*)$/) {
144 return "$InName.html";
148 # Translate some HTML characters into harmless names.
158 # Strip a path from a filename and return just the name
161 # Filename is argument
162 my $FileName = $_[0];
164 # Remove a path name if we have one
165 $FileName =~ /^(.*?)([^\/]*)$/;
171 #-----------------------------------------------------------------------------#
172 # Document header and footer #
173 # ----------------------------------------------------------------------------#
177 # Print the document header
179 my $OUT = shift (@_);
180 my $Asm = shift (@_);
181 print $OUT "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
185 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
186 <meta name="GENERATOR" content="ca65html">
188 <style type=\"text/css\">
190 background-color: $BGColor;
198 border-bottom: 1px solid grey;
203 border-top: 1px solid grey;
214 color: $KeywordColor;
220 color: $CommentColor;
234 <div id=\"top\"><h1>$Asm</h1></div>
238 # Print the document footer
240 my $OUT = shift (@_);
241 my $Name = shift (@_);
243 # Get the current date and time
244 my $Today = localtime;
247 print $OUT "<div id=\"bottom\"><address>\n";
248 print $OUT "<a href=\"http://validator.w3.org/check?uri=referer\">\n";
249 print $OUT "<img src=\"http://www.w3.org/Icons/valid-xhtml10-blue\" alt=\"Valid XHTML 1.0 Strict\" height=\"31\" width=\"88\" /></a><br>\n";
250 print $OUT "$Name; generated on $Today by ca65html<br>\n";
251 print $OUT "<a href=\"mailto:uz@cc65.org\">uz@cc65.org</a>\n";
252 print $OUT "</address></div>\n";
253 print $OUT "</body></html>\n";
258 #-----------------------------------------------------------------------------#
260 #-----------------------------------------------------------------------------#
264 sub ColorizeComment {
265 if ($Colorize && $_[0] ne "") {
266 return "<span class=\"comment\">$_[0]</span>";
276 return "<span class=\"ctrl\">$_[0]</span>";
284 sub ColorizeKeyword {
286 return "<span class=\"keyword\">$_[0]</span>";
296 return "<span class=\"string\">$_[0]</span>";
304 #-----------------------------------------------------------------------------#
305 # File list management #
306 #-----------------------------------------------------------------------------#
312 # Argument is file to add
313 my $FileName = $_[0];
315 # Get just the name (remove a path if there is one)
316 my $Name = StripPath ($FileName);
318 # Check if we have the file already
319 if (exists ($Files{$Name})) {
320 Gabble ("File \"$FileName\" already known");
324 # Check with the full pathname. If we don't find it, search in the current
326 if (-f $FileName && -r _) {
327 $Files{$Name} = $FileName;
329 } elsif (-f $Name && -r _) {
330 $Files{$Name} = $Name;
333 Abort ("$FileName not found or not readable");
339 #-----------------------------------------------------------------------------#
340 # Referencing and defining labels #
341 #-----------------------------------------------------------------------------#
345 # Get a label reference
348 # Arguments are: Filename, identifier, item that should be tagged
349 my $FileName = $_[0];
353 # Search for the identifier in the list of labels
354 if (exists ($Labels{$FileName}{$Id})) {
355 # It is a label (in this file)
356 return sprintf ("<a href=\"#%s\">%s</a>", $Labels{$FileName}{$Id}, $Item);
357 } elsif (exists ($Imports{$FileName}{$Id})) {
358 # It is an import. If LinkStyle is 1, or if the file exporting the
359 # identifier is not visible, we link to the .import statement in the
360 # current file. Otherwise we link directly to the referenced symbol
361 # in the file that exports it.
362 if ($LinkStyle == 1 or not exists ($Exports{$Id})) {
363 return sprintf ("<a href=\"#%s\">%s</a>", $Imports{$FileName}{$Id}, $Item);
365 # Get the filename from the export
367 ($FileName, $Label) = split (/#/, $Exports{$Id});
368 if (not defined ($Labels{$FileName}{$Id})) {
369 # This may currently happen because we don't see .include
370 # statements, so we may have an export but no definition.
371 # Link to the .export statement instead
372 $Label = $Exports{$Id};
374 # Link to the definition in the file
375 $Label = sprintf ("%s#%s", $FileName, $Labels{$FileName}{$Id});
377 return sprintf ("<a href=\"%s\">%s</a>", $Label, $Item);
380 # The symbol is unknown, return as is
387 #-----------------------------------------------------------------------------#
389 # ----------------------------------------------------------------------------#
393 # Process1: Read one file for the first time.
400 # Filename is parameter
401 my $InName = shift(@_);
403 # Create the output file name from the input file name
404 my $OutName = GetOutName ($InName);
406 # Current cheap local label prefix is empty
407 my $CheapPrefix = "";
409 # Open a the input file
410 my $FileName = $Files{$InName}; # Includes path if needed
411 open (INPUT, "<$FileName") or Abort ("Cannot open $FileName: $!");
413 # Keep the user happy
414 Gabble ("$FileName => $OutName");
416 # Read and process all lines from the file
417 while ($Line = <INPUT>) {
423 if ($Line =~ /^\s*(([\@?]?)[_a-zA-Z]\w*)\s*(?::=?|=)/) {
425 # Is this a local label?
428 $Id = "$CheapPrefix$1";
432 # Remember the id as new cheap local prefix
437 $Labels{$OutName}{$Id} = GenLabel();
439 # Check for an import statement
440 } elsif ($Line =~ /^\s*\.(?:(?:force)?import|importzp)\s+(.*?)\s*(?:;.*)?$/i) {
442 # Split into a list of identifiers
443 my @Ids = split (/\s*(?::\s*[A-Za-z]+\s*)?,\s*/, $1);
445 # Remove an address-size specifier, from the last identifier,
447 $Ids[$#Ids] =~ s/\s*:\s*[A-Za-z]+//;
450 $Imports{$OutName}{$Id} = GenLabel();
453 # Check for an export statement
454 } elsif ($Line =~ /^\s*\.export(?:zp)?\s+(.*?)\s*(?:;.*)?$/i) {
456 # Split into a list of identifiers
457 my @Ids = split (/\s*(?::\s*[A-Za-z]+\s*)?,\s*/, $1);
459 # Remove an address-size specifier, from the last identifier,
461 $Ids[$#Ids] =~ s/\s*:\s*[A-Za-z]+//;
464 $Exports{$Id} = sprintf ("%s#%s", $OutName, GenLabel());
467 # Check for an actor statement.
468 } elsif ($Line =~ /^\s*\.(?:(?:(?:con|de)struc|interrup)tor|condes)\s+([_a-z]\w*)/i) {
469 $Exports{$1} = sprintf ("%s#%s", $OutName, GenLabel());
471 # Check for a .proc statement
472 } elsif ($Line =~ /^\s*\.proc\s+([_a-z]\w*)/i) {
474 # Remember the ID as the new cheap-local prefix.
476 $Labels{$OutName}{$1} = GenLabel();
480 # Close the input file
486 # Pass1: Read all files for the first time.
489 # Keep the user happy
492 # Walk over the files
493 for my $InName (keys (%Files)) {
501 #-----------------------------------------------------------------------------#
503 # ----------------------------------------------------------------------------#
507 # Process2: Read one file the second time.
520 # Input file is parameter
521 my $InName = shift(@_);
523 # Create the output file name from the input file name
524 my $OutName = GetOutName ($InName);
526 # Current cheap local label prefix is empty
527 my $CheapPrefix = "";
529 # Open a the input file
530 my $FileName = $Files{$InName}; # Includes path if needed
531 open (INPUT, "<$FileName") or Abort ("Cannot open $FileName: $!");
533 # Open the output file and print the HTML header
534 open (OUTPUT, ">$HTMLDir$OutName") or Abort ("Cannot open $OutName: $!");
535 DocHeader (OUTPUT, $InName);
536 print OUTPUT "<pre>\n";
538 # Keep the user happy
539 Gabble ("$FileName => $OutName");
541 # The instructions that will have hyperlinks if a label is used.
542 # And, they will be highlighted when color is used.
543 my $LabelIns = "adc|add|and|asl|bb[rs][0-7]|b[cv][cs]|beq|bge|bit|blt|".
544 "bmi|bne|bpl|br[akl]|bsr|cmp|cop|cp[axy]|dec|eor|inc|jml|".
545 "jmp|jsl|jsr|ld[axy]|lsr|mvn|mvp|ora|pe[air]|rep|".
546 "[rs]mb[0-7]|rol|ror|sbc|sep|st[012axyz]|sub|tai|tam|tdd|".
547 "ti[ain]|tma|trb|tsb|tst";
549 # Instructions that have only the implied-addressing mode -- therefore,
550 # no hyperlinking. They will be highlighted only, when color is used.
551 my $OtherIns = "cl[acdivxy]|csh|csl|de[axy]|in[axy]|nop|ph[abdkpxy]|".
552 "pl[abdpxy]|rt[ils]|sax|say|se[cdit]|stp|swa|sxy|ta[dsxy]|".
553 "tam[0-7]|tcd|tcs|tda|tdc|tma[0-7]|ts[acx]|tx[asy]|tya|tyx|".
556 # Read the input file, replacing references with hyperlinks; and, mark
557 # labels as link targets.
559 LINE: while ($Line = <INPUT>) {
564 # Remove the newline at the end of line. Don't use chomp to be able to
565 # read dos/windows sources on unices.
566 $Line =~ s/[\r\n]*$//;
568 # If requested, convert tabs to spaces
570 # Don't ask me - this is from the perl manual page
571 1 while ($Line =~ s/\t+/' ' x (length($&) * $TabSize - length($`) % $TabSize)/e) ;
574 # Clear the output line
577 # If requested, add a html label to each line with a name "linexxx",
578 # so it can be referenced from the outside (this is the same convention
579 # that is used by c2html). If we have line numbers enabled, add them.
580 if ($LineLabels && $LineNumbers) {
581 $OutLine .= sprintf ("<a name=\"line%d\">%6d</a>: ", $LineNo, $LineNo);
582 } elsif ($LineLabels) {
583 $OutLine .= sprintf ("<a name=\"line%d\"></a>", $LineNo);
584 } elsif ($LineNumbers) {
585 $OutLine .= sprintf ("%6d: ", $LineNo);
588 # Cut off a comment from the input line. Beware: We have to check for
589 # strings, since these may contain a semicolon that is no comment
591 ($Line, $Comment) = $Line =~ /^((?:[^"';]+|".*?"|'.*?')*)(.*)$/;
592 if ($Comment =~ /^["']/) {
593 # Line with invalid syntax - there's a string start but
595 Abort (sprintf ("Invalid input at %s(%d)", $FileName, $LineNo));
598 # Remove trailing whitespace and move it together with the comment
599 # into the $Trailer variable.
601 $Trailer = $& . ColorizeComment (Cleanup ($Comment));
603 # Check for a label at the start of the line. If we have one, process
604 # it, and remove it from the line.
605 if ($Line =~ s/^\s*?(([\@?]?)[_a-zA-Z]\w*)(\s*(?::=?|=))//) {
607 # Is this a local label?
610 $Id = "$CheapPrefix$1";
614 # Remember the id as new cheap local prefix
618 # Get the label for the id
619 $Label = $Labels{$OutName}{$Id};
621 # Print the label with a tag
622 $OutLine .= "<a name=\"$Label\">$1</a>$3";
624 # Is the name explicitly assigned a value?
626 # Print all identifiers if there are any.
627 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
628 # Add the non-label stuff.
629 $OutLine .= Cleanup ($1);
631 # Use the prefix if the label is local.
632 # Get the reference to that label if we find it.
633 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
636 # Add a remainder if there is one.
637 $OutLine .= Cleanup ($Line);
639 # The line is complete; print it.
644 # Print any leading whitespace and remove it, so we don't have to
645 # care about whitespace below.
646 if ($Line =~ s/^\s+//) {
650 # Handle the import statements
651 if ($Line =~ s/^\.(?:(?:force)?import|importzp)\s+//i) {
653 # Print any fixed stuff from the line and remove it
656 # Print all identifiers if there are any
657 while ($Line =~ s/^[_a-zA-Z]\w*//) {
659 # Remember the identifier
662 # Variable to assemble HTML representation
665 # Make this import a link target
666 if (exists ($Imports{$OutName}{$Id})) {
667 $Label = $Imports{$OutName}{$Id};
668 $Contents .= sprintf (" name=\"%s\"", $Label);
671 # If we have an export for this import, add a link to this
673 if (exists ($Exports{$Id})) {
674 $Label = $Exports{$Id};
675 $Contents .= sprintf (" href=\"%s\"", $Label);
678 # Add the HTML stuff to the output line
679 if ($Contents ne "") {
680 $OutLine .= sprintf ("<a%s>%s</a>", $Contents, $Id);
685 # Check if another identifier follows
686 if ($Line =~ s/^\s*(?::\s*[A-Za-z]+\s*)?,\s*//) {
693 # Add an remainder if there is one
694 $OutLine .= Cleanup ($Line);
696 # Handle export statements
697 } elsif ($Line =~ s/^\.export(?:zp)?\s+//i) {
699 # Print the command and the whitespace.
702 # Print all identifiers if there are any
703 while ($Line =~ s/^[_a-zA-Z]\w*//) {
705 # Remember the identifier
708 # Variable to assemble HTML representation
711 # If we have a definition for this export in this file, add
712 # a link to the definition.
713 if (exists ($Labels{$OutName}{$Id})) {
714 $Label = $Labels{$OutName}{$Id};
715 $Contents = sprintf (" href=\"#%s\"", $Label);
718 # If we have this identifier in the list of exports, add a
719 # jump target for the export.
720 if (exists ($Exports{$Id})) {
721 $Label = $Exports{$Id};
722 # Be sure to use only the label part
724 $Contents .= sprintf (" name=\"%s\"", $Label);
727 # Add the HTML stuff to the output line
728 if ($Contents ne "") {
729 $OutLine .= sprintf ("<a%s>%s</a>", $Contents, $Id);
734 # Check if another identifier follows
735 if ($Line =~ s/^\s*(?::\s*[A-Za-z]+\s*)?,\s*//) {
742 # Add an remainder if there is one
743 $OutLine .= Cleanup ($Line);
745 # Handle actor statements.
746 } elsif ($Line =~ s/^(\.(?:(?:(?:con|de)struc|interrup)tor|condes)\s+)([_a-z]\w*)//i) {
748 # Print the command and the whitespace.
751 # Remember the identifier.
754 # Variable to assemble HTML representation
757 # If we have a definition for this actor, in this file,
758 # then add a link to that definition.
759 if (exists ($Labels{$OutName}{$Id})) {
760 $Contents = sprintf (" href=\"#%s\"", $Labels{$OutName}{$Id});
763 # Get the target, for linking from imports in other files.
764 $Label = $Exports{$Id};
765 # Be sure to use only the label part.
768 # Add the HTML stuff and the remainder of the actor
769 # to the output line.
770 $OutLine .= sprintf ("<a name=\"%s\"%s>%s</a>%s", $Label,
771 $Contents, $Id, Cleanup ($Line));
773 # Check for .faraddr, .addr, .dword, .word, .dbyt, .byt, .byte, .res,
774 # .elseif, .if, .align, and .org.
775 } elsif ($Line =~ s/^\.(?:(?:far)?addr|d?word|d?byte?|res|(?:else)?if|align|org)\s+//i) {
777 # Print the command and the white space
780 # Print all identifiers if there are any
781 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
782 # Add the non label stuff
783 $OutLine .= Cleanup ($1);
785 # Use the prefix if the label is local.
786 # Get the reference to that label if we find it.
787 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
790 # Add an remainder if there is one
791 $OutLine .= Cleanup ($Line);
794 } elsif ($Line =~ /^(\.proc)(\s+)([_a-z]\w*)?(.*)$/i) {
796 # Do we have an identifier?
798 # Remember the ID as the new cheap-local prefix.
801 # Get the label for the id
802 $Label = $Labels{$OutName}{$3};
804 # Print the label with a tag
805 $OutLine .= "$1$2<a name=\"$Label\">$3</a>";
809 # Print a line that has invalid syntax (its operand isn't
810 # a correctly formed name).
815 $OutLine .= Cleanup ($4);
818 } elsif ($Line =~ /^(\.include)(\s*)\"((?:[^\"]+?|\\\")+)(\".*)$/i) {
820 # Add the fixed stuff to the output line
821 $OutLine .= "$1$2"";
823 # Get the filename into a named variable
824 my $FileName = Cleanup ($3);
826 # Get the name without a path
827 my $Name = StripPath ($3);
829 # If the include file is among the list of our files, add a link,
830 # otherwise just add the name as is.
831 if (exists ($Files{$Name})) {
832 $OutLine .= sprintf ("<a href=\"%s\">%s</a>", GetOutName ($Name), $FileName);
834 $OutLine .= $FileName;
838 $OutLine .= Cleanup ($4);
841 } elsif ($CRefs && $Line =~ s/^\.dbg\s+//) {
843 # Add the fixed stuff to the output line
846 # Check for the type of the .dbg directive
847 if ($Line =~ /^(line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*)$/) {
849 # Add the fixed stuff to the output line
850 $OutLine .= "$1"";
852 # Get the filename and line number into named variables
856 # Remember the remainder
859 # Get the name without a path
860 my $Name = StripPath ($DbgFile);
862 # We don't need FileName any longer as is, so clean it up
863 $DbgFile = Cleanup ($DbgFile);
865 # Add a link to the source file
866 $OutLine .= sprintf ("<a href=\"%s.html#line%d\">%s</a>", $Name, $DbgLine, $DbgFile);
869 $OutLine .= Cleanup ($Line);
871 } elsif ($Line =~ /^(file,\s*)\"((?:[^\"]+?|\\\")+)\"(.*)$/) { #pf FIXME: doesn't handle \" correctly!
873 # Get the filename into a named variables
874 my $DbgFile = Cleanup ($2);
876 # Get the name without a path
877 my $Name = Cleanup (StripPath ($2));
879 # Add the fixed stuff to the output line
880 $OutLine .= sprintf ("%s\"<a href=\"%s.html\">%s</a>\"%s",
881 $1, $Name, $DbgFile, $3);
886 $OutLine .= Cleanup ($Line);
890 } elsif ($CRefs && $Line =~ /^(\.dbg)(\s+line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*$)/) {
892 # Add the fixed stuff to the output line
893 $OutLine .= "$1$2"";
895 # Get the filename and line number into named variables
899 # Remember the remainder
902 # Get the name without a path
903 my $Name = StripPath ($FileName);
905 # We don't need FileName any longer as is, so clean it up
906 $FileName = Cleanup ($FileName);
908 # Add a link to the source file
909 $OutLine .= sprintf ("<a href=\"%s.html#line%d\">%s</a>", $Name, $LineNo, $FileName);
912 $OutLine .= Cleanup ($Line);
914 # Check for .ifdef, .ifndef, .ifref, and .ifnref.
915 } elsif ($Line =~ s/^(\.ifn?[dr]ef\s+)(([\@?]?)[_a-z]\w*)?//i) {
917 # Print the command and the whitespace.
921 # Use the prefix if the label is local.
922 # Get the reference to that label if we find it.
923 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
926 # Add a remainder if there is one.
927 $OutLine .= Cleanup ($Line);
929 # Check for assertions.
930 } elsif ($Line =~ s/^(\.assert\s+)(.+?)(,\s*(?:error|warning)\s*(?:,.*)?)$/$2/i) {
932 # Print the command and the whitespace.
937 # Print all identifiers if there are any.
938 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
939 # Add the non-label stuff.
940 $OutLine .= Cleanup ($1);
942 # Use the prefix if the label is local.
943 # Get the reference to that label if we find it.
944 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
947 # Add a remainder if there is one.
948 $OutLine .= Cleanup ($Line . $Comment);
950 # Check for instructions with labels
951 } elsif ($Line =~ s/^($LabelIns)\b(\s*)//io) {
953 # Print the instruction and white space
954 $OutLine .= ColorizeKeyword ($1) . $2;
956 # Print all identifiers if there are any.
957 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
959 # Add the non-label stuff.
960 $OutLine .= Cleanup ($1);
962 # Is this a local label?
965 $Id = "$CheapPrefix$2";
971 # Get the reference to this label if we find it
972 $OutLine .= RefLabel ($OutName, $Id, $2);
975 # Reassemble and print the line
976 $OutLine .= Cleanup ($Line);
978 # Check for all other instructions
979 } elsif ($Line =~ /^($OtherIns)\b(.*)$/io) {
982 $OutLine .= ColorizeKeyword ($1) . Cleanup ($2);
986 # Nothing known - print the line
987 $OutLine .= Cleanup ($Line);
992 # Colorize all keywords
993 $OutLine =~ s/(?<![\w;])\.[_a-zA-Z]\w*/ColorizeCtrl ($&)/ge;
995 # Print the result with the trailer.
996 print OUTPUT "$OutLine$Trailer\n";
999 # Print the HTML footer
1000 print OUTPUT "</pre>\n";
1001 DocFooter (OUTPUT, $OutName);
1010 # Pass2: Read all files the second time.
1013 # Keep the user happy
1016 # Walk over the files
1017 for my $InName (keys (%Files)) {
1025 #-----------------------------------------------------------------------------#
1026 # Create an index page #
1027 # ----------------------------------------------------------------------------#
1031 # Print a list of all files
1037 # Print the file list in a table
1038 print $INDEX "<h2>Files</h2><p>\n";
1039 print $INDEX "<table border=\"0\" width=\"100%\">\n";
1041 for my $File (sort (keys (%Files))) {
1044 if (($Count % $IndexCols) == 0) {
1045 print $INDEX "<tr>\n";
1047 printf $INDEX "<td><a href=\"%s\">%s</a></td>\n", GetOutName ($File), $File;
1048 if (($Count % $IndexCols) == $IndexCols-1) {
1049 print $INDEX "</tr>\n";
1053 if (($Count % $IndexCols) != 0) {
1054 print $INDEX "</tr>\n";
1056 print $INDEX "</table><p><br><p>\n";
1061 # Print a list of all exports
1067 # Print the file list in a table
1068 print $INDEX "<h2>Exports</h2><p>\n";
1069 print $INDEX "<table border=\"0\" width=\"100%\">\n";
1071 for my $Export (sort (keys (%Exports))) {
1076 ($File, $Label) = split (/#/, $Exports{$Export});
1078 # The label is the label of the export statement. If we can find the
1079 # actual label, use this instead.
1080 if (exists ($Labels{$File}{$Export})) {
1081 $Label = $Labels{$File}{$Export};
1085 if (($Count % $IndexCols) == 0) {
1086 print $INDEX "<tr>\n";
1088 printf $INDEX "<td><a href=\"%s#%s\">%s</a></td>\n", $File, $Label, $Export;
1089 if (($Count % $IndexCols) == $IndexCols-1) {
1090 print $INDEX "</tr>\n";
1094 if (($Count % $IndexCols) != 0) {
1095 print $INDEX "</tr>\n";
1097 print $INDEX "</table><p><br><p>\n";
1104 # Open the index page file
1105 open (INDEX, ">$HTMLDir$IndexName") or Abort ("Cannot open $IndexName: $!");
1108 DocHeader (INDEX, $IndexTitle, 0);
1110 # Print the file list in a table
1112 ExportIndex (INDEX);
1114 # Print the document footer
1115 DocFooter (INDEX, $IndexName);
1117 # Close the index file
1123 #-----------------------------------------------------------------------------#
1124 # Print usage information #
1125 # ----------------------------------------------------------------------------#
1130 print "Usage: ca65html [options] file ...\n";
1132 print " --bgcolor c Use background color c instead of $BGColor\n";
1133 print " --colorize Add color highlights to the output\n";
1134 print " --commentcolor c Use color c for comments instead of $CommentColor\n";
1135 print " --crefs Generate references to the C source file(s)\n";
1136 print " --ctrlcolor c Use color c for directives instead of $CtrlColor\n";
1137 print " --cvttabs Convert tabs to spaces in the output\n";
1138 print " --help This text\n";
1139 print " --htmldir dir Specify directory for HTML files\n";
1140 print " --indexcols n Use n columns on index page (default $IndexCols)\n";
1141 print " --indexname file Use file for the index file instead of $IndexName\n";
1142 print " --indexpage Create an index page\n";
1143 print " --indextitle title Use title as the index title instead of $IndexTitle\n";
1144 print " --keywordcolor c Use color c for keywords instead of $KeywordColor\n";
1145 print " --linelabels Generate a linexxx HTML label for each line\n";
1146 print " --linenumbers Add line numbers to the output\n";
1147 print " --linkstyle style Use the given link style\n";
1148 print " --replaceext Replace source extension instead of appending .html\n";
1149 print " --tabsize n Use n spaces when replacing tabs (default $TabSize)\n";
1150 print " --textcolor c Use text color c instead of $TextColor\n";
1151 print " --verbose Be more verbose\n";
1156 #-----------------------------------------------------------------------------#
1158 # ----------------------------------------------------------------------------#
1162 # Get program options
1163 GetOptions ("bgcolor=s" => \$BGColor,
1164 "colorize" => \$Colorize,
1165 "commentcolor=s" => \$CommentColor,
1167 "ctrlcolor=s" => \$CtrlColor,
1168 "cvttabs" => \$CvtTabs,
1169 "debug!" => \$Debug,
1171 "htmldir=s" => \$HTMLDir,
1172 "indexcols=i" => \$IndexCols,
1173 "indexname=s" => \$IndexName,
1174 "indexpage" => \$IndexPage,
1175 "indextitle=s" => \$IndexTitle,
1176 "keywordcolor=s" => \$KeywordColor,
1177 "linelabels" => \$LineLabels,
1178 "linenumbers" => \$LineNumbers,
1179 "linkstyle=i" => \$LinkStyle,
1180 "replaceext" => \$ReplaceExt,
1181 "tabsize=i" => \$TabSize,
1182 "textcolor=s" => \$TextColor,
1183 "verbose!" => \$Verbose,
1186 # Check some arguments
1187 if ($IndexCols <= 0 || $IndexCols >= 20) {
1188 Abort ("Invalid value for --indexcols option");
1190 if ($TabSize < 1 || $TabSize > 16) {
1191 Abort ("Invalid value for --tabsize option");
1193 if ($HTMLDir ne "" && $HTMLDir =~ /[^\/]$/) {
1194 # Add a trailing path separator
1200 # Print help if requested
1205 # Check if we have input files given
1206 if ($FileCount == 0) {
1207 Abort ("No input files");
1210 # Convert the documents
1214 # Generate an index page if requested