166 lines
9.8 KiB
HTML
166 lines
9.8 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
||
|
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
||
|
<HEAD>
|
||
|
<TITLE>23.1.2. Case Conventions</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" Case Conventions">
|
||
|
<meta name="keywords" value="clm">
|
||
|
<meta name="resource-type" value="document">
|
||
|
<meta name="distribution" value="global">
|
||
|
<P>
|
||
|
<b>Common Lisp the Language, 2nd Edition</b>
|
||
|
<BR> <HR><A NAME=tex2html4119 HREF="node206.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html4117 HREF="node203.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html4111 HREF="node204.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html4121 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html4122 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html4120 HREF="node206.html"> Structured Directories</A>
|
||
|
<B>Up:</B> <A NAME=tex2html4118 HREF="node203.html"> File Names</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html4112 HREF="node204.html"> Pathnames</A>
|
||
|
<HR> <P>
|
||
|
<H2><A NAME=SECTION002712000000000000000>23.1.2. Case Conventions</A></H2>
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
<A NAME=PATHNAMECOMPONENTCASESECTION>Issues</A>
|
||
|
of alphabetic case in pathnames are a major source of problems.
|
||
|
In some file systems, the customary case is lowercase, in some uppercase,
|
||
|
in some mixed. Some file systems are case-sensitive (that is, they treat
|
||
|
<tt>FOO</tt> and <tt>foo</tt> as different file names) and others are not.
|
||
|
<P>
|
||
|
There are two kinds of pathname case portability problems: moving
|
||
|
programs from one Common Lisp to another, and moving pathname component
|
||
|
values from one file system to another. The solution to the first problem
|
||
|
is the requirement that all
|
||
|
Common Lisp implementations that support a particular file system must
|
||
|
use compatible representations for pathname component values. The solution to
|
||
|
the second problem is the use of a common representation for the
|
||
|
least-common-denominator pathname component values that exist on all
|
||
|
interesting file systems.
|
||
|
<P>
|
||
|
Requiring a common representation directly conflicts with the
|
||
|
desire among programmers that use only one file system to work with the
|
||
|
local conventions and to ignore issues of porting to other file
|
||
|
systems. The common representation cannot be the same as local (varying)
|
||
|
conventions.
|
||
|
<P>
|
||
|
X3J13 voted in June 1989 (PATHNAME-COMPONENT-CASE) <A NAME=26133> </A> to
|
||
|
add a keyword argument <tt>:case</tt> to each of the functions
|
||
|
<tt>make-pathname</tt>, <tt>pathname-host</tt>,
|
||
|
<tt>pathname-device</tt>, <tt>pathname-directory</tt>, <tt>pathname-name</tt>,
|
||
|
and <tt>pathname-type</tt>.
|
||
|
The possible values for the argument are <tt>:common</tt> and <tt>:local</tt>.
|
||
|
The default is <tt>:local</tt>.
|
||
|
<P>
|
||
|
The value <tt>:local</tt> means that strings given to <tt>make-pathname</tt>
|
||
|
or returned by any of the pathname component accessors
|
||
|
follow the local file system's conventions for alphabetic case.
|
||
|
Strings given to <tt>make-pathname</tt> will be used exactly as written if
|
||
|
the file system supports both cases. If the file system
|
||
|
supports only one case, the strings will be translated to that case.
|
||
|
<P>
|
||
|
The value <tt>:common</tt> means that strings given to <tt>make-pathname</tt>
|
||
|
or returned by any of the pathname component accessors
|
||
|
follow this common convention:
|
||
|
<UL><LI> All uppercase means that a file system's customary case will be used.
|
||
|
<LI> All lowercase means that the opposite of the customary case will be used.
|
||
|
<LI> Mixed case represents itself.
|
||
|
</UL>
|
||
|
Uppercase is used as the common case for no better reason than
|
||
|
consistency with Lisp symbols.
|
||
|
The second and third points allow translation from local representation to
|
||
|
common and back to be information-preserving. (Note that translation
|
||
|
from common to local representation and back may or may not be information-preserving,
|
||
|
depending on the nature of the local representation.)
|
||
|
<P>
|
||
|
Namestrings always use <tt>:local</tt> file system case conventions.
|
||
|
<P>
|
||
|
Finally, <tt>merge-pathnames</tt> and <tt>translate-pathname</tt> map customary case in the
|
||
|
input pathnames into customary case in the output pathname.
|
||
|
<P>
|
||
|
Examples of possible use of this convention:
|
||
|
<UL> <LI> TOPS-20 is case-sensitive and prefers uppercase,
|
||
|
translating lowercase to uppercase unless escaped with <tt>^V</tt>;
|
||
|
for a TOPS-20-based
|
||
|
file system, a Common Lisp implementation
|
||
|
should use identical
|
||
|
representations for common and local.
|
||
|
<P>
|
||
|
<LI> UNIX is case-sensitive and prefers lowercase; for a UNIX-based file system,
|
||
|
a Common Lisp implementation should translate between
|
||
|
common and local representations by inverting the case of non-mixed-case strings.
|
||
|
<P>
|
||
|
<LI> VAX/VMS is uppercase-only (that is, the file system translates all file
|
||
|
name arguments to uppercase); for a VAX/VMS-based file system,
|
||
|
a Common Lisp implementation should
|
||
|
translate common representation to local by
|
||
|
converting to uppercase and should translate local representation
|
||
|
to common with no change.
|
||
|
<P>
|
||
|
<LI> The Macintosh operating system is case-insensitive and prefers lowercase,
|
||
|
but remembers the cases of letters actually used to name a file;
|
||
|
for a Macintosh-based file system, a Common Lisp implementation should translate
|
||
|
between common and local representations by inverting the case of non-mixed-case strings
|
||
|
and should ignore case when determining whether two pathnames are <tt>equal</tt>.
|
||
|
</UL>
|
||
|
<P>
|
||
|
Here are some examples of this behavior. Assume that the host <tt>T</tt> runs
|
||
|
TOPS-20, <tt>U</tt> runs UNIX, <tt>V</tt> runs VAX/VMS, and <tt>M</tt> runs the Macintosh
|
||
|
operating system.
|
||
|
<P><pre>
|
||
|
;;; Returns two values: the PATHNAME-NAME from a namestring
|
||
|
;;; in :COMMON and :LOCAL representations (in that order).
|
||
|
(defun pathname-example (name)
|
||
|
(let ((path (parse-namestring name))))
|
||
|
(values (pathname-name path :case :common)
|
||
|
(pathname-name path :case :local))))
|
||
|
|
||
|
=> "FOO" and ¯"FOO" ;Common Local
|
||
|
(pathname-example "T:<ME>FOO.LISP") => "FOO" and "FOO"
|
||
|
(pathname-example "T:<ME>foo.LISP") => "FOO" and "FOO"
|
||
|
(pathname-example "T:<ME>^Vf^Vo^Vo.LISP") => "foo" and "foo"
|
||
|
(pathname-example "T:<ME>TeX.LISP") => "TEX" and "TEX"
|
||
|
(pathname-example "T:<ME>T^VeX.LISP") => "TeX" and "TeX"
|
||
|
(pathname-example "U:/me/FOO.lisp") => "foo" and "FOO"
|
||
|
(pathname-example "U:/me/foo.lisp") => "FOO" and "foo"
|
||
|
(pathname-example "U:/me/TeX.lisp") => "TeX" and "TeX"
|
||
|
(pathname-example "V:[me]FOO.LISP") => "FOO" and "FOO"
|
||
|
(pathname-example "V:[me]foo.LISP") => "FOO" and "FOO"
|
||
|
(pathname-example "V:[me]TeX.LISP") => "TEX" and "TEX"
|
||
|
(pathname-example "M:FOO.LISP") => "foo" and "FOO"
|
||
|
(pathname-example "M:foo.LISP") => "FOO" and "foo"
|
||
|
(pathname-example "M:TeX.LISP") => "TeX" and "TeX"
|
||
|
</pre><P>
|
||
|
The following example illustrates the creation of new pathnames.
|
||
|
The name is converted from common representation to local because
|
||
|
namestrings always use local conventions.
|
||
|
<P><pre>
|
||
|
(defun make-pathname-example (h n)
|
||
|
(namestring (make-pathname :host h :name n :case :common))
|
||
|
|
||
|
(make-pathname-example "T" "FOO") => "T:FOO"
|
||
|
(make-pathname-example "T" "foo") => "T:^Vf^Vo^Vo"
|
||
|
(make-pathname-example "T" "TeX") => "T:T^VeX"
|
||
|
(make-pathname-example "U" "FOO") => "U:foo"
|
||
|
(make-pathname-example "U" "foo") => "U:FOO"
|
||
|
(make-pathname-example "U" "TeX") => "U:TeX"
|
||
|
(make-pathname-example "V" "FOO") => "V:FOO"
|
||
|
(make-pathname-example "V" "foo") => "V:FOO"
|
||
|
(make-pathname-example "V" "TeX") => "V:TeX"
|
||
|
(make-pathname-example "M" "FOO") => "M:foo"
|
||
|
(make-pathname-example "M" "foo") => "M:FOO"
|
||
|
(make-pathname-example "M" "TeX") => "M:TeX"
|
||
|
</pre><P>
|
||
|
A big advantage of this set of conventions is that one can, for example,
|
||
|
call <tt>make-pathname</tt> with <tt>:type "LISP"</tt> and <tt>:case :common</tt>,
|
||
|
and the result will appear in a namestring as <tt>.LISP</tt> or <tt>.lisp</tt>,
|
||
|
whichever is appropriate.
|
||
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<P>
|
||
|
<BR> <HR><A NAME=tex2html4119 HREF="node206.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html4117 HREF="node203.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html4111 HREF="node204.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html4121 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html4122 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html4120 HREF="node206.html"> Structured Directories</A>
|
||
|
<B>Up:</B> <A NAME=tex2html4118 HREF="node203.html"> File Names</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html4112 HREF="node204.html"> Pathnames</A>
|
||
|
<HR> <P>
|
||
|
<HR>
|
||
|
<P><ADDRESS>
|
||
|
AI.Repository@cs.cmu.edu
|
||
|
</ADDRESS>
|
||
|
</BODY>
|