;; Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.1;; All rights reserved.2;; Copyright (C) 2007-2012, Gabriel Dos Reis.3;; All rights reserved.4;;5;; Redistribution and use in source and binary forms, with or without6;; modification, are permitted provided that the following conditions are7;; met:8;;9;; - Redistributions of source code must retain the above copyright10;; notice, this list of conditions and the following disclaimer.11;;12;; - Redistributions in binary form must reproduce the above copyright13;; notice, this list of conditions and the following disclaimer in14;; the documentation and/or other materials provided with the15;; distribution.16;;17;; - Neither the name of The Numerical ALgorithms Group Ltd. nor the18;; names of its contributors may be used to endorse or promote products19;; derived from this software without specific prior written permission.20;;21;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS22;; IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED23;; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A24;; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER25;; OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,26;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,27;; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR28;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF29;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING30;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.323334;;35;; Lisp support for cleaned up FileName domain.36;;37;; Created: June 20, 1991 (Stephen Watt)38;;3940(import-module "sys-macros")41(in-package "BOOT")4243;; E.g. "/" "/u/smwatt" "../src"44(defun |DirToString| (d)45(cond46((equal d '(:root)) "/")47((null d) "")48('t (string-right-trim "/" (namestring (make-pathname :directory d)))) ))4950(defun |StringToDir| (s)51(cond52((string= s "/") '(:root))53((string= s "") nil)54('t55(let ((lastc (aref s (- (length s) 1))))56(if (char= lastc #\/)57(pathname-directory (concat s "name.type"))58(pathname-directory (concat s "/name.type")) ))) ))5960(defun |myWritable?| (s)61(if (not (stringp s)) (|error| "``myWritable?'' requires a string arg."))62(if (string= s "") (setq s "."))63(if (not (|fnameExists?| s)) (setq s (|fnameDirectory| s)))64(if (string= s "") (setq s "."))65(if (> (|writeablep| s) 0) 't nil) )6667(defun |fnameMake| (d n e)68(if (string= e "") (setq e nil))69(make-pathname :directory (|StringToDir| d) :name n :type e))7071(defun |fnameDirectory| (f)72(|DirToString| (pathname-directory f)))7374(defun |fnameName| (f)75(let ((s (pathname-name f)))76(if s s "") ))7778(defun |fnameType| (f)79(let ((s (pathname-type f)))80(if s s "") ))8182(defun |fnameExists?| (f)83(if (probe-file (namestring f)) 't nil))8485(defun |fnameReadable?| (f)86(let ((s (open f :direction :input :if-does-not-exist nil)))87(cond (s (close s) 't) ('t nil)) )88)8990(defun |fnameWritable?| (f)91(|myWritable?| (namestring f)) )9293(defun |fnameNew| (d n e)94(if (not (|myWritable?| d))95nil96(do ((fn))97(nil)98(setq fn (|fnameMake| d (string (gensym n)) e))99(if (not (probe-file (namestring fn)))100(return-from |fnameNew| fn)) )))101102103