#!/usr/bin/perl # # $Id: bsdi-man.pl,v 1.1 2026/03/31 02:15:16 kristaps Exp $ # # bsdi-man -- HTML hypertext BSDI man page interface # based on bsdi-man.pl,v 2.10 1993/10/02 06:13:23 sanders Exp # by polk@BSDI.COM 1/10/95 # BSDI Id: bsdi-man,v 1.2 1995/01/11 02:30:01 polk Exp # Dual CGI/Plexus mode and new interface by sanders@bsdi.com 9/22/1995 # # TODO:: Add support for multiple architectures (i386, sparc) # TODO:: Add support for OS version # TODO:: Config option for man path package bsdi_man; # Config Options # map sections to their man command argument(s) %sections = ( "", "", "1", "-s 1", "1L", "-s 1", "1X", "-s 1", "2", "-s 2", "3", "-s 3", "3C", "-s 3", "3N", "-s 3", "3R", "-s 3", "3X", "-s 3", "3X11", "-M X11 -s 3", "3X1F", "-s 3", "3X1X", "-s 3", "3XT", "-s 3", "3XX", "-s 3", "3XXL", "-s 3", "3Xt", "-s 3", "4", "-s 4", "5", "-s 5", "5F", "-s 5", "5F", "-s 5", "6", "-s 6", "7", "-s 7", "8", "-s 8", "8C", "-s 8", "l", "-s local", "n", "-s new", "o", "-s old", "bsdi", "-M bsdi", "mh", "-M mh", "sendmail", "-M sendmail", "X11", "-M X11", ); @sections = keys %sections; shift @sections; # all but the "" entry $sections = join("|", @sections); # sections regexp $protocol = "1.0"; # version of the form protocol # this can easily overridden by setting $bsdi_man'webmaster $webmaster = $webmaster || $main'plexus{'admin'}; # CGI Interface -- runs at load time &main'do_bsdi_man(&env('SCRIPT_NAME'), &env('PATH_INFO'), &env('QUERY_STRING')) unless defined($main'plexus_configured); # Plexus Native Interface sub main'do_bsdi_man { local($BASE, $path, $form) = @_; local($_, %form, $query, $proto, $name, $section, $apropos); $BASE = "/" . $BASE; # we serve up our own bitmap if needed return &bitmap if ($path =~ /bsdi-man.xbm$/); # indexpage if no query data return &indexpage unless defined($form); # check to see if it's an old- or new-style query if ($form =~ m/^proto=[\d\.]*&/) { # New-style query, process the form data # We are expecting: proto=$protocol, query, section, apropos, title &decode_form($form, *form, 0); $proto = $form{'proto'}; # new-style proto die "Invalid Query Protocol Version\n" unless $proto eq $protocol; $name = $query = $form{'query'}; $section = $form{'section'}; $section = "" if $section eq "ALL"; $apropos = $form{'apropos'}; $alttitle = $form{'title'}; if (!$apropos && $query =~ m/^(.*)\(([^\)]*)\)/) { $name = $1; $section = $2; } } else { # Old-style query, look for `foo', `foo()', `foo(sect)' patterns. undef $proto; # old-style $query = join(" ", &splitquery($form)); ($name, $section) = $query =~ m/^([\w\s\+\,\.\_\-]+)\\*\(([\w\,]*)\\*\)/; $apropos = !(defined($name) && defined($section)); } $apropos ? &apropos($query) : &man($name, $section); } # --------------------- support routines ------------------------ sub debug { &http_header("text/plain"); print @_,"\n----------\n\n\n"; } sub http_header { local($content_type) = @_; if (defined($main'plexus_configured)) { &main'MIME_header('ok', $content_type); } else { print "Content-type: $content_type\n\n"; } } sub env { defined($main'ENV{$_[0]}) ? $main'ENV{$_[0]} : undef; } sub apropos { local($query) = @_; local($_, $title, $head, *APROPOS); local($names, $section, $msg, $key); local($prefix); $prefix = "Apropos "; if ($alttitle) { $prefix = ""; $title = &encode_title($alttitle); $head = &encode_data($alttitle); } else { $title = &encode_title($query); $head = &encode_data($query); } &http_header("text/html"); print "\n"; print "
\n"; print "\n"; print "Index Page and Help\n"; &formquery; print "
\n"; print "Index Page and Help\n"; &formquery; print "
\n";
print "This data is part of a licensed program from BERKELEY SOFTWARE\n";
print "DESIGN, INC. Portions are copyrighted by BSDI, The Regents of\n";
print "the University of California, Massachusetts Institute of\n";
print "Technology, Free Software Foundation, and others.\n";
print "
\n";
print "
\n";
$html_name = &encode_data($name);
$html_section = &encode_data($section);
if (!defined($sections{$section})) {
print "Sorry, section ``$html_section'' is not valid\n";
return;
}
@manargs = split(/ /, $sections{$section});
&proc(*MAN, "/usr/bin/man", @manargs, "--", $name) ||
die ("$0: open of man command failed: $!\n");
if (eof(MAN)) {
print "Sorry, no data found for $html_name($html_section)...\n";
return;
}
while() {
$_ = &encode_data($_);
if(m,()?\#include()?\s+()?\lt\;(.*\.h)\gt\;()?,) {
$match = $4; ($regexp = $match) =~ s/\./\\\./;
s,$regexp,\$match\,;
}
/^\s/ && # skip headers
s,((<[IB]>)?[\w\_\.\-]+\s*([IB]>)?\s*\(($sections)\)),&mlnk($1),oige;
print;
}
close(MAN);
print " \n";
print "\n";
print "\n";
}
sub mlnk {
local($matched) = @_;
local($link, $section);
($link = $matched) =~ s/[\s]+//g;
$link =~ s/<\/?[IB]>//g;
($link, $section) = ($link =~ m/^([^\(]*)\((.*)\)/);
$link = &encode_url($link);
$section = &encode_url($section);
return "$matched";
}
sub proc {
local(*FH, $prog, @args) = @_;
local($pid) = open(FH, "-|");
return undef unless defined($pid);
if ($pid == 0) {
exec $prog, @args;
die "exec $prog failed\n";
}
1;
}
# $indent is a bit of optional data processing I put in for
# formatting the data nicely when you are emailing it.
# This is derived from code by Denis Howe Man Page Lookup searches for man pages name and section as given in the selection menu and the query dialog. Apropos Keyword Search searches the database for the string given in the query dialog. There are also several hypertext links provided as short-cuts to various queries: Section Indexes is apropos listings of all man pages by section. Explanations of Man Sections contains pointers to the intro pages for various man sections. Or you can select a catagory from Quick Reference Categories and see man pages relevant to the selected topic.
ETX
&formquery;
print <
ETX
print "\n
Explanations of Man Sections:
intro(1) ¤
intro(2) ¤
intro(3) ¤
intro(4) ¤
intro(7) ¤
intro(8)
Quick Reference Categories:
Networking ¤
NFS ¤
Mail ¤
Languages ¤
SCO Emulation ¤
DOS
ETX
print <