📄 rdsrc.pl
字号:
last FL;
}
}
$cval = undef if $clrcval;
$commanext{$iitem} = $commaafter{$piitem} = 1
if $cval and ($cval eq $pcval);
$piitem = $iitem;
}
}
sub indexdiag {
my $iitem,$ientry,$w,$ww,$foo,$node;
open INDEXDIAG,">index.diag";
foreach $iitem (@itags) {
$ientry = $idxmap{$iitem};
print INDEXDIAG "<$iitem> ";
foreach $w (@$ientry) {
$ww = &word_txt($w);
print INDEXDIAG $ww unless $ww eq "\001";
}
print INDEXDIAG ":";
$foo = " ";
foreach $node (@nodes) {
(print INDEXDIAG $foo,$node), $foo = ", " if $idxnodes{$node,$iitem};
}
print INDEXDIAG "\n";
}
close INDEXDIAG;
}
sub fixup_xrefs {
my $pname, $p, $i, $j, $k, $caps, @repl;
for ($p=0; $p<=$#pnames; $p++) {
next if $pflags[$p] eq "code";
$pname = $pnames[$p];
for ($i=$#$pname; $i >= 0; $i--) {
if ($$pname[$i] =~ /^k/) {
$k = $$pname[$i];
$caps = ($k =~ /^kK/);
$k = substr($k,2);
$repl = $refs{$k};
die "undefined keyword `$k'\n" unless $repl;
substr($repl,0,1) =~ tr/a-z/A-Z/ if $caps;
@repl = ();
push @repl,"x $xrefs{$k}";
foreach $j (split /\s+/,$repl) {
push @repl,"n $j";
push @repl,"sp";
}
pop @repl; # remove final space
push @repl,"xe$xrefs{$k}";
splice @$pname,$i,1,@repl;
}
}
}
}
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -