Add support for external html docs
[maxima.git] / interfaces / xmaxima / Tkmaxima / Paths.tcl
blob8067a23521dd584cc410f435be38c5db139bf6c2
1 ############################################################
2 # Paths.tcl #
3 # Copyright (C) 1998 William F. Schelter #
4 # For distribution under GNU public License. See COPYING. #
5 # #
6 # Time-stamp: "2024-03-26 13:42:55 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 tk_messageBox -title Warning -icon warning -message \
132 [mc "Maxima data directory not found in '%s'" \
133 [file native $maxima_datadir]]
135 set maxima_priv(maxima_verpkgdatadir) \
136 [file join $maxima_datadir $autoconf(package) \
137 $autoconf(version)]
140 # omplotdata messages
141 #::msgcat::mcload [file join $maxima_priv(maxima_verpkgdatadir) msgs]
143 if {[info exists maxima_priv(maxima_verpkglibdir)]} {
144 # drop through
145 } elseif { [info exists env(MAXIMA_VERPKGLIBDIR)] } {
146 set maxima_priv(maxima_verpkglibdir) $env(MAXIMA_VERPKGLIBDIR)
147 } elseif { [info exists env(MAXIMA_PREFIX)] } {
148 set maxima_priv(maxima_verpkglibdir) \
149 [file join $env(MAXIMA_PREFIX) lib $autoconf(package) \
150 $autoconf(version)]
151 } else {
152 set maxima_priv(maxima_verpkglibdir) \
153 [file join $autoconf(libdir) $autoconf(package) \
154 $autoconf(version)]
156 if {[info exists maxima_priv(maxima_xmaximadir)]} {
157 # drop through
158 } elseif { [info exists env(MAXIMA_XMAXIMADIR)] } {
159 set maxima_priv(maxima_xmaximadir) $env(MAXIMA_XMAXIMADIR)
160 } else {
161 set maxima_priv(maxima_xmaximadir) \
162 [file join $maxima_priv(maxima_verpkgdatadir) xmaxima]
165 # xmaxima messages
166 ::msgcat::mcload [file join $maxima_priv(maxima_xmaximadir) msgs]
168 # Define maxima_lang_subdir
169 if { [info exists env(MAXIMA_LANG_SUBDIR)] } {
170 set maxima_priv(maxima_lang_subdir) $env(MAXIMA_LANG_SUBDIR)
171 } else {
172 if { $tcl_platform(platform) == "windows" } {
173 set wlocale [ ::msgcat::mclocale ]
174 } else {
175 set wlocale ""
176 if { [info exists env(LC_ALL)] } {
177 set wlocale $env(LC_ALL)
178 } elseif { [info exists env(LC_MESSAGES)] } {
179 set wlocale $env(LC_MESSAGES)
180 } elseif { [info exists env(LANG)] } {
181 set wlocale $env(LANG) }
183 # Only languages known to Maxima
184 set wlocale [string tolower $wlocale]
185 switch -glob $wlocale {
186 "es*utf*" {
187 set maxima_priv(maxima_lang_subdir) "es.utf8"
189 "es*" {
190 set maxima_priv(maxima_lang_subdir) "es"
192 "pt_br*utf*" {
193 set maxima_priv(maxima_lang_subdir) "pt_BR.utf8"
195 "pt_br*" {
196 set maxima_priv(maxima_lang_subdir) "pt_BR"
198 "pt*utf*" {
199 set maxima_priv(maxima_lang_subdir) "pt.utf8"
201 "pt*" {
202 set maxima_priv(maxima_lang_subdir) "pt"
204 "de*utf*" {
205 set maxima_priv(maxima_lang_subdir) "de.utf8"
207 "de*" {
208 set maxima_priv(maxima_lang_subdir) "de"
210 "fr*utf*" {
211 set maxima_priv(maxima_lang_subdir) "fr.utf8"
213 "fr*" {
214 set maxima_priv(maxima_lang_subdir) "fr"
216 "it*utf*" {
217 set maxima_priv(maxima_lang_subdir) "it.utf8"
219 "it*" {
220 set maxima_priv(maxima_lang_subdir) "it"
222 "ru*utf*" {
223 set maxima_priv(maxima_lang_subdir) "ru.utf8"
225 "ru*koi*" {
226 set maxima_priv(maxima_lang_subdir) "ru.koi8r"
228 "ru*" {
229 set maxima_priv(maxima_lang_subdir) "ru"
231 default
233 set maxima_priv(maxima_lang_subdir) ""
236 #puts $maxima_priv(maxima_lang_subdir)
239 # On Windows ::msgcat::mclocale is a good way to derive locale
240 if { $tcl_platform(platform) == "windows" } {
241 set env(LANG) [ ::msgcat::mclocale ]
244 # Bring derived quantities up here too so we can see the
245 # side effects of setting the above variables
247 # used in Menu.tcl CMMenu.tcl
248 if {[file isdir [set dir [file join $maxima_priv(maxima_verpkgdatadir) info]]]} {
249 # 5.6 and down
250 set maxima_priv(pReferenceToc) \
251 [file join $dir index.html]
252 } elseif {[file isdir [set dir [file join $maxima_priv(maxima_verpkgdatadir) doc]]]} {
253 # 5.9 and up
254 # first choose the HTML documentation
255 if { $maxima_priv(maxima_lang_subdir) != "" && \
256 [file exists [file join $dir html $maxima_priv(maxima_lang_subdir) index.html] ] } {
257 set maxima_priv(pReferenceToc) [file join $dir html $maxima_priv(maxima_lang_subdir) index.html]
258 } else {
259 set maxima_priv(pReferenceToc) [file join $dir html index.html]
261 # if the platform is Windows and Maxima is running localized, try the following help files
262 # if they exist:
263 # 1st priority: localized CHM
264 # 2nd priority: localized HTML
265 # 3rd priority: english CHM
266 # 4th priority: english HTML
267 if { $tcl_platform(platform) == "windows" } {
268 if { $maxima_priv(maxima_lang_subdir) != "" } {
269 if {[file exists [file join $dir chm $maxima_priv(maxima_lang_subdir) maxima.chm] ] } {
270 set maxima_priv(pReferenceToc) [file join $dir chm $maxima_priv(maxima_lang_subdir) maxima.chm]
271 } else {
272 if {[file exists [file join $dir html $maxima_priv(maxima_lang_subdir) index.html] ] } {
273 set maxima_priv(pReferenceToc) [file join $dir html $maxima_priv(maxima_lang_subdir) index.html]
274 } else {
275 if {[file exists [file join $dir chm maxima.chm] ] } {
276 set maxima_priv(pReferenceToc) [file join $dir chm maxima.chm]
277 } else {
278 set maxima_priv(pReferenceToc) [file join $dir html index.html]
282 } else {
283 if {[file exists [file join $dir chm maxima.chm] ] } {
284 set maxima_priv(pReferenceToc) [file join $dir chm maxima.chm]
285 } else {
286 set maxima_priv(pReferenceToc) [file join $dir html index.html]
289 } else {
290 # Platform != windows, just choose the HTML documentation
291 if { $maxima_priv(maxima_lang_subdir) != "" && \
292 [file exists [file join $dir html $maxima_priv(maxima_lang_subdir) index.html] ] } {
293 set maxima_priv(pReferenceToc) [file join $dir html $maxima_priv(maxima_lang_subdir) index.html]
294 } else {
295 set maxima_priv(pReferenceToc) [file join $dir html index.html]
298 } else {
299 tk_messageBox -title Warning -icon warning -message \
300 [mc "Documentation not found in '%s'" \
301 [file native $maxima_priv(maxima_verpkgdatadir)]]
304 # used in Menu.tcl CMMenu.tcl
305 if {[file isdir [set dir [file join $maxima_priv(maxima_verpkgdatadir) tests]]]} {
306 # 5.9 and up
307 set maxima_priv(pTestsDir) $dir
308 } elseif {[file isdir [set dir [file join $maxima_priv(maxima_verpkgdatadir) doc]]]} {
309 # 5.6 and down
310 set maxima_priv(pTestsDir) $dir
311 } else {
312 # who cares
314 set file [file join $maxima_priv(maxima_xmaximadir) "intro.html"]
315 if {![file isfile $file]} {
316 tk_messageBox -title Warning -icon warning -message \
317 [mc "Starting documentation not found in '%s'" [file native $file]]
318 set maxima_priv(firstUrl) ""
319 } else {
320 if {$tcl_platform(platform) == "windows"} {
321 # convert to unix
322 set file [file dir $file]/[file tail $file]
324 # FIXME: This is bogus - need a FileToUrl
325 set maxima_priv(firstUrl) file:/$file
327 # set up for autoloading
328 global auto_path
329 set dir [file join $maxima_priv(maxima_xmaximadir) Tkmaxima]
330 if {[file isdir $dir]} {
331 lappend auto_path $dir
333 # jfa: Windows 98 users were seeing long startup times because
334 # MAXIMA_USERDIR defaults to HOME, which is usually C:\.
335 # Make the default something else under Windows 98 as a workaround.
336 # This is ugly.
337 if {$tcl_platform(os) == "Windows 95"} {
338 if {![info exists env(MAXIMA_USERDIR)]} {
339 set env(MAXIMA_USERDIR) "$maxima_priv(maxima_prefix)/user"
342 # jfa: extend path so that gcl can see gcc in windows package
343 # I don't know that this is the best place for this
344 if {$tcl_platform(platform) == "windows"} {
345 # jfa: This is an attempt to get a working path designation
346 # on various Windows versions.
347 if {$tcl_platform(os) == "Windows 95"} {
348 # Windows 95 or Windows 98
349 regsub -all {/} "$maxima_priv(maxima_prefix)\\BIN" {\\} maxbinpath
350 } else {
351 # Other versions of Windows
352 set maxbinpath "$maxima_priv(maxima_prefix)/bin"
354 set env(PATH) "$maxbinpath;$env(PATH)"
358 proc vMAXSetMaximaCommand {} {
359 global maxima_priv tcl_platform env
361 set maxima_priv(localMaximaServer) ""
362 if {[info exists maxima_priv(xmaxima_maxima)] && \
363 $maxima_priv(xmaxima_maxima) != ""} {
364 if {[set exe [auto_execok $maxima_priv(xmaxima_maxima)]] == "" } {
366 tk_messageBox -title Error -icon error -message \
367 [mc "Maxima executable not found\n%s\n\n Try setting the environment variable XMAXIMA_MAXIMA." \
368 [file native $maxima_priv(xmaxima_maxima)]]
369 return
371 } elseif { [info exists env(XMAXIMA_MAXIMA)] } {
372 set maxima_priv(xmaxima_maxima) $env(XMAXIMA_MAXIMA)
373 if {[set exe [auto_execok $maxima_priv(xmaxima_maxima)]] == "" } {
374 tk_messageBox -title Error -icon error -message \
375 [concat [mc "Maxima executable not found."] "\n%s\nXMAXIMA_MAXIMA=$env(XMAXIMA_MAXIMA)"]
376 return
378 } else {
379 set maxima_priv(xmaxima_maxima) maxima
380 if {[set exe [auto_execok $maxima_priv(xmaxima_maxima)]] == "" } {
381 tk_messageBox -title Error -icon error -message \
382 [mc "Maxima executable not found\n\n Try setting the environment variable XMAXIMA_MAXIMA."]
384 # jfa: bypass maxima script on windows
385 # vvz: on Windows 9X/ME only
386 if {$tcl_platform(os) == "Windows 95"} {
387 # maybe it's in lib - I don't like this
388 set dir $maxima_priv(maxima_verpkglibdir)
389 # FIXME - need autoconf(lisp) so we don't need glob
390 set exes [glob -nocomplain $dir/binary-*/maxima.exe]
391 if {[llength $exes] != "1" || \
392 [set exe [lindex $exes 0]] == "" || \
393 ![file isfile $exe]} {
394 tk_messageBox -title Error -icon error -message \
395 [mc "Maxima executable not found\n\n Try setting the environment variable XMAXIMA_MAXIMA."]
396 return
398 } else {
399 set maxima_priv(xmaxima_maxima) maxima
400 if {[set exe [auto_execok $maxima_priv(xmaxima_maxima)]] == "" } {
401 tk_messageBox -title Error -icon error -message \
402 [mc "Maxima executable not found\n\n Try setting the environment variable XMAXIMA_MAXIMA."]
406 set command {}
407 lappend command $exe
408 eval lappend command $maxima_priv(opts)
409 lappend command -s PORT
410 if {$tcl_platform(platform) == "windows"} {
411 lappend command > NUL
412 } else {
413 lappend command > /dev/null
415 lappend command &
416 set maxima_priv(localMaximaServer) $command