home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / tclx7_31.z / tclx7_31 / tcldev / tclX7.3a-p1 / tclsrc / convlib.tcl < prev    next >
Encoding:
Text File  |  1993-11-19  |  3.7 KB  |  111 lines

  1. #
  2. # convlib.tcl --
  3. #
  4. #     Convert Ousterhout style tclIndex files and associated libraries to a
  5. # package library.
  6. #------------------------------------------------------------------------------
  7. # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
  8. #
  9. # Permission to use, copy, modify, and distribute this software and its
  10. # documentation for any purpose and without fee is hereby granted, provided
  11. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  12. # Mark Diekhans make no representations about the suitability of this
  13. # software for any purpose.  It is provided "as is" without express or
  14. # implied warranty.
  15. #------------------------------------------------------------------------------
  16. # $Id: convlib.tcl,v 3.0 1993/11/19 07:00:16 markd Rel $
  17. #------------------------------------------------------------------------------
  18. #
  19.  
  20. #@package: TclX-convertlib convert_lib
  21.  
  22. #------------------------------------------------------------------------------
  23. # tclx:ParseTclIndex
  24. # Parse a tclIndex file, returning an array of file names with the list of
  25. # procedures in each package. This is done by sourcing the file and then
  26. # going through the local auto_index array that was created. Issues warnings
  27. # for lines that can't be converted.  tclIndex should be an absolute path
  28. # name.  Returns 1 if all lines are converted, 0 if some failed.
  29. #
  30.  
  31. proc tclx:ParseTclIndex {tclIndex fileTblVar ignore} {
  32.     upvar $fileTblVar fileTbl
  33.     set allOK 1
  34.  
  35.     # Open and validate the file.
  36.  
  37.     set tclIndexFH [open $tclIndex r]
  38.     set hdr [gets $tclIndexFH]
  39.     if {$hdr != "# Tcl autoload index file, version 2.0"} {
  40.         error "can only convert version 2.0 Tcl auto-load files"
  41.     }
  42.     set dir [file dirname $tclIndex]  ;# Expected by the script.
  43.     eval [read $tclIndexFH]
  44.     close $tclIndexFH
  45.  
  46.     foreach procName [array names auto_index] {
  47.         if ![string match "source *" $auto_index($procName)] {
  48.             puts stderr "WARNING: Can't convert load command for \"$procName\": $auto_index($procName)"
  49.             set allOK 0
  50.             continue
  51.         }
  52.         set filePath [lindex $auto_index($procName) 1]
  53.         set fileName [file tail $filePath] 
  54.         if {[lsearch $ignore $fileName] >= 0} continue
  55.  
  56.         lappend fileTbl($filePath) $procName
  57.     }
  58.     if ![info exists fileTbl] {
  59.         error "no entries could be converted in $tclIndex"
  60.     }
  61.     return $allOK
  62. }
  63.  
  64. #------------------------------------------------------------------------------
  65. # convert_lib:
  66. # Convert a tclIndex library to a .tlib. ignore any files in the ignore
  67. # list
  68.  
  69. proc convert_lib {tclIndex packageLib {ignore {}}} {
  70.     source [info library]/buildidx.tcl
  71.  
  72.     if {[file tail $tclIndex] != "tclIndex"} {
  73.         error "Tail file name must be `tclIndex': $tclIndex"}
  74.     if ![file readable $tclIndex] {
  75.         error "File not readable: $tclIndex"
  76.     }
  77.  
  78.     # Expand to root relative file name.
  79.  
  80.     set tclIndex [glob $tclIndex]
  81.     if ![string match "/*" $tclIndex] {
  82.         set tclIndex "[pwd]/$tclIndex"
  83.     }
  84.  
  85.     # Parse the file.
  86.  
  87.     set allOK [tclx:ParseTclIndex $tclIndex fileTbl $ignore]
  88.  
  89.     # Generate the .tlib package names with contain the directory and
  90.     # file name, less any extensions.
  91.  
  92.     if {[file extension $packageLib] != ".tlib"} {
  93.         append packageLib ".tlib"
  94.     }
  95.     set libFH [open $packageLib w]
  96.  
  97.     foreach srcFile [array names fileTbl] {
  98.         set pkgName [file tail [file dirname $srcFile]]/[file tail [file root $srcFile]]
  99.         set srcFH [open $srcFile r]
  100.         puts $libFH "#@package: $pkgName $fileTbl($srcFile)\n"
  101.         copyfile $srcFH $libFH
  102.         close $srcFH
  103.     }
  104.     close $libFH
  105.     buildpackageindex $packageLib
  106.     if !$allOK {
  107.         error "*** Not all entries converted, but library generated"
  108.     }
  109. }
  110.