jpayne@69: # auto.tcl -- jpayne@69: # jpayne@69: # utility procs formerly in init.tcl dealing with auto execution of commands jpayne@69: # and can be auto loaded themselves. jpayne@69: # jpayne@69: # Copyright (c) 1991-1993 The Regents of the University of California. jpayne@69: # Copyright (c) 1994-1998 Sun Microsystems, Inc. jpayne@69: # jpayne@69: # See the file "license.terms" for information on usage and redistribution of jpayne@69: # this file, and for a DISCLAIMER OF ALL WARRANTIES. jpayne@69: # jpayne@69: jpayne@69: # auto_reset -- jpayne@69: # jpayne@69: # Destroy all cached information for auto-loading and auto-execution, so that jpayne@69: # the information gets recomputed the next time it's needed. Also delete any jpayne@69: # commands that are listed in the auto-load index. jpayne@69: # jpayne@69: # Arguments: jpayne@69: # None. jpayne@69: jpayne@69: proc auto_reset {} { jpayne@69: global auto_execs auto_index auto_path jpayne@69: if {[array exists auto_index]} { jpayne@69: foreach cmdName [array names auto_index] { jpayne@69: set fqcn [namespace which $cmdName] jpayne@69: if {$fqcn eq ""} { jpayne@69: continue jpayne@69: } jpayne@69: rename $fqcn {} jpayne@69: } jpayne@69: } jpayne@69: unset -nocomplain auto_execs auto_index ::tcl::auto_oldpath jpayne@69: if {[catch {llength $auto_path}]} { jpayne@69: set auto_path [list [info library]] jpayne@69: } elseif {[info library] ni $auto_path} { jpayne@69: lappend auto_path [info library] jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: # tcl_findLibrary -- jpayne@69: # jpayne@69: # This is a utility for extensions that searches for a library directory jpayne@69: # using a canonical searching algorithm. A side effect is to source the jpayne@69: # initialization script and set a global library variable. jpayne@69: # jpayne@69: # Arguments: jpayne@69: # basename Prefix of the directory name, (e.g., "tk") jpayne@69: # version Version number of the package, (e.g., "8.0") jpayne@69: # patch Patchlevel of the package, (e.g., "8.0.3") jpayne@69: # initScript Initialization script to source (e.g., tk.tcl) jpayne@69: # enVarName environment variable to honor (e.g., TK_LIBRARY) jpayne@69: # varName Global variable to set when done (e.g., tk_library) jpayne@69: jpayne@69: proc tcl_findLibrary {basename version patch initScript enVarName varName} { jpayne@69: upvar #0 $varName the_library jpayne@69: global auto_path env tcl_platform jpayne@69: jpayne@69: set dirs {} jpayne@69: set errors {} jpayne@69: jpayne@69: # The C application may have hardwired a path, which we honor jpayne@69: jpayne@69: if {[info exists the_library] && $the_library ne ""} { jpayne@69: lappend dirs $the_library jpayne@69: } else { jpayne@69: # Do the canonical search jpayne@69: jpayne@69: # 1. From an environment variable, if it exists. Placing this first jpayne@69: # gives the end-user ultimate control to work-around any bugs, or jpayne@69: # to customize. jpayne@69: jpayne@69: if {[info exists env($enVarName)]} { jpayne@69: lappend dirs $env($enVarName) jpayne@69: } jpayne@69: jpayne@69: # 2. In the package script directory registered within the jpayne@69: # configuration of the package itself. jpayne@69: jpayne@69: catch { jpayne@69: lappend dirs [::${basename}::pkgconfig get scriptdir,runtime] jpayne@69: } jpayne@69: jpayne@69: # 3. Relative to auto_path directories. This checks relative to the jpayne@69: # Tcl library as well as allowing loading of libraries added to the jpayne@69: # auto_path that is not relative to the core library or binary paths. jpayne@69: foreach d $auto_path { jpayne@69: lappend dirs [file join $d $basename$version] jpayne@69: if {$tcl_platform(platform) eq "unix" jpayne@69: && $tcl_platform(os) eq "Darwin"} { jpayne@69: # 4. On MacOSX, check the Resources/Scripts subdir too jpayne@69: lappend dirs [file join $d $basename$version Resources Scripts] jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: # 3. Various locations relative to the executable jpayne@69: # ../lib/foo1.0 (From bin directory in install hierarchy) jpayne@69: # ../../lib/foo1.0 (From bin/arch directory in install hierarchy) jpayne@69: # ../library (From unix directory in build hierarchy) jpayne@69: # jpayne@69: # Remaining locations are out of date (when relevant, they ought to be jpayne@69: # covered by the $::auto_path seach above) and disabled. jpayne@69: # jpayne@69: # ../../library (From unix/arch directory in build hierarchy) jpayne@69: # ../../foo1.0.1/library jpayne@69: # (From unix directory in parallel build hierarchy) jpayne@69: # ../../../foo1.0.1/library jpayne@69: # (From unix/arch directory in parallel build hierarchy) jpayne@69: jpayne@69: set parentDir [file dirname [file dirname [info nameofexecutable]]] jpayne@69: set grandParentDir [file dirname $parentDir] jpayne@69: lappend dirs [file join $parentDir lib $basename$version] jpayne@69: lappend dirs [file join $grandParentDir lib $basename$version] jpayne@69: lappend dirs [file join $parentDir library] jpayne@69: if {0} { jpayne@69: lappend dirs [file join $grandParentDir library] jpayne@69: lappend dirs [file join $grandParentDir $basename$patch library] jpayne@69: lappend dirs [file join [file dirname $grandParentDir] \ jpayne@69: $basename$patch library] jpayne@69: } jpayne@69: } jpayne@69: # uniquify $dirs in order jpayne@69: array set seen {} jpayne@69: foreach i $dirs { jpayne@69: # Make sure $i is unique under normalization. Avoid repeated [source]. jpayne@69: if {[interp issafe]} { jpayne@69: # Safe interps have no [file normalize]. jpayne@69: set norm $i jpayne@69: } else { jpayne@69: set norm [file normalize $i] jpayne@69: } jpayne@69: if {[info exists seen($norm)]} { jpayne@69: continue jpayne@69: } jpayne@69: set seen($norm) {} jpayne@69: jpayne@69: set the_library $i jpayne@69: set file [file join $i $initScript] jpayne@69: jpayne@69: # source everything when in a safe interpreter because we have a jpayne@69: # source command, but no file exists command jpayne@69: jpayne@69: if {[interp issafe] || [file exists $file]} { jpayne@69: if {![catch {uplevel #0 [list source $file]} msg opts]} { jpayne@69: return jpayne@69: } jpayne@69: append errors "$file: $msg\n" jpayne@69: append errors [dict get $opts -errorinfo]\n jpayne@69: } jpayne@69: } jpayne@69: unset -nocomplain the_library jpayne@69: set msg "Can't find a usable $initScript in the following directories: \n" jpayne@69: append msg " $dirs\n\n" jpayne@69: append msg "$errors\n\n" jpayne@69: append msg "This probably means that $basename wasn't installed properly.\n" jpayne@69: error $msg jpayne@69: } jpayne@69: jpayne@69: jpayne@69: # ---------------------------------------------------------------------- jpayne@69: # auto_mkindex jpayne@69: # ---------------------------------------------------------------------- jpayne@69: # The following procedures are used to generate the tclIndex file from Tcl jpayne@69: # source files. They use a special safe interpreter to parse Tcl source jpayne@69: # files, writing out index entries as "proc" commands are encountered. This jpayne@69: # implementation won't work in a safe interpreter, since a safe interpreter jpayne@69: # can't create the special parser and mess with its commands. jpayne@69: jpayne@69: if {[interp issafe]} { jpayne@69: return ;# Stop sourcing the file here jpayne@69: } jpayne@69: jpayne@69: # auto_mkindex -- jpayne@69: # Regenerate a tclIndex file from Tcl source files. Takes as argument the jpayne@69: # name of the directory in which the tclIndex file is to be placed, followed jpayne@69: # by any number of glob patterns to use in that directory to locate all of the jpayne@69: # relevant files. jpayne@69: # jpayne@69: # Arguments: jpayne@69: # dir - Name of the directory in which to create an index. jpayne@69: jpayne@69: # args - Any number of additional arguments giving the names of files jpayne@69: # within dir. If no additional are given auto_mkindex will look jpayne@69: # for *.tcl. jpayne@69: jpayne@69: proc auto_mkindex {dir args} { jpayne@69: if {[interp issafe]} { jpayne@69: error "can't generate index within safe interpreter" jpayne@69: } jpayne@69: jpayne@69: set oldDir [pwd] jpayne@69: cd $dir jpayne@69: jpayne@69: append index "# Tcl autoload index file, version 2.0\n" jpayne@69: append index "# This file is generated by the \"auto_mkindex\" command\n" jpayne@69: append index "# and sourced to set up indexing information for one or\n" jpayne@69: append index "# more commands. Typically each line is a command that\n" jpayne@69: append index "# sets an element in the auto_index array, where the\n" jpayne@69: append index "# element name is the name of a command and the value is\n" jpayne@69: append index "# a script that loads the command.\n\n" jpayne@69: if {![llength $args]} { jpayne@69: set args *.tcl jpayne@69: } jpayne@69: jpayne@69: auto_mkindex_parser::init jpayne@69: foreach file [lsort [glob -- {*}$args]] { jpayne@69: try { jpayne@69: append index [auto_mkindex_parser::mkindex $file] jpayne@69: } on error {msg opts} { jpayne@69: cd $oldDir jpayne@69: return -options $opts $msg jpayne@69: } jpayne@69: } jpayne@69: auto_mkindex_parser::cleanup jpayne@69: jpayne@69: set fid [open "tclIndex" w] jpayne@69: puts -nonewline $fid $index jpayne@69: close $fid jpayne@69: cd $oldDir jpayne@69: } jpayne@69: jpayne@69: # Original version of auto_mkindex that just searches the source code for jpayne@69: # "proc" at the beginning of the line. jpayne@69: jpayne@69: proc auto_mkindex_old {dir args} { jpayne@69: set oldDir [pwd] jpayne@69: cd $dir jpayne@69: set dir [pwd] jpayne@69: append index "# Tcl autoload index file, version 2.0\n" jpayne@69: append index "# This file is generated by the \"auto_mkindex\" command\n" jpayne@69: append index "# and sourced to set up indexing information for one or\n" jpayne@69: append index "# more commands. Typically each line is a command that\n" jpayne@69: append index "# sets an element in the auto_index array, where the\n" jpayne@69: append index "# element name is the name of a command and the value is\n" jpayne@69: append index "# a script that loads the command.\n\n" jpayne@69: if {![llength $args]} { jpayne@69: set args *.tcl jpayne@69: } jpayne@69: foreach file [lsort [glob -- {*}$args]] { jpayne@69: set f "" jpayne@69: set error [catch { jpayne@69: set f [open $file] jpayne@69: fconfigure $f -eofchar "\032 {}" jpayne@69: while {[gets $f line] >= 0} { jpayne@69: if {[regexp {^proc[ ]+([^ ]*)} $line match procName]} { jpayne@69: set procName [lindex [auto_qualify $procName "::"] 0] jpayne@69: append index "set [list auto_index($procName)]" jpayne@69: append index " \[list source \[file join \$dir [list $file]\]\]\n" jpayne@69: } jpayne@69: } jpayne@69: close $f jpayne@69: } msg opts] jpayne@69: if {$error} { jpayne@69: catch {close $f} jpayne@69: cd $oldDir jpayne@69: return -options $opts $msg jpayne@69: } jpayne@69: } jpayne@69: set f "" jpayne@69: set error [catch { jpayne@69: set f [open tclIndex w] jpayne@69: puts -nonewline $f $index jpayne@69: close $f jpayne@69: cd $oldDir jpayne@69: } msg opts] jpayne@69: if {$error} { jpayne@69: catch {close $f} jpayne@69: cd $oldDir jpayne@69: error $msg $info $code jpayne@69: return -options $opts $msg jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: # Create a safe interpreter that can be used to parse Tcl source files jpayne@69: # generate a tclIndex file for autoloading. This interp contains commands for jpayne@69: # things that need index entries. Each time a command is executed, it writes jpayne@69: # an entry out to the index file. jpayne@69: jpayne@69: namespace eval auto_mkindex_parser { jpayne@69: variable parser "" ;# parser used to build index jpayne@69: variable index "" ;# maintains index as it is built jpayne@69: variable scriptFile "" ;# name of file being processed jpayne@69: variable contextStack "" ;# stack of namespace scopes jpayne@69: variable imports "" ;# keeps track of all imported cmds jpayne@69: variable initCommands ;# list of commands that create aliases jpayne@69: if {![info exists initCommands]} { jpayne@69: set initCommands [list] jpayne@69: } jpayne@69: jpayne@69: proc init {} { jpayne@69: variable parser jpayne@69: variable initCommands jpayne@69: jpayne@69: if {![interp issafe]} { jpayne@69: set parser [interp create -safe] jpayne@69: $parser hide info jpayne@69: $parser hide rename jpayne@69: $parser hide proc jpayne@69: $parser hide namespace jpayne@69: $parser hide eval jpayne@69: $parser hide puts jpayne@69: foreach ns [$parser invokehidden namespace children ::] { jpayne@69: # MUST NOT DELETE "::tcl" OR BAD THINGS HAPPEN! jpayne@69: if {$ns eq "::tcl"} continue jpayne@69: $parser invokehidden namespace delete $ns jpayne@69: } jpayne@69: foreach cmd [$parser invokehidden info commands ::*] { jpayne@69: $parser invokehidden rename $cmd {} jpayne@69: } jpayne@69: $parser invokehidden proc unknown {args} {} jpayne@69: jpayne@69: # We'll need access to the "namespace" command within the jpayne@69: # interp. Put it back, but move it out of the way. jpayne@69: jpayne@69: $parser expose namespace jpayne@69: $parser invokehidden rename namespace _%@namespace jpayne@69: $parser expose eval jpayne@69: $parser invokehidden rename eval _%@eval jpayne@69: jpayne@69: # Install all the registered psuedo-command implementations jpayne@69: jpayne@69: foreach cmd $initCommands { jpayne@69: eval $cmd jpayne@69: } jpayne@69: } jpayne@69: } jpayne@69: proc cleanup {} { jpayne@69: variable parser jpayne@69: interp delete $parser jpayne@69: unset parser jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: # auto_mkindex_parser::mkindex -- jpayne@69: # jpayne@69: # Used by the "auto_mkindex" command to create a "tclIndex" file for the given jpayne@69: # Tcl source file. Executes the commands in the file, and handles things like jpayne@69: # the "proc" command by adding an entry for the index file. Returns a string jpayne@69: # that represents the index file. jpayne@69: # jpayne@69: # Arguments: jpayne@69: # file Name of Tcl source file to be indexed. jpayne@69: jpayne@69: proc auto_mkindex_parser::mkindex {file} { jpayne@69: variable parser jpayne@69: variable index jpayne@69: variable scriptFile jpayne@69: variable contextStack jpayne@69: variable imports jpayne@69: jpayne@69: set scriptFile $file jpayne@69: jpayne@69: set fid [open $file] jpayne@69: fconfigure $fid -eofchar "\032 {}" jpayne@69: set contents [read $fid] jpayne@69: close $fid jpayne@69: jpayne@69: # There is one problem with sourcing files into the safe interpreter: jpayne@69: # references like "$x" will fail since code is not really being executed jpayne@69: # and variables do not really exist. To avoid this, we replace all $ with jpayne@69: # \0 (literally, the null char) later, when getting proc names we will jpayne@69: # have to reverse this replacement, in case there were any $ in the proc jpayne@69: # name. This will cause a problem if somebody actually tries to have a \0 jpayne@69: # in their proc name. Too bad for them. jpayne@69: set contents [string map [list \$ \0] $contents] jpayne@69: jpayne@69: set index "" jpayne@69: set contextStack "" jpayne@69: set imports "" jpayne@69: jpayne@69: $parser eval $contents jpayne@69: jpayne@69: foreach name $imports { jpayne@69: catch {$parser eval [list _%@namespace forget $name]} jpayne@69: } jpayne@69: return $index jpayne@69: } jpayne@69: jpayne@69: # auto_mkindex_parser::hook command jpayne@69: # jpayne@69: # Registers a Tcl command to evaluate when initializing the child interpreter jpayne@69: # used by the mkindex parser. The command is evaluated in the parent jpayne@69: # interpreter, and can use the variable auto_mkindex_parser::parser to get to jpayne@69: # the child jpayne@69: jpayne@69: proc auto_mkindex_parser::hook {cmd} { jpayne@69: variable initCommands jpayne@69: jpayne@69: lappend initCommands $cmd jpayne@69: } jpayne@69: jpayne@69: # auto_mkindex_parser::slavehook command jpayne@69: # jpayne@69: # Registers a Tcl command to evaluate when initializing the child interpreter jpayne@69: # used by the mkindex parser. The command is evaluated in the child jpayne@69: # interpreter. jpayne@69: jpayne@69: proc auto_mkindex_parser::slavehook {cmd} { jpayne@69: variable initCommands jpayne@69: jpayne@69: # The $parser variable is defined to be the name of the child interpreter jpayne@69: # when this command is used later. jpayne@69: jpayne@69: lappend initCommands "\$parser eval [list $cmd]" jpayne@69: } jpayne@69: jpayne@69: # auto_mkindex_parser::command -- jpayne@69: # jpayne@69: # Registers a new command with the "auto_mkindex_parser" interpreter that jpayne@69: # parses Tcl files. These commands are fake versions of things like the jpayne@69: # "proc" command. When you execute them, they simply write out an entry to a jpayne@69: # "tclIndex" file for auto-loading. jpayne@69: # jpayne@69: # This procedure allows extensions to register their own commands with the jpayne@69: # auto_mkindex facility. For example, a package like [incr Tcl] might jpayne@69: # register a "class" command so that class definitions could be added to a jpayne@69: # "tclIndex" file for auto-loading. jpayne@69: # jpayne@69: # Arguments: jpayne@69: # name Name of command recognized in Tcl files. jpayne@69: # arglist Argument list for command. jpayne@69: # body Implementation of command to handle indexing. jpayne@69: jpayne@69: proc auto_mkindex_parser::command {name arglist body} { jpayne@69: hook [list auto_mkindex_parser::commandInit $name $arglist $body] jpayne@69: } jpayne@69: jpayne@69: # auto_mkindex_parser::commandInit -- jpayne@69: # jpayne@69: # This does the actual work set up by auto_mkindex_parser::command. This is jpayne@69: # called when the interpreter used by the parser is created. jpayne@69: # jpayne@69: # Arguments: jpayne@69: # name Name of command recognized in Tcl files. jpayne@69: # arglist Argument list for command. jpayne@69: # body Implementation of command to handle indexing. jpayne@69: jpayne@69: proc auto_mkindex_parser::commandInit {name arglist body} { jpayne@69: variable parser jpayne@69: jpayne@69: set ns [namespace qualifiers $name] jpayne@69: set tail [namespace tail $name] jpayne@69: if {$ns eq ""} { jpayne@69: set fakeName [namespace current]::_%@fake_$tail jpayne@69: } else { jpayne@69: set fakeName [namespace current]::[string map {:: _} _%@fake_$name] jpayne@69: } jpayne@69: proc $fakeName $arglist $body jpayne@69: jpayne@69: # YUK! Tcl won't let us alias fully qualified command names, so we can't jpayne@69: # handle names like "::itcl::class". Instead, we have to build procs with jpayne@69: # the fully qualified names, and have the procs point to the aliases. jpayne@69: jpayne@69: if {[string match *::* $name]} { jpayne@69: set exportCmd [list _%@namespace export [namespace tail $name]] jpayne@69: $parser eval [list _%@namespace eval $ns $exportCmd] jpayne@69: jpayne@69: # The following proc definition does not work if you want to tolerate jpayne@69: # space or something else diabolical in the procedure name, (i.e., jpayne@69: # space in $alias). The following does not work: jpayne@69: # "_%@eval {$alias} \$args" jpayne@69: # because $alias gets concat'ed to $args. The following does not work jpayne@69: # because $cmd is somehow undefined jpayne@69: # "set cmd {$alias} \; _%@eval {\$cmd} \$args" jpayne@69: # A gold star to someone that can make test autoMkindex-3.3 work jpayne@69: # properly jpayne@69: jpayne@69: set alias [namespace tail $fakeName] jpayne@69: $parser invokehidden proc $name {args} "_%@eval {$alias} \$args" jpayne@69: $parser alias $alias $fakeName jpayne@69: } else { jpayne@69: $parser alias $name $fakeName jpayne@69: } jpayne@69: return jpayne@69: } jpayne@69: jpayne@69: # auto_mkindex_parser::fullname -- jpayne@69: # jpayne@69: # Used by commands like "proc" within the auto_mkindex parser. Returns the jpayne@69: # qualified namespace name for the "name" argument. If the "name" does not jpayne@69: # start with "::", elements are added from the current namespace stack to jpayne@69: # produce a qualified name. Then, the name is examined to see whether or not jpayne@69: # it should really be qualified. If the name has more than the leading "::", jpayne@69: # it is returned as a fully qualified name. Otherwise, it is returned as a jpayne@69: # simple name. That way, the Tcl autoloader will recognize it properly. jpayne@69: # jpayne@69: # Arguments: jpayne@69: # name - Name that is being added to index. jpayne@69: jpayne@69: proc auto_mkindex_parser::fullname {name} { jpayne@69: variable contextStack jpayne@69: jpayne@69: if {![string match ::* $name]} { jpayne@69: foreach ns $contextStack { jpayne@69: set name "${ns}::$name" jpayne@69: if {[string match ::* $name]} { jpayne@69: break jpayne@69: } jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: if {[namespace qualifiers $name] eq ""} { jpayne@69: set name [namespace tail $name] jpayne@69: } elseif {![string match ::* $name]} { jpayne@69: set name "::$name" jpayne@69: } jpayne@69: jpayne@69: # Earlier, mkindex replaced all $'s with \0. Now, we have to reverse that jpayne@69: # replacement. jpayne@69: return [string map [list \0 \$] $name] jpayne@69: } jpayne@69: jpayne@69: # auto_mkindex_parser::indexEntry -- jpayne@69: # jpayne@69: # Used by commands like "proc" within the auto_mkindex parser to add a jpayne@69: # correctly-quoted entry to the index. This is shared code so it is done jpayne@69: # *right*, in one place. jpayne@69: # jpayne@69: # Arguments: jpayne@69: # name - Name that is being added to index. jpayne@69: jpayne@69: proc auto_mkindex_parser::indexEntry {name} { jpayne@69: variable index jpayne@69: variable scriptFile jpayne@69: jpayne@69: # We convert all metacharacters to their backslashed form, and pre-split jpayne@69: # the file name that we know about (which will be a proper list, and so jpayne@69: # correctly quoted). jpayne@69: jpayne@69: set name [string range [list \}[fullname $name]] 2 end] jpayne@69: set filenameParts [file split $scriptFile] jpayne@69: jpayne@69: append index [format \ jpayne@69: {set auto_index(%s) [list source [file join $dir %s]]%s} \ jpayne@69: $name $filenameParts \n] jpayne@69: return jpayne@69: } jpayne@69: jpayne@69: if {[llength $::auto_mkindex_parser::initCommands]} { jpayne@69: return jpayne@69: } jpayne@69: jpayne@69: # Register all of the procedures for the auto_mkindex parser that will build jpayne@69: # the "tclIndex" file. jpayne@69: jpayne@69: # AUTO MKINDEX: proc name arglist body jpayne@69: # Adds an entry to the auto index list for the given procedure name. jpayne@69: jpayne@69: auto_mkindex_parser::command proc {name args} { jpayne@69: indexEntry $name jpayne@69: } jpayne@69: jpayne@69: # Conditionally add support for Tcl byte code files. There are some tricky jpayne@69: # details here. First, we need to get the tbcload library initialized in the jpayne@69: # current interpreter. We cannot load tbcload into the child until we have jpayne@69: # done so because it needs access to the tcl_patchLevel variable. Second, jpayne@69: # because the package index file may defer loading the library until we invoke jpayne@69: # a command, we need to explicitly invoke auto_load to force it to be loaded. jpayne@69: # This should be a noop if the package has already been loaded jpayne@69: jpayne@69: auto_mkindex_parser::hook { jpayne@69: try { jpayne@69: package require tbcload jpayne@69: } on error {} { jpayne@69: # OK, don't have it so do nothing jpayne@69: } on ok {} { jpayne@69: if {[namespace which -command tbcload::bcproc] eq ""} { jpayne@69: auto_load tbcload::bcproc jpayne@69: } jpayne@69: load {} tbcload $auto_mkindex_parser::parser jpayne@69: jpayne@69: # AUTO MKINDEX: tbcload::bcproc name arglist body jpayne@69: # Adds an entry to the auto index list for the given pre-compiled jpayne@69: # procedure name. jpayne@69: jpayne@69: auto_mkindex_parser::commandInit tbcload::bcproc {name args} { jpayne@69: indexEntry $name jpayne@69: } jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: # AUTO MKINDEX: namespace eval name command ?arg arg...? jpayne@69: # Adds the namespace name onto the context stack and evaluates the associated jpayne@69: # body of commands. jpayne@69: # jpayne@69: # AUTO MKINDEX: namespace import ?-force? pattern ?pattern...? jpayne@69: # Performs the "import" action in the parser interpreter. This is important jpayne@69: # for any commands contained in a namespace that affect the index. For jpayne@69: # example, a script may say "itcl::class ...", or it may import "itcl::*" and jpayne@69: # then say "class ...". This procedure does the import operation, but keeps jpayne@69: # track of imported patterns so we can remove the imports later. jpayne@69: jpayne@69: auto_mkindex_parser::command namespace {op args} { jpayne@69: switch -- $op { jpayne@69: eval { jpayne@69: variable parser jpayne@69: variable contextStack jpayne@69: jpayne@69: set name [lindex $args 0] jpayne@69: set args [lrange $args 1 end] jpayne@69: jpayne@69: set contextStack [linsert $contextStack 0 $name] jpayne@69: $parser eval [list _%@namespace eval $name] $args jpayne@69: set contextStack [lrange $contextStack 1 end] jpayne@69: } jpayne@69: import { jpayne@69: variable parser jpayne@69: variable imports jpayne@69: foreach pattern $args { jpayne@69: if {$pattern ne "-force"} { jpayne@69: lappend imports $pattern jpayne@69: } jpayne@69: } jpayne@69: catch {$parser eval "_%@namespace import $args"} jpayne@69: } jpayne@69: ensemble { jpayne@69: variable parser jpayne@69: variable contextStack jpayne@69: if {[lindex $args 0] eq "create"} { jpayne@69: set name ::[join [lreverse $contextStack] ::] jpayne@69: catch { jpayne@69: set name [dict get [lrange $args 1 end] -command] jpayne@69: if {![string match ::* $name]} { jpayne@69: set name ::[join [lreverse $contextStack] ::]$name jpayne@69: } jpayne@69: regsub -all ::+ $name :: name jpayne@69: } jpayne@69: # create artifical proc to force an entry in the tclIndex jpayne@69: $parser eval [list ::proc $name {} {}] jpayne@69: } jpayne@69: } jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: # AUTO MKINDEX: oo::class create name ?definition? jpayne@69: # Adds an entry to the auto index list for the given class name. jpayne@69: auto_mkindex_parser::command oo::class {op name {body ""}} { jpayne@69: if {$op eq "create"} { jpayne@69: indexEntry $name jpayne@69: } jpayne@69: } jpayne@69: auto_mkindex_parser::command class {op name {body ""}} { jpayne@69: if {$op eq "create"} { jpayne@69: indexEntry $name jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: return