home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / tclx7_31.z / tclx7_31 / tcldev / tclX7.3a-p1 / tools / bldmanhelp.tcl next >
Encoding:
Text File  |  1993-11-19  |  4.4 KB  |  142 lines

  1. #
  2. # bldmanhelp.tcl --
  3. #
  4. #  Build help files from the manual pages.  This uses a table of manual
  5. # pages, sections. Brief entries are extracted from the name line.
  6. # This is not installed as part of Extended Tcl, its just used during the
  7. # build phase.
  8. #
  9. # This program is very specific to extracting manual files from John
  10. # Ousterhout's Tcl and Tk man pages.  Its not general.
  11. #
  12. # The command line is:
  13. #
  14. #   bldmanhelp docdir maninfo helpdir
  15. #
  16. # Where:
  17. #    o docdir is the directory containing the manual pages.
  18. #    o maninfo is the path to a file that when sources returns a list of
  19. #      entries describing manual pages to convert.  Each entry is a list
  20. #      of manual file and the path of the help file to generate.
  21. #    o helpdir is the directory to create the help files in.
  22. #    o brief is the brief file to create.
  23. #------------------------------------------------------------------------------
  24. # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
  25. #
  26. # Permission to use, copy, modify, and distribute this software and its
  27. # documentation for any purpose and without fee is hereby granted, provided
  28. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  29. # Mark Diekhans make no representations about the suitability of this
  30. # software for any purpose.  It is provided "as is" without express or
  31. # implied warranty.
  32. #------------------------------------------------------------------------------
  33. # $Id: bldmanhelp.tcl,v 3.0 1993/11/19 06:59:56 markd Rel $
  34. #------------------------------------------------------------------------------
  35. #
  36.  
  37. #-----------------------------------------------------------------------------
  38. # Process the name section.  This is used to generate a @brief: entry.
  39. # It returns the line that was read.
  40.  
  41. proc ProcessNameSection {manFH outFH} {
  42.     set line [gets $manFH]
  43.     case [lindex $line 0] {
  44.         {.HS .BS .BE .VS .VE} {
  45.             set line [gets $manFH]
  46.         }
  47.     }
  48.     set brief [string trim [crange $line [string first - $line]+1 end]]
  49.     puts $outFH "'\\\"@brief: $brief"
  50.     return $line
  51. }
  52.  
  53. #-----------------------------------------------------------------------------
  54. # Copy the named manual page source to the target, recursively including
  55. # .so files.  Remove macros usages that don't work good in a help file.
  56.  
  57. proc CopyManPage {manPage outFH} {
  58.     global skipSection
  59.  
  60.     set stat [catch {
  61.         open $manPage
  62.     } fh]
  63.     if {$stat != 0} {
  64.         puts stderr "can't open \"$manPage\" $fh"
  65.         return
  66.     }
  67.     while {[gets $fh line] >= 0} {
  68.         case [lindex $line 0] {
  69.             {.so} {
  70.                 CopyManPage [lindex $line 1] $outFH
  71.             }
  72.             {.SH} {
  73.                 puts $outFH $line
  74.                 if {[lindex $line 1] == "NAME"} {
  75.                     set line [ProcessNameSection $fh $outFH]
  76.                     puts $outFH $line
  77.                 }
  78.             }
  79.             {.HS .BS .BE .VS .VE} {
  80.             }
  81.             default {
  82.                 if !$skipSection {
  83.                     puts $outFH $line
  84.                 }
  85.             }
  86.         }
  87.     }
  88.     close $fh
  89. }
  90.  
  91. #-----------------------------------------------------------------------------
  92. # Process a manual file and copy it to the temporary file.  Assumes current
  93. # dir is the directory containing the manual files.
  94.  
  95. proc ProcessManFile {ent tmpFH} {
  96.     global skipSection
  97.     set skipSection 0
  98.     puts $tmpFH "'\\\"@help: [lindex $ent 1]"
  99.     CopyManPage [lindex $ent 0] $tmpFH
  100.     puts $tmpFH "'\\\"@endhelp"
  101. }
  102.  
  103. #-----------------------------------------------------------------------------
  104. # Procedure to create a temporary file containing the file constructed
  105. # for input to buildhelp.
  106. #
  107.  
  108. proc GenInputFile {docDir manInfoTbl tmpFile} {
  109.  
  110.    set tmpFH [open $tmpFile w]
  111.    set cwd [pwd]
  112.    cd $docDir
  113.  
  114.    foreach ent $manInfoTbl {
  115.        puts stdout "    preprocessing $ent"
  116.        ProcessManFile $ent $tmpFH
  117.    }
  118.    cd $cwd
  119. }
  120.  
  121. #-----------------------------------------------------------------------------
  122. # Main program for building help from manual files.  Constructs tmp input
  123. # file for the buildhelp command.
  124.  
  125. if {[llength $argv] != 4} {
  126.     error "wrong # args: bldmanhelp docdir maninfo helpdir brief"
  127. }
  128.  
  129. set tmpFile "bldmanhelp.tmp"
  130.  
  131. set docDir [lindex $argv 0]
  132. set manInfoTbl [source [lindex $argv 1]]
  133. set helpDir [lindex $argv 2]
  134. set brief [lindex $argv 3]
  135.  
  136. puts stdout "Begin preprocessing UCB manual files"
  137. GenInputFile $docDir $manInfoTbl $tmpFile
  138.  
  139. buildhelp $helpDir $brief [list $tmpFile]
  140.  
  141. unlink $tmpFile
  142.