📄 rdsrc.pl
字号:
}
}
}
sub write_txt {
# This is called from the top level, so I won't bother using
# my or local.
# Open file.
print "writing file...";
open TEXT,">nasmdoc.txt";
select TEXT;
# Preamble.
$title = "The Netwide Assembler: NASM";
$spaces = ' ' x ((75-(length $title))/2);
($underscore = $title) =~ s/./=/g;
print "$spaces$title\n$spaces$underscore\n";
for ($para = 0; $para <= $#pnames; $para++) {
$pname = $pnames[$para];
$pflags = $pflags[$para];
$ptype = substr($pflags,0,4);
print "\n"; # always one of these before a new paragraph
if ($ptype eq "chap") {
# Chapter heading. "Chapter N: Title" followed by a line of
# minus signs.
$pflags =~ /chap (.*) :(.*)/;
$title = "Chapter $1: ";
foreach $i (@$pname) {
$ww = &word_txt($i);
$title .= $ww unless $ww eq "\001";
}
print "$title\n";
$title =~ s/./-/g;
print "$title\n";
} elsif ($ptype eq "appn") {
# Appendix heading. "Appendix N: Title" followed by a line of
# minus signs.
$pflags =~ /appn (.*) :(.*)/;
$title = "Appendix $1: ";
foreach $i (@$pname) {
$ww = &word_txt($i);
$title .= $ww unless $ww eq "\001";
}
print "$title\n";
$title =~ s/./-/g;
print "$title\n";
} elsif ($ptype eq "head" || $ptype eq "subh") {
# Heading or subheading. Just a number and some text.
$pflags =~ /.... (.*) :(.*)/;
$title = sprintf "%6s ", $1;
foreach $i (@$pname) {
$ww = &word_txt($i);
$title .= $ww unless $ww eq "\001";
}
print "$title\n";
} elsif ($ptype eq "code") {
# Code paragraph. Emit each line with a seven character indent.
foreach $i (@$pname) {
warn "code line longer than 68 chars: $i\n" if length $i > 68;
print ' 'x7, $i, "\n";
}
} elsif ($ptype eq "bull" || $ptype eq "norm") {
# Ordinary paragraph, optionally bulleted. We wrap, with ragged
# 75-char right margin and either 7 or 11 char left margin
# depending on bullets.
if ($ptype eq "bull") {
$line = ' 'x7 . '(*) ';
$next = ' 'x11;
} else {
$line = $next = ' 'x7;
}
@a = @$pname;
$wd = $wprev = '';
do {
do { $w = &word_txt(shift @a) } while $w eq "\001"; # nasty hack
$wd .= $wprev;
if ($wprev =~ /-$/ || $w eq ' ' || $w eq '' || $w eq undef) {
if (length ($line . $wd) > 75) {
$line =~ s/\s*$//; # trim trailing spaces
print "$line\n";
$line = $next;
$wd =~ s/^\s*//; # trim leading spaces
}
$line .= $wd;
$wd = '';
}
$wprev = $w;
} while ($w ne '' && $w ne undef);
if ($line =~ /\S/) {
$line =~ s/\s*$//; # trim trailing spaces
print "$line\n";
}
}
}
# Close file.
select STDOUT;
close TEXT;
}
sub word_txt {
my ($w) = @_;
my $wtype, $wmajt;
return undef if $w eq '' || $w eq undef;
$wtype = substr($w,0,2);
$wmajt = substr($wtype,0,1);
$w = substr($w,2);
$w =~ s/<.*>// if $wmajt eq "w"; # remove web links
if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
return $w;
} elsif ($wtype eq "sp") {
return ' ';
} elsif ($wtype eq "da") {
return '-';
} elsif ($wmajt eq "c" || $wtype eq "wc") {
return "`${w}'";
} elsif ($wtype eq "es") {
return "_${w}";
} elsif ($wtype eq "ee") {
return "${w}_";
} elsif ($wtype eq "eo") {
return "_${w}_";
} elsif ($wmajt eq "x" || $wmajt eq "i") {
return "\001";
} else {
die "panic in word_txt: $wtype$w\n";
}
}
sub write_html {
# This is called from the top level, so I won't bother using
# my or local.
# Write contents file. Just the preamble, then a menu of links to the
# separate chapter files and the nodes therein.
print "writing contents file...";
open TEXT,">nasmdoc0.html";
select TEXT;
&html_preamble(0);
print "<p>This manual documents NASM, the Netwide Assembler: an assembler\n";
print "targetting the Intel x86 series of processors, with portable source.\n";
print "<p>";
for ($node = $tstruct_next{'Top'}; $node; $node = $tstruct_next{$node}) {
if ($tstruct_level{$node} == 1) {
# Invent a file name.
($number = lc($xrefnodes{$node})) =~ s/.*-//;
$fname="nasmdocx.html";
substr($fname,8 - length $number, length $number) = $number;
$html_fnames{$node} = $fname;
$link = $fname;
print "<p>";
} else {
# Use the preceding filename plus a marker point.
$link = $fname . "#$xrefnodes{$node}";
}
$title = "$node: ";
$pname = $tstruct_pname{$node};
foreach $i (@$pname) {
$ww = &word_html($i);
$title .= $ww unless $ww eq "\001";
}
print "<a href=\"$link\">$title</a><br>\n";
}
print "<p><a href=\"nasmdoci.html\">Index</a>\n";
print "</body></html>\n";
select STDOUT;
close TEXT;
# Open a null file, to ensure output (eg random &html_jumppoints calls)
# goes _somewhere_.
print "writing chapter files...";
open TEXT,">/dev/null";
select TEXT;
$html_lastf = '';
$in_list = 0;
for ($para = 0; $para <= $#pnames; $para++) {
$pname = $pnames[$para];
$pflags = $pflags[$para];
$ptype = substr($pflags,0,4);
$in_list = 0, print "</ul>\n" if $in_list && $ptype ne "bull";
if ($ptype eq "chap") {
# Chapter heading. Begin a new file.
$pflags =~ /chap (.*) :(.*)/;
$title = "Chapter $1: ";
$xref = $2;
&html_jumppoints; print "</body></html>\n"; select STDOUT; close TEXT;
$html_lastf = $html_fnames{$chapternode};
$chapternode = $nodexrefs{$xref};
$html_nextf = $html_fnames{$tstruct_mnext{$chapternode}};
open TEXT,">$html_fnames{$chapternode}"; select TEXT; &html_preamble(1);
foreach $i (@$pname) {
$ww = &word_html($i);
$title .= $ww unless $ww eq "\001";
}
$h = "<h2><a name=\"$xref\">$title</a></h2>\n";
print $h; print FULL $h;
} elsif ($ptype eq "appn") {
# Appendix heading. Begin a new file.
$pflags =~ /appn (.*) :(.*)/;
$title = "Appendix $1: ";
$xref = $2;
&html_jumppoints; print "</body></html>\n"; select STDOUT; close TEXT;
$html_lastf = $html_fnames{$chapternode};
$chapternode = $nodexrefs{$xref};
$html_nextf = $html_fnames{$tstruct_mnext{$chapternode}};
open TEXT,">$html_fnames{$chapternode}"; select TEXT; &html_preamble(1);
foreach $i (@$pname) {
$ww = &word_html($i);
$title .= $ww unless $ww eq "\001";
}
print "<h2><a name=\"$xref\">$title</a></h2>\n";
} elsif ($ptype eq "head" || $ptype eq "subh") {
# Heading or subheading.
$pflags =~ /.... (.*) :(.*)/;
$hdr = ($ptype eq "subh" ? "h4" : "h3");
$title = $1 . " ";
$xref = $2;
foreach $i (@$pname) {
$ww = &word_html($i);
$title .= $ww unless $ww eq "\001";
}
print "<$hdr><a name=\"$xref\">$title</a></$hdr>\n";
} elsif ($ptype eq "code") {
# Code paragraph.
print "<p><pre>\n";
foreach $i (@$pname) {
$w = $i;
$w =~ s/&/&/g;
$w =~ s/</</g;
$w =~ s/>/>/g;
print $w, "\n";
}
print "</pre>\n";
} elsif ($ptype eq "bull" || $ptype eq "norm") {
# Ordinary paragraph, optionally bulleted. We wrap, with ragged
# 75-char right margin and either 7 or 11 char left margin
# depending on bullets.
if ($ptype eq "bull") {
$in_list = 1, print "<ul>\n" unless $in_list;
$line = '<li>';
} else {
$line = '<p>';
}
@a = @$pname;
$wd = $wprev = '';
do {
do { $w = &word_html(shift @a) } while $w eq "\001"; # nasty hack
$wd .= $wprev;
if ($w eq ' ' || $w eq '' || $w eq undef) {
if (length ($line . $wd) > 75) {
$line =~ s/\s*$//; # trim trailing spaces
print "$line\n";
$line = '';
$wd =~ s/^\s*//; # trim leading spaces
}
$line .= $wd;
$wd = '';
}
$wprev = $w;
} while ($w ne '' && $w ne undef);
if ($line =~ /\S/) {
$line =~ s/\s*$//; # trim trailing spaces
print "$line\n";
}
}
}
# Close whichever file was open.
&html_jumppoints;
print "</body></html>\n";
select STDOUT;
close TEXT;
print "\n writing index file...";
open TEXT,">nasmdoci.html";
select TEXT;
&html_preamble(0);
print "<p align=center><a href=\"nasmdoc0.html\">Contents</a>\n";
print "<p>";
&html_index;
print "<p align=center><a href=\"nasmdoc0.html\">Contents</a>\n";
print "</body></html>\n";
select STDOUT;
close TEXT;
}
sub html_preamble {
print "<html><head><title>NASM Manual</title></head>\n";
print "<body><h1 align=center>The Netwide Assembler: NASM</h1>\n\n";
&html_jumppoints if $_[0];
}
sub html_jumppoints {
print "<p align=center>";
print "<a href=\"$html_nextf\">Next Chapter</a> |\n" if $html_nextf;
print "<a href=\"$html_lastf\">Previous Chapter</a> |\n" if $html_lastf;
print "<a href=\"nasmdoc0.html\">Contents</a> |\n";
print "<a href=\"nasmdoci.html\">Index</a>\n";
}
sub html_index {
my $itag, $a, @ientry, $sep, $w, $wd, $wprev, $line;
$chapternode = '';
foreach $itag (@itags) {
$ientry = $idxmap{$itag};
@a = @$ientry;
push @a, "n :";
$sep = 0;
foreach $node (@nodes) {
next if !$idxnodes{$node,$itag};
push @a, "n ," if $sep;
push @a, "sp", "x $xrefnodes{$node}", "n $node", "xe$xrefnodes{$node}";
$sep = 1;
}
$line = '';
do {
do { $w = &word_html(shift @a) } while $w eq "\001"; # nasty hack
$wd .= $wprev;
if ($w eq ' ' || $w eq '' || $w eq undef) {
if (length ($line . $wd) > 75) {
$line =~ s/\s*$//; # trim trailing spaces
print "$line\n";
$line = '';
$wd =~ s/^\s*//; # trim leading spaces
}
$line .= $wd;
$wd = '';
}
$wprev = $w;
} while ($w ne '' && $w ne undef);
if ($line =~ /\S/) {
$line =~ s/\s*$//; # trim trailing spaces
print "$line\n";
}
print "<br>\n";
}
}
sub word_html {
my ($w) = @_;
my $wtype, $wmajt, $pfx, $sfx;
return undef if $w eq '' || $w eq undef;
$wtype = substr($w,0,2);
$wmajt = substr($wtype,0,1);
$w = substr($w,2);
$pfx = $sfx = '';
$pfx = "<a href=\"$1\">", $sfx = "</a>", $w = $2
if $wmajt eq "w" && $w =~ /^<(.*)>(.*)$/;
$w =~ s/&/&/g;
$w =~ s/</</g;
$w =~ s/>/>/g;
if ($wmajt eq "n" || $wtype eq "e " || $wtype eq "w ") {
return $pfx . $w . $sfx;
} elsif ($wtype eq "sp") {
return ' ';
} elsif ($wtype eq "da") {
return '-'; # sadly, en-dashes are non-standard in HTML
} elsif ($wmajt eq "c" || $wtype eq "wc") {
return $pfx . "<code><nobr>${w}</nobr></code>" . $sfx;
} elsif ($wtype eq "es") {
return "<em>${w}";
} elsif ($wtype eq "ee") {
return "${w}</em>";
} elsif ($wtype eq "eo") {
return "<em>${w}</em>";
} elsif ($wtype eq "x ") {
# Magic: we must resolve the cross reference into file and marker
# parts, then dispose of the file part if it's us, and dispose of
# the marker part if the cross reference describes the top node of
# another file.
my $node = $nodexrefs{$w}; # find the node we're aiming at
my $level = $tstruct_level{$node}; # and its level
my $up = $node, $uplev = $level-1;
$up = $tstruct_up{$up} while $uplev--; # get top node of containing file
my $file = ($up ne $chapternode) ? $html_fnames{$up} : "";
my $marker = ($level == 1 and $file) ? "" : "#$w";
return "<a href=\"$file$marker\">";
} elsif ($wtype eq "xe") {
return "</a>";
} elsif ($wmajt eq "i") {
return "\001";
} else {
die "panic in word_html: $wtype$w\n";
}
}
sub write_texi {
# This is called from the top level, so I won't bother using
# my or local.
# Open file.
print "writing file...";
open TEXT,">nasmdoc.texi";
select TEXT;
# Preamble.
print "\\input texinfo \@c -*-texinfo-*-\n";
print "\@c \%**start of header\n";
print "\@setfilename ",$metadata{'infofile'},".info\n";
print "\@dircategory ",$metadata{'category'},"\n";
print "\@direntry\n";
printf "* %-28s %s.\n",
sprintf('%s: (%s).', $metadata{'infoname'}, $metadata{'infofile'}),
$metadata{'infotitle'};
print "\@end direntry\n";
print "\@settitle ", $metadata{'title'},"\n";
print "\@setchapternewpage odd\n";
print "\@c \%**end of header\n";
print "\n";
print "\@ifinfo\n";
print $metadata{'summary'}, "\n";
print "\n";
print "Copyright ",$metadata{'year'}," ",$metadata{'author'},"\n";
print "\n";
print $metadata{'license'}, "\n";
print "\@end ifinfo\n";
print "\n";
print "\@titlepage\n";
$title = $metadata{'title'};
$title =~ s/ - / --- /g;
print "\@title ${title}\n";
print "\@author ",$metadata{'author'},"\n";
print "\n";
print "\@page\n";
print "\@vskip 0pt plus 1filll\n";
print "Copyright \@copyright{} ",$metadata{'year'},' ',$metadata{'author'},"\n";
print "\n";
print $metadata{'license'}, "\n";
print "\@end titlepage\n";
print "\n";
print "\@node Top, $tstruct_next{'Top'}, (dir), (dir)\n";
print "\@top ",$metadata{'infotitle'},"\n";
print "\n";
print "\@ifinfo\n";
print $metadata{'summary'}, "\n";
print "\@end ifinfo\n";
$node = "Top";
$bulleting = 0;
for ($para = 0; $para <= $#pnames; $para++) {
$pname = $pnames[$para];
$pflags = $pflags[$para];
$ptype = substr($pflags,0,4);
$bulleting = 0, print "\@end itemize\n" if $bulleting && $ptype ne "bull";
print "\n"; # always one of these before a new paragraph
if ($ptype eq "chap") {
# Chapter heading. Begin a new node.
&texi_menu($node)
if $tstruct_level{$tstruct_next{$node}} > $tstruct_level{$node};
$pflags =~ /chap (.*) :(.*)/;
$node = "Chapter $1";
$title = "Chapter $1: ";
foreach $i (@$pname) {
$ww = &word_texi($i);
$title .= $ww unless $ww eq "\001";
}
print "\@node $node, $tstruct_next{$node}, $tstruct_prev{$node},";
print " $tstruct_up{$node}\n\@unnumbered $title\n";
} elsif ($ptype eq "appn") {
# Appendix heading. Begin a new node.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -