0.7.7.16:
[sbcl.git] / src / code / pathname.lisp
1 ;;;; the known-to-the-cross-compiler part of PATHNAME logic
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 (in-package "SB!IMPL")
13 \f
14 ;;;; data types used by pathnames
15
16 ;;; The HOST structure holds the functions that both parse the
17 ;;; pathname information into structure slot entries, and after
18 ;;; translation the inverse (unparse) functions.
19 (def!struct (host (:constructor nil))
20   (parse (missing-arg) :type function)
21   (unparse (missing-arg) :type function)
22   (unparse-host (missing-arg) :type function)
23   (unparse-directory (missing-arg) :type function)
24   (unparse-file (missing-arg) :type function)
25   (unparse-enough (missing-arg) :type function)
26   (customary-case (missing-arg) :type (member :upper :lower)))
27
28 (def!method print-object ((host host) stream)
29   (print-unreadable-object (host stream :type t :identity t)))
30
31 (def!struct (logical-host
32              (:make-load-form-fun make-logical-host-load-form-fun)
33              (:include host
34                        (parse #'parse-logical-namestring)
35                        (unparse #'unparse-logical-namestring)
36                        (unparse-host
37                         (lambda (x)
38                           (logical-host-name (%pathname-host x))))
39                        (unparse-directory #'unparse-logical-directory)
40                        (unparse-file #'unparse-unix-file)
41                        (unparse-enough #'unparse-enough-namestring)
42                        (customary-case :upper)))
43   (name "" :type simple-base-string)
44   (translations nil :type list)
45   (canon-transls nil :type list))
46
47 (def!method print-object ((logical-host logical-host) stream)
48   (print-unreadable-object (logical-host stream :type t)
49     (prin1 (logical-host-name logical-host) stream)))
50
51 (defun make-logical-host-load-form-fun (logical-host)
52   (values `(find-logical-host ',(logical-host-name logical-host))
53           nil))
54
55 ;;; A PATTERN is a list of entries and wildcards used for pattern
56 ;;; matches of translations.
57 (sb!xc:defstruct (pattern (:constructor make-pattern (pieces)))
58   (pieces nil :type list))
59 \f
60 ;;;; PATHNAME structures
61
62 ;;; the various magic tokens that are allowed to appear in pretty much
63 ;;; all pathname components
64 (sb!xc:deftype pathname-component-tokens ()
65   '(member nil :unspecific :wild))
66
67 (sb!xc:defstruct (pathname (:conc-name %pathname-)
68                            (:constructor %make-pathname (host
69                                                          device
70                                                          directory
71                                                          name
72                                                          type
73                                                          version))
74                            (:predicate pathnamep))
75   ;; the host (at present either a UNIX or logical host)
76   (host nil :type (or host null))
77   ;; the name of a logical or physical device holding files
78   (device nil :type (or simple-string pathname-component-tokens))
79   ;; a list of strings that are the component subdirectory components
80   (directory nil :type list)
81   ;; the filename
82   (name nil :type (or simple-string pattern pathname-component-tokens))
83   ;; the type extension of the file
84   (type nil :type (or simple-string pattern pathname-component-tokens))
85   ;; the version number of the file, a positive integer (not supported
86   ;; on standard Unix filesystems)
87   (version nil :type (or integer pathname-component-tokens (member :newest))))
88
89 ;;; Logical pathnames have the following format:
90 ;;;
91 ;;; logical-namestring ::=
92 ;;;      [host ":"] [";"] {directory ";"}* [name] ["." type ["." version]]
93 ;;;
94 ;;; host ::= word
95 ;;; directory ::= word | wildcard-word | **
96 ;;; name ::= word | wildcard-word
97 ;;; type ::= word | wildcard-word
98 ;;; version ::= pos-int | newest | NEWEST | *
99 ;;; word ::= {uppercase-letter | digit | -}+
100 ;;; wildcard-word ::= [word] '* {word '*}* [word]
101 ;;; pos-int ::= integer > 0
102 ;;;
103 ;;; Physical pathnames include all these slots and a device slot.
104
105 ;;; Logical pathnames are a subclass of PATHNAME. Their class
106 ;;; relations are mimicked using structures for efficiency.
107 (sb!xc:defstruct (logical-pathname (:conc-name %logical-pathname-)
108                                    (:include pathname)
109                                    (:constructor %make-logical-pathname
110                                                  (host
111                                                   device
112                                                   directory
113                                                   name
114                                                   type
115                                                   version))))