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
>)) {
113 # Now we've read in the entire document and we know what all the
114 # heading keywords refer to. Go through and fix up the \k references.
115 print "Fixing up cross-references...";
119 # Sort the index tags, according to the slightly odd order I've decided on.
120 print "Sorting index tags...";
125 print "Writing index-diagnostic file...";
130 # OK. Write out the various output files.
131 if ($out_format eq 'txt') {
132 print "Producing text output: ";
135 } elsif ($out_format eq 'html') {
136 print "Producing HTML output: ";
139 } elsif ($out_format eq 'texi') {
140 print "Producing Texinfo output: ";
143 } elsif ($out_format eq 'hlp') {
144 print "Producing WinHelp output: ";
147 } elsif ($out_format eq 'dip') {
148 print "Producing Documentation Intermediate Paragraphs: ";
152 die "$0: unknown output format: $out_format\n";
161 for ($i = 0; $i < length($s); $i++) {
162 $c = substr($s, $i, 1);
185 if (!/\S/ || /^\\(IA|IR|M)/) { # special case: \IA \IR \M imply new-paragraph
190 s/\\#.*$//; # strip comments
196 my $F = IO
::File
->new($name)
197 or die "Cannot open $name: $!";
204 my $pflags = "", $i, $w, $l, $t;
209 # Strip off _leading_ spaces, then determine type of paragraph.
213 # A code paragraph. The paragraph-array will contain the simple
214 # strings which form each line of the paragraph.
216 while (/^\\c (([^\\]|\\[^c])*)(.*)$/) {
224 $_ = ''; # suppress word-by-word code
226 # A chapter heading. Define the keyword and allocate a chapter
231 $xref = "chapter-$cnum";
232 $pflags = "chap $cnum :$xref";
233 die "badly formatted chapter heading: $_\n" if !/^\\C{([^}]*)}\s*(.*)$/;
234 $refs{$1} = "chapter $cnum";
235 $node = "Chapter $cnum";
237 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
240 # the standard word-by-word code will happen next
242 # An appendix heading. Define the keyword and allocate an appendix
245 $cnum = 'A' if $cnum =~ /[0-9]+/;
248 $xref = "appendix-$cnum";
249 $pflags = "appn $cnum :$xref";
250 die "badly formatted appendix heading: $_\n" if !/^\\A{([^}]*)}\s*(.*)$/;
251 $refs{$1} = "appendix $cnum";
252 $node = "Appendix $cnum";
254 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
257 # the standard word-by-word code will happen next
259 # A major heading. Define the keyword and allocate a section number.
262 $xref = "section-$cnum.$hnum";
263 $pflags = "head $cnum.$hnum :$xref";
264 die "badly formatted heading: $_\n" if !/^\\[HP]{([^}]*)}\s*(.*)$/;
265 $refs{$1} = "section $cnum.$hnum";
266 $node = "Section $cnum.$hnum";
268 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
271 # the standard word-by-word code will happen next
273 # A sub-heading. Define the keyword and allocate a section number.
275 $xref = "section-$cnum.$hnum.$snum";
276 $pflags = "subh $cnum.$hnum.$snum :$xref";
277 die "badly formatted subheading: $_\n" if !/^\\S{([^}]*)}\s*(.*)$/;
278 $refs{$1} = "section $cnum.$hnum.$snum";
279 $node = "Section $cnum.$hnum.$snum";
281 $xrefnodes{$node} = $xref; $nodexrefs{$xref} = $node;
284 # the standard word-by-word code will happen next
287 die "badly formatted index rewrite: $_\n" if !/^\\IR{([^}]*)}\s*(.*)$/;
290 # the standard word-by-word code will happen next
293 die "badly formatted index alias: $_\n" if !/^\\IA{([^}]*)}{([^}]*)}\s*$/;
295 return; # avoid word-by-word code
298 die "badly formed metadata: $_\n" if !/^\\M{([^}]*)}{([^}]*)}\s*$/;
300 return; # avoid word-by-word code
302 # A bulleted paragraph. Strip off the initial \b and let the
303 # word-by-word code take care of the rest.
307 # A normal paragraph. Just set $pflags: the word-by-word code does
312 # The word-by-word code: unless @$pname is already defined (which it
313 # will be in the case of a code paragraph), split the paragraph up
314 # into words and push each on @$pname.
316 # Each thing pushed on @$pname should have a two-character type
317 # code followed by the text.
322 # "es" for first emphasised word in emphasised bit
323 # "e " for emphasised in mid-emphasised-bit
324 # "ee" for last emphasised word in emphasised bit
325 # "eo" for single (only) emphasised word
328 # "kK" for capitalised cross-ref
330 # "wc" for code-type Web link
331 # "x " for beginning of resolved cross-ref; generates no visible output,
332 # and the text is the cross-reference code
333 # "xe" for end of resolved cross-ref; text is same as for "x ".
334 # "i " for point to be indexed: the text is the internal index into the
338 s/^\s*//, push @
$pname, "sp" if /^\s/;
339 $indexing = $qindex = 0;
340 if (/^(\\[iI])?\\c/) {
341 $qindex = 1 if $1 eq "\\I";
342 $indexing = 1, s/^\\[iI]// if $1;
344 die "badly formatted \\c: \\c$_\n" if !/{(([^\\}]|\\.)*)}(.*)$/;
351 (push @
$pname,"i"),$lastp = $#$pname if $indexing;
352 push @
$pname,"c $w" if !$qindex;
353 $$pname[$lastp] = &addidx
($node, $w, "c $w") if $indexing;
354 } elsif (/^\\[iIe]/) {
357 $qindex = 1 if $1 eq "\\I";
358 $indexing = 1, $type = "\\i" if $1;
359 $emph = 1, $type = "\\e" if $2;
360 s/^(\\[iI])?(\\e?)//;
361 die "badly formatted $type: $type$_\n" if !/{(([^\\}]|\\.)*)}(.*)$/;
368 $t = $emph ?
"es" : "n ";
370 (push @
$pname,"i"),$lastp = $#$pname if $indexing;
371 foreach $i (split /\s+/,$w) { # \e and \i can be multiple words
372 push @
$pname,"$t$i","sp" if !$qindex;
373 ($ii=$i) =~ tr/A-Z/a-z/, push @ientry,"n $ii","sp" if $indexing;
374 $t = $emph ?
"e " : "n ";
376 $w =~ tr/A-Z/a-z/, pop @ientry if $indexing;
377 $$pname[$lastp] = &addidx
($node, $w, @ientry) if $indexing;
378 pop @
$pname if !$qindex; # remove final space
379 if (substr($$pname[$#$pname],0,2) eq "es" && !$qindex) {
380 substr($$pname[$#$pname],0,2) = "eo";
381 } elsif ($emph && !$qindex) {
382 substr($$pname[$#$pname],0,2) = "ee";
384 } elsif (/^\\[kK]/) {
388 die "badly formatted \\k: \\c$_\n" if !/{([^}]*)}(.*)$/;
393 die "badly formatted \\W: \\W$_\n"
394 if !/{([^}]*)}(\\i)?(\\c)?{(([^\\}]|\\.)*)}(.*)$/;
399 $t = "wc" if $3 eq "\\c";
405 (push @
$pname,"i"),$lastp = $#$pname if $indexing;
406 push @
$pname,"$t<$l>$w";
407 $$pname[$lastp] = &addidx
($node, $w, "c $w") if $indexing;
409 die "what the hell? $_\n" if !/^(([^\s\\\-]|\\[\\{}\-])*-?)(.*)$/;
410 die "painful death! $_\n" if !length $1;
424 if ($irewrite ne undef) {
425 &addidx
(undef, $irewrite, @
$pname);
428 push @pnames, $pname;
429 push @pflags, $pflags;
435 my ($node, $text, @ientry) = @_;
436 $text = $idxalias{$text} || $text;
437 if ($node eq undef || !$idxmap{$text}) {
439 $idxmap{$text} = $ientry;
443 $idxnodes{$node,$text} = 1;
449 my $iitem, $ientry, $i, $piitem, $pcval, $cval, $clrcval;
451 @itags = map { # get back the original data as the 1st elt of each list
453 } sort { # compare auxiliary (non-first) elements of lists
454 $a->[1] cmp $b->[1] ||
455 $a->[2] cmp $b->[2] ||
457 } map { # transform array into list of 3-element lists
458 my $ientry = $idxmap{$_};
459 my $a = substr($$ientry[0],2);
460 $a =~ tr/A-Za-z0-9//cd;
461 [$_, uc($a), substr($$ientry[0],0,2)]
464 # Having done that, check for comma-hood.
466 foreach $iitem (@itags) {
467 $ientry = $idxmap{$iitem};
470 FL
:for ($i=0; $i <= $#$ientry; $i++) {
471 if ($$ientry[$i] =~ /^(n .*,)(.*)/) {
473 splice @
$ientry,$i+1,0,"n $2" if length $2;
474 $commapos{$iitem} = $i+1;
475 $cval = join("\002", @
$ientry[0..$i]);
480 $cval = undef if $clrcval;
481 $commanext{$iitem} = $commaafter{$piitem} = 1
482 if $cval and ($cval eq $pcval);
488 my $iitem,$ientry,$w,$ww,$foo,$node;
489 open INDEXDIAG
,">index.diag";
490 foreach $iitem (@itags) {
491 $ientry = $idxmap{$iitem};
492 print INDEXDIAG
"<$iitem> ";
493 foreach $w (@
$ientry) {
495 print INDEXDIAG
$ww unless $ww eq "\001";
499 foreach $node (@nodes) {
500 (print INDEXDIAG
$foo,$node), $foo = ", " if $idxnodes{$node,$iitem};
502 print INDEXDIAG
"\n";
508 my $pname, $p, $i, $j, $k, $caps, @repl;
510 for ($p=0; $p<=$#pnames; $p++) {
511 next if $pflags[$p] eq "code";
512 $pname = $pnames[$p];
513 for ($i=$#$pname; $i >= 0; $i--) {
514 if ($$pname[$i] =~ /^k/) {
516 $caps = ($k =~ /^kK/);
519 die "undefined keyword `$k'\n" unless $repl;
520 substr($repl,0,1) =~ tr/a-z/A-Z/ if $caps;
522 push @repl,"x $xrefs{$k}";
523 foreach $j (split /\s+/,$repl) {
527 pop @repl; # remove final space
528 push @repl,"xe$xrefs{$k}";
529 splice @
$pname,$i,1,@repl;
536 # This is called from the top level, so I won't bother using
540 print "writing file...";
541 open TEXT
,">nasmdoc.txt";
545 $title = "The Netwide Assembler: NASM";
546 $spaces = ' ' x
((75-(length $title))/2);
547 ($underscore = $title) =~ s/./=/g;
548 print "$spaces$title\n$spaces$underscore\n";
550 for ($para = 0; $para <= $#pnames; $para++) {
551 $pname = $pnames[$para];
552 $pflags = $pflags[$para];
553 $ptype = substr($pflags,0,4);
555 print "\n"; # always one of these before a new paragraph
557 if ($ptype eq "chap") {
558 # Chapter heading. "Chapter N: Title" followed by a line of
560 $pflags =~ /chap (.*) :(.*)/;
561 $title = "Chapter $1: ";
562 foreach $i (@
$pname) {
564 $title .= $ww unless $ww eq "\001";
569 } elsif ($ptype eq "appn") {
570 # Appendix heading. "Appendix N: Title" followed by a line of
572 $pflags =~ /appn (.*) :(.*)/;
573 $title = "Appendix $1: ";
574 foreach $i (@
$pname) {
576 $title .= $ww unless $ww eq "\001";
581 } elsif ($ptype eq "head" || $ptype eq "subh") {
582 # Heading or subheading. Just a number and some text.
583 $pflags =~ /.... (.*) :(.*)/;
584 $title = sprintf "%6s ", $1;
585 foreach $i (@
$pname) {
587 $title .= $ww unless $ww eq "\001";
590 } elsif ($ptype eq "code") {
591 # Code paragraph. Emit each line with a seven character indent.
592 foreach $i (@
$pname) {
593 warn "code line longer than 68 chars: $i\n" if length $i > 68;
594 print ' 'x7
, $i, "\n";
596 } elsif ($ptype eq "bull" || $ptype eq "norm") {
597 # Ordinary paragraph, optionally bulleted. We wrap, with ragged
598 # 75-char right margin and either 7 or 11 char left margin
599 # depending on bullets.
600 if ($ptype eq "bull") {
601 $line = ' 'x7
. '(*) ';
604 $line = $next = ' 'x7
;
609 do { $w = &word_txt
(shift @a) } while $w eq "\001"; # nasty hack
611 if ($wprev =~ /-$/ || $w eq ' ' || $w eq '' || $w eq undef) {
612 if (length ($line . $wd) > 75) {
613 $line =~ s/\s*$//; # trim trailing spaces
616 $wd =~ s/^\s*//; # trim leading spaces
622 } while ($w ne '' && $w ne undef);
624 $line =~ s/\s*$//; # trim trailing spaces
639 return undef if $w eq '' || $w eq undef;
640 $wtype = substr($w,0,2);
641 $wmajt = substr($wtype,0,1);
643 $w =~ s/<.*>// if $wmajt eq "w"; # remove web links
644 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
646 } elsif ($wtype eq "sp") {
648 } elsif ($wtype eq "da") {
650 } elsif ($wmajt eq "c" || $wtype eq "wc") {
652 } elsif ($wtype eq "es") {
654 } elsif ($wtype eq "ee") {
656 } elsif ($wtype eq "eo") {
658 } elsif ($wmajt eq "x" || $wmajt eq "i") {
661 die "panic in word_txt: $wtype$w\n";
666 # This is called from the top level, so I won't bother using
669 # Write contents file. Just the preamble, then a menu of links to the
670 # separate chapter files and the nodes therein.
671 print "writing contents file...";
672 open TEXT
,">nasmdoc0.html";
675 print "<p>This manual documents NASM, the Netwide Assembler: an assembler\n";
676 print "targetting the Intel x86 series of processors, with portable source.\n";
678 for ($node = $tstruct_next{'Top'}; $node; $node = $tstruct_next{$node}) {
679 if ($tstruct_level{$node} == 1) {
680 # Invent a file name.
681 ($number = lc($xrefnodes{$node})) =~ s/.*-//;
682 $fname="nasmdocx.html";
683 substr($fname,8 - length $number, length $number) = $number;
684 $html_fnames{$node} = $fname;
688 # Use the preceding filename plus a marker point.
689 $link = $fname . "#$xrefnodes{$node}";
692 $pname = $tstruct_pname{$node};
693 foreach $i (@
$pname) {
694 $ww = &word_html
($i);
695 $title .= $ww unless $ww eq "\001";
697 print "<a href=\"$link\">$title</a><br>\n";
699 print "<p><a href=\"nasmdoci.html\">Index</a>\n";
700 print "</body></html>\n";
704 # Open a null file, to ensure output (eg random &html_jumppoints calls)
706 print "writing chapter files...";
707 open TEXT
,">/dev/null";
713 for ($para = 0; $para <= $#pnames; $para++) {
714 $pname = $pnames[$para];
715 $pflags = $pflags[$para];
716 $ptype = substr($pflags,0,4);
718 $in_list = 0, print "</ul>\n" if $in_list && $ptype ne "bull";
719 if ($ptype eq "chap") {
720 # Chapter heading. Begin a new file.
721 $pflags =~ /chap (.*) :(.*)/;
722 $title = "Chapter $1: ";
724 &html_jumppoints
; print "</body></html>\n"; select STDOUT
; close TEXT
;
725 $html_lastf = $html_fnames{$chapternode};
726 $chapternode = $nodexrefs{$xref};
727 $html_nextf = $html_fnames{$tstruct_mnext{$chapternode}};
728 open TEXT
,">$html_fnames{$chapternode}"; select TEXT
; &html_preamble
(1);
729 foreach $i (@
$pname) {
730 $ww = &word_html
($i);
731 $title .= $ww unless $ww eq "\001";
733 $h = "<h2><a name=\"$xref\">$title</a></h2>\n";
734 print $h; print FULL
$h;
735 } elsif ($ptype eq "appn") {
736 # Appendix heading. Begin a new file.
737 $pflags =~ /appn (.*) :(.*)/;
738 $title = "Appendix $1: ";
740 &html_jumppoints
; print "</body></html>\n"; select STDOUT
; close TEXT
;
741 $html_lastf = $html_fnames{$chapternode};
742 $chapternode = $nodexrefs{$xref};
743 $html_nextf = $html_fnames{$tstruct_mnext{$chapternode}};
744 open TEXT
,">$html_fnames{$chapternode}"; select TEXT
; &html_preamble
(1);
745 foreach $i (@
$pname) {
746 $ww = &word_html
($i);
747 $title .= $ww unless $ww eq "\001";
749 print "<h2><a name=\"$xref\">$title</a></h2>\n";
750 } elsif ($ptype eq "head" || $ptype eq "subh") {
751 # Heading or subheading.
752 $pflags =~ /.... (.*) :(.*)/;
753 $hdr = ($ptype eq "subh" ?
"h4" : "h3");
756 foreach $i (@
$pname) {
757 $ww = &word_html
($i);
758 $title .= $ww unless $ww eq "\001";
760 print "<$hdr><a name=\"$xref\">$title</a></$hdr>\n";
761 } elsif ($ptype eq "code") {
764 foreach $i (@
$pname) {
772 } elsif ($ptype eq "bull" || $ptype eq "norm") {
773 # Ordinary paragraph, optionally bulleted. We wrap, with ragged
774 # 75-char right margin and either 7 or 11 char left margin
775 # depending on bullets.
776 if ($ptype eq "bull") {
777 $in_list = 1, print "<ul>\n" unless $in_list;
785 do { $w = &word_html
(shift @a) } while $w eq "\001"; # nasty hack
787 if ($w eq ' ' || $w eq '' || $w eq undef) {
788 if (length ($line . $wd) > 75) {
789 $line =~ s/\s*$//; # trim trailing spaces
792 $wd =~ s/^\s*//; # trim leading spaces
798 } while ($w ne '' && $w ne undef);
800 $line =~ s/\s*$//; # trim trailing spaces
806 # Close whichever file was open.
808 print "</body></html>\n";
812 print "\n writing index file...";
813 open TEXT
,">nasmdoci.html";
816 print "<p align=center><a href=\"nasmdoc0.html\">Contents</a>\n";
819 print "<p align=center><a href=\"nasmdoc0.html\">Contents</a>\n";
820 print "</body></html>\n";
826 print "<html><head><title>NASM Manual</title></head>\n";
827 print "<body><h1 align=center>The Netwide Assembler: NASM</h1>\n\n";
828 &html_jumppoints
if $_[0];
831 sub html_jumppoints
{
832 print "<p align=center>";
833 print "<a href=\"$html_nextf\">Next Chapter</a> |\n" if $html_nextf;
834 print "<a href=\"$html_lastf\">Previous Chapter</a> |\n" if $html_lastf;
835 print "<a href=\"nasmdoc0.html\">Contents</a> |\n";
836 print "<a href=\"nasmdoci.html\">Index</a>\n";
840 my $itag, $a, @ientry, $sep, $w, $wd, $wprev, $line;
843 foreach $itag (@itags) {
844 $ientry = $idxmap{$itag};
848 foreach $node (@nodes) {
849 next if !$idxnodes{$node,$itag};
850 push @a, "n ," if $sep;
851 push @a, "sp", "x $xrefnodes{$node}", "n $node", "xe$xrefnodes{$node}";
856 do { $w = &word_html
(shift @a) } while $w eq "\001"; # nasty hack
858 if ($w eq ' ' || $w eq '' || $w eq undef) {
859 if (length ($line . $wd) > 75) {
860 $line =~ s/\s*$//; # trim trailing spaces
863 $wd =~ s/^\s*//; # trim leading spaces
869 } while ($w ne '' && $w ne undef);
871 $line =~ s/\s*$//; # trim trailing spaces
880 my $wtype, $wmajt, $pfx, $sfx;
882 return undef if $w eq '' || $w eq undef;
884 $wtype = substr($w,0,2);
885 $wmajt = substr($wtype,0,1);
888 $pfx = "<a href=\"$1\">", $sfx = "</a>", $w = $2
889 if $wmajt eq "w" && $w =~ /^<(.*)>(.*)$/;
893 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
894 return $pfx . $w . $sfx;
895 } elsif ($wtype eq "sp") {
897 } elsif ($wtype eq "da") {
898 return '-'; # sadly, en-dashes are non-standard in HTML
899 } elsif ($wmajt eq "c" || $wtype eq "wc") {
900 return $pfx . "<code><nobr>${w}</nobr></code>" . $sfx;
901 } elsif ($wtype eq "es") {
903 } elsif ($wtype eq "ee") {
905 } elsif ($wtype eq "eo") {
906 return "<em>${w}</em>";
907 } elsif ($wtype eq "x ") {
908 # Magic: we must resolve the cross reference into file and marker
909 # parts, then dispose of the file part if it's us, and dispose of
910 # the marker part if the cross reference describes the top node of
912 my $node = $nodexrefs{$w}; # find the node we're aiming at
913 my $level = $tstruct_level{$node}; # and its level
914 my $up = $node, $uplev = $level-1;
915 $up = $tstruct_up{$up} while $uplev--; # get top node of containing file
916 my $file = ($up ne $chapternode) ?
$html_fnames{$up} : "";
917 my $marker = ($level == 1 and $file) ?
"" : "#$w";
918 return "<a href=\"$file$marker\">";
919 } elsif ($wtype eq "xe") {
921 } elsif ($wmajt eq "i") {
924 die "panic in word_html: $wtype$w\n";
929 # This is called from the top level, so I won't bother using
933 print "writing file...";
934 open TEXT
,">nasmdoc.texi";
938 print "\\input texinfo \@c -*-texinfo-*-\n";
939 print "\@c \%**start of header\n";
940 print "\@setfilename ",$metadata{'infofile'},".info\n";
941 print "\@dircategory ",$metadata{'category'},"\n";
942 print "\@direntry\n";
943 printf "* %-28s %s.\n",
944 sprintf('%s: (%s).', $metadata{'infoname'}, $metadata{'infofile'}),
945 $metadata{'infotitle'};
946 print "\@end direntry\n";
947 print "\@settitle ", $metadata{'title'},"\n";
948 print "\@setchapternewpage odd\n";
949 print "\@c \%**end of header\n";
952 print $metadata{'summary'}, "\n";
954 print "Copyright ",$metadata{'year'}," ",$metadata{'author'},"\n";
956 print $metadata{'license'}, "\n";
957 print "\@end ifinfo\n";
959 print "\@titlepage\n";
960 $title = $metadata{'title'};
961 $title =~ s/ - / --- /g;
962 print "\@title ${title}\n";
963 print "\@author ",$metadata{'author'},"\n";
966 print "\@vskip 0pt plus 1filll\n";
967 print "Copyright \@copyright{} ",$metadata{'year'},' ',$metadata{'author'},"\n";
969 print $metadata{'license'}, "\n";
970 print "\@end titlepage\n";
972 print "\@node Top, $tstruct_next{'Top'}, (dir), (dir)\n";
973 print "\@top ",$metadata{'infotitle'},"\n";
976 print $metadata{'summary'}, "\n";
977 print "\@end ifinfo\n";
982 for ($para = 0; $para <= $#pnames; $para++) {
983 $pname = $pnames[$para];
984 $pflags = $pflags[$para];
985 $ptype = substr($pflags,0,4);
987 $bulleting = 0, print "\@end itemize\n" if $bulleting && $ptype ne "bull";
988 print "\n"; # always one of these before a new paragraph
990 if ($ptype eq "chap") {
991 # Chapter heading. Begin a new node.
993 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
994 $pflags =~ /chap (.*) :(.*)/;
995 $node = "Chapter $1";
996 $title = "Chapter $1: ";
997 foreach $i (@
$pname) {
998 $ww = &word_texi
($i);
999 $title .= $ww unless $ww eq "\001";
1001 print "\@node $node, $tstruct_next{$node}, $tstruct_prev{$node},";
1002 print " $tstruct_up{$node}\n\@unnumbered $title\n";
1003 } elsif ($ptype eq "appn") {
1004 # Appendix heading. Begin a new node.
1006 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1007 $pflags =~ /appn (.*) :(.*)/;
1008 $node = "Appendix $1";
1009 $title = "Appendix $1: ";
1010 foreach $i (@
$pname) {
1011 $ww = &word_texi
($i);
1012 $title .= $ww unless $ww eq "\001";
1014 print "\@node $node, $tstruct_next{$node}, $tstruct_prev{$node},";
1015 print " $tstruct_up{$node}\n\@unnumbered $title\n";
1016 } elsif ($ptype eq "head" || $ptype eq "subh") {
1017 # Heading or subheading. Begin a new node.
1019 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1020 $pflags =~ /.... (.*) :(.*)/;
1021 $node = "Section $1";
1023 foreach $i (@
$pname) {
1024 $ww = &word_texi
($i);
1025 $title .= $ww unless $ww eq "\001";
1027 print "\@node $node, $tstruct_next{$node}, $tstruct_prev{$node},";
1028 print " $tstruct_up{$node}\n";
1029 $hdr = ($ptype eq "subh" ?
"\@unnumberedsubsec" : "\@unnumberedsec");
1030 print "$hdr $title\n";
1031 } elsif ($ptype eq "code") {
1032 # Code paragraph. Surround with @example / @end example.
1033 print "\@example\n";
1034 foreach $i (@
$pname) {
1035 warn "code line longer than 68 chars: $i\n" if length $i > 68;
1041 print "\@end example\n";
1042 } elsif ($ptype eq "bull" || $ptype eq "norm") {
1043 # Ordinary paragraph, optionally bulleted. We wrap, FWIW.
1044 if ($ptype eq "bull") {
1045 $bulleting = 1, print "\@itemize \@bullet\n" if !$bulleting;
1052 do { $w = &word_texi
(shift @a); } while $w eq "\001"; # hack
1054 if ($wprev =~ /-$/ || $w eq ' ' || $w eq '' || $w eq undef) {
1055 if (length ($line . $wd) > 75) {
1056 $line =~ s/\s*$//; # trim trailing spaces
1059 $wd =~ s/^\s*//; # trim leading spaces
1065 } while ($w ne '' && $w ne undef);
1066 if ($line =~ /\S/) {
1067 $line =~ s/\s*$//; # trim trailing spaces
1077 print "\n\@contents\n\@bye\n";
1082 # Side effect of this procedure: update global `texiwdlen' to be the length
1083 # in chars of the formatted version of the word.
1088 return undef if $w eq '' || $w eq undef;
1089 $wtype = substr($w,0,2);
1090 $wmajt = substr($wtype,0,1);
1096 $w =~ s/<.*>// if $wmajt eq "w"; # remove web links
1097 substr($w,0,1) =~ tr/a-z/A-Z/, $capital = 0 if $capital;
1098 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
1101 } elsif ($wtype eq "sp") {
1104 } elsif ($wtype eq "da") {
1107 } elsif ($wmajt eq "c" || $wtype eq "wc") {
1108 $texiwdlen = 2 + $wlen;
1109 return "\@code\{$w\}";
1110 } elsif ($wtype eq "es") {
1111 $texiwdlen = 1 + $wlen;
1112 return "\@emph\{${w}";
1113 } elsif ($wtype eq "ee") {
1114 $texiwdlen = 1 + $wlen;
1116 } elsif ($wtype eq "eo") {
1117 $texiwdlen = 2 + $wlen;
1118 return "\@emph\{${w}\}";
1119 } elsif ($wtype eq "x ") {
1120 $texiwdlen = 0; # we don't need it in this case
1121 $capital = 1; # hack
1123 } elsif ($wtype eq "xe") {
1124 $texiwdlen = 0; # we don't need it in this case
1126 } elsif ($wmajt eq "i") {
1127 $texiwdlen = 0; # we don't need it in this case
1130 die "panic in word_texi: $wtype$w\n";
1136 my $item, $i, $mpname, $title, $wd;
1138 $item = $tstruct_next{$topitem};
1142 $mpname = $tstruct_pname{$item};
1143 foreach $i (@
$mpname) {
1144 $wd = &word_texi
($i);
1145 $title .= $wd unless $wd eq "\001";
1147 print "* ${item}:: $title\n";
1148 $item = $tstruct_mnext{$item};
1150 print "* Index::\n" if $topitem eq "Top";
1151 print "\@end menu\n";
1155 my $itag, $ientry, @a, $wd, $item, $len;
1156 my $subnums = "123456789ABCDEFGHIJKLMNOPQRSTU" .
1157 "VWXYZabcdefghijklmnopqrstuvwxyz";
1159 print "\@ifinfo\n\@node Index, , $FIXMElastnode, Top\n";
1160 print "\@unnumbered Index\n\n\@menu\n";
1162 foreach $itag (@itags) {
1163 $ientry = $idxmap{$itag};
1168 $wd = &word_texi
($i);
1169 $item .= $wd, $len += $texiwdlen unless $wd eq "\001";
1172 foreach $node (@nodes) {
1173 next if !$idxnodes{$node,$itag};
1174 printf "* %s%s (%s): %s.\n",
1175 $item, " " x
(40-$len), substr($subnums,$i++,1), $node;
1178 print "\@end menu\n\@end ifinfo\n";
1182 # This is called from the top level, so I won't bother using
1185 # Build the index-tag text forms.
1186 print "building index entries...";
1189 my $ientry = $idxmap{$_};
1191 foreach $i (@
$ientry) {
1192 $ww = &word_hlp
($i,0);
1193 $title .= $ww unless $ww eq "\001";
1198 # Write the HPJ project-description file.
1199 print "writing .hpj file...";
1200 open HPJ
,">nasmdoc.hpj";
1201 print HPJ
"[OPTIONS]\ncompress=true\n";
1202 print HPJ
"title=NASM: The Netwide Assembler\noldkeyphrase=no\n\n";
1203 print HPJ
"[FILES]\nnasmdoc.rtf\n\n";
1204 print HPJ
"[CONFIG]\n";
1205 print HPJ
'CreateButton("btn_up", "&Up",'.
1206 ' "JumpContents(`nasmdoc.hlp'."'".')")';
1207 print HPJ
"\nBrowseButtons()\n";
1211 print "\n writing .rtf file...";
1212 open TEXT
,">nasmdoc.rtf";
1216 print "{\\rtf1\\ansi{\\fonttbl\n";
1217 print "\\f0\\froman Times New Roman;\\f1\\fmodern Courier New;\n";
1218 print "\\f2\\fswiss Arial;\\f3\\ftech Wingdings}\\deff0\n";
1219 print "#{\\footnote Top}\n";
1220 print "\${\\footnote Contents}\n";
1221 print "+{\\footnote browse:00000}\n";
1222 print "!{\\footnote DisableButton(\"btn_up\")}\n";
1223 print "\\keepn\\f2\\b\\fs30\\sb0\n";
1224 print "NASM: The Netwide Assembler\n";
1225 print "\\par\\pard\\plain\\sb120\n";
1226 print "This file documents NASM, the Netwide Assembler: an assembler \n";
1227 print "targetting the Intel x86 series of processors, with portable source.\n";
1232 $newpar = "\\par\\sb120\n";
1233 for ($para = 0; $para <= $#pnames; $para++) {
1234 $pname = $pnames[$para];
1235 $pflags = $pflags[$para];
1236 $ptype = substr($pflags,0,4);
1239 $newpar = "\\par\\sb120\n";
1241 if ($ptype eq "chap") {
1242 # Chapter heading. Begin a new node.
1244 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1245 $pflags =~ /chap (.*) :(.*)/;
1246 $node = "Chapter $1";
1247 $title = $footnotetitle = "Chapter $1: ";
1248 foreach $i (@
$pname) {
1249 $ww = &word_hlp
($i,1);
1250 $title .= $ww, $footnotetitle .= &word_hlp
($i,0) unless $ww eq "\001";
1253 printf "#{\\footnote %s}\n", &hlp_sectkw
($node);
1254 print "\${\\footnote $footnotetitle}\n";
1255 printf "+{\\footnote browse:%05d}\n", ++$browse;
1256 printf "!{\\footnote ChangeButtonBinding(\"btn_up\"," .
1257 "\"JumpId(\`nasmdoc.hlp',\`%s')\");\n",
1258 &hlp_sectkw
($tstruct_up{$node});
1259 print "EnableButton(\"btn_up\")}\n";
1260 &hlp_keywords
($node);
1261 print "\\keepn\\f2\\b\\fs30\\sb60\\sa60\n";
1263 $newpar = "\\par\\pard\\plain\\sb120\n";
1264 } elsif ($ptype eq "appn") {
1265 # Appendix heading. Begin a new node.
1267 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1268 $pflags =~ /appn (.*) :(.*)/;
1269 $node = "Appendix $1";
1270 $title = $footnotetitle = "Appendix $1: ";
1271 foreach $i (@
$pname) {
1272 $ww = &word_hlp
($i,1);
1273 $title .= $ww, $footnotetitle .= &word_hlp
($i,0) unless $ww eq "\001";
1276 printf "#{\\footnote %s}\n", &hlp_sectkw
($node);
1277 print "\${\\footnote $footnotetitle}\n";
1278 printf "+{\\footnote browse:%05d}\n", ++$browse;
1279 printf "!{\\footnote ChangeButtonBinding(\"btn_up\"," .
1280 "\"JumpId(\`nasmdoc.hlp',\`%s')\");\n",
1281 &hlp_sectkw
($tstruct_up{$node});
1282 print "EnableButton(\"btn_up\")}\n";
1283 &hlp_keywords
($node);
1284 print "\\keepn\\f2\\b\\fs30\\sb60\\sa60\n";
1286 $newpar = "\\par\\pard\\plain\\sb120\n";
1287 } elsif ($ptype eq "head" || $ptype eq "subh") {
1288 # Heading or subheading. Begin a new node.
1290 if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
1291 $pflags =~ /.... (.*) :(.*)/;
1292 $node = "Section $1";
1293 $title = $footnotetitle = "$1. ";
1294 foreach $i (@
$pname) {
1295 $ww = &word_hlp
($i,1);
1296 $title .= $ww, $footnotetitle .= &word_hlp
($i,0) unless $ww eq "\001";
1299 printf "#{\\footnote %s}\n", &hlp_sectkw
($node);
1300 print "\${\\footnote $footnotetitle}\n";
1301 printf "+{\\footnote browse:%05d}\n", ++$browse;
1302 printf "!{\\footnote ChangeButtonBinding(\"btn_up\"," .
1303 "\"JumpId(\`nasmdoc.hlp',\`%s')\");\n",
1304 &hlp_sectkw
($tstruct_up{$node});
1305 print "EnableButton(\"btn_up\")}\n";
1306 &hlp_keywords
($node);
1307 print "\\keepn\\f2\\b\\fs30\\sb60\\sa60\n";
1309 $newpar = "\\par\\pard\\plain\\sb120\n";
1310 } elsif ($ptype eq "code") {
1312 print "\\keep\\f1\\sb120\n";
1313 foreach $i (@
$pname) {
1315 warn "code line longer than 68 chars: $i\n" if length $i > 68;
1319 print "$x\\par\\sb0\n";
1321 $newpar = "\\pard\\f0\\sb120\n";
1322 } elsif ($ptype eq "bull" || $ptype eq "norm") {
1323 # Ordinary paragraph, optionally bulleted. We wrap, FWIW.
1324 if ($ptype eq "bull") {
1325 print "\\tx360\\li360\\fi-360{\\f3\\'9F}\\tab\n";
1326 $newpar = "\\par\\pard\\sb120\n";
1328 $newpar = "\\par\\sb120\n";
1334 do { $w = &word_hlp
((shift @a),1); } while $w eq "\001"; # hack
1336 if ($w eq ' ' || $w eq '' || $w eq undef) {
1337 if (length ($line . $wd) > 75) {
1338 $line =~ s/\s*$//; # trim trailing spaces
1339 print "$line \n"; # and put one back
1341 $wd =~ s/^\s*//; # trim leading spaces
1347 } while ($w ne '' && $w ne undef);
1348 if ($line =~ /\S/) {
1349 $line =~ s/\s*$//; # trim trailing spaces
1362 my ($w, $docode) = @_;
1365 return undef if $w eq '' || $w eq undef;
1366 $wtype = substr($w,0,2);
1367 $wmajt = substr($wtype,0,1);
1372 $w =~ s/<.*>// if $wmajt eq "w"; # remove web links
1373 substr($w,0,length($w)-1) =~ s/-/\\\'AD/g if $wmajt ne "x"; #nonbreakhyphens
1374 if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
1376 } elsif ($wtype eq "sp") {
1378 } elsif ($wtype eq "da") {
1380 } elsif ($wmajt eq "c" || $wtype eq "wc") {
1381 $w =~ s/ /\\\'A0/g; # make spaces non-breaking
1382 return $docode ?
"{\\f1 ${w}}" : $w;
1383 } elsif ($wtype eq "es") {
1385 } elsif ($wtype eq "ee") {
1387 } elsif ($wtype eq "eo") {
1388 return "{\\i ${w}}";
1389 } elsif ($wtype eq "x ") {
1391 } elsif ($wtype eq "xe") {
1392 $w = &hlp_sectkw
($w);
1393 return "}{\\v ${w}}";
1394 } elsif ($wmajt eq "i") {
1397 die "panic in word_hlp: $wtype$w\n";
1403 my $item, $kword, $i, $mpname, $title;
1405 $item = $tstruct_next{$topitem};
1406 print "\\li360\\fi-360\n";
1409 $mpname = $tstruct_pname{$item};
1410 foreach $i (@
$mpname) {
1411 $ww = &word_hlp
($i, 0);
1412 $title .= $ww unless $ww eq "\001";
1414 $kword = &hlp_sectkw
($item);
1415 print "{\\uldb ${item}: $title}{\\v $kword}\\par\\sb0\n";
1416 $item = $tstruct_mnext{$item};
1418 print "\\pard\\sb120\n";
1423 $node =~ tr/A-Z/a-z/;
1424 $node =~ tr/- ./___/;
1430 my $pfx = "K{\\footnote ";
1432 foreach $i (0..$#itags) {
1433 (print $pfx,$hlp_index[$i]), $pfx = ";\n", $done++
1434 if $idxnodes{$node,$itags[$i]};
1436 print "}\n" if $done;
1439 # Make tree structures. $tstruct_* is top-level and global.
1441 my ($item, $level) = @_;
1444 $tstruct_pname{$item} = $pname;
1445 $tstruct_next{$tstruct_previtem} = $item;
1446 $tstruct_prev{$item} = $tstruct_previtem;
1447 $tstruct_level{$item} = $level;
1448 $tstruct_up{$item} = $tstruct_last[$level-1];
1449 $tstruct_mnext{$tstruct_last[$level]} = $item;
1450 $tstruct_last[$level] = $item;
1451 for ($i=$level+1; $i<$MAXLEVEL; $i++) { $tstruct_last[$i] = undef; }
1452 $tstruct_previtem = $item;
1457 # This produces documentation intermediate paragraph format; this is
1458 # basically the digested output of the front end. Intended for use
1459 # by future backends, instead of putting it all in the same script.
1462 open(PARAS
, "> nasmdoc.dip");
1463 foreach $k (keys(%metadata)) {
1464 print PARAS
'meta :', $k, "\n";
1465 print PARAS
$metadata{$k},"\n";
1467 for ($para = 0; $para <= $#pnames; $para++) {
1468 print PARAS
$pflags[$para], "\n";
1469 print PARAS
join("\037", @
{$pnames[$para]}, "\n");
1471 foreach $k (@itags) {
1472 print PARAS
'indx :', $k, "\n";
1473 print PARAS
join("\037", @
{$idxmap{$k}}), "\n";