optparse: Process docstring and declarations correctly in defopthandler.
[lisp] / sys-base.lisp
CommitLineData
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.
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 #:mdw.runlisp
beaffa5a 27 (:use #:common-lisp #+cmu #:extensions)
861345b4 28 (:export #:*lisp-interpreter* #:*command-line-strings*))
8a2e8de1
MW
29(in-package #:mdw.runlisp)
30
31#+clisp
32(progn
33 (defvar *lisp-interpreter*)
34 (defvar *command-line-strings*)
35 (let ((args (coerce (ext:argv) 'list)))
36 (setf *lisp-interpreter* (car args))
37 (setf *command-line-strings* (nthcdr 7 args))))
38
861345b4 39(defpackage #:mdw.sys-base
8a2e8de1
MW
40 (:use #:common-lisp #+cmu #:extensions #+cmu #:mdw.runlisp)
41 (:export #:exit #:hard-exit #:*program-name* #:*command-line-strings*)
42 (:import-from #:mdw.runlisp #:*lisp-interpreter* #:*command-line-strings*)
43 #+clisp (:import-from #:ext #:exit))
861345b4 44(in-package #:mdw.sys-base)
45
46;;; --- This is currently all a bit CMUCL-specific ---
47
8a2e8de1 48#+(or cmu)
861345b4 49(defun exit (&optional (code 0))
50 "Polite way to end a program. If running in an interactive Lisp, just
0ff9df03 51 return to the top-level REPL."
8a2e8de1
MW
52 (if #+cmu *batch-mode*
53 #+cmu (throw 'lisp::%end-of-the-world code)
861345b4 54 (progn
55 (unless (zerop code)
56 (format t "~&Exiting unsuccessfully with code ~D.~%" code))
57 (abort))))
58
c59bde66 59(defun hard-exit (&optional (code 0))
861345b4 60 "Stops the program immediately in its tracks. Does nothing else. Use
0ff9df03 61 after fork, for example, to avoid flushing buffers."
c59bde66 62 (declare (type (unsigned-byte 32) code))
8a2e8de1
MW
63 #+cmu (unix::void-syscall ("_exit" c-call:int) code)
64 #+clisp (ext:quit code))
861345b4 65
8a2e8de1
MW
66(defvar *program-name*
67 (pathname-name (car *command-line-strings*))
861345b4 68 "A plausible guess at the program's name, stripped of strange extensions.")
69
70;;;----- That's all, folks --------------------------------------------------