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