Support RETURN-FROM in DEF%TR forms
[maxima.git] / interfaces / xmaxima / Tkmaxima / Paths.tcl
blob1860fc3aecf7fd2f2fff8c51e0b98ab7f47826b4
1 ############################################################
2 # Paths.tcl #
3 # Copyright (C) 1998 William F. Schelter #
4 # For distribution under GNU public License. See COPYING. #
5 # #
6 # Time-stamp: "2021-04-06 13:58:37 villate" #
7 ############################################################
9 # Attach this near the bottom of the xmaxima code to find the paths needed
10 # to start up the interface.
12 proc setMaxDir {} {
13 global env maxima_priv autoconf tcl_platform
15 if {$tcl_platform(platform) == "windows"} {
16 # Make sure the signals thread is started
17 set env(MAXIMA_SIGNALS_THREAD) "1"
19 # Assume the executable is one level down from the top
20 # for 5.6 this was src/ and for 5.9 its bin/
21 set up [file dir [file dir [info name]]]
23 if {[info exists autoconf] && \
24 [info exists autoconf(prefix)] && \
25 [info exists autoconf(exec_prefix)] && \
26 [info exists autoconf(libdir)] && \
27 [info exists autoconf(libexecdir)] && \
28 [info exists autoconf(datadir)] && \
29 [info exists autoconf(infodir)] && \
30 [info exists autoconf(version)] && \
31 [info exists autoconf(package)] && \
32 [file isdir $autoconf(datadir)] && \
33 [file isdir \
34 [file join $autoconf(datadir) \
35 $autoconf(package) $autoconf(version)]]} {
36 # Assume it's CYGWIN or MSYS in /usr/local
37 } elseif {[file isdir $up/lib] && \
38 [file isdir $up/bin] && \
39 [file isdir $up/libexec] && \
40 [file isdir $up/info] && \
41 [file isdir $up/share]} {
42 set autoconf(prefix) $up
43 set env(MAXIMA_PREFIX) $up
44 set autoconf(exec_prefix) $up
45 set autoconf(libdir) "$up/lib"
46 set autoconf(libexecdir) "$up/libexec"
47 set autoconf(datadir) "$up/share"
48 set autoconf(infodir) "$up/info"
49 # These two should be valid
50 # set autoconf(package) "maxima"
51 # set autoconf(version) "5.9.0rc1"
52 } else {
53 # Old windows 5.5 layout
54 # Assume we are in the same directory as saved_maxima
55 if {[file isfile [set exe $up/src/saved_maxima.exe]]} {
56 set env(MAXIMA_DIRECTORY) $up
57 set maxima_priv(maxima_verpkgdatadir) \
58 $env(MAXIMA_DIRECTORY)
59 set maxima_priv(xmaxima_maxima) $exe
60 set maxima_priv(maxima_xmaximadir) [file dir $exe]
62 # This should be unused
63 set maxima_priv(maxima_verpkglibdir) \
64 $env(MAXIMA_DIRECTORY)
65 set maxima_priv(maxima_verpkgdatadir) \
66 $env(MAXIMA_DIRECTORY)
68 # This should be unused
69 set maxima_priv(maxima_prefix) \
70 $env(MAXIMA_DIRECTORY)
74 #mike Could someone document all of these environment variables?
75 # autoconf(prefix) does not seem to me to be the equivalent of
76 # $env(MAXIMA_DIRECTORY) so I don't understand the next statement
78 # jfa: MAXIMA_PREFIX supersedes MAXIMA_DIRECTORY. (Why? Because the
79 # option to configure is --prefix. MAXIMA_PREFIX is thus a runtime
80 # change of --prefix.)
81 # Yes, MAXIMA_DIRECTORY means the same thing. We only include
82 # it for some level of backward compatibility.
83 if { [info exists env(MAXIMA_DIRECTORY)] } {
84 set env(MAXIMA_PREFIX) $env(MAXIMA_DIRECTORY)
87 # jfa: This whole routine is a disaster. The general plan for maxima
88 # paths is as follows:
89 # 1) Use the environment variables if they exist.
90 # 2) Otherwise, attempt to use the compile-time settings from
91 # autoconf.
92 # 3) If the entire package has been moved to a prefix other than
93 # that given at compile time, use the location of the (x)maxima
94 # executable to determine the new prefix.
95 # The corresponding path setting procedure in the maxima source can
96 # be found in init-cl.lisp.
98 # The following section should be considered temporary work-around.
99 if { [info exists env(MAXIMA_VERPKGDATADIR)] } {
100 set maxima_priv(maxima_verpkgdatadir) $env(MAXIMA_VERPKGDATADIR)
102 # End temporary workaround. It's only a workaround because the next
103 # section is backwards:
105 #mike Is it correct to assume that autoconf exists and is valid
106 # for binary windows distributions? I think it would be better
107 # to make (MAXIMA_DIRECTORY) take precedence, and work off
108 # [info nameofexe] if necessary.
110 if {[info exists maxima_priv(maxima_prefix)]} {
111 # drop through
112 } elseif { [info exists env(MAXIMA_PREFIX)] } {
113 set maxima_priv(maxima_prefix) $env(MAXIMA_PREFIX)
114 } else {
115 set maxima_priv(maxima_prefix) $autoconf(prefix)
117 if {[info exists maxima_priv(maxima_verpkgdatadir)]} {
118 # drop through
119 } else {
120 if { [info exists env(MAXIMA_DATADIR)] } {
121 set maxima_datadir $env(MAXIMA_DATADIR)
122 } elseif { [info exists env(MAXIMA_PREFIX)] } {
123 set maxima_datadir \
124 [file join $env(MAXIMA_PREFIX) share]
125 } else {
126 set maxima_datadir $autoconf(datadir)
128 # maxima_datadir is unused outside of this proc
130 if {![file isdir $maxima_datadir]} {
131 tide_notify [M [mc "Maxima data directory not found in '%s'"] \
132 [file native $maxima_datadir]]
134 set maxima_priv(maxima_verpkgdatadir) \
135 [file join $maxima_datadir $autoconf(package) \
136 $autoconf(version)]
139 # omplotdata messages
140 #::msgcat::mcload [file join $maxima_priv(maxima_verpkgdatadir) msgs]
142 if {[info exists maxima_priv(maxima_verpkglibdir)]} {
143 # drop through
144 } elseif { [info exists env(MAXIMA_VERPKGLIBDIR)] } {
145 set maxima_priv(maxima_verpkglibdir) $env(MAXIMA_VERPKGLIBDIR)
146 } elseif { [info exists env(MAXIMA_PREFIX)] } {
147 set maxima_priv(maxima_verpkglibdir) \
148 [file join $env(MAXIMA_PREFIX) lib $autoconf(package) \
149 $autoconf(version)]
150 } else {
151 set maxima_priv(maxima_verpkglibdir) \
152 [file join $autoconf(libdir) $autoconf(package) \
153 $autoconf(version)]
155 if {[info exists maxima_priv(maxima_xmaximadir)]} {
156 # drop through
157 } elseif { [info exists env(MAXIMA_XMAXIMADIR)] } {
158 set maxima_priv(maxima_xmaximadir) $env(MAXIMA_XMAXIMADIR)
159 } else {
160 set maxima_priv(maxima_xmaximadir) \
161 [file join $maxima_priv(maxima_verpkgdatadir) xmaxima]
164 # xmaxima messages
165 ::msgcat::mcload [file join $maxima_priv(maxima_xmaximadir) msgs]
167 # Define maxima_lang_subdir
168 if { [info exists env(MAXIMA_LANG_SUBDIR)] } {
169 set maxima_priv(maxima_lang_subdir) $env(MAXIMA_LANG_SUBDIR)
170 } else {
171 if { $tcl_platform(platform) == "windows" } {
172 set wlocale [ ::msgcat::mclocale ]
173 } else {
174 set wlocale ""
175 if { [info exists env(LC_ALL)] } {
176 set wlocale $env(LC_ALL)
177 } elseif { [info exists env(LC_MESSAGES)] } {
178 set wlocale $env(LC_MESSAGES)
179 } elseif { [info exists env(LANG)] } {
180 set wlocale $env(LANG) }
182 # Only languages known to Maxima
183 set wlocale [string tolower $wlocale]
184 switch -glob $wlocale {
185 "es*utf*" {
186 set maxima_priv(maxima_lang_subdir) "es.utf8"
188 "es*" {
189 set maxima_priv(maxima_lang_subdir) "es"
191 "pt_br*utf*" {
192 set maxima_priv(maxima_lang_subdir) "pt_BR.utf8"
194 "pt_br*" {
195 set maxima_priv(maxima_lang_subdir) "pt_BR"
197 "pt*utf*" {
198 set maxima_priv(maxima_lang_subdir) "pt.utf8"
200 "pt*" {
201 set maxima_priv(maxima_lang_subdir) "pt"
203 "de*utf*" {
204 set maxima_priv(maxima_lang_subdir) "de.utf8"
206 "de*" {
207 set maxima_priv(maxima_lang_subdir) "de"
209 "fr*utf*" {
210 set maxima_priv(maxima_lang_subdir) "fr.utf8"
212 "fr*" {
213 set maxima_priv(maxima_lang_subdir) "fr"
215 "it*utf*" {
216 set maxima_priv(maxima_lang_subdir) "it.utf8"
218 "it*" {
219 set maxima_priv(maxima_lang_subdir) "it"
221 "ru*utf*" {
222 set maxima_priv(maxima_lang_subdir) "ru.utf8"
224 "ru*koi*" {
225 set maxima_priv(maxima_lang_subdir) "ru.koi8r"
227 "ru*" {
228 set maxima_priv(maxima_lang_subdir) "ru"
230 default
232 set maxima_priv(maxima_lang_subdir) ""
235 #puts $maxima_priv(maxima_lang_subdir)
238 # On Windows ::msgcat::mclocale is a good way to derive locale
239 if { $tcl_platform(platform) == "windows" } {
240 set env(LANG) [ ::msgcat::mclocale ]
243 # Bring derived quantities up here too so we can see the
244 # side effects of setting the above variables
246 # used in Menu.tcl CMMenu.tcl
247 if {[file isdir [set dir [file join $maxima_priv(maxima_verpkgdatadir) info]]]} {
248 # 5.6 and down
249 set maxima_priv(pReferenceToc) \
250 [file join $dir maxima_toc.html]
251 } elseif {[file isdir [set dir [file join $maxima_priv(maxima_verpkgdatadir) doc]]]} {
252 # 5.9 and up
253 # first choose the HTML documentation
254 if { $maxima_priv(maxima_lang_subdir) != "" && \
255 [file exists [file join $dir html $maxima_priv(maxima_lang_subdir) maxima_toc.html] ] } {
256 set maxima_priv(pReferenceToc) [file join $dir html $maxima_priv(maxima_lang_subdir) maxima_toc.html]
257 } else {
258 set maxima_priv(pReferenceToc) [file join $dir html maxima_toc.html]
260 # if the platform is Windows and Maxima is running localized, try the following help files
261 # if they exist:
262 # 1st priority: localized CHM
263 # 2nd priority: localized HTML
264 # 3rd priority: english CHM
265 # 4th priority: english HTML
266 if { $tcl_platform(platform) == "windows" } {
267 if { $maxima_priv(maxima_lang_subdir) != "" } {
268 if {[file exists [file join $dir chm $maxima_priv(maxima_lang_subdir) maxima.chm] ] } {
269 set maxima_priv(pReferenceToc) [file join $dir chm $maxima_priv(maxima_lang_subdir) maxima.chm]
270 } else {
271 if {[file exists [file join $dir html $maxima_priv(maxima_lang_subdir) maxima_toc.html] ] } {
272 set maxima_priv(pReferenceToc) [file join $dir html $maxima_priv(maxima_lang_subdir) maxima_toc.html]
273 } else {
274 if {[file exists [file join $dir chm maxima.chm] ] } {
275 set maxima_priv(pReferenceToc) [file join $dir chm maxima.chm]
276 } else {
277 set maxima_priv(pReferenceToc) [file join $dir html maxima_toc.html]
281 } else {
282 if {[file exists [file join $dir chm maxima.chm] ] } {
283 set maxima_priv(pReferenceToc) [file join $dir chm maxima.chm]
284 } else {
285 set maxima_priv(pReferenceToc) [file join $dir html maxima_toc.html]
288 } else {
289 # Platform != windows, just choose the HTML documentation
290 if { $maxima_priv(maxima_lang_subdir) != "" && \
291 [file exists [file join $dir html $maxima_priv(maxima_lang_subdir) maxima_toc.html] ] } {
292 set maxima_priv(pReferenceToc) [file join $dir html $maxima_priv(maxima_lang_subdir) maxima_toc.html]
293 } else {
294 set maxima_priv(pReferenceToc) [file join $dir html maxima_toc.html]
297 } else {
298 tide_notify [M [mc "Documentation not found in '%s'"] \
299 [file native $maxima_priv(maxima_verpkgdatadir)]]
302 # used in Menu.tcl CMMenu.tcl
303 if {[file isdir [set dir [file join $maxima_priv(maxima_verpkgdatadir) tests]]]} {
304 # 5.9 and up
305 set maxima_priv(pTestsDir) $dir
306 } elseif {[file isdir [set dir [file join $maxima_priv(maxima_verpkgdatadir) doc]]]} {
307 # 5.6 and down
308 set maxima_priv(pTestsDir) $dir
309 } else {
310 # who cares
312 set file [file join $maxima_priv(maxima_xmaximadir) "intro.html"]
313 if {![file isfile $file]} {
314 tide_notify [M [mc "Starting documentation not found in '%s'"] \
315 [file native $file]]
316 set maxima_priv(firstUrl) ""
317 } else {
318 if {$tcl_platform(platform) == "windows"} {
319 # convert to unix
320 set file [file dir $file]/[file tail $file]
322 # FIXME: This is bogus - need a FileToUrl
323 set maxima_priv(firstUrl) file:/$file
325 # set up for autoloading
326 global auto_path
327 set dir [file join $maxima_priv(maxima_xmaximadir) Tkmaxima]
328 if {[file isdir $dir]} {
329 lappend auto_path $dir
331 # jfa: Windows 98 users were seeing long startup times because
332 # MAXIMA_USERDIR defaults to HOME, which is usually C:\.
333 # Make the default something else under Windows 98 as a workaround.
334 # This is ugly.
335 if {$tcl_platform(os) == "Windows 95"} {
336 if {![info exists env(MAXIMA_USERDIR)]} {
337 set env(MAXIMA_USERDIR) "$maxima_priv(maxima_prefix)/user"
340 # jfa: extend path so that gcl can see gcc in windows package
341 # I don't know that this is the best place for this
342 if {$tcl_platform(platform) == "windows"} {
343 # jfa: This is an attempt to get a working path designation
344 # on various Windows versions.
345 if {$tcl_platform(os) == "Windows 95"} {
346 # Windows 95 or Windows 98
347 regsub -all {/} "$maxima_priv(maxima_prefix)\\BIN" {\\} maxbinpath
348 } else {
349 # Other versions of Windows
350 set maxbinpath "$maxima_priv(maxima_prefix)/bin"
352 set env(PATH) "$maxbinpath;$env(PATH)"
356 proc vMAXSetMaximaCommand {} {
357 global maxima_priv tcl_platform env
359 set maxima_priv(localMaximaServer) ""
360 if {[info exists maxima_priv(xmaxima_maxima)] && \
361 $maxima_priv(xmaxima_maxima) != ""} {
362 if {[set exe [auto_execok $maxima_priv(xmaxima_maxima)]] == "" } {
364 tide_failure [M [mc "Error: Maxima executable not found\n%s\n\n Try setting the environment variable XMAXIMA_MAXIMA."] \
365 [file native $maxima_priv(xmaxima_maxima)]]
366 return
368 } elseif { [info exists env(XMAXIMA_MAXIMA)] } {
369 set maxima_priv(xmaxima_maxima) $env(XMAXIMA_MAXIMA)
370 if {[set exe [auto_execok $maxima_priv(xmaxima_maxima)]] == "" } {
371 tide_failure [M [concat [mc "Error2: maxima executable not found."] "\n%s\nXMAXIMA_MAXIMA=$env(XMAXIMA_MAXIMA)"]]
372 return
374 } else {
375 set maxima_priv(xmaxima_maxima) maxima
376 if {[set exe [auto_execok $maxima_priv(xmaxima_maxima)]] == "" } {
377 tide_failure [M [mc "Error: Maxima executable not found\n\n Try setting the environment variable XMAXIMA_MAXIMA."]]
379 # jfa: bypass maxima script on windows
380 # vvz: on Windows 9X/ME only
381 if {$tcl_platform(os) == "Windows 95"} {
382 # maybe it's in lib - I don't like this
383 set dir $maxima_priv(maxima_verpkglibdir)
384 # FIXME - need autoconf(lisp) so we don't need glob
385 set exes [glob -nocomplain $dir/binary-*/maxima.exe]
386 if {[llength $exes] != "1" || \
387 [set exe [lindex $exes 0]] == "" || \
388 ![file isfile $exe]} {
389 tide_failure [M [mc "Error: Maxima executable not found\n\n Try setting the environment variable XMAXIMA_MAXIMA."]]
390 return
392 } else {
393 set maxima_priv(xmaxima_maxima) maxima
394 if {[set exe [auto_execok $maxima_priv(xmaxima_maxima)]] == "" } {
395 tide_failure [M [mc "Error: Maxima executable not found\n\n Try setting the environment variable XMAXIMA_MAXIMA."]]
399 set command {}
400 lappend command $exe
401 eval lappend command $maxima_priv(opts)
402 lappend command -s PORT
403 if {$tcl_platform(platform) == "windows"} {
404 lappend command > NUL
405 } else {
406 lappend command > /dev/null
408 lappend command &
409 set maxima_priv(localMaximaServer) $command