fixing pr42337
[official-gcc.git] / gcc / ada / a-dirval-vms.adb
blob34032b233cb946640b11c4f57f4ea9fdf0db8f5d
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . D I R E C T O R I E S . V A L I D I T Y --
6 -- --
7 -- B o d y --
8 -- (VMS Version) --
9 -- --
10 -- Copyright (C) 2004-2009, Free Software Foundation, Inc. --
11 -- --
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. --
18 -- --
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. --
22 -- --
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/>. --
27 -- --
28 -- GNAT was originally developed by the GNAT team at New York University. --
29 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 -- --
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 :=
41 ('a' .. 'z' => False,
42 'A' .. 'Z' => False,
43 '0' .. '9' => False,
44 '_' | '$' | '-' | '.' => False,
45 others => True);
47 ---------------------------------
48 -- Is_Path_Name_Case_Sensitive --
49 ---------------------------------
51 function Is_Path_Name_Case_Sensitive return Boolean is
52 begin
53 return False;
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;
62 Last : Positive;
63 Dot_Found : Boolean := False;
65 begin
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
71 return False;
73 else
74 loop
75 -- Look for the start of the next directory or file name
77 while First <= Name'Last and then Name (First) = '/' loop
78 First := First + 1;
79 end loop;
81 -- If all directories/file names are OK, return True
83 exit when First > Name'Last;
85 Last := First;
86 Dot_Found := False;
88 -- Look for the end of the directory/file name
90 while Last < Name'Last loop
91 exit when Name (Last + 1) = '/';
92 Last := Last + 1;
94 if Name (Last) = '.' then
95 Dot_Found := True;
96 end if;
97 end loop;
99 -- If name include a dot, it can only be ".", ".." or the last
100 -- file name.
102 if Dot_Found then
103 if Name (First .. Last) /= "." and then
104 Name (First .. Last) /= ".."
105 then
106 return Last = Name'Last
107 and then Is_Valid_Simple_Name (Name (First .. Last));
109 end if;
111 -- Check if the directory/file name is valid
113 elsif not Is_Valid_Simple_Name (Name (First .. Last)) then
114 return False;
115 end if;
117 -- Move to the next name
119 First := Last + 1;
120 end loop;
121 end if;
123 -- If Name follows the rules, then it is valid
125 return True;
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;
136 begin
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
141 return False;
143 else
144 -- Check each character for validity
146 for J in Name'Range loop
147 if Invalid_Character (Name (J)) then
148 return False;
150 elsif Name (J) = '.' then
152 -- Name cannot contain several dots
154 if In_Extension then
155 return False;
157 else
158 -- Reset the number of characters to count the characters
159 -- of the extension.
161 In_Extension := True;
162 Number_Of_Characters := 0;
163 end if;
165 else
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
171 return False;
172 end if;
173 end if;
174 end loop;
175 end if;
177 -- If the rules are followed, then it is valid
179 return True;
180 end Is_Valid_Simple_Name;
182 -------------
183 -- OpenVMS --
184 -------------
186 function OpenVMS return Boolean is
187 begin
188 return True;
189 end OpenVMS;
191 -------------
192 -- Windows --
193 -------------
195 function Windows return Boolean is
196 begin
197 return False;
198 end Windows;
200 end Ada.Directories.Validity;