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 (customary-case (missing-arg) :type (member :upper :lower)))
30 (def!method print-object ((host host) stream)
31 (print-unreadable-object (host stream :type t :identity t)))
33 (def!struct (logical-host
34 (:make-load-form-fun make-logical-host-load-form-fun)
36 (parse #'parse-logical-namestring)
39 (error "called PARSE-NATIVE-NAMESTRING using a ~
40 logical host: ~S" x)))
41 (unparse #'unparse-logical-namestring)
44 (error "called NATIVE-NAMESTRING using a ~
45 logical host: ~S" 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))
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)))
61 (defun make-logical-host-load-form-fun (logical-host)
62 (values `(find-logical-host ',(logical-host-name logical-host))
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))
70 ;;;; PATHNAME structures
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)))
78 (sb!xc:defstruct (pathname (:conc-name %pathname-)
79 (:constructor %make-pathname (host
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)
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))))
100 ;;; Logical pathnames have the following format:
102 ;;; logical-namestring ::=
103 ;;; [host ":"] [";"] {directory ";"}* [name] ["." type ["." version]]
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
114 ;;; Physical pathnames include all these slots and a device slot.
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-)
120 (:constructor %make-logical-pathname