annotate gcc/ada/libgnat/a-direct.ads @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- A D A . D I R E C T O R I E S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 2004-2017, Free Software Foundation, Inc. --
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- This specification is derived for use with GNAT from AI-00248, which is --
kono
parents:
diff changeset
12 -- expected to be a part of a future expected revised Ada Reference Manual. --
kono
parents:
diff changeset
13 -- The copyright notice above, and the license provisions that follow apply --
kono
parents:
diff changeset
14 -- solely to the contents of the part following the private keyword. --
kono
parents:
diff changeset
15 -- --
kono
parents:
diff changeset
16 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
17 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
18 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
19 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
20 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
21 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
22 -- --
kono
parents:
diff changeset
23 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
24 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
25 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
28 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
29 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
30 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
31 -- --
kono
parents:
diff changeset
32 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
33 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
34 -- --
kono
parents:
diff changeset
35 ------------------------------------------------------------------------------
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 -- Ada 2005: Implementation of Ada.Directories (AI95-00248). Note that this
kono
parents:
diff changeset
38 -- unit is available without -gnat05. That seems reasonable, since you only
kono
parents:
diff changeset
39 -- get it if you explicitly ask for it.
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 -- External files may be classified as directories, special files, or ordinary
kono
parents:
diff changeset
42 -- files. A directory is an external file that is a container for files on
kono
parents:
diff changeset
43 -- the target system. A special file is an external file that cannot be
kono
parents:
diff changeset
44 -- created or read by a predefined Ada Input-Output package. External files
kono
parents:
diff changeset
45 -- that are not special files or directories are called ordinary files.
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 -- A file name is a string identifying an external file. Similarly, a
kono
parents:
diff changeset
48 -- directory name is a string identifying a directory. The interpretation of
kono
parents:
diff changeset
49 -- file names and directory names is implementation-defined.
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 -- The full name of an external file is a full specification of the name of
kono
parents:
diff changeset
52 -- the file. If the external environment allows alternative specifications of
kono
parents:
diff changeset
53 -- the name (for example, abbreviations), the full name should not use such
kono
parents:
diff changeset
54 -- alternatives. A full name typically will include the names of all of
kono
parents:
diff changeset
55 -- directories that contain the item. The simple name of an external file is
kono
parents:
diff changeset
56 -- the name of the item, not including any containing directory names. Unless
kono
parents:
diff changeset
57 -- otherwise specified, a file name or directory name parameter to a
kono
parents:
diff changeset
58 -- predefined Ada input-output subprogram can be a full name, a simple name,
kono
parents:
diff changeset
59 -- or any other form of name supported by the implementation.
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -- The default directory is the directory that is used if a directory or
kono
parents:
diff changeset
62 -- file name is not a full name (that is, when the name does not fully
kono
parents:
diff changeset
63 -- identify all of the containing directories).
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 -- A directory entry is a single item in a directory, identifying a single
kono
parents:
diff changeset
66 -- external file (including directories and special files).
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 -- For each function that returns a string, the lower bound of the returned
kono
parents:
diff changeset
69 -- value is 1.
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 with Ada.Calendar;
kono
parents:
diff changeset
72 with Ada.Finalization;
kono
parents:
diff changeset
73 with Ada.IO_Exceptions;
kono
parents:
diff changeset
74 with Ada.Strings.Unbounded;
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 package Ada.Directories is
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 -----------------------------------
kono
parents:
diff changeset
79 -- Directory and File Operations --
kono
parents:
diff changeset
80 -----------------------------------
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 function Current_Directory return String;
kono
parents:
diff changeset
83 -- Returns the full directory name for the current default directory. The
kono
parents:
diff changeset
84 -- name returned must be suitable for a future call to Set_Directory.
kono
parents:
diff changeset
85 -- The exception Use_Error is propagated if a default directory is not
kono
parents:
diff changeset
86 -- supported by the external environment.
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 procedure Set_Directory (Directory : String);
kono
parents:
diff changeset
89 -- Sets the current default directory. The exception Name_Error is
kono
parents:
diff changeset
90 -- propagated if the string given as Directory does not identify an
kono
parents:
diff changeset
91 -- existing directory. The exception Use_Error is propagated if the
kono
parents:
diff changeset
92 -- external environment does not support making Directory (in the absence
kono
parents:
diff changeset
93 -- of Name_Error) a default directory.
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 procedure Create_Directory
kono
parents:
diff changeset
96 (New_Directory : String;
kono
parents:
diff changeset
97 Form : String := "");
kono
parents:
diff changeset
98 -- Creates a directory with name New_Directory. The Form parameter can be
kono
parents:
diff changeset
99 -- used to give system-dependent characteristics of the directory; the
kono
parents:
diff changeset
100 -- interpretation of the Form parameter is implementation-defined. A null
kono
parents:
diff changeset
101 -- string for Form specifies the use of the default options of the
kono
parents:
diff changeset
102 -- implementation of the new directory. The exception Name_Error is
kono
parents:
diff changeset
103 -- propagated if the string given as New_Directory does not allow the
kono
parents:
diff changeset
104 -- identification of a directory. The exception Use_Error is propagated if
kono
parents:
diff changeset
105 -- the external environment does not support the creation of a directory
kono
parents:
diff changeset
106 -- with the given name (in the absence of Name_Error) and form.
kono
parents:
diff changeset
107 --
kono
parents:
diff changeset
108 -- The Form parameter is ignored
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 procedure Delete_Directory (Directory : String);
kono
parents:
diff changeset
111 -- Deletes an existing empty directory with name Directory. The exception
kono
parents:
diff changeset
112 -- Name_Error is propagated if the string given as Directory does not
kono
parents:
diff changeset
113 -- identify an existing directory. The exception Use_Error is propagated
kono
parents:
diff changeset
114 -- if the external environment does not support the deletion of the
kono
parents:
diff changeset
115 -- directory (or some portion of its contents) with the given name (in the
kono
parents:
diff changeset
116 -- absence of Name_Error).
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 procedure Create_Path
kono
parents:
diff changeset
119 (New_Directory : String;
kono
parents:
diff changeset
120 Form : String := "");
kono
parents:
diff changeset
121 -- Creates zero or more directories with name New_Directory. Each
kono
parents:
diff changeset
122 -- non-existent directory named by New_Directory is created. For example,
kono
parents:
diff changeset
123 -- on a typical Unix system, Create_Path ("/usr/me/my"); would create
kono
parents:
diff changeset
124 -- directory "me" in directory "usr", then create directory "my"
kono
parents:
diff changeset
125 -- in directory "me". The Form can be used to give system-dependent
kono
parents:
diff changeset
126 -- characteristics of the directory; the interpretation of the Form
kono
parents:
diff changeset
127 -- parameter is implementation-defined. A null string for Form specifies
kono
parents:
diff changeset
128 -- the use of the default options of the implementation of the new
kono
parents:
diff changeset
129 -- directory. The exception Name_Error is propagated if the string given
kono
parents:
diff changeset
130 -- as New_Directory does not allow the identification of any directory. The
kono
parents:
diff changeset
131 -- exception Use_Error is propagated if the external environment does not
kono
parents:
diff changeset
132 -- support the creation of any directories with the given name (in the
kono
parents:
diff changeset
133 -- absence of Name_Error) and form.
kono
parents:
diff changeset
134 --
kono
parents:
diff changeset
135 -- The Form parameter is ignored
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 procedure Delete_Tree (Directory : String);
kono
parents:
diff changeset
138 -- Deletes an existing directory with name Directory. The directory and
kono
parents:
diff changeset
139 -- all of its contents (possibly including other directories) are deleted.
kono
parents:
diff changeset
140 -- The exception Name_Error is propagated if the string given as Directory
kono
parents:
diff changeset
141 -- does not identify an existing directory. The exception Use_Error is
kono
parents:
diff changeset
142 -- propagated if the external environment does not support the deletion
kono
parents:
diff changeset
143 -- of the directory or some portion of its contents with the given name
kono
parents:
diff changeset
144 -- (in the absence of Name_Error). If Use_Error is propagated, it is
kono
parents:
diff changeset
145 -- unspecified if a portion of the contents of the directory are deleted.
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 procedure Delete_File (Name : String);
kono
parents:
diff changeset
148 -- Deletes an existing ordinary or special file with Name. The exception
kono
parents:
diff changeset
149 -- Name_Error is propagated if the string given as Name does not identify
kono
parents:
diff changeset
150 -- an existing ordinary or special external file. The exception Use_Error
kono
parents:
diff changeset
151 -- is propagated if the external environment does not support the deletion
kono
parents:
diff changeset
152 -- of the file with the given name (in the absence of Name_Error).
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 procedure Rename (Old_Name, New_Name : String);
kono
parents:
diff changeset
155 -- Renames an existing external file (including directories) with Old_Name
kono
parents:
diff changeset
156 -- to New_Name. The exception Name_Error is propagated if the string given
kono
parents:
diff changeset
157 -- as Old_Name does not identify an existing external file. The exception
kono
parents:
diff changeset
158 -- Use_Error is propagated if the external environment does not support the
kono
parents:
diff changeset
159 -- renaming of the file with the given name (in the absence of Name_Error).
kono
parents:
diff changeset
160 -- In particular, Use_Error is propagated if a file or directory already
kono
parents:
diff changeset
161 -- exists with New_Name.
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 procedure Copy_File
kono
parents:
diff changeset
164 (Source_Name : String;
kono
parents:
diff changeset
165 Target_Name : String;
kono
parents:
diff changeset
166 Form : String := "");
kono
parents:
diff changeset
167 -- Copies the contents of the existing external file with Source_Name to
kono
parents:
diff changeset
168 -- Target_Name. The resulting external file is a duplicate of the source
kono
parents:
diff changeset
169 -- external file. The Form argument can be used to give system-dependent
kono
parents:
diff changeset
170 -- characteristics of the resulting external file; the interpretation of
kono
parents:
diff changeset
171 -- the Form parameter is implementation-defined. Exception Name_Error is
kono
parents:
diff changeset
172 -- propagated if the string given as Source_Name does not identify an
kono
parents:
diff changeset
173 -- existing external ordinary or special file or if the string given as
kono
parents:
diff changeset
174 -- Target_Name does not allow the identification of an external file. The
kono
parents:
diff changeset
175 -- exception Use_Error is propagated if the external environment does not
kono
parents:
diff changeset
176 -- support the creating of the file with the name given by Target_Name and
kono
parents:
diff changeset
177 -- form given by Form, or copying of the file with the name given by
kono
parents:
diff changeset
178 -- Source_Name (in the absence of Name_Error).
kono
parents:
diff changeset
179 --
kono
parents:
diff changeset
180 -- Interpretation of the Form parameter:
kono
parents:
diff changeset
181 --
kono
parents:
diff changeset
182 -- The Form parameter is case-insensitive
kono
parents:
diff changeset
183 --
kono
parents:
diff changeset
184 -- Two fields are recognized in the Form parameter:
kono
parents:
diff changeset
185 -- preserve=<value>
kono
parents:
diff changeset
186 -- mode=<value>
kono
parents:
diff changeset
187 --
kono
parents:
diff changeset
188 -- <value> starts immediately after the character '=' and ends with the
kono
parents:
diff changeset
189 -- character immediately preceding the next comma (',') or with the
kono
parents:
diff changeset
190 -- last character of the parameter.
kono
parents:
diff changeset
191 --
kono
parents:
diff changeset
192 -- The allowed values for preserve= are:
kono
parents:
diff changeset
193 --
kono
parents:
diff changeset
194 -- no_attributes: Do not try to preserve any file attributes. This
kono
parents:
diff changeset
195 -- is the default if no preserve= is found in Form.
kono
parents:
diff changeset
196 --
kono
parents:
diff changeset
197 -- all_attributes: Try to preserve all file attributes (timestamps,
kono
parents:
diff changeset
198 -- access rights).
kono
parents:
diff changeset
199 --
kono
parents:
diff changeset
200 -- timestamps: Preserve the timestamp of the copied file, but not
kono
parents:
diff changeset
201 -- the other file attributes.
kono
parents:
diff changeset
202 --
kono
parents:
diff changeset
203 -- The allowed values for mode= are:
kono
parents:
diff changeset
204 --
kono
parents:
diff changeset
205 -- copy: Only copy if the destination file does not already
kono
parents:
diff changeset
206 -- exist. If it already exists, Copy_File will fail.
kono
parents:
diff changeset
207 --
kono
parents:
diff changeset
208 -- overwrite: Copy the file in all cases. Overwrite an already
kono
parents:
diff changeset
209 -- existing destination file. This is the default if
kono
parents:
diff changeset
210 -- no mode= is found in Form.
kono
parents:
diff changeset
211 --
kono
parents:
diff changeset
212 -- append: Append the original file to the destination file.
kono
parents:
diff changeset
213 -- If the destination file does not exist, the
kono
parents:
diff changeset
214 -- destination file is a copy of the source file.
kono
parents:
diff changeset
215 -- When mode=append, the field preserve=, if it
kono
parents:
diff changeset
216 -- exists, is not taken into account.
kono
parents:
diff changeset
217 --
kono
parents:
diff changeset
218 -- If the Form parameter includes one or both of the fields and the value
kono
parents:
diff changeset
219 -- or values are incorrect, Copy_File fails with Use_Error.
kono
parents:
diff changeset
220 --
kono
parents:
diff changeset
221 -- Examples of correct Forms:
kono
parents:
diff changeset
222 -- Form => "preserve=no_attributes,mode=overwrite" (the default)
kono
parents:
diff changeset
223 -- Form => "mode=append"
kono
parents:
diff changeset
224 -- Form => "mode=copy,preserve=all_attributes"
kono
parents:
diff changeset
225 --
kono
parents:
diff changeset
226 -- Examples of incorrect Forms:
kono
parents:
diff changeset
227 -- Form => "preserve=junk"
kono
parents:
diff changeset
228 -- Form => "mode=internal,preserve=timestamps"
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 ----------------------------------------
kono
parents:
diff changeset
231 -- File and directory name operations --
kono
parents:
diff changeset
232 ----------------------------------------
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 function Full_Name (Name : String) return String;
kono
parents:
diff changeset
235 -- Returns the full name corresponding to the file name specified by Name.
kono
parents:
diff changeset
236 -- The exception Name_Error is propagated if the string given as Name does
kono
parents:
diff changeset
237 -- not allow the identification of an external file (including directories
kono
parents:
diff changeset
238 -- and special files).
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 function Simple_Name (Name : String) return String;
kono
parents:
diff changeset
241 -- Returns the simple name portion of the file name specified by Name. The
kono
parents:
diff changeset
242 -- exception Name_Error is propagated if the string given as Name does not
kono
parents:
diff changeset
243 -- allow the identification of an external file (including directories and
kono
parents:
diff changeset
244 -- special files).
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 function Containing_Directory (Name : String) return String;
kono
parents:
diff changeset
247 -- Returns the name of the containing directory of the external file
kono
parents:
diff changeset
248 -- (including directories) identified by Name. If more than one directory
kono
parents:
diff changeset
249 -- can contain Name, the directory name returned is implementation-defined.
kono
parents:
diff changeset
250 -- The exception Name_Error is propagated if the string given as Name does
kono
parents:
diff changeset
251 -- not allow the identification of an external file. The exception
kono
parents:
diff changeset
252 -- Use_Error is propagated if the external file does not have a containing
kono
parents:
diff changeset
253 -- directory.
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 function Extension (Name : String) return String;
kono
parents:
diff changeset
256 -- Returns the extension name corresponding to Name. The extension name is
kono
parents:
diff changeset
257 -- a portion of a simple name (not including any separator characters),
kono
parents:
diff changeset
258 -- typically used to identify the file class. If the external environment
kono
parents:
diff changeset
259 -- does not have extension names, then the null string is returned.
kono
parents:
diff changeset
260 -- The exception Name_Error is propagated if the string given as Name does
kono
parents:
diff changeset
261 -- not allow the identification of an external file.
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 function Base_Name (Name : String) return String;
kono
parents:
diff changeset
264 -- Returns the base name corresponding to Name. The base name is the
kono
parents:
diff changeset
265 -- remainder of a simple name after removing any extension and extension
kono
parents:
diff changeset
266 -- separators. The exception Name_Error is propagated if the string given
kono
parents:
diff changeset
267 -- as Name does not allow the identification of an external file
kono
parents:
diff changeset
268 -- (including directories and special files).
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 function Compose
kono
parents:
diff changeset
271 (Containing_Directory : String := "";
kono
parents:
diff changeset
272 Name : String;
kono
parents:
diff changeset
273 Extension : String := "") return String;
kono
parents:
diff changeset
274 -- Returns the name of the external file with the specified
kono
parents:
diff changeset
275 -- Containing_Directory, Name, and Extension. If Extension is the null
kono
parents:
diff changeset
276 -- string, then Name is interpreted as a simple name; otherwise Name is
kono
parents:
diff changeset
277 -- interpreted as a base name. The exception Name_Error is propagated if
kono
parents:
diff changeset
278 -- the string given as Containing_Directory is not null and does not allow
kono
parents:
diff changeset
279 -- the identification of a directory, or if the string given as Extension
kono
parents:
diff changeset
280 -- is not null and is not a possible extension, or if the string given as
kono
parents:
diff changeset
281 -- Name is not a possible simple name (if Extension is null) or base name
kono
parents:
diff changeset
282 -- (if Extension is non-null).
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 --------------------------------
kono
parents:
diff changeset
285 -- File and directory queries --
kono
parents:
diff changeset
286 --------------------------------
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 type File_Kind is (Directory, Ordinary_File, Special_File);
kono
parents:
diff changeset
289 -- The type File_Kind represents the kind of file represented by an
kono
parents:
diff changeset
290 -- external file or directory.
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 type File_Size is range 0 .. Long_Long_Integer'Last;
kono
parents:
diff changeset
293 -- The type File_Size represents the size of an external file
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 function Exists (Name : String) return Boolean;
kono
parents:
diff changeset
296 -- Returns True if external file represented by Name exists, and False
kono
parents:
diff changeset
297 -- otherwise. The exception Name_Error is propagated if the string given as
kono
parents:
diff changeset
298 -- Name does not allow the identification of an external file (including
kono
parents:
diff changeset
299 -- directories and special files).
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 function Kind (Name : String) return File_Kind;
kono
parents:
diff changeset
302 -- Returns the kind of external file represented by Name. The exception
kono
parents:
diff changeset
303 -- Name_Error is propagated if the string given as Name does not allow the
kono
parents:
diff changeset
304 -- identification of an existing external file.
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 function Size (Name : String) return File_Size;
kono
parents:
diff changeset
307 -- Returns the size of the external file represented by Name. The size of
kono
parents:
diff changeset
308 -- an external file is the number of stream elements contained in the file.
kono
parents:
diff changeset
309 -- If the external file is discontiguous (not all elements exist), the
kono
parents:
diff changeset
310 -- result is implementation-defined. If the external file is not an
kono
parents:
diff changeset
311 -- ordinary file, the result is implementation-defined. The exception
kono
parents:
diff changeset
312 -- Name_Error is propagated if the string given as Name does not allow the
kono
parents:
diff changeset
313 -- identification of an existing external file. The exception
kono
parents:
diff changeset
314 -- Constraint_Error is propagated if the file size is not a value of type
kono
parents:
diff changeset
315 -- File_Size.
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 function Modification_Time (Name : String) return Ada.Calendar.Time;
kono
parents:
diff changeset
318 -- Returns the time that the external file represented by Name was most
kono
parents:
diff changeset
319 -- recently modified. If the external file is not an ordinary file, the
kono
parents:
diff changeset
320 -- result is implementation-defined. The exception Name_Error is propagated
kono
parents:
diff changeset
321 -- if the string given as Name does not allow the identification of an
kono
parents:
diff changeset
322 -- existing external file. The exception Use_Error is propagated if the
kono
parents:
diff changeset
323 -- external environment does not support the reading the modification time
kono
parents:
diff changeset
324 -- of the file with the name given by Name (in the absence of Name_Error).
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 -------------------------
kono
parents:
diff changeset
327 -- Directory Searching --
kono
parents:
diff changeset
328 -------------------------
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 type Directory_Entry_Type is limited private;
kono
parents:
diff changeset
331 -- The type Directory_Entry_Type represents a single item in a directory.
kono
parents:
diff changeset
332 -- These items can only be created by the Get_Next_Entry procedure in this
kono
parents:
diff changeset
333 -- package. Information about the item can be obtained from the functions
kono
parents:
diff changeset
334 -- declared in this package. A default initialized object of this type is
kono
parents:
diff changeset
335 -- invalid; objects returned from Get_Next_Entry are valid.
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 type Filter_Type is array (File_Kind) of Boolean;
kono
parents:
diff changeset
338 -- The type Filter_Type specifies which directory entries are provided from
kono
parents:
diff changeset
339 -- a search operation. If the Directory component is True, directory
kono
parents:
diff changeset
340 -- entries representing directories are provided. If the Ordinary_File
kono
parents:
diff changeset
341 -- component is True, directory entries representing ordinary files are
kono
parents:
diff changeset
342 -- provided. If the Special_File component is True, directory entries
kono
parents:
diff changeset
343 -- representing special files are provided.
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 type Search_Type is limited private;
kono
parents:
diff changeset
346 -- The type Search_Type contains the state of a directory search. A
kono
parents:
diff changeset
347 -- default-initialized Search_Type object has no entries available
kono
parents:
diff changeset
348 -- (More_Entries returns False).
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 procedure Start_Search
kono
parents:
diff changeset
351 (Search : in out Search_Type;
kono
parents:
diff changeset
352 Directory : String;
kono
parents:
diff changeset
353 Pattern : String;
kono
parents:
diff changeset
354 Filter : Filter_Type := (others => True));
kono
parents:
diff changeset
355 -- Starts a search in the directory entry in the directory named by
kono
parents:
diff changeset
356 -- Directory for entries matching Pattern. Pattern represents a file name
kono
parents:
diff changeset
357 -- matching pattern. If Pattern is null, all items in the directory are
kono
parents:
diff changeset
358 -- matched; otherwise, the interpretation of Pattern is implementation-
kono
parents:
diff changeset
359 -- defined. Only items which match Filter will be returned. After a
kono
parents:
diff changeset
360 -- successful call on Start_Search, the object Search may have entries
kono
parents:
diff changeset
361 -- available, but it may have no entries available if no files or
kono
parents:
diff changeset
362 -- directories match Pattern and Filter. The exception Name_Error is
kono
parents:
diff changeset
363 -- propagated if the string given by Directory does not identify an
kono
parents:
diff changeset
364 -- existing directory, or if Pattern does not allow the identification of
kono
parents:
diff changeset
365 -- any possible external file or directory. The exception Use_Error is
kono
parents:
diff changeset
366 -- propagated if the external environment does not support the searching
kono
parents:
diff changeset
367 -- of the directory with the given name (in the absence of Name_Error).
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 procedure End_Search (Search : in out Search_Type);
kono
parents:
diff changeset
370 -- Ends the search represented by Search. After a successful call on
kono
parents:
diff changeset
371 -- End_Search, the object Search will have no entries available. Note
kono
parents:
diff changeset
372 -- that it is not necessary to call End_Search if the call to Start_Search
kono
parents:
diff changeset
373 -- was unsuccessful and raised an exception (but it is harmless to make
kono
parents:
diff changeset
374 -- the call in this case).
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 function More_Entries (Search : Search_Type) return Boolean;
kono
parents:
diff changeset
377 -- Returns True if more entries are available to be returned by a call
kono
parents:
diff changeset
378 -- to Get_Next_Entry for the specified search object, and False otherwise.
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 procedure Get_Next_Entry
kono
parents:
diff changeset
381 (Search : in out Search_Type;
kono
parents:
diff changeset
382 Directory_Entry : out Directory_Entry_Type);
kono
parents:
diff changeset
383 -- Returns the next Directory_Entry for the search described by Search that
kono
parents:
diff changeset
384 -- matches the pattern and filter. If no further matches are available,
kono
parents:
diff changeset
385 -- Status_Error is raised. It is implementation-defined as to whether the
kono
parents:
diff changeset
386 -- results returned by this routine are altered if the contents of the
kono
parents:
diff changeset
387 -- directory are altered while the Search object is valid (for example, by
kono
parents:
diff changeset
388 -- another program). The exception Use_Error is propagated if the external
kono
parents:
diff changeset
389 -- environment does not support continued searching of the directory
kono
parents:
diff changeset
390 -- represented by Search.
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 procedure Search
kono
parents:
diff changeset
393 (Directory : String;
kono
parents:
diff changeset
394 Pattern : String;
kono
parents:
diff changeset
395 Filter : Filter_Type := (others => True);
kono
parents:
diff changeset
396 Process : not null access procedure
kono
parents:
diff changeset
397 (Directory_Entry : Directory_Entry_Type));
kono
parents:
diff changeset
398 -- Searches in the directory named by Directory for entries matching
kono
parents:
diff changeset
399 -- Pattern. The subprogram designated by Process is called with each
kono
parents:
diff changeset
400 -- matching entry in turn. Pattern represents a pattern for matching file
kono
parents:
diff changeset
401 -- names. If Pattern is null, all items in the directory are matched;
kono
parents:
diff changeset
402 -- otherwise, the interpretation of Pattern is implementation-defined.
kono
parents:
diff changeset
403 -- Only items that match Filter will be returned. The exception Name_Error
kono
parents:
diff changeset
404 -- is propagated if the string given by Directory does not identify
kono
parents:
diff changeset
405 -- an existing directory, or if Pattern does not allow the identification
kono
parents:
diff changeset
406 -- of any possible external file or directory. The exception Use_Error is
kono
parents:
diff changeset
407 -- propagated if the external environment does not support the searching
kono
parents:
diff changeset
408 -- of the directory with the given name (in the absence of Name_Error).
kono
parents:
diff changeset
409
kono
parents:
diff changeset
410 -------------------------------------
kono
parents:
diff changeset
411 -- Operations on Directory Entries --
kono
parents:
diff changeset
412 -------------------------------------
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 function Simple_Name (Directory_Entry : Directory_Entry_Type) return String;
kono
parents:
diff changeset
415 -- Returns the simple external name of the external file (including
kono
parents:
diff changeset
416 -- directories) represented by Directory_Entry. The format of the name
kono
parents:
diff changeset
417 -- returned is implementation-defined. The exception Status_Error is
kono
parents:
diff changeset
418 -- propagated if Directory_Entry is invalid.
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 function Full_Name (Directory_Entry : Directory_Entry_Type) return String;
kono
parents:
diff changeset
421 -- Returns the full external name of the external file (including
kono
parents:
diff changeset
422 -- directories) represented by Directory_Entry. The format of the name
kono
parents:
diff changeset
423 -- returned is implementation-defined. The exception Status_Error is
kono
parents:
diff changeset
424 -- propagated if Directory_Entry is invalid.
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 function Kind (Directory_Entry : Directory_Entry_Type) return File_Kind;
kono
parents:
diff changeset
427 -- Returns the kind of external file represented by Directory_Entry. The
kono
parents:
diff changeset
428 -- exception Status_Error is propagated if Directory_Entry is invalid.
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 function Size (Directory_Entry : Directory_Entry_Type) return File_Size;
kono
parents:
diff changeset
431 -- Returns the size of the external file represented by Directory_Entry.
kono
parents:
diff changeset
432 -- The size of an external file is the number of stream elements contained
kono
parents:
diff changeset
433 -- in the file. If the external file is discontiguous (not all elements
kono
parents:
diff changeset
434 -- exist), the result is implementation-defined. If the external file
kono
parents:
diff changeset
435 -- represented by Directory_Entry is not an ordinary file, the result is
kono
parents:
diff changeset
436 -- implementation-defined. The exception Status_Error is propagated if
kono
parents:
diff changeset
437 -- Directory_Entry is invalid. The exception Constraint_Error is propagated
kono
parents:
diff changeset
438 -- if the file size is not a value of type File_Size.
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 function Modification_Time
kono
parents:
diff changeset
441 (Directory_Entry : Directory_Entry_Type) return Ada.Calendar.Time;
kono
parents:
diff changeset
442 -- Returns the time that the external file represented by Directory_Entry
kono
parents:
diff changeset
443 -- was most recently modified. If the external file represented by
kono
parents:
diff changeset
444 -- Directory_Entry is not an ordinary file, the result is
kono
parents:
diff changeset
445 -- implementation-defined. The exception Status_Error is propagated if
kono
parents:
diff changeset
446 -- Directory_Entry is invalid. The exception Use_Error is propagated if
kono
parents:
diff changeset
447 -- the external environment does not support the reading the modification
kono
parents:
diff changeset
448 -- time of the file represented by Directory_Entry.
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 ----------------
kono
parents:
diff changeset
451 -- Exceptions --
kono
parents:
diff changeset
452 ----------------
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 Status_Error : exception renames Ada.IO_Exceptions.Status_Error;
kono
parents:
diff changeset
455 Name_Error : exception renames Ada.IO_Exceptions.Name_Error;
kono
parents:
diff changeset
456 Use_Error : exception renames Ada.IO_Exceptions.Use_Error;
kono
parents:
diff changeset
457 Device_Error : exception renames Ada.IO_Exceptions.Device_Error;
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 private
kono
parents:
diff changeset
460 type Directory_Entry_Type is record
kono
parents:
diff changeset
461 Is_Valid : Boolean := False;
kono
parents:
diff changeset
462 Simple : Ada.Strings.Unbounded.Unbounded_String;
kono
parents:
diff changeset
463 Full : Ada.Strings.Unbounded.Unbounded_String;
kono
parents:
diff changeset
464 Kind : File_Kind := Ordinary_File;
kono
parents:
diff changeset
465 end record;
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 -- The type Search_Data is defined in the body, so that the spec does not
kono
parents:
diff changeset
468 -- depend on packages of the GNAT hierarchy.
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 type Search_Data;
kono
parents:
diff changeset
471 type Search_Ptr is access Search_Data;
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 -- Search_Type need to be a controlled type, because it includes component
kono
parents:
diff changeset
474 -- of type Dir_Type (in GNAT.Directory_Operations) that need to be closed
kono
parents:
diff changeset
475 -- (if opened) during finalization. The component need to be an access
kono
parents:
diff changeset
476 -- value, because Search_Data is not fully defined in the spec.
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 type Search_Type is new Ada.Finalization.Controlled with record
kono
parents:
diff changeset
479 Value : Search_Ptr;
kono
parents:
diff changeset
480 end record;
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 procedure Finalize (Search : in out Search_Type);
kono
parents:
diff changeset
483 -- Close the directory, if opened, and deallocate Value
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 procedure End_Search (Search : in out Search_Type) renames Finalize;
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 end Ada.Directories;