[Home]Man Pages

I wanted to have an online searchable man page repository with the standard Linux man pages.

First I got the raw man page tarball:

ftp://ftp.win.tue.nl/pub/linux-local/manpages/

Then I got the man2html Perl script (which I don't think I made very good use of):

http://www.oac.uci.edu/indiv/ehood/man2html.doc.html

Then I used nroff and man2html to generate the html versions of the man pages.

I then wrote this script for generating a nice index page:

 #!/bin/sh
 # the next line restarts using -*-Tcl-*-sh \
 exec tclsh "$0" ${1+"$@"}

 set head "<html>\
      <head>
      <META http-equiv=\"Content-Type\" 
            content=\"text/html; charset=ISO-8859-1\">
      <meta name=\"description\" content=\"Index of Linux man pages\">
      <meta name=\"keywords\" 
            content=\"unix, linux, programming, software, how-tos\">
      <title>Linux Man Pages Index</title> 
      </head>
      <body bgcolor=white  text=black><a name=\"top\"></a>
      <img src=http://inferno.slug.org/gif/sluglogo1.gif>
      <p>
      <center>
      <h2>Linux Man Pages Release 1.53</h2>
      <p>
      <form action=http://inferno.slug.org/cgi-bin/findManPageDoc
            method=get>
      <!-- appends /?search=\[ entered value \] to action -->
      <input type=text name=search>
         <b><i><font color=brown>Search</font></i></b>
      </form>
      </center>
      <p>"

 set foot "</ul></table></body>"

 regsub -all {[ ]+} $head { } head
 regsub -all {[ ]+} $foot { } foot

 set allfiles [ glob man-pages-1.53/man*/*.html ]

 set allfiles [ lsort -dictionary $allfiles ]

 foreach file $allfiles {
   set section [ lindex [ split $file / ] end-1 ]
   set command [ lindex [ split $file / ] end ]
   regexp {(.+).html$} $command -> command
   append body($section) "<li><a href=./$file>$command</a>\n"
 }   

 set BODY    "\n<table align=\"center\" width=80%>\n"
 append BODY "<td valign=top>\n"

 foreach section [ lsort -dictionary [ array names body ] ] {
   if { [ string equal man3 $section ] || \
        [ string equal man4 $section ] } {
      append BODY "<td valign=top>\n"
   }
   append BODY "<b><font color=brown>${section}</font></b>\n"
   append BODY "<ul>\n$body($section)\n</ul>\n"
 }

 set fid [ open index.html w ]

 puts $fid "$head\n$BODY\n$foot"
 close $fid
 exit
Which calls this cgi script:
 #!/usr/local/bin/tclsh

 # http 'gets' actions are found in the QUERY_STRING env variable
 set cmd [ lindex [ split $::env(QUERY_STRING) = ] end ]
 # prevent directory traversals
 set cmd [ lindex [ split $cmd / ] end ]

 set results [ list ]

 foreach dir [ glob -nocomplain /apache/htdocs/man-pages-1.53/man* ] {
   set test $dir/${cmd}.html
   if { [ file exists $test ] } {
      lappend results $test
   }
 }

 set len [ llength $results ]

 switch -exact $len {
   0 { 
      set retval "<html>\n<head>\n"
      append retval "<meta http-equiv=\"refresh\"\n"
      append retval "content=\"3;url=http://inferno.slug.org/man-pages.html\">\n"
      append retval "</head>\n<body>\n"
      append retval "<h2>No pages found for $cmd</h2>\n"
     }
   1 { 
      set fid [ open $results r ]
      set retval [ read $fid [ file size $results ] ]
      close $fid
     }
   default {
           set retval "<html>\n<head>\n"
           append retval "</head>\n<body>\n"
           append retval "<h2>Multiple matches found for "
           append retval "<font color=red>$cmd</font>"
           append retval ":</h2><p><p>\n"
           append retval "<ul>\n"
           foreach result $results {
              set dir [ lindex [ split $result / ] end-1 ]
              append retval "<li><a href=http://inferno.slug.org/man-pages-1.53/$dir/$cmd.html>$dir $cmd</a><p>\n"
           }
           }
 }

 puts "Content-Type: text/html\n"
 puts $retval
 puts "\n<p><p><a href=http://inferno.slug.org/man-pages><b>Return to Index Page</a>"
And this is the result:

http://inferno.slug.org/man-pages


Silverlake Linux Users Group Wiki | Recent Changes | Preferences
Password required to edit | View other revisions
Last edited October 27, 2003 11:42 am by gateway (diff)
Search: