/[cmucl]/src/code/pathname.lisp
ViewVC logotype

Contents of /src/code/pathname.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.59.2.1 - (show annotations)
Mon Mar 24 10:54:40 2003 UTC (11 years ago) by gerd
Branch: cold-pcl
Changes since 1.59: +8 -9 lines
Merge with HEAD
1 ;;; -*- Package: LISP -*-
2 ;;; **********************************************************************
3 ;;; This code was written as part of the CMU Common Lisp project at
4 ;;; Carnegie Mellon University, and has been placed in the public domain.
5 ;;;
6 (ext:file-comment
7 "$Header: /tiger/var/lib/cvsroots/cmucl/src/code/pathname.lisp,v 1.59.2.1 2003/03/24 10:54:40 gerd Exp $")
8 ;;;
9 ;;; **********************************************************************
10 ;;;
11 ;;; Machine/filesystem independent pathname functions for CMU Common Lisp.
12 ;;;
13 ;;; Written by William Lott, Paul Gleichauf and Rob MacLachlan.
14 ;;; Earlier version written by Jim Large and Rob MacLachlan
15 ;;;
16 ;;; **********************************************************************
17
18 (in-package "LISP")
19
20 (export '(pathname pathnamep logical-pathname
21 parse-namestring merge-pathnames make-pathname
22 pathname-host pathname-device pathname-directory pathname-name
23 pathname-type pathname-version namestring file-namestring
24 directory-namestring host-namestring enough-namestring
25 wild-pathname-p pathname-match-p translate-pathname
26 translate-logical-pathname logical-pathname-translations
27 load-logical-pathname-translations *default-pathname-defaults*))
28
29 (in-package "EXTENSIONS")
30 (export '(search-list search-list-defined-p clear-search-list
31 enumerate-search-list *autoload-translations*))
32
33 (in-package "LISP")
34
35 (defvar *autoload-translations* nil
36 "When non-nil, attempt to load \"library:<host>.translations\" to resolve
37 an otherwise undefined logical host.")
38
39
40 ;;;; HOST structures
41
42 ;;; The host structure holds the functions that both parse the pathname
43 ;;; information into sturcture slot entries, and after translation the inverse
44 ;;; (unparse) functions.
45 ;;;
46 (defstruct (host
47 (:print-function %print-host))
48 (parse (required-argument) :type function)
49 (unparse (required-argument) :type function)
50 (unparse-host (required-argument) :type function)
51 (unparse-directory (required-argument) :type function)
52 (unparse-file (required-argument) :type function)
53 (unparse-enough (required-argument) :type function)
54 (customary-case (required-argument) :type (member :upper :lower)))
55
56 ;;; %PRINT-HOST -- Internal
57 ;;;
58 (defun %print-host (host stream depth)
59 (declare (ignore depth))
60 (print-unreadable-object (host stream :type t)))
61
62 (defstruct (logical-host
63 (:include host
64 (:parse #'parse-logical-namestring)
65 (:unparse #'unparse-logical-namestring)
66 (:unparse-host
67 #'(lambda (x) (logical-host-name (%pathname-host x))))
68 (:unparse-directory #'unparse-logical-directory)
69 (:unparse-file #'unparse-unix-file)
70 (:unparse-enough #'unparse-enough-namestring)
71 (:customary-case :upper))
72 (:make-load-form-fun make-logical-host-load-form-fun))
73 (name "" :type simple-base-string)
74 (translations nil :type list)
75 (canon-transls nil :type list))
76
77 (defun make-logical-host-load-form-fun (logical-host)
78 (values `(find-logical-host ',(logical-host-name logical-host))
79 nil))
80
81 ;;; The various magic tokens that are allowed to appear in pretty much all
82 ;;; pathname components.
83 ;;;
84 (deftype component-tokens ()
85 '(member nil :unspecific :wild))
86
87 ;;;; Pathname structures
88
89 (defstruct (pathname
90 (:conc-name %pathname-)
91 (:print-function %print-pathname)
92 (:constructor
93 %make-pathname (host device directory name type version))
94 (:predicate pathnamep)
95 (:make-load-form-fun :just-dump-it-normally))
96 ;; Slot holds the host, at present either a UNIX or logical host.
97 (host nil :type (or host null))
98 ;; Device is the name of a logical or physical device holding files.
99 (device nil :type (or simple-string component-tokens))
100 ;; A list of strings that are the component subdirectory components.
101 (directory nil :type list)
102 ;; The filename.
103 (name nil :type (or simple-string pattern component-tokens))
104 ;; The type extension of the file.
105 (type nil :type (or simple-string pattern component-tokens))
106 ;; The version number of the file, a positive integer, but not supported
107 ;; on standard UNIX filesystems.
108 (version nil :type (or integer component-tokens (member :newest))))
109
110 ;;; %PRINT-PATHNAME -- Internal
111 ;;;
112 ;;; The printed representation of the pathname structure.
113 ;;;
114 (defun %print-pathname (pathname stream depth)
115 (declare (ignore depth))
116 (let ((namestring (handler-case (namestring pathname)
117 (error nil))))
118 (cond (namestring
119 (if (or *print-escape* *print-readably*)
120 (format stream "#p~S" namestring)
121 (format stream "~A" namestring)))
122 (*print-readably*
123 (error "~S Cannot be printed readably." pathname))
124 (t
125 (funcall (formatter "#<Unprintable pathname, Host=~S, Device=~S, ~
126 Directory=~S, Name=~S, Type=~S, Version=~S>")
127 stream
128 (%pathname-host pathname)
129 (%pathname-device pathname)
130 (%pathname-directory pathname)
131 (%pathname-name pathname)
132 (%pathname-type pathname)
133 (%pathname-version pathname))))))
134
135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 ;;;
137 ;;; Logical pathnames have the following format:
138 ;;;
139 ;;; logical-namestring ::=
140 ;;; [host ":"] [";"] {directory ";"}* [name] ["." type ["." version]]
141 ;;;
142 ;;; host ::= word
143 ;;; directory ::= word | wildcard-word | **
144 ;;; name ::= word | wildcard-word
145 ;;; type ::= word | wildcard-word
146 ;;; version ::= pos-int | newest | NEWEST | *
147 ;;; word ::= {uppercase-letter | digit | -}+
148 ;;; wildcard-word ::= [word] '* {word '*}* [word]
149 ;;; pos-int ::= integer > 0
150 ;;;
151 ;;; Physical pathnames include all these slots and a device slot.
152 ;;;
153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
154
155 ;; Logical pathnames are a subclass of pathname, their class relations are
156 ;; mimiced using structures for efficency.
157
158 (defstruct (logical-pathname
159 (:conc-name %logical-pathname-)
160 (:print-function %print-logical-pathname)
161 (:include pathname)
162 (:constructor %make-logical-pathname
163 (host device directory name type version))
164 (:make-load-form-fun :just-dump-it-normally)))
165
166 (declaim (freeze-type logical-pathname logical-host))
167
168 ;;; %PRINT-LOGICAL-PATHNAME -- Internal
169 ;;;
170 ;;; The printed representation of the logical-pathname structure.
171 ;;; The potential conflict with search-lists requires isolating the printed
172 ;;; representation to use the i/o macro #.(logical-pathname <path-designator>).
173 ;;;
174 (defun %print-logical-pathname (pathname stream depth)
175 (declare (ignore depth))
176 (let ((namestring (handler-case (namestring pathname)
177 (error nil))))
178 (cond (namestring
179 (if (or *print-escape* *print-readably*)
180 (format stream "#.(logical-pathname ~S)" namestring)
181 (format stream "~A" namestring)))
182 (*print-readably*
183 (error "~S Cannot be printed readably." pathname))
184 (t
185 (funcall (formatter "#<Unprintable pathname, Host=~S, ~
186 Directory=~S, File=~S, Name=~S, Version=~S>")
187 stream
188 (%pathname-host pathname)
189 (%pathname-directory pathname)
190 (%pathname-name pathname)
191 (%pathname-type pathname)
192 (%pathname-version pathname))))))
193
194 ;;; %MAKE-PATHNAME-OBJECT -- internal
195 ;;;
196 ;;; A pathname is logical if the host component is a logical-host.
197 ;;; This constructor is used to make an instance of the correct type
198 ;;; from parsed arguments.
199
200 (defun %make-pathname-object (host device directory name type version)
201 (if (typep host 'logical-host)
202 (%make-logical-pathname host :unspecific directory name type version)
203 (%make-pathname host device directory name type version)))
204
205 ;;; *LOGICAL-HOSTS* --internal.
206 ;;;
207 ;;; Hash table searching maps a logical-pathname's host to their physical
208 ;;; pathname translation.
209
210 (defvar *logical-hosts* (make-hash-table :test #'equal))
211
212 ;;; PATH-DESIGNATOR -- internal type
213 ;;;
214 (deftype path-designator ()
215 "A path specification, either a string, stream or pathname."
216 '(or string stream pathname))
217
218
219 ;;;; Patterns
220
221 ;;; Patterns are a list of entries and wildcards used for pattern matches
222 ;;; of translations.
223
224 (defstruct (pattern
225 (:print-function %print-pattern)
226 (:make-load-form-fun :just-dump-it-normally)
227 (:constructor make-pattern (pieces)))
228 (pieces nil :type list))
229
230 ;;; %PRINT-PATTERN -- Internal
231 ;;;
232 (defun %print-pattern (pattern stream depth)
233 (declare (ignore depth))
234 (print-unreadable-object (pattern stream :type t)
235 (if *print-pretty*
236 (let ((*print-escape* t))
237 (pprint-fill stream (pattern-pieces pattern) nil))
238 (prin1 (pattern-pieces pattern) stream))))
239
240 ;;; PATTERN= -- Internal
241 ;;;
242 (defun pattern= (pattern1 pattern2)
243 (declare (type pattern pattern1 pattern2))
244 (let ((pieces1 (pattern-pieces pattern1))
245 (pieces2 (pattern-pieces pattern2)))
246 (and (= (length pieces1) (length pieces2))
247 (every #'(lambda (piece1 piece2)
248 (typecase piece1
249 (simple-string
250 (and (simple-string-p piece2)
251 (string= piece1 piece2)))
252 (cons
253 (and (consp piece2)
254 (eq (car piece1) (car piece2))
255 (string= (cdr piece1) (cdr piece2))))
256 (t
257 (eq piece1 piece2))))
258 pieces1
259 pieces2))))
260
261 ;;; PATTERN-MATCHES -- Internal
262 ;;;
263 ;;; If the string matches the pattern returns the multiple values T and a
264 ;;; list of the matched strings.
265 ;;;
266 (defun pattern-matches (pattern string)
267 (declare (type pattern pattern)
268 (type simple-string string))
269 (let ((len (length string)))
270 (labels ((maybe-prepend (subs cur-sub chars)
271 (if cur-sub
272 (let* ((len (length chars))
273 (new (make-string len))
274 (index len))
275 (dolist (char chars)
276 (setf (schar new (decf index)) char))
277 (cons new subs))
278 subs))
279 (matches (pieces start subs cur-sub chars)
280 (if (null pieces)
281 (if (= start len)
282 (values t (maybe-prepend subs cur-sub chars))
283 (values nil nil))
284 (let ((piece (car pieces)))
285 (etypecase piece
286 (simple-string
287 (let ((end (+ start (length piece))))
288 (and (<= end len)
289 (string= piece string
290 :start2 start :end2 end)
291 (matches (cdr pieces) end
292 (maybe-prepend subs cur-sub chars)
293 nil nil))))
294 (list
295 (ecase (car piece)
296 (:character-set
297 (and (< start len)
298 (let ((char (schar string start)))
299 (if (find char (cdr piece) :test #'char=)
300 (matches (cdr pieces) (1+ start) subs t
301 (cons char chars))))))))
302 ((member :single-char-wild)
303 (and (< start len)
304 (matches (cdr pieces) (1+ start) subs t
305 (cons (schar string start) chars))))
306 ((member :multi-char-wild)
307 (multiple-value-bind
308 (won new-subs)
309 (matches (cdr pieces) start subs t chars)
310 (if won
311 (values t new-subs)
312 (and (< start len)
313 (matches pieces (1+ start) subs t
314 (cons (schar string start)
315 chars)))))))))))
316 (multiple-value-bind
317 (won subs)
318 (matches (pattern-pieces pattern) 0 nil nil nil)
319 (values won (reverse subs))))))
320
321
322 ;;; DIRECTORY-COMPONENTS-MATCH -- Internal
323 ;;;
324 ;;; Pathname-match-p for directory components. If thing is empty
325 ;;; then it matches :wild, (:absolute :wild-inferiors), or (:relative
326 ;;; :wild-inferiors).
327 ;;;
328 (defun directory-components-match (thing wild)
329 (or (eq thing wild)
330 (eq wild :wild)
331 (and (consp wild)
332 (let ((wild1 (first wild)))
333 (cond ((and (null thing) (member wild1 '(:absolute :relative)))
334 (equal (rest wild) '(:wild-inferiors)))
335 ((eq wild1 :wild-inferiors)
336 (let ((wild-subdirs (rest wild)))
337 (or (null wild-subdirs)
338 (loop
339 (when (directory-components-match thing
340 wild-subdirs)
341 (return t))
342 (pop thing)
343 (unless thing (return nil))))))
344 ((consp thing)
345 (and (components-match (first thing) wild1)
346 (directory-components-match (rest thing)
347 (rest wild)))))))))
348
349
350 ;;; COMPONENTS-MATCH -- Internal
351 ;;;
352 ;;; Return true if pathname component Thing is matched by Wild. Not
353 ;;; commutative.
354 ;;;
355 (defun components-match (thing wild)
356 (declare (type (or pattern symbol simple-string integer) thing wild))
357 (or (eq thing wild)
358 (eq wild :wild)
359 (typecase thing
360 (simple-base-string
361 ;; String is matched by itself, a matching pattern or :WILD.
362 (typecase wild
363 (pattern
364 (values (pattern-matches wild thing)))
365 (simple-base-string
366 (string= thing wild))))
367 (pattern
368 ;; A pattern is only matched by an identical pattern.
369 (and (pattern-p wild) (pattern= thing wild)))
370 (integer
371 ;; an integer (version number) is matched by :WILD or the same
372 ;; integer. This branch will actually always be NIL as long is the
373 ;; version is a fixnum.
374 (eql thing wild)))))
375
376
377 ;;; COMPARE-COMPONENT -- Internal
378 ;;;
379 ;;; A predicate for comparing two pathname slot component sub-entries.
380 ;;;
381 (defun compare-component (this that)
382 (or (eql this that)
383 (typecase this
384 (simple-string
385 (and (simple-string-p that)
386 (string= this that)))
387 (pattern
388 (and (pattern-p that)
389 (pattern= this that)))
390 (cons
391 (and (consp that)
392 (compare-component (car this) (car that))
393 (compare-component (cdr this) (cdr that)))))))
394
395
396 ;;;; Pathname functions.
397
398 ;;; Implementation determined defaults to pathname slots.
399
400 (defvar *default-pathname-defaults*)
401
402 ;;; PATHNAME= -- Internal
403 ;;;
404 (defun pathname= (pathname1 pathname2)
405 (declare (type pathname pathname1)
406 (type pathname pathname2))
407 (and (eq (%pathname-host pathname1)
408 (%pathname-host pathname2))
409 (compare-component (%pathname-device pathname1)
410 (%pathname-device pathname2))
411 (compare-component (%pathname-directory pathname1)
412 (%pathname-directory pathname2))
413 (compare-component (%pathname-name pathname1)
414 (%pathname-name pathname2))
415 (compare-component (%pathname-type pathname1)
416 (%pathname-type pathname2))
417 (compare-component (%pathname-version pathname1)
418 (%pathname-version pathname2))))
419
420 ;;; WITH-PATHNAME -- Internal
421 ;;; Converts the expr, a pathname designator (a pathname, or string, or
422 ;;; stream), into a pathname.
423 ;;;
424 (defmacro with-pathname ((var expr) &body body)
425 `(let ((,var (let ((,var ,expr))
426 (etypecase ,var
427 (pathname ,var)
428 (string (parse-namestring ,var))
429 (file-stream (file-name ,var))))))
430 ,@body))
431
432 ;;; WITH-HOST -- Internal
433 ;;;
434 ;;; Converts the var, a host or string name for a host, into a logical-host
435 ;;; structure or nil if not defined.
436 ;;;
437 ;;; pw notes 1/12/97 this potentially useful macro is not used anywhere
438 ;;; and 'find-host' is not defined. 'find-logical-host' seems to be needed.
439 ;;;
440 (defmacro with-host ((var expr) &body body)
441 `(let ((,var (let ((,var ,expr))
442 (typecase ,var
443 (logical-host ,var)
444 (string (find-logical-host ,var nil))
445 (t nil)))))
446 ,@body))
447
448 ;;; PATHNAME -- Interface
449 ;;;
450 (defun pathname (thing)
451 "Convert thing (a pathname, string or stream) into a pathname."
452 (declare (type path-designator thing))
453 (with-pathname (pathname thing)
454 pathname))
455
456 ;;; MAYBE-DIDDLE-CASE -- Internal
457 ;;;
458 ;;; Change the case of thing if diddle-p T.
459 ;;;
460 (defun maybe-diddle-case (thing diddle-p)
461 (if (and diddle-p (not (or (symbolp thing) (integerp thing))))
462 (labels ((check-for (pred in)
463 (typecase in
464 (pattern
465 (dolist (piece (pattern-pieces in))
466 (when (typecase piece
467 (simple-string
468 (check-for pred piece))
469 (cons
470 (case (car in)
471 (:character-set
472 (check-for pred (cdr in))))))
473 (return t))))
474 (list
475 (dolist (x in)
476 (when (check-for pred x)
477 (return t))))
478 (simple-base-string
479 (dotimes (i (length in))
480 (when (funcall pred (schar in i))
481 (return t))))
482 (t nil)))
483 (diddle-with (fun thing)
484 (typecase thing
485 (pattern
486 (make-pattern
487 (mapcar #'(lambda (piece)
488 (typecase piece
489 (simple-base-string
490 (funcall fun piece))
491 (cons
492 (case (car piece)
493 (:character-set
494 (cons :character-set
495 (funcall fun (cdr piece))))
496 (t
497 piece)))
498 (t
499 piece)))
500 (pattern-pieces thing))))
501 (list
502 (mapcar fun thing))
503 (simple-base-string
504 (funcall fun thing))
505 (t
506 thing))))
507 (let ((any-uppers (check-for #'upper-case-p thing))
508 (any-lowers (check-for #'lower-case-p thing)))
509 (cond ((and any-uppers any-lowers)
510 ;; Mixed case, stays the same.
511 thing)
512 (any-uppers
513 ;; All uppercase, becomes all lower case.
514 (diddle-with #'(lambda (x) (if (stringp x)
515 (string-downcase x)
516 x)) thing))
517 (any-lowers
518 ;; All lowercase, becomes all upper case.
519 (diddle-with #'(lambda (x) (if (stringp x)
520 (string-upcase x)
521 x)) thing))
522 (t
523 ;; No letters? I guess just leave it.
524 thing))))
525 thing))
526
527
528 ;;; MERGE-DIRECTORIES -- Internal
529 ;;;
530 (defun merge-directories (dir1 dir2 diddle-case)
531 (if (or (eq (car dir1) :absolute)
532 (null dir2))
533 dir1
534 (let ((results nil))
535 (flet ((add (dir)
536 (if (and (eq dir :back)
537 results
538 (not (eq (car results) :back)))
539 (pop results)
540 (push dir results))))
541 (dolist (dir (maybe-diddle-case dir2 diddle-case))
542 (add dir))
543 (dolist (dir (cdr dir1))
544 (add dir)))
545 (reverse results))))
546
547 ;;; MERGE-PATHNAMES -- Interface
548 ;;;
549 (defun merge-pathnames (pathname
550 &optional
551 (defaults *default-pathname-defaults*)
552 (default-version :newest))
553 "Construct a filled in pathname by completing the unspecified components
554 from the defaults."
555 (declare (type path-designator pathname)
556 (type path-designator defaults)
557 (values pathname))
558 (with-pathname (defaults defaults)
559 (let ((pathname (let ((*default-pathname-defaults* defaults))
560 (pathname pathname))))
561 (let* ((default-host (%pathname-host defaults))
562 (pathname-host (%pathname-host pathname))
563 (diddle-case
564 (and default-host pathname-host
565 (not (eq (host-customary-case default-host)
566 (host-customary-case pathname-host))))))
567 (%make-pathname-object
568 (or pathname-host default-host)
569 (or (%pathname-device pathname)
570 (maybe-diddle-case (%pathname-device defaults)
571 diddle-case))
572 (merge-directories (%pathname-directory pathname)
573 (%pathname-directory defaults)
574 diddle-case)
575 (or (%pathname-name pathname)
576 (maybe-diddle-case (%pathname-name defaults)
577 diddle-case))
578 (or (%pathname-type pathname)
579 (maybe-diddle-case (%pathname-type defaults)
580 diddle-case))
581 (or (if (null (%pathname-name pathname))
582 (or (%pathname-version pathname)
583 (%pathname-version defaults))
584 (%pathname-version pathname))
585 default-version))))))
586
587 ;;; IMPORT-DIRECTORY -- Internal
588 ;;;
589 (defun import-directory (directory diddle-case)
590 (etypecase directory
591 (null nil)
592 ((member :wild) '(:absolute :wild-inferiors))
593 ((member :unspecific) '(:relative))
594 (list
595 (collect ((results))
596 (ecase (pop directory)
597 (:absolute
598 (results :absolute)
599 (when (search-list-p (car directory))
600 (results (pop directory))))
601 (:relative
602 (results :relative)))
603 (dolist (piece directory)
604 (cond ((member piece '(:wild :wild-inferiors :up :back))
605 (results piece))
606 ((or (simple-string-p piece) (pattern-p piece))
607 (results (maybe-diddle-case piece diddle-case)))
608 ((stringp piece)
609 (results (maybe-diddle-case (coerce piece 'simple-string)
610 diddle-case)))
611 (t
612 (error "~S is not allowed as a directory component." piece))))
613 (results)))
614 (simple-string
615 `(:absolute
616 ,(maybe-diddle-case directory diddle-case)))
617 (string
618 `(:absolute
619 ,(maybe-diddle-case (coerce directory 'simple-string)
620 diddle-case)))))
621
622 ;;; MAKE-PATHNAME -- Interface
623 ;;;
624 (defun make-pathname (&key host
625 (device nil devp)
626 (directory nil dirp)
627 (name nil namep)
628 (type nil typep)
629 (version nil versionp)
630 defaults
631 (case :local))
632 "Makes a new pathname from the component arguments. Note that host is
633 a host-structure or string."
634 (declare (type (or string host component-tokens) host)
635 (type (or string component-tokens) device)
636 (type (or list string pattern component-tokens) directory)
637 (type (or string pattern component-tokens) name type)
638 (type (or integer component-tokens (member :newest)) version)
639 (type (or path-designator null) defaults)
640 (type (member :common :local) case))
641 (let* ((defaults (when defaults
642 (with-pathname (defaults defaults) defaults)))
643 (default-host (if defaults
644 (%pathname-host defaults)
645 (%pathname-host *default-pathname-defaults*)))
646 ;; toy@rtp.ericsson.se: CLHS says make-pathname can take a
647 ;; string (as a logical-host) for the host part. We map that
648 ;; string into the corresponding logical host structure.
649
650 ;; pw@snoopy.mv.com:
651 ;; HyperSpec says for the arg to MAKE-PATHNAME;
652 ;; "host---a valid physical pathname host. ..."
653 ;; where it probably means -- a valid pathname host.
654 ;; "valid pathname host n. a valid physical pathname host or
655 ;; a valid logical pathname host."
656 ;; and defines
657 ;; "valid physical pathname host n. any of a string,
658 ;; a list of strings, or the symbol :unspecific,
659 ;; that is recognized by the implementation as the name of a host."
660 ;; "valid logical pathname host n. a string that has been defined
661 ;; as the name of a logical host. ..."
662 ;; HS is silent on what happens if the :host arg is NOT one of these.
663 ;; It seems an error message is appropriate.
664 (host (typecase host
665 (host host) ; A valid host, use it.
666 ((string 0) default-host) ; "" cannot be a logical host
667 (string (find-logical-host host t)) ; logical-host or lose.
668 (t default-host))) ; unix-host
669 (diddle-args (and (eq (host-customary-case host) :lower)
670 (eq case :common)))
671 (diddle-defaults
672 (not (eq (host-customary-case host)
673 (host-customary-case default-host))))
674 (dev (if devp device (if defaults (%pathname-device defaults))))
675 (dir (import-directory directory diddle-args))
676 (ver (cond
677 (versionp version)
678 (defaults (%pathname-version defaults))
679 (t nil))))
680 (when (and defaults (not dirp))
681 (setf dir
682 (merge-directories dir
683 (%pathname-directory defaults)
684 diddle-defaults)))
685
686 ;; A bit of sanity checking on user arguments.
687 (flet ((check-component-validity (name name-or-type)
688 (when (stringp name)
689 (let ((unix-directory-separator #\/))
690 (when (eq host (%pathname-host *default-pathname-defaults*))
691 (when (find unix-directory-separator name)
692 (warn "Silly argument for a unix ~A: ~S"
693 name-or-type name)))))))
694 (check-component-validity name :pathname-name)
695 (check-component-validity type :pathname-type))
696
697 (macrolet ((pick (var varp field)
698 `(cond ((or (simple-string-p ,var)
699 (pattern-p ,var))
700 (maybe-diddle-case ,var diddle-args))
701 ((stringp ,var)
702 (maybe-diddle-case (coerce ,var 'simple-string)
703 diddle-args))
704 (,varp
705 (maybe-diddle-case ,var diddle-args))
706 (defaults
707 (maybe-diddle-case (,field defaults)
708 diddle-defaults))
709 (t
710 nil))))
711 (%make-pathname-object host
712 dev ; forced to :unspecific when logical-host
713 dir
714 (pick name namep %pathname-name)
715 (pick type typep %pathname-type)
716 ver))))
717
718 ;;; PATHNAME-HOST -- Interface
719 ;;;
720 (defun pathname-host (pathname &key (case :local))
721 "Accessor for the pathname's host."
722 (declare (type path-designator pathname)
723 (type (member :local :common) case)
724 (values (or string null))
725 (ignore case))
726 (host-namestring pathname))
727
728 ;;; PATHNAME-DEVICE -- Interface
729 ;;;
730 (defun pathname-device (pathname &key (case :local))
731 "Accessor for pathname's device."
732 (declare (type path-designator pathname)
733 (type (member :local :common) case))
734 (with-pathname (pathname pathname)
735 (maybe-diddle-case (%pathname-device pathname)
736 (and (eq case :common)
737 (eq (host-customary-case
738 (%pathname-host pathname))
739 :lower)))))
740
741 ;;; PATHNAME-DIRECTORY -- Interface
742 ;;;
743 (defun pathname-directory (pathname &key (case :local))
744 "Accessor for the pathname's directory list."
745 (declare (type path-designator pathname)
746 (type (member :local :common) case))
747 (with-pathname (pathname pathname)
748 (maybe-diddle-case (%pathname-directory pathname)
749 (and (eq case :common)
750 (eq (host-customary-case
751 (%pathname-host pathname))
752 :lower)))))
753 ;;; PATHNAME-NAME -- Interface
754 ;;;
755 (defun pathname-name (pathname &key (case :local))
756 "Accessor for the pathname's name."
757 (declare (type path-designator pathname)
758 (type (member :local :common) case))
759 (with-pathname (pathname pathname)
760 (maybe-diddle-case (%pathname-name pathname)
761 (and (eq case :common)
762 (eq (host-customary-case
763 (%pathname-host pathname))
764 :lower)))))
765
766 ;;; PATHNAME-TYPE
767 ;;;
768 (defun pathname-type (pathname &key (case :local))
769 "Accessor for the pathname's name."
770 (declare (type path-designator pathname)
771 (type (member :local :common) case))
772 (with-pathname (pathname pathname)
773 (maybe-diddle-case (%pathname-type pathname)
774 (and (eq case :common)
775 (eq (host-customary-case
776 (%pathname-host pathname))
777 :lower)))))
778
779 ;;; PATHNAME-VERSION
780 ;;;
781 (defun pathname-version (pathname)
782 "Accessor for the pathname's version."
783 (declare (type path-designator pathname))
784 (with-pathname (pathname pathname)
785 (%pathname-version pathname)))
786
787
788 ;;;; Namestrings
789
790 ;;; %PRINT-NAMESTRING-PARSE-ERROR -- Internal
791 ;;;
792 (defun %print-namestring-parse-error (condition stream)
793 (format stream "Parse error in namestring: ~?~% ~A~% ~V@T^"
794 (namestring-parse-error-complaint condition)
795 (namestring-parse-error-arguments condition)
796 (namestring-parse-error-namestring condition)
797 (namestring-parse-error-offset condition)))
798
799 (define-condition namestring-parse-error (parse-error)
800 ((complaint :reader namestring-parse-error-complaint :initarg :complaint)
801 (arguments :reader namestring-parse-error-arguments :initarg :arguments
802 :initform nil)
803 (namestring :reader namestring-parse-error-namestring :initarg :namestring)
804 (offset :reader namestring-parse-error-offset :initarg :offset))
805 (:report %print-namestring-parse-error))
806
807
808 ;;; %PARSE-NAMESTRING -- Internal
809 ;;;
810 ;;; Handle the case where parse-namestring is actually parsing a namestring.
811 ;;; We pick off the :JUNK-ALLOWED case then find a host to use for parsing,
812 ;;; call the parser, then check if the host matches.
813 ;;;
814 (defun %parse-namestring (namestr host defaults start end junk-allowed)
815 (declare (type string namestr)
816 (type (or host string null) host)
817 (type pathname defaults)
818 (type index start)
819 (type (or index null) end))
820 (if junk-allowed
821 (handler-case
822 (%parse-namestring namestr host defaults start end nil)
823 (namestring-parse-error (condition)
824 (values nil (namestring-parse-error-offset condition))))
825 (let* ((end (or end (length namestr)))
826 (host (if (and host (stringp host))
827 (find-logical-host host)
828 host))
829 (default-host (%pathname-host defaults))
830 (parse-host (or host
831 (extract-logical-host-prefix namestr start end)
832 default-host)))
833 (unless parse-host
834 (error "When Host arg is not supplied, Defaults arg must ~
835 have a non-null PATHNAME-HOST."))
836
837 (multiple-value-bind
838 (new-host device directory file type version)
839 (funcall (host-parse parse-host) namestr start end)
840 (when (and host new-host (not (eq new-host host)))
841 (error "Host in namestring: ~S~@
842 does not match explicit host argument: ~S"
843 namestr host))
844 (let ((pn-host (or new-host parse-host)))
845 (values (%make-pathname-object
846 pn-host device directory file type version)
847 end))))))
848
849
850 ;;; EXTRACT-LOGICAL-HOST-PREFIX -- Internal
851 ;;;
852 ;;; If namestr begins with a colon-terminated, defined, logical host, then
853 ;;; return that host, otherwise return NIL.
854 ;;;
855 (defun extract-logical-host-prefix (namestr start end)
856 (declare (type simple-base-string namestr)
857 (type index start end)
858 (values (or logical-host null)))
859 (let ((colon-pos (position #\: namestr :start start :end end)))
860 (if colon-pos
861 (find-logical-host (nstring-upcase (subseq namestr start colon-pos))
862 nil)
863 nil)))
864
865 ;;; PARSE-NAMESTRING -- Interface
866 ;;;
867 (defun parse-namestring (thing
868 &optional host (defaults *default-pathname-defaults*)
869 &key (start 0) end junk-allowed)
870 "Converts pathname, a pathname designator, into a pathname structure,
871 for a physical pathname, returns the printed representation. Host may be
872 a physical host structure or host namestring."
873 (declare (type path-designator thing)
874 (type (or list string host (member :unspecific)) host)
875 (type pathname defaults)
876 (type index start)
877 (type (or index null) end))
878 ;; Generally, redundant specification of information in software,
879 ;; whether in code or in comments, is bad. However, the ANSI spec
880 ;; for this is messy enough that it's hard to hold in short-term
881 ;; memory, so I've recorded these redundant notes on the
882 ;; implications of the ANSI spec.
883 ;;
884 ;; According to the ANSI spec, HOST can be a valid pathname host, or
885 ;; a logical host, or NIL.
886 ;;
887 ;; A valid pathname host can be a valid physical pathname host or a
888 ;; valid logical pathname host.
889 ;;
890 ;; A valid physical pathname host is "any of a string, a list of
891 ;; strings, or the symbol :UNSPECIFIC, that is recognized by the
892 ;; implementation as the name of a host". In SBCL as of 0.6.9.8,
893 ;; that means :UNSPECIFIC: though someday we might want to
894 ;; generalize it to allow strings like "RTFM.MIT.EDU" or lists like
895 ;; '("RTFM" "MIT" "EDU"), that's not supported now.
896 ;;
897 ;; A valid logical pathname host is a string which has been defined as
898 ;; the name of a logical host, as with LOAD-LOGICAL-PATHNAME-TRANSLATIONS.
899 ;;
900 (let ((host (etypecase host
901 ((string 0)
902 ;; This is a special host. It's not valid as a
903 ;; logical host, so it is a sensible thing to
904 ;; designate the physical Unix host object. So
905 ;; we do that.
906 *unix-host*)
907 (string
908 ;; In general ANSI-compliant Common Lisps, a
909 ;; string might also be a physical pathname host,
910 ;; but ANSI leaves this up to the implementor,
911 ;; and in CMUCL we don't do it, so it must be a
912 ;; logical host.
913 (find-logical-host host))
914 ((or null (member :unspecific))
915 ;; CLHS says that HOST=:UNSPECIFIC has
916 ;; implementation-defined behavior. We
917 ;; just turn it into NIL.
918 nil)
919 (list
920 ;; ANSI also allows LISTs to designate hosts,
921 ;; but leaves its interpretation
922 ;; implementation-defined. Our interpretation
923 ;; is that it's unsupported.:-|
924 (error "A LIST representing a pathname host is not ~
925 supported in this implementation:~% ~S"
926 host))
927 (host
928 host))))
929 (declare (type (or null host) host))
930 (etypecase thing
931 (simple-string
932 (%parse-namestring thing host defaults start end junk-allowed))
933 (string
934 (%parse-namestring (coerce thing 'simple-string)
935 host defaults start end junk-allowed))
936 (pathname
937 (let ((host (if host host (%pathname-host defaults))))
938 (unless (eq host (%pathname-host thing))
939 (error "Hosts do not match: ~S and ~S."
940 host (%pathname-host thing))))
941 (values thing start))
942 (stream
943 (let ((name (file-name thing)))
944 (unless name
945 (error "Can't figure out the file associated with stream:~% ~S"
946 thing))
947 (values name nil))))))
948
949
950 ;;; NAMESTRING -- Interface
951 ;;;
952 (defun namestring (pathname)
953 "Construct the full (name)string form of the pathname."
954 (declare (type path-designator pathname)
955 (values (or null simple-base-string)))
956 (with-pathname (pathname pathname)
957 (when pathname
958 (let ((host (%pathname-host pathname)))
959 (unless host
960 (error "Cannot determine the namestring for pathnames with no ~
961 host:~% ~S" pathname))
962 (funcall (host-unparse host) pathname)))))
963
964
965 ;;; HOST-NAMESTRING -- Interface
966 ;;;
967 (defun host-namestring (pathname)
968 "Returns a string representation of the name of the host in the pathname."
969 (declare (type path-designator pathname)
970 (values (or null simple-base-string)))
971 (with-pathname (pathname pathname)
972 (let ((host (%pathname-host pathname)))
973 (if host
974 (funcall (host-unparse-host host) pathname)
975 (error
976 "Cannot determine the namestring for pathnames with no host:~% ~S"
977 pathname)))))
978
979 ;;; DIRECTORY-NAMESTRING -- Interface
980 ;;;
981 (defun directory-namestring (pathname)
982 "Returns a string representation of the directories used in the pathname."
983 (declare (type path-designator pathname)
984 (values (or null simple-base-string)))
985 (with-pathname (pathname pathname)
986 (let ((host (%pathname-host pathname)))
987 (if host
988 (funcall (host-unparse-directory host) pathname)
989 (error
990 "Cannot determine the namestring for pathnames with no host:~% ~S"
991 pathname)))))
992
993 ;;; FILE-NAMESTRING -- Interface
994 ;;;
995 (defun file-namestring (pathname)
996 "Returns a string representation of the name used in the pathname."
997 (declare (type path-designator pathname)
998 (values (or null simple-base-string)))
999 (with-pathname (pathname pathname)
1000 (let ((host (%pathname-host pathname)))
1001 (if host
1002 (funcall (host-unparse-file host) pathname)
1003 (error
1004 "Cannot determine the namestring for pathnames with no host:~% ~S"
1005 pathname)))))
1006
1007 ;;; ENOUGH-NAMESTRING -- Interface
1008 ;;;
1009 (defun enough-namestring (pathname
1010 &optional (defaults *default-pathname-defaults*))
1011 "Returns an abbreviated pathname sufficent to identify the pathname relative
1012 to the defaults."
1013 (declare (type path-designator pathname))
1014 (with-pathname (pathname pathname)
1015 (let ((host (%pathname-host pathname)))
1016 (if host
1017 (with-pathname (defaults defaults)
1018 (funcall (host-unparse-enough host) pathname defaults))
1019 (error
1020 "Cannot determine the namestring for pathnames with no host:~% ~S"
1021 pathname)))))
1022
1023
1024 ;;;; Wild pathnames.
1025
1026 ;;; WILD-PATHNAME-P -- Interface
1027 ;;;
1028 (defun wild-pathname-p (pathname &optional field-key)
1029 "Predicate for determining whether pathname contains any wildcards."
1030 (declare (type path-designator pathname)
1031 (type (member nil :host :device :directory :name :type :version)
1032 field-key))
1033 (with-pathname (pathname pathname)
1034 (flet ((frob (x)
1035 (or (pattern-p x) (member x '(:wild :wild-inferiors)))))
1036 (ecase field-key
1037 ((nil)
1038 (or (wild-pathname-p pathname :host)
1039 (wild-pathname-p pathname :device)
1040 (wild-pathname-p pathname :directory)
1041 (wild-pathname-p pathname :name)
1042 (wild-pathname-p pathname :type)
1043 (wild-pathname-p pathname :version)))
1044 (:host (frob (%pathname-host pathname)))
1045 (:device (frob (%pathname-device pathname)))
1046 (:directory (some #'frob (%pathname-directory pathname)))
1047 (:name (frob (%pathname-name pathname)))
1048 (:type (frob (%pathname-type pathname)))
1049 (:version (frob (%pathname-version pathname)))))))
1050
1051
1052 ;;; PATHNAME-MATCH-P -- Interface
1053 ;;;
1054 (defun pathname-match-p (in-pathname in-wildname)
1055 "Pathname matches the wildname template?"
1056 (declare (type path-designator in-pathname))
1057 (with-pathname (pathname in-pathname)
1058 (with-pathname (wildname in-wildname)
1059 (macrolet ((frob (field &optional (op 'components-match ))
1060 `(or (null (,field wildname))
1061 (,op (,field pathname) (,field wildname)))))
1062 (and (or (null (%pathname-host wildname))
1063 (eq (%pathname-host wildname) (%pathname-host pathname)))
1064 (frob %pathname-device)
1065 (frob %pathname-directory directory-components-match)
1066 (frob %pathname-name)
1067 (frob %pathname-type)
1068 (frob %pathname-version))))))
1069
1070
1071 ;;; SUBSTITUTE-INTO -- Internal
1072 ;;;
1073 ;;; Place the substitutions into the pattern and return the string or pattern
1074 ;;; that results. If DIDDLE-CASE is true, we diddle the result case as well,
1075 ;;; in case we are translating between hosts with difference conventional case.
1076 ;;; The second value is the tail of subs with all of the values that we used up
1077 ;;; stripped off. Note that PATTERN-MATCHES matches all consecutive wildcards
1078 ;;; as a single string, so we ignore subsequent contiguous wildcards.
1079 ;;;
1080 (defun substitute-into (pattern subs diddle-case)
1081 (declare (type pattern pattern)
1082 (type list subs)
1083 (values (or simple-base-string pattern) list))
1084 (let ((in-wildcard nil)
1085 (pieces nil)
1086 (strings nil))
1087 (dolist (piece (pattern-pieces pattern))
1088 (cond ((simple-string-p piece)
1089 (push piece strings)
1090 (setf in-wildcard nil))
1091 (in-wildcard)
1092 (t
1093 (setf in-wildcard t)
1094 (unless subs
1095 (error "Not enough wildcards in FROM pattern to match ~
1096 TO pattern:~% ~S"
1097 pattern))
1098 (let ((sub (pop subs)))
1099 (typecase sub
1100 (pattern
1101 (when strings
1102 (push (apply #'concatenate 'simple-string
1103 (nreverse strings))
1104 pieces))
1105 (dolist (piece (pattern-pieces sub))
1106 (push piece pieces)))
1107 (simple-string
1108 (push sub strings))
1109 (t
1110 (error "Can't substitute this into the middle of a word:~
1111 ~% ~S"
1112 sub)))))))
1113
1114 (when strings
1115 (push (apply #'concatenate 'simple-string (nreverse strings))
1116 pieces))
1117 (values
1118 (maybe-diddle-case
1119 (if (and pieces (simple-string-p (car pieces)) (null (cdr pieces)))
1120 (car pieces)
1121 (make-pattern (nreverse pieces)))
1122 diddle-case)
1123 subs)))
1124
1125
1126 ;;; DIDNT-MATCH-ERROR -- Internal
1127 ;;;
1128 ;;; Called when we can't see how source and from matched.
1129 ;;;
1130 (defun didnt-match-error (source from)
1131 (error "Pathname components from Source and From args to TRANSLATE-PATHNAME~@
1132 did not match:~% ~S ~S"
1133 source from))
1134
1135
1136 ;;; TRANSLATE-COMPONENT -- Internal
1137 ;;;
1138 ;;; Do TRANSLATE-COMPONENT for all components except host and directory.
1139 ;;;
1140 (defun translate-component (source from to diddle-case)
1141 (typecase to
1142 (pattern
1143 (typecase from
1144 (pattern
1145 (typecase source
1146 (pattern
1147 (if (pattern= from source)
1148 source
1149 (didnt-match-error source from)))
1150 (simple-string
1151 (multiple-value-bind
1152 (won subs)
1153 (pattern-matches from source)
1154 (if won
1155 (values (substitute-into to subs diddle-case))
1156 (didnt-match-error source from))))
1157 (t
1158 (maybe-diddle-case source diddle-case))))
1159 ((member :wild)
1160 (values (substitute-into to (list source) diddle-case)))
1161 (t
1162 (if (components-match source from)
1163 (maybe-diddle-case source diddle-case)
1164 (didnt-match-error source from)))))
1165 ((member nil :wild)
1166 (maybe-diddle-case source diddle-case))
1167 (t
1168 (if (components-match source from)
1169 to
1170 (didnt-match-error source from)))))
1171
1172
1173 ;;; COMPUTE-DIRECTORY-SUBSTITUTIONS -- Internal
1174 ;;;
1175 ;;; Return a list of all the things that we want to substitute into the TO
1176 ;;; pattern (the things matched by from on source.) When From contains
1177 ;;; :WILD-INFERIORS, the result contains a sublist of the matched source
1178 ;;; subdirectories.
1179 ;;;
1180 (defun compute-directory-substitutions (orig-source orig-from)
1181 (let ((source orig-source)
1182 (from orig-from))
1183 (collect ((subs))
1184 (loop
1185 (unless source
1186 (unless (every #'(lambda (x) (eq x :wild-inferiors)) from)
1187 (didnt-match-error orig-source orig-from))
1188 (subs ())
1189 (return))
1190 (unless from (didnt-match-error orig-source orig-from))
1191 (let ((from-part (pop from))
1192 (source-part (pop source)))
1193 (typecase from-part
1194 (pattern
1195 (typecase source-part
1196 (pattern
1197 (if (pattern= from-part source-part)
1198 (subs source-part)
1199 (didnt-match-error orig-source orig-from)))
1200 (simple-string
1201 (multiple-value-bind
1202 (won new-subs)
1203 (pattern-matches from-part source-part)
1204 (if won
1205 (dolist (sub new-subs)
1206 (subs sub))
1207 (didnt-match-error orig-source orig-from))))
1208 (t
1209 (didnt-match-error orig-source orig-from))))
1210 ((member :wild)
1211 (subs source-part))
1212 ((member :wild-inferiors)
1213 (let ((remaining-source (cons source-part source)))
1214 (collect ((res))
1215 (loop
1216 (when (directory-components-match remaining-source from)
1217 (return))
1218 (unless remaining-source
1219 (didnt-match-error orig-source orig-from))
1220 (res (pop remaining-source)))
1221 (subs (res))
1222 (setq source remaining-source))))
1223 (simple-string
1224 (unless (and (simple-string-p source-part)
1225 (string= from-part source-part))
1226 (didnt-match-error orig-source orig-from)))
1227 (t
1228 (didnt-match-error orig-source orig-from)))))
1229 (subs))))
1230
1231
1232 ;;; TRANSLATE-DIRECTORIES -- Internal
1233 ;;;
1234 ;;; Called by TRANSLATE-PATHNAME on the directory components of its argument
1235 ;;; pathanames to produce the result directory component. If any leaves the
1236 ;;; directory NIL, we return the source directory. The :RELATIVE or :ABSOLUTE
1237 ;;; is taken from the source directory, except if TO is :ABSOLUTE, in which
1238 ;;; case the result will be :ABSOLUTE.
1239 ;;;
1240 (defun translate-directories (source from to diddle-case)
1241 (if (not (and source to from))
1242 (let ((source (mapcar #'(lambda (x) (maybe-diddle-case x diddle-case))
1243 source)))
1244 (if (null to)
1245 source
1246 (collect ((res))
1247 (res (cond ((null source) (first to))
1248 ((eq (first to) :absolute) :absolute)
1249 (t (first source))))
1250 (let ((match (rest source)))
1251 (dolist (to-part (rest to))
1252 (cond ((eq to-part :wild)
1253 (when match
1254 (res (first match))
1255 (setf match nil)))
1256 ((eq to-part :wild-inferiors)
1257 (when match
1258 (dolist (src-part match)
1259 (res src-part))
1260 (setf match nil)))
1261 (t
1262 (res to-part)))))
1263 (res))))
1264 (collect ((res))
1265 (res (if (eq (first to) :absolute)
1266 :absolute
1267 (first source)))
1268 (let ((subs-left (compute-directory-substitutions (rest source)
1269 (rest from))))
1270 (dolist (to-part (rest to))
1271 (typecase to-part
1272 ((member :wild)
1273 (assert subs-left)
1274 (let ((match (pop subs-left)))
1275 (when (listp match)
1276 (error ":WILD-INFERIORS not paired in from and to ~
1277 patterns:~% ~S ~S" from to))
1278 (res (maybe-diddle-case match diddle-case))))
1279 ((member :wild-inferiors)
1280 (assert subs-left)
1281 (let ((match (pop subs-left)))
1282 (unless (listp match)
1283 (error ":WILD-INFERIORS not paired in from and to ~
1284 patterns:~% ~S ~S" from to))
1285 (dolist (x match)
1286 (res (maybe-diddle-case x diddle-case)))))
1287 (pattern
1288 (multiple-value-bind
1289 (new new-subs-left)
1290 (substitute-into to-part subs-left diddle-case)
1291 (setf subs-left new-subs-left)
1292 (res new)))
1293 (t (res to-part)))))
1294 (res))))
1295
1296
1297 ;;; TRANSLATE-PATHNAME -- Interface
1298 ;;;
1299 (defun translate-pathname (source from-wildname to-wildname &key)
1300 "Use the source pathname to translate the from-wildname's wild and
1301 unspecified elements into a completed to-pathname based on the to-wildname."
1302 (declare (type path-designator source from-wildname to-wildname))
1303 (with-pathname (source source)
1304 (with-pathname (from from-wildname)
1305 (with-pathname (to to-wildname)
1306 (let* ((source-host (%pathname-host source))
1307 (to-host (%pathname-host to))
1308 (diddle-case
1309 (and source-host to-host
1310 (not (eq (host-customary-case source-host)
1311 (host-customary-case to-host))))))
1312 (macrolet ((frob (field &optional (op 'translate-component))
1313 `(let ((result (,op (,field source)
1314 (,field from)
1315 (,field to)
1316 diddle-case)))
1317 (if (eq result :error)
1318 (error "~S doesn't match ~S" source from)
1319 result))))
1320 (%make-pathname-object
1321 (or to-host source-host)
1322 (frob %pathname-device)
1323 (frob %pathname-directory translate-directories)
1324 (frob %pathname-name)
1325 (frob %pathname-type)
1326 (frob %pathname-version))))))))
1327
1328
1329 ;;;; Search lists.
1330
1331 ;;; The SEARCH-LIST structure.
1332 ;;;
1333 (defstruct (search-list
1334 (:print-function %print-search-list)
1335 (:make-load-form-fun
1336 (lambda (search-list)
1337 (values `(intern-search-list ',(search-list-name search-list))
1338 nil))))
1339 ;;
1340 ;; The name of this search-list. Always stored in lowercase.
1341 (name (required-argument) :type simple-string)
1342 ;;
1343 ;; T if this search-list has been defined. Otherwise NIL.
1344 (defined nil :type (member t nil))
1345 ;;
1346 ;; The list of expansions for this search-list. Each expansion is the list
1347 ;; of directory components to use in place of this search-list.
1348 (expansions nil :type list))
1349
1350 (defun %print-search-list (sl stream depth)
1351 (declare (ignore depth))
1352 (print-unreadable-object (sl stream :type t)
1353 (write-string (search-list-name sl) stream)))
1354
1355 ;;; *SEARCH-LISTS* -- internal.
1356 ;;;
1357 ;;; Hash table mapping search-list names to search-list structures.
1358 ;;;
1359 (defvar *search-lists* (make-hash-table :test #'equal))
1360
1361 ;;; FIND-SEARCH-LIST -- internal
1362 ;;;
1363 (defun find-search-list (name &optional (flame-not-found-p t))
1364 (let ((search-list (gethash (string-downcase name) *search-lists*)))
1365 (if search-list search-list
1366 (when flame-not-found-p
1367 (error "Search-list ~a not defined." name)))))
1368
1369 ;;; INTERN-SEARCH-LIST -- internal interface.
1370 ;;;
1371 ;;; When search-lists are encountered in namestrings, they are converted to
1372 ;;; search-list structures right then, instead of waiting until the search
1373 ;;; list used. This allows us to verify ahead of time that there are no
1374 ;;; circularities and makes expansion much quicker.
1375 ;;;
1376 (defun intern-search-list (name)
1377 (let ((name (string-downcase name)))
1378 (or (gethash name *search-lists*)
1379 (let ((new (make-search-list :name name)))
1380 (setf (gethash name *search-lists*) new)
1381 new))))
1382
1383 ;;; CLEAR-SEARCH-LIST -- public.
1384 ;;;
1385 ;;; Clear the definition. Note: we can't remove it from the hash-table
1386 ;;; because there may be pathnames still refering to it. So we just clear
1387 ;;; out the expansions and set defined to NIL.
1388 ;;;
1389 (defun clear-search-list (name)
1390 "Clear the current definition for the search-list NAME. Returns T if such
1391 a definition existed, and NIL if not."
1392 (let* ((name (string-downcase name))
1393 (search-list (gethash name *search-lists*)))
1394 (when (and search-list (search-list-defined search-list))
1395 (setf (search-list-defined search-list) nil)
1396 (setf (search-list-expansions search-list) nil)
1397 t)))
1398
1399 ;;; CLEAR-ALL-SEARCH-LISTS -- sorta public.
1400 ;;;
1401 ;;; Again, we can't actually remove the entries from the hash-table, so we
1402 ;;; just mark them as being undefined.
1403 ;;;
1404 (defun clear-all-search-lists ()
1405 "Clear the definition for all search-lists. Only use this if you know
1406 what you are doing."
1407 (maphash #'(lambda (name search-list)
1408 (declare (ignore name))
1409 (setf (search-list-defined search-list) nil)
1410 (setf (search-list-expansions search-list) nil))
1411 *search-lists*)
1412 nil)
1413
1414 ;;; EXTRACT-SEARCH-LIST -- internal.
1415 ;;;
1416 ;;; Extract the search-list from PATHNAME and return it. If PATHNAME
1417 ;;; doesn't start with a search-list, then either error (if FLAME-IF-NONE
1418 ;;; is true) or return NIL (if FLAME-IF-NONE is false).
1419 ;;;
1420 (defun extract-search-list (pathname flame-if-none)
1421 (with-pathname (pathname pathname)
1422 (let* ((directory (%pathname-directory pathname))
1423 (search-list (cadr directory)))
1424 (cond ((search-list-p search-list)
1425 search-list)
1426 (flame-if-none
1427 (error "~S doesn't start with a search-list." pathname))
1428 (t
1429 nil)))))
1430
1431 ;;; SEARCH-LIST -- public.
1432 ;;;
1433 ;;; We have to convert the internal form of the search-list back into a
1434 ;;; bunch of pathnames.
1435 ;;;
1436 (defun search-list (pathname)
1437 "Return the expansions for the search-list starting PATHNAME. If PATHNAME
1438 does not start with a search-list, then an error is signaled. If
1439 the search-list has not been defined yet, then an error is signaled.
1440 The expansion for a search-list can be set with SETF."
1441 (with-pathname (pathname pathname)
1442 (let ((search-list (extract-search-list pathname t))
1443 (host (%pathname-host pathname)))
1444 (if (search-list-defined search-list)
1445 (mapcar #'(lambda (directory)
1446 (make-pathname :host host
1447 :directory (cons :absolute directory)))
1448 (search-list-expansions search-list))
1449 (error "Search list ~S has not been defined yet." pathname)))))
1450
1451 ;;; SEARCH-LIST-DEFINED-P -- public.
1452 ;;;
1453 (defun search-list-defined-p (pathname)
1454 "Returns T if the search-list starting PATHNAME is currently defined, and
1455 NIL otherwise. An error is signaled if PATHNAME does not start with a
1456 search-list."
1457 (with-pathname (pathname pathname)
1458 (search-list-defined (extract-search-list pathname t))))
1459
1460 ;;; %SET-SEARCH-LIST -- public setf method
1461 ;;;
1462 ;;; Set the expansion for the search-list in PATHNAME. If this would result
1463 ;;; in any circularities, we flame out. If anything goes wrong, we leave the
1464 ;;; old defintion intact.
1465 ;;;
1466 (defun %set-search-list (pathname values)
1467 (let ((search-list (extract-search-list pathname t)))
1468 (labels
1469 ((check (target-list path)
1470 (when (eq search-list target-list)
1471 (error "That would result in a circularity:~% ~
1472 ~A~{ -> ~A~} -> ~A"
1473 (search-list-name search-list)
1474 (reverse path)
1475 (search-list-name target-list)))
1476 (when (search-list-p target-list)
1477 (push (search-list-name target-list) path)
1478 (dolist (expansion (search-list-expansions target-list))
1479 (check (car expansion) path))))
1480 (convert (pathname)
1481 (with-pathname (pathname pathname)
1482 (when (or (pathname-name pathname)
1483 (pathname-type pathname)
1484 (pathname-version pathname))
1485 (error "Search-lists cannot expand into pathnames that have ~
1486 a name, type, or ~%version specified:~% ~S"
1487 pathname))
1488 (let ((directory (pathname-directory pathname)))
1489 (let ((expansion
1490 (if directory
1491 (ecase (car directory)
1492 (:absolute (cdr directory))
1493 (:relative (cons (intern-search-list "default")
1494 (cdr directory))))
1495 (list (intern-search-list "default")))))
1496 (check (car expansion) nil)
1497 expansion)))))
1498 (setf (search-list-expansions search-list)
1499 (if (listp values)
1500 (mapcar #'convert values)
1501 (list (convert values)))))
1502 (setf (search-list-defined search-list) t))
1503 values)
1504
1505 ;;; ENUMERATE-SEARCH-LIST -- public.
1506 ;;;
1507 (defmacro enumerate-search-list ((var pathname &optional result) &body body)
1508 "Execute BODY with VAR bound to each successive possible expansion for
1509 PATHNAME and then return RESULT. Note: if PATHNAME does not contain a
1510 search-list, then BODY is executed exactly once. Everything is wrapped
1511 in a block named NIL, so RETURN can be used to terminate early. Note:
1512 VAR is *not* bound inside of RESULT."
1513 (let ((body-name (gensym)))
1514 `(block nil
1515 (flet ((,body-name (,var)
1516 ,@body))
1517 (%enumerate-search-list ,pathname #',body-name)
1518 ,result))))
1519
1520 (defun %enumerate-search-list (pathname function)
1521 (let* ((pathname (if (logical-pathname-p pathname)
1522 (translate-logical-pathname pathname)
1523 pathname))
1524 (search-list (extract-search-list pathname nil)))
1525 (cond
1526 ((not search-list)
1527 (funcall function pathname))
1528 ((not (search-list-defined search-list))
1529 (error "Undefined search list: ~A"
1530 (search-list-name search-list)))
1531 (t
1532 (let ((tail (cddr (pathname-directory pathname))))
1533 (dolist (expansion
1534 (search-list-expansions search-list))
1535 (%enumerate-search-list (make-pathname :defaults pathname
1536 :directory
1537 (cons :absolute
1538 (append expansion
1539 tail)))
1540 function)))))))
1541
1542
1543 ;;;; Logical pathname support. ANSI 92-102 specification.
1544 ;;;; As logical-pathname translations are loaded they are canonicalized as
1545 ;;;; patterns to enable rapid efficent translation into physical pathnames.
1546
1547 ;;;; Utilities:
1548
1549 ;;; LOGICAL-WORD-OR-LOSE -- Internal
1550 ;;;
1551 ;;; Canonicalize a logical pathanme word by uppercasing it checking that it
1552 ;;; contains only legal characters.
1553 ;;;
1554 (defun logical-word-or-lose (word)
1555 (declare (string word))
1556 (let ((word (string-upcase word)))
1557 (dotimes (i (length word))
1558 (let ((ch (schar word i)))
1559 (unless (or (alpha-char-p ch) (digit-char-p ch) (char= ch #\-))
1560 (error 'namestring-parse-error
1561 :complaint "Logical namestring character ~
1562 is not alphanumeric or hyphen:~% ~S"
1563 :arguments (list ch)
1564 :namestring word :offset i))))
1565 word))
1566
1567
1568 ;;; FIND-LOGICAL-HOST -- Internal
1569 ;;;
1570 ;;; Given a logical host or string, return a logical host. If Error-p is
1571 ;;; NIL, then return NIL when no such host exists.
1572 ;;;
1573 (defun find-logical-host (thing &optional (errorp t))
1574 (etypecase thing
1575 (string
1576 (let* ((valid-hostname
1577 (catch 'error-bailout
1578 (handler-bind
1579 ((namestring-parse-error
1580 (lambda(c)(declare (ignore c))
1581 (unless errorp
1582 (throw 'error-bailout nil)))))
1583 (logical-word-or-lose thing))))
1584 (found
1585 (and valid-hostname
1586 (or (gethash valid-hostname *logical-hosts*)
1587 (and *autoload-translations*
1588 (ignore-errors
1589 (load-logical-pathname-translations
1590 valid-hostname))
1591 (gethash valid-hostname *logical-hosts*))))))
1592 (if (or found (not errorp))
1593 found
1594 (error 'simple-file-error
1595 :pathname thing
1596 :format-control "Logical host not yet defined: ~S"
1597 :format-arguments (list thing)))))
1598 (logical-host thing)))
1599
1600 ;;; INTERN-LOGICAL-HOST -- Internal
1601 ;;;
1602 ;;; Given a logical host name or host, return a logical host, creating a new
1603 ;;; one if necessary.
1604 ;;;
1605 (defun intern-logical-host (thing)
1606 (declare (values logical-host))
1607 (or (find-logical-host thing nil)
1608 (let* ((name (logical-word-or-lose thing))
1609 (new (make-logical-host :name name)))
1610 (setf (gethash name *logical-hosts*) new)
1611 new)))
1612
1613
1614 ;;;; Logical pathname parsing:
1615
1616 ;;; MAYBE-MAKE-LOGICAL-PATTERN -- Internal
1617 ;;;
1618 ;;; Deal with multi-char wildcards in a logical pathname token.
1619 ;;;
1620 (defun maybe-make-logical-pattern (namestring chunks)
1621 (let ((chunk (caar chunks)))
1622 (collect ((pattern))
1623 (let ((last-pos 0)
1624 (len (length chunk)))
1625 (declare (fixnum last-pos))
1626 (loop
1627 (when (= last-pos len) (return))
1628 (let ((pos (or (position #\* chunk :start last-pos) len)))
1629 (if (= pos last-pos)
1630 (when (pattern)
1631 (error 'namestring-parse-error
1632 :complaint "Double asterisk inside of logical ~
1633 word: ~S"
1634 :arguments (list chunk)
1635 :namestring namestring
1636 :offset (+ (cdar chunks) pos)))
1637 (pattern (subseq chunk last-pos pos)))
1638 (if (= pos len)
1639 (return)
1640 (pattern :multi-char-wild))
1641 (setq last-pos (1+ pos)))))
1642 (assert (pattern))
1643 (if (cdr (pattern))
1644 (make-pattern (pattern))
1645 (let ((x (car (pattern))))
1646 (if (eq x :multi-char-wild)
1647 :wild
1648 x))))))
1649
1650
1651 ;;; LOGICAL-CHUNKIFY -- Internal
1652 ;;;
1653 ;;; Return a list of conses where the cdr is the start position and the car
1654 ;;; is a string (token) or character (punctuation.)
1655 ;;;
1656 (defun logical-chunkify (namestr start end)
1657 (collect ((chunks))
1658 (do ((i start (1+ i))
1659 (prev 0))
1660 ((= i end)
1661 (when (> end prev)
1662 (chunks (cons (nstring-upcase (subseq namestr prev end)) prev))))
1663 (let ((ch (schar namestr i)))
1664 (unless (or (alpha-char-p ch) (digit-char-p ch)
1665 (member ch '(#\- #\*)))
1666 (when (> i prev)
1667 (chunks (cons (nstring-upcase (subseq namestr prev i)) prev)))
1668 (setq prev (1+ i))
1669 (unless (member ch '(#\; #\: #\.))
1670 (error 'namestring-parse-error
1671 :complaint "Illegal character for logical pathname:~% ~S"
1672 :arguments (list ch)
1673 :namestring namestr
1674 :offset i))
1675 (chunks (cons ch i)))))
1676 (chunks)))
1677
1678
1679 ;;; PARSE-LOGICAL-NAMESTRING -- Internal
1680 ;;;
1681 ;;; Break up a logical-namestring, always a string, into its constituent
1682 ;;; parts.
1683 ;;;
1684 (defun parse-logical-namestring (namestr start end)
1685 (declare (type simple-base-string namestr)
1686 (type index start end))
1687 (collect ((directory))
1688 (let ((host nil)
1689 (name nil)
1690 (type nil)
1691 (version nil))
1692 (labels ((expecting (what chunks)
1693 (unless (and chunks (simple-string-p (caar chunks)))
1694 (error 'namestring-parse-error
1695 :complaint "Expecting ~A, got ~:[nothing~;~:*~S~]."
1696 :arguments (list what (caar chunks))
1697 :namestring namestr
1698 :offset (if chunks (cdar chunks) end)))
1699 (caar chunks))
1700 (parse-host (chunks)
1701 (case (caadr chunks)
1702 (#\:
1703 (setq host
1704 (find-logical-host (expecting "a host name" chunks)))
1705 (parse-relative (cddr chunks)))
1706 (t
1707 (parse-relative chunks))))
1708 (parse-relative (chunks)
1709 (case (caar chunks)
1710 (#\;
1711 (directory :relative)
1712 (parse-directory (cdr chunks)))
1713 (t
1714 (directory :absolute) ; Assumption! Maybe revoked later.
1715 (parse-directory chunks))))
1716 (parse-directory (chunks)
1717 (case (caadr chunks)
1718 (#\;
1719 (directory
1720 (let ((res (expecting "a directory name" chunks)))
1721 (cond ((string= res "..") :up)
1722 ((string= res "**") :wild-inferiors)
1723 (t
1724 (maybe-make-logical-pattern namestr chunks)))))
1725 (parse-directory (cddr chunks)))
1726 (t
1727 (parse-name chunks))))
1728 (parse-name (chunks)
1729 (when chunks
1730 (expecting "a file name" chunks)
1731 (setq name (maybe-make-logical-pattern namestr chunks))
1732 (expecting-dot (cdr chunks))))
1733 (expecting-dot (chunks)
1734 (when chunks
1735 (unless (eql (caar chunks) #\.)
1736 (error 'namestring-parse-error
1737 :complaint "Expecting a dot, got ~S."
1738 :arguments (list (caar chunks))
1739 :namestring namestr
1740 :offset (cdar chunks)))
1741 (if type
1742 (parse-version (cdr chunks))
1743 (parse-type (cdr chunks)))))
1744 (parse-type (chunks)
1745 (expecting "a file type" chunks)
1746 (setq type (maybe-make-logical-pattern namestr chunks))
1747 (expecting-dot (cdr chunks)))
1748 (parse-version (chunks)
1749 (let ((str (expecting "a positive integer, * or NEWEST"
1750 chunks)))
1751 (cond
1752 ((string= str "*") (setq version :wild))
1753 ((string= str "NEWEST") (setq version :newest))
1754 (t
1755 (multiple-value-bind
1756 (res pos)
1757 (parse-integer str :junk-allowed t)
1758 (unless (and res (plusp res))
1759 (error 'namestring-parse-error
1760 :complaint "Expected a positive integer, ~
1761 got ~S"
1762 :arguments (list str)
1763 :namestring namestr
1764 :offset (+ pos (cdar chunks))))
1765 (setq version res)))))
1766 (when (cdr chunks)
1767 (error 'namestring-parse-error
1768 :complaint "Extra stuff after end of file name."
1769 :namestring namestr
1770 :offset (cdadr chunks)))))
1771 (parse-host (logical-chunkify namestr start end)))
1772 (values host :unspecific
1773 (directory)
1774 name type version))))
1775
1776
1777 ;;; Can't defvar here because not all host methods are loaded yet.
1778 (declaim (special *logical-pathname-defaults*))
1779
1780 ;;; LOGICAL-PATHNAME -- Public
1781 ;;;
1782 (defun logical-pathname (pathspec)
1783 "Converts the pathspec argument to a logical-pathname and returns it."
1784 (declare (type (or logical-pathname string stream) pathspec)
1785 (values logical-pathname))
1786 (if (typep pathspec 'logical-pathname)
1787 pathspec
1788 (let ((res (parse-namestring pathspec nil *logical-pathname-defaults*)))
1789 (when (eq (%pathname-host res)
1790 (%pathname-host *logical-pathname-defaults*))
1791 (error
1792 'simple-type-error
1793 :format-control "Logical namestring does not specify a host:~% ~S"
1794 :format-arguments (list pathspec)
1795 :datum pathspec
1796 :expected-type '(satisfies logical-pathname-namestring-p)))
1797 res)))
1798
1799
1800
1801 ;;;; Logical pathname unparsing:
1802
1803 ;;; UNPARSE-LOGICAL-DIRECTORY -- Internal
1804 ;;;
1805 (defun unparse-logical-directory (pathname)
1806 (declare (type pathname pathname))
1807 (collect ((pieces))
1808 (let ((directory (%pathname-directory pathname)))
1809 (when directory
1810 (ecase (pop directory)
1811 (:absolute) ;; Nothing special.
1812 (:relative (pieces ";")))
1813 (dolist (dir directory)
1814 (cond ((or (stringp dir) (pattern-p dir))
1815 (pieces (unparse-logical-piece dir))
1816 (pieces ";"))
1817 ((eq dir :wild)
1818 (pieces "*;"))
1819 ((eq dir :wild-inferiors)
1820 (pieces "**;"))
1821 (t
1822 (error "Invalid directory component: ~S" dir))))))
1823 (apply #'concatenate 'simple-string (pieces))))
1824
1825
1826 ;;; UNPARSE-LOGICAL-PIECE -- Internal
1827 ;;;
1828 (defun unparse-logical-piece (thing)
1829 (etypecase thing
1830 (simple-string thing)
1831 (pattern
1832 (collect ((strings))
1833 (dolist (piece (pattern-pieces thing))
1834 (etypecase piece
1835 (simple-string (strings piece))
1836 (keyword
1837 (cond ((eq piece :wild-inferiors)
1838 (strings "**"))
1839 ((eq piece :multi-char-wild)
1840 (strings "*"))
1841 (t (error "Invalid keyword: ~S" piece))))))
1842 (apply #'concatenate 'simple-string (strings))))))
1843
1844 ;;; UNPARSE-ENOUGH-NAMESTRING -- Internal
1845 ;;;
1846 (defun unparse-enough-namestring (pathname defaults)
1847 (let* ((path-dir (pathname-directory pathname))
1848 (def-dir (pathname-directory defaults))
1849 (enough-dir
1850 ;; Go down the directory lists to see what matches. What's
1851 ;; left is what we want, more or less.
1852 (cond ((and (eq (first path-dir) (first def-dir))
1853 (eq (first path-dir) :absolute))
1854 ;; Both paths are :absolute, so find where the common
1855 ;; parts end and return what's left
1856 (do* ((p (rest path-dir) (rest p))
1857 (d (rest def-dir) (rest d)))
1858 ((or (endp p) (endp d)
1859 (not (equal (first p) (first d))))
1860 `(:relative ,@p))))
1861 (t
1862 ;; At least one path is :relative, so just return the
1863 ;; original path. If the original path is :relative,
1864 ;; then that's the right one. If PATH-DIR is
1865 ;; :absolute, we want to return that except when
1866 ;; DEF-DIR is :absolute, as handled above. so return
1867 ;; the original directory.
1868 path-dir))))
1869 (make-pathname :host (%pathname-host pathname)
1870 :directory enough-dir
1871 :name (pathname-name pathname)
1872 :type (pathname-type pathname)
1873 :version (pathname-version pathname))))
1874
1875 ;;; UNPARSE-LOGICAL-NAMESTRING -- Internal
1876 ;;;
1877 (defun unparse-logical-namestring (pathname)
1878 (declare (type logical-pathname pathname))
1879 (concatenate 'simple-string
1880 (logical-host-name (%pathname-host pathname)) ":"
1881 (unparse-logical-directory pathname)
1882 (unparse-unix-file pathname)))
1883
1884
1885 ;;;; Logical pathname translations:
1886
1887 ;;; CANONICALIZE-LOGICAL-PATHNAME-TRANSLATIONS -- Internal
1888 ;;;
1889 ;;; Verify that the list of translations consists of lists and prepare
1890 ;;; canonical translations (parse pathnames and expand out wildcards into
1891 ;;; patterns).
1892 ;;;
1893 (defun canonicalize-logical-pathname-translations (transl-list host)
1894 (declare (type list transl-list) (type host host)
1895 (values list))
1896 (collect ((res))
1897 (dolist (tr transl-list)
1898 (unless (and (consp tr) (= (length tr) 2))
1899 (error "Logical pathname translation is not a two-list:~% ~S"
1900 tr))
1901 (let ((from (first tr)))
1902 (res (list (if (typep from 'logical-pathname)
1903 from
1904 (parse-namestring from host))
1905 (pathname (second tr))))))
1906 (res)))
1907
1908
1909 ;;; LOGICAL-PATHNAME-TRANSLATIONS -- Public
1910 ;;;
1911 (defun logical-pathname-translations (host)
1912 "Return the (logical) host object argument's list of translations."
1913 (declare (type (or string logical-host) host)
1914 (values list))
1915 (logical-host-translations (find-logical-host host)))
1916
1917 ;;; (SETF LOGICAL-PATHNAME-TRANSLATIONS) -- Public
1918 ;;;
1919 (defun (setf logical-pathname-translations) (translations host)
1920 "Set the translations list for the logical host argument.
1921 Return translations."
1922 (declare (type (or string logical-host) host)
1923 (type list translations)
1924 (values list))
1925
1926 (let ((host (intern-logical-host host)))
1927 (setf (logical-host-canon-transls host)
1928 (canonicalize-logical-pathname-translations translations host))
1929 (setf (logical-host-translations host) translations)))
1930
1931
1932 ;;; The search mechanism for loading pathname translations uses the CMUCL
1933 ;;; extension of search-lists. The user can add to the library: search-list
1934 ;;; using setf. The file for translations should have the name defined by
1935 ;;; the hostname (a string) and with type component "translations".
1936
1937 ;;; LOAD-LOGICAL-PATHNAME-TRANSLATIONS -- Public
1938 ;;;
1939 (defun load-logical-pathname-translations (host)
1940 "Search for a logical pathname named host, if not already defined. If already
1941 defined no attempt to find or load a definition is attempted and NIL is
1942 returned. If host is not already defined, but definition is found and loaded
1943 successfully, T is returned, else error."
1944 (declare (type string host)
1945 (values (member t nil)))
1946 (let ((*autoload-translations* nil))
1947 (unless (or (string-equal host "library")
1948 (find-logical-host host nil))
1949 (with-open-file (in-str (make-pathname :defaults "library:"
1950 :name (string-downcase host)
1951 :type "translations"))
1952 (if *load-verbose*
1953 (format *error-output*
1954 ";; Loading pathname translations from ~A~%"
1955 (namestring (truename in-str))))
1956 (setf (logical-pathname-translations host) (read in-str)))
1957 t)))
1958
1959 ;;; TRANSLATE-LOGICAL-PATHNAME -- Public
1960 ;;;
1961 (defun translate-logical-pathname (pathname &key)
1962 "Translates pathname to a physical pathname, which is returned."
1963 (declare (type path-designator pathname)
1964 (values (or null pathname)))
1965 (typecase pathname
1966 (logical-pathname
1967 (dolist (x (logical-host-canon-transls (%pathname-host pathname))
1968 (error 'simple-file-error
1969 :pathname pathname
1970 :format-control "No translation for ~S"
1971 :format-arguments (list pathname)))
1972 (destructuring-bind (from to) x
1973 (when (pathname-match-p pathname from)
1974 (return (translate-logical-pathname
1975 (translate-pathname pathname from to)))))))
1976 (pathname pathname)
1977 (stream (translate-logical-pathname (pathname pathname)))
1978 (t (translate-logical-pathname (pathname pathname)))))
1979
1980 (defvar *logical-pathname-defaults*
1981 (%make-logical-pathname (make-logical-host :name "BOGUS") :unspecific
1982 nil nil nil nil))

  ViewVC Help
Powered by ViewVC 1.1.5