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