]> git.pond.sub.org Git - empserver/blobdiff - info/subj2html.pl
New info Hvy-Plastic
[empserver] / info / subj2html.pl
index 76354030be1fe2d3092630e1d7b92b5ae335c018..e5d8cceebef16224558e0d54653a18e242ff7966 100644 (file)
@@ -7,12 +7,16 @@ my $dome = 0;
 my $esc="\\";
 my @a;
 
+print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n";
+print "   \"http://www.w3.org/TR/html4/strict.dtd\">\n";
+print "<html>\n";
+print "<head>\n";
+
 line: while (<>) {
     chomp;                     # strip record separator
-    s/([^\\](\\\\)*)\\\".*/$1/g;# strip comments
+    s/([^\\](\\\\)*)\\\".*/$1/g; # strip comments
 
     @a = req($_);
-
     if (!@a) {
        if ($dome) {
            while ($_ =~ /[A-Za-z0-9\-\.]+/g) {
@@ -30,7 +34,11 @@ line: while (<>) {
     if ($a[1] eq "TH") {
        @a = checkarg(2, @a);
        $a[3] = htmlify($a[3]);
-       print "<title>$a[2] : $a[3]</title><h1>$a[2] : $a[3]</h1>\n";
+       print "<title>$a[2] : $a[3]</title>\n";
+       print "</head>\n";
+       print "<body>\n";
+       print "<h1>$a[2] : $a[3]</h1>\n";
+       print "<p>\n";
        next line;
     }
 
@@ -53,14 +61,13 @@ line: while (<>) {
        next line;
     }
 
-    if ($a[1] =~ "eo") { $esc = 0; next line; }
-    if ($a[1] =~ "ec") { $esc = $#a == 1 ? "\\" : $a[2]; next line; }
+    if ($a[1] eq "eo") { $esc = 0; next line; }
+    if ($a[1] eq "ec") { $esc = $#a == 1 ? "\\" : $a[2]; next line; }
 
-    if (/^\.(NF|nf)/) { $dome = 1; printf (("<p><pre>\n")); next line; }
-    if (/^\.(FI|fi)/) { $dome = 0; printf (("</pre><p>\n")); next line; }
-    if (/^\.s3/) { printf (("<p>\n")); next line; }
-    if (/^\.s1/) { printf (("<hr> \n")); next line; }
-    if (/^\.br/) { printf "<br>\n"; next line; }
+    if ($a[1] =~ /NF|nf/i) { $dome = 1; printf (("<p><pre>\n")); next line; }
+    if ($a[1] =~ /FI|fi/i) { $dome = 0; printf (("</pre><p>\n")); next line; }
+    if ($a[1] eq "s1") { printf (("<hr><p>\n")); next line; }
+    if ($a[1] eq "br") { printf "<br>\n"; next line; }
 
     if ($a[1] eq "SA") {
        @a = checkarg(1, @a);
@@ -74,12 +81,15 @@ line: while (<>) {
     # ignore unknown request
 }
 
+print "</body>\n";
+print "</html>\n";
+
 sub req {
     local ($_) = @_;
-    if (/^([\.\'])[ \t]*([^ ]+) *(.*)/) {
+    if (/^([\.\'])[ \t]*([^ ]*) *(.*)/) {
        my @a = ($1, $2);
        $_ = $3;
-       while (/(\"((\\.|[^\\\"])*)(\"|$))|(([^ ]|\\.)+) */g) {
+       while (/\G(\"((\\.|[^\\\"])*)(\"|\Z))|\G(([^ ]|\\.)+) */g) {
            push(@a, $2 || $5);
        }
        return @a;
@@ -105,38 +115,40 @@ sub anchor {
 
 # 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/\&/&amp;/g;
-        s/\</&lt;/g;
-        s/\>/&gt;/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/<em>/g;
-        s/\\\*U/<\/em>/g;
-        s/\\fI/<em>/g;
-        s/\\fR/<\/em><\/em>/g;
-        s/\\fB/<strong>/g;
-        s/\\fP/<\/strong><\/em>/g;
-       s/\\\*\(bF/<strong>/g;  # bold font
-       s/\\\*\(pF/<\/strong><\/em>/g; # pica font
-       s/\\\*\(nF/<\/strong><\/em>/g; # normal font
-       s/\\\*\(iF/<em>/g;      # italic font
-       s/\\\(mu/x/g;           # multiply symbol
-       s/\\ /&nbsp;/g;         # non breaking space
-        return $_;
+    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/\&/&amp;/g;
+    s/\</&lt;/g;
+    s/\>/&gt;/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/<em>/g;
+    s/\\\*U/<\/em>/g;
+    s/\\fI/<em>/g;
+    s/\\fR/<\/em><\/em>/g;
+    s/\\fB/<strong>/g;
+    s/\\fP/<\/strong><\/em>/g;
+    s/\\\*\(bF/<strong>/g;     # bold font
+    s/\\\*\(pF/<\/strong><\/em>/g; # pica font
+    s/\\\*\(nF/<\/strong><\/em>/g; # normal font
+    s/\\\*\(iF/<em>/g;         # italic font
+    s/\\\(mu/x/g;              # multiply symbol
+    s/\\ /&nbsp;/g;            # non breaking space
+    return $_;
 }