2 ## --------------------------------------------------------------------------
4 ## Copyright 1996-2017 The NASM Authors - All Rights Reserved
5 ## See the file AUTHORS included with the NASM distribution for
6 ## the specific copyright holders.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted provided that the following
10 ## conditions are met:
12 ## * Redistributions of source code must retain the above copyright
13 ## notice, this list of conditions and the following disclaimer.
14 ## * Redistributions in binary form must reproduce the above
15 ## copyright notice, this list of conditions and the following
16 ## disclaimer in the documentation and/or other materials provided
17 ## with the distribution.
19 ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20 ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21 ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ## --------------------------------------------------------------------------
36 # Read the source-form of the NASM manual and generate the various
41 # Ellipsis support would be nice.
43 # Source-form features:
44 # ---------------------
47 # Bullets the paragraph. Rest of paragraph is indented to cope. In
48 # HTML, consecutive groups of bulleted paragraphs become unordered
52 # produces `_foobar_' in text and italics in HTML, PS, RTF
54 # Inline code \c{foobar}
55 # produces ``foobar'' in text, and fixed-pitch font in HTML, PS, RTF
60 # produces fixed-pitch font where appropriate, and doesn't break
61 # pages except sufficiently far into the middle of a display.
63 # Chapter, header and subheader
64 # \C{intro} Introduction
65 # \H{whatsnasm} What is NASM?
66 # \S{free} NASM Is Free
67 # dealt with as appropriate. Chapters begin on new sides, possibly
68 # even new _pages_. (Sub)?headers are good places to begin new
69 # pages. Just _after_ a (sub)?header isn't.
70 # The keywords can be substituted with \K and \k.
72 # Keyword \K{cintro} \k{cintro}
73 # Expands to `Chapter 1', `Section 1.1', `Section 1.1.1'. \K has an
74 # initial capital whereas \k doesn't. In HTML, will produce
77 # Web link \W{http://foobar/}{text} or \W{mailto:me@here}\c{me@here}
78 # the \W prefix is ignored except in HTML; in HTML the last part
79 # becomes a hyperlink to the first part.
82 # In case it's necessary, they expand to the real versions.
84 # Nonbreaking hyphen \-
88 # Causes everything after it on the line to be ignored by the
89 # source-form processor.
91 # Indexable word \i{foobar} (or \i\e{foobar} or \i\c{foobar}, equally)
92 # makes word appear in index, referenced to that point
93 # \i\c comes up in code style even in the index; \i\e doesn't come
94 # up in emphasised style.
96 # Indexable non-displayed word \I{foobar} or \I\c{foobar}
97 # just as \i{foobar} except that nothing is displayed for it
100 # \IR{foobar} \c{foobar} operator, uses of
101 # tidies up the appearance in the index of something the \i or \I
102 # operator was applied to
105 # \IA{foobar}{bazquux}
106 # aliases one index tag (as might be supplied to \i or \I) to
107 # another, so that \I{foobar} has the effect of \I{bazquux}, and
108 # \i{foobar} has the effect of \I{bazquux}foobar
112 # defines document metadata, such as authorship, title and copyright;
113 # different output formats use this differently.
117 # Includes filename. Recursion is allowed.
123 $out_path = File
::Spec
->curdir();
125 while ($ARGV[0] =~ /^-/) {
126 my $opt = shift @ARGV;
129 } elsif ($opt =~ /^\-[Ii](.*)$/) {
130 push(@include_path, $1);
131 } elsif ($opt =~ /^\-[Oo](.*)$/) {
136 $out_format = shift(@ARGV);
138 @files = ('-') unless(scalar(@files));
142 $tstruct_previtem = $node = "Top";
144 $tstruct_level{$tstruct_previtem} = 0;
145 $tstruct_last[$tstruct_level{$tstruct_previtem}] = $tstruct_previtem;
146 $MAXLEVEL = 10; # really 3, but play safe ;-)
148 # Read the file; pass a paragraph at a time to the paragraph processor.
149 print "Reading input...";
150 $pname = "para000000";
151 @pnames = @pflags = ();
153 foreach $file (@files) {
159 # Now we've read in the entire document and we know what all the
160 # heading keywords refer to. Go through and fix up the \k references.
161 print "Fixing up cross-references...";
165 # Sort the index tags, according to the slightly odd order I've decided on.
166 print "Sorting index tags...";
170 # Make output directory if necessary
174 print "Writing index-diagnostic file...";
179 # OK. Write out the various output files.
180 if ($out_format eq 'txt') {
181 print "Producing text output: ";
184 } elsif ($out_format eq 'html') {
185 print "Producing HTML output: ";
188 } elsif ($out_format eq 'texi') {
189 print "Producing Texinfo output: ";
192 } elsif ($out_format eq 'hlp') {
193 print "Producing WinHelp output: ";
196 } elsif ($out_format eq 'dip') {
197 print "Producing Documentation Intermediate Paragraphs: ";
201 die "$0: unknown output format: $out_format\n";
210 for ($i = 0; $i < length($s); $i++) {
211 $c = substr($s, $i, 1);
235 if (!/\S/ || /^\\(IA|IR|M)/) { # special case: \IA \IR \M imply new-paragraph
240 s/\\#.*$//; # strip comments
249 open($F, '<-'); # stdin
252 foreach my $idir ( File
::Spec
->curdir, @include_path ) {
253 my $fpath = File
::Spec
->catfile($idir, $name);
254 if (open($F, '<', $fpath)) {
259 die "Cannot open $name: $!\n" unless ($found);
261 while (defined($_ = <$F>)) {
268 my $pflags = "", $i, $w, $l, $t;
273 # Strip off _leading_ spaces, then determine type of paragraph.
277 # A code paragraph. The paragraph-array will contain the simple
278 # strings which form each line of the paragraph.
280 while (/^\\c (([^\\]|\\[^c])*)(.*)$/) {
288 $_ = ''; # suppress word-by-word code
290 # A chapter heading. Define the keyword and allocate a chapter
295 $xref = "chapter-$cnum";
296 $pflags = "chap $cnum :$xref";
297 die "badly formatted chapter heading: $_\n" if !/^\\C\{([^\}]*)\}\s*(.*)$/;
298 $refs{$1} = "chapter $cnum";
299 $node = "Chapter $cnum";
301 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
304 # the standard word-by-word code will happen next
306 # An appendix heading. Define the keyword and allocate an appendix
309 $cnum = 'A' if $cnum =~ /[0-9]+/;
312 $xref = "appendix-$cnum";
313 $pflags = "appn $cnum :$xref";
314 die "badly formatted appendix heading: $_\n" if !/^\\A\{([^\}]*)}\s*(.*)$/;
315 $refs{$1} = "appendix $cnum";
316 $node = "Appendix $cnum";
318 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
321 # the standard word-by-word code will happen next
323 # A major heading. Define the keyword and allocate a section number.
326 $xref = "section-$cnum.$hnum";
327 $pflags = "head $cnum.$hnum :$xref";
328 die "badly formatted heading: $_\n" if !/^\\[HP]{([^\}]*)}\s*(.*)$/;
329 $refs{$1} = "section $cnum.$hnum";
330 $node = "Section $cnum.$hnum";
332 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
335 # the standard word-by-word code will happen next
337 # A sub-heading. Define the keyword and allocate a section number.
339 $xref = "section-$cnum.$hnum.$snum";
340 $pflags = "subh $cnum.$hnum.$snum :$xref";
341 die "badly formatted subheading: $_\n" if !/^\\S\{([^\}]*)\}\s*(.*)$/;
342 $refs{$1} = "section $cnum.$hnum.$snum";
343 $node = "Section $cnum.$hnum.$snum";
345 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
348 # the standard word-by-word code will happen next
351 die "badly formatted index rewrite: $_\n" if !/^\\IR\{([^\}]*)\}\s*(.*)$/;
354 # the standard word-by-word code will happen next
357 die "badly formatted index alias: $_\n" if !/^\\IA\{([^\}]*)}\{([^\}]*)\}\s*$/;
359 return; # avoid word-by-word code
362 die "badly formed metadata: $_\n" if !/^\\M\{([^\}]*)}\{([^\}]*)\}\s*$/;
364 return; # avoid word-by-word code
366 # A bulleted paragraph. Strip off the initial \b and let the
367 # word-by-word code take care of the rest.
371 # A normal paragraph. Just set $pflags: the word-by-word code does
376 # The word-by-word code: unless @$pname is already defined (which it
377 # will be in the case of a code paragraph), split the paragraph up
378 # into words and push each on @$pname.
380 # Each thing pushed on @$pname should have a two-character type
381 # code followed by the text.
386 # "es" for first emphasised word in emphasised bit
387 # "e " for emphasised in mid-emphasised-bit
388 # "ee" for last emphasised word in emphasised bit
389 # "eo" for single (only) emphasised word
392 # "kK" for capitalised cross-ref
394 # "wc" for code-type Web link
395 # "x " for beginning of resolved cross-ref; generates no visible output,
396 # and the text is the cross-reference code
397 # "xe" for end of resolved cross-ref; text is same as for "x ".
398 # "i " for point to be indexed: the text is the internal index into the
402 s/^\s*//, push @
$pname, "sp" if /^\s/;
403 $indexing = $qindex = 0;
404 if (/^(\\[iI])?\\c/) {
405 $qindex = 1 if $1 eq "\\I";
406 $indexing = 1, s/^\\[iI]// if $1;
408 die "badly formatted \\c: \\c$_\n" if !/\{(([^\\}]|\\.)*)\}(.*)$/;
415 (push @
$pname,"i"),$lastp = $#$pname if $indexing;
416 push @
$pname,"c $w" if !$qindex;
417 $$pname[$lastp] = &addidx
($node, $w, "c $w") if $indexing;
418 } elsif (/^\\[iIe]/) {
421 $qindex = 1 if $1 eq "\\I";
422 $indexing = 1, $type = "\\i" if $1;
423 $emph = 1, $type = "\\e" if $2;
424 s/^(\\[iI])?(\\e?)//;
425 die "badly formatted $type: $type$_\n" if !/\{(([^\\}]|\\.)*)\}(.*)$/;
432 $t = $emph ?
"es" : "n ";
434 (push @
$pname,"i"),$lastp = $#$pname if $indexing;
435 foreach $i (split /\s+/,$w) { # \e and \i can be multiple words
436 push @
$pname,"$t$i","sp" if !$qindex;
437 ($ii=$i) =~ tr/A-Z/a-z/, push @ientry,"n $ii","sp" if $indexing;
438 $t = $emph ?
"e " : "n ";
440 $w =~ tr/A-Z/a-z/, pop @ientry if $indexing;
441 $$pname[$lastp] = &addidx
($node, $w, @ientry) if $indexing;
442 pop @
$pname if !$qindex; # remove final space
443 if (substr($$pname[$#$pname],0,2) eq "es" && !$qindex) {
444 substr($$pname[$#$pname],0,2) = "eo";
445 } elsif ($emph && !$qindex) {
446 substr($$pname[$#$pname],0,2) = "ee";
448 } elsif (/^\\[kK]/) {
452 die "badly formatted \\k: \\k$_\n" if !/\{([^\}]*)\}(.*)$/;
457 die "badly formatted \\W: \\W$_\n"
458 if !/\{([^\}]*)\}(\\i)?(\\c)?\{(([^\\}]|\\.)*)\}(.*)$/;
463 $t = "wc" if $3 eq "\\c";
469 (push @
$pname,"i"),$lastp = $#$pname if $indexing;
470 push @
$pname,"$t<$l>$w";
471 $$pname[$lastp] = &addidx
($node, $w, "c $w") if $indexing;
473 die "what the hell? $_\n" if !/^(([^\s\\\-]|\\[\\{}\-])*-?)(.*)$/;
474 die "painful death! $_\n" if !length $1;
488 if ($irewrite ne undef) {
489 &addidx
(undef, $irewrite, @
$pname);
492 push @pnames, $pname;
493 push @pflags, $pflags;
499 my ($node, $text, @ientry) = @_;
500 $text = $idxalias{$text} || $text;
501 if ($node eq undef || !$idxmap{$text}) {
503 $idxmap{$text} = $ientry;
507 $idxnodes{$node,$text} = 1;
513 my $iitem, $ientry, $i, $piitem, $pcval, $cval, $clrcval;
515 @itags = map { # get back the original data as the 1st elt of each list
517 } sort { # compare auxiliary (non-first) elements of lists
518 $a->[1] cmp $b->[1] ||
519 $a->[2] cmp $b->[2] ||
521 } map { # transform array into list of 3-element lists
522 my $ientry = $idxmap{$_};
523 my $a = substr($$ientry[0],2);
524 $a =~ tr/A-Za-z0-9//cd;
525 [$_, uc($a), substr($$ientry[0],0,2)]
528 # Having done that, check for comma-hood.
530 foreach $iitem (@itags) {
531 $ientry = $idxmap{$iitem};
534 FL
:for ($i=0; $i <= $#$ientry; $i++) {
535 if ($$ientry[$i] =~ /^(n .*,)(.*)/) {
537 splice @
$ientry,$i+1,0,"n $2" if length $2;
538 $commapos{$iitem} = $i+1;
539 $cval = join("\002", @
$ientry[0..$i]);
544 $cval = undef if $clrcval;
545 $commanext{$iitem} = $commaafter{$piitem} = 1
546 if $cval and ($cval eq $pcval);
552 my $iitem,$ientry,$w,$ww,$foo,$node;
553 open INDEXDIAG
, '>', File
::Spec
->catfile($out_path, 'index.diag');
554 foreach $iitem (@itags) {
555 $ientry = $idxmap{$iitem};
556 print INDEXDIAG
"<$iitem> ";
557 foreach $w (@
$ientry) {
559 print INDEXDIAG
$ww unless $ww eq "\001";
563 foreach $node (@nodes) {
564 (print INDEXDIAG
$foo,$node), $foo = ", " if $idxnodes{$node,$iitem};
566 print INDEXDIAG
"\n";
572 my $pname, $p, $i, $j, $k, $caps, @repl;
574 for ($p=0; $p<=$#pnames; $p++) {
575 next if $pflags[$p] eq "code";
576 $pname = $pnames[$p];
577 for ($i=$#$pname; $i >= 0; $i--) {
578 if ($$pname[$i] =~ /^k/) {
580 $caps = ($k =~ /^kK/);
583 die "undefined keyword `$k'\n" unless $repl;
584 substr($repl,0,1) =~ tr/a-z/A-Z/ if $caps;
586 push @repl,"x $xrefs{$k}";
587 foreach $j (split /\s+/,$repl) {
591 pop @repl; # remove final space
592 push @repl,"xe$xrefs{$k}";
593 splice @
$pname,$i,1,@repl;
600 # This is called from the top level, so I won't bother using
604 print "writing file...";
605 open TEXT
, '>', File
::Spec
->catfile($out_path, 'nasmdoc.txt');
609 $title = "The Netwide Assembler: NASM";
610 $spaces = ' ' x
((75-(length $title))/2);
611 ($underscore = $title) =~ s/./=/g;
612 print "$spaces$title\n$spaces$underscore\n";
614 for ($para = 0; $para <= $#pnames; $para++) {
615 $pname = $pnames[$para];
616 $pflags = $pflags[$para];
617 $ptype = substr($pflags,0,4);
619 print "\n"; # always one of these before a new paragraph
621 if ($ptype eq "chap") {
622 # Chapter heading. "Chapter N: Title" followed by a line of
624 $pflags =~ /chap (.*) :(.*)/;
625 $title = "Chapter $1: ";
626 foreach $i (@
$pname) {
628 $title .= $ww unless $ww eq "\001";
633 } elsif ($ptype eq "appn") {
634 # Appendix heading. "Appendix N: Title" followed by a line of
636 $pflags =~ /appn (.*) :(.*)/;
637 $title = "Appendix $1: ";
638 foreach $i (@
$pname) {
640 $title .= $ww unless $ww eq "\001";
645 } elsif ($ptype eq "head" || $ptype eq "subh") {
646 # Heading or subheading. Just a number and some text.
647 $pflags =~ /.... (.*) :(.*)/;
648 $title = sprintf "%6s ", $1;
649 foreach $i (@
$pname) {
651 $title .= $ww unless $ww eq "\001";
654 } elsif ($ptype eq "code") {
655 # Code paragraph. Emit each line with a seven character indent.
656 foreach $i (@
$pname) {
657 warn "code line longer than 68 chars: $i\n" if length $i > 68;
658 print ' 'x7
, $i, "\n";
660 } elsif ($ptype eq "bull" || $ptype eq "norm") {
661 # Ordinary paragraph, optionally bulleted. We wrap, with ragged
662 # 75-char right margin and either 7 or 11 char left margin
663 # depending on bullets.
664 if ($ptype eq "bull") {
665 $line = ' 'x7
. '(*) ';
668 $line = $next = ' 'x7
;
673 do { $w = &word_txt
(shift @a) } while $w eq "\001"; # nasty hack
675 if ($wprev =~ /-$/ || $w eq ' ' || $w eq '' || $w eq undef) {
676 if (length ($line . $wd) > 75) {
677 $line =~ s/\s*$//; # trim trailing spaces
680 $wd =~ s/^\s*//; # trim leading spaces
686 } while ($w ne '' && $w ne undef);
688 $line =~ s/\s*$//; # trim trailing spaces
703 return undef if $w eq '' || $w eq undef;
704 $wtype = substr($w,0,2);
705 $wmajt = substr($wtype,0,1);
707 $w =~ s/<.*>// if $wmajt eq "w"; # remove web links
708 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
710 } elsif ($wtype eq "sp") {
712 } elsif ($wtype eq "da") {
714 } elsif ($wmajt eq "c" || $wtype eq "wc") {
716 } elsif ($wtype eq "es") {
718 } elsif ($wtype eq "ee") {
720 } elsif ($wtype eq "eo") {
722 } elsif ($wmajt eq "x" || $wmajt eq "i") {
725 die "panic in word_txt: $wtype$w\n";
730 # This is called from the top level, so I won't bother using
733 # Write contents file. Just the preamble, then a menu of links to the
734 # separate chapter files and the nodes therein.
735 print "writing contents file...";
736 open TEXT
, '>', File
::Spec
->catfile($out_path, 'nasmdoc0.html');
739 print "<p>This manual documents NASM, the Netwide Assembler: an assembler\n";
740 print "targetting the Intel x86 series of processors, with portable source.\n";
742 for ($node = $tstruct_next{'Top'}; $node; $node = $tstruct_next{$node}) {
743 if ($tstruct_level{$node} == 1) {
744 # Invent a file name.
745 ($number = lc($xrefnodes{$node})) =~ s/.*-//;
746 $fname="nasmdocx.html";
747 substr($fname,8 - length $number, length $number) = $number;
748 $html_fnames{$node} = $fname;
752 # Use the preceding filename plus a marker point.
753 $link = $fname . "#$xrefnodes{$node}";
756 $pname = $tstruct_pname{$node};
757 foreach $i (@
$pname) {
758 $ww = &word_html
($i);
759 $title .= $ww unless $ww eq "\001";
761 print "<a href=\"$link\">$title</a><br>\n";
763 print "<p><a href=\"nasmdoci.html\">Index</a>\n";
764 print "</body></html>\n";
768 # Open a null file, to ensure output (eg random &html_jumppoints calls)
770 print "writing chapter files...";
771 open TEXT
, '>', File
::Spec
->devnull();
777 for ($para = 0; $para <= $#pnames; $para++) {
778 $pname = $pnames[$para];
779 $pflags = $pflags[$para];
780 $ptype = substr($pflags,0,4);
782 $in_list = 0, print "</ul>\n" if $in_list && $ptype ne "bull";
783 if ($ptype eq "chap") {
784 # Chapter heading. Begin a new file.
785 $pflags =~ /chap (.*) :(.*)/;
786 $title = "Chapter $1: ";
788 &html_jumppoints
; print "</body></html>\n"; select STDOUT
; close TEXT
;
789 $html_lastf = $html_fnames{$chapternode};
790 $chapternode = $nodexrefs{$xref};
791 $html_nextf = $html_fnames{$tstruct_mnext{$chapternode}};
792 open(TEXT
, '>', File
::Spec
->catfile($out_path, $html_fnames{$chapternode}));
795 foreach $i (@
$pname) {
796 $ww = &word_html
($i);
797 $title .= $ww unless $ww eq "\001";
799 $h = "<h2><a name=\"$xref\">$title</a></h2>\n";
800 print $h; print FULL
$h;
801 } elsif ($ptype eq "appn") {
802 # Appendix heading. Begin a new file.
803 $pflags =~ /appn (.*) :(.*)/;
804 $title = "Appendix $1: ";
806 &html_jumppoints
; print "</body></html>\n"; select STDOUT
; close TEXT
;
807 $html_lastf = $html_fnames{$chapternode};
808 $chapternode = $nodexrefs{$xref};
809 $html_nextf = $html_fnames{$tstruct_mnext{$chapternode}};
810 open(TEXT
, '>', File
::Spec
->catfile($out_path, $html_fnames{$chapternode}));
813 foreach $i (@
$pname) {
814 $ww = &word_html
($i);
815 $title .= $ww unless $ww eq "\001";
817 print "<h2><a name=\"$xref\">$title</a></h2>\n";
818 } elsif ($ptype eq "head" || $ptype eq "subh") {
819 # Heading or subheading.
820 $pflags =~ /.... (.*) :(.*)/;
821 $hdr = ($ptype eq "subh" ?
"h4" : "h3");
824 foreach $i (@
$pname) {
825 $ww = &word_html
($i);
826 $title .= $ww unless $ww eq "\001";
828 print "<$hdr><a name=\"$xref\">$title</a></$hdr>\n";
829 } elsif ($ptype eq "code") {
832 foreach $i (@
$pname) {
840 } elsif ($ptype eq "bull" || $ptype eq "norm") {
841 # Ordinary paragraph, optionally bulleted. We wrap, with ragged
842 # 75-char right margin and either 7 or 11 char left margin
843 # depending on bullets.
844 if ($ptype eq "bull") {
845 $in_list = 1, print "<ul>\n" unless $in_list;
853 do { $w = &word_html
(shift @a) } while $w eq "\001"; # nasty hack
855 if ($w eq ' ' || $w eq '' || $w eq undef) {
856 if (length ($line . $wd) > 75) {
857 $line =~ s/\s*$//; # trim trailing spaces
860 $wd =~ s/^\s*//; # trim leading spaces
866 } while ($w ne '' && $w ne undef);
868 $line =~ s/\s*$//; # trim trailing spaces
874 # Close whichever file was open.
876 print "</body></html>\n";
880 print "\n writing index file...";
881 open TEXT
, '>', File
::Spec
->catfile($out_path, 'nasmdoci.html');
884 print "<p align=center><a href=\"nasmdoc0.html\">Contents</a>\n";
887 print "<p align=center><a href=\"nasmdoc0.html\">Contents</a>\n";
888 print "</body></html>\n";
894 print "<html><head><title>NASM Manual</title></head>\n";
895 print "<body><h1 align=center>The Netwide Assembler: NASM</h1>\n\n";
896 &html_jumppoints
if $_[0];
899 sub html_jumppoints
{
900 print "<p align=center>";
901 print "<a href=\"$html_nextf\">Next Chapter</a> |\n" if $html_nextf;
902 print "<a href=\"$html_lastf\">Previous Chapter</a> |\n" if $html_lastf;
903 print "<a href=\"nasmdoc0.html\">Contents</a> |\n";
904 print "<a href=\"nasmdoci.html\">Index</a>\n";
908 my $itag, $a, @ientry, $sep, $w, $wd, $wprev, $line;
911 foreach $itag (@itags) {
912 $ientry = $idxmap{$itag};
916 foreach $node (@nodes) {
917 next if !$idxnodes{$node,$itag};
918 push @a, "n ," if $sep;
919 push @a, "sp", "x $xrefnodes{$node}", "n $node", "xe$xrefnodes{$node}";
924 do { $w = &word_html
(shift @a) } while $w eq "\001"; # nasty hack
926 if ($w eq ' ' || $w eq '' || $w eq undef) {
927 if (length ($line . $wd) > 75) {
928 $line =~ s/\s*$//; # trim trailing spaces
931 $wd =~ s/^\s*//; # trim leading spaces
937 } while ($w ne '' && $w ne undef);
939 $line =~ s/\s*$//; # trim trailing spaces
948 my $wtype, $wmajt, $pfx, $sfx;
950 return undef if $w eq '' || $w eq undef;
952 $wtype = substr($w,0,2);
953 $wmajt = substr($wtype,0,1);
956 $pfx = "<a href=\"$1\">", $sfx = "</a>", $w = $2
957 if $wmajt eq "w" && $w =~ /^<(.*)>(.*)$/;
961 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
962 return $pfx . $w . $sfx;
963 } elsif ($wtype eq "sp") {
965 } elsif ($wtype eq "da") {
966 return '-'; # sadly, en-dashes are non-standard in HTML
967 } elsif ($wmajt eq "c" || $wtype eq "wc") {
968 return $pfx . "<code><nobr>${w}</nobr></code>" . $sfx;
969 } elsif ($wtype eq "es") {
971 } elsif ($wtype eq "ee") {
973 } elsif ($wtype eq "eo") {
974 return "<em>${w}</em>";
975 } elsif ($wtype eq "x ") {
976 # Magic: we must resolve the cross reference into file and marker
977 # parts, then dispose of the file part if it's us, and dispose of
978 # the marker part if the cross reference describes the top node of
980 my $node = $nodexrefs{$w}; # find the node we're aiming at
981 my $level = $tstruct_level{$node}; # and its level
982 my $up = $node, $uplev = $level-1;
983 $up = $tstruct_up{$up} while $uplev--; # get top node of containing file
984 my $file = ($up ne $chapternode) ?
$html_fnames{$up} : "";
985 my $marker = ($level == 1 and $file) ?
"" : "#$w";
986 return "<a href=\"$file$marker\">";
987 } elsif ($wtype eq "xe") {
989 } elsif ($wmajt eq "i") {
992 die "panic in word_html: $wtype$w\n";
997 # This is called from the top level, so I won't bother using
1001 print "writing file...";
1002 open TEXT
,'>', File
::Spec
->catfile($out_path, 'nasmdoc.texi');
1006 print "\\input texinfo \@c -*-texinfo-*-\n";
1007 print "\@c \%**start of header\n";
1008 print "\@setfilename ",$metadata{'infofile'},".info\n";
1009 print "\@dircategory ",$metadata{'category'},"\n";
1010 print "\@direntry\n";
1011 printf "* %-28s %s.\n",
1012 sprintf('%s: (%s).', $metadata{'infoname'}, $metadata{'infofile'}),
1013 $metadata{'infotitle'};
1014 print "\@end direntry\n";
1015 print "\@settitle ", $metadata{'title'},"\n";
1016 print "\@setchapternewpage odd\n";
1017 print "\@c \%**end of header\n";
1020 print $metadata{'summary'}, "\n";
1022 print "Copyright ",$metadata{'year'}," ",$metadata{'author'},"\n";
1024 print $metadata{'license'}, "\n";
1025 print "\@end ifinfo\n";
1027 print "\@titlepage\n";
1028 $title = $metadata{'title'};
1029 $title =~ s/ - / --- /g;
1030 print "\@title ${title}\n";
1031 print "\@author ",$metadata{'author'},"\n";
1034 print "\@vskip 0pt plus 1filll\n";
1035 print "Copyright \@copyright{} ",$metadata{'year'},' ',$metadata{'author'},"\n";
1037 print $metadata{'license'}, "\n";
1038 print "\@end titlepage\n";
1040 print "\@node Top, $tstruct_next{'Top'}, (dir), (dir)\n";
1041 print "\@top ",$metadata{'infotitle'},"\n";
1044 print $metadata{'summary'}, "\n";
1045 print "\@end ifinfo\n";
1050 for ($para = 0; $para <= $#pnames; $para++) {
1051 $pname = $pnames[$para];
1052 $pflags = $pflags[$para];
1053 $ptype = substr($pflags,0,4);
1055 $bulleting = 0, print "\@end itemize\n" if $bulleting && $ptype ne "bull";
1056 print "\n"; # always one of these before a new paragraph
1058 if ($ptype eq "chap") {
1059 # Chapter heading. Begin a new node.
1061 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1062 $pflags =~ /chap (.*) :(.*)/;
1063 $node = "Chapter $1";
1064 $title = "Chapter $1: ";
1065 foreach $i (@
$pname) {
1066 $ww = &word_texi
($i);
1067 $title .= $ww unless $ww eq "\001";
1069 print "\@node $node, $tstruct_next{$node}, $tstruct_prev{$node},";
1070 print " $tstruct_up{$node}\n\@unnumbered $title\n";
1071 } elsif ($ptype eq "appn") {
1072 # Appendix heading. Begin a new node.
1074 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1075 $pflags =~ /appn (.*) :(.*)/;
1076 $node = "Appendix $1";
1077 $title = "Appendix $1: ";
1078 foreach $i (@
$pname) {
1079 $ww = &word_texi
($i);
1080 $title .= $ww unless $ww eq "\001";
1082 print "\@node $node, $tstruct_next{$node}, $tstruct_prev{$node},";
1083 print " $tstruct_up{$node}\n\@unnumbered $title\n";
1084 } elsif ($ptype eq "head" || $ptype eq "subh") {
1085 # Heading or subheading. Begin a new node.
1087 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1088 $pflags =~ /.... (.*) :(.*)/;
1089 $node = "Section $1";
1091 foreach $i (@
$pname) {
1092 $ww = &word_texi
($i);
1093 $title .= $ww unless $ww eq "\001";
1095 print "\@node $node, $tstruct_next{$node}, $tstruct_prev{$node},";
1096 print " $tstruct_up{$node}\n";
1097 $hdr = ($ptype eq "subh" ?
"\@unnumberedsubsec" : "\@unnumberedsec");
1098 print "$hdr $title\n";
1099 } elsif ($ptype eq "code") {
1100 # Code paragraph. Surround with @example / @end example.
1101 print "\@example\n";
1102 foreach $i (@
$pname) {
1103 warn "code line longer than 68 chars: $i\n" if length $i > 68;
1109 print "\@end example\n";
1110 } elsif ($ptype eq "bull" || $ptype eq "norm") {
1111 # Ordinary paragraph, optionally bulleted. We wrap, FWIW.
1112 if ($ptype eq "bull") {
1113 $bulleting = 1, print "\@itemize \@bullet\n" if !$bulleting;
1120 do { $w = &word_texi
(shift @a); } while $w eq "\001"; # hack
1122 if ($wprev =~ /-$/ || $w eq ' ' || $w eq '' || $w eq undef) {
1123 if (length ($line . $wd) > 75) {
1124 $line =~ s/\s*$//; # trim trailing spaces
1127 $wd =~ s/^\s*//; # trim leading spaces
1133 } while ($w ne '' && $w ne undef);
1134 if ($line =~ /\S/) {
1135 $line =~ s/\s*$//; # trim trailing spaces
1145 print "\n\@contents\n\@bye\n";
1150 # Side effect of this procedure: update global `texiwdlen' to be the length
1151 # in chars of the formatted version of the word.
1156 return undef if $w eq '' || $w eq undef;
1157 $wtype = substr($w,0,2);
1158 $wmajt = substr($wtype,0,1);
1164 $w =~ s/<.*>// if $wmajt eq "w"; # remove web links
1165 substr($w,0,1) =~ tr/a-z/A-Z/, $capital = 0 if $capital;
1166 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
1169 } elsif ($wtype eq "sp") {
1172 } elsif ($wtype eq "da") {
1175 } elsif ($wmajt eq "c" || $wtype eq "wc") {
1176 $texiwdlen = 2 + $wlen;
1177 return "\@code\{$w\}";
1178 } elsif ($wtype eq "es") {
1179 $texiwdlen = 1 + $wlen;
1180 return "\@emph\{${w}";
1181 } elsif ($wtype eq "ee") {
1182 $texiwdlen = 1 + $wlen;
1184 } elsif ($wtype eq "eo") {
1185 $texiwdlen = 2 + $wlen;
1186 return "\@emph\{${w}\}";
1187 } elsif ($wtype eq "x ") {
1188 $texiwdlen = 0; # we don't need it in this case
1189 $capital = 1; # hack
1191 } elsif ($wtype eq "xe") {
1192 $texiwdlen = 0; # we don't need it in this case
1194 } elsif ($wmajt eq "i") {
1195 $texiwdlen = 0; # we don't need it in this case
1198 die "panic in word_texi: $wtype$w\n";
1204 my $item, $i, $mpname, $title, $wd;
1206 $item = $tstruct_next{$topitem};
1210 $mpname = $tstruct_pname{$item};
1211 foreach $i (@
$mpname) {
1212 $wd = &word_texi
($i);
1213 $title .= $wd unless $wd eq "\001";
1215 print "* ${item}:: $title\n";
1216 $item = $tstruct_mnext{$item};
1218 print "* Index::\n" if $topitem eq "Top";
1219 print "\@end menu\n";
1223 my $itag, $ientry, @a, $wd, $item, $len;
1224 my $subnums = "123456789ABCDEFGHIJKLMNOPQRSTU" .
1225 "VWXYZabcdefghijklmnopqrstuvwxyz";
1227 print "\@ifinfo\n\@node Index, , $FIXMElastnode, Top\n";
1228 print "\@unnumbered Index\n\n\@menu\n";
1230 foreach $itag (@itags) {
1231 $ientry = $idxmap{$itag};
1236 $wd = &word_texi
($i);
1237 $item .= $wd, $len += $texiwdlen unless $wd eq "\001";
1240 foreach $node (@nodes) {
1241 next if !$idxnodes{$node,$itag};
1242 printf "* %s%s (%s): %s.\n",
1243 $item, " " x
(40-$len), substr($subnums,$i++,1), $node;
1246 print "\@end menu\n\@end ifinfo\n";
1250 # This is called from the top level, so I won't bother using
1253 # Build the index-tag text forms.
1254 print "building index entries...";
1257 my $ientry = $idxmap{$_};
1259 foreach $i (@
$ientry) {
1260 $ww = &word_hlp
($i,0);
1261 $title .= $ww unless $ww eq "\001";
1266 # Write the HPJ project-description file.
1267 print "writing .hpj file...";
1268 open HPJ
, '>', File
::Spec
->catfile($out_path, 'nasmdoc.hpj');
1269 print HPJ
"[OPTIONS]\ncompress=true\n";
1270 print HPJ
"title=NASM: The Netwide Assembler\noldkeyphrase=no\n\n";
1271 print HPJ
"[FILES]\nnasmdoc.rtf\n\n";
1272 print HPJ
"[CONFIG]\n";
1273 print HPJ
'CreateButton("btn_up", "&Up",'.
1274 ' "JumpContents(`nasmdoc.hlp'."'".')")';
1275 print HPJ
"\nBrowseButtons()\n";
1279 print "\n writing .rtf file...";
1280 open TEXT
,'>', File
::Spec
->catfile($out_path, 'nasmdoc.rtf');
1284 print "{\\rtf1\\ansi{\\fonttbl\n";
1285 print "\\f0\\froman Times New Roman;\\f1\\fmodern Courier New;\n";
1286 print "\\f2\\fswiss Arial;\\f3\\ftech Wingdings}\\deff0\n";
1287 print "#{\\footnote Top}\n";
1288 print "\${\\footnote Contents}\n";
1289 print "+{\\footnote browse:00000}\n";
1290 print "!{\\footnote DisableButton(\"btn_up\")}\n";
1291 print "\\keepn\\f2\\b\\fs30\\sb0\n";
1292 print "NASM: The Netwide Assembler\n";
1293 print "\\par\\pard\\plain\\sb120\n";
1294 print "This file documents NASM, the Netwide Assembler: an assembler \n";
1295 print "targetting the Intel x86 series of processors, with portable source.\n";
1300 $newpar = "\\par\\sb120\n";
1301 for ($para = 0; $para <= $#pnames; $para++) {
1302 $pname = $pnames[$para];
1303 $pflags = $pflags[$para];
1304 $ptype = substr($pflags,0,4);
1307 $newpar = "\\par\\sb120\n";
1309 if ($ptype eq "chap") {
1310 # Chapter heading. Begin a new node.
1312 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1313 $pflags =~ /chap (.*) :(.*)/;
1314 $node = "Chapter $1";
1315 $title = $footnotetitle = "Chapter $1: ";
1316 foreach $i (@
$pname) {
1317 $ww = &word_hlp
($i,1);
1318 $title .= $ww, $footnotetitle .= &word_hlp
($i,0) unless $ww eq "\001";
1321 printf "#{\\footnote %s}\n", &hlp_sectkw
($node);
1322 print "\${\\footnote $footnotetitle}\n";
1323 printf "+{\\footnote browse:%05d}\n", ++$browse;
1324 printf "!{\\footnote ChangeButtonBinding(\"btn_up\"," .
1325 "\"JumpId(\`nasmdoc.hlp',\`%s')\");\n",
1326 &hlp_sectkw
($tstruct_up{$node});
1327 print "EnableButton(\"btn_up\")}\n";
1328 &hlp_keywords
($node);
1329 print "\\keepn\\f2\\b\\fs30\\sb60\\sa60\n";
1331 $newpar = "\\par\\pard\\plain\\sb120\n";
1332 } elsif ($ptype eq "appn") {
1333 # Appendix heading. Begin a new node.
1335 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1336 $pflags =~ /appn (.*) :(.*)/;
1337 $node = "Appendix $1";
1338 $title = $footnotetitle = "Appendix $1: ";
1339 foreach $i (@
$pname) {
1340 $ww = &word_hlp
($i,1);
1341 $title .= $ww, $footnotetitle .= &word_hlp
($i,0) unless $ww eq "\001";
1344 printf "#{\\footnote %s}\n", &hlp_sectkw
($node);
1345 print "\${\\footnote $footnotetitle}\n";
1346 printf "+{\\footnote browse:%05d}\n", ++$browse;
1347 printf "!{\\footnote ChangeButtonBinding(\"btn_up\"," .
1348 "\"JumpId(\`nasmdoc.hlp',\`%s')\");\n",
1349 &hlp_sectkw
($tstruct_up{$node});
1350 print "EnableButton(\"btn_up\")}\n";
1351 &hlp_keywords
($node);
1352 print "\\keepn\\f2\\b\\fs30\\sb60\\sa60\n";
1354 $newpar = "\\par\\pard\\plain\\sb120\n";
1355 } elsif ($ptype eq "head" || $ptype eq "subh") {
1356 # Heading or subheading. Begin a new node.
1358 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1359 $pflags =~ /.... (.*) :(.*)/;
1360 $node = "Section $1";
1361 $title = $footnotetitle = "$1. ";
1362 foreach $i (@
$pname) {
1363 $ww = &word_hlp
($i,1);
1364 $title .= $ww, $footnotetitle .= &word_hlp
($i,0) unless $ww eq "\001";
1367 printf "#{\\footnote %s}\n", &hlp_sectkw
($node);
1368 print "\${\\footnote $footnotetitle}\n";
1369 printf "+{\\footnote browse:%05d}\n", ++$browse;
1370 printf "!{\\footnote ChangeButtonBinding(\"btn_up\"," .
1371 "\"JumpId(\`nasmdoc.hlp',\`%s')\");\n",
1372 &hlp_sectkw
($tstruct_up{$node});
1373 print "EnableButton(\"btn_up\")}\n";
1374 &hlp_keywords
($node);
1375 print "\\keepn\\f2\\b\\fs30\\sb60\\sa60\n";
1377 $newpar = "\\par\\pard\\plain\\sb120\n";
1378 } elsif ($ptype eq "code") {
1380 print "\\keep\\f1\\sb120\n";
1381 foreach $i (@
$pname) {
1383 warn "code line longer than 68 chars: $i\n" if length $i > 68;
1387 print "$x\\par\\sb0\n";
1389 $newpar = "\\pard\\f0\\sb120\n";
1390 } elsif ($ptype eq "bull" || $ptype eq "norm") {
1391 # Ordinary paragraph, optionally bulleted. We wrap, FWIW.
1392 if ($ptype eq "bull") {
1393 print "\\tx360\\li360\\fi-360{\\f3\\'9F}\\tab\n";
1394 $newpar = "\\par\\pard\\sb120\n";
1396 $newpar = "\\par\\sb120\n";
1402 do { $w = &word_hlp
((shift @a),1); } while $w eq "\001"; # hack
1404 if ($w eq ' ' || $w eq '' || $w eq undef) {
1405 if (length ($line . $wd) > 75) {
1406 $line =~ s/\s*$//; # trim trailing spaces
1407 print "$line \n"; # and put one back
1409 $wd =~ s/^\s*//; # trim leading spaces
1415 } while ($w ne '' && $w ne undef);
1416 if ($line =~ /\S/) {
1417 $line =~ s/\s*$//; # trim trailing spaces
1430 my ($w, $docode) = @_;
1433 return undef if $w eq '' || $w eq undef;
1434 $wtype = substr($w,0,2);
1435 $wmajt = substr($wtype,0,1);
1440 $w =~ s/<.*>// if $wmajt eq "w"; # remove web links
1441 substr($w,0,length($w)-1) =~ s/-/\\\'AD/g if $wmajt ne "x"; #nonbreakhyphens
1442 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
1444 } elsif ($wtype eq "sp") {
1446 } elsif ($wtype eq "da") {
1448 } elsif ($wmajt eq "c" || $wtype eq "wc") {
1449 $w =~ s/ /\\\'A0/g; # make spaces non-breaking
1450 return $docode ?
"{\\f1 ${w}}" : $w;
1451 } elsif ($wtype eq "es") {
1453 } elsif ($wtype eq "ee") {
1455 } elsif ($wtype eq "eo") {
1456 return "{\\i ${w}}";
1457 } elsif ($wtype eq "x ") {
1459 } elsif ($wtype eq "xe") {
1460 $w = &hlp_sectkw
($w);
1461 return "}{\\v ${w}}";
1462 } elsif ($wmajt eq "i") {
1465 die "panic in word_hlp: $wtype$w\n";
1471 my $item, $kword, $i, $mpname, $title;
1473 $item = $tstruct_next{$topitem};
1474 print "\\li360\\fi-360\n";
1477 $mpname = $tstruct_pname{$item};
1478 foreach $i (@
$mpname) {
1479 $ww = &word_hlp
($i, 0);
1480 $title .= $ww unless $ww eq "\001";
1482 $kword = &hlp_sectkw
($item);
1483 print "{\\uldb ${item}: $title}{\\v $kword}\\par\\sb0\n";
1484 $item = $tstruct_mnext{$item};
1486 print "\\pard\\sb120\n";
1491 $node =~ tr/A-Z/a-z/;
1492 $node =~ tr/- ./___/;
1498 my $pfx = "K{\\footnote ";
1500 foreach $i (0..$#itags) {
1501 (print $pfx,$hlp_index[$i]), $pfx = ";\n", $done++
1502 if $idxnodes{$node,$itags[$i]};
1504 print "}\n" if $done;
1507 # Make tree structures. $tstruct_* is top-level and global.
1509 my ($item, $level) = @_;
1512 $tstruct_pname{$item} = $pname;
1513 $tstruct_next{$tstruct_previtem} = $item;
1514 $tstruct_prev{$item} = $tstruct_previtem;
1515 $tstruct_level{$item} = $level;
1516 $tstruct_up{$item} = $tstruct_last[$level-1];
1517 $tstruct_mnext{$tstruct_last[$level]} = $item;
1518 $tstruct_last[$level] = $item;
1519 for ($i=$level+1; $i<$MAXLEVEL; $i++) { $tstruct_last[$i] = undef; }
1520 $tstruct_previtem = $item;
1525 # This produces documentation intermediate paragraph format; this is
1526 # basically the digested output of the front end. Intended for use
1527 # by future backends, instead of putting it all in the same script.
1530 open(PARAS
, '>', File
::Spec
->catfile($out_path, 'nasmdoc.dip'));
1531 foreach $k (sort(keys(%metadata))) {
1532 print PARAS
'meta :', $k, "\n";
1533 print PARAS
$metadata{$k},"\n";
1535 for ($para = 0; $para <= $#pnames; $para++) {
1536 print PARAS
$pflags[$para], "\n";
1537 print PARAS
join("\037", @
{$pnames[$para]}, "\n");
1539 foreach $k (@itags) {
1540 print PARAS
'indx :', $k, "\n";
1541 print PARAS
join("\037", @
{$idxmap{$k}}), "\n";