Corrected a long-standing error in which ending text with a literal
[xcircuit.git] / lib / tcl / xcircuit.tcl.in
blobe70b9cb1bf1188121c9f14b9cae71e23d2c08a12
1 # Wishrc startup for ToolScript (xcircuit)
3 # Loads the shared object (xcircuit.so) file into Tcl, runs the
4 # wrapper script to generate the GUI, then runs the initialization
5 # routine for the XCircuit package.
7 global XCOps
9 set envlibdir [array get env "XCIRCUIT_LIB_DIR"]
10 if {$envlibdir == {}} {
11 set XCIRCUIT_LIB_DIR LIBDIR
13 unset envlibdir
15 set envsrcdir [array get env "XCIRCUIT_SRC_DIR"]
16 if {$envsrcdir != {}} {
17 set path [lindex $envsrcdir 1]
18 } else {
19 set path SCRIPTSDIR
20 set XCIRCUIT_SRC_DIR $path
22 unset envsrcdir
24 if {[string compare $tcl_platform(platform) "windows"] == 0} {
25 set libext .dll
26 } else {
27 set libext .so
30 set tcllibdir $path
31 if {![file exists ${tcllibdir}/xcircuit$libext]} {
32 set tcllibdir ${path}/tcl
34 if {![file exists ${tcllibdir}/xcircuit$libext]} {
35 puts stderr "Error: Cannot find file xcircuit$libext"
37 load ${tcllibdir}/xcircuit$libext
39 package require Xcircuit
41 # It is important to make sure no magic commands overlap with Tcl built-in
42 # commands, because otherwise the namespace import will fail.
44 proc pushnamespace { name } {
46 set y [namespace eval ${name} info commands ::${name}::*]
47 set z [info commands]
49 foreach v $y {
50 regsub -all {\*} $v {\\*} i
51 set x [namespace tail $i]
52 if {[lsearch $z $x] < 0} {
53 namespace import $i
54 } else {
55 puts "Warning: ${name} command '$x' use fully-qualified name '$v'"
60 proc popnamespace { name } {
61 set z [info commands]
62 set l [expr [string length ${name}] + 5]
64 while {[set v [lsearch $z ${name}_tcl_*]] >= 0} {
65 set y [lindex $z $v]
66 set w [string range $y $l end]
67 interp alias {} ::$w {}
68 rename ::$y ::$w
69 puts "Info: replacing ::$w with ::$y"
71 namespace forget ::${name}::*
74 set auto_noexec 1 ;# don't EVER call UNIX commands w/o "shell" in front
76 # Have we called xcircuit from tkcon?
78 if {[lsearch [interp aliases] tkcon] != -1} {
79 set XcConsole tkcon
80 wm withdraw .
82 # Rename conflicting TkCon commands before pushing xcircuit's namespace
84 if {[lsearch [info commands] orig_edit] < 0} { rename edit orig_edit }
85 } else {
87 # Extend the "unknown" command-line handler to be compatible with the
88 # way we have renamed certain core Tcl/Tk functions.
90 rename unknown tcl_unknown
91 proc unknown { args } {
92 # CAD tools special:
93 # Check for commands which were renamed to tcl_(command)
95 set cmd [lindex $args 0]
96 if {[lsearch [info commands] tcl_$cmd] >= 0} {
97 set arglist [concat tcl_$cmd [lrange $args 1 end]]
98 set ret [catch {eval $arglist} result]
99 if {$ret == 0} {
100 return $result
101 } else {
102 return -code $ret -errorcode $errorCode $result
105 return [eval [concat tcl_unknown $args]]
109 # Rename conflicting Tcl/Tk commands before pushing xcircuit's namespace
111 if {[lsearch [info commands] tcl_label] < 0} {catch {rename label tcl_label}}
113 # Allow commands in the xcircuit namespace to be called from the toplevel namespace
115 pushnamespace xcircuit
117 #----------------------------------------------------------------------
118 # Cross-Application section
119 #----------------------------------------------------------------------
121 # Check namespaces for existence of other applications
122 set UsingMagic 0
123 set UsingIRSIM 0
124 set UsingNetgen 0
125 set nlist [namespace children]
126 foreach i $nlist {
127 switch $i {
128 ::magic { set UsingMagic 1 }
129 ::irsim { set UsingIRSIM 1 }
130 ::netgen { set UsingNetgen 1 }
134 # Setup IRSIM assuming that the Tcl version is installed.
135 # We do not need to rename procedure irsim to NULL because it is
136 # redefined in a script, which simply overwrites the original.
138 proc irsim { args } {
139 global CAD_ROOT
140 set irsimscript [glob -nocomplain ${CAD_ROOT}/irsim/tcl/irsim.tcl]
141 if { ${irsimscript} == {} } {
142 puts stderr "\"irsim\" requires Tcl-based IRSIM version 9.6 or newer."
143 puts stderr "Could not find script \"irsim.tcl\". If IRSIM is installed in a"
144 puts stderr "place other than CAD_ROOT (=${CAD_ROOT}), use the command"
145 puts stderr "\"source <path>/irsim.tcl\" before doing \"irsim\"."
146 } else {
147 source $irsimscript
148 eval {irsim} $args
152 # Setup Magic assuming that the Tcl version is installed.
154 proc magic { args } {
155 global CAD_ROOT
156 set magicscript [glob -nocomplain ${CAD_ROOT}/magic/tcl/magic.tcl]
157 if { ${magicscript} == {} } {
158 puts stderr "\"magic\" requires Tcl-based Magic version 7.2 or newer."
159 puts stderr "Could not find script \"magic.tcl\". If Magic is installed in a"
160 puts stderr "place other than CAD_ROOT (=${CAD_ROOT}), use the command"
161 puts stderr "\"source <path>/magic.tcl\"."
162 } else {
163 set argv $args
164 set argc [llength $args]
165 uplevel #0 source $magicscript
169 # Setup Netgen assuming that the Tcl version is installed.
171 proc netgen { args } {
172 global CAD_ROOT
173 set netgenscript [glob -nocomplain ${CAD_ROOT}/netgen/tcl/netgen.tcl]
174 if { ${netgenscript} == {} } {
175 puts stderr "\"netgen\" requires Tcl-based Netgen version 1.2 or newer."
176 puts stderr "Could not find script \"netgen.tcl\". If Netgen is installed in a"
177 puts stderr "place other than CAD_ROOT (=${CAD_ROOT}), use the command"
178 puts stderr "\"source <path>/netgen.tcl\"."
179 } else {
180 set argv $args
181 set argc [llength $args]
182 source $netgenscript
186 # Source the default resources file
188 catch {source ${tcllibdir}/resource.tcl}
190 # Sourcing of individual resource overrides
192 set envhomedir [array get env "HOME"]
193 if {$envhomedir != {}} {
194 set homepath [lindex $envhomedir 1]
195 set homedefaults ${homepath}/.Xdefaults
196 if {[file exists $homedefaults]} {
197 if {[catch {option readfile $homedefaults userDefault}]} {
198 puts stderr "Warning: Error parsing file $homedefaults"
201 unset homedefaults
202 unset homepath
204 unset envhomedir
206 # Run the xcircuit start function
208 if {[string length $argv] == 0} {
209 # Source the GUI-generating script
210 source ${tcllibdir}/wrapper.tcl
211 xcircuit::start .xcircuit
212 } else {
213 set do_wrapper true
214 set argafter {xcircuit::start}
215 for {set i 0} {$i < $argc} {incr i 1} {
216 set x [lindex $argv $i]
217 switch -regexp -- $x {
218 ^-now {
219 set do_wrapper false
221 ^-r {
222 set XCOps(library) "all"
224 ^-noc {
225 # this option already handled---absorb it and do nothing.
227 default {
228 lappend argafter $x
233 # Set up for interactive or filter (batch) mode processing
234 if {$do_wrapper} {
235 # Source the GUI-generating script
236 source ${tcllibdir}/wrapper.tcl
237 set argafter [linsert $argafter 1 .xcircuit]
238 } elseif {[info commands wm] != ""} {
239 simple .xcdummy -exitproc "quitnocheck"
240 set XCOps(window) .xcdummy
242 unset x i do_wrapper
243 eval $argafter ;# xcircuit::start .xcircuit ${argv}
245 unset tcllibdir
247 # The GUI wrapper iconifies the window while generating it
248 catch {wm deiconify $XCOps(toplevel)}
250 # Invoke the "wire" button by default
251 catch {$XCOps(focus).mainframe.toolbar.bw invoke}
253 # Xcircuit start function drops back to interpreter after initialization & setup
255 if {[info commands wm] != ""} {
256 if {[string range [wm title .] 0 3] == "wish"} {
257 wm withdraw .
259 if {[string range [wm title .] 0 8] == "xcircexec"} {
260 wm withdraw .