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) | |
5a64d91b MW |
28 | (:export #:*raw-command-line* #:*command-line* #:exit) |
29 | #+clisp (:import-from #:ext #:exit)) | |
340560aa | 30 | |
861345b4 | 31 | (defpackage #:mdw.sys-base |
e5152ebe | 32 | (:use #:common-lisp #:runlisp) |
340560aa MW |
33 | (:export #:exit #:hard-exit #:*program-name* #:*command-line* |
34 | set-command-line-arguments) | |
5a64d91b | 35 | (:import-from #:runlisp #:*raw-command-line* #:*command-line* #:exit)) |
861345b4 | 36 | (in-package #:mdw.sys-base) |
37 | ||
340560aa MW |
38 | (defvar *raw-command-line*) |
39 | (defvar *command-line*) | |
40 | (defvar *program-name*) | |
5a64d91b | 41 | |
340560aa MW |
42 | (defun set-command-line-arguments () |
43 | (setf *raw-command-line* | |
1cbc65e7 MW |
44 | (or (when (member :cl-launched *features*) |
45 | (cons (or (funcall (intern "GETENV" (find-package :cl-launch)) | |
46 | "CL_LAUNCH_FILE") | |
47 | "<unknown-script>") | |
48 | (symbol-value (intern "*ARGUMENTS*" | |
49 | (find-package :cl-launch))))) | |
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)) | |
53 | #+clisp (coerce (ext:argv) 'list) | |
54 | '("<unknown-lisp>" "--" "<unknown-script>"))) | |
55 | (setf *command-line* | |
1cbc65e7 MW |
56 | (or (when (member :cl-launched *features*) |
57 | *raw-command-line*) | |
340560aa MW |
58 | (cdr (member "--" *raw-command-line* :test #'string=)) |
59 | *raw-command-line*)) | |
60 | (setf *program-name* (pathname-name (car *command-line*)))) | |
61 | (set-command-line-arguments) | |
5a64d91b MW |
62 | |
63 | #-clisp | |
64 | (unless (fboundp 'exit) | |
65 | (defun exit (&optional (code 0)) | |
66 | "Polite way to end a program." | |
67 | #+(or cmu ecl) (ext:quit code) | |
68 | #+sbcl (sb-ext:quit :unix-status code) | |
69 | #-(or cmu ecl sbcl) | |
70 | (progn | |
71 | (unless (zerop code) | |
72 | (format t "~&Exiting unsuccessfully with code ~D.~%" code)) | |
73 | (abort)))) | |
74 | ||
e5152ebe MW |
75 | (defun hard-exit (&optional (code 0)) |
76 | "Stops the program immediately in its tracks. Does nothing else. Use | |
77 | after fork, for example, to avoid flushing buffers." | |
78 | (declare (type (unsigned-byte 32) code)) | |
79 | #+cmu (unix::void-syscall ("_exit" c-call:int) code) | |
d7d81997 | 80 | #+sbcl (sb-ext:quit :unix-status code :recklessly-p t) |
e5152ebe | 81 | #+(or clisp ecl) (ext:quit code)) |
861345b4 | 82 | |
861345b4 | 83 | ;;;----- That's all, folks -------------------------------------------------- |