1
;********************************************************
3
; description: Initialize Maxima
4
; date: Wed Jan 13 1999 - 20:27
5
; author: Liam Healy <Liam.Healy@nrl.navy.mil>
6
;********************************************************
1
;;********************************************************
3
;; description: Initialize Maxima
4
;; date: Wed Jan 13 1999 - 20:27
5
;; author: Liam Healy <Liam.Healy@nrl.navy.mil>
6
;;********************************************************
9
(use-package "COMMAND-LINE")
10
10
;;; An ANSI-CL portable initializer to replace init_max1.lisp
12
12
;;; Locations of various types of files. These variables are discussed
20
20
(defvar *maxima-sharedir*)
21
21
(defvar *maxima-symdir*)
22
22
(defvar *maxima-srcdir*)
23
(defvar *maxima-demodir*)
24
(defvar *maxima-testsdir*)
25
23
(defvar *maxima-docdir*)
26
24
(defvar *maxima-infodir*)
27
25
(defvar *maxima-htmldir*)
28
(defvar *maxima-plotdir*)
29
26
(defvar *maxima-layout-autotools*)
30
27
(defvar *maxima-userdir*)
28
(defvar *maxima-tempdir*)
29
(defvar *maxima-lang-subdir*)
31
(defmvar $maxima_tempdir)
32
(putprop '$maxima_tempdir 'shadow-string-assignment 'assign)
33
(putprop '$maxima_tempdir '*maxima-tempdir* 'lisp-shadow)
35
(defmvar $maxima_userdir)
36
(putprop '$maxima_userdir 'shadow-string-assignment 'assign)
37
(putprop '$maxima_userdir '*maxima-userdir* 'lisp-shadow)
39
(defun shadow-string-assignment (var value)
42
(set (get var 'lisp-shadow) (maybe-invert-string-case (symbol-name (stripdollar value))))
45
(set (get var 'lisp-shadow) value)
48
(merror "Attempt to assign a non-string to ~:M" var))))
32
50
(defun print-directories ()
33
51
(format t "maxima-prefix=~a~%" *maxima-prefix*)
43
61
(format t "maxima-plotdir=~a~%" *maxima-plotdir*)
44
62
(format t "maxima-layout-autotools=~a~%" *maxima-layout-autotools*)
45
63
(format t "maxima-userdir=~a~%" *maxima-userdir*)
64
(format t "maxima-tempdir=~a~%" *maxima-tempdir*)
65
(format t "maxima-lang-subdir=~a~%" *maxima-lang-subdir*)
48
68
(defvar *maxima-lispname* #+clisp "clisp"
53
74
#+openmcl "openmcl"
54
#-(or clisp cmu sbcl gcl allegro openmcl) "unknownlisp")
56
(defun combine-path (list)
57
(let ((result (first list)))
60
(concatenate 'string result "/" x))) (rest list))
75
#-(or clisp cmu scl sbcl gcl allegro openmcl) "unknownlisp")
63
79
(defvar $file_search_lisp nil
64
80
"Directories to search for Lisp source code.")
70
86
"Directories to search for demos.")
72
88
(defvar $file_search_usage nil)
90
(defvar $file_search_tests nil
91
"Directories to search for maxima test suite")
73
93
(defvar $chemin nil)
76
(defun maxima-getenv (envvar)
80
(defun maxima-getenv (envvar)
81
(system:getenv envvar))
84
(defun maxima-getenv (envvar)
85
(cdr (assoc envvar ext:*environment-list* :test #'string=)))
88
(defun maxima-getenv (envvar)
89
(sb-ext:posix-getenv envvar))
92
(defun maxima-getenv (envvar)
96
(defun maxima-getenv (envvar)
99
96
(defun maxima-parse-dirstring (str)
200
198
(combine-path (list (maxima-parse-dirstring base-dir) maxima-dir))))
200
(defun default-tempdir ()
201
(let ((home-env (maxima-getenv "HOME"))
204
(if (and home-env (string/= home-env ""))
205
(if (string= home-env "c:\\")
208
(if (string= *autoconf-win32* "true")
211
(maxima-parse-dirstring base-dir)))
214
(let (locale language territory codeset)
215
(setq cl-info::*index-name* "index")
216
(unless (setq *maxima-lang-subdir* (maxima-getenv "MAXIMA_LANG_SUBDIR"))
217
(setq locale (or (maxima-getenv "LC_ALL")
218
(maxima-getenv "LC_MESSAGES")
219
(maxima-getenv "LANG")))
222
(setq *maxima-lang-subdir* nil))
223
((zl-member locale '("C" "POSIX" "c" "posix"))
224
(setq *maxima-lang-subdir* nil))
225
(t (when (eql (position #\. locale) 5)
226
(setq codeset (string-downcase (subseq locale 6))))
227
(when (eql (position #\_ locale) 2)
228
(setq territory (string-downcase (subseq locale 3 5))))
229
(setq language (string-downcase (subseq locale 0 2)))
230
;; Set *maxima-lang-subdir* only for known languages.
231
;; Extend procedure below as soon as new translation
235
((equal language "en")
236
(setq *maxima-lang-subdir* nil))
237
;; Latin-1 aka iso-8859-1 languages
238
((zl-member language '("es" "pt"))
239
(if (zl-member codeset '("utf-8" "utf8"))
240
(setq *maxima-lang-subdir* (concatenate 'string language ".utf8"))
241
(setq *maxima-lang-subdir* language)))
242
(t (setq *maxima-lang-subdir* nil)))
243
;; Translation of the word "Index" to match node "Fuction and Variable Index"
245
((equal language "es")
246
(setq cl-info::*index-name* (format nil "~andice" (code-char #xCD))))
247
((equal language "pt")
248
(setq cl-info::*index-name* (format nil "~andice" (code-char #xCD))))
250
;; Additional language-dependent pattern to match nodes such as
251
;; -- Function: foo (x)
253
;; -- Option variable: bar
255
;; This pattern is suitable for all Latin-1 (aka ISO-8859-1) langages
256
((zl-member language '("es" "pt"))
257
(setq cl-info::*extra-chars* (format nil "~a-~a" (code-char #xC0) (code-char #xFF))))
260
(setq cl-info::*lang-subdir* *maxima-lang-subdir*)))
202
262
(defun set-pathnames ()
203
263
(let ((maxima-prefix-env (maxima-getenv "MAXIMA_PREFIX"))
204
264
(maxima-layout-autotools-env (maxima-getenv "MAXIMA_LAYOUT_AUTOTOOLS"))
205
(maxima-userdir-env (maxima-getenv "MAXIMA_USERDIR")))
265
(maxima-userdir-env (maxima-getenv "MAXIMA_USERDIR"))
266
(maxima-tempdir-env (maxima-getenv "MAXIMA_TEMPDIR")))
206
267
;; MAXIMA_DIRECTORY is a deprecated substitute for MAXIMA_PREFIX
207
268
(if (not maxima-prefix-env)
208
269
(setq maxima-prefix-env (maxima-getenv "MAXIMA_DIRECTORY")))
219
280
(set-pathnames-without-autoconf maxima-prefix-env))
220
281
(if maxima-userdir-env
221
282
(setq *maxima-userdir* (maxima-parse-dirstring maxima-userdir-env))
222
(setq *maxima-userdir* (default-userdir))))
283
(setq *maxima-userdir* (default-userdir)))
284
(if maxima-tempdir-env
285
(setq *maxima-tempdir* (maxima-parse-dirstring maxima-tempdir-env))
286
(setq *maxima-tempdir* (default-tempdir)))
288
; Assign initial values for Maxima shadow variables
289
(setq $maxima_userdir *maxima-userdir*)
290
(setf (gethash '$maxima_userdir *variable-initial-values*) *maxima-userdir*)
291
(setq $maxima_tempdir *maxima-tempdir*)
292
(setf (gethash '$maxima_tempdir *variable-initial-values*) *maxima-tempdir*))
224
294
(let* ((ext #+gcl "o"
225
#+cmu (c::backend-fasl-file-type c::*target-backend*)
295
#+(or cmu scl) (c::backend-fasl-file-type c::*target-backend*)
229
299
#+(and openmcl darwinppc-target) "dfsl"
230
300
#+(and openmcl linuxppc-target) "pfsl"
231
#-(or gcl cmu sbcl clisp allegro openmcl)
301
#-(or gcl cmu scl sbcl clisp allegro openmcl)
233
303
(lisp-patterns (concatenate
236
306
(maxima-patterns "###.{mac,mc}")
237
307
(demo-patterns "###.{dem,dm1,dm2,dm3,dmt}")
238
308
(usage-patterns "##.{usg,texi}")
239
(share-subdirs "{affine,algebra,calculus,combinatorics,contrib,contrib/nset,contrib/pdiff,diffequations,graphics,integequations,integration,macro,matrix,misc,numeric,physics,simplification,specfunctions,sym,tensor,trigonometry,utils,vector}"))
318
"contrib/descriptive"
319
"contrib/diffequations"
320
"contrib/diffequations/tests"
325
"contrib/gentran/test"
328
"contrib/maximaMathML"
330
"contrib/numericalio"
336
"contrib/simplex/Tests"
360
; Smash the list of share subdirs into a string of the form "{affine,algebra,...,vector}" .
361
(share-subdirs (format nil "{~{~A~^,~}}" share-subdirs-list)))
240
363
(setq $file_search_lisp
242
365
;; actually, this entry is not correct.
265
388
(combine-path (list *maxima-sharedir* share-subdirs
267
390
(combine-path (list *maxima-docdir* usage-patterns))))
391
(setq $file_search_tests
392
`((mlist) ,(combine-path (list *maxima-testsdir* maxima-patterns))))
269
(concatenate 'string *maxima-symdir* "/"))
270
(setq cl-info::*info-paths* (list (concatenate 'string
271
*maxima-infodir* "/")))))
395
(combine-path (list *maxima-symdir* lisp-patterns))
396
(combine-path (list *maxima-symdir* maxima-patterns))))
397
(setq cl-info::*info-paths* (list (concatenate 'string *maxima-infodir* "/")))
398
;; Share subdirs are not required here since all .info files are installed
399
;; in one directory *maxima-infodir* -- there is no info files in share.
401
;(setq L (mapcar #'(lambda (x) (concatenate 'string *maxima-sharedir* "/" x "/")) share-subdirs-list))
402
;(setq cl-info::*info-paths* (append cl-info::*info-paths* L))
404
; Look for "foo.info" in share directory "foo".
405
(loop for d in share-subdirs-list do
406
(let ((name (if (find #\/ d) (unix-like-basename d) d)))
407
(when (cl-info::file-search name cl-info::*info-paths* '("info") nil)
408
#+debug (format t "SET-PATHNAMES: found an info file for share directory ~S~%" name)
409
(nconc cl-info::*default-info-files* `(,(concatenate 'string name ".info"))))))))
273
411
(defun get-dirs (path)
274
412
#+(or :clisp :sbcl)
282
420
(if (equal (subseq pathstring (- len 1) len) "/")
283
421
(progn (setf len (- len 1))
284
422
(setf pathstring (subseq pathstring 0 len))))
285
(subseq pathstring (+ (position #\/ pathstring :from-end t) 1) len)))
423
(subseq pathstring (+ (or (position #\/ pathstring :from-end t) (position #\\ pathstring :from-end t)) 1) len)))
287
425
(defun unix-like-dirname (path)
288
426
(let* ((pathstring (namestring path))
290
428
(if (equal (subseq pathstring (- len 1) len) "/")
291
429
(progn (setf len (- len 1))
292
430
(setf pathstring (subseq pathstring 0 len))))
293
(subseq pathstring 0 (position #\/ pathstring :from-end t))))
431
(subseq pathstring 0 (or (position #\/ pathstring :from-end t) (position #\\ pathstring :from-end t)))))
295
433
(defun list-avail-action ()
296
434
(let* ((maxima-verpkglibdir (if (maxima-getenv "MAXIMA-VERPKGLIBDIR")
325
463
(setf lisp-string (unix-like-basename lisp))
326
464
(when (search "binary-" lisp-string)
327
465
(setf lisp-string (subseq lisp-string (length "binary-")
328
(length lisp-string)))
466
(length lisp-string)))
329
467
(format t "version ~a, lisp ~a~%" version-string lisp-string))))
332
470
(defun process-maxima-args (input-stream batch-flag)
333
; (format t "processing maxima args = ")
334
; (mapc #'(lambda (x) (format t "\"~a\"~%" x)) (get-application-args))
471
;; (format t "processing maxima args = ")
472
;; (mapc #'(lambda (x) (format t "\"~a\"~%" x)) (get-application-args))
336
474
(let ((maxima-options nil))
337
475
(setf maxima-options
396
534
:action #'(lambda (file)
398
536
:help-string "Preload <lisp-file>.")
537
(make-cl-option :names '("-q" "--quiet")
538
:action #'(lambda () (declare (special *maxima-quiet*)) (setq *maxima-quiet* t))
539
:help-string "Suppress Maxima start-up message.")
399
540
(make-cl-option :names '("--disable-readline")
400
541
:action #'(lambda ()
544
:help-string "Disable readline support.")
403
545
(make-cl-option :names '("-s" "--server")
404
546
:argument "<port>"
405
547
:action #'(lambda (port-string)
446
589
(setf (values input-stream batch-flag)
447
590
(process-maxima-args input-stream batch-flag))
448
#+(or cmu sbcl clisp allegro mcl)
451
(with-simple-restart (macsyma-quit "Macsyma top-level")
452
(macsyma-top-level input-stream batch-flag))))
453
#-(or cmu sbcl clisp allegro mcl)
455
(macsyma-top-level input-stream batch-flag)))))
459
($setup_autoload "eigen.mac" '$eigenvectors '$eigenvalues)
593
(with-simple-restart (macsyma-quit "Maxima top-level")
594
(macsyma-top-level input-stream batch-flag)))))))
596
(import 'cl-user::run)
461
598
(defun $to_lisp ()
462
(format t "~&Type (to-maxima) to restart~%")
599
(format t "~&Type (to-maxima) to restart, ($quit) to quit Maxima.~%")
463
600
(let ((old-debugger-hook *debugger-hook*))
464
601
(catch 'to-maxima
466
(maxima-read-eval-print-loop)
603
(maxima-read-eval-print-loop)
467
604
(setf *debugger-hook* old-debugger-hook)
468
605
(format t "Returning to Maxima~%"))))
471
608
(defun to-maxima ()
472
609
(throw 'to-maxima t))
482
619
(prin1 (eval form))))))
484
621
(defun maxima-lisp-debugger-repl (condition me-or-my-encapsulation)
622
(declare (ignore me-or-my-encapsulation))
485
623
(format t "~&Maxima encountered a Lisp error:~%~% ~A" condition)
486
624
(format t "~&~%Automatically continuing.~%To reenable the Lisp debugger set *debugger-hook* to nil.~%")
487
625
(throw 'to-maxima-repl t))
490
(format t "jfa was here"))
492
(defvar $help "type describe(topic) or example(topic);")
494
(defun $help () $help) ;
496
;; CMUCL needs because when maxima reaches EOF, it calls BYE, not $QUIT.
517
(defun $maxima_server (port)
518
(load "/home/amundson/devel/maxima/archive/src/server.lisp")
627
(defvar $help "type `describe(topic);' or `example(topic);' or `? topic'")
629
(defun $help (&rest args)
630
(declare (ignore args))
633
;;; Now that all of maxima has been loaded, define the various lists
634
;;; and hashtables of builtin symbols and values.
636
;;; The symbols in problematic-symbols contains properties with
637
;;; circular data structures. Attempting to copy a circular structure
638
;;; into *builtin-symbol-props* would cause a hang. Lacking a better
639
;;; solution, we simply avoid those symbols.
640
(let ((problematic-symbols '($%gamma $%phi $global $%pi $%e)))
641
(do-symbols (s (find-package :maxima))
642
(when (and (eql (symbol-package s) (find-package :maxima))
643
(memq (getchar s 1) '($ % &)))
644
(push s *builtin-symbols*)
645
(when (not (memq s problematic-symbols))
646
(setf (gethash s *builtin-symbol-props*)
647
(copy-tree (symbol-plist s)))))))
649
(dolist (s *builtin-symbols*)
651
(push s *builtin-symbols-with-values*)))
653
(dolist (s *builtin-symbols-with-values*)
654
(setf (gethash s *builtin-symbol-values*) (symbol-value s)))
656
(setf *builtin-$props* (copy-list $props))
657
(setf *builtin-$rules* (copy-list $rules))