1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="gprolog.css">
<TITLE>
File name processing
</TITLE>
</HEAD>
<BODY TEXT=black BGCOLOR=white>
<A HREF="gprolog048.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="gprolog023.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="gprolog050.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>
<H3 CLASS="subsection"><A NAME="htoc239">7.26</A> File name processing</H3><UL>
<LI><A HREF="gprolog049.html#toc192"><TT>absolute_file_name/2</TT></A>
<LI><A HREF="gprolog049.html#toc193"><TT>decompose_file_name/4</TT></A>
<LI><A HREF="gprolog049.html#toc194"><TT>prolog_file_name/2</TT></A>
</UL>
<A NAME="toc192"></A>
<H4 CLASS="subsubsection"><A NAME="htoc240">7.26.1</A> <TT>absolute_file_name/2</TT></H4>
<A NAME="absolute-file-name/2"></A>
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
absolute_file_name(+atom, atom)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>absolute_file_name(File1, File2)</TT> succeeds if <TT>File2</TT> is
the absolute pathname associated with the relative file name <TT>File1</TT>.
<TT>File1</TT> can contain <TT>$<I>VAR_NAME</I></TT> sub-strings. When
such a sub-string is encountered, it is expanded with the value of the
environment variable whose name is <I><TT>VAR_NAME</TT></I> if exists
(otherwise no expansion is done). <TT>File1</TT> can also begin with a
sub-string <TT>~<I>USER_NAME</I>/</TT>, this is expanded as the home
directory of the user <I><TT>USER_NAME</TT></I>. If
<I><TT>USER_NAME</TT></I> does not exist <TT>File1</TT> is an invalid
pathname. If no <I><TT>USER_NAME</TT></I> is given (i.e. <TT>File1</TT>
begins with <TT>~/</TT>) the <TT>~</TT> character is expanded as the
value of the environment variable <TT>HOME</TT>. If the <TT>HOME</TT>
variable is not defined <TT>File1</TT> is an invalid pathname. Relative
references to the current directory (<TT>/./</TT> sub-string) and to the
parent directory (<TT>/../</TT> sub-strings) are removed and no longer
appear in <TT>File2</TT>. <TT>File1</TT> is also invalid if it contains too
many <TT>/../</TT> consecutive sub-strings (i.e. parent directory relative
references). Finally if <TT>File1</TT> is <TT>user</TT> then <TT>File2</TT>
is also unified with <TT>user</TT> to allow this predicate to be called on
Prolog file names (since <TT>user</TT> in DEC-10 input/output predicates
denotes the current input/output stream). <BR>
<BR>
Most predicates using a file name implicitly call this predicate to obtain
the desired file, e.g. <TT>open/4</TT>. <BR>
<BR>
<B>Errors</B><BR>
<TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>File1</TT> is a variable</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>File1</TT> is neither a variable nor an atom</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(atom, File1)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>File2</TT> is neither a variable nor an atom</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(atom, File2)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>File1</TT> is an atom but not a valid pathname</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>domain_error(os_path, File1)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR></TABLE><BR>
<B>Portability</B><BR>
<BR>
GNU Prolog predicate.<BR>
<BR>
<A NAME="toc193"></A>
<H4 CLASS="subsubsection"><A NAME="htoc241">7.26.2</A> <TT>decompose_file_name/4</TT></H4>
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
decompose_file_name(+atom, ?atom, ?atom, ?atom)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>decompose_file_name(File, Directory, Prefix, Suffix)</TT> decomposes
the pathname <TT>File</TT> and extracts the <TT>Directory</TT> part
(characters before the last <TT>/</TT>), the <TT>Prefix</TT> part
(characters after the last <TT>/</TT> and before the last <TT>.</TT> or
until the end if there is no suffix) and the <TT>Suffix</TT> part
(characters from the last <TT>.</TT> to the end of the string). <BR>
<BR>
<B>Errors</B><BR>
<TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>File</TT> is a variable</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>File</TT> is neither a variable nor an atom</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(atom, File)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>Directory</TT> is neither a variable nor an atom</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(atom, Directory)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>Prefix</TT> is neither a variable nor an atom</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(atom, Prefix)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>Suffix</TT> is neither a variable nor an atom</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(atom, Suffix)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR></TABLE><BR>
<B>Portability</B><BR>
<BR>
GNU Prolog predicate.<BR>
<BR>
<A NAME="toc194"></A>
<H4 CLASS="subsubsection"><A NAME="htoc242">7.26.3</A> <TT>prolog_file_name/2</TT></H4>
<A NAME="prolog-file-name/2"></A>
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
prolog_file_name(+atom, ?atom)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>prolog_file_name(File1, File2)</TT> unifies <TT>File2</TT> with the
Prolog file name associated with <TT>File1</TT>. More precisely <TT>File2</TT>
is computed as follows:
<UL CLASS="itemize"><LI CLASS="li-itemize">if <TT>File1</TT> has a suffix or if it is <TT>user</TT> then
<TT>File2</TT> is unified with <TT>File1</TT>.<BR>
<BR>
<LI CLASS="li-itemize">else if the file whose name is <TT>File1</TT> + <TT>'.pl'</TT> exists
then <TT>File2</TT> is unified with this name.<BR>
<BR>
<LI CLASS="li-itemize">else if the file whose name is <TT>File1</TT> + <TT>'.pro'</TT> exists
then <TT>File2</TT> is unified with this name.<BR>
<BR>
<LI CLASS="li-itemize">else <TT>File2</TT> is unified with the name <TT>File1</TT> +
<TT>'.pl'</TT>.</UL>
This predicate uses <TT>absolute_file_name/2</TT> to check the existence
of a file (section <A HREF="#absolute-file-name/2">7.26.1</A>).<BR>
<BR>
<B>Errors</B><BR>
<TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>File1</TT> is a variable</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>File1</TT> is neither a variable nor an atom</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(atom, File1)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>File2</TT> is neither a variable nor an atom</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(atom, File2)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>File1</TT> is an atom but not a valid pathname</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>domain_error(os_path, File1)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR></TABLE><BR>
<B>Portability</B><BR>
<BR>
GNU Prolog predicate.<BR>
<BR>
<HR SIZE=2>
Copyright (C) 1999-2007 Daniel Diaz
<BR>
<BR>
Verbatim copying and distribution of this entire article is permitted in any
medium, provided this notice is preserved. <BR>
<BR>
<A HREF="index.html#copyright">More about the copyright</A>
<HR>
<A HREF="gprolog048.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="gprolog023.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="gprolog050.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
|