1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . D I R E C T O R I E S . V A L I D I T Y --
10 -- Copyright (C) 2004-2009, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 3, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. --
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
20 -- additional permissions described in the GCC Runtime Library Exception, --
21 -- version 3.1, as published by the Free Software Foundation. --
23 -- You should have received a copy of the GNU General Public License and --
24 -- a copy of the GCC Runtime Library Exception along with this program; --
25 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
26 -- <http://www.gnu.org/licenses/>. --
28 -- GNAT was originally developed by the GNAT team at New York University. --
29 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 ------------------------------------------------------------------------------
33 -- This is the OpenVMS version of this package
35 package body Ada
.Directories
.Validity
is
37 Max_Number_Of_Characters
: constant := 39;
38 Max_Path_Length
: constant := 1_024
;
40 Invalid_Character
: constant array (Character) of Boolean :=
44 '_' |
'$' |
'-' |
'.' => False,
47 ---------------------------------
48 -- Is_Path_Name_Case_Sensitive --
49 ---------------------------------
51 function Is_Path_Name_Case_Sensitive
return Boolean is
54 end Is_Path_Name_Case_Sensitive
;
56 ------------------------
57 -- Is_Valid_Path_Name --
58 ------------------------
60 function Is_Valid_Path_Name
(Name
: String) return Boolean is
61 First
: Positive := Name
'First;
63 Dot_Found
: Boolean := False;
66 -- A valid path (directory) name cannot be empty, and cannot contain
67 -- more than 1024 characters. Directories can be ".", ".." or be simple
68 -- name without extensions.
70 if Name
'Length = 0 or else Name
'Length > Max_Path_Length
then
75 -- Look for the start of the next directory or file name
77 while First
<= Name
'Last and then Name
(First
) = '/' loop
81 -- If all directories/file names are OK, return True
83 exit when First
> Name
'Last;
88 -- Look for the end of the directory/file name
90 while Last
< Name
'Last loop
91 exit when Name
(Last
+ 1) = '/';
94 if Name
(Last
) = '.' then
99 -- If name include a dot, it can only be ".", ".." or the last
103 if Name
(First
.. Last
) /= "." and then
104 Name
(First
.. Last
) /= ".."
106 return Last
= Name
'Last
107 and then Is_Valid_Simple_Name
(Name
(First
.. Last
));
111 -- Check if the directory/file name is valid
113 elsif not Is_Valid_Simple_Name
(Name
(First
.. Last
)) then
117 -- Move to the next name
123 -- If Name follows the rules, then it is valid
126 end Is_Valid_Path_Name
;
128 --------------------------
129 -- Is_Valid_Simple_Name --
130 --------------------------
132 function Is_Valid_Simple_Name
(Name
: String) return Boolean is
133 In_Extension
: Boolean := False;
134 Number_Of_Characters
: Natural := 0;
137 -- A file name cannot be empty, and cannot have more than 39 characters
138 -- before or after a single '.'.
140 if Name
'Length = 0 then
144 -- Check each character for validity
146 for J
in Name
'Range loop
147 if Invalid_Character
(Name
(J
)) then
150 elsif Name
(J
) = '.' then
152 -- Name cannot contain several dots
158 -- Reset the number of characters to count the characters
161 In_Extension
:= True;
162 Number_Of_Characters
:= 0;
166 -- Check that the number of character is not too large
168 Number_Of_Characters
:= Number_Of_Characters
+ 1;
170 if Number_Of_Characters
> Max_Number_Of_Characters
then
177 -- If the rules are followed, then it is valid
180 end Is_Valid_Simple_Name
;
186 function OpenVMS
return Boolean is
195 function Windows
return Boolean is
200 end Ada
.Directories
.Validity
;