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 $Debug = 0; # No debugging
79 my $Help = 0; # Help flag
80 my $HTMLDir = ""; # Directory in which to create the files
81 my $IndexCols = 6; # Columns in the file listing
82 my $IndexTitle = "Index"; # Title of index page
83 my $IndexName = "index.html"; # Name of index page
84 my $IndexPage = 0; # Create an index page
85 my $KeywordColor = "#A020F0"; # Color for keywords
86 my $LineLabels = 0; # Add a HTML label to each line
87 my $LineNumbers = 0; # Add line numbers to the output
88 my $LinkStyle = 0; # Default link style
89 my $ReplaceExt = 0; # Replace extension instead of appending
90 my $StringColor = "#6169C1"; # Color for strings
91 my $TextColor = "#000000"; # Text color
92 my $Verbose = 0; # Be quiet
94 # Table used to convert the label number into names
95 my @NameTab = ('A' .. 'Z', '0' .. '9');
99 #-----------------------------------------------------------------------------#
101 # ----------------------------------------------------------------------------#
105 # Terminate with an error
107 print STDERR "ca65html: @_\n";
111 # Print a message if verbose is true
114 print "ca65html: @_\n";
118 # Generate a label and return it
123 my $Num = $LabelNum++;
126 for ($I = 0; $I < 4; $I++) {
127 $L = $NameTab[$Num % 36] . $L;
133 # Make an output file name from an input file name
136 # Input name is parameter
139 # Create the output file name from the input file name
140 if ($ReplaceExt && $InName =~ /^(.+)\.([^\.\/]*)$/) {
143 return "$InName.html";
147 # Translate some HTML characters into harmless names.
157 # Strip a path from a filename and return just the name
160 # Filename is argument
161 my $FileName = $_[0];
163 # Remove a path name if we have one
164 $FileName =~ /^(.*?)([^\/]*)$/;
170 #-----------------------------------------------------------------------------#
171 # Document header and footer #
172 # ----------------------------------------------------------------------------#
176 # Print the document header
178 my $OUT = shift (@_);
179 my $Asm = shift (@_);
180 print $OUT "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
184 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
185 <meta name="GENERATOR" content="ca65html">
187 <style type=\"text/css\">
189 background-color: $BGColor;
197 border-bottom: 1px solid grey;
202 border-top: 1px solid grey;
213 color: $KeywordColor;
219 color: $CommentColor;
233 <div id=\"top\"><h1>$Asm</h1></div>
237 # Print the document footer
239 my $OUT = shift (@_);
240 my $Name = shift (@_);
242 # Get the current date and time
243 my $Today = localtime;
246 print $OUT "<div id=\"bottom\"><address>\n";
247 print $OUT "<a href=\"http://validator.w3.org/check?uri=referer\">\n";
248 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";
249 print $OUT "$Name; generated on $Today by ca65html<br>\n";
250 print $OUT "<a href=\"mailto:uz@cc65.org\">uz@cc65.org</a>\n";
251 print $OUT "</address></div>\n";
252 print $OUT "</body></html>\n";
257 #-----------------------------------------------------------------------------#
259 #-----------------------------------------------------------------------------#
263 sub ColorizeComment {
264 if ($Colorize && $_[0] ne "") {
265 return "<span class=\"comment\">$_[0]</span>";
275 return "<span class=\"ctrl\">$_[0]</span>";
283 sub ColorizeKeyword {
285 return "<span class=\"keyword\">$_[0]</span>";
295 return "<span class=\"string\">$_[0]</span>";
303 #-----------------------------------------------------------------------------#
304 # File list management #
305 #-----------------------------------------------------------------------------#
311 # Argument is file to add
312 my $FileName = $_[0];
314 # Get just the name (remove a path if there is one)
315 my $Name = StripPath ($FileName);
317 # Check if we have the file already
318 if (exists ($Files{$Name})) {
319 Gabble ("File \"$FileName\" already known");
323 # Check with the full pathname. If we don't find it, search in the current
325 if (-f $FileName && -r _) {
326 $Files{$Name} = $FileName;
328 } elsif (-f $Name && -r _) {
329 $Files{$Name} = $Name;
332 Abort ("$FileName not found or not readable");
338 #-----------------------------------------------------------------------------#
339 # Referencing and defining labels #
340 #-----------------------------------------------------------------------------#
344 # Get a label reference
347 # Arguments are: Filename, identifier, item that should be tagged
348 my $FileName = $_[0];
352 # Search for the identifier in the list of labels
353 if (exists ($Labels{$FileName}{$Id})) {
354 # It is a label (in this file)
355 return sprintf ("<a href=\"#%s\">%s</a>", $Labels{$FileName}{$Id}, $Item);
356 } elsif (exists ($Imports{$FileName}{$Id})) {
357 # It is an import. If LinkStyle is 1, or if the file exporting the
358 # identifier is not visible, we link to the .import statement in the
359 # current file. Otherwise we link directly to the referenced symbol
360 # in the file that exports it.
361 if ($LinkStyle == 1 or not exists ($Exports{$Id})) {
362 return sprintf ("<a href=\"#%s\">%s</a>", $Imports{$FileName}{$Id}, $Item);
364 # Get the filename from the export
366 ($FileName, $Label) = split (/#/, $Exports{$Id});
367 if (not defined ($Labels{$FileName}{$Id})) {
368 # This may currently happen because we don't see .include
369 # statements, so we may have an export but no definition.
370 # Link to the .export statement instead
371 $Label = $Exports{$Id};
373 # Link to the definition in the file
374 $Label = sprintf ("%s#%s", $FileName, $Labels{$FileName}{$Id});
376 return sprintf ("<a href=\"%s\">%s</a>", $Label, $Item);
379 # The symbol is unknown, return as is
386 #-----------------------------------------------------------------------------#
388 # ----------------------------------------------------------------------------#
392 # Process1: Read one file for the first time.
399 # Filename is parameter
400 my $InName = shift(@_);
402 # Create the output file name from the input file name
403 my $OutName = GetOutName ($InName);
405 # Current cheap local label prefix is empty
406 my $CheapPrefix = "";
408 # Open a the input file
409 my $FileName = $Files{$InName}; # Includes path if needed
410 open (INPUT, "<$FileName") or Abort ("Cannot open $FileName: $!");
412 # Keep the user happy
413 Gabble ("$FileName => $OutName");
415 # Read and process all lines from the file
416 while ($Line = <INPUT>) {
422 if ($Line =~ /^\s*(([\@?]?)[_a-zA-Z]\w*)\s*(?::=?|=)/) {
424 # Is this a local label?
427 $Id = "$CheapPrefix$1";
431 # Remember the id as new cheap local prefix
436 $Labels{$OutName}{$Id} = GenLabel();
438 # Check for an import statement
439 } elsif ($Line =~ /^\s*\.(?:(?:force)?import|importzp)\s+(.*?)\s*(?:;.*)?$/i) {
441 # Split into a list of identifiers
442 my @Ids = split (/\s*(?::\s*[A-Za-z]+\s*)?,\s*/, $1);
444 # Remove an address-size specifier, from the last identifier,
446 $Ids[$#Ids] =~ s/\s*:\s*[A-Za-z]+//;
449 $Imports{$OutName}{$Id} = GenLabel();
452 # Check for an export statement
453 } elsif ($Line =~ /^\s*\.export(?:zp)?\s+(.*?)\s*(?:;.*)?$/i) {
455 # Split into a list of identifiers
456 my @Ids = split (/\s*(?::\s*[A-Za-z]+\s*)?,\s*/, $1);
458 # Remove an address-size specifier, from the last identifier,
460 $Ids[$#Ids] =~ s/\s*:\s*[A-Za-z]+//;
463 $Exports{$Id} = sprintf ("%s#%s", $OutName, GenLabel());
466 # Check for an actor statement.
467 } elsif ($Line =~ /^\s*\.(?:(?:(?:con|de)struc|interrup)tor|condes)\s+([_a-z]\w*)/i) {
468 $Exports{$1} = sprintf ("%s#%s", $OutName, GenLabel());
470 # Check for a .proc statement
471 } elsif ($Line =~ /^\s*\.proc\s+([_a-z]\w*)/i) {
473 # Remember the ID as the new cheap-local prefix.
475 $Labels{$OutName}{$1} = GenLabel();
479 # Close the input file
485 # Pass1: Read all files for the first time.
488 # Keep the user happy
491 # Walk over the files
492 for my $InName (keys (%Files)) {
500 #-----------------------------------------------------------------------------#
502 # ----------------------------------------------------------------------------#
506 # Process2: Read one file the second time.
519 # Input file is parameter
520 my $InName = shift(@_);
522 # Create the output file name from the input file name
523 my $OutName = GetOutName ($InName);
525 # Current cheap local label prefix is empty
526 my $CheapPrefix = "";
528 # Open a the input file
529 my $FileName = $Files{$InName}; # Includes path if needed
530 open (INPUT, "<$FileName") or Abort ("Cannot open $FileName: $!");
532 # Open the output file and print the HTML header
533 open (OUTPUT, ">$HTMLDir$OutName") or Abort ("Cannot open $OutName: $!");
534 DocHeader (OUTPUT, $InName);
535 print OUTPUT "<pre>\n";
537 # Keep the user happy
538 Gabble ("$FileName => $OutName");
540 # The instructions that will have hyperlinks if a label is used.
541 # And, they will be highlighted when color is used.
542 my $LabelIns = "adc|add|and|asl|bb[rs][0-7]|b[cv][cs]|beq|bge|bit|blt|".
543 "bmi|bne|bpl|br[akl]|bsr|cmp|cop|cp[axy]|dec|eor|inc|jml|".
544 "jmp|jsl|jsr|ld[axy]|lsr|mvn|mvp|ora|pe[air]|rep|".
545 "[rs]mb[0-7]|rol|ror|sbc|sep|st[012axyz]|sub|tai|tam|tdd|".
546 "ti[ain]|tma|trb|tsb|tst";
548 # Instructions that have only the implied-addressing mode -- therefore,
549 # no hyperlinking. They will be highlighted only, when color is used.
550 my $OtherIns = "cl[acdivxy]|csh|csl|de[axy]|in[axy]|nop|ph[abdkpxy]|".
551 "pl[abdpxy]|rt[ils]|sax|say|se[cdit]|stp|swa|sxy|ta[dsxy]|".
552 "tam[0-7]|tcd|tcs|tda|tdc|tma[0-7]|ts[acx]|tx[asy]|tya|tyx|".
555 # Read the input file, replacing references with hyperlinks; and, mark
556 # labels as link targets.
558 LINE: while ($Line = <INPUT>) {
563 # Remove the newline at the end of line. Don't use chomp to be able to
564 # read dos/windows sources on unices.
565 $Line =~ s/[\r\n]*$//;
567 # If requested, convert tabs to spaces
569 # Don't ask me - this is from the perl manual page
570 1 while ($Line =~ s/\t+/' ' x (length($&)*8 - length($`)%8)/e) ;
573 # Clear the output line
576 # If requested, add a html label to each line with a name "linexxx",
577 # so it can be referenced from the outside (this is the same convention
578 # that is used by c2html). If we have line numbers enabled, add them.
579 if ($LineLabels && $LineNumbers) {
580 $OutLine .= sprintf ("<a name=\"line%d\">%6d</a>: ", $LineNo, $LineNo);
581 } elsif ($LineLabels) {
582 $OutLine .= sprintf ("<a name=\"line%d\"></a>", $LineNo);
583 } elsif ($LineNumbers) {
584 $OutLine .= sprintf ("%6d: ", $LineNo);
587 # Cut off a comment from the input line. Beware: We have to check for
588 # strings, since these may contain a semicolon that is no comment
590 ($Line, $Comment) = $Line =~ /^((?:[^"';]+|".*?"|'.*?')*)(.*)$/;
591 if ($Comment =~ /^["']/) {
592 # Line with invalid syntax - there's a string start but
594 Abort (sprintf ("Invalid input at %s(%d)", $FileName, $LineNo));
597 # Remove trailing whitespace and move it together with the comment
598 # into the $Trailer variable.
600 $Trailer = $& . ColorizeComment (Cleanup ($Comment));
602 # Check for a label at the start of the line. If we have one, process
603 # it, and remove it from the line.
604 if ($Line =~ s/^\s*?(([\@?]?)[_a-zA-Z]\w*)(\s*(?::=?|=))//) {
606 # Is this a local label?
609 $Id = "$CheapPrefix$1";
613 # Remember the id as new cheap local prefix
617 # Get the label for the id
618 $Label = $Labels{$OutName}{$Id};
620 # Print the label with a tag
621 $OutLine .= "<a name=\"$Label\">$1</a>$3";
623 # Is the name explicitly assigned a value?
625 # Print all identifiers if there are any.
626 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
627 # Add the non-label stuff.
628 $OutLine .= Cleanup ($1);
630 # Use the prefix if the label is local.
631 # Get the reference to that label if we find it.
632 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
635 # Add a remainder if there is one.
636 $OutLine .= Cleanup ($Line);
638 # The line is complete; print it.
643 # Print any leading whitespace and remove it, so we don't have to
644 # care about whitespace below.
645 if ($Line =~ s/^\s+//) {
649 # Handle the import statements
650 if ($Line =~ s/^\.(?:(?:force)?import|importzp)\s+//i) {
652 # Print any fixed stuff from the line and remove it
655 # Print all identifiers if there are any
656 while ($Line =~ s/^[_a-zA-Z]\w*//) {
658 # Remember the identifier
661 # Variable to assemble HTML representation
664 # Make this import a link target
665 if (exists ($Imports{$OutName}{$Id})) {
666 $Label = $Imports{$OutName}{$Id};
667 $Contents .= sprintf (" name=\"%s\"", $Label);
670 # If we have an export for this import, add a link to this
672 if (exists ($Exports{$Id})) {
673 $Label = $Exports{$Id};
674 $Contents .= sprintf (" href=\"%s\"", $Label);
677 # Add the HTML stuff to the output line
678 if ($Contents ne "") {
679 $OutLine .= sprintf ("<a%s>%s</a>", $Contents, $Id);
684 # Check if another identifier follows
685 if ($Line =~ s/^\s*(?::\s*[A-Za-z]+\s*)?,\s*//) {
692 # Add an remainder if there is one
693 $OutLine .= Cleanup ($Line);
695 # Handle export statements
696 } elsif ($Line =~ s/^\.export(?:zp)?\s+//i) {
698 # Print the command and the whitespace.
701 # Print all identifiers if there are any
702 while ($Line =~ s/^[_a-zA-Z]\w*//) {
704 # Remember the identifier
707 # Variable to assemble HTML representation
710 # If we have a definition for this export in this file, add
711 # a link to the definition.
712 if (exists ($Labels{$OutName}{$Id})) {
713 $Label = $Labels{$OutName}{$Id};
714 $Contents = sprintf (" href=\"#%s\"", $Label);
717 # If we have this identifier in the list of exports, add a
718 # jump target for the export.
719 if (exists ($Exports{$Id})) {
720 $Label = $Exports{$Id};
721 # Be sure to use only the label part
723 $Contents .= sprintf (" name=\"%s\"", $Label);
726 # Add the HTML stuff to the output line
727 if ($Contents ne "") {
728 $OutLine .= sprintf ("<a%s>%s</a>", $Contents, $Id);
733 # Check if another identifier follows
734 if ($Line =~ s/^\s*(?::\s*[A-Za-z]+\s*)?,\s*//) {
741 # Add an remainder if there is one
742 $OutLine .= Cleanup ($Line);
744 # Handle actor statements.
745 } elsif ($Line =~ s/^(\.(?:(?:(?:con|de)struc|interrup)tor|condes)\s+)([_a-z]\w*)//i) {
747 # Print the command and the whitespace.
750 # Remember the identifier.
753 # Variable to assemble HTML representation
756 # If we have a definition for this actor, in this file,
757 # then add a link to that definition.
758 if (exists ($Labels{$OutName}{$Id})) {
759 $Contents = sprintf (" href=\"#%s\"", $Labels{$OutName}{$Id});
762 # Get the target, for linking from imports in other files.
763 $Label = $Exports{$Id};
764 # Be sure to use only the label part.
767 # Add the HTML stuff and the remainder of the actor
768 # to the output line.
769 $OutLine .= sprintf ("<a name=\"%s\"%s>%s</a>%s", $Label,
770 $Contents, $Id, Cleanup ($Line));
772 # Check for .faraddr, .addr, .dword, .word, .dbyt, .byt, .byte, .res,
773 # .elseif, .if, .align, and .org.
774 } elsif ($Line =~ s/^\.(?:(?:far)?addr|d?word|d?byte?|res|(?:else)?if|align|org)\s+//i) {
776 # Print the command and the white space
779 # Print all identifiers if there are any
780 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
781 # Add the non label stuff
782 $OutLine .= Cleanup ($1);
784 # Use the prefix if the label is local.
785 # Get the reference to that label if we find it.
786 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
789 # Add an remainder if there is one
790 $OutLine .= Cleanup ($Line);
793 } elsif ($Line =~ /^(\.proc)(\s+)([_a-z]\w*)?(.*)$/i) {
795 # Do we have an identifier?
797 # Remember the ID as the new cheap-local prefix.
800 # Get the label for the id
801 $Label = $Labels{$OutName}{$3};
803 # Print the label with a tag
804 $OutLine .= "$1$2<a name=\"$Label\">$3</a>";
808 # Print a line that has invalid syntax (its operand isn't
809 # a correctly formed name).
814 $OutLine .= Cleanup ($4);
817 } elsif ($Line =~ /^(\.include)(\s*)\"((?:[^\"]+?|\\\")+)(\".*)$/i) {
819 # Add the fixed stuff to the output line
820 $OutLine .= "$1$2"";
822 # Get the filename into a named variable
823 my $FileName = Cleanup ($3);
825 # Get the name without a path
826 my $Name = StripPath ($3);
828 # If the include file is among the list of our files, add a link,
829 # otherwise just add the name as is.
830 if (exists ($Files{$Name})) {
831 $OutLine .= sprintf ("<a href=\"%s\">%s</a>", GetOutName ($Name), $FileName);
833 $OutLine .= $FileName;
837 $OutLine .= Cleanup ($4);
840 } elsif ($CRefs && $Line =~ s/^\.dbg\s+//) {
842 # Add the fixed stuff to the output line
845 # Check for the type of the .dbg directive
846 if ($Line =~ /^(line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*)$/) {
848 # Add the fixed stuff to the output line
849 $OutLine .= "$1"";
851 # Get the filename and line number into named variables
855 # Remember the remainder
858 # Get the name without a path
859 my $Name = StripPath ($DbgFile);
861 # We don't need FileName any longer as is, so clean it up
862 $DbgFile = Cleanup ($DbgFile);
864 # Add a link to the source file
865 $OutLine .= sprintf ("<a href=\"%s.html#line%d\">%s</a>", $Name, $DbgLine, $DbgFile);
868 $OutLine .= Cleanup ($Line);
870 } elsif ($Line =~ /^(file,\s*)\"((?:[^\"]+?|\\\")+)\"(.*)$/) { #pf FIXME: doesn't handle \" correctly!
872 # Get the filename into a named variables
873 my $DbgFile = Cleanup ($2);
875 # Get the name without a path
876 my $Name = Cleanup (StripPath ($2));
878 # Add the fixed stuff to the output line
879 $OutLine .= sprintf ("%s\"<a href=\"%s.html\">%s</a>\"%s",
880 $1, $Name, $DbgFile, $3);
885 $OutLine .= Cleanup ($Line);
889 } elsif ($CRefs && $Line =~ /^(\.dbg)(\s+line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*$)/) {
891 # Add the fixed stuff to the output line
892 $OutLine .= "$1$2"";
894 # Get the filename and line number into named variables
898 # Remember the remainder
901 # Get the name without a path
902 my $Name = StripPath ($FileName);
904 # We don't need FileName any longer as is, so clean it up
905 $FileName = Cleanup ($FileName);
907 # Add a link to the source file
908 $OutLine .= sprintf ("<a href=\"%s.html#line%d\">%s</a>", $Name, $LineNo, $FileName);
911 $OutLine .= Cleanup ($Line);
913 # Check for .ifdef, .ifndef, .ifref, and .ifnref.
914 } elsif ($Line =~ s/^(\.ifn?[dr]ef\s+)(([\@?]?)[_a-z]\w*)?//i) {
916 # Print the command and the whitespace.
920 # Use the prefix if the label is local.
921 # Get the reference to that label if we find it.
922 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
925 # Add a remainder if there is one.
926 $OutLine .= Cleanup ($Line);
928 # Check for assertions.
929 } elsif ($Line =~ s/^(\.assert\s+)(.+?)(,\s*(?:error|warning)\s*(?:,.*)?)$/$2/i) {
931 # Print the command and the whitespace.
936 # Print all identifiers if there are any.
937 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
938 # Add the non-label stuff.
939 $OutLine .= Cleanup ($1);
941 # Use the prefix if the label is local.
942 # Get the reference to that label if we find it.
943 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
946 # Add a remainder if there is one.
947 $OutLine .= Cleanup ($Line . $Comment);
949 # Check for instructions with labels
950 } elsif ($Line =~ s/^($LabelIns)\b(\s*)//io) {
952 # Print the instruction and white space
953 $OutLine .= ColorizeKeyword ($1) . $2;
955 # Print all identifiers if there are any.
956 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
958 # Add the non-label stuff.
959 $OutLine .= Cleanup ($1);
961 # Is this a local label?
964 $Id = "$CheapPrefix$2";
970 # Get the reference to this label if we find it
971 $OutLine .= RefLabel ($OutName, $Id, $2);
974 # Reassemble and print the line
975 $OutLine .= Cleanup ($Line);
977 # Check for all other instructions
978 } elsif ($Line =~ /^($OtherIns)\b(.*)$/io) {
981 $OutLine .= ColorizeKeyword ($1) . Cleanup ($2);
985 # Nothing known - print the line
986 $OutLine .= Cleanup ($Line);
991 # Colorize all keywords
992 $OutLine =~ s/(?<![\w;])\.[_a-zA-Z]\w*/ColorizeCtrl ($&)/ge;
994 # Print the result with the trailer.
995 print OUTPUT "$OutLine$Trailer\n";
998 # Print the HTML footer
999 print OUTPUT "</pre>\n";
1000 DocFooter (OUTPUT, $OutName);
1009 # Pass2: Read all files the second time.
1012 # Keep the user happy
1015 # Walk over the files
1016 for my $InName (keys (%Files)) {
1024 #-----------------------------------------------------------------------------#
1025 # Create an index page #
1026 # ----------------------------------------------------------------------------#
1030 # Print a list of all files
1036 # Print the file list in a table
1037 print $INDEX "<h2>Files</h2><p>\n";
1038 print $INDEX "<table border=\"0\" width=\"100%\">\n";
1040 for my $File (sort (keys (%Files))) {
1043 if (($Count % $IndexCols) == 0) {
1044 print $INDEX "<tr>\n";
1046 printf $INDEX "<td><a href=\"%s\">%s</a></td>\n", GetOutName ($File), $File;
1047 if (($Count % $IndexCols) == $IndexCols-1) {
1048 print $INDEX "</tr>\n";
1052 if (($Count % $IndexCols) != 0) {
1053 print $INDEX "</tr>\n";
1055 print $INDEX "</table><p><br><p>\n";
1060 # Print a list of all exports
1066 # Print the file list in a table
1067 print $INDEX "<h2>Exports</h2><p>\n";
1068 print $INDEX "<table border=\"0\" width=\"100%\">\n";
1070 for my $Export (sort (keys (%Exports))) {
1075 ($File, $Label) = split (/#/, $Exports{$Export});
1077 # The label is the label of the export statement. If we can find the
1078 # actual label, use this instead.
1079 if (exists ($Labels{$File}{$Export})) {
1080 $Label = $Labels{$File}{$Export};
1084 if (($Count % $IndexCols) == 0) {
1085 print $INDEX "<tr>\n";
1087 printf $INDEX "<td><a href=\"%s#%s\">%s</a></td>\n", $File, $Label, $Export;
1088 if (($Count % $IndexCols) == $IndexCols-1) {
1089 print $INDEX "</tr>\n";
1093 if (($Count % $IndexCols) != 0) {
1094 print $INDEX "</tr>\n";
1096 print $INDEX "</table><p><br><p>\n";
1103 # Open the index page file
1104 open (INDEX, ">$HTMLDir$IndexName") or Abort ("Cannot open $IndexName: $!");
1107 DocHeader (INDEX, $IndexTitle, 0);
1109 # Print the file list in a table
1111 ExportIndex (INDEX);
1113 # Print the document footer
1114 DocFooter (INDEX, $IndexName);
1116 # Close the index file
1122 #-----------------------------------------------------------------------------#
1123 # Print usage information #
1124 # ----------------------------------------------------------------------------#
1129 print "Usage: ca65html [options] file ...\n";
1131 print " --bgcolor c Use background color c instead of $BGColor\n";
1132 print " --colorize Add color highlights to the output\n";
1133 print " --commentcolor c Use color c for comments instead of $CommentColor\n";
1134 print " --crefs Generate references to the C source file(s)\n";
1135 print " --ctrlcolor c Use color c for directives instead of $CtrlColor\n";
1136 print " --cvttabs Convert tabs to spaces in the output\n";
1137 print " --help This text\n";
1138 print " --htmldir dir Specify directory for HTML files\n";
1139 print " --indexcols n Use n columns on index page (default $IndexCols)\n";
1140 print " --indexname file Use file for the index file instead of $IndexName\n";
1141 print " --indexpage Create an index page\n";
1142 print " --indextitle title Use title as the index title instead of $IndexTitle\n";
1143 print " --keywordcolor c Use color c for keywords instead of $KeywordColor\n";
1144 print " --linelabels Generate a linexxx HTML label for each line\n";
1145 print " --linenumbers Add line numbers to the output\n";
1146 print " --linkstyle style Use the given link style\n";
1147 print " --replaceext Replace source extension instead of appending .html\n";
1148 print " --textcolor c Use text color c instead of $TextColor\n";
1149 print " --verbose Be more verbose\n";
1154 #-----------------------------------------------------------------------------#
1156 # ----------------------------------------------------------------------------#
1160 # Get program options
1161 GetOptions ("bgcolor=s" => \$BGColor,
1162 "colorize" => \$Colorize,
1163 "commentcolor=s" => \$CommentColor,
1165 "ctrlcolor=s" => \$CtrlColor,
1166 "cvttabs" => \$CvtTabs,
1167 "debug!" => \$Debug,
1169 "htmldir=s" => \$HTMLDir,
1170 "indexcols=i" => \$IndexCols,
1171 "indexname=s" => \$IndexName,
1172 "indexpage" => \$IndexPage,
1173 "indextitle=s" => \$IndexTitle,
1174 "keywordcolor=s" => \$KeywordColor,
1175 "linelabels" => \$LineLabels,
1176 "linenumbers" => \$LineNumbers,
1177 "linkstyle=i" => \$LinkStyle,
1178 "replaceext" => \$ReplaceExt,
1179 "textcolor=s" => \$TextColor,
1180 "verbose!" => \$Verbose,
1183 # Check some arguments
1184 if ($IndexCols <= 0 || $IndexCols >= 20) {
1185 Abort ("Invalid value for --indexcols option");
1187 if ($HTMLDir ne "" && $HTMLDir =~ /[^\/]$/) {
1188 # Add a trailing path separator
1194 # Print help if requested
1199 # Check if we have input files given
1200 if ($FileCount == 0) {
1201 Abort ("No input files");
1204 # Convert the documents
1208 # Generate an index page if requested