File: chap-19.texi

package info (click to toggle)
gclinfo 2.2-9
  • links: PTS
  • area: main
  • in suites: potato
  • size: 3,928 kB
  • ctags: 15
  • sloc: sed: 1,681; makefile: 127; lisp: 58; sh: 40
file content (2450 lines) | stat: -rw-r--r-- 93,975 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450


@node Filenames, Files, Hash Tables, Top
@chapter Filenames

@menu
* Overview of Filenames::	
* Pathnames::			
* Logical Pathnames::		
* Filenames Dictionary::	
@end menu

@node Overview of Filenames, Pathnames, Filenames, Filenames
@section Overview of Filenames

@c including concept-filenames

There are many kinds of @i{file systems},
varying widely both in their superficial syntactic details,
		and in their underlying power and structure.
The facilities provided by @r{Common Lisp} for referring to and manipulating @i{files}
has been chosen to be compatible with many kinds of @i{file systems},
while at the same time minimizing the program-visible differences 
between kinds of @i{file systems}.

Since @i{file systems} vary in their conventions for naming @i{files},
there are two distinct ways to represent @i{filenames}:
as @i{namestrings} and as @i{pathnames}.

@menu
* Namestrings as Filenames::	
* Pathnames as Filenames::	
* Parsing Namestrings Into Pathnames::	
@end menu

@node Namestrings as Filenames, Pathnames as Filenames, Overview of Filenames, Overview of Filenames
@subsection Namestrings as Filenames

A @i{namestring}
@IGindex{namestring}
 is a @i{string} that represents a @i{filename}.

In general, the syntax of @i{namestrings} involves the use of 
@i{implementation-defined} conventions, 
usually those customary for the @i{file system} in which the named @i{file} resides.
The only exception is the syntax of a @i{logical pathname} @i{namestring},
which is defined in this specification; see @ref{Syntax of Logical Pathname Namestrings}.

A @i{conforming program} must never unconditionally use a
@i{literal} @i{namestring} other than a @i{logical pathname} @i{namestring}
because @r{Common Lisp} does not define any @i{namestring} syntax 
other than that for @i{logical pathnames}
that would be guaranteed to be portable.
However, a @i{conforming program} can, if it is careful, 
successfully manipulate user-supplied data 
which contains or refers to non-portable @i{namestrings}.

A @i{namestring} can be @i{coerced} to a @i{pathname} by the @i{functions} @b{pathname}
or @b{parse-namestring}.

@node Pathnames as Filenames, Parsing Namestrings Into Pathnames, Namestrings as Filenames, Overview of Filenames
@subsection Pathnames as Filenames

@i{Pathnames}
@IGindex{pathname}
 are structured @i{objects} that can represent,
in an @i{implementation-independent} way,
the @i{filenames} that are used natively by an underlying @i{file system}.

In addition, @i{pathnames} can also represent certain partially composed 
@i{filenames} for which an underlying @i{file system} 
might not have a specific @i{namestring} representation.

A @i{pathname} need not correspond to any file that actually exists, 
and more than one @i{pathname} can refer to the same file.
For example, the @i{pathname} with a version of @t{:newest} 
might refer to the same file as a @i{pathname} 
with the same components except a certain number as the version.
Indeed, a @i{pathname} with version @t{:newest} might refer to
different files as time passes, because the meaning of such a @i{pathname}
depends on the state of the file system.  

Some @i{file systems} naturally use a structural model for their
@i{filenames}, while others do not.  Within the @r{Common Lisp} @i{pathname} model, 
all @i{filenames} are seen as having a particular structure,
even if that structure is not reflected in the underlying @i{file system}.
The nature of the mapping between structure imposed by @i{pathnames}
and the structure, if any, that is used by the underlying @i{file system}
is @i{implementation-defined}.

Every @i{pathname} has six components:
     a host,
     a device,
     a directory,
     a name,
     a type,
 and a version.
By naming @i{files} with @i{pathnames}, 
@r{Common Lisp} programs can work in essentially the same way even in @i{file systems}
that seem superficially quite different.
For a detailed description of these components, see @ref{Pathname Components}.

The mapping of the @i{pathname} components into the concepts peculiar to
each @i{file system} is @i{implementation-defined}.
There exist conceivable @i{pathnames}
for which there is no mapping to a syntactically valid @i{filename}
in a particular @i{implementation}.
An @i{implementation} may use various strategies in an attempt to find a mapping;
for example, 
an @i{implementation} may quietly truncate @i{filenames}
that exceed length limitations imposed by the underlying @i{file system},
or ignore certain @i{pathname} components
for which the @i{file system} provides no support.
If such a mapping cannot be found,
an error of @i{type} @b{file-error} is signaled.

The time at which this mapping and associated error signaling 
occurs is @i{implementation-dependent}.
Specifically, it may occur 
    at the time the @i{pathname} is constructed,
    when coercing a @i{pathname} to a @i{namestring},
 or when an attempt is made to @i{open} or otherwise access the @i{file} 
     designated by the @i{pathname}.

Figure 19--1 lists some @i{defined names} that are applicable to @i{pathnames}.

@group
@noindent
@w{  *default-pathname-defaults*  namestring          pathname-name          }
@w{  directory-namestring         open                pathname-type          }
@w{  enough-namestring            parse-namestring    pathname-version       }
@w{  file-namestring              pathname            pathnamep              }
@w{  file-string-length           pathname-device     translate-pathname     }
@w{  host-namestring              pathname-directory  truename               }
@w{  make-pathname                pathname-host       user-homedir-pathname  }
@w{  merge-pathnames              pathname-match-p    wild-pathname-p        }

@noindent
@w{                     Figure 19--1: Pathname Operations                    }

@end group

@node Parsing Namestrings Into Pathnames,  , Pathnames as Filenames, Overview of Filenames
@subsection Parsing Namestrings Into Pathnames

Parsing is the operation used to convert a @i{namestring} into a @i{pathname}.

Except in the case of parsing @i{logical pathname} @i{namestrings},

this operation is @i{implementation-dependent},
because the format of @i{namestrings} is @i{implementation-dependent}.

A @i{conforming implementation} is free to accommodate other @i{file system}
features in its @i{pathname} representation and provides a parser that can process 
such specifications in @i{namestrings}.  
@i{Conforming programs} must not depend on any such features, 
since those features will not be portable.

@c end of including concept-filenames

@node Pathnames, Logical Pathnames, Overview of Filenames, Filenames
@section Pathnames

@c including concept-pathnames

@menu
* Pathname Components::		
* Interpreting Pathname Component Values::  
* Merging Pathnames::		
@end menu

@node Pathname Components, Interpreting Pathname Component Values, Pathnames, Pathnames
@subsection Pathname Components

A @i{pathname} has six components:
     a host,
     a device,
     a directory,
     a name,
     a type,
 and a version.

@menu
* The Pathname Host Component::	 
* The Pathname Device Component::  
* The Pathname Directory Component::  
* The Pathname Name Component::	 
* The Pathname Type Component::	 
* The Pathname Version Component::  
@end menu

@node The Pathname Host Component, The Pathname Device Component, Pathname Components, Pathname Components
@subsubsection The Pathname Host Component

The name of the file system on which the file resides,
or the name of a @i{logical host}.

@node The Pathname Device Component, The Pathname Directory Component, The Pathname Host Component, Pathname Components
@subsubsection The Pathname Device Component

Corresponds to the ``device'' or ``file structure'' concept in many
host file systems: the name of a logical or physical device containing files.

@node The Pathname Directory Component, The Pathname Name Component, The Pathname Device Component, Pathname Components
@subsubsection The Pathname Directory Component

Corresponds to the ``directory'' concept in many host file systems:
the name of a group of related files.

@node The Pathname Name Component, The Pathname Type Component, The Pathname Directory Component, Pathname Components
@subsubsection The Pathname Name Component

The ``name'' part of a group of @i{files} that can be thought of
as conceptually related.

@node The Pathname Type Component, The Pathname Version Component, The Pathname Name Component, Pathname Components
@subsubsection The Pathname Type Component

Corresponds to the ``filetype'' or ``extension'' concept in many host
file systems.  This says what kind of file this is.  
This component is always a @i{string}, @b{nil}, @t{:wild}, or @t{:unspecific}.

@node The Pathname Version Component,  , The Pathname Type Component, Pathname Components
@subsubsection The Pathname Version Component

Corresponds to the ``version number'' concept in many host file systems.

The version is either a positive @i{integer} 
or a @i{symbol} from the following list:
@b{nil}, @t{:wild}, @t{:unspecific}, or @t{:newest}
(refers to the largest version number that already exists in 
the file system when reading a file, or to
a version number
greater than any already existing in the file system
when writing a new file).  Implementations 
can define other special version @i{symbols}.

@node Interpreting Pathname Component Values, Merging Pathnames, Pathname Components, Pathnames
@subsection Interpreting Pathname Component Values

@menu
* Strings in Component Values::	 
* Special Characters in Pathname Components::  
* Case in Pathname Components::	 
* Local Case in Pathname Components::  
* Common Case in Pathname Components::	
* Special Pathname Component Values::  
* NIL as a Component Value::	
* ->WILD as a Component Value::	 
* ->UNSPECIFIC as a Component Value::  
* Relation between component values NIL and ->UNSPECIFIC::  
* Restrictions on Wildcard Pathnames::	
* Restrictions on Examining Pathname Components::  
* Restrictions on Examining a Pathname Host Component::	 
* Restrictions on Examining a Pathname Device Component::  
* Restrictions on Examining a Pathname Directory Component::  
* Directory Components in Non-Hierarchical File Systems::  
* Restrictions on Examining a Pathname Name Component::	 
* Restrictions on Examining a Pathname Type Component::	 
* Restrictions on Examining a Pathname Version Component::  
* Notes about the Pathname Version Component::	
* Restrictions on Constructing Pathnames::  
@end menu

@node Strings in Component Values, Special Characters in Pathname Components, Interpreting Pathname Component Values, Interpreting Pathname Component Values
@subsubsection Strings in Component Values

@node Special Characters in Pathname Components, Case in Pathname Components, Strings in Component Values, Interpreting Pathname Component Values
@subsubsection Special Characters in Pathname Components

@i{Strings} in @i{pathname} component values 
never contain special @i{characters} that represent
separation between @i{pathname} fields, 
such as @i{slash} in @r{Unix} @i{filenames}.
Whether separator @i{characters} are permitted as 
part of a @i{string} in a @i{pathname} component
is @i{implementation-defined}; 
however, if the @i{implementation} does permit it, 
it must arrange to properly ``quote'' the character for the 
@i{file system} when constructing a @i{namestring}.
For example,

@example
 ;; In a TOPS-20 implementation, which uses {@t{^}}V to quote 
 (NAMESTRING (MAKE-PATHNAME :HOST "OZ" :NAME "<TEST>"))
@result{}  #P"OZ:PS:{@t{^}}V<TEST{@t{^}}V>"
@i{NOT}@result{} #P"OZ:PS:<TEST>"
@end example

@node Case in Pathname Components, Local Case in Pathname Components, Special Characters in Pathname Components, Interpreting Pathname Component Values
@subsubsection Case in Pathname Components

@i{Namestrings} always use local file system @i{case} conventions, 
but @r{Common Lisp} @i{functions} that manipulate @i{pathname} components
allow the caller to select either of two conventions for representing
@i{case} in component values by supplying a value for the
@t{:case} keyword argument.
Figure 19--2 lists the functions 
relating to @i{pathnames} that permit a @t{:case} argument:

@group
@noindent
@w{  make-pathname    pathname-directory  pathname-name  }
@w{  pathname-device  pathname-host       pathname-type  }

@noindent
@w{  Figure 19--2: Pathname functions using a :CASE argument}

@end group

@node Local Case in Pathname Components, Common Case in Pathname Components, Case in Pathname Components, Interpreting Pathname Component Values
@subsubsection Local Case in Pathname Components

For the functions in @i{Figure~19--2},
a value of @t{:local}
@IKindex{local}
 for the @t{:case} argument 
(the default for these functions)
indicates that the functions should receive and yield @i{strings} in component values
as if they were already represented according to the host @i{file system}'s 
convention for @i{case}.

If the @i{file system} supports both @i{cases}, @i{strings} given or received
as @i{pathname} component values under this protocol are to be used exactly
as written.  If the file system only supports one @i{case}, 
the @i{strings} will be translated to that @i{case}.

@node Common Case in Pathname Components, Special Pathname Component Values, Local Case in Pathname Components, Interpreting Pathname Component Values
@subsubsection Common Case in Pathname Components

For the functions in @i{Figure~19--2},
a value of @t{:common}
@IKindex{common}
 for the @t{:case} argument 
that these @i{functions} should receive 
and yield @i{strings} in component values according to the following conventions:

@table @asis

@item @t{*}  
All @i{uppercase} means to use a file system's customary @i{case}.
@item @t{*}  
All @i{lowercase} means to use the opposite of the customary @i{case}.
@item @t{*}  
Mixed @i{case} represents itself.
@end table

Note that these conventions have been chosen in such a way that translation
from @t{:local} to @t{:common} and back to @t{:local} is information-preserving.

@node Special Pathname Component Values, NIL as a Component Value, Common Case in Pathname Components, Interpreting Pathname Component Values
@subsubsection Special Pathname Component Values

@node NIL as a Component Value, ->WILD as a Component Value, Special Pathname Component Values, Interpreting Pathname Component Values
@subsubsection NIL as a Component Value

As a @i{pathname} component value,
@b{nil} represents that the component is ``unfilled'';
see @ref{Merging Pathnames}.

The value of any @i{pathname} component can be @b{nil}.

When constructing a @i{pathname},
@b{nil} in the host component might mean a default host
rather than an actual @b{nil} in some @i{implementations}.

@node ->WILD as a Component Value, ->UNSPECIFIC as a Component Value, NIL as a Component Value, Interpreting Pathname Component Values
@subsubsection :WILD as a Component Value

If @t{:wild}
@IKindex{wild}
 is the value of a @i{pathname} component,
that component is considered to be a wildcard, which matches anything.

A @i{conforming program} must be prepared to encounter a value of @t{:wild}
as the value of any @i{pathname} component,
or as an @i{element} of a @i{list} that is the value of the directory component.

When constructing a @i{pathname},
a @i{conforming program} may use @t{:wild} as the value of any or all of
the directory, name, type, 
or version component, but must not use @t{:wild} as the value of the host,
or device component.

If @t{:wild} is used as the value of the directory component in the construction
of a @i{pathname}, the effect is equivalent to specifying the list
@t{(:absolute :wild-inferiors)},
or the same as @t{(:absolute :wild)} in a @i{file system} that does not support
@t{:wild-inferiors}.
@IKindex{wild-inferiors}

@node ->UNSPECIFIC as a Component Value, Relation between component values NIL and ->UNSPECIFIC, ->WILD as a Component Value, Interpreting Pathname Component Values
@subsubsection :UNSPECIFIC as a Component Value

If @t{:unspecific}
@IKindex{unspecific}
 is the value of a @i{pathname} component,
the component is considered to be ``absent'' 
or to ``have no meaning''
in the @i{filename} being represented by the @i{pathname}.

Whether a value of @t{:unspecific} is permitted for any component
on any given @i{file system} accessible to the @i{implementation}
is @i{implementation-defined}.
A @i{conforming program} must never unconditionally use a
@t{:unspecific} as the value of a @i{pathname} component because
such a value is not guaranteed to be permissible in all implementations.
However, a @i{conforming program} can, if it is careful, 
successfully manipulate user-supplied data 
which contains or refers to non-portable @i{pathname} components.
And certainly a @i{conforming program} should be prepared for the
possibility that any components of a @i{pathname} could be @t{:unspecific}.

When @i{reading}_1 the value of any @i{pathname} component,
@i{conforming programs} should be prepared for the value to be @t{:unspecific}.

When @i{writing}_1 the value of any @i{pathname} component,
the consequences are undefined if @t{:unspecific} is given 
for a @i{pathname} in a @i{file system} for which it does not make sense.

@node Relation between component values NIL and ->UNSPECIFIC, Restrictions on Wildcard Pathnames, ->UNSPECIFIC as a Component Value, Interpreting Pathname Component Values
@subsubsection Relation between component values NIL and :UNSPECIFIC

If a @i{pathname} is converted to a @i{namestring}, 
the @i{symbols} @b{nil} and @t{:unspecific}
cause the field to be treated as if it were empty.
That is,
both @b{nil} and @t{:unspecific} 
cause the component not to appear in the @i{namestring}.

However, when merging a @i{pathname} with a set of defaults,
only a @b{nil} value for a component 
will be replaced with the default for that component, 
while a value of @t{:unspecific}
will be left alone as if the field were ``filled'';
see the @i{function} @b{merge-pathnames} and @ref{Merging Pathnames}.

@node Restrictions on Wildcard Pathnames, Restrictions on Examining Pathname Components, Relation between component values NIL and ->UNSPECIFIC, Interpreting Pathname Component Values
@subsubsection Restrictions on Wildcard Pathnames

  Wildcard @i{pathnames} can be used with @b{directory} but not with 
  @b{open},
  and return true from @b{wild-pathname-p}. When examining
  wildcard components of a wildcard @i{pathname}, conforming programs
  must be prepared to encounter any of the following additional values
  in any component or any element of a @i{list} that is the directory component:

@table @asis

@item @t{*}  
The @i{symbol} @t{:wild}, which matches anything.

@item @t{*}  
A @i{string} containing @i{implementation-dependent} 
		 special wildcard @i{characters}.

@item @t{*}  
Any @i{object},
		 representing an @i{implementation-dependent} wildcard pattern.

@end table

@node Restrictions on Examining Pathname Components, Restrictions on Examining a Pathname Host Component, Restrictions on Wildcard Pathnames, Interpreting Pathname Component Values
@subsubsection Restrictions on Examining Pathname Components

The space of possible @i{objects} that a @i{conforming program} 
must be prepared to @i{read}_1 
as the value of a @i{pathname} component
is substantially larger than the space of possible @i{objects} 
that a @i{conforming program} is permitted to @i{write}_1
into such a component.

While the values discussed 
    in the subsections of this section,
    in @ref{Special Pathname Component Values},
and in @ref{Restrictions on Wildcard Pathnames} 
apply to values that might be seen when 
reading the component values,
substantially more restrictive rules apply to constructing pathnames;
see @ref{Restrictions on Constructing Pathnames}.

When examining @i{pathname} components,
@i{conforming programs} should be aware of the following restrictions.

@node Restrictions on Examining a Pathname Host Component, Restrictions on Examining a Pathname Device Component, Restrictions on Examining Pathname Components, Interpreting Pathname Component Values
@subsubsection Restrictions on Examining a Pathname Host Component

It is @i{implementation-dependent} what @i{object} is used to represent the host. 

@node Restrictions on Examining a Pathname Device Component, Restrictions on Examining a Pathname Directory Component, Restrictions on Examining a Pathname Host Component, Interpreting Pathname Component Values
@subsubsection Restrictions on Examining a Pathname Device Component

The device might be a @i{string},
@t{:wild}, @t{:unspecific}, or @b{nil}.

Note that @t{:wild} might result from an attempt to @i{read}_1
the @i{pathname} component, even though portable programs are restricted
from @i{writing}_1 such a component value; 
see @ref{Restrictions on Wildcard Pathnames} and @ref{Restrictions on Constructing Pathnames}.

@node Restrictions on Examining a Pathname Directory Component, Directory Components in Non-Hierarchical File Systems, Restrictions on Examining a Pathname Device Component, Interpreting Pathname Component Values
@subsubsection Restrictions on Examining a Pathname Directory Component

The directory might be a @i{string},
@t{:wild}, @t{:unspecific}, or @b{nil}.

The directory can be a @i{list} of @i{strings} and @i{symbols}. 

The @i{car} of the @i{list} is one of the symbols @t{:absolute}
@IKindex{absolute}
 or 
@t{:relative}
@IKindex{relative}
, meaning:

@table @asis

@item @t{:absolute}  
A @i{list} whose @i{car} is the symbol @t{:absolute} represents 
  a directory path starting from the root directory.  The list 
  @t{(:absolute)} represents the root directory.  The list 
  @t{(:absolute "foo" "bar" "baz")} represents the directory called
  @t{"/foo/bar/baz"} in Unix (except possibly for @i{case}).

@item @t{:relative}  
A @i{list} whose @i{car} is the symbol @t{:relative} represents 
  a directory path starting from a default directory.  
  The list @t{(:relative)} has the same meaning as @b{nil} and hence is not used.
  The list @t{(:relative "foo" "bar")} represents the directory named @t{"bar"} 
  in the directory named @t{"foo"} in the default directory.

@end table

Each remaining element of the @i{list} is a @i{string} or a @i{symbol}.

Each @i{string} names a single level of directory structure.
The @i{strings} should contain only the directory names 
themselves---no punctuation characters.

In place of a @i{string}, at any point in the @i{list}, @i{symbols} 
can occur to indicate special file notations.
Figure 19--3 lists the @i{symbols} that have standard meanings.
Implementations are permitted to add additional @i{objects} 
of any @i{type} that is disjoint from @b{string}
if necessary to represent features of their file systems that cannot be
represented with the standard @i{strings} and @i{symbols}.

Supplying any non-@i{string}, including any of the @i{symbols} listed below, 
to a file system for which it does not make sense
signals an error of @i{type} @b{file-error}.
For example, Unix does not support @t{:wild-inferiors} in most implementations.

@IKindex{wild}

@IKindex{wild-inferiors}

@IKindex{up}

@IKindex{back}

@group
@noindent
@w{  Symbol           Meaning                                             }
@w{  @t{:wild}            Wildcard match of one level of directory structure  }
@w{  @t{:wild-inferiors}  Wildcard match of any number of directory levels    }
@w{  @t{:up}              Go upward in directory structure (semantic)         }
@w{  @t{:back}            Go upward in directory structure (syntactic)        }

@noindent
@w{          Figure 19--3: Special Markers In Directory Component         }

@end group

The following notes apply to the previous figure:

@table @asis

@item Invalid Combinations  
Using @t{:absolute} or @t{:wild-inferiors} 
immediately followed by @t{:up} or @t{:back}
signals an error of @i{type} @b{file-error}.

@item Syntactic vs Semantic  
``Syntactic'' means that the action of @t{:back} 
depends only on the @i{pathname}
and not on the contents of the file system.  

``Semantic'' means that the action of @t{:up} 
depends on the contents of the file system; 
to resolve a @i{pathname} containing 
@t{:up} to a @i{pathname} whose directory component
contains only @t{:absolute} and 
@i{strings} requires probing the file system.

@t{:up} differs from 
@t{:back} only in file systems that support multiple
  names for directories, perhaps via symbolic links.  For example,
  suppose that there is a directory
@t{(:absolute "X" "Y" "Z")}
  linked to 
@t{(:absolute "A" "B" "C")}
  and there also exist directories
@t{(:absolute "A" "B" "Q")} and 
@t{(:absolute "X" "Y" "Q")}.
Then
@t{(:absolute "X" "Y" "Z" :up "Q")}
  designates
@t{(:absolute "A" "B" "Q")}
  while
@t{(:absolute "X" "Y" "Z" :back "Q")}
  designates
@t{(:absolute "X" "Y" "Q")}
@end table

@node Directory Components in Non-Hierarchical File Systems, Restrictions on Examining a Pathname Name Component, Restrictions on Examining a Pathname Directory Component, Interpreting Pathname Component Values
@subsubsection Directory Components in Non-Hierarchical File Systems

In non-hierarchical @i{file systems},
the only valid @i{list} values for the directory component of a @i{pathname}
are @t{(:absolute @i{string})} and @t{(:absolute :wild)}.
@t{:relative} directories and the keywords
@t{:wild-inferiors}, @t{:up}, and @t{:back} are not used 
in non-hierarchical @i{file systems}.

@node Restrictions on Examining a Pathname Name Component, Restrictions on Examining a Pathname Type Component, Directory Components in Non-Hierarchical File Systems, Interpreting Pathname Component Values
@subsubsection Restrictions on Examining a Pathname Name Component

The name might be a @i{string},
@t{:wild}, @t{:unspecific}, or @b{nil}.

@node Restrictions on Examining a Pathname Type Component, Restrictions on Examining a Pathname Version Component, Restrictions on Examining a Pathname Name Component, Interpreting Pathname Component Values
@subsubsection Restrictions on Examining a Pathname Type Component

The type might be a @i{string},
@t{:wild}, @t{:unspecific}, or @b{nil}.

@node Restrictions on Examining a Pathname Version Component, Notes about the Pathname Version Component, Restrictions on Examining a Pathname Type Component, Interpreting Pathname Component Values
@subsubsection Restrictions on Examining a Pathname Version Component

The version can be any @i{symbol} or any @i{integer}.  

The symbol @t{:newest} refers to the largest version number 
that already exists in the @i{file system}
when reading, overwriting, appending, superseding, or directory listing 
an existing @i{file}.
The symbol @t{:newest} refers to the smallest version number
greater than any existing version number when creating a new file.

The symbols @b{nil}, @t{:unspecific}, and @t{:wild} have special meanings and
restrictions; see @ref{Special Pathname Component Values} and @ref{Restrictions on Constructing Pathnames}.

Other @i{symbols} and @i{integers}
have @i{implementation-defined} meaning.

@node Notes about the Pathname Version Component, Restrictions on Constructing Pathnames, Restrictions on Examining a Pathname Version Component, Interpreting Pathname Component Values
@subsubsection Notes about the Pathname Version Component

It is suggested, but not required, that implementations do the following:

@table @asis

@item @t{*}  
Use positive @i{integers} starting at 1 as version numbers.

@item @t{*}  
Recognize the symbol @t{:oldest}
		 to designate the smallest existing version number.

@item @t{*}  
Use @i{keywords} for other special versions.

@end table

@node Restrictions on Constructing Pathnames,  , Notes about the Pathname Version Component, Interpreting Pathname Component Values
@subsubsection Restrictions on Constructing Pathnames

  When constructing a @i{pathname} from components, conforming programs
  must follow these rules:

@table @asis

@item @t{*}  
Any component can be @b{nil}.
  @b{nil} in the host might mean a default host 
  rather than an actual @b{nil} in some implementations.

@item @t{*}  
The host, device, directory, name, and type can be @i{strings}.  There
  are @i{implementation-dependent} limits on the number and type of
  @i{characters} in these @i{strings}.

@item @t{*}  
The directory can be a @i{list} of @i{strings} and @i{symbols}.
  There are @i{implementation-dependent} limits on the @i{list}'s
  length and contents.

@item @t{*}  
The version can be @t{:newest}.

@item @t{*}  
Any component can be taken 
  from the corresponding component of another @i{pathname}.
  When the two @i{pathnames} are for different file systems
    (in implementations that support multiple file systems),
  an appropriate translation occurs.
  If no meaningful translation is possible,
  an error is signaled.
  The definitions of ``appropriate'' and ``meaningful'' 
  are @i{implementation-dependent}.

@item @t{*}  
An implementation might support other values for some components,
  but a portable program cannot use those values.
  A conforming program can use @i{implementation-dependent} values
  but this can make it non-portable;
  for example, it might work only with @r{Unix} file systems.
@end table

@node Merging Pathnames,  , Interpreting Pathname Component Values, Pathnames
@subsection Merging Pathnames

Merging takes a @i{pathname} with unfilled components
and supplies values for those components from a source of defaults.

If a component's value is @b{nil}, that component is considered to be unfilled.
If a component's value is any @i{non-nil} @i{object}, 
including @t{:unspecific}, that component is considered to be filled.

Except as explicitly specified otherwise,
for functions that manipulate or inquire about @i{files} in the @i{file system},
the pathname argument to such a function
is merged with @b{*default-pathname-defaults*} before accessing the @i{file system}
(as if by @b{merge-pathnames}).

@menu
* Examples of Merging Pathnames::  
@end menu

@node Examples of Merging Pathnames,  , Merging Pathnames, Merging Pathnames
@subsubsection Examples of Merging Pathnames

Although the following examples are possible to execute only in
@i{implementations} which permit @t{:unspecific} in the indicated
position andwhich permit four-letter type components, they serve to illustrate
the basic concept of @i{pathname} merging.

@example
 (pathname-type 
   (merge-pathnames (make-pathname :type "LISP")
                    (make-pathname :type "TEXT")))
@result{}  "LISP"

 (pathname-type 
   (merge-pathnames (make-pathname :type nil)
                    (make-pathname :type "LISP")))
@result{}  "LISP"

 (pathname-type 
   (merge-pathnames (make-pathname :type :unspecific)
                    (make-pathname :type "LISP")))
@result{}  :UNSPECIFIC
@end example

@c end of including concept-pathnames

@node Logical Pathnames, Filenames Dictionary, Pathnames, Filenames
@section Logical Pathnames

@c including concept-logical-pathnames

@menu
* Syntax of Logical Pathname Namestrings::  
* Logical Pathname Components::	 
@end menu

@node Syntax of Logical Pathname Namestrings, Logical Pathname Components, Logical Pathnames, Logical Pathnames
@subsection Syntax of Logical Pathname Namestrings

The syntax of a @i{logical pathname} @i{namestring} is as follows.
(Note that unlike many notational descriptions in this document,
 this is a syntactic description of character sequences,
 not a structural description of @i{objects}.)

@w{@i{logical-pathname} ::=@r{[}!@i{host} @i{host-marker}@r{]} }
@w{                     @r{[}!@i{@i{relative-directory-marker}}@r{]} @{!@i{directory} @i{directory-marker}@}{*} }
@w{                     @r{[}!@i{name}@r{]} @r{[}@i{type-marker} !@i{type} @r{[}@i{version-marker} !@i{version}@r{]}@r{]}}

@w{@i{host} ::=!@i{word}}

@w{@i{directory} ::=!@i{word} | !@i{wildcard-word} | !@i{wild-inferiors-word}}

@w{@i{name} ::=!@i{word} | !@i{wildcard-word}}

@w{@i{type} ::=!@i{word} | !@i{wildcard-word}}

@w{@i{version} ::=!@i{pos-int} | @i{newest-word} | @i{wildcard-version}}

@i{host-marker}---a @i{colon}.

@i{relative-directory-marker}---a @i{semicolon}.

@i{directory-marker}---a @i{semicolon}.

@i{type-marker}---a @i{dot}.

@i{version-marker}---a @i{dot}.

@i{wild-inferiors-word}---The two character sequence ``@t{**}'' (two @i{asterisks}).

@i{newest-word}---The six character sequence ``@t{newest}'' 
		   or the six character sequence ``@t{NEWEST}''.

@i{wildcard-version}---an @i{asterisk}.

@i{wildcard-word}---one or more @i{asterisks}, uppercase letters,
   digits, and hyphens, including at least one @i{asterisk}, 
   with no two @i{asterisks} adjacent.

@i{word}---one or more uppercase letters, digits, and hyphens.

@i{pos-int}---a positive @i{integer}.

@menu
* Additional Information about Parsing Logical Pathname Namestrings::  
* The Host part of a Logical Pathname Namestring::  
* The Device part of a Logical Pathname Namestring::  
* The Directory part of a Logical Pathname Namestring::	 
* The Type part of a Logical Pathname Namestring::  
* The Version part of a Logical Pathname Namestring::  
* Wildcard Words in a Logical Pathname Namestring::  
* Lowercase Letters in a Logical Pathname Namestring::	
* Other Syntax in a Logical Pathname Namestring::  
@end menu

@node Additional Information about Parsing Logical Pathname Namestrings, The Host part of a Logical Pathname Namestring, Syntax of Logical Pathname Namestrings, Syntax of Logical Pathname Namestrings
@subsubsection Additional Information about Parsing Logical Pathname Namestrings

@node The Host part of a Logical Pathname Namestring, The Device part of a Logical Pathname Namestring, Additional Information about Parsing Logical Pathname Namestrings, Syntax of Logical Pathname Namestrings
@subsubsection The Host part of a Logical Pathname Namestring

The @i{host} must have been defined as a @i{logical pathname} host;
this can be done by using @b{setf} of @b{logical-pathname-translations}.

The @i{logical pathname} host name @t{"SYS"} is reserved for the implementation.
The existence and meaning of @t{SYS:} @i{logical pathnames} 
is @i{implementation-defined}.

@node The Device part of a Logical Pathname Namestring, The Directory part of a Logical Pathname Namestring, The Host part of a Logical Pathname Namestring, Syntax of Logical Pathname Namestrings
@subsubsection The Device part of a Logical Pathname Namestring

There is no syntax for a @i{logical pathname} device since
the device component of a @i{logical pathname} is always @t{:unspecific};
see @ref{Unspecific Components of a Logical Pathname}.

@node The Directory part of a Logical Pathname Namestring, The Type part of a Logical Pathname Namestring, The Device part of a Logical Pathname Namestring, Syntax of Logical Pathname Namestrings
@subsubsection The Directory part of a Logical Pathname Namestring

If a @i{relative-directory-marker} precedes the @i{directories},
the directory component parsed is as @i{relative};
otherwise, the directory component is parsed as @i{absolute}.

If a @i{wild-inferiors-marker} is specified,
it parses into @t{:wild-inferiors}.

@node The Type part of a Logical Pathname Namestring, The Version part of a Logical Pathname Namestring, The Directory part of a Logical Pathname Namestring, Syntax of Logical Pathname Namestrings
@subsubsection The Type part of a Logical Pathname Namestring

The @i{type} of a @i{logical pathname} for a @i{source file}
is @t{"LISP"}.   This should be translated into whatever type is 
appropriate in a physical pathname.

@node The Version part of a Logical Pathname Namestring, Wildcard Words in a Logical Pathname Namestring, The Type part of a Logical Pathname Namestring, Syntax of Logical Pathname Namestrings
@subsubsection The Version part of a Logical Pathname Namestring

Some @i{file systems} do not have @i{versions}. 
@i{Logical pathname} translation to such a @i{file system}
ignores the @i{version}.
This implies that a program cannot rely on being able to store
more than one version of a file named by a @i{logical pathname}.

If a @i{wildcard-version} is specified,
it parses into @t{:wild}.

@node Wildcard Words in a Logical Pathname Namestring, Lowercase Letters in a Logical Pathname Namestring, The Version part of a Logical Pathname Namestring, Syntax of Logical Pathname Namestrings
@subsubsection Wildcard Words in a Logical Pathname Namestring

Each @i{asterisk} in a @i{wildcard-word} matches a sequence of 
zero or more characters.  The @i{wildcard-word} ``@t{*}'' 
parses into @t{:wild}; other @i{wildcard-words} parse into @i{strings}.

@node Lowercase Letters in a Logical Pathname Namestring, Other Syntax in a Logical Pathname Namestring, Wildcard Words in a Logical Pathname Namestring, Syntax of Logical Pathname Namestrings
@subsubsection Lowercase Letters in a Logical Pathname Namestring

When parsing @i{words} and @i{wildcard-words},
lowercase letters are translated to uppercase.

@node Other Syntax in a Logical Pathname Namestring,  , Lowercase Letters in a Logical Pathname Namestring, Syntax of Logical Pathname Namestrings
@subsubsection Other Syntax in a Logical Pathname Namestring

The consequences of using characters other than those specified here
in a @i{logical pathname} @i{namestring} are unspecified.

The consequences of using any value not specified here as a 
@i{logical pathname} component are unspecified.

@node Logical Pathname Components,  , Syntax of Logical Pathname Namestrings, Logical Pathnames
@subsection Logical Pathname Components

@menu
* Unspecific Components of a Logical Pathname::	 
* Null Strings as Components of a Logical Pathname::  
@end menu

@node Unspecific Components of a Logical Pathname, Null Strings as Components of a Logical Pathname, Logical Pathname Components, Logical Pathname Components
@subsubsection Unspecific Components of a Logical Pathname

The device component of a @i{logical pathname} is always @t{:unspecific};
no other component of a @i{logical pathname} can be @t{:unspecific}.  

@node Null Strings as Components of a Logical Pathname,  , Unspecific Components of a Logical Pathname, Logical Pathname Components
@subsubsection Null Strings as Components of a Logical Pathname

The null string, @t{""}, is not a valid value for any component of a @i{logical pathname}.

@c end of including concept-logical-pathnames

@node Filenames Dictionary,  , Logical Pathnames, Filenames
@section Filenames Dictionary

@c including dict-pathnames

@menu
* pathname (System Class)::	
* logical-pathname (System Class)::  
* pathname::			
* make-pathname::		
* pathnamep::			
* pathname-host::		
* load-logical-pathname-translations::	
* logical-pathname-translations::  
* logical-pathname::		
* *default-pathname-defaults*::	 
* namestring::			
* parse-namestring::		
* wild-pathname-p::		
* pathname-match-p::		
* translate-logical-pathname::	
* translate-pathname::		
* merge-pathnames::		
@end menu

@node pathname (System Class), logical-pathname (System Class), Filenames Dictionary, Filenames Dictionary
@subsection pathname                                                     [System Class]

@subsubheading  Class Precedence List::
@b{pathname},
@b{t}

@subsubheading  Description::

A @i{pathname} is a structured @i{object} which represents a @i{filename}.

There are two kinds of @i{pathnames}---@i{physical pathnames} and
@i{logical pathnames}.

@node logical-pathname (System Class), pathname, pathname (System Class), Filenames Dictionary
@subsection logical-pathname                                             [System Class]

@subsubheading  Class Precedence List::

@b{logical-pathname},
@b{pathname},
@b{t}

@subsubheading  Description::

A @i{pathname} that uses a @i{namestring} syntax that is 
@i{implementation-independent}, 
and that has component values that are @i{implementation-independent}.
@i{Logical pathnames} do not refer directly to @i{filenames}

@subsubheading  See Also::

@ref{File System Concepts},
@ref{Sharpsign P},
@ref{Printing Pathnames}

@node pathname, make-pathname, logical-pathname (System Class), Filenames Dictionary
@subsection pathname                                                         [Function]

@code{pathname}  @i{pathspec} @result{}  @i{pathname}

@subsubheading  Arguments and Values::

@i{pathspec}---a @i{pathname designator}.

@i{pathname}---a @i{pathname}.

@subsubheading  Description::

Returns the @i{pathname} denoted by @i{pathspec}.

If the @i{pathspec} @i{designator} is a @i{stream},
the @i{stream} can be either open or closed;
in both cases, the @b{pathname} returned 
corresponds to the @i{filename} used to open the @i{file}.
@b{pathname} returns the same @i{pathname} for a @i{file stream}
after it is closed as it did when it was open.

If the @i{pathspec} @i{designator} is
a @i{file stream} created by opening a @i{logical pathname},
a @i{logical pathname} is returned.

@subsubheading  Examples::

@example
 ;; There is a great degree of variability permitted here.  The next
 ;; several examples are intended to illustrate just a few of the many
 ;; possibilities.  Whether the name is canonicalized to a particular
 ;; case (either upper or lower) depends on both the file system and the
 ;; implementation since two different implementations using the same
 ;; file system might differ on many issues.  How information is stored
 ;; internally (and possibly presented in #S notation) might vary,
 ;; possibly requiring `accessors' such as PATHNAME-NAME to perform case
 ;; conversion upon access.  The format of a namestring is dependent both
 ;; on the file system and the implementation since, for example, one
 ;; implementation might include the host name in a namestring, and
 ;; another might not.  #S notation would generally only be used in a
 ;; situation where no appropriate namestring could be constructed for use
 ;; with #P.
 (setq p1 (pathname "test"))
@result{}  #P"CHOCOLATE:TEST" ; with case canonicalization (e.g., VMS)
@i{OR}@result{} #P"VANILLA:test"   ; without case canonicalization (e.g., Unix)
@i{OR}@result{} #P"test"
@i{OR}@result{} #S(PATHNAME :HOST "STRAWBERRY" :NAME "TEST")
@i{OR}@result{} #S(PATHNAME :HOST "BELGIAN-CHOCOLATE" :NAME "test")
 (setq p2 (pathname "test"))
@result{}  #P"CHOCOLATE:TEST"
@i{OR}@result{} #P"VANILLA:test"
@i{OR}@result{} #P"test"
@i{OR}@result{} #S(PATHNAME :HOST "STRAWBERRY" :NAME "TEST")
@i{OR}@result{} #S(PATHNAME :HOST "BELGIAN-CHOCOLATE" :NAME "test")
 (pathnamep p1) @result{}  @i{true}
 (eq p1 (pathname p1)) @result{}  @i{true}
 (eq p1 p2)
@result{}  @i{true}
@i{OR}@result{} @i{false}
 (with-open-file (stream "test" :direction :output)
   (pathname stream))
@result{}  #P"ORANGE-CHOCOLATE:>Gus>test.lisp.newest"
@end example

@subsubheading  See Also::

@b{pathname},
@b{logical-pathname},
@ref{File System Concepts},

@ref{Pathnames as Filenames}

@node make-pathname, pathnamep, pathname, Filenames Dictionary
@subsection make-pathname                                                    [Function]

@code{make-pathname}  @i{{&key} host device directory name type version defaults case}@*
   @result{}  @i{pathname}

@subsubheading  Arguments and Values::

@i{host}---a @i{valid physical pathname host}.
 Complicated defaulting behavior; see below.

@i{device}---a @i{valid pathname device}.
 Complicated defaulting behavior; see below.

@i{directory}---a @i{valid pathname directory}.
 Complicated defaulting behavior; see below.

@i{name}---a @i{valid pathname name}.
 Complicated defaulting behavior; see below.

@i{type}---a @i{valid pathname type}.
 Complicated defaulting behavior; see below.

@i{version}---a @i{valid pathname version}.
 Complicated defaulting behavior; see below.

@i{defaults}---a @i{pathname designator}.
 The default is a @i{pathname} whose host component is the same as the
          host component of the @i{value} of @b{*default-pathname-defaults*},
	  and whose other components are all @b{nil}.

@i{case}---one of @t{:common} or @t{:local}.
 The default is @t{:local}.

@i{pathname}---a @i{pathname}.

@subsubheading  Description::

Constructs and returns a @i{pathname} from the supplied keyword arguments.

After the components supplied explicitly by
       @i{host},
       @i{device}, 
       @i{directory},
       @i{name},
       @i{type},
   and @i{version} 
are filled in, 
the merging rules used by @b{merge-pathnames} 
are used to fill in any 
unsupplied
components
from the defaults supplied by @i{defaults}.

Whenever a @i{pathname} is constructed the components may be 
canonicalized if appropriate.
For the explanation of the arguments that can be supplied for each component,
see @ref{Pathname Components}.

If @i{case} is supplied,
it is treated as described in @ref{Case in Pathname Components}.

The resulting @i{pathname} is a @i{logical pathname} 
if and only its host component 
is
a @i{logical host} 
or a @i{string} that names a defined @i{logical host}.

If the @i{directory} is a @i{string},
it should be the name of a top level directory,
and should not contain any punctuation characters; that is,
specifying a @i{string}, @i{str}, is
equivalent to specifying the list @t{(:absolute @i{str})}.
Specifying the symbol @t{:wild} is equivalent to specifying the list 
@t{(:absolute :wild-inferiors)}, or @t{(:absolute :wild)} 
in a file system that does not support @t{:wild-inferiors}.

@subsubheading  Examples::

@example
 ;; Implementation A -- an implementation with access to a single
 ;;  Unix file system.  This implementation happens to never display
 ;;  the `host' information in a namestring, since there is only one host. 
 (make-pathname :directory '(:absolute "public" "games")
                :name "chess" :type "db")
@result{}  #P"/public/games/chess.db" 

 ;; Implementation B -- an implementation with access to one or more
 ;;  VMS file systems.  This implementation displays `host' information
 ;;  in the namestring only when the host is not the local host.
 ;;  It uses a double colon to separate a host name from the host's local
 ;;  file name.
 (make-pathname :directory '(:absolute "PUBLIC" "GAMES")
                :name "CHESS" :type "DB")
@result{}  #P"SYS$DISK:[PUBLIC.GAMES]CHESS.DB" 
 (make-pathname :host "BOBBY"
                :directory '(:absolute "PUBLIC" "GAMES")
                :name "CHESS" :type "DB")
@result{}  #P"BOBBY::SYS$DISK:[PUBLIC.GAMES]CHESS.DB" 

 ;; Implementation C -- an implementation with simultaneous access to
 ;;  multiple file systems from the same Lisp image.  In this 
 ;;  implementation, there is a convention that any text preceding the
 ;;  first colon in a pathname namestring is a host name.
 (dolist (case '(:common :local))
   (dolist (host '("MY-LISPM" "MY-VAX" "MY-UNIX"))
     (print (make-pathname :host host :case case
                           :directory '(:absolute "PUBLIC" "GAMES")
                           :name "CHESS" :type "DB"))))
@t{ |> } #P"MY-LISPM:>public>games>chess.db"
@t{ |> } #P"MY-VAX:SYS$DISK:[PUBLIC.GAMES]CHESS.DB"
@t{ |> } #P"MY-UNIX:/public/games/chess.db"
@t{ |> } #P"MY-LISPM:>public>games>chess.db" 
@t{ |> } #P"MY-VAX:SYS$DISK:[PUBLIC.GAMES]CHESS.DB" 
@t{ |> } #P"MY-UNIX:/PUBLIC/GAMES/CHESS.DB" 
@result{}  NIL
@end example

@subsubheading  Affected By::

The @i{file system}.

@subsubheading  See Also::

@ref{merge-pathnames}
,
@b{pathname},
@b{logical-pathname},
@ref{File System Concepts},

@ref{Pathnames as Filenames}

@subsubheading  Notes::

Portable programs should not supply @t{:unspecific} for any component.
See @ref{->UNSPECIFIC as a Component Value}.

@node pathnamep, pathname-host, make-pathname, Filenames Dictionary
@subsection pathnamep                                                        [Function]

@code{pathnamep}  @i{object} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

@i{object}---an @i{object}.

@i{generalized-boolean}---a @i{generalized boolean}.

@subsubheading  Description::

Returns @i{true} if @i{object} is of @i{type} @b{pathname};
otherwise, returns @i{false}.

@subsubheading  Examples::

@example
 (setq q "test")  @result{}  "test"
 (pathnamep q) @result{}  @i{false}
 (setq q (pathname "test"))
@result{}  #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME "test" :TYPE NIL
       :VERSION NIL)
 (pathnamep q) @result{}  @i{true} 
 (setq q (logical-pathname "SYS:SITE;FOO.SYSTEM"))
@result{}  #P"SYS:SITE;FOO.SYSTEM"
 (pathnamep q) @result{}  @i{true}
@end example

@subsubheading  Notes::

@example
 (pathnamep @i{object}) @equiv{} (typep @i{object} 'pathname)
@end example

@node pathname-host, load-logical-pathname-translations, pathnamep, Filenames Dictionary
@subsection pathname-host, pathname-device, pathname-directory,
@subheading pathname-name, pathname-type,   pathname-version
@flushright
@i{[Function]}
@end flushright

@code{pathname-host}  @i{pathname {&key} case} @result{}  @i{host}

@code{pathname-device}  @i{pathname {&key} case} @result{}  @i{device}

@code{pathname-directory}  @i{pathname {&key} case} @result{}  @i{directory}

@code{pathname-name}  @i{pathname {&key} case} @result{}  @i{name}

@code{pathname-type}  @i{pathname {&key} case} @result{}  @i{type}

@code{pathname-version}  @i{pathname} @result{}  @i{version}

@subsubheading  Arguments and Values::

@i{pathname}---a @i{pathname designator}.

@i{case}---one of @t{:local} or @t{:common}.
 The default is @t{:local}.

@i{host}---a @i{valid pathname host}.

@i{device}---a @i{valid pathname device}.

@i{directory}---a @i{valid pathname directory}.

@i{name}---a @i{valid pathname name}.

@i{type}---a @i{valid pathname type}.

@i{version}---a @i{valid pathname version}.

@subsubheading  Description::

These functions return the components of @i{pathname}.

If the @i{pathname} @i{designator} is a @i{pathname},
it represents the name used to open the file. This may be, but is
not required to be, the actual name of the file. 

If @i{case} is supplied,
it is treated as described in @ref{Case in Pathname Components}.

@subsubheading  Examples::

@example
 (setq q (make-pathname :host "KATHY"
                        :directory "CHAPMAN" 
                        :name "LOGIN" :type "COM"))
@result{}  #P"KATHY::[CHAPMAN]LOGIN.COM"
 (pathname-host q) @result{}  "KATHY"
 (pathname-name q) @result{}  "LOGIN"
 (pathname-type q) @result{}  "COM"

 ;; Because namestrings are used, the results shown in the remaining
 ;; examples are not necessarily the only possible results.  Mappings
 ;; from namestring representation to pathname representation are 
 ;; dependent both on the file system involved and on the implementation
 ;; (since there may be several implementations which can manipulate the
 ;; the same file system, and those implementations are not constrained
 ;; to agree on all details). Consult the documentation for each
 ;; implementation for specific information on how namestrings are treated
 ;; that implementation.

 ;; VMS
 (pathname-directory (parse-namestring "[FOO.*.BAR]BAZ.LSP"))
@result{}  (:ABSOLUTE "FOO" "BAR")
 (pathname-directory (parse-namestring "[FOO.*.BAR]BAZ.LSP") :case :common)
@result{}  (:ABSOLUTE "FOO" "BAR")

 ;; Unix
 (pathname-directory "foo.l") @result{}  NIL
 (pathname-device "foo.l") @result{}  :UNSPECIFIC
 (pathname-name "foo.l") @result{}  "foo"
 (pathname-name "foo.l" :case :local) @result{}  "foo"
 (pathname-name "foo.l" :case :common) @result{}  "FOO"
 (pathname-type "foo.l") @result{}  "l"
 (pathname-type "foo.l" :case :local) @result{}  "l"
 (pathname-type "foo.l" :case :common) @result{}  "L"
 (pathname-type "foo") @result{}  :UNSPECIFIC
 (pathname-type "foo" :case :common) @result{}  :UNSPECIFIC
 (pathname-type "foo.") @result{}  ""
 (pathname-type "foo." :case :common) @result{}  ""
 (pathname-directory (parse-namestring "/foo/bar/baz.lisp") :case :local)
@result{}  (:ABSOLUTE "foo" "bar")
 (pathname-directory (parse-namestring "/foo/bar/baz.lisp") :case :local)
@result{}  (:ABSOLUTE "FOO" "BAR")
 (pathname-directory (parse-namestring "../baz.lisp"))
@result{}  (:RELATIVE :UP)
 (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/BAR/../Mum/baz"))
@result{}  (:ABSOLUTE "foo" "BAR" :UP "Mum")
 (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/BAR/../Mum/baz") :case :common)
@result{}  (:ABSOLUTE "FOO" "bar" :UP "Mum")
 (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/*/bar/baz.l"))
@result{}  (:ABSOLUTE "foo" :WILD "bar")
 (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/*/bar/baz.l") :case :common)
@result{}  (:ABSOLUTE "FOO" :WILD "BAR")

 ;; Symbolics LMFS
 (pathname-directory (parse-namestring ">foo>**>bar>baz.lisp"))
@result{}  (:ABSOLUTE "foo" :WILD-INFERIORS "bar")
 (pathname-directory (parse-namestring ">foo>*>bar>baz.lisp"))
@result{}  (:ABSOLUTE "foo" :WILD "bar")
 (pathname-directory (parse-namestring ">foo>*>bar>baz.lisp") :case :common)
@result{}  (:ABSOLUTE "FOO" :WILD "BAR")
 (pathname-device (parse-namestring ">foo>baz.lisp")) @result{}  :UNSPECIFIC
@end example

@subsubheading  Affected By::

The @i{implementation} and the host @i{file system}.

@subsubheading  Exceptional Situations::

Should signal an error of @i{type} @b{type-error} if its first argument is not a @i{pathname}.

@subsubheading  See Also::

@b{pathname},
@b{logical-pathname},
@ref{File System Concepts},

@ref{Pathnames as Filenames}

@node load-logical-pathname-translations, logical-pathname-translations, pathname-host, Filenames Dictionary
@subsection load-logical-pathname-translations                               [Function]

@code{load-logical-pathname-translations}  @i{host} @result{}  @i{just-loaded}

@subsubheading  Arguments and Values::

@i{host}---a @i{string}.

@i{just-loaded}---a @i{generalized boolean}.

@subsubheading  Description::

Searches for and loads the definition of a @i{logical host} named @i{host},
if it is not already defined.
The specific nature of the search is @i{implementation-defined}.

If the @i{host} is already defined, 
no attempt to find or load a definition is attempted,
and @i{false} is returned.
If the @i{host} is not already defined,
but a definition is successfully found and loaded,
@i{true} is returned.
Otherwise, an error is signaled.

@subsubheading  Examples::

@example
 (translate-logical-pathname "hacks:weather;barometer.lisp.newest")
@t{ |> } Error: The logical host HACKS is not defined.
 (load-logical-pathname-translations "HACKS")
@t{ |> } ;; Loading SYS:SITE;HACKS.TRANSLATIONS
@t{ |> } ;; Loading done.
@result{}  @i{true}
 (translate-logical-pathname "hacks:weather;barometer.lisp.newest")
@result{}  #P"HELIUM:[SHARED.HACKS.WEATHER]BAROMETER.LSP;0"
 (load-logical-pathname-translations "HACKS")
@result{}  @i{false}
@end example

@subsubheading  Exceptional Situations::

If no definition is found, an error of @i{type} @b{error} is signaled.

@subsubheading  See Also::

@b{logical-pathname}

@subsubheading  Notes::

@i{Logical pathname} definitions will be created not just by 
@i{implementors} but also by @i{programmers}.  As such,
it is important that the search strategy be documented.
For example, an @i{implementation} might define that the
definition of a @i{host} is to be found in a file called
``@i{host}.translations'' in some specifically named directory.

@node logical-pathname-translations, logical-pathname, load-logical-pathname-translations, Filenames Dictionary
@subsection logical-pathname-translations                                    [Accessor]

@code{logical-pathname-translations}  @i{host} @result{}  @i{translations}

(setf (@code{         logical-pathname-translations} @i{host}) new-translations)@*

@subsubheading  Arguments and Values::

@i{host}--a @i{logical host designator}.

@i{translations}, @i{new-translations}---a @i{list}.

@subsubheading  Description::

Returns the host's @i{list} of translations.
Each translation is a @i{list} of at least two elements: 
@i{from-wildcard} and @i{to-wildcard}.  Any
    additional elements are @i{implementation-defined}.  
@i{From-wildcard} is a
    @i{logical pathname} whose host is @i{host}.  
@i{To-wildcard} is a @i{pathname}.    

[Reviewer Note by Laddaga: Can this be a logical pathname?]

@t{(setf (logical-pathname-translations @i{host}) @i{translations})} sets a 
@i{logical pathname} host's
@i{list} of @i{translations}.  If @i{host} 
is a @i{string} that has
    not been previously used as 
a @i{logical pathname} host, a new 
@i{logical pathname} host is defined; 
otherwise an existing host's translations are
    replaced.  @i{logical pathname} host names are compared with @b{string-equal}.

    When setting the translations list, each @i{from-wildcard} 
can be a @i{logical pathname} whose
host is @i{host} or a @i{logical pathname} namestring
    parseable by @t{(parse-namestring @i{string} @i{host})}, 
where @i{host}
    represents the appropriate @i{object} as defined 
by @b{parse-namestring}. Each
    @i{to-wildcard} can be anything coercible to a 
@i{pathname} by
    @t{(pathname @i{to-wildcard})}.  
If @i{to-wildcard} coerces to a @i{logical pathname},
@b{translate-logical-pathname} 
will perform repeated translation steps when
    it uses it.

@i{host} is either the host component of a 
@i{logical pathname} or a
    @i{string} that has been defined 
as a @i{logical pathname} host name by @b{setf} of
@b{logical-pathname-translations}. 

@subsubheading  Examples::

[Reviewer Note by Laddaga: Shouldn't there be some @t{*.*}'s in the list
		   of translations for @t{PROG} below?]

@example
 ;;;A very simple example of setting up a logical pathname host.  No
 ;;;translations are necessary to get around file system restrictions, so
 ;;;all that is necessary is to specify the root of the physical directory
 ;;;tree that contains the logical file system.
 ;;;The namestring syntax on the right-hand side is implementation-dependent.
 (setf (logical-pathname-translations "foo")
       '(("**;*.*.*"              "MY-LISPM:>library>foo>**>")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "foo:bar;baz;mum.quux.3")
@result{}  #P"MY-LISPM:>library>foo>bar>baz>mum.quux.3"

 ;;;A more complex example, dividing the files among two file servers
 ;;;and several different directories.  This Unix doesn't support
 ;;;:WILD-INFERIORS in the directory, so each directory level must
 ;;;be translated individually.  No file name or type translations
 ;;;are required except for .MAIL to .MBX.
 ;;;The namestring syntax on the right-hand side is implementation-dependent.
 (setf (logical-pathname-translations "prog")
       '(("RELEASED;*.*.*"        "MY-UNIX:/sys/bin/my-prog/")
         ("RELEASED;*;*.*.*"      "MY-UNIX:/sys/bin/my-prog/*/")
         ("EXPERIMENTAL;*.*.*"    "MY-UNIX:/usr/Joe/development/prog/")
         ("EXPERIMENTAL;DOCUMENTATION;*.*.*"
                                  "MY-VAX:SYS$DISK:[JOE.DOC]")
         ("EXPERIMENTAL;*;*.*.*"  "MY-UNIX:/usr/Joe/development/prog/*/")
         ("MAIL;**;*.MAIL"        "MY-VAX:SYS$DISK:[JOE.MAIL.PROG...]*.MBX")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:mail;save;ideas.mail.3")
@result{}  #P"MY-VAX:SYS$DISK:[JOE.MAIL.PROG.SAVE]IDEAS.MBX.3"

 ;;;Example translations for a program that uses three files main.lisp,
 ;;;auxiliary.lisp, and documentation.lisp.  These translations might be
 ;;;supplied by a software supplier as examples.

 ;;;For Unix with long file names
 (setf (logical-pathname-translations "prog")
       '(("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
@result{}  #P"/lib/prog/documentation.lisp"

 ;;;For Unix with 14-character file names, using .lisp as the type
 (setf (logical-pathname-translations "prog")
       '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
         ("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
@result{}  #P"/lib/prog/docum.lisp"

 ;;;For Unix with 14-character file names, using .l as the type
 ;;;The second translation shortens the compiled file type to .b
 (setf (logical-pathname-translations "prog")
       `(("**;*.LISP.*"            ,(logical-pathname "PROG:**;*.L.*"))
         (,(compile-file-pathname (logical-pathname "PROG:**;*.LISP.*"))
                                   ,(logical-pathname "PROG:**;*.B.*"))
         ("CODE;DOCUMENTATION.*.*" "/lib/prog/documentatio.*")
         ("CODE;*.*.*"             "/lib/prog/")))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
@result{}  #P"/lib/prog/documentatio.l"

 ;;;For a Cray with 6 character names and no directories, types, or versions.
 (setf (logical-pathname-translations "prog")
       (let ((l '(("MAIN" "PGMN")
                  ("AUXILIARY" "PGAUX")
                  ("DOCUMENTATION" "PGDOC")))
             (logpath (logical-pathname "prog:code;"))
             (phypath (pathname "XXX")))
         (append
           ;; Translations for source files
           (mapcar #'(lambda (x)
                       (let ((log (first x))
                             (phy (second x)))
                         (list (make-pathname :name log
                                              :type "LISP"
                                              :version :wild
                                              :defaults logpath)
                               (make-pathname :name phy
                                              :defaults phypath))))
                   l)
           ;; Translations for compiled files
           (mapcar #'(lambda (x)
                       (let* ((log (first x))
                              (phy (second x))
                              (com (compile-file-pathname
                                     (make-pathname :name log
                                                    :type "LISP"
                                                    :version :wild
                                                    :defaults logpath))))
                         (setq phy (concatenate 'string phy "B"))
                         (list com
                               (make-pathname :name phy
                                              :defaults phypath))))
                   l))))

 ;;;Sample use of that logical pathname.  The return value
 ;;;is implementation-dependent.          
 (translate-logical-pathname "prog:code;documentation.lisp")
@result{}  #P"PGDOC"
@end example

@subsubheading  Exceptional Situations::

If @i{host} is incorrectly supplied, 
an error of @i{type} @b{type-error} is signaled.

@subsubheading  See Also::

@b{logical-pathname},

@ref{Pathnames as Filenames}

@subsubheading  Notes::

Implementations can define additional @i{functions}
that operate on @i{logical pathname} hosts,
for example to specify additional translation rules or options.

@node logical-pathname, *default-pathname-defaults*, logical-pathname-translations, Filenames Dictionary
@subsection logical-pathname                                                 [Function]

@code{logical-pathname}  @i{pathspec} @result{}  @i{logical-pathname}

@subsubheading  Arguments and Values::

@i{pathspec}---a @i{logical pathname}, 
		   a @i{logical pathname} @i{namestring},
		or a @i{stream}.

@i{logical-pathname}---a @i{logical pathname}.

@subsubheading  Description::

@b{logical-pathname} converts @i{pathspec} to a
@i{logical pathname} and returns the new @i{logical pathname}.
If @i{pathspec} is a @i{logical pathname} @i{namestring},
it should contain a host component and its following @i{colon}.
If @i{pathspec} is a @i{stream}, it should be one
for which @b{pathname} returns a @i{logical pathname}.  

If @i{pathspec} is a @i{stream}, the @i{stream} can be either open or closed.
@b{logical-pathname} returns the same @i{logical pathname} after a
file is closed as it did when the file was open.

It is an error if @i{pathspec} is a @i{stream} that is 
created with
  @b{make-two-way-stream}, 
  @b{make-echo-stream},             
  @b{make-broadcast-stream}, 
  @b{make-concatenated-stream},
  @b{make-string-input-stream},
or
  @b{make-string-output-stream}.

@subsubheading  Exceptional Situations::

Signals an error of @i{type} @b{type-error} if @i{pathspec} isn't supplied correctly.

@subsubheading  See Also::

@b{logical-pathname},
@ref{translate-logical-pathname}
,
@ref{Logical Pathnames}

@node *default-pathname-defaults*, namestring, logical-pathname, Filenames Dictionary
@subsection *default-pathname-defaults*                                      [Variable]

@subsubheading  Value Type::

a @i{pathname} @i{object}.

@subsubheading  Initial Value::

An @i{implementation-dependent} @i{pathname}, 
typically in the working directory that was current when @r{Common Lisp} was started up.

@subsubheading  Description::

a @i{pathname}, used as the default whenever a @i{function}
needs a default @i{pathname} and one is not supplied.

@subsubheading  Examples::                                                   
@example
 ;; This example illustrates a possible usage for a hypothetical Lisp running on a
 ;; DEC TOPS-20 file system.  Since pathname conventions vary between Lisp 
 ;; implementations and host file system types, it is not possible to provide a
 ;; general-purpose, conforming example.
 *default-pathname-defaults* @result{}  #P"PS:<FRED>"
 (merge-pathnames (make-pathname :name "CALENDAR"))
@result{}  #P"PS:<FRED>CALENDAR"
 (let ((*default-pathname-defaults* (pathname "<MARY>")))
   (merge-pathnames (make-pathname :name "CALENDAR")))
@result{}  #P"<MARY>CALENDAR"
@end example

@subsubheading  Affected By::

The @i{implementation}.

@node namestring, parse-namestring, *default-pathname-defaults*, Filenames Dictionary
@subsection namestring, file-namestring, directory-namestring, 
@subheading host-namestring, enough-namestring
@flushright
@i{[Function]}
@end flushright

@code{namestring}  @i{pathname} @result{}  @i{namestring}

@code{file-namestring}  @i{pathname} @result{}  @i{namestring}

@code{directory-namestring}  @i{pathname} @result{}  @i{namestring}

@code{host-namestring}  @i{pathname} @result{}  @i{namestring}

@code{enough-namestring}  @i{pathname {&optional} defaults} @result{}  @i{namestring}

@subsubheading  Arguments and Values::

@i{pathname}---a @i{pathname designator}.

@i{defaults}---a @i{pathname designator}.

 The default is the @i{value} of @b{*default-pathname-defaults*}.

@i{namestring}---a @i{string} or @b{nil}.

[Editorial Note by KMP: Under what circumstances can NIL be returned??]

@subsubheading  Description::

These functions convert @i{pathname} into a namestring.
The name represented by @i{pathname} is returned as a @i{namestring}
in an @i{implementation-dependent} canonical form.

@b{namestring} returns the full form of @i{pathname}.

@b{file-namestring} returns just the name, type, and version
 components of @i{pathname}.

@b{directory-namestring} returns the directory name portion.

@b{host-namestring} returns the host name. 

@b{enough-namestring} returns an abbreviated namestring 
 that is just sufficient to identify the file named by @i{pathname}
 when considered relative to the @i{defaults}.
 It is required that

@example
 (merge-pathnames (enough-namestring pathname defaults) defaults)
@equiv{} (merge-pathnames (parse-namestring pathname nil defaults) defaults)
@end example

in all cases, and the result of @b{enough-namestring} is
the shortest reasonable @i{string} that will satisfy this criterion.

It is not necessarily possible to construct a valid @i{namestring} 
by concatenating some of the three shorter @i{namestrings} in some order.

@subsubheading  Examples::

@example
 (namestring "getty")            
@result{}  "getty"
 (setq q (make-pathname :host "kathy" 
                         :directory 
                           (pathname-directory *default-pathname-defaults*)
                         :name "getty")) 
@result{}  #S(PATHNAME :HOST "kathy" :DEVICE NIL :DIRECTORY @i{directory-name} 
       :NAME "getty" :TYPE NIL :VERSION NIL)
 (file-namestring q) @result{}  "getty"
 (directory-namestring q) @result{}  @i{directory-name}
 (host-namestring q) @result{}  "kathy" 
@end example

@example
 ;;;Using Unix syntax and the wildcard conventions used by the
 ;;;particular version of Unix on which this example was created:
 (namestring
   (translate-pathname "/usr/dmr/hacks/frob.l"
                       "/usr/d*/hacks/*.l"
                       "/usr/d*/backup/hacks/backup-*.*"))
@result{}  "/usr/dmr/backup/hacks/backup-frob.l"
 (namestring
   (translate-pathname "/usr/dmr/hacks/frob.l"
                       "/usr/d*/hacks/fr*.l"
                       "/usr/d*/backup/hacks/backup-*.*"))
@result{}  "/usr/dmr/backup/hacks/backup-ob.l"

 ;;;This is similar to the above example but uses two different hosts,
 ;;;U: which is a Unix and V: which is a VMS.  Note the translation
 ;;;of file type and alphabetic case conventions.
 (namestring
   (translate-pathname "U:/usr/dmr/hacks/frob.l"
                       "U:/usr/d*/hacks/*.l"
                       "V:SYS$DISK:[D*.BACKUP.HACKS]BACKUP-*.*"))
@result{}  "V:SYS$DISK:[DMR.BACKUP.HACKS]BACKUP-FROB.LSP"
 (namestring
   (translate-pathname "U:/usr/dmr/hacks/frob.l"
                       "U:/usr/d*/hacks/fr*.l"
                       "V:SYS$DISK:[D*.BACKUP.HACKS]BACKUP-*.*"))
@result{}  "V:SYS$DISK:[DMR.BACKUP.HACKS]BACKUP-OB.LSP"
@end example

@subsubheading  See Also::

@ref{truename}
,
@ref{merge-pathnames}
,
@b{pathname},
@b{logical-pathname},
@ref{File System Concepts},

@ref{Pathnames as Filenames}

@node parse-namestring, wild-pathname-p, namestring, Filenames Dictionary
@subsection parse-namestring                                                 [Function]

@code{parse-namestring}  @i{thing {&optional} host default-pathname {&key} start end junk-allowed}@*
   @result{}  @i{pathname, position}

@subsubheading  Arguments and Values::

@i{thing}---a @i{string},
	        a @i{pathname},
	     or a @i{stream associated with a file}.

@i{host}---a @i{valid pathname host}, a @i{logical host}, or @b{nil}.

@i{default-pathname}---a @i{pathname designator}.
 The default is the @i{value} of @b{*default-pathname-defaults*}.

@i{start}, @i{end}---@i{bounding index designators} of @i{thing}.
 The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.

@i{junk-allowed}---a @i{generalized boolean}.
  The default is @i{false}.

@i{pathname}---a @i{pathname}, or @b{nil}.

@i{position}---a @i{bounding index designator} for @i{thing}.

@subsubheading  Description::

Converts @i{thing} into a @i{pathname}.

The @i{host} supplies a host name with respect to which the parsing occurs.

If @i{thing} is a @i{stream associated with a file},
processing proceeds as if the @i{pathname} used to open that @i{file}
had been supplied instead.

If @i{thing} is a @i{pathname},
the @i{host} and the host component of @i{thing} are compared.
If they match, 
two values are immediately returned: @i{thing} and @i{start};
otherwise (if they do not match), an error is signaled.

Otherwise (if @i{thing} is a @i{string}),
@b{parse-namestring} parses the name of a @i{file} within
the substring of @i{thing} bounded by @i{start} and @i{end}.

If @i{thing} is a @i{string} then 
the substring of @i{thing} @i{bounded} by @i{start} and @i{end}
is parsed into a @i{pathname} 
as follows:

@table @asis

@item @t{*}  
If @i{host} is a @i{logical host} then @i{thing} is parsed
  as a @i{logical pathname} @i{namestring} 
  on the @i{host}.

@item @t{*}  
If @i{host} is @b{nil} and @i{thing} is a syntactically valid 
  @i{logical pathname} @i{namestring} containing an explicit host,
  then it is parsed as a @i{logical pathname} @i{namestring}.

@item @t{*}  
If  @i{host} is @b{nil},
      @i{default-pathname} is a @i{logical pathname},
  and @i{thing} is a syntactically valid @i{logical pathname} @i{namestring}
       without an explicit host,
  then it is parsed as a @i{logical pathname} @i{namestring}
        on the host that is the host component of @i{default-pathname}.

@item @t{*}  
Otherwise, the parsing of @i{thing} is @i{implementation-defined}.

@end table

In the first 
of these
cases,
the host portion of the @i{logical pathname} namestring
and its following @i{colon} are optional.

If the host portion of the namestring and @i{host} 
are both present and do not match,
an error is signaled.               

If @i{junk-allowed} is @i{true},
then the @i{primary value} is the @i{pathname} parsed 
or, if no syntactically correct @i{pathname} was seen, @b{nil}.
If @i{junk-allowed} is @i{false},
then the entire substring is scanned, 
and the @i{primary value} is the @i{pathname} parsed.

In either case, the @i{secondary value}
is the index into @i{thing} of the delimiter that terminated the parse,
or the index beyond the substring if the parse terminated at the end of the substring
  (as will always be the case if @i{junk-allowed} is @i{false}).

Parsing a @i{null} @i{string} always succeeds,
producing a @i{pathname} with all components (except the host) equal to @b{nil}.

If @i{thing} contains an explicit host name and no explicit device name,
then it is @i{implementation-defined} whether @b{parse-namestring}
will supply the standard default device for that host as the device component
of the resulting @i{pathname}.

@subsubheading  Examples::

@example
 (setq q (parse-namestring "test"))  
@result{}  #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME "test" 
       :TYPE NIL :VERSION NIL)
 (pathnamep q) @result{}  @i{true}
 (parse-namestring "test") 
@result{}  #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME "test"
       :TYPE NIL :VERSION NIL), 4
 (setq s (open @i{xxx})) @result{}  #<Input File Stream...>
 (parse-namestring s) 
@result{}  #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME @i{xxx} 
       :TYPE NIL :VERSION NIL), 0
 (parse-namestring "test" nil nil :start 2 :end 4 )
 @result{}  #S(PATHNAME ...), 15
 (parse-namestring "foo.lisp")
@result{}  #P"foo.lisp"
@end example

@subsubheading  Exceptional Situations::           

If @i{junk-allowed} is @i{false},
an error of @i{type} @b{parse-error} is signaled if @i{thing} 
does not consist entirely of the representation of a @i{pathname}, 
possibly surrounded on either side by @i{whitespace}_1 characters if that is
appropriate to the cultural conventions of the implementation.

If @i{host} is supplied and not @b{nil},
and @i{thing} contains a manifest host name, 
an error of @i{type} @b{error} is signaled if the hosts do not match.

If @i{thing} is a @i{logical pathname} namestring
and if the host portion of the namestring and @i{host} 
are both present and do not match,
an error of @i{type} @b{error} is signaled.               

@subsubheading  See Also::

@b{pathname},
@b{logical-pathname},
@ref{File System Concepts},

@ref{->UNSPECIFIC as a Component Value},

@ref{Pathnames as Filenames}

@node wild-pathname-p, pathname-match-p, parse-namestring, Filenames Dictionary
@subsection wild-pathname-p                                                  [Function]

@code{wild-pathname-p}  @i{pathname {&optional} field-key} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values::

@i{pathname}---a @i{pathname designator}.

@i{Field-key}---one of @t{:host},
			   @t{:device}
			   @t{:directory},
			   @t{:name},
			   @t{:type},
		 	   @t{:version},
			or @b{nil}.

@i{generalized-boolean}---a @i{generalized boolean}.

@subsubheading  Description::

@b{wild-pathname-p} tests @i{pathname} for the presence of wildcard components.  

If @i{pathname} is a @i{pathname} (as returned by @b{pathname})
it represents the name used to open the file. This may be, but is
not required to be, the actual name of the file. 

If @i{field-key} is not supplied or @b{nil}, @b{wild-pathname-p}    
returns true if @i{pathname} has any wildcard components, @b{nil} 
if @i{pathname} has none.
If @i{field-key} is @i{non-nil}, @b{wild-pathname-p}    
returns true if the indicated component of @i{pathname} is a wildcard, 
@b{nil} if the component is not a wildcard.  

@subsubheading  Examples::
@example
 ;;;The following examples are not portable.  They are written to run
 ;;;with particular file systems and particular wildcard conventions.
 ;;;Other implementations will behave differently.  These examples are
 ;;;intended to be illustrative, not to be prescriptive.

 (wild-pathname-p (make-pathname :name :wild)) @result{}  @i{true}
 (wild-pathname-p (make-pathname :name :wild) :name) @result{}  @i{true}
 (wild-pathname-p (make-pathname :name :wild) :type) @result{}  @i{false}
 (wild-pathname-p (pathname "s:>foo>**>")) @result{}  @i{true} ;Lispm
 (wild-pathname-p (pathname :name "F*O")) @result{}  @i{true} ;Most places
@end example

@subsubheading  Exceptional Situations::

If @i{pathname} is not a @i{pathname}, a @i{string}, 
or a @i{stream associated with a file} an error of @i{type} @b{type-error} is signaled.

@subsubheading  See Also::

@b{pathname},
@b{logical-pathname},
@ref{File System Concepts},

@ref{Pathnames as Filenames}

@subsubheading  Notes::

Not all implementations support wildcards in all fields.
See @ref{->WILD as a Component Value} and @ref{Restrictions on Wildcard Pathnames}.

@node pathname-match-p, translate-logical-pathname, wild-pathname-p, Filenames Dictionary
@subsection pathname-match-p                                                 [Function]

@code{pathname-match-p}  @i{pathname wildcard} @result{}  @i{generalized-boolean}

@subsubheading  Arguments and Values:: 

@i{pathname}---a @i{pathname designator}.

@i{wildcard}---a @i{designator} for a @i{wild} @i{pathname}.

@i{generalized-boolean}---a @i{generalized boolean}.

@subsubheading  Description::

@b{pathname-match-p} returns true if 
@i{pathname} matches @i{wildcard}, otherwise @b{nil}.  The 
matching rules are @i{implementation-defined} but should be consistent with 
@b{directory}. Missing components of @i{wildcard} default to @t{:wild}.

It is valid for @i{pathname} to be a wild @i{pathname}; 
a wildcard field in @i{pathname} only matches a
wildcard field in @i{wildcard} (@i{i.e.}, @b{pathname-match-p} is not commutative).
It is valid for @i{wildcard} to be a non-wild @i{pathname}.

@subsubheading  Exceptional Situations::

If @i{pathname} or @i{wildcard} is not a @i{pathname}, @i{string}, 
or @i{stream associated with a file} an error of @i{type} @b{type-error} is signaled.

@subsubheading  See Also::

@ref{directory}
,
@b{pathname},
@b{logical-pathname},
@ref{File System Concepts},

@ref{Pathnames as Filenames}

@node translate-logical-pathname, translate-pathname, pathname-match-p, Filenames Dictionary
@subsection translate-logical-pathname                                       [Function]

@code{translate-logical-pathname}  @i{pathname {&key}} @result{}  @i{physical-pathname}

@subsubheading  Arguments and Values:: 

@i{pathname}---a @i{pathname designator},
		or a @i{logical pathname} @i{namestring}.

@i{physical-pathname}---a @i{physical pathname}.

@subsubheading  Description::

Translates @i{pathname} to a @i{physical pathname}, which it returns.

If @i{pathname} is a @i{stream}, the
@i{stream} can be either open or closed.
@b{translate-logical-pathname} returns the same 
physical pathname after a
    file is closed as it did when the file was open.

It is an error if @i{pathname} is a @i{stream} that is 
created with @b{make-two-way-stream}, 
@b{make-echo-stream},             
@b{make-broadcast-stream}, 
@b{make-concatenated-stream}, @b{make-string-input-stream},
@b{make-string-output-stream}.

If @i{pathname} is a @i{logical pathname} namestring,
the host portion of the 
@i{logical pathname} namestring and its following @i{colon} are required.

@i{Pathname} is first coerced to a @i{pathname}.
If the coerced @i{pathname} is a physical pathname, it is returned.
If the coerced @i{pathname} is a @i{logical pathname},
the first matching translation (according to @b{pathname-match-p})
of the @i{logical pathname} host is applied, as if by calling 
@b{translate-pathname}.  If the result is
    a @i{logical pathname}, this process is repeated.  
When the result is
    finally a physical pathname, it is returned.
    If no translation matches, an error 
is signaled.

@b{translate-logical-pathname} might perform additional translations,
    typically to provide translation of file types to local naming
    conventions, to accomodate physical file systems with limited length
    names, or to deal with special character requirements such as
    translating hyphens to underscores or uppercase letters to lowercase.
    Any such additional translations are @i{implementation-defined}.  Some
    implementations do no additional translations.

    There are no specified keyword arguments for
@b{translate-logical-pathname}, 
but implementations are permitted to extend
    it by adding keyword arguments.  

@subsubheading  Examples::

See @b{logical-pathname-translations}.

@subsubheading  Exceptional Situations::

If @i{pathname} is incorrectly supplied, an error of @i{type} @b{type-error} is signaled.

If no translation matches, an error of @i{type} @b{file-error} is signaled.

[Editorial Note by KMP: Is file-error really right, or should it be pathname-error?]

@subsubheading  See Also::

@ref{logical-pathname}
,
@ref{logical-pathname-translations}
, 
@b{logical-pathname},
@ref{File System Concepts},

@ref{Pathnames as Filenames}

@node translate-pathname, merge-pathnames, translate-logical-pathname, Filenames Dictionary
@subsection translate-pathname                                               [Function]

@code{translate-pathname}  @i{source from-wildcard to-wildcard {&key}}@*
   @result{}  @i{translated-pathname}

@subsubheading  Arguments and Values:: 

@i{source}---a @i{pathname designator}.

@i{from-wildcard}---a @i{pathname designator}.

@i{to-wildcard}---a @i{pathname designator}.

@i{translated-pathname}---a @i{pathname}.

@subsubheading  Description::

@b{translate-pathname} translates @i{source} 
(that matches @i{from-wildcard}) into a corresponding @i{pathname} 
that matches @i{to-wildcard}, and returns the corresponding @i{pathname}.

The resulting @i{pathname} is @i{to-wildcard} with each wildcard or missing
field replaced by a portion of @i{source}.  A ``wildcard field'' is a
@i{pathname} component with a value of @t{:wild}, a @t{:wild} element of a
@i{list}-valued directory component, or an @i{implementation-defined} portion
of a component, such as the @t{"*"} in the complex wildcard string
@t{"foo*bar"} that some implementations support.  An implementation that
adds other wildcard features, such as regular expressions, must define
how @b{translate-pathname} extends to those features.  
A ``missing field'' is a @i{pathname} component with a value of @b{nil}.

    The portion of @i{source} 
that is copied into the resulting @i{pathname} is 
@i{implementation-defined}.  Typically 
it is determined by the user interface conventions
    of the file systems involved.  Usually it is the portion of @i{source}
    that matches a wildcard field of 
@i{from-wildcard} that is in the same
    position as the wildcard or missing field of 
@i{to-wildcard}.  If there
    is no wildcard field in 
@i{from-wildcard} at that position, then usually
    it is the entire corresponding 
@i{pathname} component of @i{source}, or in
    the case of a 
@i{list}-valued directory component, the entire corresponding
    @i{list} element.  

    During the copying of a portion of @i{source} into 
the resulting @i{pathname}, additional
    @i{implementation-defined} translations of @i{case} or file naming
    conventions might occur, especially when 
@i{from-wildcard} and
    @i{to-wildcard} are for different hosts.

It is valid for
    @i{source} to be a wild 
@i{pathname}; in general this will produce a wild
    result.  It 
is valid for @i{from-wildcard} and/or @i{to-wildcard} to be
    non-wild @i{pathnames}.  

    There are no specified keyword arguments for 
@b{translate-pathname}, but
    implementations are permitted to extend it by adding keyword arguments.

@b{translate-pathname} maps customary case in
@i{source} into customary case in the output @i{pathname}.

@subsubheading  Examples::

@example
 ;; The results of the following five forms are all implementation-dependent.
 ;; The second item in particular is shown with multiple results just to 
 ;; emphasize one of many particular variations which commonly occurs.
 (pathname-name (translate-pathname "foobar" "foo*" "*baz")) @result{}  "barbaz"
 (pathname-name (translate-pathname "foobar" "foo*" "*"))
@result{}  "foobar"
@i{OR}@result{} "bar"
 (pathname-name (translate-pathname "foobar" "*"    "foo*")) @result{}  "foofoobar"
 (pathname-name (translate-pathname "bar"    "*"    "foo*")) @result{}  "foobar"
 (pathname-name (translate-pathname "foobar" "foo*" "baz*")) @result{}  "bazbar"

 (defun translate-logical-pathname-1 (pathname rules)
   (let ((rule (assoc pathname rules :test #'pathname-match-p)))
     (unless rule (error "No translation rule for ~A" pathname))
     (translate-pathname pathname (first rule) (second rule))))
 (translate-logical-pathname-1 "FOO:CODE;BASIC.LISP"
                       '(("FOO:DOCUMENTATION;" "MY-UNIX:/doc/foo/")
                         ("FOO:CODE;"          "MY-UNIX:/lib/foo/")
                         ("FOO:PATCHES;*;"     "MY-UNIX:/lib/foo/patch/*/")))
@result{}  #P"MY-UNIX:/lib/foo/basic.l"

;;;This example assumes one particular set of wildcard conventions
;;;Not all file systems will run this example exactly as written
 (defun rename-files (from to)
   (dolist (file (directory from))
     (rename-file file (translate-pathname file from to))))
 (rename-files "/usr/me/*.lisp" "/dev/her/*.l")
   ;Renames /usr/me/init.lisp to /dev/her/init.l
 (rename-files "/usr/me/pcl*/*" "/sys/pcl/*/")
   ;Renames /usr/me/pcl-5-may/low.lisp to /sys/pcl/pcl-5-may/low.lisp
   ;In some file systems the result might be /sys/pcl/5-may/low.lisp
 (rename-files "/usr/me/pcl*/*" "/sys/library/*/")
   ;Renames /usr/me/pcl-5-may/low.lisp to /sys/library/pcl-5-may/low.lisp
   ;In some file systems the result might be /sys/library/5-may/low.lisp
 (rename-files "/usr/me/foo.bar" "/usr/me2/")
   ;Renames /usr/me/foo.bar to /usr/me2/foo.bar
 (rename-files "/usr/joe/*-recipes.text" "/usr/jim/cookbook/joe's-*-rec.text")
   ;Renames /usr/joe/lamb-recipes.text to /usr/jim/cookbook/joe's-lamb-rec.text
   ;Renames /usr/joe/pork-recipes.text to /usr/jim/cookbook/joe's-pork-rec.text
   ;Renames /usr/joe/veg-recipes.text to /usr/jim/cookbook/joe's-veg-rec.text
@end example

@subsubheading  Exceptional Situations::

If any of @i{source}, @i{from-wildcard}, or @i{to-wildcard}
is not a @i{pathname}, a @i{string}, or a @i{stream associated with a file}
an error of @i{type} @b{type-error} is signaled.  

@t{(pathname-match-p @i{source from-wildcard})} must
be true or an error of @i{type} @b{error} is signaled.

@subsubheading  See Also::

@ref{namestring; file-namestring; directory-namestring; host-namestring; enough-namestring}
,
@ref{pathname-host; pathname-device; pathname-directory; pathname-name; pathname-type; pathname-version}
,

@b{pathname},
@b{logical-pathname},
@ref{File System Concepts},

@ref{Pathnames as Filenames}

@subsubheading  Notes::

The exact behavior of @b{translate-pathname} cannot be dictated
by the @r{Common Lisp} language and must be allowed to vary, depending on the
user interface conventions of the file systems involved.

The following is an implementation guideline.
One file system performs this operation by
    examining each piece of the three 
@i{pathnames} in turn, where a piece is a
    @i{pathname} component or a 
@i{list} element of a structured component such as
    a hierarchical directory.  Hierarchical directory elements in
    @i{from-wildcard} and 
@i{to-wildcard} are matched by whether they are
    wildcards, not by depth in the directory hierarchy.  If the piece in
@i{to-wildcard} is present and not wild, it is copied into the result.
    If the piece in @i{to-wildcard} is 
@t{:wild} or @b{nil}, the piece in @i{source} is
    copied into the result.  Otherwise, the piece in
@i{to-wildcard} might be
    a complex wildcard such as @t{"foo*bar"} and the piece in 
@i{from-wildcard}
    should be wild; the portion of the piece in 
@i{source} that matches the
    wildcard portion of the piece in 
@i{from-wildcard} replaces the wildcard
    portion of the piece in 
@i{to-wildcard} and the value produced is used in
    the result.

@node merge-pathnames,  , translate-pathname, Filenames Dictionary
@subsection merge-pathnames                                                  [Function]

@code{merge-pathnames}  @i{pathname {&optional} default-pathname default-version}@*
   @result{}  @i{merged-pathname}

@subsubheading  Arguments and Values::

@i{pathname}---a @i{pathname designator}.

@i{default-pathname}---a @i{pathname designator}.

 The default is the @i{value} of @b{*default-pathname-defaults*}.

@i{default-version}---a @i{valid pathname version}.

 The default is @t{:newest}.

@i{merged-pathname}---a @i{pathname}.

@subsubheading  Description::

Constructs a @i{pathname} from @i{pathname} 
by filling in any unsupplied components with the corresponding values
from @i{default-pathname} and @i{default-version}. 

Defaulting of pathname components 
is done by filling in components taken from another @i{pathname}.

This is especially useful for cases such as 
a program that has an input file and an output file.
Unspecified components of the output pathname will come from the input pathname,
except that the type should not default
to the type of the input pathname
but rather to the appropriate default type for output from the program;
for example, see the @i{function} @b{compile-file-pathname}.

If no version is supplied, @i{default-version} is used.
If @i{default-version} is @b{nil}, the version component will remain unchanged.

If @i{pathname} explicitly specifies a host and not a device, and 
if the host component of @i{default-pathname} matches the host component
of @i{pathname}, then the device is taken from the @i{default-pathname};
otherwise the device will be the default file device for that host.  If
@i{pathname} does not specify a host, device, directory, name,
or type, each such component is copied from @i{default-pathname}.
If @i{pathname} does not specify a name, then the version, if not provided, will
come from @i{default-pathname}, just like the other components.  If
@i{pathname} does specify a name, then the version is not affected
by @i{default-pathname}. If this process leaves the
version missing, the @i{default-version} is used.
If the host's file name syntax provides a way
to input a version without a name or type, the user can let the name
and type default but supply a version different from the one in @i{default-pathname}.

If @i{pathname} is a @i{stream}, @i{pathname} effectively
becomes @t{(pathname @i{pathname})}. @b{merge-pathnames}
can be used on either an open or a closed @i{stream}.

If @i{pathname} is a @i{pathname}
it represents the name used to open the file. This may be, but is
not required to be, the actual name of the file. 

@b{merge-pathnames} recognizes a @i{logical pathname} @i{namestring}
   when @i{default-pathname} is a @i{logical pathname},

or when the @i{namestring} begins with 
    the name of a defined @i{logical host} followed by a @i{colon}.
In the first of these two cases,

the host portion of the @i{logical pathname} @i{namestring}
and its following @i{colon} are optional.

@b{merge-pathnames} returns a 
@i{logical pathname} if and only if
   its first argument is a @i{logical pathname},

or its first argument is a @i{logical pathname} @i{namestring} with an explicit host,
or its first argument does not specify a host 
    and the @i{default-pathname} is a @i{logical pathname}.

@i{Pathname} merging treats a relative directory specially.  
If @t{(pathname-directory @i{pathname})} is a @i{list} whose
@i{car} is @t{:relative}, and 
@t{(pathname-directory @i{default-pathname})} is a @i{list}, then
the merged directory is the value of

@example
 (append (pathname-directory @i{default-pathname})
         (cdr  ;remove :relative from the front
           (pathname-directory @i{pathname})))
@end example

except that if the resulting @i{list} contains a @i{string} or @t{:wild}
immediately followed by @t{:back}, both of them are removed.  This removal of 
redundant @t{:back} @i{keywords} is repeated as many times as possible.
If @t{(pathname-directory @i{default-pathname})} is not a @i{list} or
@t{(pathname-directory @i{pathname})} is not a @i{list} 
whose @i{car} is @t{:relative}, the merged directory is
@t{(or (pathname-directory @i{pathname}) (pathname-directory @i{default-pathname}))}

@b{merge-pathnames} maps customary case in @i{pathname} 
into customary case in the output @i{pathname}.

@subsubheading  Examples::
@example
 (merge-pathnames "CMUC::FORMAT"
                  "CMUC::PS:<LISPIO>.FASL")
@result{}  #P"CMUC::PS:<LISPIO>FORMAT.FASL.0"
@end example

@subsubheading  See Also::

@b{*default-pathname-defaults*},
@b{pathname},
@b{logical-pathname},
@ref{File System Concepts},

@ref{Pathnames as Filenames}

@subsubheading  Notes::

The net effect 
is that if just a name is supplied, 
the host, device, directory, and type will come from @i{default-pathname}, 
but the version will come from @i{default-version}.
If nothing or just a directory is supplied,
the name, type, and version will come from @i{default-pathname} together.

@c end of including dict-pathnames

@c %**end of chapter