3 # Empire - A multi-player, client/server Internet based war game.
4 # Copyright (C) 1986-2013, 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-FILE]
36 # Convert INFO-FILE (or else standard input) to HTML on standard output.
47 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n";
48 print " \"http://www.w3.org/TR/html4/strict.dtd\">\n";
53 chomp; # strip record separator
54 s/((^|[^\\])(\\\\)*)\\\".*/$1/g; # strip comments
59 if ($is_subj && $in_nf) {
60 while ($_ =~ /[A-Za-z0-9\-\.]+/g) {
66 print htmlify($_), "\n" unless $ignore;
72 if ($a[1] eq "ig") { $ignore = 1; next line; }
74 $ignore = 0 if $a[1] eq "..";
80 $is_subj = $a[2] eq 'Subject' || $a[2] eq 'Info';
81 $a[3] = htmlify($a[3]);
82 print "<title>$a[2] : $a[3]</title>\n";
85 print "<h1>$a[2] : $a[3]</h1>\n";
92 $a[2] = htmlify($a[2]);
93 print "<samp>[##:##] Command : </samp><KBD>$a[2]</KBD><p>\n";
98 my $str = htmlify(join(' ',@a[2..$#a]));
99 print "<br><samp>[##:##] Command : </samp><kbd>$str</kbd><p>\n";
103 if ($a[1] eq "L" && $is_subj) {
105 print "<br>" . anchor("$`") . " $'\n";
109 if ($a[1] =~ /^LV?$/) {
110 @a = checkarg(1, @a);
111 $a[2] = htmlify($a[2]);
112 print "<h2>$a[2]</h2>\n";
117 if ($a[1] eq "eo") { $esc = 0; next line; }
118 if ($a[1] eq "ec") { $esc = $#a == 1 ? "\\" : $a[2]; next line; }
120 if ($a[1] =~ /NF|nf/i) { $in_nf = 1; printf (("<p><pre>\n")); next line; }
121 if ($a[1] =~ /FI|fi/i) { $in_nf = 0; printf (("</pre><p>\n")); next line; }
122 if ($a[1] eq "s1") { printf (("<hr><p>\n")); next line; }
123 if ($a[1] eq "br") { printf "<br>\n"; next line; }
126 @a = checkarg(1, @a);
127 @a = split(/[\: \"\,\.]+/, $a[2]);
131 print "<p>See also : ", join("\n, ", @a), "\n";
134 # ignore unknown request
142 if (/^([\.\'])[ \t]*([^ ]*) *(.*)/) {
145 while (/\G(\"((\\.|[^\\\"])*)(\"|\Z))|\G(([^ ]|\\.)+) */g) {
155 warn "extra arguments for $a[1] ignored" if $#a > $n+1;
156 warn "missing arguments for $a[1] supplied" if $#a < $n+1;
165 # FIXME don't create dangling links here
166 return "<a href=\"$_.html\">$_</a>";
169 # Translate HTML special characters into escape sequences
172 die "funny escape character `$esc' not supported"
173 if $esc && $esc ne "\\";
174 # translate some troff escapes
175 s/\\&//g if $esc; # zero width space character
176 # escape HTML special characters
180 return $_ unless $esc;
181 # translate more troff escapes
182 s/\\e/&\#92;/g; # escape character
183 # turn quoted strings that look like info names into links
185 while (/\\\*Q([A-Za-z0-9\-\.]+)\\\*U|\"info ([A-Za-z0-9\-\.]+)\"/) {
187 $_ = $` . anchor($1) . "$'";
189 $_ = "$`\"info " . anchor($2) . "\"$'";
192 # tranlate more troff escapes and strings
196 s/\\fR/<\/em><\/em>/g;
198 s/\\fP/<\/strong><\/em>/g;
199 s/\\\*\(bF/<strong>/g; # bold font
200 s/\\\*\(pF/<\/strong><\/em>/g; # pica font
201 s/\\\*\(nF/<\/strong><\/em>/g; # normal font
202 s/\\\*\(iF/<em>/g; # italic font
203 s/\\\(mu/x/g; # multiply symbol
204 s/\\ / /g; # non breaking space