X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=utils.lisp;h=9c2f9799ec661f199606af985fe5adebaf72715d;hb=c18c02e07944ea56688b4fc350dbdab400f84fe1;hp=dcd099530255f25c9a00bfa723103499cad1c414;hpb=7f3cd207cac41ffb53fa8ca0d4563554e4ef16fa;p=lml.git diff --git a/utils.lisp b/utils.lisp index dcd0995..9c2f979 100644 --- a/utils.lisp +++ b/utils.lisp @@ -1,9 +1,8 @@ -;;; $Id: utils.lisp,v 1.7 2003/03/12 17:01:48 kevin Exp $ +;;; $Id$ ;;;; ;;;; General purpose utilities -(in-package :lml) - +(in-package #:lml) (defmacro aif (test then &optional else) `(let ((it ,test)) @@ -19,38 +18,40 @@ (string-equal "keyword" (package-name (symbol-package x))))) (defun list-to-spaced-string (list) - (if (consp list) - (format nil "~A~{ ~A~}" (first list) (rest list)) - "")) + (format nil "~{~A~^ ~}" list)) + +(defun print-n-chars (char n stream) + (declare (fixnum n) + (optimize (speed 3) (safety 0) (space 0))) + (do ((i 0 (1+ i))) + ((= i n) char) + (declare (fixnum i)) + (write-char char stream))) (defun indent-spaces (n &optional (stream *standard-output*)) "Indent n*2 spaces to output stream" - (let ((fmt (format nil "~~~DT" (+ n n)))) - (format stream fmt))) + (print-n-chars #\space (+ n n) stream)) (defun print-file-contents (file &optional (strm *standard-output*)) "Opens a reads a file. Returns the contents as a single string" (when (probe-file file) (with-open-file (in file :direction :input) - (do ((line (read-line in nil 'eof) - (read-line in nil 'eof))) - ((eql line 'eof)) - (format strm "~A~%" line))))) + (do ((line (read-line in nil 'eof) + (read-line in nil 'eof))) + ((eql line 'eof)) + (write-string line strm) + (write-char #\newline strm))))) (defun date-string (ut) - (if (typep ut 'integer) - (multiple-value-bind (sec min hr day mon year dow daylight-p zone) - (decode-universal-time ut) - (declare (ignore daylight-p zone)) - (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" - dow - day - (1- mon) - year - hr min sec)))) + (check-type ut integer) + (multiple-value-bind (sec min hr day mon year dow daylight-p zone) + (decode-universal-time ut) + (declare (ignore daylight-p zone)) + (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" + dow day (1- mon) year hr min sec))) (defun lml-quit (&optional (code 0)) - "Function to exit the Lisp implementation. Copied from CLOCC's QUIT function." + "Function to exit the Lisp implementation." #+allegro (excl:exit code) #+clisp (#+lisp=cl ext:quit #-lisp=cl lisp:quit code) #+(or cmu scl) (ext:quit code) @@ -78,4 +79,4 @@ #+mcl (ccl:mac-default-directory) #-(or allegro clisp cmu scl sbcl cormanlisp lispworks lucid mcl) (truename ".")) - +