#!/usr/local/bin/perl require "common.pl"; $webmaster = "Shishir Gundavaram (shishir\@bu\.edu)"; $script = $ENV{'SCRIPT_NAME'}; $man_path = "/usr/local/man"; $nroff = "/usr/bin/nroff -man"; $last_line = "Last change:"; &parse_form_data (*FORM); ($manpage = $FORM{'manpage'}) =~ s/^\s*(.*)\b\s*$/$1/; $section = $FORM{'section'}; if ( (!$manpage) || ($manpage !~ /^[\w\+\-]+$/) ) { &return_error (500, "UNIX Manual Page Gateway Error", "Invalid manual page specification."); } else { if ($section !~ /^\d+$/) { $section = &find_section (); } else { $section = &check_section (); } if ( ($section >= 1) && ($section <= 8) ) { &display_manpage (); } else { &return_error (500, "UNIX Manual Page Gateway Error", "Could not find the requested document."); } } exit (0); sub find_section { local ($temp_section, $loop, $temp_dir, $temp_file); $temp_section = 0; for ($loop=1; $loop <= 8; $loop++) { $temp_dir = join("", $man_path, "/man", $loop); $temp_file = join("", $temp_dir, "/", $manpage, ".", $loop); if (-e $temp_file) { $temp_section = $loop; } } return ($temp_section); } sub check_section { local ($temp_section, $temp_file); $temp_section = 0; $temp_file = join ("", $man_path, "/man", $section, "/", $manpage, ".", $section); if (-e $temp_file) { $temp_section = $section; } return ($temp_section); } sub display_manpage { local ($file, $blank, $heading); $file = join ("", $man_path, "/man", $section, "/", $manpage, ".", $section); print "Content-type: text/html", "\n\n"; print "", "\n"; print "UNIX Manual Page Gateway", "\n"; print "
Полезная информация

", "\n"; print "

UNIX Manual Page Gateway

", "\n"; print "
";

    open (MANUAL, "$nroff $file |");
    $blank = 0;

    while () {
        next if ( (/^$manpage\(\w+\)/i) || (/\b$last_line/o) );

        if (/^([A-Z0-9_ ]+)$/) {
            $heading = $1;
            print "

", $heading, "

", "\n"; } elsif (/^\s*$/) { $blank++; if ($blank < 2) { print; } } else { $blank = 0; s//&/g if (/&/); s//</g if (//); if (/((_\010\S)+)/) { s//$1<\/B>/g; s/_\010//g; } if ($heading =~ /ALSO/) { if (/([\w\+\-]+)\((\w+)\)/) { s//$1($2)<\/A>/g; } } print; } } print "

", "\n"; print "
", "\n"; close (MANUAL); }