home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tk42r2x.zip / TclTk / bin / man2ipf.tcl next >
Text File  |  1999-07-27  |  5KB  |  206 lines

  1. #!/proj/tcl/install/5.x-sparc/bin/tclsh7.5
  2.  
  3. if [catch {
  4.  
  5. # man2ipf.tcl --
  6. #
  7. # This file contains procedures that work in conjunction with the
  8. # man2tcl program to generate an IPF file from Tcl manual entries.
  9. #
  10. # Copyright (c) 1996 by Sun Microsystems, Inc.
  11. #
  12. # SCCS: @(#) man2ipf.tcl 1.5 96/04/11 20:21:43
  13. #
  14.  
  15. set homeDir [pwd]
  16.  
  17. # sarray -
  18. #
  19. # Save an array to a file so that it can be sourced.
  20. #
  21. # Arguments:
  22. # file -        Name of the output file
  23. # args -        Name of the arrays to save
  24. #
  25. proc sarray {file args} {
  26.     set file [open $file w]
  27.     foreach a $args {
  28.     upvar $a array
  29.     if ![array exists array] {
  30.         puts "sarray: \"$a\" isn't an array"
  31.         break
  32.     }    
  33.     
  34.     foreach name [lsort [array names array]] {
  35.         regsub -all " " $name "\\ " name1
  36.         puts $file "set ${a}($name1) \{$array($name)\}"
  37.     }
  38.     }
  39.     close $file
  40. }
  41.  
  42.  
  43.  
  44. # footer --
  45. #
  46. # Builds footer info for HTML pages
  47. #
  48. # Arguments:
  49. # None
  50.  
  51. proc footer {files} {
  52.     lappend f ":cgraphic.----------------------------------------:ecgraphic."
  53.     set h {[}
  54.     foreach file $files {
  55.     lappend h ":link reftype=hd refid='$file'.$file:elink."
  56.     lappend h "|"
  57.     }
  58.     lappend f [join [lreplace $h end end {]} ] " "]
  59.     lappend f ":cgraphic.----------------------------------------"
  60.     lappend f "Copyright © 1989-1994 The Regents of the University of California."
  61.     lappend f "Copyright © 1994-1996 Sun Microsystems, Inc."
  62.     lappend f ":ecgraphic."
  63.     return [join $f "\n"]
  64. }
  65.  
  66.  
  67.  
  68.  
  69. # doDir --
  70. #
  71. # Given a directory as argument, translate all the man pages in
  72. # that directory.
  73. #
  74. # Arguments:
  75. # dir -            Name of the directory.
  76.  
  77. proc doDir dir {
  78.     foreach f [lsort [glob $dir/*.\[13n\]]] {
  79.     do $f    ;# defined in man2ipf1.tcl & man2ipf2.tcl
  80.     }
  81. }
  82.  
  83.  
  84. if {$argc < 3} {
  85.     puts stderr "usage: $argv0 projectName fullVersion manFiles..."
  86.     puts stderr "example: $argv0 tcl 8.0.5 e:/tcl8.0.5/doc e:/tk8.0.5/doc"
  87.     exit 1
  88. }
  89.     
  90. #set nextres {001}
  91. set baseName [lindex $argv 0]
  92. set fullVersion [lindex $argv 1]
  93. regsub -all {\.} $fullVersion {} shortVersion
  94. set tclfiles {}
  95. set tkfiles {}
  96. # divide into entries for sections 1, 3 and n
  97. set tclfiles1 {}
  98. set tclfiles3 {}
  99. set tclfilesn {}
  100. set tkfiles1 {}
  101. set tkfiles3 {}
  102. set tkfilesn {}
  103. foreach i [lrange $argv 2 end] {
  104.     set i [file join $i]
  105.     if [ regexp tk $i ] {
  106.         set pkg {tk}
  107.     } else {
  108.         set pkg {tcl}
  109.     }
  110.     if [file isdir $i] {
  111.         foreach f [lsort [glob [file join $i *.1]]] {
  112.             lappend ${pkg}files1 $f
  113.         }
  114.         foreach f [lsort [glob [file join $i *.3]]] {
  115.             lappend ${pkg}files3 $f
  116.         }
  117.         foreach f [lsort [glob [file join $i *.n]]] {
  118.             lappend ${pkg}filesn $f
  119.         }
  120.     } elseif [file exists $i] {
  121.         set ext [ file extension $i ]
  122.         switch $ext {
  123.            {.1} {lappend ${pkg}files1 $i}
  124.            {.3} {lappend ${pkg}files3 $i}
  125.            {.n} {lappend ${pkg}filesn $i}
  126.            default {lappend ${pkg}files $i}
  127.         }
  128.     }
  129. }
  130.  
  131. #set footer [footer $files]
  132.  
  133. set file [ open "$baseName$shortVersion.ipf" w ]
  134. fconfigure $file -translation crlf
  135. puts $file ":userdoc.\n:docprof toc=12.\n:title.Tcl/Tk $fullVersion Reference"
  136.  
  137. # make the hyperlink arrays and contents for all files
  138.     
  139. set ext {tcl1}
  140. set sets [ list $tclfiles1 $tclfiles3 $tclfilesn $tclfiles \
  141.                 $tkfiles1 $tkfiles3 $tkfilesn $tkfiles ]
  142. foreach set $sets {
  143. #puts "set \[$set\]"
  144.     switch $ext {
  145.         {tcl1} {
  146.             set title {Tcl Applications}
  147.             set ext {tcl3}
  148.         }
  149.         {tcl3} {
  150.             set title {Tcl Library Procedures}
  151.             set ext {tcln}
  152.         }
  153.         {tcln} {
  154.             set title {Tcl Built-In Commands}
  155.             set ext {tcll}
  156.         }
  157.         {tcll} {
  158.             set title {Tcl Other Manual Pages}
  159.             set ext {tk1}
  160.         }
  161.         {tk1} {
  162.             set title {Tk Applications}
  163.             set ext {tk3}
  164.         }
  165.         {tk3} {
  166.             set title {Tk Library Procedures}
  167.             set ext {tkn}
  168.         }
  169.         {tkn} {
  170.             set title {Tk Built-In Commands}
  171.             set ext {tkl}
  172.         }
  173.         default {
  174.             set title {Tk Other Manual Pages}
  175.             set ext {}
  176.         }
  177.     }
  178.     if {$set != {} } {
  179.         puts $file "\n:h1 name='$title'.$title"
  180. #        puts $file "\n:i1 id='$title'.$title"
  181.     }
  182.     foreach manpg $set {
  183.         global homeDir
  184.     
  185.         # build hyperlink database arrays: NAME_file and KEY_file
  186.         #
  187.  
  188.         source $homeDir/man2ipf2.tcl
  189.         puts "Building IPF from man page $manpg..."
  190.         do $manpg
  191.  
  192.         catch {unset NAME_file}
  193.     }
  194. }
  195.  
  196. puts $file ":euserdoc."
  197. close $file
  198.  
  199. } result] {
  200.     global errorInfo
  201.     puts stderr $result
  202.     puts stderr "in"
  203.     puts stderr $errorInfo
  204. }
  205.  
  206.