frontend.lisp: Hack around CLisp's bizarreness.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 22 May 2011 14:07:33 +0000 (15:07 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 22 May 2011 14:33:48 +0000 (15:33 +0100)
Annoyingly, CLisp's PROBE-FILE signals an error if you give it a
directory name.  Bodge around this.  I pinched the basic idea from
the CL-FAD package, by Peter Seibel and Edi Weitz.

frontend.lisp

index 1ff3e2f..7801a8a 100644 (file)
 (defvar opt-format :bind
   "Which format to use on output.")
 
 (defvar opt-format :bind
   "Which format to use on output.")
 
+(defun directory-exists-p (name)
+  
+  ;; Make a pathname for NAME which has the right form for a directory.
+  (let ((dirpath
+        (let ((path (pathname name)))
+          (if (null (pathname-name path))
+              path
+              (make-pathname :directory 
+                             (append (or (pathname-directory path)
+                                         (list :relative))
+                                     (list (pathname-name path)))
+                             :name nil
+                             :type nil
+                             :defaults path)))))
+
+    ;; Now check that it exists.
+    #+clisp (and (ext:probe-directory dirpath) (truename dirpath))
+    #-clisp (probe-file dirpath)))
+
 (eval-when (:compile-toplevel :load-toplevel)
   (defopthandler dir (var arg) ()
 (eval-when (:compile-toplevel :load-toplevel)
   (defopthandler dir (var arg) ()
-    (let ((path (probe-file arg)))
+    (let ((path (directory-exists-p arg)))
       (if (and path
               (not (pathname-name path)))
          (setf var path)
       (if (and path
               (not (pathname-name path)))
          (setf var path)