3 ;;; Basic system-specific stuff
5 ;;; (c) 2005 Mark Wooding
8 ;;;----- Licensing notice ---------------------------------------------------
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.
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.
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.
26 (:export #:*command-line* #:exit)
27 #+clisp (:import-from #:ext #:exit))
29 (defpackage #:mdw.sys-base
30 (:use #:common-lisp #:runlisp)
31 (:export #:exit #:hard-exit #:*program-name* #:*command-line*
32 #:set-command-line-arguments)
33 (:import-from #:runlisp #:*command-line* #:exit))
34 (in-package #:mdw.sys-base)
36 (defvar *command-line*)
37 (defvar *program-name*)
39 (defun set-command-line-arguments ()
41 (let ((uiop-package (find-package :uiop))
42 (cll-package (find-package :cl-launch)))
43 (cons (or (and uiop-package
44 (funcall (intern "ARGV0" uiop-package)))
46 (some (intern "GETENV" cll-package)
47 (list "__CL_ARGV0" "CL_LAUNCH_FILE")))
48 #+sbcl (car sb-ext:*posix-argv*)
49 #+cmu (car ext:*command-line-strings*)
50 #+clisp (aref (ext:argv) 0)
54 (funcall (intern "COMMAND-LINE-ARGUMENTS"
57 (symbol-value (intern "*ARGUMENTS*" cll-package)))
58 (t #.(or (car '(#+sbcl (cdr sb-ext:*posix-argv*)
59 #+cmu (cdr ext:*command-line-strings*)
60 #+clisp (coerce (subseq (ext:argv) 8)
62 #+ecl (loop for i from 1
64 collect (ext:argv i))))
65 (error "Unsupported Lisp."))))))
67 *program-name* (pathname-name (car *command-line*))))
69 (set-command-line-arguments)
72 (unless (fboundp 'exit)
73 (defun exit (&optional (code 0))
74 "Polite way to end a program."
75 #+(or cmu ecl) (ext:quit code)
76 #+sbcl (sb-ext:exit :code code)
80 (format t "~&Exiting unsuccessfully with code ~D.~%" code))
83 (defun hard-exit (&optional (code 0))
84 "Stops the program immediately in its tracks. Does nothing else. Use
85 after fork, for example, to avoid flushing buffers."
86 (declare (type (unsigned-byte 32) code))
87 #+cmu (unix::void-syscall ("_exit" c-call:int) code)
88 #+sbcl (sb-ext:exit :code code :abort t)
89 #+(or clisp ecl) (ext:quit code))
91 ;;;----- That's all, folks --------------------------------------------------