My various dotfiles

chap-19.texi 92KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451
  1. @node Filenames, Files, Hash Tables, Top
  2. @chapter Filenames
  3. @menu
  4. * Overview of Filenames::
  5. * Pathnames::
  6. * Logical Pathnames::
  7. * Filenames Dictionary::
  8. @end menu
  9. @node Overview of Filenames, Pathnames, Filenames, Filenames
  10. @section Overview of Filenames
  11. @c including concept-filenames
  12. There are many kinds of @i{file systems},
  13. varying widely both in their superficial syntactic details,
  14. and in their underlying power and structure.
  15. The facilities provided by @r{Common Lisp} for referring to and manipulating @i{files}
  16. has been chosen to be compatible with many kinds of @i{file systems},
  17. while at the same time minimizing the program-visible differences
  18. between kinds of @i{file systems}.
  19. Since @i{file systems} vary in their conventions for naming @i{files},
  20. there are two distinct ways to represent @i{filenames}:
  21. as @i{namestrings} and as @i{pathnames}.
  22. @menu
  23. * Namestrings as Filenames::
  24. * Pathnames as Filenames::
  25. * Parsing Namestrings Into Pathnames::
  26. @end menu
  27. @node Namestrings as Filenames, Pathnames as Filenames, Overview of Filenames, Overview of Filenames
  28. @subsection Namestrings as Filenames
  29. A @i{namestring}
  30. @IGindex{namestring}
  31. is a @i{string} that represents a @i{filename}.
  32. In general, the syntax of @i{namestrings} involves the use of
  33. @i{implementation-defined} conventions,
  34. usually those customary for the @i{file system} in which the named @i{file} resides.
  35. The only exception is the syntax of a @i{logical pathname} @i{namestring},
  36. which is defined in this specification; see @ref{Syntax of Logical Pathname Namestrings}.
  37. A @i{conforming program} must never unconditionally use a
  38. @i{literal} @i{namestring} other than a @i{logical pathname} @i{namestring}
  39. because @r{Common Lisp} does not define any @i{namestring} syntax
  40. other than that for @i{logical pathnames}
  41. that would be guaranteed to be portable.
  42. However, a @i{conforming program} can, if it is careful,
  43. successfully manipulate user-supplied data
  44. which contains or refers to non-portable @i{namestrings}.
  45. A @i{namestring} can be @i{coerced} to a @i{pathname} by the @i{functions} @b{pathname}
  46. or @b{parse-namestring}.
  47. @node Pathnames as Filenames, Parsing Namestrings Into Pathnames, Namestrings as Filenames, Overview of Filenames
  48. @subsection Pathnames as Filenames
  49. @i{Pathnames}
  50. @IGindex{pathname}
  51. are structured @i{objects} that can represent,
  52. in an @i{implementation-independent} way,
  53. the @i{filenames} that are used natively by an underlying @i{file system}.
  54. In addition, @i{pathnames} can also represent certain partially composed
  55. @i{filenames} for which an underlying @i{file system}
  56. might not have a specific @i{namestring} representation.
  57. A @i{pathname} need not correspond to any file that actually exists,
  58. and more than one @i{pathname} can refer to the same file.
  59. For example, the @i{pathname} with a version of @t{:newest}
  60. might refer to the same file as a @i{pathname}
  61. with the same components except a certain number as the version.
  62. Indeed, a @i{pathname} with version @t{:newest} might refer to
  63. different files as time passes, because the meaning of such a @i{pathname}
  64. depends on the state of the file system.
  65. Some @i{file systems} naturally use a structural model for their
  66. @i{filenames}, while others do not. Within the @r{Common Lisp} @i{pathname} model,
  67. all @i{filenames} are seen as having a particular structure,
  68. even if that structure is not reflected in the underlying @i{file system}.
  69. The nature of the mapping between structure imposed by @i{pathnames}
  70. and the structure, if any, that is used by the underlying @i{file system}
  71. is @i{implementation-defined}.
  72. Every @i{pathname} has six components:
  73. a host,
  74. a device,
  75. a directory,
  76. a name,
  77. a type,
  78. and a version.
  79. By naming @i{files} with @i{pathnames},
  80. @r{Common Lisp} programs can work in essentially the same way even in @i{file systems}
  81. that seem superficially quite different.
  82. For a detailed description of these components, see @ref{Pathname Components}.
  83. The mapping of the @i{pathname} components into the concepts peculiar to
  84. each @i{file system} is @i{implementation-defined}.
  85. There exist conceivable @i{pathnames}
  86. for which there is no mapping to a syntactically valid @i{filename}
  87. in a particular @i{implementation}.
  88. An @i{implementation} may use various strategies in an attempt to find a mapping;
  89. for example,
  90. an @i{implementation} may quietly truncate @i{filenames}
  91. that exceed length limitations imposed by the underlying @i{file system},
  92. or ignore certain @i{pathname} components
  93. for which the @i{file system} provides no support.
  94. If such a mapping cannot be found,
  95. an error of @i{type} @b{file-error} is signaled.
  96. The time at which this mapping and associated error signaling
  97. occurs is @i{implementation-dependent}.
  98. Specifically, it may occur
  99. at the time the @i{pathname} is constructed,
  100. when coercing a @i{pathname} to a @i{namestring},
  101. or when an attempt is made to @i{open} or otherwise access the @i{file}
  102. designated by the @i{pathname}.
  103. Figure 19--1 lists some @i{defined names} that are applicable to @i{pathnames}.
  104. @group
  105. @noindent
  106. @w{ *default-pathname-defaults* namestring pathname-name }
  107. @w{ directory-namestring open pathname-type }
  108. @w{ enough-namestring parse-namestring pathname-version }
  109. @w{ file-namestring pathname pathnamep }
  110. @w{ file-string-length pathname-device translate-pathname }
  111. @w{ host-namestring pathname-directory truename }
  112. @w{ make-pathname pathname-host user-homedir-pathname }
  113. @w{ merge-pathnames pathname-match-p wild-pathname-p }
  114. @noindent
  115. @w{ Figure 19--1: Pathname Operations }
  116. @end group
  117. @node Parsing Namestrings Into Pathnames, , Pathnames as Filenames, Overview of Filenames
  118. @subsection Parsing Namestrings Into Pathnames
  119. Parsing is the operation used to convert a @i{namestring} into a @i{pathname}.
  120. Except in the case of parsing @i{logical pathname} @i{namestrings},
  121. this operation is @i{implementation-dependent},
  122. because the format of @i{namestrings} is @i{implementation-dependent}.
  123. A @i{conforming implementation} is free to accommodate other @i{file system}
  124. features in its @i{pathname} representation and provides a parser that can process
  125. such specifications in @i{namestrings}.
  126. @i{Conforming programs} must not depend on any such features,
  127. since those features will not be portable.
  128. @c end of including concept-filenames
  129. @node Pathnames, Logical Pathnames, Overview of Filenames, Filenames
  130. @section Pathnames
  131. @c including concept-pathnames
  132. @menu
  133. * Pathname Components::
  134. * Interpreting Pathname Component Values::
  135. * Merging Pathnames::
  136. @end menu
  137. @node Pathname Components, Interpreting Pathname Component Values, Pathnames, Pathnames
  138. @subsection Pathname Components
  139. A @i{pathname} has six components:
  140. a host,
  141. a device,
  142. a directory,
  143. a name,
  144. a type,
  145. and a version.
  146. @menu
  147. * The Pathname Host Component::
  148. * The Pathname Device Component::
  149. * The Pathname Directory Component::
  150. * The Pathname Name Component::
  151. * The Pathname Type Component::
  152. * The Pathname Version Component::
  153. @end menu
  154. @node The Pathname Host Component, The Pathname Device Component, Pathname Components, Pathname Components
  155. @subsubsection The Pathname Host Component
  156. The name of the file system on which the file resides,
  157. or the name of a @i{logical host}.
  158. @node The Pathname Device Component, The Pathname Directory Component, The Pathname Host Component, Pathname Components
  159. @subsubsection The Pathname Device Component
  160. Corresponds to the ``device'' or ``file structure'' concept in many
  161. host file systems: the name of a logical or physical device containing files.
  162. @node The Pathname Directory Component, The Pathname Name Component, The Pathname Device Component, Pathname Components
  163. @subsubsection The Pathname Directory Component
  164. Corresponds to the ``directory'' concept in many host file systems:
  165. the name of a group of related files.
  166. @node The Pathname Name Component, The Pathname Type Component, The Pathname Directory Component, Pathname Components
  167. @subsubsection The Pathname Name Component
  168. The ``name'' part of a group of @i{files} that can be thought of
  169. as conceptually related.
  170. @node The Pathname Type Component, The Pathname Version Component, The Pathname Name Component, Pathname Components
  171. @subsubsection The Pathname Type Component
  172. Corresponds to the ``filetype'' or ``extension'' concept in many host
  173. file systems. This says what kind of file this is.
  174. This component is always a @i{string}, @b{nil}, @t{:wild}, or @t{:unspecific}.
  175. @node The Pathname Version Component, , The Pathname Type Component, Pathname Components
  176. @subsubsection The Pathname Version Component
  177. Corresponds to the ``version number'' concept in many host file systems.
  178. The version is either a positive @i{integer}
  179. or a @i{symbol} from the following list:
  180. @b{nil}, @t{:wild}, @t{:unspecific}, or @t{:newest}
  181. (refers to the largest version number that already exists in
  182. the file system when reading a file, or to
  183. a version number
  184. greater than any already existing in the file system
  185. when writing a new file). Implementations
  186. can define other special version @i{symbols}.
  187. @node Interpreting Pathname Component Values, Merging Pathnames, Pathname Components, Pathnames
  188. @subsection Interpreting Pathname Component Values
  189. @menu
  190. * Strings in Component Values::
  191. * Special Characters in Pathname Components::
  192. * Case in Pathname Components::
  193. * Local Case in Pathname Components::
  194. * Common Case in Pathname Components::
  195. * Special Pathname Component Values::
  196. * NIL as a Component Value::
  197. * ->WILD as a Component Value::
  198. * ->UNSPECIFIC as a Component Value::
  199. * Relation between component values NIL and ->UNSPECIFIC::
  200. * Restrictions on Wildcard Pathnames::
  201. * Restrictions on Examining Pathname Components::
  202. * Restrictions on Examining a Pathname Host Component::
  203. * Restrictions on Examining a Pathname Device Component::
  204. * Restrictions on Examining a Pathname Directory Component::
  205. * Directory Components in Non-Hierarchical File Systems::
  206. * Restrictions on Examining a Pathname Name Component::
  207. * Restrictions on Examining a Pathname Type Component::
  208. * Restrictions on Examining a Pathname Version Component::
  209. * Notes about the Pathname Version Component::
  210. * Restrictions on Constructing Pathnames::
  211. @end menu
  212. @node Strings in Component Values, Special Characters in Pathname Components, Interpreting Pathname Component Values, Interpreting Pathname Component Values
  213. @subsubsection Strings in Component Values
  214. @node Special Characters in Pathname Components, Case in Pathname Components, Strings in Component Values, Interpreting Pathname Component Values
  215. @subsubsection Special Characters in Pathname Components
  216. @i{Strings} in @i{pathname} component values
  217. never contain special @i{characters} that represent
  218. separation between @i{pathname} fields,
  219. such as @i{slash} in @r{Unix} @i{filenames}.
  220. Whether separator @i{characters} are permitted as
  221. part of a @i{string} in a @i{pathname} component
  222. is @i{implementation-defined};
  223. however, if the @i{implementation} does permit it,
  224. it must arrange to properly ``quote'' the character for the
  225. @i{file system} when constructing a @i{namestring}.
  226. For example,
  227. @example
  228. ;; In a TOPS-20 implementation, which uses {@t{^}}V to quote
  229. (NAMESTRING (MAKE-PATHNAME :HOST "OZ" :NAME "<TEST>"))
  230. @result{} #P"OZ:PS:{@t{^}}V<TEST{@t{^}}V>"
  231. @i{NOT}@result{} #P"OZ:PS:<TEST>"
  232. @end example
  233. @node Case in Pathname Components, Local Case in Pathname Components, Special Characters in Pathname Components, Interpreting Pathname Component Values
  234. @subsubsection Case in Pathname Components
  235. @i{Namestrings} always use local file system @i{case} conventions,
  236. but @r{Common Lisp} @i{functions} that manipulate @i{pathname} components
  237. allow the caller to select either of two conventions for representing
  238. @i{case} in component values by supplying a value for the
  239. @t{:case} keyword argument.
  240. Figure 19--2 lists the functions
  241. relating to @i{pathnames} that permit a @t{:case} argument:
  242. @group
  243. @noindent
  244. @w{ make-pathname pathname-directory pathname-name }
  245. @w{ pathname-device pathname-host pathname-type }
  246. @noindent
  247. @w{ Figure 19--2: Pathname functions using a :CASE argument}
  248. @end group
  249. @node Local Case in Pathname Components, Common Case in Pathname Components, Case in Pathname Components, Interpreting Pathname Component Values
  250. @subsubsection Local Case in Pathname Components
  251. For the functions in @i{Figure~19--2},
  252. a value of @t{:local}
  253. @IKindex{local}
  254. for the @t{:case} argument
  255. (the default for these functions)
  256. indicates that the functions should receive and yield @i{strings} in component values
  257. as if they were already represented according to the host @i{file system}'s
  258. convention for @i{case}.
  259. If the @i{file system} supports both @i{cases}, @i{strings} given or received
  260. as @i{pathname} component values under this protocol are to be used exactly
  261. as written. If the file system only supports one @i{case},
  262. the @i{strings} will be translated to that @i{case}.
  263. @node Common Case in Pathname Components, Special Pathname Component Values, Local Case in Pathname Components, Interpreting Pathname Component Values
  264. @subsubsection Common Case in Pathname Components
  265. For the functions in @i{Figure~19--2},
  266. a value of @t{:common}
  267. @IKindex{common}
  268. for the @t{:case} argument
  269. that these @i{functions} should receive
  270. and yield @i{strings} in component values according to the following conventions:
  271. @table @asis
  272. @item @t{*}
  273. All @i{uppercase} means to use a file system's customary @i{case}.
  274. @item @t{*}
  275. All @i{lowercase} means to use the opposite of the customary @i{case}.
  276. @item @t{*}
  277. Mixed @i{case} represents itself.
  278. @end table
  279. Note that these conventions have been chosen in such a way that translation
  280. from @t{:local} to @t{:common} and back to @t{:local} is information-preserving.
  281. @node Special Pathname Component Values, NIL as a Component Value, Common Case in Pathname Components, Interpreting Pathname Component Values
  282. @subsubsection Special Pathname Component Values
  283. @node NIL as a Component Value, ->WILD as a Component Value, Special Pathname Component Values, Interpreting Pathname Component Values
  284. @subsubsection NIL as a Component Value
  285. As a @i{pathname} component value,
  286. @b{nil} represents that the component is ``unfilled'';
  287. see @ref{Merging Pathnames}.
  288. The value of any @i{pathname} component can be @b{nil}.
  289. When constructing a @i{pathname},
  290. @b{nil} in the host component might mean a default host
  291. rather than an actual @b{nil} in some @i{implementations}.
  292. @node ->WILD as a Component Value, ->UNSPECIFIC as a Component Value, NIL as a Component Value, Interpreting Pathname Component Values
  293. @subsubsection :WILD as a Component Value
  294. If @t{:wild}
  295. @IKindex{wild}
  296. is the value of a @i{pathname} component,
  297. that component is considered to be a wildcard, which matches anything.
  298. A @i{conforming program} must be prepared to encounter a value of @t{:wild}
  299. as the value of any @i{pathname} component,
  300. or as an @i{element} of a @i{list} that is the value of the directory component.
  301. When constructing a @i{pathname},
  302. a @i{conforming program} may use @t{:wild} as the value of any or all of
  303. the directory, name, type,
  304. or version component, but must not use @t{:wild} as the value of the host,
  305. or device component.
  306. If @t{:wild} is used as the value of the directory component in the construction
  307. of a @i{pathname}, the effect is equivalent to specifying the list
  308. @t{(:absolute :wild-inferiors)},
  309. or the same as @t{(:absolute :wild)} in a @i{file system} that does not support
  310. @t{:wild-inferiors}.
  311. @IKindex{wild-inferiors}
  312. @node ->UNSPECIFIC as a Component Value, Relation between component values NIL and ->UNSPECIFIC, ->WILD as a Component Value, Interpreting Pathname Component Values
  313. @subsubsection :UNSPECIFIC as a Component Value
  314. If @t{:unspecific}
  315. @IKindex{unspecific}
  316. is the value of a @i{pathname} component,
  317. the component is considered to be ``absent''
  318. or to ``have no meaning''
  319. in the @i{filename} being represented by the @i{pathname}.
  320. Whether a value of @t{:unspecific} is permitted for any component
  321. on any given @i{file system} accessible to the @i{implementation}
  322. is @i{implementation-defined}.
  323. A @i{conforming program} must never unconditionally use a
  324. @t{:unspecific} as the value of a @i{pathname} component because
  325. such a value is not guaranteed to be permissible in all implementations.
  326. However, a @i{conforming program} can, if it is careful,
  327. successfully manipulate user-supplied data
  328. which contains or refers to non-portable @i{pathname} components.
  329. And certainly a @i{conforming program} should be prepared for the
  330. possibility that any components of a @i{pathname} could be @t{:unspecific}.
  331. When @i{reading}_1 the value of any @i{pathname} component,
  332. @i{conforming programs} should be prepared for the value to be @t{:unspecific}.
  333. When @i{writing}_1 the value of any @i{pathname} component,
  334. the consequences are undefined if @t{:unspecific} is given
  335. for a @i{pathname} in a @i{file system} for which it does not make sense.
  336. @node Relation between component values NIL and ->UNSPECIFIC, Restrictions on Wildcard Pathnames, ->UNSPECIFIC as a Component Value, Interpreting Pathname Component Values
  337. @subsubsection Relation between component values NIL and :UNSPECIFIC
  338. If a @i{pathname} is converted to a @i{namestring},
  339. the @i{symbols} @b{nil} and @t{:unspecific}
  340. cause the field to be treated as if it were empty.
  341. That is,
  342. both @b{nil} and @t{:unspecific}
  343. cause the component not to appear in the @i{namestring}.
  344. However, when merging a @i{pathname} with a set of defaults,
  345. only a @b{nil} value for a component
  346. will be replaced with the default for that component,
  347. while a value of @t{:unspecific}
  348. will be left alone as if the field were ``filled'';
  349. see the @i{function} @b{merge-pathnames} and @ref{Merging Pathnames}.
  350. @node Restrictions on Wildcard Pathnames, Restrictions on Examining Pathname Components, Relation between component values NIL and ->UNSPECIFIC, Interpreting Pathname Component Values
  351. @subsubsection Restrictions on Wildcard Pathnames
  352. Wildcard @i{pathnames} can be used with @b{directory} but not with
  353. @b{open},
  354. and return true from @b{wild-pathname-p}. When examining
  355. wildcard components of a wildcard @i{pathname}, conforming programs
  356. must be prepared to encounter any of the following additional values
  357. in any component or any element of a @i{list} that is the directory component:
  358. @table @asis
  359. @item @t{*}
  360. The @i{symbol} @t{:wild}, which matches anything.
  361. @item @t{*}
  362. A @i{string} containing @i{implementation-dependent}
  363. special wildcard @i{characters}.
  364. @item @t{*}
  365. Any @i{object},
  366. representing an @i{implementation-dependent} wildcard pattern.
  367. @end table
  368. @node Restrictions on Examining Pathname Components, Restrictions on Examining a Pathname Host Component, Restrictions on Wildcard Pathnames, Interpreting Pathname Component Values
  369. @subsubsection Restrictions on Examining Pathname Components
  370. The space of possible @i{objects} that a @i{conforming program}
  371. must be prepared to @i{read}_1
  372. as the value of a @i{pathname} component
  373. is substantially larger than the space of possible @i{objects}
  374. that a @i{conforming program} is permitted to @i{write}_1
  375. into such a component.
  376. While the values discussed
  377. in the subsections of this section,
  378. in @ref{Special Pathname Component Values},
  379. and in @ref{Restrictions on Wildcard Pathnames}
  380. apply to values that might be seen when
  381. reading the component values,
  382. substantially more restrictive rules apply to constructing pathnames;
  383. see @ref{Restrictions on Constructing Pathnames}.
  384. When examining @i{pathname} components,
  385. @i{conforming programs} should be aware of the following restrictions.
  386. @node Restrictions on Examining a Pathname Host Component, Restrictions on Examining a Pathname Device Component, Restrictions on Examining Pathname Components, Interpreting Pathname Component Values
  387. @subsubsection Restrictions on Examining a Pathname Host Component
  388. It is @i{implementation-dependent} what @i{object} is used to represent the host.
  389. @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
  390. @subsubsection Restrictions on Examining a Pathname Device Component
  391. The device might be a @i{string},
  392. @t{:wild}, @t{:unspecific}, or @b{nil}.
  393. Note that @t{:wild} might result from an attempt to @i{read}_1
  394. the @i{pathname} component, even though portable programs are restricted
  395. from @i{writing}_1 such a component value;
  396. see @ref{Restrictions on Wildcard Pathnames} and @ref{Restrictions on Constructing Pathnames}.
  397. @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
  398. @subsubsection Restrictions on Examining a Pathname Directory Component
  399. The directory might be a @i{string},
  400. @t{:wild}, @t{:unspecific}, or @b{nil}.
  401. The directory can be a @i{list} of @i{strings} and @i{symbols}.
  402. The @i{car} of the @i{list} is one of the symbols @t{:absolute}
  403. @IKindex{absolute}
  404. or
  405. @t{:relative}
  406. @IKindex{relative}
  407. , meaning:
  408. @table @asis
  409. @item @t{:absolute}
  410. A @i{list} whose @i{car} is the symbol @t{:absolute} represents
  411. a directory path starting from the root directory. The list
  412. @t{(:absolute)} represents the root directory. The list
  413. @t{(:absolute "foo" "bar" "baz")} represents the directory called
  414. @t{"/foo/bar/baz"} in Unix (except possibly for @i{case}).
  415. @item @t{:relative}
  416. A @i{list} whose @i{car} is the symbol @t{:relative} represents
  417. a directory path starting from a default directory.
  418. The list @t{(:relative)} has the same meaning as @b{nil} and hence is not used.
  419. The list @t{(:relative "foo" "bar")} represents the directory named @t{"bar"}
  420. in the directory named @t{"foo"} in the default directory.
  421. @end table
  422. Each remaining element of the @i{list} is a @i{string} or a @i{symbol}.
  423. Each @i{string} names a single level of directory structure.
  424. The @i{strings} should contain only the directory names
  425. themselves---no punctuation characters.
  426. In place of a @i{string}, at any point in the @i{list}, @i{symbols}
  427. can occur to indicate special file notations.
  428. Figure 19--3 lists the @i{symbols} that have standard meanings.
  429. Implementations are permitted to add additional @i{objects}
  430. of any @i{type} that is disjoint from @b{string}
  431. if necessary to represent features of their file systems that cannot be
  432. represented with the standard @i{strings} and @i{symbols}.
  433. Supplying any non-@i{string}, including any of the @i{symbols} listed below,
  434. to a file system for which it does not make sense
  435. signals an error of @i{type} @b{file-error}.
  436. For example, Unix does not support @t{:wild-inferiors} in most implementations.
  437. @IKindex{wild}
  438. @IKindex{wild-inferiors}
  439. @IKindex{up}
  440. @IKindex{back}
  441. @group
  442. @noindent
  443. @w{ Symbol Meaning }
  444. @w{ @t{:wild} Wildcard match of one level of directory structure }
  445. @w{ @t{:wild-inferiors} Wildcard match of any number of directory levels }
  446. @w{ @t{:up} Go upward in directory structure (semantic) }
  447. @w{ @t{:back} Go upward in directory structure (syntactic) }
  448. @noindent
  449. @w{ Figure 19--3: Special Markers In Directory Component }
  450. @end group
  451. The following notes apply to the previous figure:
  452. @table @asis
  453. @item Invalid Combinations
  454. Using @t{:absolute} or @t{:wild-inferiors}
  455. immediately followed by @t{:up} or @t{:back}
  456. signals an error of @i{type} @b{file-error}.
  457. @item Syntactic vs Semantic
  458. ``Syntactic'' means that the action of @t{:back}
  459. depends only on the @i{pathname}
  460. and not on the contents of the file system.
  461. ``Semantic'' means that the action of @t{:up}
  462. depends on the contents of the file system;
  463. to resolve a @i{pathname} containing
  464. @t{:up} to a @i{pathname} whose directory component
  465. contains only @t{:absolute} and
  466. @i{strings} requires probing the file system.
  467. @t{:up} differs from
  468. @t{:back} only in file systems that support multiple
  469. names for directories, perhaps via symbolic links. For example,
  470. suppose that there is a directory
  471. @t{(:absolute "X" "Y" "Z")}
  472. linked to
  473. @t{(:absolute "A" "B" "C")}
  474. and there also exist directories
  475. @t{(:absolute "A" "B" "Q")} and
  476. @t{(:absolute "X" "Y" "Q")}.
  477. Then
  478. @t{(:absolute "X" "Y" "Z" :up "Q")}
  479. designates
  480. @t{(:absolute "A" "B" "Q")}
  481. while
  482. @t{(:absolute "X" "Y" "Z" :back "Q")}
  483. designates
  484. @t{(:absolute "X" "Y" "Q")}
  485. @end table
  486. @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
  487. @subsubsection Directory Components in Non-Hierarchical File Systems
  488. In non-hierarchical @i{file systems},
  489. the only valid @i{list} values for the directory component of a @i{pathname}
  490. are @t{(:absolute @i{string})} and @t{(:absolute :wild)}.
  491. @t{:relative} directories and the keywords
  492. @t{:wild-inferiors}, @t{:up}, and @t{:back} are not used
  493. in non-hierarchical @i{file systems}.
  494. @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
  495. @subsubsection Restrictions on Examining a Pathname Name Component
  496. The name might be a @i{string},
  497. @t{:wild}, @t{:unspecific}, or @b{nil}.
  498. @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
  499. @subsubsection Restrictions on Examining a Pathname Type Component
  500. The type might be a @i{string},
  501. @t{:wild}, @t{:unspecific}, or @b{nil}.
  502. @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
  503. @subsubsection Restrictions on Examining a Pathname Version Component
  504. The version can be any @i{symbol} or any @i{integer}.
  505. The symbol @t{:newest} refers to the largest version number
  506. that already exists in the @i{file system}
  507. when reading, overwriting, appending, superseding, or directory listing
  508. an existing @i{file}.
  509. The symbol @t{:newest} refers to the smallest version number
  510. greater than any existing version number when creating a new file.
  511. The symbols @b{nil}, @t{:unspecific}, and @t{:wild} have special meanings and
  512. restrictions; see @ref{Special Pathname Component Values} and @ref{Restrictions on Constructing Pathnames}.
  513. Other @i{symbols} and @i{integers}
  514. have @i{implementation-defined} meaning.
  515. @node Notes about the Pathname Version Component, Restrictions on Constructing Pathnames, Restrictions on Examining a Pathname Version Component, Interpreting Pathname Component Values
  516. @subsubsection Notes about the Pathname Version Component
  517. It is suggested, but not required, that implementations do the following:
  518. @table @asis
  519. @item @t{*}
  520. Use positive @i{integers} starting at 1 as version numbers.
  521. @item @t{*}
  522. Recognize the symbol @t{:oldest}
  523. to designate the smallest existing version number.
  524. @item @t{*}
  525. Use @i{keywords} for other special versions.
  526. @end table
  527. @node Restrictions on Constructing Pathnames, , Notes about the Pathname Version Component, Interpreting Pathname Component Values
  528. @subsubsection Restrictions on Constructing Pathnames
  529. When constructing a @i{pathname} from components, conforming programs
  530. must follow these rules:
  531. @table @asis
  532. @item @t{*}
  533. Any component can be @b{nil}.
  534. @b{nil} in the host might mean a default host
  535. rather than an actual @b{nil} in some implementations.
  536. @item @t{*}
  537. The host, device, directory, name, and type can be @i{strings}. There
  538. are @i{implementation-dependent} limits on the number and type of
  539. @i{characters} in these @i{strings}.
  540. @item @t{*}
  541. The directory can be a @i{list} of @i{strings} and @i{symbols}.
  542. There are @i{implementation-dependent} limits on the @i{list}'s
  543. length and contents.
  544. @item @t{*}
  545. The version can be @t{:newest}.
  546. @item @t{*}
  547. Any component can be taken
  548. from the corresponding component of another @i{pathname}.
  549. When the two @i{pathnames} are for different file systems
  550. (in implementations that support multiple file systems),
  551. an appropriate translation occurs.
  552. If no meaningful translation is possible,
  553. an error is signaled.
  554. The definitions of ``appropriate'' and ``meaningful''
  555. are @i{implementation-dependent}.
  556. @item @t{*}
  557. An implementation might support other values for some components,
  558. but a portable program cannot use those values.
  559. A conforming program can use @i{implementation-dependent} values
  560. but this can make it non-portable;
  561. for example, it might work only with @r{Unix} file systems.
  562. @end table
  563. @node Merging Pathnames, , Interpreting Pathname Component Values, Pathnames
  564. @subsection Merging Pathnames
  565. Merging takes a @i{pathname} with unfilled components
  566. and supplies values for those components from a source of defaults.
  567. If a component's value is @b{nil}, that component is considered to be unfilled.
  568. If a component's value is any @i{non-nil} @i{object},
  569. including @t{:unspecific}, that component is considered to be filled.
  570. Except as explicitly specified otherwise,
  571. for functions that manipulate or inquire about @i{files} in the @i{file system},
  572. the pathname argument to such a function
  573. is merged with @b{*default-pathname-defaults*} before accessing the @i{file system}
  574. (as if by @b{merge-pathnames}).
  575. @menu
  576. * Examples of Merging Pathnames::
  577. @end menu
  578. @node Examples of Merging Pathnames, , Merging Pathnames, Merging Pathnames
  579. @subsubsection Examples of Merging Pathnames
  580. Although the following examples are possible to execute only in
  581. @i{implementations} which permit @t{:unspecific} in the indicated
  582. position andwhich permit four-letter type components, they serve to illustrate
  583. the basic concept of @i{pathname} merging.
  584. @example
  585. (pathname-type
  586. (merge-pathnames (make-pathname :type "LISP")
  587. (make-pathname :type "TEXT")))
  588. @result{} "LISP"
  589. (pathname-type
  590. (merge-pathnames (make-pathname :type nil)
  591. (make-pathname :type "LISP")))
  592. @result{} "LISP"
  593. (pathname-type
  594. (merge-pathnames (make-pathname :type :unspecific)
  595. (make-pathname :type "LISP")))
  596. @result{} :UNSPECIFIC
  597. @end example
  598. @c end of including concept-pathnames
  599. @node Logical Pathnames, Filenames Dictionary, Pathnames, Filenames
  600. @section Logical Pathnames
  601. @c including concept-logical-pathnames
  602. @menu
  603. * Syntax of Logical Pathname Namestrings::
  604. * Logical Pathname Components::
  605. @end menu
  606. @node Syntax of Logical Pathname Namestrings, Logical Pathname Components, Logical Pathnames, Logical Pathnames
  607. @subsection Syntax of Logical Pathname Namestrings
  608. The syntax of a @i{logical pathname} @i{namestring} is as follows.
  609. (Note that unlike many notational descriptions in this document,
  610. this is a syntactic description of character sequences,
  611. not a structural description of @i{objects}.)
  612. @w{@i{logical-pathname} ::=@r{[}!@i{host} @i{host-marker}@r{]} }
  613. @w{ @r{[}!@i{@i{relative-directory-marker}}@r{]} @{!@i{directory} @i{directory-marker}@}{*} }
  614. @w{ @r{[}!@i{name}@r{]} @r{[}@i{type-marker} !@i{type} @r{[}@i{version-marker} !@i{version}@r{]}@r{]}}
  615. @w{@i{host} ::=!@i{word}}
  616. @w{@i{directory} ::=!@i{word} | !@i{wildcard-word} | !@i{wild-inferiors-word}}
  617. @w{@i{name} ::=!@i{word} | !@i{wildcard-word}}
  618. @w{@i{type} ::=!@i{word} | !@i{wildcard-word}}
  619. @w{@i{version} ::=!@i{pos-int} | @i{newest-word} | @i{wildcard-version}}
  620. @i{host-marker}---a @i{colon}.
  621. @i{relative-directory-marker}---a @i{semicolon}.
  622. @i{directory-marker}---a @i{semicolon}.
  623. @i{type-marker}---a @i{dot}.
  624. @i{version-marker}---a @i{dot}.
  625. @i{wild-inferiors-word}---The two character sequence ``@t{**}'' (two @i{asterisks}).
  626. @i{newest-word}---The six character sequence ``@t{newest}''
  627. or the six character sequence ``@t{NEWEST}''.
  628. @i{wildcard-version}---an @i{asterisk}.
  629. @i{wildcard-word}---one or more @i{asterisks}, uppercase letters,
  630. digits, and hyphens, including at least one @i{asterisk},
  631. with no two @i{asterisks} adjacent.
  632. @i{word}---one or more uppercase letters, digits, and hyphens.
  633. @i{pos-int}---a positive @i{integer}.
  634. @menu
  635. * Additional Information about Parsing Logical Pathname Namestrings::
  636. * The Host part of a Logical Pathname Namestring::
  637. * The Device part of a Logical Pathname Namestring::
  638. * The Directory part of a Logical Pathname Namestring::
  639. * The Type part of a Logical Pathname Namestring::
  640. * The Version part of a Logical Pathname Namestring::
  641. * Wildcard Words in a Logical Pathname Namestring::
  642. * Lowercase Letters in a Logical Pathname Namestring::
  643. * Other Syntax in a Logical Pathname Namestring::
  644. @end menu
  645. @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
  646. @subsubsection Additional Information about Parsing Logical Pathname Namestrings
  647. @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
  648. @subsubsection The Host part of a Logical Pathname Namestring
  649. The @i{host} must have been defined as a @i{logical pathname} host;
  650. this can be done by using @b{setf} of @b{logical-pathname-translations}.
  651. The @i{logical pathname} host name @t{"SYS"} is reserved for the implementation.
  652. The existence and meaning of @t{SYS:} @i{logical pathnames}
  653. is @i{implementation-defined}.
  654. @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
  655. @subsubsection The Device part of a Logical Pathname Namestring
  656. There is no syntax for a @i{logical pathname} device since
  657. the device component of a @i{logical pathname} is always @t{:unspecific};
  658. see @ref{Unspecific Components of a Logical Pathname}.
  659. @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
  660. @subsubsection The Directory part of a Logical Pathname Namestring
  661. If a @i{relative-directory-marker} precedes the @i{directories},
  662. the directory component parsed is as @i{relative};
  663. otherwise, the directory component is parsed as @i{absolute}.
  664. If a @i{wild-inferiors-marker} is specified,
  665. it parses into @t{:wild-inferiors}.
  666. @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
  667. @subsubsection The Type part of a Logical Pathname Namestring
  668. The @i{type} of a @i{logical pathname} for a @i{source file}
  669. is @t{"LISP"}. This should be translated into whatever type is
  670. appropriate in a physical pathname.
  671. @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
  672. @subsubsection The Version part of a Logical Pathname Namestring
  673. Some @i{file systems} do not have @i{versions}.
  674. @i{Logical pathname} translation to such a @i{file system}
  675. ignores the @i{version}.
  676. This implies that a program cannot rely on being able to store
  677. more than one version of a file named by a @i{logical pathname}.
  678. If a @i{wildcard-version} is specified,
  679. it parses into @t{:wild}.
  680. @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
  681. @subsubsection Wildcard Words in a Logical Pathname Namestring
  682. Each @i{asterisk} in a @i{wildcard-word} matches a sequence of
  683. zero or more characters. The @i{wildcard-word} ``@t{*}''
  684. parses into @t{:wild}; other @i{wildcard-words} parse into @i{strings}.
  685. @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
  686. @subsubsection Lowercase Letters in a Logical Pathname Namestring
  687. When parsing @i{words} and @i{wildcard-words},
  688. lowercase letters are translated to uppercase.
  689. @node Other Syntax in a Logical Pathname Namestring, , Lowercase Letters in a Logical Pathname Namestring, Syntax of Logical Pathname Namestrings
  690. @subsubsection Other Syntax in a Logical Pathname Namestring
  691. The consequences of using characters other than those specified here
  692. in a @i{logical pathname} @i{namestring} are unspecified.
  693. The consequences of using any value not specified here as a
  694. @i{logical pathname} component are unspecified.
  695. @node Logical Pathname Components, , Syntax of Logical Pathname Namestrings, Logical Pathnames
  696. @subsection Logical Pathname Components
  697. @menu
  698. * Unspecific Components of a Logical Pathname::
  699. * Null Strings as Components of a Logical Pathname::
  700. @end menu
  701. @node Unspecific Components of a Logical Pathname, Null Strings as Components of a Logical Pathname, Logical Pathname Components, Logical Pathname Components
  702. @subsubsection Unspecific Components of a Logical Pathname
  703. The device component of a @i{logical pathname} is always @t{:unspecific};
  704. no other component of a @i{logical pathname} can be @t{:unspecific}.
  705. @node Null Strings as Components of a Logical Pathname, , Unspecific Components of a Logical Pathname, Logical Pathname Components
  706. @subsubsection Null Strings as Components of a Logical Pathname
  707. The null string, @t{""}, is not a valid value for any component of a @i{logical pathname}.
  708. @c end of including concept-logical-pathnames
  709. @node Filenames Dictionary, , Logical Pathnames, Filenames
  710. @section Filenames Dictionary
  711. @c including dict-pathnames
  712. @menu
  713. * pathname (System Class)::
  714. * logical-pathname (System Class)::
  715. * pathname::
  716. * make-pathname::
  717. * pathnamep::
  718. * pathname-host::
  719. * load-logical-pathname-translations::
  720. * logical-pathname-translations::
  721. * logical-pathname::
  722. * *default-pathname-defaults*::
  723. * namestring::
  724. * parse-namestring::
  725. * wild-pathname-p::
  726. * pathname-match-p::
  727. * translate-logical-pathname::
  728. * translate-pathname::
  729. * merge-pathnames::
  730. @end menu
  731. @node pathname (System Class), logical-pathname (System Class), Filenames Dictionary, Filenames Dictionary
  732. @subsection pathname [System Class]
  733. @subsubheading Class Precedence List::
  734. @b{pathname},
  735. @b{t}
  736. @subsubheading Description::
  737. A @i{pathname} is a structured @i{object} which represents a @i{filename}.
  738. There are two kinds of @i{pathnames}---@i{physical pathnames} and
  739. @i{logical pathnames}.
  740. @node logical-pathname (System Class), pathname, pathname (System Class), Filenames Dictionary
  741. @subsection logical-pathname [System Class]
  742. @subsubheading Class Precedence List::
  743. @b{logical-pathname},
  744. @b{pathname},
  745. @b{t}
  746. @subsubheading Description::
  747. A @i{pathname} that uses a @i{namestring} syntax that is
  748. @i{implementation-independent},
  749. and that has component values that are @i{implementation-independent}.
  750. @i{Logical pathnames} do not refer directly to @i{filenames}
  751. @subsubheading See Also::
  752. @ref{File System Concepts},
  753. @ref{Sharpsign P},
  754. @ref{Printing Pathnames}
  755. @node pathname, make-pathname, logical-pathname (System Class), Filenames Dictionary
  756. @subsection pathname [Function]
  757. @code{pathname} @i{pathspec} @result{} @i{pathname}
  758. @subsubheading Arguments and Values::
  759. @i{pathspec}---a @i{pathname designator}.
  760. @i{pathname}---a @i{pathname}.
  761. @subsubheading Description::
  762. Returns the @i{pathname} denoted by @i{pathspec}.
  763. If the @i{pathspec} @i{designator} is a @i{stream},
  764. the @i{stream} can be either open or closed;
  765. in both cases, the @b{pathname} returned
  766. corresponds to the @i{filename} used to open the @i{file}.
  767. @b{pathname} returns the same @i{pathname} for a @i{file stream}
  768. after it is closed as it did when it was open.
  769. If the @i{pathspec} @i{designator} is
  770. a @i{file stream} created by opening a @i{logical pathname},
  771. a @i{logical pathname} is returned.
  772. @subsubheading Examples::
  773. @example
  774. ;; There is a great degree of variability permitted here. The next
  775. ;; several examples are intended to illustrate just a few of the many
  776. ;; possibilities. Whether the name is canonicalized to a particular
  777. ;; case (either upper or lower) depends on both the file system and the
  778. ;; implementation since two different implementations using the same
  779. ;; file system might differ on many issues. How information is stored
  780. ;; internally (and possibly presented in #S notation) might vary,
  781. ;; possibly requiring `accessors' such as PATHNAME-NAME to perform case
  782. ;; conversion upon access. The format of a namestring is dependent both
  783. ;; on the file system and the implementation since, for example, one
  784. ;; implementation might include the host name in a namestring, and
  785. ;; another might not. #S notation would generally only be used in a
  786. ;; situation where no appropriate namestring could be constructed for use
  787. ;; with #P.
  788. (setq p1 (pathname "test"))
  789. @result{} #P"CHOCOLATE:TEST" ; with case canonicalization (e.g., VMS)
  790. @i{OR}@result{} #P"VANILLA:test" ; without case canonicalization (e.g., Unix)
  791. @i{OR}@result{} #P"test"
  792. @i{OR}@result{} #S(PATHNAME :HOST "STRAWBERRY" :NAME "TEST")
  793. @i{OR}@result{} #S(PATHNAME :HOST "BELGIAN-CHOCOLATE" :NAME "test")
  794. (setq p2 (pathname "test"))
  795. @result{} #P"CHOCOLATE:TEST"
  796. @i{OR}@result{} #P"VANILLA:test"
  797. @i{OR}@result{} #P"test"
  798. @i{OR}@result{} #S(PATHNAME :HOST "STRAWBERRY" :NAME "TEST")
  799. @i{OR}@result{} #S(PATHNAME :HOST "BELGIAN-CHOCOLATE" :NAME "test")
  800. (pathnamep p1) @result{} @i{true}
  801. (eq p1 (pathname p1)) @result{} @i{true}
  802. (eq p1 p2)
  803. @result{} @i{true}
  804. @i{OR}@result{} @i{false}
  805. (with-open-file (stream "test" :direction :output)
  806. (pathname stream))
  807. @result{} #P"ORANGE-CHOCOLATE:>Gus>test.lisp.newest"
  808. @end example
  809. @subsubheading See Also::
  810. @b{pathname},
  811. @b{logical-pathname},
  812. @ref{File System Concepts},
  813. @ref{Pathnames as Filenames}
  814. @node make-pathname, pathnamep, pathname, Filenames Dictionary
  815. @subsection make-pathname [Function]
  816. @code{make-pathname} @i{{&key} host device directory name type version defaults case}@*
  817. @result{} @i{pathname}
  818. @subsubheading Arguments and Values::
  819. @i{host}---a @i{valid physical pathname host}.
  820. Complicated defaulting behavior; see below.
  821. @i{device}---a @i{valid pathname device}.
  822. Complicated defaulting behavior; see below.
  823. @i{directory}---a @i{valid pathname directory}.
  824. Complicated defaulting behavior; see below.
  825. @i{name}---a @i{valid pathname name}.
  826. Complicated defaulting behavior; see below.
  827. @i{type}---a @i{valid pathname type}.
  828. Complicated defaulting behavior; see below.
  829. @i{version}---a @i{valid pathname version}.
  830. Complicated defaulting behavior; see below.
  831. @i{defaults}---a @i{pathname designator}.
  832. The default is a @i{pathname} whose host component is the same as the
  833. host component of the @i{value} of @b{*default-pathname-defaults*},
  834. and whose other components are all @b{nil}.
  835. @i{case}---one of @t{:common} or @t{:local}.
  836. The default is @t{:local}.
  837. @i{pathname}---a @i{pathname}.
  838. @subsubheading Description::
  839. Constructs and returns a @i{pathname} from the supplied keyword arguments.
  840. After the components supplied explicitly by
  841. @i{host},
  842. @i{device},
  843. @i{directory},
  844. @i{name},
  845. @i{type},
  846. and @i{version}
  847. are filled in,
  848. the merging rules used by @b{merge-pathnames}
  849. are used to fill in any
  850. unsupplied
  851. components
  852. from the defaults supplied by @i{defaults}.
  853. Whenever a @i{pathname} is constructed the components may be
  854. canonicalized if appropriate.
  855. For the explanation of the arguments that can be supplied for each component,
  856. see @ref{Pathname Components}.
  857. If @i{case} is supplied,
  858. it is treated as described in @ref{Case in Pathname Components}.
  859. The resulting @i{pathname} is a @i{logical pathname}
  860. if and only its host component
  861. is
  862. a @i{logical host}
  863. or a @i{string} that names a defined @i{logical host}.
  864. If the @i{directory} is a @i{string},
  865. it should be the name of a top level directory,
  866. and should not contain any punctuation characters; that is,
  867. specifying a @i{string}, @i{str}, is
  868. equivalent to specifying the list @t{(:absolute @i{str})}.
  869. Specifying the symbol @t{:wild} is equivalent to specifying the list
  870. @t{(:absolute :wild-inferiors)}, or @t{(:absolute :wild)}
  871. in a file system that does not support @t{:wild-inferiors}.
  872. @subsubheading Examples::
  873. @example
  874. ;; Implementation A -- an implementation with access to a single
  875. ;; Unix file system. This implementation happens to never display
  876. ;; the `host' information in a namestring, since there is only one host.
  877. (make-pathname :directory '(:absolute "public" "games")
  878. :name "chess" :type "db")
  879. @result{} #P"/public/games/chess.db"
  880. ;; Implementation B -- an implementation with access to one or more
  881. ;; VMS file systems. This implementation displays `host' information
  882. ;; in the namestring only when the host is not the local host.
  883. ;; It uses a double colon to separate a host name from the host's local
  884. ;; file name.
  885. (make-pathname :directory '(:absolute "PUBLIC" "GAMES")
  886. :name "CHESS" :type "DB")
  887. @result{} #P"SYS$DISK:[PUBLIC.GAMES]CHESS.DB"
  888. (make-pathname :host "BOBBY"
  889. :directory '(:absolute "PUBLIC" "GAMES")
  890. :name "CHESS" :type "DB")
  891. @result{} #P"BOBBY::SYS$DISK:[PUBLIC.GAMES]CHESS.DB"
  892. ;; Implementation C -- an implementation with simultaneous access to
  893. ;; multiple file systems from the same Lisp image. In this
  894. ;; implementation, there is a convention that any text preceding the
  895. ;; first colon in a pathname namestring is a host name.
  896. (dolist (case '(:common :local))
  897. (dolist (host '("MY-LISPM" "MY-VAX" "MY-UNIX"))
  898. (print (make-pathname :host host :case case
  899. :directory '(:absolute "PUBLIC" "GAMES")
  900. :name "CHESS" :type "DB"))))
  901. @t{ |> } #P"MY-LISPM:>public>games>chess.db"
  902. @t{ |> } #P"MY-VAX:SYS$DISK:[PUBLIC.GAMES]CHESS.DB"
  903. @t{ |> } #P"MY-UNIX:/public/games/chess.db"
  904. @t{ |> } #P"MY-LISPM:>public>games>chess.db"
  905. @t{ |> } #P"MY-VAX:SYS$DISK:[PUBLIC.GAMES]CHESS.DB"
  906. @t{ |> } #P"MY-UNIX:/PUBLIC/GAMES/CHESS.DB"
  907. @result{} NIL
  908. @end example
  909. @subsubheading Affected By::
  910. The @i{file system}.
  911. @subsubheading See Also::
  912. @ref{merge-pathnames}
  913. ,
  914. @b{pathname},
  915. @b{logical-pathname},
  916. @ref{File System Concepts},
  917. @ref{Pathnames as Filenames}
  918. @subsubheading Notes::
  919. Portable programs should not supply @t{:unspecific} for any component.
  920. See @ref{->UNSPECIFIC as a Component Value}.
  921. @node pathnamep, pathname-host, make-pathname, Filenames Dictionary
  922. @subsection pathnamep [Function]
  923. @code{pathnamep} @i{object} @result{} @i{generalized-boolean}
  924. @subsubheading Arguments and Values::
  925. @i{object}---an @i{object}.
  926. @i{generalized-boolean}---a @i{generalized boolean}.
  927. @subsubheading Description::
  928. Returns @i{true} if @i{object} is of @i{type} @b{pathname};
  929. otherwise, returns @i{false}.
  930. @subsubheading Examples::
  931. @example
  932. (setq q "test") @result{} "test"
  933. (pathnamep q) @result{} @i{false}
  934. (setq q (pathname "test"))
  935. @result{} #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME "test" :TYPE NIL
  936. :VERSION NIL)
  937. (pathnamep q) @result{} @i{true}
  938. (setq q (logical-pathname "SYS:SITE;FOO.SYSTEM"))
  939. @result{} #P"SYS:SITE;FOO.SYSTEM"
  940. (pathnamep q) @result{} @i{true}
  941. @end example
  942. @subsubheading Notes::
  943. @example
  944. (pathnamep @i{object}) @equiv{} (typep @i{object} 'pathname)
  945. @end example
  946. @node pathname-host, load-logical-pathname-translations, pathnamep, Filenames Dictionary
  947. @subsection pathname-host, pathname-device, pathname-directory,
  948. @subheading pathname-name, pathname-type, pathname-version
  949. @flushright
  950. @i{[Function]}
  951. @end flushright
  952. @code{pathname-host} @i{pathname {&key} case} @result{} @i{host}
  953. @code{pathname-device} @i{pathname {&key} case} @result{} @i{device}
  954. @code{pathname-directory} @i{pathname {&key} case} @result{} @i{directory}
  955. @code{pathname-name} @i{pathname {&key} case} @result{} @i{name}
  956. @code{pathname-type} @i{pathname {&key} case} @result{} @i{type}
  957. @code{pathname-version} @i{pathname} @result{} @i{version}
  958. @subsubheading Arguments and Values::
  959. @i{pathname}---a @i{pathname designator}.
  960. @i{case}---one of @t{:local} or @t{:common}.
  961. The default is @t{:local}.
  962. @i{host}---a @i{valid pathname host}.
  963. @i{device}---a @i{valid pathname device}.
  964. @i{directory}---a @i{valid pathname directory}.
  965. @i{name}---a @i{valid pathname name}.
  966. @i{type}---a @i{valid pathname type}.
  967. @i{version}---a @i{valid pathname version}.
  968. @subsubheading Description::
  969. These functions return the components of @i{pathname}.
  970. If the @i{pathname} @i{designator} is a @i{pathname},
  971. it represents the name used to open the file. This may be, but is
  972. not required to be, the actual name of the file.
  973. If @i{case} is supplied,
  974. it is treated as described in @ref{Case in Pathname Components}.
  975. @subsubheading Examples::
  976. @example
  977. (setq q (make-pathname :host "KATHY"
  978. :directory "CHAPMAN"
  979. :name "LOGIN" :type "COM"))
  980. @result{} #P"KATHY::[CHAPMAN]LOGIN.COM"
  981. (pathname-host q) @result{} "KATHY"
  982. (pathname-name q) @result{} "LOGIN"
  983. (pathname-type q) @result{} "COM"
  984. ;; Because namestrings are used, the results shown in the remaining
  985. ;; examples are not necessarily the only possible results. Mappings
  986. ;; from namestring representation to pathname representation are
  987. ;; dependent both on the file system involved and on the implementation
  988. ;; (since there may be several implementations which can manipulate the
  989. ;; the same file system, and those implementations are not constrained
  990. ;; to agree on all details). Consult the documentation for each
  991. ;; implementation for specific information on how namestrings are treated
  992. ;; that implementation.
  993. ;; VMS
  994. (pathname-directory (parse-namestring "[FOO.*.BAR]BAZ.LSP"))
  995. @result{} (:ABSOLUTE "FOO" "BAR")
  996. (pathname-directory (parse-namestring "[FOO.*.BAR]BAZ.LSP") :case :common)
  997. @result{} (:ABSOLUTE "FOO" "BAR")
  998. ;; Unix
  999. (pathname-directory "foo.l") @result{} NIL
  1000. (pathname-device "foo.l") @result{} :UNSPECIFIC
  1001. (pathname-name "foo.l") @result{} "foo"
  1002. (pathname-name "foo.l" :case :local) @result{} "foo"
  1003. (pathname-name "foo.l" :case :common) @result{} "FOO"
  1004. (pathname-type "foo.l") @result{} "l"
  1005. (pathname-type "foo.l" :case :local) @result{} "l"
  1006. (pathname-type "foo.l" :case :common) @result{} "L"
  1007. (pathname-type "foo") @result{} :UNSPECIFIC
  1008. (pathname-type "foo" :case :common) @result{} :UNSPECIFIC
  1009. (pathname-type "foo.") @result{} ""
  1010. (pathname-type "foo." :case :common) @result{} ""
  1011. (pathname-directory (parse-namestring "/foo/bar/baz.lisp") :case :local)
  1012. @result{} (:ABSOLUTE "foo" "bar")
  1013. (pathname-directory (parse-namestring "/foo/bar/baz.lisp") :case :local)
  1014. @result{} (:ABSOLUTE "FOO" "BAR")
  1015. (pathname-directory (parse-namestring "../baz.lisp"))
  1016. @result{} (:RELATIVE :UP)
  1017. (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/BAR/../Mum/baz"))
  1018. @result{} (:ABSOLUTE "foo" "BAR" :UP "Mum")
  1019. (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/BAR/../Mum/baz") :case :common)
  1020. @result{} (:ABSOLUTE "FOO" "bar" :UP "Mum")
  1021. (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/*/bar/baz.l"))
  1022. @result{} (:ABSOLUTE "foo" :WILD "bar")
  1023. (PATHNAME-DIRECTORY (PARSE-NAMESTRING "/foo/*/bar/baz.l") :case :common)
  1024. @result{} (:ABSOLUTE "FOO" :WILD "BAR")
  1025. ;; Symbolics LMFS
  1026. (pathname-directory (parse-namestring ">foo>**>bar>baz.lisp"))
  1027. @result{} (:ABSOLUTE "foo" :WILD-INFERIORS "bar")
  1028. (pathname-directory (parse-namestring ">foo>*>bar>baz.lisp"))
  1029. @result{} (:ABSOLUTE "foo" :WILD "bar")
  1030. (pathname-directory (parse-namestring ">foo>*>bar>baz.lisp") :case :common)
  1031. @result{} (:ABSOLUTE "FOO" :WILD "BAR")
  1032. (pathname-device (parse-namestring ">foo>baz.lisp")) @result{} :UNSPECIFIC
  1033. @end example
  1034. @subsubheading Affected By::
  1035. The @i{implementation} and the host @i{file system}.
  1036. @subsubheading Exceptional Situations::
  1037. Should signal an error of @i{type} @b{type-error} if its first argument is not a @i{pathname}.
  1038. @subsubheading See Also::
  1039. @b{pathname},
  1040. @b{logical-pathname},
  1041. @ref{File System Concepts},
  1042. @ref{Pathnames as Filenames}
  1043. @node load-logical-pathname-translations, logical-pathname-translations, pathname-host, Filenames Dictionary
  1044. @subsection load-logical-pathname-translations [Function]
  1045. @code{load-logical-pathname-translations} @i{host} @result{} @i{just-loaded}
  1046. @subsubheading Arguments and Values::
  1047. @i{host}---a @i{string}.
  1048. @i{just-loaded}---a @i{generalized boolean}.
  1049. @subsubheading Description::
  1050. Searches for and loads the definition of a @i{logical host} named @i{host},
  1051. if it is not already defined.
  1052. The specific nature of the search is @i{implementation-defined}.
  1053. If the @i{host} is already defined,
  1054. no attempt to find or load a definition is attempted,
  1055. and @i{false} is returned.
  1056. If the @i{host} is not already defined,
  1057. but a definition is successfully found and loaded,
  1058. @i{true} is returned.
  1059. Otherwise, an error is signaled.
  1060. @subsubheading Examples::
  1061. @example
  1062. (translate-logical-pathname "hacks:weather;barometer.lisp.newest")
  1063. @t{ |> } Error: The logical host HACKS is not defined.
  1064. (load-logical-pathname-translations "HACKS")
  1065. @t{ |> } ;; Loading SYS:SITE;HACKS.TRANSLATIONS
  1066. @t{ |> } ;; Loading done.
  1067. @result{} @i{true}
  1068. (translate-logical-pathname "hacks:weather;barometer.lisp.newest")
  1069. @result{} #P"HELIUM:[SHARED.HACKS.WEATHER]BAROMETER.LSP;0"
  1070. (load-logical-pathname-translations "HACKS")
  1071. @result{} @i{false}
  1072. @end example
  1073. @subsubheading Exceptional Situations::
  1074. If no definition is found, an error of @i{type} @b{error} is signaled.
  1075. @subsubheading See Also::
  1076. @b{logical-pathname}
  1077. @subsubheading Notes::
  1078. @i{Logical pathname} definitions will be created not just by
  1079. @i{implementors} but also by @i{programmers}. As such,
  1080. it is important that the search strategy be documented.
  1081. For example, an @i{implementation} might define that the
  1082. definition of a @i{host} is to be found in a file called
  1083. ``@i{host}.translations'' in some specifically named directory.
  1084. @node logical-pathname-translations, logical-pathname, load-logical-pathname-translations, Filenames Dictionary
  1085. @subsection logical-pathname-translations [Accessor]
  1086. @code{logical-pathname-translations} @i{host} @result{} @i{translations}
  1087. (setf (@code{ logical-pathname-translations} @i{host}) new-translations)@*
  1088. @subsubheading Arguments and Values::
  1089. @i{host}--a @i{logical host designator}.
  1090. @i{translations}, @i{new-translations}---a @i{list}.
  1091. @subsubheading Description::
  1092. Returns the host's @i{list} of translations.
  1093. Each translation is a @i{list} of at least two elements:
  1094. @i{from-wildcard} and @i{to-wildcard}. Any
  1095. additional elements are @i{implementation-defined}.
  1096. @i{From-wildcard} is a
  1097. @i{logical pathname} whose host is @i{host}.
  1098. @i{To-wildcard} is a @i{pathname}.
  1099. [Reviewer Note by Laddaga: Can this be a logical pathname?]
  1100. @t{(setf (logical-pathname-translations @i{host}) @i{translations})} sets a
  1101. @i{logical pathname} host's
  1102. @i{list} of @i{translations}. If @i{host}
  1103. is a @i{string} that has
  1104. not been previously used as
  1105. a @i{logical pathname} host, a new
  1106. @i{logical pathname} host is defined;
  1107. otherwise an existing host's translations are
  1108. replaced. @i{logical pathname} host names are compared with @b{string-equal}.
  1109. When setting the translations list, each @i{from-wildcard}
  1110. can be a @i{logical pathname} whose
  1111. host is @i{host} or a @i{logical pathname} namestring
  1112. parseable by @t{(parse-namestring @i{string} @i{host})},
  1113. where @i{host}
  1114. represents the appropriate @i{object} as defined
  1115. by @b{parse-namestring}. Each
  1116. @i{to-wildcard} can be anything coercible to a
  1117. @i{pathname} by
  1118. @t{(pathname @i{to-wildcard})}.
  1119. If @i{to-wildcard} coerces to a @i{logical pathname},
  1120. @b{translate-logical-pathname}
  1121. will perform repeated translation steps when
  1122. it uses it.
  1123. @i{host} is either the host component of a
  1124. @i{logical pathname} or a
  1125. @i{string} that has been defined
  1126. as a @i{logical pathname} host name by @b{setf} of
  1127. @b{logical-pathname-translations}.
  1128. @subsubheading Examples::
  1129. [Reviewer Note by Laddaga: Shouldn't there be some @t{*.*}'s in the list
  1130. of translations for @t{PROG} below?]
  1131. @example
  1132. ;;;A very simple example of setting up a logical pathname host. No
  1133. ;;;translations are necessary to get around file system restrictions, so
  1134. ;;;all that is necessary is to specify the root of the physical directory
  1135. ;;;tree that contains the logical file system.
  1136. ;;;The namestring syntax on the right-hand side is implementation-dependent.
  1137. (setf (logical-pathname-translations "foo")
  1138. '(("**;*.*.*" "MY-LISPM:>library>foo>**>")))
  1139. ;;;Sample use of that logical pathname. The return value
  1140. ;;;is implementation-dependent.
  1141. (translate-logical-pathname "foo:bar;baz;mum.quux.3")
  1142. @result{} #P"MY-LISPM:>library>foo>bar>baz>mum.quux.3"
  1143. ;;;A more complex example, dividing the files among two file servers
  1144. ;;;and several different directories. This Unix doesn't support
  1145. ;;;:WILD-INFERIORS in the directory, so each directory level must
  1146. ;;;be translated individually. No file name or type translations
  1147. ;;;are required except for .MAIL to .MBX.
  1148. ;;;The namestring syntax on the right-hand side is implementation-dependent.
  1149. (setf (logical-pathname-translations "prog")
  1150. '(("RELEASED;*.*.*" "MY-UNIX:/sys/bin/my-prog/")
  1151. ("RELEASED;*;*.*.*" "MY-UNIX:/sys/bin/my-prog/*/")
  1152. ("EXPERIMENTAL;*.*.*" "MY-UNIX:/usr/Joe/development/prog/")
  1153. ("EXPERIMENTAL;DOCUMENTATION;*.*.*"
  1154. "MY-VAX:SYS$DISK:[JOE.DOC]")
  1155. ("EXPERIMENTAL;*;*.*.*" "MY-UNIX:/usr/Joe/development/prog/*/")
  1156. ("MAIL;**;*.MAIL" "MY-VAX:SYS$DISK:[JOE.MAIL.PROG...]*.MBX")))
  1157. ;;;Sample use of that logical pathname. The return value
  1158. ;;;is implementation-dependent.
  1159. (translate-logical-pathname "prog:mail;save;ideas.mail.3")
  1160. @result{} #P"MY-VAX:SYS$DISK:[JOE.MAIL.PROG.SAVE]IDEAS.MBX.3"
  1161. ;;;Example translations for a program that uses three files main.lisp,
  1162. ;;;auxiliary.lisp, and documentation.lisp. These translations might be
  1163. ;;;supplied by a software supplier as examples.
  1164. ;;;For Unix with long file names
  1165. (setf (logical-pathname-translations "prog")
  1166. '(("CODE;*.*.*" "/lib/prog/")))
  1167. ;;;Sample use of that logical pathname. The return value
  1168. ;;;is implementation-dependent.
  1169. (translate-logical-pathname "prog:code;documentation.lisp")
  1170. @result{} #P"/lib/prog/documentation.lisp"
  1171. ;;;For Unix with 14-character file names, using .lisp as the type
  1172. (setf (logical-pathname-translations "prog")
  1173. '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
  1174. ("CODE;*.*.*" "/lib/prog/")))
  1175. ;;;Sample use of that logical pathname. The return value
  1176. ;;;is implementation-dependent.
  1177. (translate-logical-pathname "prog:code;documentation.lisp")
  1178. @result{} #P"/lib/prog/docum.lisp"
  1179. ;;;For Unix with 14-character file names, using .l as the type
  1180. ;;;The second translation shortens the compiled file type to .b
  1181. (setf (logical-pathname-translations "prog")
  1182. `(("**;*.LISP.*" ,(logical-pathname "PROG:**;*.L.*"))
  1183. (,(compile-file-pathname (logical-pathname "PROG:**;*.LISP.*"))
  1184. ,(logical-pathname "PROG:**;*.B.*"))
  1185. ("CODE;DOCUMENTATION.*.*" "/lib/prog/documentatio.*")
  1186. ("CODE;*.*.*" "/lib/prog/")))
  1187. ;;;Sample use of that logical pathname. The return value
  1188. ;;;is implementation-dependent.
  1189. (translate-logical-pathname "prog:code;documentation.lisp")
  1190. @result{} #P"/lib/prog/documentatio.l"
  1191. ;;;For a Cray with 6 character names and no directories, types, or versions.
  1192. (setf (logical-pathname-translations "prog")
  1193. (let ((l '(("MAIN" "PGMN")
  1194. ("AUXILIARY" "PGAUX")
  1195. ("DOCUMENTATION" "PGDOC")))
  1196. (logpath (logical-pathname "prog:code;"))
  1197. (phypath (pathname "XXX")))
  1198. (append
  1199. ;; Translations for source files
  1200. (mapcar #'(lambda (x)
  1201. (let ((log (first x))
  1202. (phy (second x)))
  1203. (list (make-pathname :name log
  1204. :type "LISP"
  1205. :version :wild
  1206. :defaults logpath)
  1207. (make-pathname :name phy
  1208. :defaults phypath))))
  1209. l)
  1210. ;; Translations for compiled files
  1211. (mapcar #'(lambda (x)
  1212. (let* ((log (first x))
  1213. (phy (second x))
  1214. (com (compile-file-pathname
  1215. (make-pathname :name log
  1216. :type "LISP"
  1217. :version :wild
  1218. :defaults logpath))))
  1219. (setq phy (concatenate 'string phy "B"))
  1220. (list com
  1221. (make-pathname :name phy
  1222. :defaults phypath))))
  1223. l))))
  1224. ;;;Sample use of that logical pathname. The return value
  1225. ;;;is implementation-dependent.
  1226. (translate-logical-pathname "prog:code;documentation.lisp")
  1227. @result{} #P"PGDOC"
  1228. @end example
  1229. @subsubheading Exceptional Situations::
  1230. If @i{host} is incorrectly supplied,
  1231. an error of @i{type} @b{type-error} is signaled.
  1232. @subsubheading See Also::
  1233. @b{logical-pathname},
  1234. @ref{Pathnames as Filenames}
  1235. @subsubheading Notes::
  1236. Implementations can define additional @i{functions}
  1237. that operate on @i{logical pathname} hosts,
  1238. for example to specify additional translation rules or options.
  1239. @node logical-pathname, *default-pathname-defaults*, logical-pathname-translations, Filenames Dictionary
  1240. @subsection logical-pathname [Function]
  1241. @code{logical-pathname} @i{pathspec} @result{} @i{logical-pathname}
  1242. @subsubheading Arguments and Values::
  1243. @i{pathspec}---a @i{logical pathname},
  1244. a @i{logical pathname} @i{namestring},
  1245. or a @i{stream}.
  1246. @i{logical-pathname}---a @i{logical pathname}.
  1247. @subsubheading Description::
  1248. @b{logical-pathname} converts @i{pathspec} to a
  1249. @i{logical pathname} and returns the new @i{logical pathname}.
  1250. If @i{pathspec} is a @i{logical pathname} @i{namestring},
  1251. it should contain a host component and its following @i{colon}.
  1252. If @i{pathspec} is a @i{stream}, it should be one
  1253. for which @b{pathname} returns a @i{logical pathname}.
  1254. If @i{pathspec} is a @i{stream}, the @i{stream} can be either open or closed.
  1255. @b{logical-pathname} returns the same @i{logical pathname} after a
  1256. file is closed as it did when the file was open.
  1257. It is an error if @i{pathspec} is a @i{stream} that is
  1258. created with
  1259. @b{make-two-way-stream},
  1260. @b{make-echo-stream},
  1261. @b{make-broadcast-stream},
  1262. @b{make-concatenated-stream},
  1263. @b{make-string-input-stream},
  1264. or
  1265. @b{make-string-output-stream}.
  1266. @subsubheading Exceptional Situations::
  1267. Signals an error of @i{type} @b{type-error} if @i{pathspec} isn't supplied correctly.
  1268. @subsubheading See Also::
  1269. @b{logical-pathname},
  1270. @ref{translate-logical-pathname}
  1271. ,
  1272. @ref{Logical Pathnames}
  1273. @node *default-pathname-defaults*, namestring, logical-pathname, Filenames Dictionary
  1274. @subsection *default-pathname-defaults* [Variable]
  1275. @subsubheading Value Type::
  1276. a @i{pathname} @i{object}.
  1277. @subsubheading Initial Value::
  1278. An @i{implementation-dependent} @i{pathname},
  1279. typically in the working directory that was current when @r{Common Lisp} was started up.
  1280. @subsubheading Description::
  1281. a @i{pathname}, used as the default whenever a @i{function}
  1282. needs a default @i{pathname} and one is not supplied.
  1283. @subsubheading Examples::
  1284. @example
  1285. ;; This example illustrates a possible usage for a hypothetical Lisp running on a
  1286. ;; DEC TOPS-20 file system. Since pathname conventions vary between Lisp
  1287. ;; implementations and host file system types, it is not possible to provide a
  1288. ;; general-purpose, conforming example.
  1289. *default-pathname-defaults* @result{} #P"PS:<FRED>"
  1290. (merge-pathnames (make-pathname :name "CALENDAR"))
  1291. @result{} #P"PS:<FRED>CALENDAR"
  1292. (let ((*default-pathname-defaults* (pathname "<MARY>")))
  1293. (merge-pathnames (make-pathname :name "CALENDAR")))
  1294. @result{} #P"<MARY>CALENDAR"
  1295. @end example
  1296. @subsubheading Affected By::
  1297. The @i{implementation}.
  1298. @node namestring, parse-namestring, *default-pathname-defaults*, Filenames Dictionary
  1299. @subsection namestring, file-namestring, directory-namestring,
  1300. @subheading host-namestring, enough-namestring
  1301. @flushright
  1302. @i{[Function]}
  1303. @end flushright
  1304. @code{namestring} @i{pathname} @result{} @i{namestring}
  1305. @code{file-namestring} @i{pathname} @result{} @i{namestring}
  1306. @code{directory-namestring} @i{pathname} @result{} @i{namestring}
  1307. @code{host-namestring} @i{pathname} @result{} @i{namestring}
  1308. @code{enough-namestring} @i{pathname {&optional} defaults} @result{} @i{namestring}
  1309. @subsubheading Arguments and Values::
  1310. @i{pathname}---a @i{pathname designator}.
  1311. @i{defaults}---a @i{pathname designator}.
  1312. The default is the @i{value} of @b{*default-pathname-defaults*}.
  1313. @i{namestring}---a @i{string} or @b{nil}.
  1314. [Editorial Note by KMP: Under what circumstances can NIL be returned??]
  1315. @subsubheading Description::
  1316. These functions convert @i{pathname} into a namestring.
  1317. The name represented by @i{pathname} is returned as a @i{namestring}
  1318. in an @i{implementation-dependent} canonical form.
  1319. @b{namestring} returns the full form of @i{pathname}.
  1320. @b{file-namestring} returns just the name, type, and version
  1321. components of @i{pathname}.
  1322. @b{directory-namestring} returns the directory name portion.
  1323. @b{host-namestring} returns the host name.
  1324. @b{enough-namestring} returns an abbreviated namestring
  1325. that is just sufficient to identify the file named by @i{pathname}
  1326. when considered relative to the @i{defaults}.
  1327. It is required that
  1328. @example
  1329. (merge-pathnames (enough-namestring pathname defaults) defaults)
  1330. @equiv{} (merge-pathnames (parse-namestring pathname nil defaults) defaults)
  1331. @end example
  1332. in all cases, and the result of @b{enough-namestring} is
  1333. the shortest reasonable @i{string} that will satisfy this criterion.
  1334. It is not necessarily possible to construct a valid @i{namestring}
  1335. by concatenating some of the three shorter @i{namestrings} in some order.
  1336. @subsubheading Examples::
  1337. @example
  1338. (namestring "getty")
  1339. @result{} "getty"
  1340. (setq q (make-pathname :host "kathy"
  1341. :directory
  1342. (pathname-directory *default-pathname-defaults*)
  1343. :name "getty"))
  1344. @result{} #S(PATHNAME :HOST "kathy" :DEVICE NIL :DIRECTORY @i{directory-name}
  1345. :NAME "getty" :TYPE NIL :VERSION NIL)
  1346. (file-namestring q) @result{} "getty"
  1347. (directory-namestring q) @result{} @i{directory-name}
  1348. (host-namestring q) @result{} "kathy"
  1349. @end example
  1350. @example
  1351. ;;;Using Unix syntax and the wildcard conventions used by the
  1352. ;;;particular version of Unix on which this example was created:
  1353. (namestring
  1354. (translate-pathname "/usr/dmr/hacks/frob.l"
  1355. "/usr/d*/hacks/*.l"
  1356. "/usr/d*/backup/hacks/backup-*.*"))
  1357. @result{} "/usr/dmr/backup/hacks/backup-frob.l"
  1358. (namestring
  1359. (translate-pathname "/usr/dmr/hacks/frob.l"
  1360. "/usr/d*/hacks/fr*.l"
  1361. "/usr/d*/backup/hacks/backup-*.*"))
  1362. @result{} "/usr/dmr/backup/hacks/backup-ob.l"
  1363. ;;;This is similar to the above example but uses two different hosts,
  1364. ;;;U: which is a Unix and V: which is a VMS. Note the translation
  1365. ;;;of file type and alphabetic case conventions.
  1366. (namestring
  1367. (translate-pathname "U:/usr/dmr/hacks/frob.l"
  1368. "U:/usr/d*/hacks/*.l"
  1369. "V:SYS$DISK:[D*.BACKUP.HACKS]BACKUP-*.*"))
  1370. @result{} "V:SYS$DISK:[DMR.BACKUP.HACKS]BACKUP-FROB.LSP"
  1371. (namestring
  1372. (translate-pathname "U:/usr/dmr/hacks/frob.l"
  1373. "U:/usr/d*/hacks/fr*.l"
  1374. "V:SYS$DISK:[D*.BACKUP.HACKS]BACKUP-*.*"))
  1375. @result{} "V:SYS$DISK:[DMR.BACKUP.HACKS]BACKUP-OB.LSP"
  1376. @end example
  1377. @subsubheading See Also::
  1378. @ref{truename}
  1379. ,
  1380. @ref{merge-pathnames}
  1381. ,
  1382. @b{pathname},
  1383. @b{logical-pathname},
  1384. @ref{File System Concepts},
  1385. @ref{Pathnames as Filenames}
  1386. @node parse-namestring, wild-pathname-p, namestring, Filenames Dictionary
  1387. @subsection parse-namestring [Function]
  1388. @code{parse-namestring} @i{thing {&optional} host default-pathname {&key} start end junk-allowed}@*
  1389. @result{} @i{pathname, position}
  1390. @subsubheading Arguments and Values::
  1391. @i{thing}---a @i{string},
  1392. a @i{pathname},
  1393. or a @i{stream associated with a file}.
  1394. @i{host}---a @i{valid pathname host}, a @i{logical host}, or @b{nil}.
  1395. @i{default-pathname}---a @i{pathname designator}.
  1396. The default is the @i{value} of @b{*default-pathname-defaults*}.
  1397. @i{start}, @i{end}---@i{bounding index designators} of @i{thing}.
  1398. The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.
  1399. @i{junk-allowed}---a @i{generalized boolean}.
  1400. The default is @i{false}.
  1401. @i{pathname}---a @i{pathname}, or @b{nil}.
  1402. @i{position}---a @i{bounding index designator} for @i{thing}.
  1403. @subsubheading Description::
  1404. Converts @i{thing} into a @i{pathname}.
  1405. The @i{host} supplies a host name with respect to which the parsing occurs.
  1406. If @i{thing} is a @i{stream associated with a file},
  1407. processing proceeds as if the @i{pathname} used to open that @i{file}
  1408. had been supplied instead.
  1409. If @i{thing} is a @i{pathname},
  1410. the @i{host} and the host component of @i{thing} are compared.
  1411. If they match,
  1412. two values are immediately returned: @i{thing} and @i{start};
  1413. otherwise (if they do not match), an error is signaled.
  1414. Otherwise (if @i{thing} is a @i{string}),
  1415. @b{parse-namestring} parses the name of a @i{file} within
  1416. the substring of @i{thing} bounded by @i{start} and @i{end}.
  1417. If @i{thing} is a @i{string} then
  1418. the substring of @i{thing} @i{bounded} by @i{start} and @i{end}
  1419. is parsed into a @i{pathname}
  1420. as follows:
  1421. @table @asis
  1422. @item @t{*}
  1423. If @i{host} is a @i{logical host} then @i{thing} is parsed
  1424. as a @i{logical pathname} @i{namestring}
  1425. on the @i{host}.
  1426. @item @t{*}
  1427. If @i{host} is @b{nil} and @i{thing} is a syntactically valid
  1428. @i{logical pathname} @i{namestring} containing an explicit host,
  1429. then it is parsed as a @i{logical pathname} @i{namestring}.
  1430. @item @t{*}
  1431. If @i{host} is @b{nil},
  1432. @i{default-pathname} is a @i{logical pathname},
  1433. and @i{thing} is a syntactically valid @i{logical pathname} @i{namestring}
  1434. without an explicit host,
  1435. then it is parsed as a @i{logical pathname} @i{namestring}
  1436. on the host that is the host component of @i{default-pathname}.
  1437. @item @t{*}
  1438. Otherwise, the parsing of @i{thing} is @i{implementation-defined}.
  1439. @end table
  1440. In the first
  1441. of these
  1442. cases,
  1443. the host portion of the @i{logical pathname} namestring
  1444. and its following @i{colon} are optional.
  1445. If the host portion of the namestring and @i{host}
  1446. are both present and do not match,
  1447. an error is signaled.
  1448. If @i{junk-allowed} is @i{true},
  1449. then the @i{primary value} is the @i{pathname} parsed
  1450. or, if no syntactically correct @i{pathname} was seen, @b{nil}.
  1451. If @i{junk-allowed} is @i{false},
  1452. then the entire substring is scanned,
  1453. and the @i{primary value} is the @i{pathname} parsed.
  1454. In either case, the @i{secondary value}
  1455. is the index into @i{thing} of the delimiter that terminated the parse,
  1456. or the index beyond the substring if the parse terminated at the end of the substring
  1457. (as will always be the case if @i{junk-allowed} is @i{false}).
  1458. Parsing a @i{null} @i{string} always succeeds,
  1459. producing a @i{pathname} with all components (except the host) equal to @b{nil}.
  1460. If @i{thing} contains an explicit host name and no explicit device name,
  1461. then it is @i{implementation-defined} whether @b{parse-namestring}
  1462. will supply the standard default device for that host as the device component
  1463. of the resulting @i{pathname}.
  1464. @subsubheading Examples::
  1465. @example
  1466. (setq q (parse-namestring "test"))
  1467. @result{} #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME "test"
  1468. :TYPE NIL :VERSION NIL)
  1469. (pathnamep q) @result{} @i{true}
  1470. (parse-namestring "test")
  1471. @result{} #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME "test"
  1472. :TYPE NIL :VERSION NIL), 4
  1473. (setq s (open @i{xxx})) @result{} #<Input File Stream...>
  1474. (parse-namestring s)
  1475. @result{} #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME @i{xxx}
  1476. :TYPE NIL :VERSION NIL), 0
  1477. (parse-namestring "test" nil nil :start 2 :end 4 )
  1478. @result{} #S(PATHNAME ...), 15
  1479. (parse-namestring "foo.lisp")
  1480. @result{} #P"foo.lisp"
  1481. @end example
  1482. @subsubheading Exceptional Situations::
  1483. If @i{junk-allowed} is @i{false},
  1484. an error of @i{type} @b{parse-error} is signaled if @i{thing}
  1485. does not consist entirely of the representation of a @i{pathname},
  1486. possibly surrounded on either side by @i{whitespace}_1 characters if that is
  1487. appropriate to the cultural conventions of the implementation.
  1488. If @i{host} is supplied and not @b{nil},
  1489. and @i{thing} contains a manifest host name,
  1490. an error of @i{type} @b{error} is signaled if the hosts do not match.
  1491. If @i{thing} is a @i{logical pathname} namestring
  1492. and if the host portion of the namestring and @i{host}
  1493. are both present and do not match,
  1494. an error of @i{type} @b{error} is signaled.
  1495. @subsubheading See Also::
  1496. @b{pathname},
  1497. @b{logical-pathname},
  1498. @ref{File System Concepts},
  1499. @ref{->UNSPECIFIC as a Component Value},
  1500. @ref{Pathnames as Filenames}
  1501. @node wild-pathname-p, pathname-match-p, parse-namestring, Filenames Dictionary
  1502. @subsection wild-pathname-p [Function]
  1503. @code{wild-pathname-p} @i{pathname {&optional} field-key} @result{} @i{generalized-boolean}
  1504. @subsubheading Arguments and Values::
  1505. @i{pathname}---a @i{pathname designator}.
  1506. @i{Field-key}---one of @t{:host},
  1507. @t{:device}
  1508. @t{:directory},
  1509. @t{:name},
  1510. @t{:type},
  1511. @t{:version},
  1512. or @b{nil}.
  1513. @i{generalized-boolean}---a @i{generalized boolean}.
  1514. @subsubheading Description::
  1515. @b{wild-pathname-p} tests @i{pathname} for the presence of wildcard components.
  1516. If @i{pathname} is a @i{pathname} (as returned by @b{pathname})
  1517. it represents the name used to open the file. This may be, but is
  1518. not required to be, the actual name of the file.
  1519. If @i{field-key} is not supplied or @b{nil}, @b{wild-pathname-p}
  1520. returns true if @i{pathname} has any wildcard components, @b{nil}
  1521. if @i{pathname} has none.
  1522. If @i{field-key} is @i{non-nil}, @b{wild-pathname-p}
  1523. returns true if the indicated component of @i{pathname} is a wildcard,
  1524. @b{nil} if the component is not a wildcard.
  1525. @subsubheading Examples::
  1526. @example
  1527. ;;;The following examples are not portable. They are written to run
  1528. ;;;with particular file systems and particular wildcard conventions.
  1529. ;;;Other implementations will behave differently. These examples are
  1530. ;;;intended to be illustrative, not to be prescriptive.
  1531. (wild-pathname-p (make-pathname :name :wild)) @result{} @i{true}
  1532. (wild-pathname-p (make-pathname :name :wild) :name) @result{} @i{true}
  1533. (wild-pathname-p (make-pathname :name :wild) :type) @result{} @i{false}
  1534. (wild-pathname-p (pathname "s:>foo>**>")) @result{} @i{true} ;Lispm
  1535. (wild-pathname-p (pathname :name "F*O")) @result{} @i{true} ;Most places
  1536. @end example
  1537. @subsubheading Exceptional Situations::
  1538. If @i{pathname} is not a @i{pathname}, a @i{string},
  1539. or a @i{stream associated with a file} an error of @i{type} @b{type-error} is signaled.
  1540. @subsubheading See Also::
  1541. @b{pathname},
  1542. @b{logical-pathname},
  1543. @ref{File System Concepts},
  1544. @ref{Pathnames as Filenames}
  1545. @subsubheading Notes::
  1546. Not all implementations support wildcards in all fields.
  1547. See @ref{->WILD as a Component Value} and @ref{Restrictions on Wildcard Pathnames}.
  1548. @node pathname-match-p, translate-logical-pathname, wild-pathname-p, Filenames Dictionary
  1549. @subsection pathname-match-p [Function]
  1550. @code{pathname-match-p} @i{pathname wildcard} @result{} @i{generalized-boolean}
  1551. @subsubheading Arguments and Values::
  1552. @i{pathname}---a @i{pathname designator}.
  1553. @i{wildcard}---a @i{designator} for a @i{wild} @i{pathname}.
  1554. @i{generalized-boolean}---a @i{generalized boolean}.
  1555. @subsubheading Description::
  1556. @b{pathname-match-p} returns true if
  1557. @i{pathname} matches @i{wildcard}, otherwise @b{nil}. The
  1558. matching rules are @i{implementation-defined} but should be consistent with
  1559. @b{directory}. Missing components of @i{wildcard} default to @t{:wild}.
  1560. It is valid for @i{pathname} to be a wild @i{pathname};
  1561. a wildcard field in @i{pathname} only matches a
  1562. wildcard field in @i{wildcard} (@i{i.e.}, @b{pathname-match-p} is not commutative).
  1563. It is valid for @i{wildcard} to be a non-wild @i{pathname}.
  1564. @subsubheading Exceptional Situations::
  1565. If @i{pathname} or @i{wildcard} is not a @i{pathname}, @i{string},
  1566. or @i{stream associated with a file} an error of @i{type} @b{type-error} is signaled.
  1567. @subsubheading See Also::
  1568. @ref{directory}
  1569. ,
  1570. @b{pathname},
  1571. @b{logical-pathname},
  1572. @ref{File System Concepts},
  1573. @ref{Pathnames as Filenames}
  1574. @node translate-logical-pathname, translate-pathname, pathname-match-p, Filenames Dictionary
  1575. @subsection translate-logical-pathname [Function]
  1576. @code{translate-logical-pathname} @i{pathname {&key}} @result{} @i{physical-pathname}
  1577. @subsubheading Arguments and Values::
  1578. @i{pathname}---a @i{pathname designator},
  1579. or a @i{logical pathname} @i{namestring}.
  1580. @i{physical-pathname}---a @i{physical pathname}.
  1581. @subsubheading Description::
  1582. Translates @i{pathname} to a @i{physical pathname}, which it returns.
  1583. If @i{pathname} is a @i{stream}, the
  1584. @i{stream} can be either open or closed.
  1585. @b{translate-logical-pathname} returns the same
  1586. physical pathname after a
  1587. file is closed as it did when the file was open.
  1588. It is an error if @i{pathname} is a @i{stream} that is
  1589. created with @b{make-two-way-stream},
  1590. @b{make-echo-stream},
  1591. @b{make-broadcast-stream},
  1592. @b{make-concatenated-stream}, @b{make-string-input-stream},
  1593. @b{make-string-output-stream}.
  1594. If @i{pathname} is a @i{logical pathname} namestring,
  1595. the host portion of the
  1596. @i{logical pathname} namestring and its following @i{colon} are required.
  1597. @i{Pathname} is first coerced to a @i{pathname}.
  1598. If the coerced @i{pathname} is a physical pathname, it is returned.
  1599. If the coerced @i{pathname} is a @i{logical pathname},
  1600. the first matching translation (according to @b{pathname-match-p})
  1601. of the @i{logical pathname} host is applied, as if by calling
  1602. @b{translate-pathname}. If the result is
  1603. a @i{logical pathname}, this process is repeated.
  1604. When the result is
  1605. finally a physical pathname, it is returned.
  1606. If no translation matches, an error
  1607. is signaled.
  1608. @b{translate-logical-pathname} might perform additional translations,
  1609. typically to provide translation of file types to local naming
  1610. conventions, to accomodate physical file systems with limited length
  1611. names, or to deal with special character requirements such as
  1612. translating hyphens to underscores or uppercase letters to lowercase.
  1613. Any such additional translations are @i{implementation-defined}. Some
  1614. implementations do no additional translations.
  1615. There are no specified keyword arguments for
  1616. @b{translate-logical-pathname},
  1617. but implementations are permitted to extend
  1618. it by adding keyword arguments.
  1619. @subsubheading Examples::
  1620. See @b{logical-pathname-translations}.
  1621. @subsubheading Exceptional Situations::
  1622. If @i{pathname} is incorrectly supplied, an error of @i{type} @b{type-error} is signaled.
  1623. If no translation matches, an error of @i{type} @b{file-error} is signaled.
  1624. [Editorial Note by KMP: Is file-error really right, or should it be pathname-error?]
  1625. @subsubheading See Also::
  1626. @ref{logical-pathname}
  1627. ,
  1628. @ref{logical-pathname-translations}
  1629. ,
  1630. @b{logical-pathname},
  1631. @ref{File System Concepts},
  1632. @ref{Pathnames as Filenames}
  1633. @node translate-pathname, merge-pathnames, translate-logical-pathname, Filenames Dictionary
  1634. @subsection translate-pathname [Function]
  1635. @code{translate-pathname} @i{source from-wildcard to-wildcard {&key}}@*
  1636. @result{} @i{translated-pathname}
  1637. @subsubheading Arguments and Values::
  1638. @i{source}---a @i{pathname designator}.
  1639. @i{from-wildcard}---a @i{pathname designator}.
  1640. @i{to-wildcard}---a @i{pathname designator}.
  1641. @i{translated-pathname}---a @i{pathname}.
  1642. @subsubheading Description::
  1643. @b{translate-pathname} translates @i{source}
  1644. (that matches @i{from-wildcard}) into a corresponding @i{pathname}
  1645. that matches @i{to-wildcard}, and returns the corresponding @i{pathname}.
  1646. The resulting @i{pathname} is @i{to-wildcard} with each wildcard or missing
  1647. field replaced by a portion of @i{source}. A ``wildcard field'' is a
  1648. @i{pathname} component with a value of @t{:wild}, a @t{:wild} element of a
  1649. @i{list}-valued directory component, or an @i{implementation-defined} portion
  1650. of a component, such as the @t{"*"} in the complex wildcard string
  1651. @t{"foo*bar"} that some implementations support. An implementation that
  1652. adds other wildcard features, such as regular expressions, must define
  1653. how @b{translate-pathname} extends to those features.
  1654. A ``missing field'' is a @i{pathname} component with a value of @b{nil}.
  1655. The portion of @i{source}
  1656. that is copied into the resulting @i{pathname} is
  1657. @i{implementation-defined}. Typically
  1658. it is determined by the user interface conventions
  1659. of the file systems involved. Usually it is the portion of @i{source}
  1660. that matches a wildcard field of
  1661. @i{from-wildcard} that is in the same
  1662. position as the wildcard or missing field of
  1663. @i{to-wildcard}. If there
  1664. is no wildcard field in
  1665. @i{from-wildcard} at that position, then usually
  1666. it is the entire corresponding
  1667. @i{pathname} component of @i{source}, or in
  1668. the case of a
  1669. @i{list}-valued directory component, the entire corresponding
  1670. @i{list} element.
  1671. During the copying of a portion of @i{source} into
  1672. the resulting @i{pathname}, additional
  1673. @i{implementation-defined} translations of @i{case} or file naming
  1674. conventions might occur, especially when
  1675. @i{from-wildcard} and
  1676. @i{to-wildcard} are for different hosts.
  1677. It is valid for
  1678. @i{source} to be a wild
  1679. @i{pathname}; in general this will produce a wild
  1680. result. It
  1681. is valid for @i{from-wildcard} and/or @i{to-wildcard} to be
  1682. non-wild @i{pathnames}.
  1683. There are no specified keyword arguments for
  1684. @b{translate-pathname}, but
  1685. implementations are permitted to extend it by adding keyword arguments.
  1686. @b{translate-pathname} maps customary case in
  1687. @i{source} into customary case in the output @i{pathname}.
  1688. @subsubheading Examples::
  1689. @example
  1690. ;; The results of the following five forms are all implementation-dependent.
  1691. ;; The second item in particular is shown with multiple results just to
  1692. ;; emphasize one of many particular variations which commonly occurs.
  1693. (pathname-name (translate-pathname "foobar" "foo*" "*baz")) @result{} "barbaz"
  1694. (pathname-name (translate-pathname "foobar" "foo*" "*"))
  1695. @result{} "foobar"
  1696. @i{OR}@result{} "bar"
  1697. (pathname-name (translate-pathname "foobar" "*" "foo*")) @result{} "foofoobar"
  1698. (pathname-name (translate-pathname "bar" "*" "foo*")) @result{} "foobar"
  1699. (pathname-name (translate-pathname "foobar" "foo*" "baz*")) @result{} "bazbar"
  1700. (defun translate-logical-pathname-1 (pathname rules)
  1701. (let ((rule (assoc pathname rules :test #'pathname-match-p)))
  1702. (unless rule (error "No translation rule for ~A" pathname))
  1703. (translate-pathname pathname (first rule) (second rule))))
  1704. (translate-logical-pathname-1 "FOO:CODE;BASIC.LISP"
  1705. '(("FOO:DOCUMENTATION;" "MY-UNIX:/doc/foo/")
  1706. ("FOO:CODE;" "MY-UNIX:/lib/foo/")
  1707. ("FOO:PATCHES;*;" "MY-UNIX:/lib/foo/patch/*/")))
  1708. @result{} #P"MY-UNIX:/lib/foo/basic.l"
  1709. ;;;This example assumes one particular set of wildcard conventions
  1710. ;;;Not all file systems will run this example exactly as written
  1711. (defun rename-files (from to)
  1712. (dolist (file (directory from))
  1713. (rename-file file (translate-pathname file from to))))
  1714. (rename-files "/usr/me/*.lisp" "/dev/her/*.l")
  1715. ;Renames /usr/me/init.lisp to /dev/her/init.l
  1716. (rename-files "/usr/me/pcl*/*" "/sys/pcl/*/")
  1717. ;Renames /usr/me/pcl-5-may/low.lisp to /sys/pcl/pcl-5-may/low.lisp
  1718. ;In some file systems the result might be /sys/pcl/5-may/low.lisp
  1719. (rename-files "/usr/me/pcl*/*" "/sys/library/*/")
  1720. ;Renames /usr/me/pcl-5-may/low.lisp to /sys/library/pcl-5-may/low.lisp
  1721. ;In some file systems the result might be /sys/library/5-may/low.lisp
  1722. (rename-files "/usr/me/foo.bar" "/usr/me2/")
  1723. ;Renames /usr/me/foo.bar to /usr/me2/foo.bar
  1724. (rename-files "/usr/joe/*-recipes.text" "/usr/jim/cookbook/joe's-*-rec.text")
  1725. ;Renames /usr/joe/lamb-recipes.text to /usr/jim/cookbook/joe's-lamb-rec.text
  1726. ;Renames /usr/joe/pork-recipes.text to /usr/jim/cookbook/joe's-pork-rec.text
  1727. ;Renames /usr/joe/veg-recipes.text to /usr/jim/cookbook/joe's-veg-rec.text
  1728. @end example
  1729. @subsubheading Exceptional Situations::
  1730. If any of @i{source}, @i{from-wildcard}, or @i{to-wildcard}
  1731. is not a @i{pathname}, a @i{string}, or a @i{stream associated with a file}
  1732. an error of @i{type} @b{type-error} is signaled.
  1733. @t{(pathname-match-p @i{source from-wildcard})} must
  1734. be true or an error of @i{type} @b{error} is signaled.
  1735. @subsubheading See Also::
  1736. @ref{namestring; file-namestring; directory-namestring; host-namestring; enough-namestring}
  1737. ,
  1738. @ref{pathname-host; pathname-device; pathname-directory; pathname-name; pathname-type; pathname-version}
  1739. ,
  1740. @b{pathname},
  1741. @b{logical-pathname},
  1742. @ref{File System Concepts},
  1743. @ref{Pathnames as Filenames}
  1744. @subsubheading Notes::
  1745. The exact behavior of @b{translate-pathname} cannot be dictated
  1746. by the @r{Common Lisp} language and must be allowed to vary, depending on the
  1747. user interface conventions of the file systems involved.
  1748. The following is an implementation guideline.
  1749. One file system performs this operation by
  1750. examining each piece of the three
  1751. @i{pathnames} in turn, where a piece is a
  1752. @i{pathname} component or a
  1753. @i{list} element of a structured component such as
  1754. a hierarchical directory. Hierarchical directory elements in
  1755. @i{from-wildcard} and
  1756. @i{to-wildcard} are matched by whether they are
  1757. wildcards, not by depth in the directory hierarchy. If the piece in
  1758. @i{to-wildcard} is present and not wild, it is copied into the result.
  1759. If the piece in @i{to-wildcard} is
  1760. @t{:wild} or @b{nil}, the piece in @i{source} is
  1761. copied into the result. Otherwise, the piece in
  1762. @i{to-wildcard} might be
  1763. a complex wildcard such as @t{"foo*bar"} and the piece in
  1764. @i{from-wildcard}
  1765. should be wild; the portion of the piece in
  1766. @i{source} that matches the
  1767. wildcard portion of the piece in
  1768. @i{from-wildcard} replaces the wildcard
  1769. portion of the piece in
  1770. @i{to-wildcard} and the value produced is used in
  1771. the result.
  1772. @node merge-pathnames, , translate-pathname, Filenames Dictionary
  1773. @subsection merge-pathnames [Function]
  1774. @code{merge-pathnames} @i{pathname {&optional} default-pathname default-version}@*
  1775. @result{} @i{merged-pathname}
  1776. @subsubheading Arguments and Values::
  1777. @i{pathname}---a @i{pathname designator}.
  1778. @i{default-pathname}---a @i{pathname designator}.
  1779. The default is the @i{value} of @b{*default-pathname-defaults*}.
  1780. @i{default-version}---a @i{valid pathname version}.
  1781. The default is @t{:newest}.
  1782. @i{merged-pathname}---a @i{pathname}.
  1783. @subsubheading Description::
  1784. Constructs a @i{pathname} from @i{pathname}
  1785. by filling in any unsupplied components with the corresponding values
  1786. from @i{default-pathname} and @i{default-version}.
  1787. Defaulting of pathname components
  1788. is done by filling in components taken from another @i{pathname}.
  1789. This is especially useful for cases such as
  1790. a program that has an input file and an output file.
  1791. Unspecified components of the output pathname will come from the input pathname,
  1792. except that the type should not default
  1793. to the type of the input pathname
  1794. but rather to the appropriate default type for output from the program;
  1795. for example, see the @i{function} @b{compile-file-pathname}.
  1796. If no version is supplied, @i{default-version} is used.
  1797. If @i{default-version} is @b{nil}, the version component will remain unchanged.
  1798. If @i{pathname} explicitly specifies a host and not a device, and
  1799. if the host component of @i{default-pathname} matches the host component
  1800. of @i{pathname}, then the device is taken from the @i{default-pathname};
  1801. otherwise the device will be the default file device for that host. If
  1802. @i{pathname} does not specify a host, device, directory, name,
  1803. or type, each such component is copied from @i{default-pathname}.
  1804. If @i{pathname} does not specify a name, then the version, if not provided, will
  1805. come from @i{default-pathname}, just like the other components. If
  1806. @i{pathname} does specify a name, then the version is not affected
  1807. by @i{default-pathname}. If this process leaves the
  1808. version missing, the @i{default-version} is used.
  1809. If the host's file name syntax provides a way
  1810. to input a version without a name or type, the user can let the name
  1811. and type default but supply a version different from the one in @i{default-pathname}.
  1812. If @i{pathname} is a @i{stream}, @i{pathname} effectively
  1813. becomes @t{(pathname @i{pathname})}. @b{merge-pathnames}
  1814. can be used on either an open or a closed @i{stream}.
  1815. If @i{pathname} is a @i{pathname}
  1816. it represents the name used to open the file. This may be, but is
  1817. not required to be, the actual name of the file.
  1818. @b{merge-pathnames} recognizes a @i{logical pathname} @i{namestring}
  1819. when @i{default-pathname} is a @i{logical pathname},
  1820. or when the @i{namestring} begins with
  1821. the name of a defined @i{logical host} followed by a @i{colon}.
  1822. In the first of these two cases,
  1823. the host portion of the @i{logical pathname} @i{namestring}
  1824. and its following @i{colon} are optional.
  1825. @b{merge-pathnames} returns a
  1826. @i{logical pathname} if and only if
  1827. its first argument is a @i{logical pathname},
  1828. or its first argument is a @i{logical pathname} @i{namestring} with an explicit host,
  1829. or its first argument does not specify a host
  1830. and the @i{default-pathname} is a @i{logical pathname}.
  1831. @i{Pathname} merging treats a relative directory specially.
  1832. If @t{(pathname-directory @i{pathname})} is a @i{list} whose
  1833. @i{car} is @t{:relative}, and
  1834. @t{(pathname-directory @i{default-pathname})} is a @i{list}, then
  1835. the merged directory is the value of
  1836. @example
  1837. (append (pathname-directory @i{default-pathname})
  1838. (cdr ;remove :relative from the front
  1839. (pathname-directory @i{pathname})))
  1840. @end example
  1841. except that if the resulting @i{list} contains a @i{string} or @t{:wild}
  1842. immediately followed by @t{:back}, both of them are removed. This removal of
  1843. redundant @t{:back} @i{keywords} is repeated as many times as possible.
  1844. If @t{(pathname-directory @i{default-pathname})} is not a @i{list} or
  1845. @t{(pathname-directory @i{pathname})} is not a @i{list}
  1846. whose @i{car} is @t{:relative}, the merged directory is
  1847. @t{(or (pathname-directory @i{pathname}) (pathname-directory @i{default-pathname}))}
  1848. @b{merge-pathnames} maps customary case in @i{pathname}
  1849. into customary case in the output @i{pathname}.
  1850. @subsubheading Examples::
  1851. @example
  1852. (merge-pathnames "CMUC::FORMAT"
  1853. "CMUC::PS:<LISPIO>.FASL")
  1854. @result{} #P"CMUC::PS:<LISPIO>FORMAT.FASL.0"
  1855. @end example
  1856. @subsubheading See Also::
  1857. @b{*default-pathname-defaults*},
  1858. @b{pathname},
  1859. @b{logical-pathname},
  1860. @ref{File System Concepts},
  1861. @ref{Pathnames as Filenames}
  1862. @subsubheading Notes::
  1863. The net effect
  1864. is that if just a name is supplied,
  1865. the host, device, directory, and type will come from @i{default-pathname},
  1866. but the version will come from @i{default-version}.
  1867. If nothing or just a directory is supplied,
  1868. the name, type, and version will come from @i{default-pathname} together.
  1869. @c end of including dict-pathnames
  1870. @c %**end of chapter