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>) {
566 # If requested, convert tabs to spaces
568 # Don't ask me - this is from the perl manual page
569 1 while ($Line =~ s/\t+/' ' x (length($&)*8 - length($`)%8)/e) ;
572 # Clear the output line
575 # If requested, add a html label to each line with a name "linexxx",
576 # so it can be referenced from the outside (this is the same convention
577 # that is used by c2html). If we have line numbers enabled, add them.
578 if ($LineLabels && $LineNumbers) {
579 $OutLine .= sprintf ("<a name=\"line%d\">%6d</a>: ", $LineNo, $LineNo);
580 } elsif ($LineLabels) {
581 $OutLine .= sprintf ("<a name=\"line%d\"></a>", $LineNo);
582 } elsif ($LineNumbers) {
583 $OutLine .= sprintf ("%6d: ", $LineNo);
586 # Cut off a comment from the input line. Beware: We have to check for
587 # strings, since these may contain a semicolon that is no comment
589 ($Line, $Comment) = $Line =~ /^((?:[^"';]+|".*?"|'.*?')*)(.*)$/;
590 if ($Comment =~ /^["']/) {
591 # Line with invalid syntax - there's a string start but
593 Abort (sprintf ("Invalid input at %s(%d)", $FileName, $LineNo));
596 # Remove trailing whitespace and move it together with the comment
597 # into the $Trailer variable.
599 $Trailer = $& . ColorizeComment (Cleanup ($Comment));
601 # Check for a label at the start of the line. If we have one, process
602 # it, and remove it from the line.
603 if ($Line =~ s/^\s*?(([\@?]?)[_a-zA-Z]\w*)(\s*(?::=?|=))//) {
605 # Is this a local label?
608 $Id = "$CheapPrefix$1";
612 # Remember the id as new cheap local prefix
616 # Get the label for the id
617 $Label = $Labels{$OutName}{$Id};
619 # Print the label with a tag
620 $OutLine .= "<a name=\"$Label\">$1</a>$3";
622 # Is the name explicitly assigned a value?
624 # Print all identifiers if there are any.
625 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
626 # Add the non-label stuff.
627 $OutLine .= Cleanup ($1);
629 # Use the prefix if the label is local.
630 # Get the reference to that label if we find it.
631 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
634 # Add a remainder if there is one.
635 $OutLine .= Cleanup ($Line);
637 # The line is complete; print it.
642 # Print any leading whitespace and remove it, so we don't have to
643 # care about whitespace below.
644 if ($Line =~ s/^\s+//) {
648 # Handle the import statements
649 if ($Line =~ s/^\.(?:(?:force)?import|importzp)\s+//i) {
651 # Print any fixed stuff from the line and remove it
654 # Print all identifiers if there are any
655 while ($Line =~ s/^[_a-zA-Z]\w*//) {
657 # Remember the identifier
660 # Variable to assemble HTML representation
663 # Make this import a link target
664 if (exists ($Imports{$OutName}{$Id})) {
665 $Label = $Imports{$OutName}{$Id};
666 $Contents .= sprintf (" name=\"%s\"", $Label);
669 # If we have an export for this import, add a link to this
671 if (exists ($Exports{$Id})) {
672 $Label = $Exports{$Id};
673 $Contents .= sprintf (" href=\"%s\"", $Label);
676 # Add the HTML stuff to the output line
677 if ($Contents ne "") {
678 $OutLine .= sprintf ("<a%s>%s</a>", $Contents, $Id);
683 # Check if another identifier follows
684 if ($Line =~ s/^\s*(?::\s*[A-Za-z]+\s*)?,\s*//) {
691 # Add an remainder if there is one
692 $OutLine .= Cleanup ($Line);
694 # Handle export statements
695 } elsif ($Line =~ s/^\.export(?:zp)?\s+//i) {
697 # Print the command and the whitespace.
700 # Print all identifiers if there are any
701 while ($Line =~ s/^[_a-zA-Z]\w*//) {
703 # Remember the identifier
706 # Variable to assemble HTML representation
709 # If we have a definition for this export in this file, add
710 # a link to the definition.
711 if (exists ($Labels{$OutName}{$Id})) {
712 $Label = $Labels{$OutName}{$Id};
713 $Contents = sprintf (" href=\"#%s\"", $Label);
716 # If we have this identifier in the list of exports, add a
717 # jump target for the export.
718 if (exists ($Exports{$Id})) {
719 $Label = $Exports{$Id};
720 # Be sure to use only the label part
722 $Contents .= sprintf (" name=\"%s\"", $Label);
725 # Add the HTML stuff to the output line
726 if ($Contents ne "") {
727 $OutLine .= sprintf ("<a%s>%s</a>", $Contents, $Id);
732 # Check if another identifier follows
733 if ($Line =~ s/^\s*(?::\s*[A-Za-z]+\s*)?,\s*//) {
740 # Add an remainder if there is one
741 $OutLine .= Cleanup ($Line);
743 # Handle actor statements.
744 } elsif ($Line =~ s/^(\.(?:(?:(?:con|de)struc|interrup)tor|condes)\s+)([_a-z]\w*)//i) {
746 # Print the command and the whitespace.
749 # Remember the identifier.
752 # Variable to assemble HTML representation
755 # If we have a definition for this actor, in this file,
756 # then add a link to that definition.
757 if (exists ($Labels{$OutName}{$Id})) {
758 $Contents = sprintf (" href=\"#%s\"", $Labels{$OutName}{$Id});
761 # Get the target, for linking from imports in other files.
762 $Label = $Exports{$Id};
763 # Be sure to use only the label part.
766 # Add the HTML stuff and the remainder of the actor
767 # to the output line.
768 $OutLine .= sprintf ("<a name=\"%s\"%s>%s</a>%s", $Label,
769 $Contents, $Id, Cleanup ($Line));
771 # Check for .faraddr, .addr, .dword, .word, .dbyt, .byt, .byte, .res,
772 # .elseif, .if, .align, and .org.
773 } elsif ($Line =~ s/^\.(?:(?:far)?addr|d?word|d?byte?|res|(?:else)?if|align|org)\s+//i) {
775 # Print the command and the white space
778 # Print all identifiers if there are any
779 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
780 # Add the non label stuff
781 $OutLine .= Cleanup ($1);
783 # Use the prefix if the label is local.
784 # Get the reference to that label if we find it.
785 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
788 # Add an remainder if there is one
789 $OutLine .= Cleanup ($Line);
792 } elsif ($Line =~ /^(\.proc)(\s+)([_a-z]\w*)?(.*)$/i) {
794 # Do we have an identifier?
796 # Remember the ID as the new cheap-local prefix.
799 # Get the label for the id
800 $Label = $Labels{$OutName}{$3};
802 # Print the label with a tag
803 $OutLine .= "$1$2<a name=\"$Label\">$3</a>";
807 # Print a line that has invalid syntax (its operand isn't
808 # a correctly formed name).
813 $OutLine .= Cleanup ($4);
816 } elsif ($Line =~ /^(\.include)(\s*)\"((?:[^\"]+?|\\\")+)(\".*)$/i) {
818 # Add the fixed stuff to the output line
819 $OutLine .= "$1$2"";
821 # Get the filename into a named variable
822 my $FileName = Cleanup ($3);
824 # Get the name without a path
825 my $Name = StripPath ($3);
827 # If the include file is among the list of our files, add a link,
828 # otherwise just add the name as is.
829 if (exists ($Files{$Name})) {
830 $OutLine .= sprintf ("<a href=\"%s\">%s</a>", GetOutName ($Name), $FileName);
832 $OutLine .= $FileName;
836 $OutLine .= Cleanup ($4);
839 } elsif ($CRefs && $Line =~ s/^\.dbg\s+//) {
841 # Add the fixed stuff to the output line
844 # Check for the type of the .dbg directive
845 if ($Line =~ /^(line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*)$/) {
847 # Add the fixed stuff to the output line
848 $OutLine .= "$1"";
850 # Get the filename and line number into named variables
854 # Remember the remainder
857 # Get the name without a path
858 my $Name = StripPath ($DbgFile);
860 # We don't need FileName any longer as is, so clean it up
861 $DbgFile = Cleanup ($DbgFile);
863 # Add a link to the source file
864 $OutLine .= sprintf ("<a href=\"%s.html#line%d\">%s</a>", $Name, $DbgLine, $DbgFile);
867 $OutLine .= Cleanup ($Line);
869 } elsif ($Line =~ /^(file,\s*)\"((?:[^\"]+?|\\\")+)\"(.*)$/) { #pf FIXME: doesn't handle \" correctly!
871 # Get the filename into a named variables
872 my $DbgFile = Cleanup ($2);
874 # Get the name without a path
875 my $Name = Cleanup (StripPath ($2));
877 # Add the fixed stuff to the output line
878 $OutLine .= sprintf ("%s\"<a href=\"%s.html\">%s</a>\"%s",
879 $1, $Name, $DbgFile, $3);
884 $OutLine .= Cleanup ($Line);
888 } elsif ($CRefs && $Line =~ /^(\.dbg)(\s+line,\s*)\"((?:[^\"]+?|\\\")+)\"(,\s*)(\d+)(.*$)/) {
890 # Add the fixed stuff to the output line
891 $OutLine .= "$1$2"";
893 # Get the filename and line number into named variables
897 # Remember the remainder
900 # Get the name without a path
901 my $Name = StripPath ($FileName);
903 # We don't need FileName any longer as is, so clean it up
904 $FileName = Cleanup ($FileName);
906 # Add a link to the source file
907 $OutLine .= sprintf ("<a href=\"%s.html#line%d\">%s</a>", $Name, $LineNo, $FileName);
910 $OutLine .= Cleanup ($Line);
912 # Check for .ifdef, .ifndef, .ifref, and .ifnref.
913 } elsif ($Line =~ s/^(\.ifn?[dr]ef\s+)(([\@?]?)[_a-z]\w*)?//i) {
915 # Print the command and the whitespace.
919 # Use the prefix if the label is local.
920 # Get the reference to that label if we find it.
921 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
924 # Add a remainder if there is one.
925 $OutLine .= Cleanup ($Line);
927 # Check for assertions.
928 } elsif ($Line =~ s/^(\.assert\s+)(.+?)(,\s*(?:error|warning)\s*(?:,.*)?)$/$2/i) {
930 # Print the command and the whitespace.
935 # Print all identifiers if there are any.
936 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
937 # Add the non-label stuff.
938 $OutLine .= Cleanup ($1);
940 # Use the prefix if the label is local.
941 # Get the reference to that label if we find it.
942 $OutLine .= RefLabel ($OutName, ($3 ne "") ? "$CheapPrefix$2" : $2, $2);
945 # Add a remainder if there is one.
946 $OutLine .= Cleanup ($Line . $Comment);
948 # Check for instructions with labels
949 } elsif ($Line =~ s/^($LabelIns)\b(\s*)//io) {
951 # Print the instruction and white space
952 $OutLine .= ColorizeKeyword ($1) . $2;
954 # Print all identifiers if there are any.
955 while ($Line =~ s/^([^_a-zA-Z]*?)(([\@?]?)[_a-zA-Z]\w*)//) {
957 # Add the non-label stuff.
958 $OutLine .= Cleanup ($1);
960 # Is this a local label?
963 $Id = "$CheapPrefix$2";
969 # Get the reference to this label if we find it
970 $OutLine .= RefLabel ($OutName, $Id, $2);
973 # Reassemble and print the line
974 $OutLine .= Cleanup ($Line);
976 # Check for all other instructions
977 } elsif ($Line =~ /^($OtherIns)\b(.*)$/io) {
980 $OutLine .= ColorizeKeyword ($1) . Cleanup ($2);
984 # Nothing known - print the line
985 $OutLine .= Cleanup ($Line);
990 # Colorize all keywords
991 $OutLine =~ s/(?<![\w;])\.[_a-zA-Z]\w*/ColorizeCtrl ($&)/ge;
993 # Print the result with the trailer.
994 print OUTPUT "$OutLine$Trailer\n";
997 # Print the HTML footer
998 print OUTPUT "</pre>\n";
999 DocFooter (OUTPUT, $OutName);
1008 # Pass2: Read all files the second time.
1011 # Keep the user happy
1014 # Walk over the files
1015 for my $InName (keys (%Files)) {
1023 #-----------------------------------------------------------------------------#
1024 # Create an index page #
1025 # ----------------------------------------------------------------------------#
1029 # Print a list of all files
1035 # Print the file list in a table
1036 print $INDEX "<h2>Files</h2><p>\n";
1037 print $INDEX "<table border=\"0\" width=\"100%\">\n";
1039 for my $File (sort (keys (%Files))) {
1042 if (($Count % $IndexCols) == 0) {
1043 print $INDEX "<tr>\n";
1045 printf $INDEX "<td><a href=\"%s\">%s</a></td>\n", GetOutName ($File), $File;
1046 if (($Count % $IndexCols) == $IndexCols-1) {
1047 print $INDEX "</tr>\n";
1051 if (($Count % $IndexCols) != 0) {
1052 print $INDEX "</tr>\n";
1054 print $INDEX "</table><p><br><p>\n";
1059 # Print a list of all exports
1065 # Print the file list in a table
1066 print $INDEX "<h2>Exports</h2><p>\n";
1067 print $INDEX "<table border=\"0\" width=\"100%\">\n";
1069 for my $Export (sort (keys (%Exports))) {
1074 ($File, $Label) = split (/#/, $Exports{$Export});
1076 # The label is the label of the export statement. If we can find the
1077 # actual label, use this instead.
1078 if (exists ($Labels{$File}{$Export})) {
1079 $Label = $Labels{$File}{$Export};
1083 if (($Count % $IndexCols) == 0) {
1084 print $INDEX "<tr>\n";
1086 printf $INDEX "<td><a href=\"%s#%s\">%s</a></td>\n", $File, $Label, $Export;
1087 if (($Count % $IndexCols) == $IndexCols-1) {
1088 print $INDEX "</tr>\n";
1092 if (($Count % $IndexCols) != 0) {
1093 print $INDEX "</tr>\n";
1095 print $INDEX "</table><p><br><p>\n";
1102 # Open the index page file
1103 open (INDEX, ">$HTMLDir$IndexName") or Abort ("Cannot open $IndexName: $!");
1106 DocHeader (INDEX, $IndexTitle, 0);
1108 # Print the file list in a table
1110 ExportIndex (INDEX);
1112 # Print the document footer
1113 DocFooter (INDEX, $IndexName);
1115 # Close the index file
1121 #-----------------------------------------------------------------------------#
1122 # Print usage information #
1123 # ----------------------------------------------------------------------------#
1128 print "Usage: ca65html [options] file ...\n";
1130 print " --bgcolor c Use background color c instead of $BGColor\n";
1131 print " --colorize Add color highlights to the output\n";
1132 print " --commentcolor c Use color c for comments instead of $CommentColor\n";
1133 print " --crefs Generate references to the C source file(s)\n";
1134 print " --ctrlcolor c Use color c for directives instead of $CtrlColor\n";
1135 print " --cvttabs Convert tabs to spaces in the output\n";
1136 print " --help This text\n";
1137 print " --htmldir dir Specify directory for HTML files\n";
1138 print " --indexcols n Use n columns on index page (default $IndexCols)\n";
1139 print " --indexname file Use file for the index file instead of $IndexName\n";
1140 print " --indexpage Create an index page\n";
1141 print " --indextitle title Use title as the index title instead of $IndexTitle\n";
1142 print " --keywordcolor c Use color c for keywords instead of $KeywordColor\n";
1143 print " --linelabels Generate a linexxx HTML label for each line\n";
1144 print " --linenumbers Add line numbers to the output\n";
1145 print " --linkstyle style Use the given link style\n";
1146 print " --replaceext Replace source extension instead of appending .html\n";
1147 print " --textcolor c Use text color c instead of $TextColor\n";
1148 print " --verbose Be more verbose\n";
1153 #-----------------------------------------------------------------------------#
1155 # ----------------------------------------------------------------------------#
1159 # Get program options
1160 GetOptions ("bgcolor=s" => \$BGColor,
1161 "colorize" => \$Colorize,
1162 "commentcolor=s" => \$CommentColor,
1164 "ctrlcolor=s" => \$CtrlColor,
1165 "cvttabs" => \$CvtTabs,
1166 "debug!" => \$Debug,
1168 "htmldir=s" => \$HTMLDir,
1169 "indexcols=i" => \$IndexCols,
1170 "indexname=s" => \$IndexName,
1171 "indexpage" => \$IndexPage,
1172 "indextitle=s" => \$IndexTitle,
1173 "keywordcolor=s" => \$KeywordColor,
1174 "linelabels" => \$LineLabels,
1175 "linenumbers" => \$LineNumbers,
1176 "linkstyle=i" => \$LinkStyle,
1177 "replaceext" => \$ReplaceExt,
1178 "textcolor=s" => \$TextColor,
1179 "verbose!" => \$Verbose,
1182 # Check some arguments
1183 if ($IndexCols <= 0 || $IndexCols >= 20) {
1184 Abort ("Invalid value for --indexcols option");
1186 if ($HTMLDir ne "" && $HTMLDir =~ /[^\/]$/) {
1187 # Add a trailing path separator
1193 # Print help if requested
1198 # Check if we have input files given
1199 if ($FileCount == 0) {
1200 Abort ("No input files");
1203 # Convert the documents
1207 # Generate an index page if requested