0.7.1.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 ;;; What would it mean to dump a logical host and reload it into
52 ;;; another Lisp image? It's not clear, so we don't support it.
53 (defun make-logical-host-load-form-fun (logical-host)
54   (error "~@<A logical host can't be dumped as a constant: ~2I~_~S~:>"
55          logical-host))
56
57 ;;; A PATTERN is a list of entries and wildcards used for pattern
58 ;;; matches of translations.
59 (sb!xc:defstruct (pattern (:constructor make-pattern (pieces)))
60   (pieces nil :type list))
61 \f
62 ;;;; PATHNAME structures
63
64 ;;; the various magic tokens that are allowed to appear in pretty much
65 ;;; all pathname components
66 (sb!xc:deftype pathname-component-tokens ()
67   '(member nil :unspecific :wild))
68
69 (sb!xc:defstruct (pathname (:conc-name %pathname-)
70                            (:constructor %make-pathname (host
71                                                          device
72                                                          directory
73                                                          name
74                                                          type
75                                                          version))
76                            (:predicate pathnamep))
77   ;; the host (at present either a UNIX or logical host)
78   (host nil :type (or host null))
79   ;; the name of a logical or physical device holding files
80   (device nil :type (or simple-string pathname-component-tokens))
81   ;; a list of strings that are the component subdirectory components
82   (directory nil :type list)
83   ;; the filename
84   (name nil :type (or simple-string pattern pathname-component-tokens))
85   ;; the type extension of the file
86   (type nil :type (or simple-string pattern pathname-component-tokens))
87   ;; the version number of the file, a positive integer (not supported
88   ;; on standard Unix filesystems)
89   (version nil :type (or integer pathname-component-tokens (member :newest))))
90
91 ;;; Logical pathnames have the following format:
92 ;;;
93 ;;; logical-namestring ::=
94 ;;;      [host ":"] [";"] {directory ";"}* [name] ["." type ["." version]]
95 ;;;
96 ;;; host ::= word
97 ;;; directory ::= word | wildcard-word | **
98 ;;; name ::= word | wildcard-word
99 ;;; type ::= word | wildcard-word
100 ;;; version ::= pos-int | newest | NEWEST | *
101 ;;; word ::= {uppercase-letter | digit | -}+
102 ;;; wildcard-word ::= [word] '* {word '*}* [word]
103 ;;; pos-int ::= integer > 0
104 ;;;
105 ;;; Physical pathnames include all these slots and a device slot.
106
107 ;;; Logical pathnames are a subclass of PATHNAME. Their class
108 ;;; relations are mimicked using structures for efficiency.
109 (sb!xc:defstruct (logical-pathname (:conc-name %logical-pathname-)
110                                    (:include pathname)
111                                    (:constructor %make-logical-pathname
112                                                  (host
113                                                   device
114                                                   directory
115                                                   name
116                                                   type
117                                                   version))))