0.6.7.22: removed CVS dollar-Header-dollar tags from sources
[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 (sb!xc:defstruct (host (:constructor nil))
20   (parse (required-argument) :type function)
21   (unparse (required-argument) :type function)
22   (unparse-host (required-argument) :type function)
23   (unparse-directory (required-argument) :type function)
24   (unparse-file (required-argument) :type function)
25   (unparse-enough (required-argument) :type function)
26   (customary-case (required-argument) :type (member :upper :lower)))
27
28 (sb!xc:defstruct (logical-host
29                   (:include host
30                             (:parse #'parse-logical-namestring)
31                             (:unparse #'unparse-logical-namestring)
32                             (:unparse-host
33                              (lambda (x)
34                                (logical-host-name (%pathname-host x))))
35                             (:unparse-directory #'unparse-logical-directory)
36                             (:unparse-file #'unparse-unix-file)
37                             (:unparse-enough #'identity)
38                             (:customary-case :upper)))
39   (name "" :type simple-base-string)
40   (translations nil :type list)
41   (canon-transls nil :type list))
42
43 ;;; A PATTERN is a list of entries and wildcards used for pattern
44 ;;; matches of translations.
45 (sb!xc:defstruct (pattern (:constructor make-pattern (pieces)))
46   (pieces nil :type list))
47 \f
48 ;;;; PATHNAME structures
49
50 ;;; the various magic tokens that are allowed to appear in pretty much
51 ;;; all pathname components
52 (sb!xc:deftype component-tokens () ; FIXME: rename to PATHNAME-COMPONENT-TOKENS
53   '(member nil :unspecific :wild))
54
55 (sb!xc:defstruct (pathname (:conc-name %pathname-)
56                            (:constructor %make-pathname (host
57                                                          device
58                                                          directory
59                                                          name
60                                                          type
61                                                          version))
62                            (:predicate pathnamep))
63   ;; the host (at present either a UNIX or logical host)
64   (host nil :type (or host null))
65   ;; the name of a logical or physical device holding files
66   (device nil :type (or simple-string component-tokens))
67   ;; a list of strings that are the component subdirectory components
68   (directory nil :type list)
69   ;; the filename
70   (name nil :type (or simple-string pattern component-tokens))
71   ;; the type extension of the file
72   (type nil :type (or simple-string pattern component-tokens))
73   ;; the version number of the file, a positive integer (not supported
74   ;; on standard Unix filesystems)
75   (version nil :type (or integer component-tokens (member :newest))))
76
77 ;;; Logical pathnames have the following format:
78 ;;;
79 ;;; logical-namestring ::=
80 ;;;      [host ":"] [";"] {directory ";"}* [name] ["." type ["." version]]
81 ;;;
82 ;;; host ::= word
83 ;;; directory ::= word | wildcard-word | **
84 ;;; name ::= word | wildcard-word
85 ;;; type ::= word | wildcard-word
86 ;;; version ::= pos-int | newest | NEWEST | *
87 ;;; word ::= {uppercase-letter | digit | -}+
88 ;;; wildcard-word ::= [word] '* {word '*}* [word]
89 ;;; pos-int ::= integer > 0
90 ;;;
91 ;;; Physical pathnames include all these slots and a device slot.
92
93 ;;; Logical pathnames are a subclass of pathname. Their class
94 ;;; relations are mimicked using structures for efficency.
95 (sb!xc:defstruct (logical-pathname (:conc-name %logical-pathname-)
96                                    (:include pathname)
97                                    (:constructor %make-logical-pathname
98                                                  (host
99                                                   device
100                                                   directory
101                                                   name
102                                                   type
103                                                   version))))
104 \f
105 (defmacro-mundanely enumerate-search-list ((var pathname &optional result)
106                                            &body body)
107   #!+sb-doc
108   "Execute BODY with VAR bound to each successive possible expansion for
109    PATHNAME and then return RESULT. Note: if PATHNAME does not contain a
110    search-list, then BODY is executed exactly once. Everything is wrapped
111    in a block named NIL, so RETURN can be used to terminate early. Note:
112    VAR is *not* bound inside of RESULT."
113   (let ((body-name (gensym)))
114     `(block nil
115        (flet ((,body-name (,var)
116                 ,@body))
117          (%enumerate-search-list ,pathname #',body-name)
118          ,result))))
119