]> git.pond.sub.org Git - empserver/blob - info/emp2html.pl
Import of Empire 4.2.12
[empserver] / info / emp2html.pl
1 #!/usr/local/bin/perl
2
3
4 $[ = 1;                 # set array base to 1
5
6 line: while (<>) {
7     chop;       # strip record separator
8     @Fld = split(' ', $_, 9999);
9
10 procline:
11     if (/^\.TH/) {
12         $str=$Fld[3];
13         for ($i=4;$i <= $#Fld; $i++) {
14             $str .= " " . $Fld[$i];
15         }
16         $str = &htmlify($str);
17         printf("<title>%s : %s</title><h1>%s : %s</h1>\n",
18                $Fld[2],$str,$Fld[2], $str);
19         next line;
20     }
21
22     if (/^\.SY/) {
23 #       $i = $_ =~ "\"" && ($RLENGTH = length($&), $RSTART = length($`)+1);
24 #       $str = substr($_, $i + 1, length($_) - $i - 1);
25         $str = substr($_,5);
26         $str = &htmlify($str);
27         printf "<samp>[##:##] </samp><KBD>%s</KBD><p>\n", $str;
28         next line;
29     }
30
31     if (/^\.EX/) {
32         $str = substr($_, 5);
33         printf "<br><samp>[##:##] </samp><kbd>%s</kbd><p>\n", &htmlify($str);
34         next line;
35     }
36
37     if (/^\.L/) {
38         $str = substr($_, 4);
39         printf "<h2>%s</h2>\n", &htmlify($str);
40         next line;
41     }
42
43     if (/^\.(NF|nf)/) { printf (("<p><pre>\n")); next line;    }
44     if (/^\.(FI|fi)/) { printf (("</pre><p>\n")); next line;   }
45     if (/^\.s3/) { printf (("<p>\n"));  next line; }
46     if (/^\.s1/) {printf (("<hr> \n")); next line; }
47     if (/^\.br/) { printf "<br>\n"; next line; }
48     if (/^\.SA/) {
49         @a = split('[: ",.]+');
50
51         printf("See also : %s\n",&anchor($a[3]) );
52         for ($i = 4; $i <= $#a ; ($i)++) {       
53             printf(", %s\n",&anchor($a[$i]));
54         }
55
56         while (<>) {
57             chop;       # strip record separator
58             @a = split('[: ,.]+');
59             @Fld = split(' ', $_, 9999);
60             if (/^\./) { goto procline; }
61             for ($i = 1; $i <= $#a ; ($i)++) {       
62                 printf(", %s\n",&anchor($a[$i]));
63             }
64         }
65             
66         exit(0);
67     }
68             
69     if (/^\./) {        next line; }
70
71     if (/^(See also|See Also|see also)/) {
72         @a = split('[: ,.]+');
73
74         printf("See also : %s\n",&anchor($a[3]) );
75         for ($i = 4; $i <= $#a ; ($i)++) {       
76             printf(", %s\n",&anchor($a[$i]));
77         }
78
79         while (<>) {
80             chop;       # strip record separator
81             @a = split('[: ,.]+');
82             @Fld = split(' ', $_, 9999);
83             if (/^\./) { goto procline; }
84             for ($i = 1; $i <= $#a ; ($i)++) {       
85                 printf(", %s\n",&anchor($a[$i]));
86             }
87         }
88             
89         exit(0);
90     }
91             
92     printf "%s\n", &htmlify($_);
93 }
94
95 #sub anchor {
96 #    local($_) = @_;
97 #    $file = $_ . ".t";
98 #    if (-r $file) {
99 #       return ("<a href=" . $_ . ".html" . ">" . $_ . "</a>");
100 #    } else {
101 #       return ( " " . $_ . " ");
102 #    }
103 #}
104
105 sub anchor {
106     local($_) = @_;
107     local(@file,$file);
108     $file = $_ . ".t";
109 #    if (-r $file) {
110     if (1) {
111       $file =~ s/.t$/.html/;
112       return ("<a href=\"$file\">$_</a>");
113     } else {
114         @file = <$_*t>;
115         if (@file) {
116           warn "Expanding $_ to $file[$[]\n";
117           $file[$[] =~ s/.t$/.html/;
118           return ("<a href=\"$file[$[]\">$_</a>");
119         } else {
120           warn "Unable to link $_\n";
121           return ( "<em>$_</em>");
122         }
123     }
124 }
125
126     
127 # Translate HTML special characters into escape sequences
128 sub htmlify {
129         local($_) = @_;
130         s/^\"(.*)\"$/$1/;
131         s/\\&//g;               # a nothing character
132         s/\&/&amp;/g;
133         s/\</&lt;/g;
134         s/\>/&gt;/g;
135         while (@a = /(\\\*Q)([A-Za-z0-9\-\.]+)(\\\*U)/) {
136             /(\\\*Q)([A-Za-z\-]+)(\\\*U)/;
137             $_ = $` . &anchor($a[2]) . $';
138         }
139         while (@a = /(\\\*Q)(\"info )([A-Za-z0-9\-\.]+)(\\\*U)/) {
140             /(\\\*Q)(\"info )([\w\-\.]+)(\\\*U)/;
141             $_ = $` . "\"info " . &anchor($a[3]) . $';
142         }
143         while (@a = /(\"info )([A-Za-z0-9\-\.]+)/) {
144             /(\"info )([\w\-\.]+)/;
145             $_ = $` . "\"info " . &anchor($a[2]) . $';
146         }
147         s/\\\*Q/<em>/g;
148         s/\\\*U/<\/em>/g;
149         s/\\fI/<em>/g;
150         s/\\fR/<\/em><\/em>/g;
151         s/\\fB/<strong>/g;
152         s/\\fP/<\/strong><\/em>/g;
153         s/\\\*\(bF/<strong>/g;  # bold font
154         s/\\\*\(pF/<\/strong><\/em>/g; # pica font
155         s/\\\*\(nF/<\/strong><\/em>/g; # normal font
156         s/\\\*\(iF/<em>/g;      # italic font
157         s/\\\(mu/x/g;           # multiply symbol
158         s/\\ / /g;              # should be non breaking space
159         return $_;
160 }
161
162 #sub htmlify {
163 #    local($str) = @_;
164 #    $str;
165 #}
166
167