safely.lisp: SAFE-COPY shouldn't make two copies under CLisp.
[lisp] / sys-base.lisp
... / ...
CommitLineData
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.
16;;;
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.
21;;;
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
26(defpackage #:runlisp
27 (:use #:common-lisp)
28 (:export #:*command-line* #:exit)
29 #+clisp (:import-from #:ext #:exit))
30
31(defpackage #:mdw.sys-base
32 (:use #:common-lisp #:runlisp)
33 (:export #:exit #:hard-exit #:*program-name* #:*command-line*
34 #:set-command-line-arguments)
35 (:import-from #:runlisp #:*command-line* #:exit))
36(in-package #:mdw.sys-base)
37
38(defvar *command-line*)
39(defvar *program-name*)
40
41(defun set-command-line-arguments ()
42 (setf *command-line*
43 (or (when (member :cl-launch *features*)
44 (let* ((cll-package (find-package :cl-launch))
45 (name (funcall (intern "GETENV" cll-package)
46 "CL_LAUNCH_FILE"))
47 (args (symbol-value (intern "*ARGUMENTS*"
48 cll-package))))
49 (if name
50 (cons name args)
51 args)))
52 #+cmu ext:*command-line-strings*
53 #+sbcl sb-ext:*posix-argv*
54 #+ecl (loop from i below (ext:argc) collect (ext:argv i))
55 #+clisp (loop with argv = (ext:argv)
56 for i from 7 below (length argv)
57 collect (aref argv i))
58 '("<unknown-lisp>" "--" "<unknown-script>")))
59 (setf *program-name* (pathname-name (car *command-line*))))
60(set-command-line-arguments)
61
62#-clisp
63(unless (fboundp 'exit)
64 (defun exit (&optional (code 0))
65 "Polite way to end a program."
66 #+(or cmu ecl) (ext:quit code)
67 #+sbcl (sb-ext:quit :unix-status code)
68 #-(or cmu ecl sbcl)
69 (progn
70 (unless (zerop code)
71 (format t "~&Exiting unsuccessfully with code ~D.~%" code))
72 (abort))))
73
74(defun hard-exit (&optional (code 0))
75 "Stops the program immediately in its tracks. Does nothing else. Use
76 after fork, for example, to avoid flushing buffers."
77 (declare (type (unsigned-byte 32) code))
78 #+cmu (unix::void-syscall ("_exit" c-call:int) code)
79 #+sbcl (sb-ext:quit :unix-status code :recklessly-p t)
80 #+(or clisp ecl) (ext:quit code))
81
82;;;----- That's all, folks --------------------------------------------------