18c14b9f37cd6ced1b3f7d1c163b56f12f508512
[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   (parse-native (missing-arg) :type function)
22   (unparse (missing-arg) :type function)
23   (unparse-native (missing-arg) :type function)
24   (unparse-host (missing-arg) :type function)
25   (unparse-directory (missing-arg) :type function)
26   (unparse-file (missing-arg) :type function)
27   (unparse-enough (missing-arg) :type function)
28   (customary-case (missing-arg) :type (member :upper :lower)))
29
30 (def!method print-object ((host host) stream)
31   (print-unreadable-object (host stream :type t :identity t)))
32
33 (def!struct (logical-host
34              (:make-load-form-fun make-logical-host-load-form-fun)
35              (:include host
36                        (parse #'parse-logical-namestring)
37                        (parse-native
38                         (lambda (x)
39                           (error "called PARSE-NATIVE-NAMESTRING using a ~
40                                   logical host: ~S" x)))
41                        (unparse #'unparse-logical-namestring)
42                        (unparse-native
43                         (lambda (x)
44                           (error "called NATIVE-NAMESTRING using a ~
45                                   logical host: ~S" x)))
46                        (unparse-host
47                         (lambda (x)
48                           (logical-host-name (%pathname-host x))))
49                        (unparse-directory #'unparse-logical-directory)
50                        (unparse-file #'unparse-logical-file)
51                        (unparse-enough #'unparse-enough-namestring)
52                        (customary-case :upper)))
53   (name "" :type simple-base-string)
54   (translations nil :type list)
55   (canon-transls nil :type list))
56
57 (def!method print-object ((logical-host logical-host) stream)
58   (print-unreadable-object (logical-host stream :type t)
59     (prin1 (logical-host-name logical-host) stream)))
60
61 (defun make-logical-host-load-form-fun (logical-host)
62   (values `(find-logical-host ',(logical-host-name logical-host))
63           nil))
64
65 ;;; A PATTERN is a list of entries and wildcards used for pattern
66 ;;; matches of translations.
67 (def!struct (pattern (:constructor make-pattern (pieces)))
68   (pieces nil :type list))
69 \f
70 ;;;; PATHNAME structures
71
72 ;;; the various magic tokens that are allowed to appear in pretty much
73 ;;; all pathname components
74 (eval-when (#-sb-xc :compile-toplevel :load-toplevel :execute)
75   (def!type pathname-component-tokens ()
76     '(member nil :unspecific :wild)))
77
78 (sb!xc:defstruct (pathname (:conc-name %pathname-)
79                            (:constructor %make-pathname (host
80                                                          device
81                                                          directory
82                                                          name
83                                                          type
84                                                          version))
85                            (:predicate pathnamep))
86   ;; the host (at present either a UNIX or logical host)
87   (host nil :type (or host null))
88   ;; the name of a logical or physical device holding files
89   (device nil :type (or simple-string pathname-component-tokens))
90   ;; a list of strings that are the component subdirectory components
91   (directory nil :type list)
92   ;; the filename
93   (name nil :type (or simple-string pattern pathname-component-tokens))
94   ;; the type extension of the file
95   (type nil :type (or simple-string pattern pathname-component-tokens))
96   ;; the version number of the file, a positive integer (not supported
97   ;; on standard Unix filesystems)
98   (version nil :type (or integer pathname-component-tokens (member :newest))))
99
100 ;;; Logical pathnames have the following format:
101 ;;;
102 ;;; logical-namestring ::=
103 ;;;      [host ":"] [";"] {directory ";"}* [name] ["." type ["." version]]
104 ;;;
105 ;;; host ::= word
106 ;;; directory ::= word | wildcard-word | **
107 ;;; name ::= word | wildcard-word
108 ;;; type ::= word | wildcard-word
109 ;;; version ::= pos-int | newest | NEWEST | *
110 ;;; word ::= {uppercase-letter | digit | -}+
111 ;;; wildcard-word ::= [word] '* {word '*}* [word]
112 ;;; pos-int ::= integer > 0
113 ;;;
114 ;;; Physical pathnames include all these slots and a device slot.
115
116 ;;; Logical pathnames are a subclass of PATHNAME. Their class
117 ;;; relations are mimicked using structures for efficiency.
118 (sb!xc:defstruct (logical-pathname (:conc-name %logical-pathname-)
119                                    (:include pathname)
120                                    (:constructor %make-logical-pathname
121                                                  (host
122                                                   device
123                                                   directory
124                                                   name
125                                                   type
126                                                   version))))