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