3 # Read the source-form of the NASM manual and generate the various
8 # Ellipsis support would be nice.
10 # Source-form features:
11 # ---------------------
14 # Bullets the paragraph. Rest of paragraph is indented to cope. In
15 # HTML, consecutive groups of bulleted paragraphs become unordered
19 # produces `_foobar_' in text and italics in HTML, PS, RTF
21 # Inline code \c{foobar}
22 # produces ``foobar'' in text, and fixed-pitch font in HTML, PS, RTF
27 # produces fixed-pitch font where appropriate, and doesn't break
28 # pages except sufficiently far into the middle of a display.
30 # Chapter, header and subheader
31 # \C{intro} Introduction
32 # \H{whatsnasm} What is NASM?
33 # \S{free} NASM Is Free
34 # dealt with as appropriate. Chapters begin on new sides, possibly
35 # even new _pages_. (Sub)?headers are good places to begin new
36 # pages. Just _after_ a (sub)?header isn't.
37 # The keywords can be substituted with \K and \k.
39 # Keyword \K{cintro} \k{cintro}
40 # Expands to `Chapter 1', `Section 1.1', `Section 1.1.1'. \K has an
41 # initial capital whereas \k doesn't. In HTML, will produce
44 # Web link \W{http://foobar/}{text} or \W{mailto:me@here}\c{me@here}
45 # the \W prefix is ignored except in HTML; in HTML the last part
46 # becomes a hyperlink to the first part.
49 # In case it's necessary, they expand to the real versions.
51 # Nonbreaking hyphen \-
55 # Causes everything after it on the line to be ignored by the
56 # source-form processor.
58 # Indexable word \i{foobar} (or \i\e{foobar} or \i\c{foobar}, equally)
59 # makes word appear in index, referenced to that point
60 # \i\c comes up in code style even in the index; \i\e doesn't come
61 # up in emphasised style.
63 # Indexable non-displayed word \I{foobar} or \I\c{foobar}
64 # just as \i{foobar} except that nothing is displayed for it
67 # \IR{foobar} \c{foobar} operator, uses of
68 # tidies up the appearance in the index of something the \i or \I
69 # operator was applied to
72 # \IA{foobar}{bazquux}
73 # aliases one index tag (as might be supplied to \i or \I) to
74 # another, so that \I{foobar} has the effect of \I{bazquux}, and
75 # \i{foobar} has the effect of \I{bazquux}foobar
79 # defines document metadata, such as authorship, title and copyright;
80 # different output formats use this differently.
84 # Includes filename. Recursion is allowed.
89 $diag = 1, shift @ARGV if $ARGV[0] eq "-d";
91 ($out_format) = @ARGV;
95 $tstruct_previtem = $node = "Top";
97 $tstruct_level{$tstruct_previtem} = 0;
98 $tstruct_last[$tstruct_level{$tstruct_previtem}] = $tstruct_previtem;
99 $MAXLEVEL = 10; # really 3, but play safe ;-)
101 # Read the file; pass a paragraph at a time to the paragraph processor.
102 print "Reading input...";
103 $pname = "para000000";
104 @pnames = @pflags = ();
106 while (defined($_ = <STDIN
>)) {
112 # Now we've read in the entire document and we know what all the
113 # heading keywords refer to. Go through and fix up the \k references.
114 print "Fixing up cross-references...";
118 # Sort the index tags, according to the slightly odd order I've decided on.
119 print "Sorting index tags...";
124 print "Writing index-diagnostic file...";
129 # OK. Write out the various output files.
130 if ($out_format eq 'txt') {
131 print "Producing text output: ";
134 } elsif ($out_format eq 'html') {
135 print "Producing HTML output: ";
138 } elsif ($out_format eq 'texi') {
139 print "Producing Texinfo output: ";
142 } elsif ($out_format eq 'hlp') {
143 print "Producing WinHelp output: ";
146 } elsif ($out_format eq 'dip') {
147 print "Producing Documentation Intermediate Paragraphs: ";
151 die "$0: unknown output format: $out_format\n";
164 if (!/\S/ || /^\\(IA|IR|M)/) { # special case: \IA \IR \M imply new-paragraph
169 s/\\#.*$//; # strip comments
175 my $F = IO
::File
->new($name)
176 or die "Cannot open $name: $!";
183 my $pflags = "", $i, $w, $l, $t;
188 # Strip off _leading_ spaces, then determine type of paragraph.
192 # A code paragraph. The paragraph-array will contain the simple
193 # strings which form each line of the paragraph.
195 while (/^\\c (([^\\]|\\[^c])*)(.*)$/) {
203 $_ = ''; # suppress word-by-word code
205 # A chapter heading. Define the keyword and allocate a chapter
210 $xref = "chapter-$cnum";
211 $pflags = "chap $cnum :$xref";
212 die "badly formatted chapter heading: $_\n" if !/^\\C{([^}]*)}\s*(.*)$/;
213 $refs{$1} = "chapter $cnum";
214 $node = "Chapter $cnum";
216 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
219 # the standard word-by-word code will happen next
221 # An appendix heading. Define the keyword and allocate an appendix
224 $cnum = 'A' if $cnum =~ /[0-9]+/;
227 $xref = "appendix-$cnum";
228 $pflags = "appn $cnum :$xref";
229 die "badly formatted appendix heading: $_\n" if !/^\\A{([^}]*)}\s*(.*)$/;
230 $refs{$1} = "appendix $cnum";
231 $node = "Appendix $cnum";
233 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
236 # the standard word-by-word code will happen next
238 # A major heading. Define the keyword and allocate a section number.
241 $xref = "section-$cnum.$hnum";
242 $pflags = "head $cnum.$hnum :$xref";
243 die "badly formatted heading: $_\n" if !/^\\[HP]{([^}]*)}\s*(.*)$/;
244 $refs{$1} = "section $cnum.$hnum";
245 $node = "Section $cnum.$hnum";
247 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
250 # the standard word-by-word code will happen next
252 # A sub-heading. Define the keyword and allocate a section number.
254 $xref = "section-$cnum.$hnum.$snum";
255 $pflags = "subh $cnum.$hnum.$snum :$xref";
256 die "badly formatted subheading: $_\n" if !/^\\S{([^}]*)}\s*(.*)$/;
257 $refs{$1} = "section $cnum.$hnum.$snum";
258 $node = "Section $cnum.$hnum.$snum";
260 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
263 # the standard word-by-word code will happen next
266 die "badly formatted index rewrite: $_\n" if !/^\\IR{([^}]*)}\s*(.*)$/;
269 # the standard word-by-word code will happen next
272 die "badly formatted index alias: $_\n" if !/^\\IA{([^}]*)}{([^}]*)}\s*$/;
274 return; # avoid word-by-word code
277 die "badly formed metadata: $_\n" if !/^\\M{([^}]*)}{([^}]*)}\s*$/;
279 return; # avoid word-by-word code
281 # A bulleted paragraph. Strip off the initial \b and let the
282 # word-by-word code take care of the rest.
286 # A normal paragraph. Just set $pflags: the word-by-word code does
291 # The word-by-word code: unless @$pname is already defined (which it
292 # will be in the case of a code paragraph), split the paragraph up
293 # into words and push each on @$pname.
295 # Each thing pushed on @$pname should have a two-character type
296 # code followed by the text.
301 # "es" for first emphasised word in emphasised bit
302 # "e " for emphasised in mid-emphasised-bit
303 # "ee" for last emphasised word in emphasised bit
304 # "eo" for single (only) emphasised word
307 # "kK" for capitalised cross-ref
309 # "wc" for code-type Web link
310 # "x " for beginning of resolved cross-ref; generates no visible output,
311 # and the text is the cross-reference code
312 # "xe" for end of resolved cross-ref; text is same as for "x ".
313 # "i " for point to be indexed: the text is the internal index into the
317 s/^\s*//, push @
$pname, "sp" if /^\s/;
318 $indexing = $qindex = 0;
319 if (/^(\\[iI])?\\c/) {
320 $qindex = 1 if $1 eq "\\I";
321 $indexing = 1, s/^\\[iI]// if $1;
323 die "badly formatted \\c: \\c$_\n" if !/{(([^\\}]|\\.)*)}(.*)$/;
330 (push @
$pname,"i"),$lastp = $#$pname if $indexing;
331 push @
$pname,"c $w" if !$qindex;
332 $$pname[$lastp] = &addidx
($node, $w, "c $w") if $indexing;
333 } elsif (/^\\[iIe]/) {
336 $qindex = 1 if $1 eq "\\I";
337 $indexing = 1, $type = "\\i" if $1;
338 $emph = 1, $type = "\\e" if $2;
339 s/^(\\[iI])?(\\e?)//;
340 die "badly formatted $type: $type$_\n" if !/{(([^\\}]|\\.)*)}(.*)$/;
347 $t = $emph ?
"es" : "n ";
349 (push @
$pname,"i"),$lastp = $#$pname if $indexing;
350 foreach $i (split /\s+/,$w) { # \e and \i can be multiple words
351 push @
$pname,"$t$i","sp" if !$qindex;
352 ($ii=$i) =~ tr/A-Z/a-z/, push @ientry,"n $ii","sp" if $indexing;
353 $t = $emph ?
"e " : "n ";
355 $w =~ tr/A-Z/a-z/, pop @ientry if $indexing;
356 $$pname[$lastp] = &addidx
($node, $w, @ientry) if $indexing;
357 pop @
$pname if !$qindex; # remove final space
358 if (substr($$pname[$#$pname],0,2) eq "es" && !$qindex) {
359 substr($$pname[$#$pname],0,2) = "eo";
360 } elsif ($emph && !$qindex) {
361 substr($$pname[$#$pname],0,2) = "ee";
363 } elsif (/^\\[kK]/) {
367 die "badly formatted \\k: \\c$_\n" if !/{([^}]*)}(.*)$/;
372 die "badly formatted \\W: \\W$_\n"
373 if !/{([^}]*)}(\\i)?(\\c)?{(([^\\}]|\\.)*)}(.*)$/;
378 $t = "wc" if $3 eq "\\c";
384 (push @
$pname,"i"),$lastp = $#$pname if $indexing;
385 push @
$pname,"$t<$l>$w";
386 $$pname[$lastp] = &addidx
($node, $w, "c $w") if $indexing;
388 die "what the hell? $_\n" if !/^(([^\s\\\-]|\\[\\{}\-])*-?)(.*)$/;
389 die "painful death! $_\n" if !length $1;
403 if ($irewrite ne undef) {
404 &addidx
(undef, $irewrite, @
$pname);
407 push @pnames, $pname;
408 push @pflags, $pflags;
414 my ($node, $text, @ientry) = @_;
415 $text = $idxalias{$text} || $text;
416 if ($node eq undef || !$idxmap{$text}) {
418 $idxmap{$text} = $ientry;
422 $idxnodes{$node,$text} = 1;
428 my $iitem, $ientry, $i, $piitem, $pcval, $cval, $clrcval;
430 @itags = map { # get back the original data as the 1st elt of each list
432 } sort { # compare auxiliary (non-first) elements of lists
433 $a->[1] cmp $b->[1] ||
434 $a->[2] cmp $b->[2] ||
436 } map { # transform array into list of 3-element lists
437 my $ientry = $idxmap{$_};
438 my $a = substr($$ientry[0],2);
439 $a =~ tr/A-Za-z0-9//cd;
440 [$_, uc($a), substr($$ientry[0],0,2)]
443 # Having done that, check for comma-hood.
445 foreach $iitem (@itags) {
446 $ientry = $idxmap{$iitem};
449 FL
:for ($i=0; $i <= $#$ientry; $i++) {
450 if ($$ientry[$i] =~ /^(n .*,)(.*)/) {
452 splice @
$ientry,$i+1,0,"n $2" if length $2;
453 $commapos{$iitem} = $i+1;
454 $cval = join("\002", @
$ientry[0..$i]);
459 $cval = undef if $clrcval;
460 $commanext{$iitem} = $commaafter{$piitem} = 1
461 if $cval and ($cval eq $pcval);
467 my $iitem,$ientry,$w,$ww,$foo,$node;
468 open INDEXDIAG
,">index.diag";
469 foreach $iitem (@itags) {
470 $ientry = $idxmap{$iitem};
471 print INDEXDIAG
"<$iitem> ";
472 foreach $w (@
$ientry) {
474 print INDEXDIAG
$ww unless $ww eq "\001";
478 foreach $node (@nodes) {
479 (print INDEXDIAG
$foo,$node), $foo = ", " if $idxnodes{$node,$iitem};
481 print INDEXDIAG
"\n";
487 my $pname, $p, $i, $j, $k, $caps, @repl;
489 for ($p=0; $p<=$#pnames; $p++) {
490 next if $pflags[$p] eq "code";
491 $pname = $pnames[$p];
492 for ($i=$#$pname; $i >= 0; $i--) {
493 if ($$pname[$i] =~ /^k/) {
495 $caps = ($k =~ /^kK/);
498 die "undefined keyword `$k'\n" unless $repl;
499 substr($repl,0,1) =~ tr/a-z/A-Z/ if $caps;
501 push @repl,"x $xrefs{$k}";
502 foreach $j (split /\s+/,$repl) {
506 pop @repl; # remove final space
507 push @repl,"xe$xrefs{$k}";
508 splice @
$pname,$i,1,@repl;
515 # This is called from the top level, so I won't bother using
519 print "writing file...";
520 open TEXT
,">nasmdoc.txt";
524 $title = "The Netwide Assembler: NASM";
525 $spaces = ' ' x
((75-(length $title))/2);
526 ($underscore = $title) =~ s/./=/g;
527 print "$spaces$title\n$spaces$underscore\n";
529 for ($para = 0; $para <= $#pnames; $para++) {
530 $pname = $pnames[$para];
531 $pflags = $pflags[$para];
532 $ptype = substr($pflags,0,4);
534 print "\n"; # always one of these before a new paragraph
536 if ($ptype eq "chap") {
537 # Chapter heading. "Chapter N: Title" followed by a line of
539 $pflags =~ /chap (.*) :(.*)/;
540 $title = "Chapter $1: ";
541 foreach $i (@
$pname) {
543 $title .= $ww unless $ww eq "\001";
548 } elsif ($ptype eq "appn") {
549 # Appendix heading. "Appendix N: Title" followed by a line of
551 $pflags =~ /appn (.*) :(.*)/;
552 $title = "Appendix $1: ";
553 foreach $i (@
$pname) {
555 $title .= $ww unless $ww eq "\001";
560 } elsif ($ptype eq "head" || $ptype eq "subh") {
561 # Heading or subheading. Just a number and some text.
562 $pflags =~ /.... (.*) :(.*)/;
563 $title = sprintf "%6s ", $1;
564 foreach $i (@
$pname) {
566 $title .= $ww unless $ww eq "\001";
569 } elsif ($ptype eq "code") {
570 # Code paragraph. Emit each line with a seven character indent.
571 foreach $i (@
$pname) {
572 warn "code line longer than 68 chars: $i\n" if length $i > 68;
573 print ' 'x7
, $i, "\n";
575 } elsif ($ptype eq "bull" || $ptype eq "norm") {
576 # Ordinary paragraph, optionally bulleted. We wrap, with ragged
577 # 75-char right margin and either 7 or 11 char left margin
578 # depending on bullets.
579 if ($ptype eq "bull") {
580 $line = ' 'x7
. '(*) ';
583 $line = $next = ' 'x7
;
588 do { $w = &word_txt
(shift @a) } while $w eq "\001"; # nasty hack
590 if ($wprev =~ /-$/ || $w eq ' ' || $w eq '' || $w eq undef) {
591 if (length ($line . $wd) > 75) {
592 $line =~ s/\s*$//; # trim trailing spaces
595 $wd =~ s/^\s*//; # trim leading spaces
601 } while ($w ne '' && $w ne undef);
603 $line =~ s/\s*$//; # trim trailing spaces
618 return undef if $w eq '' || $w eq undef;
619 $wtype = substr($w,0,2);
620 $wmajt = substr($wtype,0,1);
622 $w =~ s/<.*>// if $wmajt eq "w"; # remove web links
623 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
625 } elsif ($wtype eq "sp") {
627 } elsif ($wtype eq "da") {
629 } elsif ($wmajt eq "c" || $wtype eq "wc") {
631 } elsif ($wtype eq "es") {
633 } elsif ($wtype eq "ee") {
635 } elsif ($wtype eq "eo") {
637 } elsif ($wmajt eq "x" || $wmajt eq "i") {
640 die "panic in word_txt: $wtype$w\n";
645 # This is called from the top level, so I won't bother using
648 # Write contents file. Just the preamble, then a menu of links to the
649 # separate chapter files and the nodes therein.
650 print "writing contents file...";
651 open TEXT
,">nasmdoc0.html";
654 print "<p>This manual documents NASM, the Netwide Assembler: an assembler\n";
655 print "targetting the Intel x86 series of processors, with portable source.\n";
657 for ($node = $tstruct_next{'Top'}; $node; $node = $tstruct_next{$node}) {
658 if ($tstruct_level{$node} == 1) {
659 # Invent a file name.
660 ($number = lc($xrefnodes{$node})) =~ s/.*-//;
661 $fname="nasmdocx.html";
662 substr($fname,8 - length $number, length $number) = $number;
663 $html_fnames{$node} = $fname;
667 # Use the preceding filename plus a marker point.
668 $link = $fname . "#$xrefnodes{$node}";
671 $pname = $tstruct_pname{$node};
672 foreach $i (@
$pname) {
673 $ww = &word_html
($i);
674 $title .= $ww unless $ww eq "\001";
676 print "<a href=\"$link\">$title</a><br>\n";
678 print "<p><a href=\"nasmdoci.html\">Index</a>\n";
679 print "</body></html>\n";
683 # Open a null file, to ensure output (eg random &html_jumppoints calls)
685 print "writing chapter files...";
686 open TEXT
,">/dev/null";
692 for ($para = 0; $para <= $#pnames; $para++) {
693 $pname = $pnames[$para];
694 $pflags = $pflags[$para];
695 $ptype = substr($pflags,0,4);
697 $in_list = 0, print "</ul>\n" if $in_list && $ptype ne "bull";
698 if ($ptype eq "chap") {
699 # Chapter heading. Begin a new file.
700 $pflags =~ /chap (.*) :(.*)/;
701 $title = "Chapter $1: ";
703 &html_jumppoints
; print "</body></html>\n"; select STDOUT
; close TEXT
;
704 $html_lastf = $html_fnames{$chapternode};
705 $chapternode = $nodexrefs{$xref};
706 $html_nextf = $html_fnames{$tstruct_mnext{$chapternode}};
707 open TEXT
,">$html_fnames{$chapternode}"; select TEXT
; &html_preamble
(1);
708 foreach $i (@
$pname) {
709 $ww = &word_html
($i);
710 $title .= $ww unless $ww eq "\001";
712 $h = "<h2><a name=\"$xref\">$title</a></h2>\n";
713 print $h; print FULL
$h;
714 } elsif ($ptype eq "appn") {
715 # Appendix heading. Begin a new file.
716 $pflags =~ /appn (.*) :(.*)/;
717 $title = "Appendix $1: ";
719 &html_jumppoints
; print "</body></html>\n"; select STDOUT
; close TEXT
;
720 $html_lastf = $html_fnames{$chapternode};
721 $chapternode = $nodexrefs{$xref};
722 $html_nextf = $html_fnames{$tstruct_mnext{$chapternode}};
723 open TEXT
,">$html_fnames{$chapternode}"; select TEXT
; &html_preamble
(1);
724 foreach $i (@
$pname) {
725 $ww = &word_html
($i);
726 $title .= $ww unless $ww eq "\001";
728 print "<h2><a name=\"$xref\">$title</a></h2>\n";
729 } elsif ($ptype eq "head" || $ptype eq "subh") {
730 # Heading or subheading.
731 $pflags =~ /.... (.*) :(.*)/;
732 $hdr = ($ptype eq "subh" ?
"h4" : "h3");
735 foreach $i (@
$pname) {
736 $ww = &word_html
($i);
737 $title .= $ww unless $ww eq "\001";
739 print "<$hdr><a name=\"$xref\">$title</a></$hdr>\n";
740 } elsif ($ptype eq "code") {
743 foreach $i (@
$pname) {
751 } elsif ($ptype eq "bull" || $ptype eq "norm") {
752 # Ordinary paragraph, optionally bulleted. We wrap, with ragged
753 # 75-char right margin and either 7 or 11 char left margin
754 # depending on bullets.
755 if ($ptype eq "bull") {
756 $in_list = 1, print "<ul>\n" unless $in_list;
764 do { $w = &word_html
(shift @a) } while $w eq "\001"; # nasty hack
766 if ($w eq ' ' || $w eq '' || $w eq undef) {
767 if (length ($line . $wd) > 75) {
768 $line =~ s/\s*$//; # trim trailing spaces
771 $wd =~ s/^\s*//; # trim leading spaces
777 } while ($w ne '' && $w ne undef);
779 $line =~ s/\s*$//; # trim trailing spaces
785 # Close whichever file was open.
787 print "</body></html>\n";
791 print "\n writing index file...";
792 open TEXT
,">nasmdoci.html";
795 print "<p align=center><a href=\"nasmdoc0.html\">Contents</a>\n";
798 print "<p align=center><a href=\"nasmdoc0.html\">Contents</a>\n";
799 print "</body></html>\n";
805 print "<html><head><title>NASM Manual</title></head>\n";
806 print "<body><h1 align=center>The Netwide Assembler: NASM</h1>\n\n";
807 &html_jumppoints
if $_[0];
810 sub html_jumppoints
{
811 print "<p align=center>";
812 print "<a href=\"$html_nextf\">Next Chapter</a> |\n" if $html_nextf;
813 print "<a href=\"$html_lastf\">Previous Chapter</a> |\n" if $html_lastf;
814 print "<a href=\"nasmdoc0.html\">Contents</a> |\n";
815 print "<a href=\"nasmdoci.html\">Index</a>\n";
819 my $itag, $a, @ientry, $sep, $w, $wd, $wprev, $line;
822 foreach $itag (@itags) {
823 $ientry = $idxmap{$itag};
827 foreach $node (@nodes) {
828 next if !$idxnodes{$node,$itag};
829 push @a, "n ," if $sep;
830 push @a, "sp", "x $xrefnodes{$node}", "n $node", "xe$xrefnodes{$node}";
835 do { $w = &word_html
(shift @a) } while $w eq "\001"; # nasty hack
837 if ($w eq ' ' || $w eq '' || $w eq undef) {
838 if (length ($line . $wd) > 75) {
839 $line =~ s/\s*$//; # trim trailing spaces
842 $wd =~ s/^\s*//; # trim leading spaces
848 } while ($w ne '' && $w ne undef);
850 $line =~ s/\s*$//; # trim trailing spaces
859 my $wtype, $wmajt, $pfx, $sfx;
861 return undef if $w eq '' || $w eq undef;
863 $wtype = substr($w,0,2);
864 $wmajt = substr($wtype,0,1);
867 $pfx = "<a href=\"$1\">", $sfx = "</a>", $w = $2
868 if $wmajt eq "w" && $w =~ /^<(.*)>(.*)$/;
872 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
873 return $pfx . $w . $sfx;
874 } elsif ($wtype eq "sp") {
876 } elsif ($wtype eq "da") {
877 return '-'; # sadly, en-dashes are non-standard in HTML
878 } elsif ($wmajt eq "c" || $wtype eq "wc") {
879 return $pfx . "<code><nobr>${w}</nobr></code>" . $sfx;
880 } elsif ($wtype eq "es") {
882 } elsif ($wtype eq "ee") {
884 } elsif ($wtype eq "eo") {
885 return "<em>${w}</em>";
886 } elsif ($wtype eq "x ") {
887 # Magic: we must resolve the cross reference into file and marker
888 # parts, then dispose of the file part if it's us, and dispose of
889 # the marker part if the cross reference describes the top node of
891 my $node = $nodexrefs{$w}; # find the node we're aiming at
892 my $level = $tstruct_level{$node}; # and its level
893 my $up = $node, $uplev = $level-1;
894 $up = $tstruct_up{$up} while $uplev--; # get top node of containing file
895 my $file = ($up ne $chapternode) ?
$html_fnames{$up} : "";
896 my $marker = ($level == 1 and $file) ?
"" : "#$w";
897 return "<a href=\"$file$marker\">";
898 } elsif ($wtype eq "xe") {
900 } elsif ($wmajt eq "i") {
903 die "panic in word_html: $wtype$w\n";
908 # This is called from the top level, so I won't bother using
912 print "writing file...";
913 open TEXT
,">nasmdoc.texi";
917 print "\\input texinfo \@c -*-texinfo-*-\n";
918 print "\@c \%**start of header\n";
919 print "\@setfilename ",$metadata{'infofile'},".info\n";
920 print "\@dircategory ",$metadata{'category'},"\n";
921 print "\@direntry\n";
922 printf "* %-28s %s.\n",
923 sprintf('%s: (%s).', $metadata{'infoname'}, $metadata{'infofile'}),
924 $metadata{'infotitle'};
925 print "\@end direntry\n";
926 print "\@settitle ", $metadata{'title'},"\n";
927 print "\@setchapternewpage odd\n";
928 print "\@c \%**end of header\n";
931 print $metadata{'summary'}, "\n";
933 print "Copyright ",$metadata{'year'}," ",$metadata{'author'},"\n";
935 print $metadata{'license'}, "\n";
936 print "\@end ifinfo\n";
938 print "\@titlepage\n";
939 $title = $metadata{'title'};
940 $title =~ s/ - / --- /g;
941 print "\@title ${title}\n";
942 print "\@author ",$metadata{'author'},"\n";
945 print "\@vskip 0pt plus 1filll\n";
946 print "Copyright \@copyright{} ",$metadata{'year'},' ',$metadata{'author'},"\n";
948 print $metadata{'license'}, "\n";
949 print "\@end titlepage\n";
951 print "\@node Top, $tstruct_next{'Top'}, (dir), (dir)\n";
952 print "\@top ",$metadata{'infotitle'},"\n";
955 print $metadata{'summary'}, "\n";
956 print "\@end ifinfo\n";
961 for ($para = 0; $para <= $#pnames; $para++) {
962 $pname = $pnames[$para];
963 $pflags = $pflags[$para];
964 $ptype = substr($pflags,0,4);
966 $bulleting = 0, print "\@end itemize\n" if $bulleting && $ptype ne "bull";
967 print "\n"; # always one of these before a new paragraph
969 if ($ptype eq "chap") {
970 # Chapter heading. Begin a new node.
972 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
973 $pflags =~ /chap (.*) :(.*)/;
974 $node = "Chapter $1";
975 $title = "Chapter $1: ";
976 foreach $i (@
$pname) {
977 $ww = &word_texi
($i);
978 $title .= $ww unless $ww eq "\001";
980 print "\@node $node, $tstruct_next{$node}, $tstruct_prev{$node},";
981 print " $tstruct_up{$node}\n\@unnumbered $title\n";
982 } elsif ($ptype eq "appn") {
983 # Appendix heading. Begin a new node.
985 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
986 $pflags =~ /appn (.*) :(.*)/;
987 $node = "Appendix $1";
988 $title = "Appendix $1: ";
989 foreach $i (@
$pname) {
990 $ww = &word_texi
($i);
991 $title .= $ww unless $ww eq "\001";
993 print "\@node $node, $tstruct_next{$node}, $tstruct_prev{$node},";
994 print " $tstruct_up{$node}\n\@unnumbered $title\n";
995 } elsif ($ptype eq "head" || $ptype eq "subh") {
996 # Heading or subheading. Begin a new node.
998 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
999 $pflags =~ /.... (.*) :(.*)/;
1000 $node = "Section $1";
1002 foreach $i (@
$pname) {
1003 $ww = &word_texi
($i);
1004 $title .= $ww unless $ww eq "\001";
1006 print "\@node $node, $tstruct_next{$node}, $tstruct_prev{$node},";
1007 print " $tstruct_up{$node}\n";
1008 $hdr = ($ptype eq "subh" ?
"\@unnumberedsubsec" : "\@unnumberedsec");
1009 print "$hdr $title\n";
1010 } elsif ($ptype eq "code") {
1011 # Code paragraph. Surround with @example / @end example.
1012 print "\@example\n";
1013 foreach $i (@
$pname) {
1014 warn "code line longer than 68 chars: $i\n" if length $i > 68;
1020 print "\@end example\n";
1021 } elsif ($ptype eq "bull" || $ptype eq "norm") {
1022 # Ordinary paragraph, optionally bulleted. We wrap, FWIW.
1023 if ($ptype eq "bull") {
1024 $bulleting = 1, print "\@itemize \@bullet\n" if !$bulleting;
1031 do { $w = &word_texi
(shift @a); } while $w eq "\001"; # hack
1033 if ($wprev =~ /-$/ || $w eq ' ' || $w eq '' || $w eq undef) {
1034 if (length ($line . $wd) > 75) {
1035 $line =~ s/\s*$//; # trim trailing spaces
1038 $wd =~ s/^\s*//; # trim leading spaces
1044 } while ($w ne '' && $w ne undef);
1045 if ($line =~ /\S/) {
1046 $line =~ s/\s*$//; # trim trailing spaces
1056 print "\n\@contents\n\@bye\n";
1061 # Side effect of this procedure: update global `texiwdlen' to be the length
1062 # in chars of the formatted version of the word.
1067 return undef if $w eq '' || $w eq undef;
1068 $wtype = substr($w,0,2);
1069 $wmajt = substr($wtype,0,1);
1075 $w =~ s/<.*>// if $wmajt eq "w"; # remove web links
1076 substr($w,0,1) =~ tr/a-z/A-Z/, $capital = 0 if $capital;
1077 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
1080 } elsif ($wtype eq "sp") {
1083 } elsif ($wtype eq "da") {
1086 } elsif ($wmajt eq "c" || $wtype eq "wc") {
1087 $texiwdlen = 2 + $wlen;
1088 return "\@code\{$w\}";
1089 } elsif ($wtype eq "es") {
1090 $texiwdlen = 1 + $wlen;
1091 return "\@emph\{${w}";
1092 } elsif ($wtype eq "ee") {
1093 $texiwdlen = 1 + $wlen;
1095 } elsif ($wtype eq "eo") {
1096 $texiwdlen = 2 + $wlen;
1097 return "\@emph\{${w}\}";
1098 } elsif ($wtype eq "x ") {
1099 $texiwdlen = 0; # we don't need it in this case
1100 $capital = 1; # hack
1102 } elsif ($wtype eq "xe") {
1103 $texiwdlen = 0; # we don't need it in this case
1105 } elsif ($wmajt eq "i") {
1106 $texiwdlen = 0; # we don't need it in this case
1109 die "panic in word_texi: $wtype$w\n";
1115 my $item, $i, $mpname, $title, $wd;
1117 $item = $tstruct_next{$topitem};
1121 $mpname = $tstruct_pname{$item};
1122 foreach $i (@
$mpname) {
1123 $wd = &word_texi
($i);
1124 $title .= $wd unless $wd eq "\001";
1126 print "* ${item}:: $title\n";
1127 $item = $tstruct_mnext{$item};
1129 print "* Index::\n" if $topitem eq "Top";
1130 print "\@end menu\n";
1134 my $itag, $ientry, @a, $wd, $item, $len;
1135 my $subnums = "123456789ABCDEFGHIJKLMNOPQRSTU" .
1136 "VWXYZabcdefghijklmnopqrstuvwxyz";
1138 print "\@ifinfo\n\@node Index, , $FIXMElastnode, Top\n";
1139 print "\@unnumbered Index\n\n\@menu\n";
1141 foreach $itag (@itags) {
1142 $ientry = $idxmap{$itag};
1147 $wd = &word_texi
($i);
1148 $item .= $wd, $len += $texiwdlen unless $wd eq "\001";
1151 foreach $node (@nodes) {
1152 next if !$idxnodes{$node,$itag};
1153 printf "* %s%s (%s): %s.\n",
1154 $item, " " x
(40-$len), substr($subnums,$i++,1), $node;
1157 print "\@end menu\n\@end ifinfo\n";
1161 # This is called from the top level, so I won't bother using
1164 # Build the index-tag text forms.
1165 print "building index entries...";
1168 my $ientry = $idxmap{$_};
1170 foreach $i (@
$ientry) {
1171 $ww = &word_hlp
($i,0);
1172 $title .= $ww unless $ww eq "\001";
1177 # Write the HPJ project-description file.
1178 print "writing .hpj file...";
1179 open HPJ
,">nasmdoc.hpj";
1180 print HPJ
"[OPTIONS]\ncompress=true\n";
1181 print HPJ
"title=NASM: The Netwide Assembler\noldkeyphrase=no\n\n";
1182 print HPJ
"[FILES]\nnasmdoc.rtf\n\n";
1183 print HPJ
"[CONFIG]\n";
1184 print HPJ
'CreateButton("btn_up", "&Up",'.
1185 ' "JumpContents(`nasmdoc.hlp'."'".')")';
1186 print HPJ
"\nBrowseButtons()\n";
1190 print "\n writing .rtf file...";
1191 open TEXT
,">nasmdoc.rtf";
1195 print "{\\rtf1\\ansi{\\fonttbl\n";
1196 print "\\f0\\froman Times New Roman;\\f1\\fmodern Courier New;\n";
1197 print "\\f2\\fswiss Arial;\\f3\\ftech Wingdings}\\deff0\n";
1198 print "#{\\footnote Top}\n";
1199 print "\${\\footnote Contents}\n";
1200 print "+{\\footnote browse:00000}\n";
1201 print "!{\\footnote DisableButton(\"btn_up\")}\n";
1202 print "\\keepn\\f2\\b\\fs30\\sb0\n";
1203 print "NASM: The Netwide Assembler\n";
1204 print "\\par\\pard\\plain\\sb120\n";
1205 print "This file documents NASM, the Netwide Assembler: an assembler \n";
1206 print "targetting the Intel x86 series of processors, with portable source.\n";
1211 $newpar = "\\par\\sb120\n";
1212 for ($para = 0; $para <= $#pnames; $para++) {
1213 $pname = $pnames[$para];
1214 $pflags = $pflags[$para];
1215 $ptype = substr($pflags,0,4);
1218 $newpar = "\\par\\sb120\n";
1220 if ($ptype eq "chap") {
1221 # Chapter heading. Begin a new node.
1223 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1224 $pflags =~ /chap (.*) :(.*)/;
1225 $node = "Chapter $1";
1226 $title = $footnotetitle = "Chapter $1: ";
1227 foreach $i (@
$pname) {
1228 $ww = &word_hlp
($i,1);
1229 $title .= $ww, $footnotetitle .= &word_hlp
($i,0) unless $ww eq "\001";
1232 printf "#{\\footnote %s}\n", &hlp_sectkw
($node);
1233 print "\${\\footnote $footnotetitle}\n";
1234 printf "+{\\footnote browse:%05d}\n", ++$browse;
1235 printf "!{\\footnote ChangeButtonBinding(\"btn_up\"," .
1236 "\"JumpId(\`nasmdoc.hlp',\`%s')\");\n",
1237 &hlp_sectkw
($tstruct_up{$node});
1238 print "EnableButton(\"btn_up\")}\n";
1239 &hlp_keywords
($node);
1240 print "\\keepn\\f2\\b\\fs30\\sb60\\sa60\n";
1242 $newpar = "\\par\\pard\\plain\\sb120\n";
1243 } elsif ($ptype eq "appn") {
1244 # Appendix heading. Begin a new node.
1246 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1247 $pflags =~ /appn (.*) :(.*)/;
1248 $node = "Appendix $1";
1249 $title = $footnotetitle = "Appendix $1: ";
1250 foreach $i (@
$pname) {
1251 $ww = &word_hlp
($i,1);
1252 $title .= $ww, $footnotetitle .= &word_hlp
($i,0) unless $ww eq "\001";
1255 printf "#{\\footnote %s}\n", &hlp_sectkw
($node);
1256 print "\${\\footnote $footnotetitle}\n";
1257 printf "+{\\footnote browse:%05d}\n", ++$browse;
1258 printf "!{\\footnote ChangeButtonBinding(\"btn_up\"," .
1259 "\"JumpId(\`nasmdoc.hlp',\`%s')\");\n",
1260 &hlp_sectkw
($tstruct_up{$node});
1261 print "EnableButton(\"btn_up\")}\n";
1262 &hlp_keywords
($node);
1263 print "\\keepn\\f2\\b\\fs30\\sb60\\sa60\n";
1265 $newpar = "\\par\\pard\\plain\\sb120\n";
1266 } elsif ($ptype eq "head" || $ptype eq "subh") {
1267 # Heading or subheading. Begin a new node.
1269 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1270 $pflags =~ /.... (.*) :(.*)/;
1271 $node = "Section $1";
1272 $title = $footnotetitle = "$1. ";
1273 foreach $i (@
$pname) {
1274 $ww = &word_hlp
($i,1);
1275 $title .= $ww, $footnotetitle .= &word_hlp
($i,0) unless $ww eq "\001";
1278 printf "#{\\footnote %s}\n", &hlp_sectkw
($node);
1279 print "\${\\footnote $footnotetitle}\n";
1280 printf "+{\\footnote browse:%05d}\n", ++$browse;
1281 printf "!{\\footnote ChangeButtonBinding(\"btn_up\"," .
1282 "\"JumpId(\`nasmdoc.hlp',\`%s')\");\n",
1283 &hlp_sectkw
($tstruct_up{$node});
1284 print "EnableButton(\"btn_up\")}\n";
1285 &hlp_keywords
($node);
1286 print "\\keepn\\f2\\b\\fs30\\sb60\\sa60\n";
1288 $newpar = "\\par\\pard\\plain\\sb120\n";
1289 } elsif ($ptype eq "code") {
1291 print "\\keep\\f1\\sb120\n";
1292 foreach $i (@
$pname) {
1294 warn "code line longer than 68 chars: $i\n" if length $i > 68;
1298 print "$x\\par\\sb0\n";
1300 $newpar = "\\pard\\f0\\sb120\n";
1301 } elsif ($ptype eq "bull" || $ptype eq "norm") {
1302 # Ordinary paragraph, optionally bulleted. We wrap, FWIW.
1303 if ($ptype eq "bull") {
1304 print "\\tx360\\li360\\fi-360{\\f3\\'9F}\\tab\n";
1305 $newpar = "\\par\\pard\\sb120\n";
1307 $newpar = "\\par\\sb120\n";
1313 do { $w = &word_hlp
((shift @a),1); } while $w eq "\001"; # hack
1315 if ($w eq ' ' || $w eq '' || $w eq undef) {
1316 if (length ($line . $wd) > 75) {
1317 $line =~ s/\s*$//; # trim trailing spaces
1318 print "$line \n"; # and put one back
1320 $wd =~ s/^\s*//; # trim leading spaces
1326 } while ($w ne '' && $w ne undef);
1327 if ($line =~ /\S/) {
1328 $line =~ s/\s*$//; # trim trailing spaces
1341 my ($w, $docode) = @_;
1344 return undef if $w eq '' || $w eq undef;
1345 $wtype = substr($w,0,2);
1346 $wmajt = substr($wtype,0,1);
1351 $w =~ s/<.*>// if $wmajt eq "w"; # remove web links
1352 substr($w,0,length($w)-1) =~ s/-/\\\'AD/g if $wmajt ne "x"; #nonbreakhyphens
1353 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
1355 } elsif ($wtype eq "sp") {
1357 } elsif ($wtype eq "da") {
1359 } elsif ($wmajt eq "c" || $wtype eq "wc") {
1360 $w =~ s/ /\\\'A0/g; # make spaces non-breaking
1361 return $docode ?
"{\\f1 ${w}}" : $w;
1362 } elsif ($wtype eq "es") {
1364 } elsif ($wtype eq "ee") {
1366 } elsif ($wtype eq "eo") {
1367 return "{\\i ${w}}";
1368 } elsif ($wtype eq "x ") {
1370 } elsif ($wtype eq "xe") {
1371 $w = &hlp_sectkw
($w);
1372 return "}{\\v ${w}}";
1373 } elsif ($wmajt eq "i") {
1376 die "panic in word_hlp: $wtype$w\n";
1382 my $item, $kword, $i, $mpname, $title;
1384 $item = $tstruct_next{$topitem};
1385 print "\\li360\\fi-360\n";
1388 $mpname = $tstruct_pname{$item};
1389 foreach $i (@
$mpname) {
1390 $ww = &word_hlp
($i, 0);
1391 $title .= $ww unless $ww eq "\001";
1393 $kword = &hlp_sectkw
($item);
1394 print "{\\uldb ${item}: $title}{\\v $kword}\\par\\sb0\n";
1395 $item = $tstruct_mnext{$item};
1397 print "\\pard\\sb120\n";
1402 $node =~ tr/A-Z/a-z/;
1403 $node =~ tr/- ./___/;
1409 my $pfx = "K{\\footnote ";
1411 foreach $i (0..$#itags) {
1412 (print $pfx,$hlp_index[$i]), $pfx = ";\n", $done++
1413 if $idxnodes{$node,$itags[$i]};
1415 print "}\n" if $done;
1418 # Make tree structures. $tstruct_* is top-level and global.
1420 my ($item, $level) = @_;
1423 $tstruct_pname{$item} = $pname;
1424 $tstruct_next{$tstruct_previtem} = $item;
1425 $tstruct_prev{$item} = $tstruct_previtem;
1426 $tstruct_level{$item} = $level;
1427 $tstruct_up{$item} = $tstruct_last[$level-1];
1428 $tstruct_mnext{$tstruct_last[$level]} = $item;
1429 $tstruct_last[$level] = $item;
1430 for ($i=$level+1; $i<$MAXLEVEL; $i++) { $tstruct_last[$i] = undef; }
1431 $tstruct_previtem = $item;
1436 # This produces documentation intermediate paragraph format; this is
1437 # basically the digested output of the front end. Intended for use
1438 # by future backends, instead of putting it all in the same script.
1441 open(PARAS
, "> nasmdoc.dip");
1442 foreach $k (keys(%metadata)) {
1443 print PARAS
'meta :', $k, "\n";
1444 print PARAS
$metadata{$k},"\n";
1446 for ($para = 0; $para <= $#pnames; $para++) {
1447 print PARAS
$pflags[$para], "\n";
1448 print PARAS
join("\037", @
{$pnames[$para]}, "\n");
1450 foreach $k (@itags) {
1451 print PARAS
'indx :', $k, "\n";
1452 print PARAS
join("\037", @
{$idxmap{$k}}), "\n";