1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
\r
2 ;;;; *************************************************************************
\r
3 ;;;; FILE IDENTIFICATION
\r
5 ;;;; Name: utils.lisp
\r
6 ;;;; Purpose: General purpose utilities
\r
7 ;;;; Author: Kevin M. Rosenberg
\r
8 ;;;; Date Started: June 2002
\r
10 ;;;; $Id: utils.lisp,v 1.5 2003/07/15 21:49:36 kevin Exp $
\r
12 ;;;; This file, part of LML2, is copyrighted and open-source software.
\r
13 ;;;; Rights of modification and redistribution are in the LICENSE file.
\r
15 ;;;; *************************************************************************
\r
19 (defmacro aif (test then &optional else)
\r
21 (if it ,then ,else)))
\r
23 (defmacro awhen (test-form &body body)
\r
27 (defun print-file-contents (file &optional (strm *standard-output*))
\r
28 "Opens a reads a file. Returns the contents as a single string"
\r
29 (when (probe-file file)
\r
30 (let ((eof (cons 'eof nil)))
\r
31 (with-open-file (in file :direction :input)
\r
32 (do ((line (read-line in nil eof)
\r
33 (read-line in nil eof)))
\r
35 (write-string line strm)
\r
36 (write-char #\newline strm))))))
\r
38 (defun date-string (ut)
\r
39 (check-type ut integer)
\r
40 (multiple-value-bind (sec min hr day mon year dow daylight-p zone)
\r
41 (decode-universal-time ut)
\r
42 (declare (ignore daylight-p zone))
\r
43 (format nil "~[Mon~;Tue~;Wed~;Thu~;Fri~;Sat~;Sun~], ~d ~[Jan~;Feb~;Mar~;Apr~;May~;Jun~;Jul~;Aug~;Sep~;Oct~;Nov~;Dec~] ~d ~2,'0d:~2,'0d:~2,'0d"
\r
44 dow day (1- mon) year hr min sec)))
\r
46 (defun lml-quit (&optional (code 0))
\r
47 "Function to exit the Lisp implementation."
\r
48 #+allegro (excl:exit code)
\r
49 #+clisp (#+lisp=cl ext:quit #-lisp=cl lisp:quit code)
\r
50 #+(or cmu scl) (ext:quit code)
\r
51 #+cormanlisp (win32:exitprocess code)
\r
52 #+gcl (lisp:bye code)
\r
53 #+lispworks (lw:quit :status code)
\r
54 #+lucid (lcl:quit code)
\r
55 #+sbcl (sb-ext:quit :unix-status (typecase code (number code) (null 0) (t 1)))
\r
56 #+openmcl (ccl:quit code)
\r
57 #+(and mcl (not openmcl)) (declare (ignore code))
\r
58 #+(and mcl (not openmcl)) (ccl:quit)
\r
59 #-(or allegro clisp cmu scl cormanlisp gcl lispworks lucid sbcl mcl)
\r
60 (error 'not-implemented :proc (list 'quit code)))
\r
64 "Returns the current working directory. Based on CLOCC's DEFAULT-DIRECTORY function."
\r
65 #+allegro (excl:current-directory)
\r
66 #+clisp (#+lisp=cl ext:default-directory #-lisp=cl lisp:default-directory)
\r
67 #+(or cmu scl) (ext:default-directory)
\r
68 #+cormanlisp (ccl:get-current-directory)
\r
69 #+lispworks (hcl:get-working-directory)
\r
70 #+lucid (lcl:working-directory)
\r
71 #+sbcl (sb-unix:posix-getcwd/)
\r
72 #+mcl (ccl:mac-default-directory)
\r
73 #-(or allegro clisp cmu scl sbcl cormanlisp lispworks lucid mcl) (truename "."))
\r
77 (defun fformat (&rest args)
\r
78 (declare (dynamic-extent args))
\r
79 (apply (if (find-package 'kmrcl)
\r
80 (symbol-function (intern (symbol-name #:fformat)
\r
81 (symbol-name #:kmrcl)))
\r
85 (defmacro fformat (stream control-string &rest args)
\r
87 `(funcall (formatter ,control-string) ,stream ,@args)
\r
88 `(format nil ,control-string ,@args)))
\r