mkpkgidx.tcl

Go to the documentation of this file.
00001 /*  command line:*/
00002 /*  $ interpreter mkpkgidx.tcl -p package1.n.n -p package2 -p package3.n ...*/
00003 /*      packageName file1 file2 ...*/
00004 /*  use wish as interpreter instead of tclsh in order to handle graphical packages*/
00005 
00006 /*  Copyright (c) 2001 by Jean-Luc Fontaine <jfontain@free.fr>.*/
00007 /*  This code may be distributed under the same terms as Tcl.*/
00008 /* */
00009 /*  $Id: mkpkgidx.tcl,v 1.3 2004/01/15 06:36:14 andreas_kupries Exp $*/
00010 
00011 /*  this utility must be used to create the package index file for a package that*/
00012 /*  uses stooop.*/
00013 /*  it differs from the tcl pkg_mkIndex procedure in the way it sources files.*/
00014 /*  since base classes can usually be found in files separate from the derived*/
00015 /*  class source file, sourcing each file in a different interpreter (as is done*/
00016 /*  in the pkg_mkIndex procedure) results in an error for stooop that catches the*/
00017 /*  fact that the base class is not defined. the solution is to use a single*/
00018 /*  interpreter which will source the class files in order (base classes first at*/
00019 /*  the user's responsibility). since stooop is loaded in that single interpreter,*/
00020 /*  inheritance problems and others are automatically caught in the process.*/
00021 /*  the generated package index file is fully compatible with the tcl generated*/
00022 /*  ones.*/
00023 /*  the stooop library makes sure that base classes source files are automatically*/
00024 /*  sourced when a derived class is defined (see the stooop.tcl source file for*/
00025 /*  more information).*/
00026 /*  if your software requires one or more packages, you may force their loading*/
00027 /*  by using the -p arguments. each package version number is optionally appended*/
00028 /*  to the package name and follows the same rules as the Tcl package require*/
00029 /*  command*/
00030 /*  example: $ tclsh -p switched.1 -p scwoop foo bar.tcl barfoo.tcl foobar.tcl ...*/
00031 
00032 if {[catch {package require stooop 4}]} {
00033     /*  in case stooop package is not installed*/
00034     source stooop.tcl
00035 }
00036 namespace import stooop::*
00037 
00038 ret  indexData (type packageName , type files) {
00039     global auto_index
00040 
00041     set index "# Package index file created with stooop version [package provide stooop] for stooop packages\n"
00042     set data {}
00043 
00044     foreach command [info commands] {
00045         set defined($command) {}
00046     }
00047 
00048     foreach file $files {
00049         # source at global level to avoid variable names collisions:
00050         uplevel #0 source [list $file]
00051 
00052         catch {unset newCommands}                    ;# empty new commands array
00053         foreach command [info commands] {
00054             # check new commands at the global level
00055             # filter out tk widget commands and ignore commands eventually
00056             # loaded from a package required by the new commands
00057             if {
00058                 [string match .* $command]||[info exists defined($command)]||
00059                 [info exists auto_index($command)]||\
00060                 [info exists auto_index(::$command)]
00061             } continue
00062             set newCommands($command) {}
00063             set defined($command) {}
00064         }
00065         # check new classes, which actually are namespaces:
00066         foreach class [array name stooop::declared] {
00067             if {![info exists declared($class)]} {
00068                 # check new commands at the class namespace level:
00069                 foreach command [info commands ::${class}::*] {
00070                     # ignore commands eventually loaded from a package required
00071                     # by the new commands
00072                     if {\
00073                         [info exists defined($command)]||\
00074                         [info exists auto_index($command)]||\
00075                         [info exists auto_index(::$command)]\
00076                     } continue
00077                     set newCommands($command) {}
00078                     set defined($command) {}
00079                 }
00080                 set declared($class) {}
00081             }
00082         }
00083         # so far only sourceable file, not shared libraries, are handled
00084         lappend data [list $file source [lsort [array names newCommands]]]
00085     }
00086     set version [package provide $packageName]
00087     append index "\npackage ifneeded $packageName $version \[list tclPkgSetup \$dir $packageName $version [list $data]\]"
00088     return $index
00089 }
00090 
00091 ret  printUsage (type exitCode) {
00092     global argv0
00093 
00094     puts stderr "usage: $argv0 \[\[-p package.n.n\] \[-p package.n.n\] ...\] moduleName tclFile tclFile ..."
00095     exit $exitCode
00096 }
00097 
00098 /*  first gather eventual packages:*/
00099 for { index =  0} {$index<[llength $argv]} {incr index} {
00100     if {[string compare [lindex $argv $index] -p]!=0} break
00101      version =  {}
00102     scan [lindex $argv [incr index]] {%[^.].%s} name version
00103     eval package require $name $version
00104 }
00105 
00106  argv =  [lrange $argv $index end]                   ;/*  keep remaining arguments*/
00107 if {[llength $argv]<2} {
00108     printUsage 1
00109 }
00110 
00111 puts [open pkgIndex.tcl w] [indexData [lindex $argv 0] [lrange $argv 1 end]]
00112 exit                                                     ;/*  in case wish is used*/
00113 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1