Commit | Line | Data |
---|---|---|
861345b4 | 1 | ;;; -*-lisp-*- |
2 | ;;; | |
861345b4 | 3 | ;;; Basic system-specific stuff |
4 | ;;; | |
5 | ;;; (c) 2005 Mark Wooding | |
6 | ;;; | |
7 | ||
8 | ;;;----- Licensing notice --------------------------------------------------- | |
9 | ;;; | |
10 | ;;; This program is free software; you can redistribute it and/or modify | |
11 | ;;; it under the terms of the GNU General Public License as published by | |
12 | ;;; the Free Software Foundation; either version 2 of the License, or | |
13 | ;;; (at your option) any later version. | |
b2c12b4e | 14 | ;;; |
861345b4 | 15 | ;;; This program is distributed in the hope that it will be useful, |
16 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;;; GNU General Public License for more details. | |
b2c12b4e | 19 | ;;; |
861345b4 | 20 | ;;; You should have received a copy of the GNU General Public License |
21 | ;;; along with this program; if not, write to the Free Software Foundation, | |
22 | ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
23 | ||
e5152ebe MW |
24 | (defpackage #:runlisp |
25 | (:use #:common-lisp) | |
3bb66aca | 26 | (:export #:*command-line* #:exit) |
5a64d91b | 27 | #+clisp (:import-from #:ext #:exit)) |
340560aa | 28 | |
861345b4 | 29 | (defpackage #:mdw.sys-base |
e5152ebe | 30 | (:use #:common-lisp #:runlisp) |
340560aa | 31 | (:export #:exit #:hard-exit #:*program-name* #:*command-line* |
d0754e55 | 32 | #:set-command-line-arguments) |
3bb66aca | 33 | (:import-from #:runlisp #:*command-line* #:exit)) |
861345b4 | 34 | (in-package #:mdw.sys-base) |
35 | ||
340560aa MW |
36 | (defvar *command-line*) |
37 | (defvar *program-name*) | |
5a64d91b | 38 | |
340560aa | 39 | (defun set-command-line-arguments () |
003ebbaa | 40 | (setf *command-line* |
d0754e55 | 41 | (or (when (member :cl-launch *features*) |
460f9a0d MW |
42 | (let* ((cll-package (find-package :cl-launch)) |
43 | (name (funcall (intern "GETENV" cll-package) | |
44 | "CL_LAUNCH_FILE")) | |
45 | (args (symbol-value (intern "*ARGUMENTS*" | |
46 | cll-package)))) | |
47 | (if name | |
48 | (cons name args) | |
49 | args))) | |
340560aa MW |
50 | #+cmu ext:*command-line-strings* |
51 | #+sbcl sb-ext:*posix-argv* | |
52 | #+ecl (loop from i below (ext:argc) collect (ext:argv i)) | |
003ebbaa | 53 | #+clisp (loop with argv = (ext:argv) |
4da88bb9 | 54 | for i from 7 below (length argv) |
003ebbaa | 55 | collect (aref argv i)) |
340560aa | 56 | '("<unknown-lisp>" "--" "<unknown-script>"))) |
340560aa MW |
57 | (setf *program-name* (pathname-name (car *command-line*)))) |
58 | (set-command-line-arguments) | |
5a64d91b MW |
59 | |
60 | #-clisp | |
61 | (unless (fboundp 'exit) | |
62 | (defun exit (&optional (code 0)) | |
63 | "Polite way to end a program." | |
64 | #+(or cmu ecl) (ext:quit code) | |
77f935da | 65 | #+sbcl (sb-ext:exit :code code) |
5a64d91b MW |
66 | #-(or cmu ecl sbcl) |
67 | (progn | |
68 | (unless (zerop code) | |
69 | (format t "~&Exiting unsuccessfully with code ~D.~%" code)) | |
70 | (abort)))) | |
71 | ||
e5152ebe MW |
72 | (defun hard-exit (&optional (code 0)) |
73 | "Stops the program immediately in its tracks. Does nothing else. Use | |
74 | after fork, for example, to avoid flushing buffers." | |
75 | (declare (type (unsigned-byte 32) code)) | |
76 | #+cmu (unix::void-syscall ("_exit" c-call:int) code) | |
77f935da | 77 | #+sbcl (sb-ext:exit :code code :abort t) |
e5152ebe | 78 | #+(or clisp ecl) (ext:quit code)) |
861345b4 | 79 | |
861345b4 | 80 | ;;;----- That's all, folks -------------------------------------------------- |