OSDN Git Service

* config/arm/crti.asm: Give _init and _fini function type.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-dirval-vms.adb
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 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 2,  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.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- As a special exception,  if other files  instantiate  generics from this --
24 -- unit, or you link  this unit with other files  to produce an executable, --
25 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
26 -- covered  by the  GNU  General  Public  License.  This exception does not --
27 -- however invalidate  any other reasons why  the executable file  might be --
28 -- covered by the  GNU Public License.                                      --
29 --                                                                          --
30 -- GNAT was originally developed  by the GNAT team at  New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --  This is the OpenVMS version of this package
36
37 package body Ada.Directories.Validity is
38
39    Max_Number_Of_Characters : constant := 39;
40    Max_Path_Length          : constant := 1_024;
41
42    Invalid_Character : constant array (Character) of Boolean :=
43                          ('a' .. 'z' => False,
44                           'A' .. 'Z' => False,
45                           '_' | '$' | '-' | '.' => False,
46                           others => True);
47
48    ------------------------
49    -- Is_Valid_Path_Name --
50    ------------------------
51
52    function Is_Valid_Path_Name (Name : String) return Boolean is
53       First     : Positive := Name'First;
54       Last      : Positive;
55       Dot_Found : Boolean := False;
56
57    begin
58       --  A valid path (directory) name cannot be empty, and cannot contain
59       --  more than 1024 characters. Directories can be ".", ".." or be simple
60       --  name without extensions.
61
62       if Name'Length = 0 or else Name'Length > Max_Path_Length then
63          return False;
64
65       else
66          loop
67             --  Look for the start of the next directory or file name
68
69             while First <= Name'Last and then Name (First) = '/' loop
70                First := First + 1;
71             end loop;
72
73             --  If all directories/file names are OK, return True
74
75             exit when First > Name'Last;
76
77             Last := First;
78             Dot_Found := False;
79
80             --  Look for the end of the directory/file name
81
82             while Last < Name'Last loop
83                exit when Name (Last + 1) = '/';
84                Last := Last + 1;
85
86                if Name (Last) = '.' then
87                   Dot_Found := True;
88                end if;
89             end loop;
90
91             --  If name include a dot, it can only be ".", ".." or a the last
92             --  file name.
93
94             if Dot_Found then
95                if Name (First .. Last) /= "." and then
96                   Name (First .. Last) /= ".."
97                then
98                   return Last = Name'Last
99                     and then Is_Valid_Simple_Name (Name (First .. Last));
100
101                end if;
102
103             --  Check if the directory/file name is valid
104
105             elsif not Is_Valid_Simple_Name (Name (First .. Last)) then
106                   return False;
107             end if;
108
109             --  Move to the next name
110
111             First := Last + 1;
112          end loop;
113       end if;
114
115       --  If Name follows the rules, then it is valid
116
117       return True;
118    end Is_Valid_Path_Name;
119
120    --------------------------
121    -- Is_Valid_Simple_Name --
122    --------------------------
123
124    function Is_Valid_Simple_Name (Name : String) return Boolean is
125       In_Extension         : Boolean := False;
126       Number_Of_Characters : Natural := 0;
127
128    begin
129       --  A file name cannot be empty, and cannot have more than 39 characters
130       --  before or after a single '.'.
131
132       if Name'Length = 0 then
133          return False;
134
135       else
136          --  Check each character for validity
137
138          for J in Name'Range loop
139             if Invalid_Character (Name (J)) then
140                return False;
141
142             elsif Name (J) = '.' then
143
144                --  Name cannot contain several dots
145
146                if In_Extension then
147                   return False;
148
149                else
150                   --  Reset the number of characters to count the characters
151                   --  of the extension.
152
153                   In_Extension := True;
154                   Number_Of_Characters := 0;
155                end if;
156
157             else
158                --  Check that the number of character is not too large
159
160                Number_Of_Characters := Number_Of_Characters + 1;
161
162                if Number_Of_Characters > Max_Number_Of_Characters then
163                   return False;
164                end if;
165             end if;
166          end loop;
167       end if;
168
169       --  If the rules are followed, then it is valid
170
171       return True;
172    end Is_Valid_Simple_Name;
173
174 end Ada.Directories.Validity;
175