mkpkgidx.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 if {[catch {package require stooop 4}]} {
00033
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
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] ;
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 ;
00113