1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/f_pars_1.htm
2024-04-01 10:24:07 +02:00

95 lines
13 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Function PARSE-NAMESTRING</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="f_namest.htm">
<LINK REL=UP HREF="c_filena.htm">
<LINK REL=NEXT HREF="f_wild_p.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="f_namest.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_filena.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_wild_p.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="parse-namestring"><I>Function</I> <B>PARSE-NAMESTRING</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>parse-namestring</B> <I>thing <TT>&amp;optional</TT> host default-pathname <TT>&amp;key</TT> start end junk-allowed</I><P> =&gt; <I>pathname, position</I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>thing</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A>, a <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A>, or a <A REL=DEFINITION HREF="26_glo_s.htm#stream_associated_with_a_file"><I>stream associated with a file</I></A>. <P>
<I>host</I>---a <A REL=DEFINITION HREF="26_glo_v.htm#valid_pathname_host"><I>valid pathname host</I></A>, a <A REL=DEFINITION HREF="26_glo_l.htm#logical_host"><I>logical host</I></A>, or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
<I>default-pathname</I>---a <A REL=DEFINITION HREF="26_glo_p.htm#pathname_designator"><I>pathname designator</I></A>. The default is the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of <A REL=DEFINITION HREF="v_defaul.htm#STdefault-pathname-defaultsST"><B>*default-pathname-defaults*</B></A>. <P>
<I>start</I>, <I>end</I>---<A REL=DEFINITION HREF="26_glo_b.htm#bounding_index_designator"><I>bounding index designators</I></A> of <I>thing</I>. The defaults for <I>start</I> and <I>end</I> are <TT>0</TT> and <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>, respectively. <P>
<I>junk-allowed</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. The default is <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A>. <P>
<I>pathname</I>---a <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A>, or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
<I>position</I>---a <A REL=DEFINITION HREF="26_glo_b.htm#bounding_index_designator"><I>bounding index designator</I></A> for <I>thing</I>. <P>
<P><B>Description:</B><P>
<P>
Converts <I>thing</I> into a <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A>. <P>
The <I>host</I> supplies a host name with respect to which the parsing occurs. <P>
If <I>thing</I> is a <A REL=DEFINITION HREF="26_glo_s.htm#stream_associated_with_a_file"><I>stream associated with a file</I></A>, processing proceeds as if the <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A> used to open that <A REL=DEFINITION HREF="26_glo_f.htm#file"><I>file</I></A> had been supplied instead. <P>
If <I>thing</I> is a <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A>, the <I>host</I> and the host component of <I>thing</I> are compared. If they match, two values are immediately returned: <I>thing</I> and <I>start</I>; otherwise (if they do not match), an error is signaled. <P>
<P>
Otherwise (if <I>thing</I> is a <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A>), <A REL=DEFINITION HREF="#parse-namestring"><B>parse-namestring</B></A> parses the name of a <A REL=DEFINITION HREF="26_glo_f.htm#file"><I>file</I></A> within the substring of <I>thing</I> bounded by <I>start</I> and <I>end</I>. <P>
If <I>thing</I> is a <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A> then the substring of <I>thing</I> <A REL=DEFINITION HREF="26_glo_b.htm#bounded"><I>bounded</I></A> by <I>start</I> and <I>end</I> is parsed into a <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A> as follows: <P>
<P><DL><P>
<DT>* If <I>host</I> is a <A REL=DEFINITION HREF="26_glo_l.htm#logical_host"><I>logical host</I></A> then <I>thing</I> is parsed as a <A REL=DEFINITION HREF="26_glo_l.htm#logical_pathname"><I>logical pathname</I></A> <A REL=DEFINITION HREF="26_glo_n.htm#namestring"><I>namestring</I></A> on the <I>host</I>. <P><DD>
<DT>* If <I>host</I> is <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A> and <I>thing</I> is a syntactically valid <A REL=DEFINITION HREF="26_glo_l.htm#logical_pathname"><I>logical pathname</I></A> <A REL=DEFINITION HREF="26_glo_n.htm#namestring"><I>namestring</I></A> containing an explicit host, then it is parsed as a <A REL=DEFINITION HREF="26_glo_l.htm#logical_pathname"><I>logical pathname</I></A> <A REL=DEFINITION HREF="26_glo_n.htm#namestring"><I>namestring</I></A>. <P><DD>
<DT>* If <I>host</I> is <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>, <I>default-pathname</I> is a <A REL=DEFINITION HREF="26_glo_l.htm#logical_pathname"><I>logical pathname</I></A>, and <I>thing</I> is a syntactically valid <A REL=DEFINITION HREF="26_glo_l.htm#logical_pathname"><I>logical pathname</I></A> <A REL=DEFINITION HREF="26_glo_n.htm#namestring"><I>namestring</I></A> without an explicit host, then it is parsed as a <A REL=DEFINITION HREF="26_glo_l.htm#logical_pathname"><I>logical pathname</I></A> <A REL=DEFINITION HREF="26_glo_n.htm#namestring"><I>namestring</I></A> on the host that is the host component of <I>default-pathname</I>. <P><DD>
<DT>* Otherwise, the parsing of <I>thing</I> is <A REL=DEFINITION HREF="26_glo_i.htm#implementation-defined"><I>implementation-defined</I></A>. <P><DD>
<P></DL><P>
In the first of these cases, the host portion of the <A REL=DEFINITION HREF="26_glo_l.htm#logical_pathname"><I>logical pathname</I></A> namestring and its following <A REL=DEFINITION HREF="26_glo_c.htm#colon"><I>colon</I></A> are optional. <P>
If the host portion of the namestring and <I>host</I> are both present and do not match, an error is signaled. <P>
If <I>junk-allowed</I> is <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A>, then the <A REL=DEFINITION HREF="26_glo_p.htm#primary_value"><I>primary value</I></A> is the <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A> parsed or, if no syntactically correct <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A> was seen, <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. If <I>junk-allowed</I> is <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A>, then the entire substring is scanned, and the <A REL=DEFINITION HREF="26_glo_p.htm#primary_value"><I>primary value</I></A> is the <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A> parsed. <P>
In either case, the <A REL=DEFINITION HREF="26_glo_s.htm#secondary_value"><I>secondary value</I></A> is the index into <I>thing</I> of the delimiter that terminated the parse, or the index beyond the substring if the parse terminated at the end of the substring (as will always be the case if <I>junk-allowed</I> is <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A>). <P>
Parsing a <A REL=DEFINITION HREF="26_glo_n.htm#null"><I>null</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A> always succeeds, producing a <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A> with all components (except the host) equal to <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
If <I>thing</I> contains an explicit host name and no explicit device name, then it is <A REL=DEFINITION HREF="26_glo_i.htm#implementation-defined"><I>implementation-defined</I></A> whether <A REL=DEFINITION HREF="#parse-namestring"><B>parse-namestring</B></A> will supply the standard default device for that host as the device component of the resulting <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A>. <P>
<P><B>Examples:</B><P>
<P>
<PRE>
(setq q (parse-namestring &quot;test&quot;))
=&gt; #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME &quot;test&quot;
:TYPE NIL :VERSION NIL)
(pathnamep q) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(parse-namestring &quot;test&quot;)
=&gt; #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME &quot;test&quot;
:TYPE NIL :VERSION NIL), 4
(setq s (open xxx)) =&gt; #&lt;Input File Stream...&gt;
(parse-namestring s)
=&gt; #S(PATHNAME :HOST NIL :DEVICE NIL :DIRECTORY NIL :NAME xxx
:TYPE NIL :VERSION NIL), 0
(parse-namestring &quot;test&quot; nil nil :start 2 :end 4 )
=&gt; #S(PATHNAME ...), 15
(parse-namestring &quot;foo.lisp&quot;)
=&gt; #P&quot;foo.lisp&quot;
</PRE>
</TT> <P>
<P><B>Affected By:</B> None.
<P>
<P><B>Exceptional Situations:</B><P>
<P>
If <I>junk-allowed</I> is <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A>, an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_parse_.htm#parse-error"><B>parse-error</B></A> is signaled if <I>thing</I> does not consist entirely of the representation of a <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A>, possibly surrounded on either side by <A REL=DEFINITION HREF="26_glo_w.htm#whitespace"><I>whitespace</I></A>[1] characters if that is appropriate to the cultural conventions of the implementation. <P>
If <I>host</I> is supplied and not <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>, and <I>thing</I> contains a manifest host name, an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_error.htm#error"><B>error</B></A> is signaled if the hosts do not match. <P>
If <I>thing</I> is a <A REL=DEFINITION HREF="26_glo_l.htm#logical_pathname"><I>logical pathname</I></A> namestring and if the host portion of the namestring and <I>host</I> are both present and do not match, an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_error.htm#error"><B>error</B></A> is signaled. <P>
<P><B>See Also:</B><P>
<P>
<A REL=DEFINITION HREF="t_pn.htm#pathname"><B>pathname</B></A>, <A REL=DEFINITION HREF="t_logica.htm#logical-pathname"><B>logical-pathname</B></A>, <A REL=CHILD HREF="20_a.htm">Section 20.1 (File System Concepts)</A>, <A REL=CHILD HREF="19_bbbc.htm">Section 19.2.2.2.3 (:UNSPECIFIC as a Component Value)</A>, <A REL=CHILD HREF="19_ab.htm">Section 19.1.2 (Pathnames as Filenames)</A> <P>
<P><B>Notes:</B> None.
<P>
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss157.htm">FILE-OPEN-ERROR:SIGNAL-FILE-ERROR</A><LI> <A REL=CHILD HREF="../Issues/iss260.htm">PATHNAME-PRINT-READ:SHARPSIGN-P</A><LI> <A REL=CHILD HREF="../Issues/iss258.htm">PATHNAME-HOST-PARSING:RECOGNIZE-LOGICAL-HOST-NAMES</A><LI> <A REL=CHILD HREF="../Issues/iss261.htm">PATHNAME-STREAM</A><LI> <A REL=CHILD HREF="../Issues/iss284.htm">RANGE-OF-START-AND-END-PARAMETERS:INTEGER-AND-INTEGER-NIL</A><LI> <A REL=CHILD HREF="../Issues/iss332.htm">SUBSEQ-OUT-OF-BOUNDS</A><LI> <A REL=CHILD HREF="../Issues/iss266.htm">PATHNAME-UNSPECIFIC-COMPONENT:NEW-TOKEN</A><LI> <A REL=CHILD HREF="../Issues/iss259.htm">PATHNAME-LOGICAL:ADD</A><LI> <A REL=CHILD HREF="../Issues/iss264.htm">PATHNAME-SYMBOL</A><P></UL><HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>