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

Contents of /src/code/pathname.lisp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5