• Aucun résultat trouvé

Wildcard Pathname Mapping

Dans le document Introduction to the 1/0 System (Page 88-92)

4. Naming of Files

4.6 Wildcard Pathname Mapping

In the Symbolics system, as in some other systems, wildcard pathnames are used not only to specify groups of files, but to specify mappings between pairs of pathnames, for operations such as renaming and copying files.

For example, you might ask to copy *foo* .lisp to *bar* .lisp. All the files to be copied match the wildcard name *foo* .lisp. *bar* .lisp is a specification of how to construct the pathname of the new file. The two wildcard pathnames, as in the above example, are called the source pattern and target pattern. The original name of any file to be copied is called the starting instance. Here is an example:

Source pattern:

Target pattern:

Starting instance:

Target instance:

f:>fie>*old*.lisp vx:/usr2/fum/*older*.1 f:>fie>--oldfoo.lisp vx:/usr2/fum/--olderfoo.l

A more abstract description of this terminology:

Source pattern A pathname containing wild components.

Target pattern A pathname containing wild components.

Source instance A pathname that matches the source pattern.

Target instance A pathname specified by applying the common sequences between the source and target patterns to the source instance.

Two Zmacs commands accept pairs of wildcard file specifications:

Copy File (M-X)

Rename File (M-X)

The components of the target instance are determined component-by-component for all components except the host. (The host component is always determined

literally from the source and target patterns; it cannot be wild.) The mapping of pathnames is done in the native case of the target host. The source pattern and source instance are coerced to the target host via the :new-default-pathname message before the mapping takes place. See the method

(flavor:method :new-default-pathname pathname), page 97.

When the type of the target pattern is :wild, it uses the canonical type for the target, regardless of the surface form for the type in the source pattern and instance.

NOTE

In the Lisp Machine File System,

*

as the directory portion of a file specification specifies a relative pathname. You must use >** to indicate a wild directory component that matches any directory at all.

See the section "LMFS Pathnames", page 101.

Here are the rules used in constructing a target instance, given the source and target patterns and a particular source instance. This set of rules is applied separately to each component in the pathname. In the mapping rules, a * character as the only contents of a component of a file spec is considered to be the same as the keyword symbol :wild. The rule uses the patterns from the example above.

1. If the target pattern does not contain *, copy the target pattern component literally to the target instance.

2. If the target pattern is :wild, copy the source component to the target literally with no further analysis. The type component is handled somewhat differently - when source and target hosts are of different system types, it uses the canonical-type mechanism to translate the type. This does not apply when the target pattern is :wild-inferiors, in directory specifications.

3. Find the positions of all

*

characters in the source and target patterns.

Take the characters intervening between * characters as a literal value.

Literal values for the name component:

Source: old Target: 01 der

4. Find each literal value from the source pattern in the source instance. Take the characters intervening between literal values as a matching value for the

*

from the source pattern. The matching value could be any number of characters, including zero. Matching values for the name component:

-- and foo

5. Create the component by assembling the literal and matching values in left to right order, SUbstituting the matching values where * appears in the target pattern. For the name component:

--olderfoo

When not enough matching values are available (due to too few * in the source pattern) use the null string as the matching value. When the source pattern has too many

*,

ignore the first extra

*

and everything following it.

Some examples:

Source pattern Source instance Target pattern Target instance

*report 6802-report *summary 6802-summary

1 mfs-* lmfs-errors * lmfs-errors

1* 1 1* 1

1* 1 i sp 1* lisp

OLO-OIR OLO-OIR NEW-PLACE NEW-PLACE

* doc *-extract doc-extract

doc doc doc-extract doc-extract

4.6.1 Wildcard Directory Mapping

The rules for mapping directory components between two wildcard pathnames and a starting instance are parallel to the rules for single names. Directory-level components play roughly the roles of characters in the name-translating algorithm.

See the section "Wildcard Pathname Mapping", page 79.

Consider a directory component as a sequence of directory level components. The levels are separated by level delimiters (> in LMFS). Example: In the pathname

>foo>bar>*>mumble*>x>**>y>a.b.3, the directory-level components are foo, bar, *, mumble*, x, **, and y. The source and target patterns, as well as the starting instance, are considered as sequences of directory-level components, and are matched and translated level by level.

For this purpose, each directory-level component can be classified as one of three directory level components act as constant substrings in that algorithm, and wild-inferiors levels as *s. That is, wild-wild-inferiors level components match and, on the target side, carry, zero to any number of constant directory-level components.

Examples: .

Must-match components are matched with exactly one directory-level component, which must be present. They are mapped according to the string-mapping rules in the name-translating algorithm. See the section "Wildcard Pathname Mapping", page 79.

You can intersperse constants, must-matches, and wild-inferiors directory-level components, as long as the sequence of wildcard types is the same in both patterns.

Source pattern:

Target pattern:

Starting instance:

Target instance:

>a>*>c>**>*.lisp.*

>bsg>sub>new-*>q>**>*.*.*

>a>bb>c>d>e>p1.1isp.6

>bsg>sub>new-bb>q>d>e>p1.1isp.6

Dans le document Introduction to the 1/0 System (Page 88-92)