From 955bdeb223d0148f0a84ef22e5811c81931c0341 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 11 May 2013 15:49:11 +0200 Subject: [PATCH] Fold subj2html.pl into emp2html.pl --- Make.mk | 7 +-- info/emp2html.pl | 57 ++++++++++++++++- info/subj2html.pl | 154 ---------------------------------------------- 3 files changed, 56 insertions(+), 162 deletions(-) delete mode 100644 info/subj2html.pl diff --git a/Make.mk b/Make.mk index 9e222218a..87968b6ba 100644 --- a/Make.mk +++ b/Make.mk @@ -62,8 +62,6 @@ include $(srcdir)/info/subjects.mk # Abbreviations topics := $(patsubst %.t,%,$(notdir $(tsrc))) info := $(topics) $(subjects) all TOP -subjects.html := $(addprefix info.html/, $(addsuffix .html, $(subjects))) -topics.html := $(addprefix info.html/, $(addsuffix .html, $(topics))) scripts := $(srcdir)/src/scripts depcomp := $(SHELL) $(srcdir)/depcomp tarball := $(SHELL) -e $(scripts)/tarball @@ -295,7 +293,7 @@ info.nr/%: info/%.t # Pipes in make are a pain. The "test -s" catches obvious errors. info.html/%.html: info/%.t - perl $(filter %.pl, $^) $< >$@ + perl $(srcdir)/info/emp2html.pl $< >$@ ### Explicit rules @@ -345,8 +343,7 @@ info.html/all.html: info.nr/all info/ls2html.pl $(info.nr): info/CRT.MAC info/INFO.MAC info/Blank.awk -$(subjects.html) info.html/TOP.html: info/subj2html.pl -$(topics.html): info/emp2html.pl +$(info.html): info/emp2html.pl info.ps: info/TROFF.MAC info/INFO.MAC $(ttop) $(tsubj) $(tsrc) groff $^ >$@ diff --git a/info/emp2html.pl b/info/emp2html.pl index ce131d8d6..0cd134246 100644 --- a/info/emp2html.pl +++ b/info/emp2html.pl @@ -1,10 +1,47 @@ -#!/usr/local/bin/perl +#!/usr/bin/perl +# +# Empire - A multi-player, client/server Internet based war game. +# Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak, +# Ken Stevens, Steve McClure, Markus Armbruster +# +# Empire is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# --- +# +# See files README, COPYING and CREDITS in the root of the source +# tree for related information and legal notices. It is expected +# that future projects/authors will amend these files as needed. +# +# --- +# +# emp2html.pl: Convert info source to HTML +# +# Known contributors to this file: +# Drake Diedrich, 1996 +# Markus Armbruster, 2004-2013 +# +# Usage: emp2html.pl [INFO-FILE] +# +# Convert INFO-FILE (or else standard input) to HTML on standard output. use strict; use warnings; +my $in_nf = 0; my $esc = "\\"; my $ignore = 0; +my $is_subj; my @a; print ") { @a = req($_); if (!@a) { + if ($is_subj && $in_nf) { + while ($_ =~ /[A-Za-z0-9\-\.]+/g) { + print htmlify("$`"); + print anchor("$&"); + $_="$'"; + } + } print htmlify($_), "\n" unless $ignore; next line; } @@ -33,6 +77,7 @@ line: while (<>) { if ($a[1] eq "TH") { @a = checkarg(2, @a); + $is_subj = $a[2] eq 'Subject' || $a[2] eq 'Info'; $a[3] = htmlify($a[3]); print "$a[2] : $a[3]\n"; print "\n"; @@ -55,6 +100,12 @@ line: while (<>) { next line; } + if ($a[1] eq "L" && $is_subj) { + $a[2] =~ / /; + print "
" . anchor("$`") . " $'\n"; + next line; + } + if ($a[1] =~ /^LV?$/) { @a = checkarg(1, @a); $a[2] = htmlify($a[2]); @@ -66,8 +117,8 @@ line: while (<>) { if ($a[1] eq "eo") { $esc = 0; next line; } if ($a[1] eq "ec") { $esc = $#a == 1 ? "\\" : $a[2]; next line; } - if ($a[1] =~ /NF|nf/i) { printf (("

\n")); next line; }
-    if ($a[1] =~ /FI|fi/i) { printf (("

\n")); next line; } + if ($a[1] =~ /NF|nf/i) { $in_nf = 1; printf (("

\n")); next line; }
+    if ($a[1] =~ /FI|fi/i) { $in_nf = 0; printf (("

\n")); next line; } if ($a[1] eq "s1") { printf (("


\n")); next line; } if ($a[1] eq "br") { printf "
\n"; next line; } diff --git a/info/subj2html.pl b/info/subj2html.pl deleted file mode 100644 index e5d8cceeb..000000000 --- a/info/subj2html.pl +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; - -my $dome = 0; -my $esc="\\"; -my @a; - -print "\n"; -print "\n"; -print "\n"; - -line: while (<>) { - chomp; # strip record separator - s/([^\\](\\\\)*)\\\".*/$1/g; # strip comments - - @a = req($_); - if (!@a) { - if ($dome) { - while ($_ =~ /[A-Za-z0-9\-\.]+/g) { - print htmlify("$`"); - print anchor("$&"); - $_="$'"; - } - } - print htmlify($_), "\n"; - next line; - } - - # requests - - if ($a[1] eq "TH") { - @a = checkarg(2, @a); - $a[3] = htmlify($a[3]); - print "$a[2] : $a[3]\n"; - print "\n"; - print "\n"; - print "

$a[2] : $a[3]

\n"; - print "

\n"; - next line; - } - - if ($a[1] eq "SY") { - @a = checkarg(1, @a); - $a[2] = htmlify($a[2]); - print "[##:##] Command : $a[2]

\n"; - next line; - } - - if ($a[1] eq "EX") { - my $str = htmlify(join(' ',@a[2..$#a])); - print "
[##:##] Command : $str

\n"; - next line; - } - - if ($a[1] eq "L") { - $a[2] =~ / /; - print "
" . anchor("$`") . " $'\n"; - next line; - } - - if ($a[1] eq "eo") { $esc = 0; next line; } - if ($a[1] eq "ec") { $esc = $#a == 1 ? "\\" : $a[2]; next line; } - - if ($a[1] =~ /NF|nf/i) { $dome = 1; printf (("

\n")); next line; }
-    if ($a[1] =~ /FI|fi/i) { $dome = 0; printf (("

\n")); next line; } - if ($a[1] eq "s1") { printf (("


\n")); next line; } - if ($a[1] eq "br") { printf "
\n"; next line; } - - if ($a[1] eq "SA") { - @a = checkarg(1, @a); - @a = split(/[\: \"\,\.]+/, $a[2]); - for my $a (@a) { - $a = anchor($a); - } - print "

See also : ", join("\n, ", @a), "\n"; - } - - # ignore unknown request -} - -print "\n"; -print "\n"; - -sub req { - local ($_) = @_; - if (/^([\.\'])[ \t]*([^ ]*) *(.*)/) { - my @a = ($1, $2); - $_ = $3; - while (/\G(\"((\\.|[^\\\"])*)(\"|\Z))|\G(([^ ]|\\.)+) */g) { - push(@a, $2 || $5); - } - return @a; - } - return (); -} - -sub checkarg { - my ($n, @a) = @_; - warn "extra arguments for $a[1] ignored" if $#a > $n+1; - warn "missing arguments for $a[1] supplied" if $#a < $n+1; - while ($#a < $n+1) { - push @a, ""; - } - return @a; -} - -sub anchor { - local ($_) = @_; - # FIXME don't create dangling links here - return "$_"; -} - -# Translate HTML special characters into escape sequences -sub htmlify { - local ($_) = @_; - die "funny escape character `$esc' not supported" - if $esc && $esc ne "\\"; - # translate some troff escapes - s/\\&//g if $esc; # zero width space character - # escape HTML special characters - s/\&/&/g; - s/\/>/g; - # delete form feed - s/\f//g; - return $_ unless $esc; - # translate more troff escapes - s/\\e/&\#92;/g; # escape character - # turn quoted strings that look like info names into links - # tacky... - while (/(\\\*Q)([A-Za-z0-9\-\.]+)(\\\*U)/) { - $_ = $` . anchor($2) . "$'"; - } - while (/(\"info )([A-Za-z0-9\-\.]+)/) { - $_ = "$`\"info " . anchor($2) . "$'"; - } - # tranlate more troff escapes and strings - s/\\\*Q//g; - s/\\\*U/<\/em>/g; - s/\\fI//g; - s/\\fR/<\/em><\/em>/g; - s/\\fB//g; - s/\\fP/<\/strong><\/em>/g; - s/\\\*\(bF//g; # bold font - s/\\\*\(pF/<\/strong><\/em>/g; # pica font - s/\\\*\(nF/<\/strong><\/em>/g; # normal font - s/\\\*\(iF//g; # italic font - s/\\\(mu/x/g; # multiply symbol - s/\\ / /g; # non breaking space - return $_; -} -- 2.43.0