2
#!/citi/gtfd/mach/bin/perl -w
4
# $Id: hman.pl,v 1.7 1997/11/04 21:56:13 teto Exp teto $
5
# $Source: /pub/src/dev/hman/RCS/hman.pl,v $
6
############################################
8
# reorganize location of man pages - move 3x stuff from man3 to man3x
9
# recurse - if 'man 3x curses' does not work try 'man 3 curses'
11
# Fix broken whatis entries - instead of
12
# manpage section - description
13
# manpage description section -
14
# highlite keywords found
15
# pass MANPATH as a command line argument
16
############################################
18
# http://www.jinr.dubna.su/~gagin
19
# http://thsun1.jinr.dubna.su/~gagin/rman.pl
20
# http://thsun1.jinr.dubna.su/cgi-bin/rman.pl
21
# http://www.jinr.dubna.su/~gagin/rman.pl.html
23
# CGI form interface to PolyglotMan program, which is available as
24
# ftp://ftp.cs.berkeley.edu:/ucb/people/phelps/tcltk/rman.tar.Z
26
# The most recent version of this program available as
27
# http://www.geocities.com/SiliconValley/Lakes/8777/hman.html
28
#---------------------------------------------------------------------
29
# This is free software; you can redistribute it and/or modify
30
# it under the terms of the GNU General Public License as published by
31
# the Free Software Foundation; either version 2, or (at your option)
34
# hman is distributed in the hope that
35
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied
36
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
37
# See the GNU General Public License for more details.
39
# You should have received a copy of the GNU General Public License
40
# along with this software; see the file COPYING. If not, write to the
41
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
42
# Boston, MA 02111-1307, USA.
44
# THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
45
# CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
46
# PERFOHMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
47
# NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
48
# SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
49
# SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
50
# PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").
51
# ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES
52
# IS SPECIFICALLY DISCLAIMED.
53
#---------------------------------------------------------------------
54
# Request form: hman.pl?ManTopic=SOMETOPIC&ManSection=SECTION
55
# Request form: hman.pl?DirectPath=filename
57
#---------------------------------------------------------------------
60
# path to PolyglotMan program. "-b" is not nessesary
61
$hman="$ENV{HMANPRG} $ENV{HMANOPT}";
64
$ManPrg='/usr/bin/man';
67
$ENV{PAGER} = '/bin/cat';
69
# path to man directories
70
($ManPathFind = $ENV{MANPATH}) =~ s/:/ /g;
73
$hmanpl='/cgi-bin/hman';
75
# if man produced number of lines less then follows,
76
# I assume that request failed
79
# tail of every produced html document
80
$HtmlTail='<hr><A HREF="' . $hmanpl . '">Back to Hman</a>';
81
# $HtmlTitle="<title>CGI form interface to PolyglotMan</title>\n";
82
$HtmlHdr="Content-type: text/html\n\n";
84
# end changable things
85
#----------------------------------------------------------------------
95
'9', 'Linux Internals',
99
# Set unbuffered I/O. Prevents buffering problems with
101
select((select(STDOUT), $| = 1)[0]);
104
$string = $ENV{QUERY_STRING};
108
if($string eq "") { initialForm(); }
111
# Generic parameter parsing ...
113
$DirectPath = $ManSection = $ManTopic = "";
114
$string =~ s/&/'; \$/g;
116
$string =~ s/^(.*)$/\$$1';/;
119
hmanDirect($DirectPath) if ($DirectPath ne "");
121
if ($ManTopic eq "") { badness("<code>Topic for man search needed</code>\n"); }
123
if ($ManSection eq "") { badness("<code>No section specified</code>\n"); }
125
$ManSection =~ s/all//;
126
if ($ManSection =~ /key/) { manKey($ManTopic); }
129
open(MANOUT, "$ManPrg $ManSection $ManTopic |")
130
|| die "$hmanpl: can't run \"$ManPrg Section $ManTopic |\", $!\n";
132
$temp = <MANOUT> || last;
136
if (@temp < $emptyman) {
138
print"<strong>Request failed for topic $ManTopic:</strong>\n<code>";
140
print "</code><br><h3>Let's try a keyword search:</h3><hr>\n";
144
$cmd = "$hman -r \"$hmanpl?ManTopic=%s&ManSection=%s\" -l \"Man page for $ManTopic";
145
if ($ManSection eq "") {
148
$cmd .= "($ManSection)\"";
151
open(HMANIN, "| $cmd") || die "$hmanpl: can't open $cmd: $!\n";
152
for (@temp) {print HMANIN;}
153
while(<MANOUT>){print HMANIN;}
158
###############################################################################
161
<h1>Select a manual page:</h1>
162
<FORM METHOD="GET" action="$hmanpl">
165
<td align=right>Section:</td>
167
<select name=ManSection>
168
<OPTION value=all>All</option>
169
<OPTION value=key>Keyword Search</option>
171
for ($ndx = 0; $ndx < @ManSections; $ndx += 2) {
172
print ' <OPTION value=' . $ManSections[$ndx] . '>'
173
. "$ManSections[$ndx] - $ManSections[$ndx + 1] "
174
. '</option>' . "\n";
181
<td align=right>Topic:</td>
182
<td><input type="TEXT" name="ManTopic"></td>
185
<td align=right><INPUT TYPE="submit" VALUE="Search">
186
<td align=left><input type="reset" value="Reset">
195
my($topic) = ($_[0]);
196
my($cmd, $mixedCase, $navigation, $zcat);
198
foreach (split(/\s*/, $topic)) {
199
$mixedCase .= "[" . $_ . uc($_) . "]";
201
$cmd = 'find ' . $ManPathFind . ' \( -type f -o -type l \) -name '
202
. $mixedCase .'\* | sort -t. +1';
203
open(FINDIN, "$cmd |") || die "can't open pipe \"$cmd |\": $!";
206
if ($navigation == 0) {
211
print "<li><A HREF=\"$hmanpl?DirectPath=$_\">$_</a>\n";
214
print "</UL><hr>\n" if ($navigation == 1);
217
my($path) = ($_[0], $_[1]);
218
my($cmd, $dir, $topic, $section);
219
($dir = $path) =~ s/\.(gz|z|Z)$//;
220
($topic = $dir) =~ s,^.*/,,;
221
$dir =~ s,/[^/]*/[^/]*$,,;
222
# $dir =~ s,/[^/]*$,,;
223
($section=$topic)=~s/^.*\.([^\.]*)$/$1/;
224
$topic =~ s/\.[^\.]*$//;
226
$cmd = "cd $dir; (gzip -dc < $path 2>/dev/null || cat < $path) | $hman -r '"
227
. $hmanpl . '?ManTopic=%s&ManSection=%s' ."' -l 'Man page for $topic($section)'";
228
system($cmd) || warn "can't run command \"$cmd\": $!";
238
print "<strong>Request failed:</strong> $text, Try again<hr>\n";
242
my($topic) = ($_[0]);
243
open(TMPHTML,"$ManPrg -k $topic | sort -u |")
244
|| die "can't open pipe \"$ManPrg -k $topic | sort -u |\": $!\n";
245
print "<title>Keyword search results for \"$topic\"</title>\n";
246
print "<h1>Keyword search results for \"$topic\"</h1><hr>\n";
249
next if (! /^([^(]+)\s*\(([^)]+)[^-]+-\s(.*)[\n\r]*$/);
250
@topics=split(/, /,$1);
252
print "<h2>$3:</h2>\n";
254
for $topic (@topics) {
255
print "<li><A HREF=\"$hmanpl?ManSection=$2&ManTopic=$topic\">$topic</a>($2)\n";