optparse.lisp: Fix stupid paren-positioning blunders.
[lisp] / sys-base.lisp
... / ...
CommitLineData
1;;; -*-lisp-*-
2;;;
3;;; Basic system-specific stuff
4;;;
5;;; (c) 2005 Mark Wooding
6;;;
7
8;;;----- Licensing notice ---------------------------------------------------
9;;;
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.
14;;;
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.
19;;;
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.
23
24(defpackage #:runlisp
25 (:use #:common-lisp)
26 (:export #:*command-line* #:exit)
27 #+clisp (:import-from #:ext #:exit))
28
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)
35
36(defvar *command-line*)
37(defvar *program-name*)
38
39(defun set-command-line-arguments ()
40 (setf *command-line*
41 (or (when (member :cl-launch *features*)
42 (let* ((uiop-package (find-package :uiop))
43 (cll-package (find-package :cl-launch))
44 (name (some (intern "GETENV"
45 (or uiop-package cll-package))
46 (list "__CL_ARGV0" "CL_LAUNCH_FILE")))
47 (args (symbol-value
48 (if uiop-package
49 (intern "*COMMAND-LINE-ARGUMENTS*"
50 uiop-package)
51 (intern "*ARGUMENTS*" cll-package)))))
52 (if name
53 (cons name args)
54 args)))
55 #+cmu ext:*command-line-strings*
56 #+sbcl sb-ext:*posix-argv*
57 #+ecl (loop from i below (ext:argc) collect (ext:argv i))
58 #+clisp (loop with argv = (ext:argv)
59 for i from 7 below (length argv)
60 collect (aref argv i))
61 '("<unknown-lisp>" "--" "<unknown-script>")))
62 (setf *program-name* (pathname-name (car *command-line*))))
63(set-command-line-arguments)
64
65#-clisp
66(unless (fboundp 'exit)
67 (defun exit (&optional (code 0))
68 "Polite way to end a program."
69 #+(or cmu ecl) (ext:quit code)
70 #+sbcl (sb-ext:exit :code code)
71 #-(or cmu ecl sbcl)
72 (progn
73 (unless (zerop code)
74 (format t "~&Exiting unsuccessfully with code ~D.~%" code))
75 (abort))))
76
77(defun hard-exit (&optional (code 0))
78 "Stops the program immediately in its tracks. Does nothing else. Use
79 after fork, for example, to avoid flushing buffers."
80 (declare (type (unsigned-byte 32) code))
81 #+cmu (unix::void-syscall ("_exit" c-call:int) code)
82 #+sbcl (sb-ext:exit :code code :abort t)
83 #+(or clisp ecl) (ext:quit code))
84
85;;;----- That's all, folks --------------------------------------------------