3 $MAN = $ENV{'W3MMAN_MAN'} || '@MAN@';
4 $QUERY = $ENV{'QUERY_STRING'} || $ARGV[0];
5 $SCRIPT_NAME = $ENV{'SCRIPT_NAME'} || $0;
6 $CGI = "file://$SCRIPT_NAME";
8 # $CGI2 = "file:///\$LIB/hlink.cgi?";
10 $ENV{'PAGER'} = 'cat';
13 for (split('&', $QUERY)) {
14 ($v, $q) = split('=', $_, 2);
15 $query{$v} = &form_decode($q);
19 $query{"man"} = &form_decode($QUERY);
22 if ((! $query{"man"}) && (! $query{"local"})) {
23 if ($query{"keyword"}) {
24 $keyword = $query{"keyword"};
25 $k = &html_quote($keyword);
27 Content-Type: text/html
30 <head><title>man -k $k</title></head>
32 <h2>man -k <b>$k</b></h2>
35 $keyword =~ s:([^-\w\200-\377.,])::g;
36 open(F, "$MAN -k $keyword 2> /dev/null |");
43 s@(\w[\w.\-]*(\s*\,\s*\w[\w.\-]*)*)\s*(\([\dn]\w*\))@&keyword_ref($1, $3)@ge;
44 print "<li>$_$title\n";
55 Content-Type: text/html
58 <head><title>man</title></head>
62 <tr><td>Manual:<td><input name=man>
63 <tr><td>Section:<td><input name=section>
64 <tr><td>Keyword:<td><input name=keyword>
65 <tr><td><td><input type=submit> <input type=reset>
74 if ($query{"local"}) {
75 $file = $query{"local"};
76 if (! ($file =~ /^\//)) {
77 $file = $query{"pwd"} . '/' . $file;
79 open(F, "$MAN -l $file 2> /dev/null |");
82 if ($man =~ s/\((\w+)\)$//) {
84 $man_section = "$man($1)";
85 } elsif ($query{"section"}) {
86 $section = $query{"section"};
87 $man_section = "$man($section)";
90 $man_section = "$man";
93 $section =~ s:([^-\w\200-\377.,])::g;
94 $man =~ s:([^-\w\200-\377.,])::g;
95 open(F, "$MAN $section $man 2> /dev/null |");
103 if (! defined($header)) {
109 } elsif ($_ eq $header) { # delete header
112 } elsif (!/\010/ && /^$space[\w\200-\377].*\s\S/o) { # delete footer
121 $blank > 0 && print "\n";
130 s@([\200-\377].)(\010{1,2}\1)+@<b>$1</b>@g;
131 s@(\&\w+;|.)(\010\1)+@<b>$1</b>@g;
132 s@__\010{1,2}((\<b\>)?[\200-\377].(\</b\>)?)@<u>$1</u>@g;
133 s@_\010((\<b\>)?(\&\w+\;|.)(\</b\>)?)@<u>$1</u>@g;
134 s@((\<b\>)?[\200-\377].(\</b\>)?)\010{1,2}__@<u>$1</u>@g;
135 s@((\<b\>)?(\&\w+\;|.)(\</b\>)?)\010_@<u>$1</u>@g;
138 s@\</b\>\</u\>\<b\>_\</b\>\<u\>\<b\>@_@g;
139 s@\</u\>\<b\>_\</b\>\<u\>@_@g;
146 Content-Type: text/html
149 <head><title>man $man_section</title></head>
158 s@(http|ftp)://[\w.\-/~]+[\w/]@<a href="$&">$&</a>@g;
159 s@(\W)(mailto:)?(\w[\w.\-]*\@\w[\w.\-]*\.[\w.\-]*\w)@$1<a href="mailto:$3">$2$3</a>@g;
160 s@(\W)(\~?/[\w.][\w.\-/~]*)@$1 . &file_ref($2)@ge;
161 s@(include(<\/?[bu]\>|\s)*\<)([\w.\-/]+)@$1 . &include_ref($3)@ge;
162 if ($prev && m@^\s*(\<[bu]\>)*(\w[\w.\-]*)(\</[bu]\>)*(\([\dm]\w*\))@) {
164 $prev =~ s@(\w[\w.\-]*-)((\</[bu]\>)*\s*)$@<a href="$CGI?$cmd">$1</a>$2@;
167 s@^(\s*(\<[bu]\>)*)(\w[\w.\-]*)@@;
168 print "$1<a href=\"$CGI?$cmd\">$3</a>";
173 s@(\w[\w.\-]*)((\</[bu]\>)*)(\([\dm]\w*\))@<a href="$CGI?$1$4">$1</a>$2$4@g;
174 if (m@(\w[\w.\-]*)-(\</[bu]\>)*\s*$@) {
186 if ($query{'quit'}) {
187 if ($query{'local'}) {
188 print STDERR "File $file not found.\n";
190 print STDERR "No manual entry for $man_section.\n";
192 print STDERR "No manual entry for $man_section.\n";
199 Content-Type: text/html
202 <head><title>man $man_section</title></head>
206 if ($query{'local'}) {
207 print "File <B>$file</B> not found.\n";
209 print "No manual entry for <B>$man_section</B>.\n";
222 (! -d && -x) || return 0;
223 if (! defined(%PATH)) {
224 for $p (split(":", $ENV{'PATH'})) {
230 return defined($PATH{$_});
236 if (&is_command($_)) {
237 ($man = $_) =~ s@.*/@@;
238 return "<a href=\"$CGI?$man\">$_</a>";
240 if (/^\~/ || -f || -d) {
241 return "<a href=\"$CGI2$_\">$_</a>";
252 "/usr/local/include",
253 "/usr/X11R6/include",
258 -f "$d/$_" && return "<a href=\"$CGI2$d/$_\">$_</a>";
267 for (split(/\s*,\s*/)) {
268 push(@a, "<a href=\"$CGI?$_$s\">$_</a>");
270 return join(", ", @a) . $s;
281 s/[<>&"]/$QUOTE{$&}/g;
288 s/%([\da-f][\da-f])/pack('c', hex($1))/egi;