1 #-----------------------------------------------------------------------------
2 # TclInit.tcl -- Extended Tcl initialization.
3 #-----------------------------------------------------------------------------
4 # $Id: TclInit.tcl,v 2.0 1992/10/16 04:51:37 markd Rel $
5 #-----------------------------------------------------------------------------
8 set TCLENV
(inUnknown
) 0
11 # Unknown command trap handler.
13 proc unknown {cmdName args
} {
15 if $TCLENV(inUnknown
) {
16 error "recursive unknown command trap: \"$cmdName\""}
17 set TCLENV
(inUnknown
) 1
19 set stat
[catch {demand_load
$cmdName} ret
]
20 if {$stat == 0 && $ret} {
21 set TCLENV
(inUnknown
) 0
22 return [uplevel 1 [list eval $cmdName $args]]
26 global errorInfo errorCode
27 set TCLENV
(inUnknown
) 0
28 error $ret $errorInfo $errorCode
31 global env interactiveSession noAutoExec
33 if {$interactiveSession && ([info level
] == 1) && ([info script
] == "") &&
34 (!([info exists noAutoExec
] && [set noAutoExec
]))} {
35 if {[file rootname
$cmdName] == "$cmdName"} {
36 if [info exists env
(PATH
)] {
37 set binpath
[searchpath
[split $env(PATH
) :] $cmdName]
39 set binpath
[searchpath
"." $cmdName]
44 if {[file executable
$binpath]} {
45 set TCLENV
(inUnknown
) 0
46 uplevel 1 [list system
[concat $cmdName $args]]
50 set TCLENV
(inUnknown
) 0
51 error "invalid command name: \"$cmdName\""
55 # Search a path list for a file. (catch is for bad ~user)
57 proc searchpath
{pathlist
file} {
58 foreach dir
$pathlist {
59 if {$dir == ""} {set dir .
}
60 if {[catch {file exists
$dir/$file} result
] == 0 && $result} {
68 # Define a proc to be available for demand_load.
70 proc autoload
{filenam args
} {
73 set TCLENV
(PROC
:$i) [list F
$filenam]
78 # Search TCLPATH for a file to source.
81 global TCLPATH errorCode
82 if {[string first
/ $name] >= 0} {
83 return [uplevel #0 source $name]
85 set where
[searchpath
$TCLPATH $name]
87 error "couldn't find $name in Tcl search path" "" "TCLSH FILE_NOT_FOUND"
89 uplevel #0 source $where
92 autoload buildidx.tcl buildpackageindex
94 # == Put any code you want all Tcl programs to include here. ==
96 if !$interactiveSession return
98 # == Interactive Tcl session initialization ==
100 set TCLENV
(topLevelPromptHook
) {global programName
; concat "$programName>" }
101 set TCLENV
(downLevelPromptHook
) {concat "=>"}
103 if [file readable ~
/.tclrc
] {source ~
/.tclrc
}