-
Notifications
You must be signed in to change notification settings - Fork 8
/
tcllauncher.tcl
80 lines (63 loc) · 2.13 KB
/
tcllauncher.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#
# tcllauncher.tcl - tcl code that tcllauncher uses to do its thing
#
package require Tclx
#
# this is the code that gets called when Tcl launches because the
# tcllauncher "version" of Tcl jimmies the command line to make it
# so.
#
# this routine must now figure out what to do to launch the app
#
#
proc main {{argv ""}} {
set prog [info nameofexecutable]
# have we been invoked as a shell? If so, prog is empty, get it from
# the SHELL environment variable
if {$prog == ""} {
set prog $::env(SHELL)
}
set path [file split $prog]
set shortName [lindex $path end]
#
# tcllauncher cannot be invoked directly as "tcllauncher" -- it must be
# aliased to some other name
#
if {$shortName == "tcllauncher"} {
puts stderr "tcllauncher cannot be invoked as \"tcllauncher\"; it must be copied or linked as some other name"
exit 255
}
# if the last dir in the chain is "bin", swap in "lib/tcllauncher" in
# its place and tag a ".tcl" onto the end of the path name.
#
# otherwise just look in the same directory where the instance of the
# tcllauncher was found.
#
#puts stderr "path '$path', prog '$prog', shortName '$shortName'"
if {[lindex $path end-1] == "bin"} {
# this version looks for ../lib/tcllauncher/$shortName.tcl`
#set path [eval file join [lreplace $path end-1 end-1 lib tcllauncher]]
# this version looks for ../lib/$shortName/main.tcl
set ::launchdir [eval file join [lreplace $path end-1 end lib $shortName]]
set path [eval file join $::launchdir main.tcl]
} else {
set path $prog.tcl
}
if {![file readable $path]} {
puts stderr "$shortName: can't read '$path' (tcllauncher)"
exit 254
}
set ::argv0 $shortName
set initialArgv $argv
# ok now source in the file we (tcllauncher) figured out is the one
if {[catch {uplevel #0 source $path} catchResult] == 1} {
append ::errorInfo "\n from tcllauncher running \"[string trim "$::argv0 $initialArgv"]\""
puts stderr $::errorInfo
exit 255
}
exit 0
}
if {!$tcl_interactive} {
main $argv
}
# vim: set ts=8 sw=4 sts=4 noet :