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