1 ;;;; the known-to-the-cross-compiler part of PATHNAME logic
3 ;;;; This software is part of the SBCL system. See the README file for
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.
12 (in-package "SB!IMPL")
14 ;;;; data types used by pathnames
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 (unparse-directory-separator (missing-arg) :type simple-string
)
29 (customary-case (missing-arg) :type
(member :upper
:lower
)))
31 (def!method print-object
((host host
) stream
)
32 (print-unreadable-object (host stream
:type t
:identity t
)))
34 (def!struct
(logical-host
35 (:make-load-form-fun make-logical-host-load-form-fun
)
37 (parse #'parse-logical-namestring
)
40 (error "called PARSE-NATIVE-NAMESTRING using a ~
41 logical host: ~S" x
)))
42 (unparse #'unparse-logical-namestring
)
45 (error "called NATIVE-NAMESTRING using a ~
46 logical host: ~S" x
)))
49 (logical-host-name (%pathname-host x
))))
50 (unparse-directory #'unparse-logical-directory
)
51 (unparse-file #'unparse-logical-file
)
52 (unparse-enough #'unparse-enough-namestring
)
53 (unparse-directory-separator ";")
54 (customary-case :upper
)))
55 (name "" :type simple-string
)
56 (translations nil
:type list
)
57 (canon-transls nil
:type list
))
59 (def!method print-object
((logical-host logical-host
) stream
)
60 (print-unreadable-object (logical-host stream
:type t
)
61 (prin1 (logical-host-name logical-host
) stream
)))
63 (defun make-logical-host-load-form-fun (logical-host)
64 (values `(find-logical-host ',(logical-host-name logical-host
))
67 ;;; A PATTERN is a list of entries and wildcards used for pattern
68 ;;; matches of translations.
69 (def!struct
(pattern (:constructor make-pattern
(pieces)))
70 (pieces nil
:type list
))
72 ;;;; PATHNAME structures
74 ;;; the various magic tokens that are allowed to appear in pretty much
75 ;;; all pathname components
76 (eval-when (#-sb-xc
:compile-toplevel
:load-toplevel
:execute
)
77 (def!type pathname-component-tokens
()
78 '(member nil
:unspecific
:wild
)))
80 (sb!xc
:defstruct
(pathname (:conc-name %pathname-
)
81 (:constructor %make-pathname
(host
87 (:predicate pathnamep
))
88 ;; the host (at present either a UNIX or logical host)
89 (host nil
:type
(or host null
))
90 ;; the name of a logical or physical device holding files
91 (device nil
:type
(or simple-string pathname-component-tokens
))
92 ;; a list of strings that are the component subdirectory components
93 (directory nil
:type list
)
95 (name nil
:type
(or simple-string pattern pathname-component-tokens
))
96 ;; the type extension of the file
97 (type nil
:type
(or simple-string pattern pathname-component-tokens
))
98 ;; the version number of the file, a positive integer (not supported
99 ;; on standard Unix filesystems)
100 (version nil
:type
(or integer pathname-component-tokens
(member :newest
))))
102 ;;; Logical pathnames have the following format:
104 ;;; logical-namestring ::=
105 ;;; [host ":"] [";"] {directory ";"}* [name] ["." type ["." version]]
108 ;;; directory ::= word | wildcard-word | **
109 ;;; name ::= word | wildcard-word
110 ;;; type ::= word | wildcard-word
111 ;;; version ::= pos-int | newest | NEWEST | *
112 ;;; word ::= {uppercase-letter | digit | -}+
113 ;;; wildcard-word ::= [word] '* {word '*}* [word]
114 ;;; pos-int ::= integer > 0
116 ;;; Physical pathnames include all these slots and a device slot.
118 ;;; Logical pathnames are a subclass of PATHNAME. Their class
119 ;;; relations are mimicked using structures for efficiency.
120 (sb!xc
:defstruct
(logical-pathname (:conc-name %logical-pathname-
)
122 (:constructor %make-logical-pathname