Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
;; Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
2
;; All rights reserved.
3
;; Copyright (C) 2007-2012, Gabriel Dos Reis.
4
;; All rights reserved.
5
;;
6
;; Redistribution and use in source and binary forms, with or without
7
;; modification, are permitted provided that the following conditions are
8
;; met:
9
;;
10
;; - Redistributions of source code must retain the above copyright
11
;; notice, this list of conditions and the following disclaimer.
12
;;
13
;; - Redistributions in binary form must reproduce the above copyright
14
;; notice, this list of conditions and the following disclaimer in
15
;; the documentation and/or other materials provided with the
16
;; distribution.
17
;;
18
;; - Neither the name of The Numerical ALgorithms Group Ltd. nor the
19
;; names of its contributors may be used to endorse or promote products
20
;; derived from this software without specific prior written permission.
21
;;
22
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23
;; IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24
;; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25
;; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26
;; OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
;; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34
35
;;
36
;; Lisp support for cleaned up FileName domain.
37
;;
38
;; Created: June 20, 1991 (Stephen Watt)
39
;;
40
41
(import-module "sys-macros")
42
(in-package "BOOT")
43
44
;; E.g. "/" "/u/smwatt" "../src"
45
(defun |DirToString| (d)
46
(cond
47
((equal d '(:root)) "/")
48
((null d) "")
49
('t (string-right-trim "/" (namestring (make-pathname :directory d)))) ))
50
51
(defun |StringToDir| (s)
52
(cond
53
((string= s "/") '(:root))
54
((string= s "") nil)
55
('t
56
(let ((lastc (aref s (- (length s) 1))))
57
(if (char= lastc #\/)
58
(pathname-directory (concat s "name.type"))
59
(pathname-directory (concat s "/name.type")) ))) ))
60
61
(defun |myWritable?| (s)
62
(if (not (stringp s)) (|error| "``myWritable?'' requires a string arg."))
63
(if (string= s "") (setq s "."))
64
(if (not (|fnameExists?| s)) (setq s (|fnameDirectory| s)))
65
(if (string= s "") (setq s "."))
66
(if (> (|writeablep| s) 0) 't nil) )
67
68
(defun |fnameMake| (d n e)
69
(if (string= e "") (setq e nil))
70
(make-pathname :directory (|StringToDir| d) :name n :type e))
71
72
(defun |fnameDirectory| (f)
73
(|DirToString| (pathname-directory f)))
74
75
(defun |fnameName| (f)
76
(let ((s (pathname-name f)))
77
(if s s "") ))
78
79
(defun |fnameType| (f)
80
(let ((s (pathname-type f)))
81
(if s s "") ))
82
83
(defun |fnameExists?| (f)
84
(if (probe-file (namestring f)) 't nil))
85
86
(defun |fnameReadable?| (f)
87
(let ((s (open f :direction :input :if-does-not-exist nil)))
88
(cond (s (close s) 't) ('t nil)) )
89
)
90
91
(defun |fnameWritable?| (f)
92
(|myWritable?| (namestring f)) )
93
94
(defun |fnameNew| (d n e)
95
(if (not (|myWritable?| d))
96
nil
97
(do ((fn))
98
(nil)
99
(setq fn (|fnameMake| d (string (gensym n)) e))
100
(if (not (probe-file (namestring fn)))
101
(return-from |fnameNew| fn)) )))
102
103