3 # Empire - A multi-player, client/server Internet based war game.
4 # Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
5 # Ken Stevens, Steve McClure, Markus Armbruster
7 # Empire is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # See files README, COPYING and CREDITS in the root of the source
23 # tree for related information and legal notices. It is expected
24 # that future projects/authors will amend these files as needed.
28 # emp2html.pl: Convert info source to HTML
30 # Known contributors to this file:
31 # Drake Diedrich, 1996
32 # Markus Armbruster, 2004-2013
34 # Usage: emp2html.pl INFO...
36 # Convert info source on standard input to HTML on standard output.
37 # INFO... are the info page names.
53 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n";
54 print " \"http://www.w3.org/TR/html4/strict.dtd\">\n";
58 line: while (<STDIN>) {
59 chomp; # strip record separator
60 s/((^|[^\\])(\\\\)*)\\\".*/$1/g; # strip comments
65 if ($is_subj && $in_nf) {
66 while ($_ =~ /[A-Za-z0-9\-\.]+/g) {
72 print htmlify($_), "\n" unless $ignore;
78 if ($a[1] eq "ig") { $ignore = 1; next line; }
80 $ignore = 0 if $a[1] eq "..";
86 $is_subj = $a[2] eq 'Subject' || $a[2] eq 'Info';
87 $a[3] = htmlify($a[3]);
88 print "<title>$a[2] : $a[3]</title>\n";
91 print "<h1>$a[2] : $a[3]</h1>\n";
98 $a[2] = htmlify($a[2]);
99 print "<samp>[##:##] Command : </samp><KBD>$a[2]</KBD><p>\n";
104 my $str = htmlify(join(' ',@a[2..$#a]));
105 print "<br><samp>[##:##] Command : </samp><kbd>$str</kbd><p>\n";
109 if ($a[1] eq "L" && $is_subj) {
111 print "<br>" . anchor("$`") . " $'\n";
115 if ($a[1] =~ /^LV?$/) {
116 @a = checkarg(1, @a);
117 $a[2] = htmlify($a[2]);
118 print "<h2>$a[2]</h2>\n";
123 if ($a[1] eq "eo") { $esc = 0; next line; }
124 if ($a[1] eq "ec") { $esc = $#a == 1 ? "\\" : $a[2]; next line; }
126 if ($a[1] =~ /NF|nf/i) { $in_nf = 1; printf (("<p><pre>\n")); next line; }
127 if ($a[1] =~ /FI|fi/i) { $in_nf = 0; printf (("</pre><p>\n")); next line; }
128 if ($a[1] eq "s1") { printf (("<hr><p>\n")); next line; }
129 if ($a[1] eq "br") { printf "<br>\n"; next line; }
132 @a = checkarg(1, @a);
133 @a = split(/[\: \"\,\.]+/, $a[2]);
137 print "<p>See also : ", join("\n, ", @a), "\n";
140 # ignore unknown request
148 if (/^([\.\'])[ \t]*([^ ]*) *(.*)/) {
151 while (/\G(\"((\\.|[^\\\"])*)(\"|\Z))|\G(([^ ]|\\.)+) */g) {
161 warn "extra arguments for $a[1] ignored" if $#a > $n+1;
162 warn "missing arguments for $a[1] supplied" if $#a < $n+1;
171 return $topic{$_} ? "<a href=\"$_.html\">$_</a>" : $_;
174 # Translate HTML special characters into escape sequences
177 die "funny escape character `$esc' not supported"
178 if $esc && $esc ne "\\";
179 # translate some troff escapes
180 s/\\&//g if $esc; # zero width space character
181 # escape HTML special characters
185 return $_ unless $esc;
186 # translate more troff escapes
187 s/\\e/&\#92;/g; # escape character
188 # turn quoted strings that look like info names into links
191 while (/\\\*Q([A-Za-z0-9\-\.]+)\\\*U|\"info ([A-Za-z0-9\-\.]+)\"/) {
192 if (defined $1 && $topic{$1}) {
193 $pfx = $` . anchor($1);
194 } elsif (defined $2 && $topic{$2}) {
195 $pfx = "$`\"info " . anchor($2) . "\"";
202 # tranlate more troff escapes and strings
206 s/\\fR/<\/em><\/em>/g;
208 s/\\fP/<\/strong><\/em>/g;
209 s/\\\*\(bF/<strong>/g; # bold font
210 s/\\\*\(pF/<\/strong><\/em>/g; # pica font
211 s/\\\*\(nF/<\/strong><\/em>/g; # normal font
212 s/\\\*\(iF/<em>/g; # italic font
213 s/\\\(mu/x/g; # multiply symbol
214 s/\\ / /g; # non breaking space