OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [ada/] [a-dirval-vms.adb] - Blame information for rev 826

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 281 jeremybenn
------------------------------------------------------------------------------
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
------------------------------------------------------------------------------
32
 
33
--  This is the OpenVMS version of this package
34
 
35
package body Ada.Directories.Validity is
36
 
37
   Max_Number_Of_Characters : constant := 39;
38
   Max_Path_Length          : constant := 1_024;
39
 
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);
46
 
47
   ---------------------------------
48
   -- Is_Path_Name_Case_Sensitive --
49
   ---------------------------------
50
 
51
   function Is_Path_Name_Case_Sensitive return Boolean is
52
   begin
53
      return False;
54
   end Is_Path_Name_Case_Sensitive;
55
 
56
   ------------------------
57
   -- Is_Valid_Path_Name --
58
   ------------------------
59
 
60
   function Is_Valid_Path_Name (Name : String) return Boolean is
61
      First     : Positive := Name'First;
62
      Last      : Positive;
63
      Dot_Found : Boolean := False;
64
 
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.
69
 
70
      if Name'Length = 0 or else Name'Length > Max_Path_Length then
71
         return False;
72
 
73
      else
74
         loop
75
            --  Look for the start of the next directory or file name
76
 
77
            while First <= Name'Last and then Name (First) = '/' loop
78
               First := First + 1;
79
            end loop;
80
 
81
            --  If all directories/file names are OK, return True
82
 
83
            exit when First > Name'Last;
84
 
85
            Last := First;
86
            Dot_Found := False;
87
 
88
            --  Look for the end of the directory/file name
89
 
90
            while Last < Name'Last loop
91
               exit when Name (Last + 1) = '/';
92
               Last := Last + 1;
93
 
94
               if Name (Last) = '.' then
95
                  Dot_Found := True;
96
               end if;
97
            end loop;
98
 
99
            --  If name include a dot, it can only be ".", ".." or the last
100
            --  file name.
101
 
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));
108
 
109
               end if;
110
 
111
            --  Check if the directory/file name is valid
112
 
113
            elsif not Is_Valid_Simple_Name (Name (First .. Last)) then
114
                  return False;
115
            end if;
116
 
117
            --  Move to the next name
118
 
119
            First := Last + 1;
120
         end loop;
121
      end if;
122
 
123
      --  If Name follows the rules, then it is valid
124
 
125
      return True;
126
   end Is_Valid_Path_Name;
127
 
128
   --------------------------
129
   -- Is_Valid_Simple_Name --
130
   --------------------------
131
 
132
   function Is_Valid_Simple_Name (Name : String) return Boolean is
133
      In_Extension         : Boolean := False;
134
      Number_Of_Characters : Natural := 0;
135
 
136
   begin
137
      --  A file name cannot be empty, and cannot have more than 39 characters
138
      --  before or after a single '.'.
139
 
140
      if Name'Length = 0 then
141
         return False;
142
 
143
      else
144
         --  Check each character for validity
145
 
146
         for J in Name'Range loop
147
            if Invalid_Character (Name (J)) then
148
               return False;
149
 
150
            elsif Name (J) = '.' then
151
 
152
               --  Name cannot contain several dots
153
 
154
               if In_Extension then
155
                  return False;
156
 
157
               else
158
                  --  Reset the number of characters to count the characters
159
                  --  of the extension.
160
 
161
                  In_Extension := True;
162
                  Number_Of_Characters := 0;
163
               end if;
164
 
165
            else
166
               --  Check that the number of character is not too large
167
 
168
               Number_Of_Characters := Number_Of_Characters + 1;
169
 
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;
176
 
177
      --  If the rules are followed, then it is valid
178
 
179
      return True;
180
   end Is_Valid_Simple_Name;
181
 
182
   -------------
183
   -- OpenVMS --
184
   -------------
185
 
186
   function OpenVMS return Boolean is
187
   begin
188
      return True;
189
   end OpenVMS;
190
 
191
   -------------
192
   -- Windows --
193
   -------------
194
 
195
   function Windows return Boolean is
196
   begin
197
      return False;
198
   end Windows;
199
 
200
end Ada.Directories.Validity;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.