"Fossies" - the Fresh Open Source Software Archive

Member "rman-3.2/contrib/youki.pl" (26 Jul 2003, 5086 Bytes) of package /linux/www/old/rman-3.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "youki.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/local/bin/perl5
    2 #
    3 # CGI script for translating manpage into html on the fly.
    4 # Front-end for PolyglotMan (formerly called RosettaMan)
    5 #
    6 # Author: Youki Kadobayashi  <youki@center.osaka-u.ac.jp>
    7 #
    8 # NOTE: Replace 'CGI::Apache' with just 'CGI' for systems without mod_perl.
    9 #
   10 # ALSO: You may want to recompile rman like this:
   11 #   MANREFPRINTF = "/mod-bin/cgi-rman.pl?keyword=%s&section=%s"
   12 #
   13 
   14 use CGI::Apache font;           # for people with mod_perl and apache
   15 ## use CGI font;            # for people without mod_perl
   16 $par = "<P>\n";
   17 $brk = "<BR>\n";
   18 $bg = '#c0ffff';
   19 
   20 $query = new CGI::Apache;       # for people with mod_perl and apache
   21 ## $query = new CGI;            # for people without mod_perl
   22 
   23 %mandatory = ('keyword' => 'Name or keyword',
   24           'section' => 'Manual page section');
   25 
   26 @given = $query->param;
   27 if ($#given < 0) {
   28     &request_page;
   29     exit 0;
   30 }
   31 
   32 foreach $field (keys %mandatory) {
   33     if ($query->param($field) eq '') {
   34         push(@missing, $mandatory{$field});
   35     }
   36 }
   37 if ($#missing >= 0) {
   38     &info_missing_page(@missing);
   39 } else {
   40     if ($query->param('type') eq 'apropos') {
   41     &apropos_page;
   42     } else {
   43     &manual_page;
   44     }
   45 }
   46 exit 0;
   47 
   48 sub standout {
   49     my ($level, $color, $string) = @_;
   50 
   51     # As per CGI.pm documentation "Generating new HTML tags"
   52     return $query->font({color => "$color"}, "<$level>$string</$level>");
   53 }
   54 
   55 sub error_page {
   56     my ($message) = @_;
   57 
   58 #    print $query->header,
   59 #       $query->start_html(-title=>$message, -BGCOLOR=>$bg);
   60 
   61     print &standout("H2", "brown", $message),
   62         "The above error occured during the manual page generation",
   63         " process.  Please check keyword and section number,",
   64         " then try again.", $par;
   65 
   66 #    print $query->end_html;
   67 }
   68 
   69 sub info_missing_page {
   70     my (@missing) = @_;
   71 
   72     print $query->header,
   73         $query->start_html(-title=>"Information is missing",
   74                    -BGCOLOR=>$bg);
   75 
   76     print &standout("H2", "brown", "Information is missing"),
   77         "Sorry but your request was not fulfilled because",
   78         " the following information is missing in your entry:", $par,
   79         join(' ', @missing), $par,
   80         "Please go back and make sure to enter data on the missing field.";
   81 
   82     print $query->end_html;
   83 }
   84 
   85 sub request_page {
   86     print $query->header,
   87         $query->start_html(-title=>'Hypertext Manual Page',
   88                    -author=>'Youki Kadobayashi',
   89                    -BGCOLOR=>$bg);
   90 
   91     print &standout("H2", "green", "Hypertext Manual Page");
   92 
   93     print $query->start_form,
   94     "Type of Search: ",
   95         $query->radio_group(-name=>'type',
   96                     -values=>['man', 'apropos'],
   97                     -default=>'man'), $brk,
   98     "Name or Keyword: ",
   99         $query->textfield(-name=>'keyword'), $brk,
  100     "Manpage Section: ",
  101         $query->popup_menu(-name=>'section',
  102                    -labels=>{
  103                        0 => 'All Sections',
  104                        1 => '1 - General Commands',
  105                        2 => '2 - System Calls',
  106                        3 => '3 - Library Functions',
  107                        4 => '4 - Device Special Files',
  108                        5 => '5 - File Formats',
  109                        6 => '6 - Games',
  110                        7 => '7 - Macros and Conventions',
  111                        8 => '8 - System Administration',
  112                        'pgsql' => 'PostgreSQL',
  113                        'tcl' => 'Tcl/Tk',
  114                        'mh' => 'Message Handler',
  115                        'isode' => 'ISODE',
  116                        'X11' => 'X Window System'},
  117                    -values=>[0, 1, 2, 3, 4, 5, 6, 7, 8,
  118                          'pgsql', 'tcl', 'mh',
  119                          'isode', 'X11'],
  120                    -default=>0), $brk;
  121 
  122     print $query->submit(-name=>'Submit'), $query->reset,
  123         $query->end_form, $par;
  124 
  125     print $query->end_html;
  126 }
  127 
  128 sub manual_page {
  129     my $keyword = $query->param('keyword');
  130     my $section = $query->param('section');
  131     my $man = "man";
  132     my $ok = "-a-zA-Z0-9._";
  133 
  134     # sanitize for security
  135     $section =~ s/[^$ok]+/_/go;
  136     $keyword =~ s/[^$ok]+/_/go;
  137 
  138     if ($section =~ /^[A-Za-z]/) {
  139     $man .= " -M$section";
  140     }
  141     elsif ($section =~ /^\d/) {
  142     $section =~ s/^(\d)\w*/\1/go;
  143     $man .= " -s $section";
  144     }
  145     $man .= ' ' . $keyword;
  146     open (MAN, "$man | /usr/local/bin/rman -f html -n $keyword -s $section |");
  147 
  148     print $query->header;
  149     # start_html and end_html not needed here, since rman tacks them.
  150     print "<!-- text generated with '$man' by cgi-rman.pl -->\n";
  151     while (<MAN>) {
  152     print $_;
  153     }
  154     if ($? != 0 || $. < 15) {
  155     &error_page("Your request for manual page '$keyword' failed.");
  156 #   print "return code $?  line $.\n";
  157     close(MAN);
  158     return;
  159     }
  160     close(MAN);
  161 }
  162 
  163 sub apropos_page {
  164     my $keyword = $query->param('keyword');
  165     my $section = $query->param('section'); # igored
  166     my $man = "man -k";
  167     my $matches = 0;
  168 
  169     $man .= ' ' . $keyword;
  170     open (MAN, "$man |");
  171 
  172     $url = $query->url;
  173     print $query->header, $query->start_html(-title=>$man);
  174 
  175     while (<MAN>) {
  176     if (/^([a-zA-Z0-9_.-]+)[, ][a-zA-Z0-9_., -]*\((\d)\w*\)/) {
  177         print $`, qq{ <A HREF="$url?keyword=$1&section=$2&type=man"> },
  178         $&, "</A>", $';
  179         ++$matches;
  180     } else {
  181         print $_;
  182     }
  183     print $brk;
  184     }
  185     if ($? != 0 || $matches == 0) {
  186     &error_page("Your search request with keyword '$keyword' failed.");
  187 #   print "return code $?  matches $matches\n";
  188     close(MAN);
  189     return;
  190     }
  191     close(MAN);
  192 
  193     print $query->end_html;
  194 }
  195