2003-05-31 Bud Davis <bdavis9659@comcast.net>
[official-gcc.git] / gcc / ada / a-tienau.adb
blobf420f76b21c07b15e250d3cd23727865be6f9696
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUNTIME COMPONENTS --
4 -- --
5 -- A D A . T E X T _ I O . E N U M E R A T I O N _ A U X --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
35 with Ada.Characters.Handling; use Ada.Characters.Handling;
36 with Interfaces.C_Streams; use Interfaces.C_Streams;
38 -- Note: this package does not yet deal properly with wide characters ???
40 package body Ada.Text_IO.Enumeration_Aux is
42 -----------------------
43 -- Local Subprograms --
44 -----------------------
46 -- These definitions replace the ones in Ada.Characters.Handling, which
47 -- do not seem to work for some strange not understood reason ??? at
48 -- least in the OS/2 version.
50 function To_Lower (C : Character) return Character;
51 function To_Upper (C : Character) return Character;
53 ------------------
54 -- Get_Enum_Lit --
55 ------------------
57 procedure Get_Enum_Lit
58 (File : File_Type;
59 Buf : out String;
60 Buflen : out Natural)
62 ch : int;
63 C : Character;
65 begin
66 Buflen := 0;
67 Load_Skip (File);
68 ch := Getc (File);
69 C := Character'Val (ch);
71 -- Character literal case. If the initial character is a quote, then
72 -- we read as far as we can without backup (see ACVC test CE3905L)
74 if C = ''' then
75 Store_Char (File, ch, Buf, Buflen);
77 ch := Getc (File);
79 if ch in 16#20# .. 16#7E# or else ch >= 16#80# then
80 Store_Char (File, ch, Buf, Buflen);
82 ch := Getc (File);
84 if ch = Character'Pos (''') then
85 Store_Char (File, ch, Buf, Buflen);
86 else
87 Ungetc (ch, File);
88 end if;
90 else
91 Ungetc (ch, File);
92 end if;
94 -- Similarly for identifiers, read as far as we can, in particular,
95 -- do read a trailing underscore (again see ACVC test CE3905L to
96 -- understand why we do this, although it seems somewhat peculiar).
98 else
99 -- Identifier must start with a letter
101 if not Is_Letter (C) then
102 Ungetc (ch, File);
103 return;
104 end if;
106 -- If we do have a letter, loop through the characters quitting on
107 -- the first non-identifier character (note that this includes the
108 -- cases of hitting a line mark or page mark).
110 loop
111 C := Character'Val (ch);
112 Store_Char (File, Character'Pos (To_Upper (C)), Buf, Buflen);
114 ch := Getc (File);
115 exit when ch = EOF;
116 C := Character'Val (ch);
118 exit when not Is_Letter (C)
119 and then not Is_Digit (C)
120 and then C /= '_';
122 exit when C = '_'
123 and then Buf (Buflen) = '_';
124 end loop;
126 Ungetc (ch, File);
127 end if;
128 end Get_Enum_Lit;
130 ---------
131 -- Put --
132 ---------
134 procedure Put
135 (File : File_Type;
136 Item : String;
137 Width : Field;
138 Set : Type_Set)
140 Actual_Width : constant Count := Count'Max (Count (Width), Item'Length);
142 begin
143 if Set = Lower_Case and then Item (1) /= ''' then
144 declare
145 Iteml : String (Item'First .. Item'Last);
147 begin
148 for J in Item'Range loop
149 Iteml (J) := To_Lower (Item (J));
150 end loop;
152 Put_Item (File, Iteml);
153 end;
155 else
156 Put_Item (File, Item);
157 end if;
159 for J in 1 .. Actual_Width - Item'Length loop
160 Put (File, ' ');
161 end loop;
162 end Put;
164 ----------
165 -- Puts --
166 ----------
168 procedure Puts
169 (To : out String;
170 Item : in String;
171 Set : Type_Set)
173 Ptr : Natural;
175 begin
176 if Item'Length > To'Length then
177 raise Layout_Error;
179 else
180 Ptr := To'First;
181 for J in Item'Range loop
182 if Set = Lower_Case and then Item (1) /= ''' then
183 To (Ptr) := To_Lower (Item (J));
184 else
185 To (Ptr) := Item (J);
186 end if;
188 Ptr := Ptr + 1;
189 end loop;
191 while Ptr <= To'Last loop
192 To (Ptr) := ' ';
193 Ptr := Ptr + 1;
194 end loop;
195 end if;
196 end Puts;
198 -------------------
199 -- Scan_Enum_Lit --
200 -------------------
202 procedure Scan_Enum_Lit
203 (From : String;
204 Start : out Natural;
205 Stop : out Natural)
207 C : Character;
209 -- Processing for Scan_Enum_Lit
211 begin
212 String_Skip (From, Start);
214 -- Character literal case. If the initial character is a quote, then
215 -- we read as far as we can without backup (see ACVC test CE3905L
216 -- which is for the analogous case for reading from a file).
218 if From (Start) = ''' then
219 Stop := Start;
221 if Stop = From'Last then
222 raise Data_Error;
223 else
224 Stop := Stop + 1;
225 end if;
227 if From (Stop) in ' ' .. '~'
228 or else From (Stop) >= Character'Val (16#80#)
229 then
230 if Stop = From'Last then
231 raise Data_Error;
232 else
233 Stop := Stop + 1;
235 if From (Stop) = ''' then
236 return;
237 end if;
238 end if;
239 end if;
241 Stop := Stop - 1;
242 raise Data_Error;
244 -- Similarly for identifiers, read as far as we can, in particular,
245 -- do read a trailing underscore (again see ACVC test CE3905L to
246 -- understand why we do this, although it seems somewhat peculiar).
248 else
249 -- Identifier must start with a letter
251 if not Is_Letter (From (Start)) then
252 raise Data_Error;
253 end if;
255 -- If we do have a letter, loop through the characters quitting on
256 -- the first non-identifier character (note that this includes the
257 -- cases of hitting a line mark or page mark).
259 Stop := Start;
260 while Stop < From'Last loop
261 C := From (Stop + 1);
263 exit when not Is_Letter (C)
264 and then not Is_Digit (C)
265 and then C /= '_';
267 exit when C = '_'
268 and then From (Stop) = '_';
270 Stop := Stop + 1;
271 end loop;
272 end if;
274 end Scan_Enum_Lit;
276 --------------
277 -- To_Lower --
278 --------------
280 function To_Lower (C : Character) return Character is
281 begin
282 if C in 'A' .. 'Z' then
283 return Character'Val (Character'Pos (C) + 32);
284 else
285 return C;
286 end if;
287 end To_Lower;
289 function To_Upper (C : Character) return Character is
290 begin
291 if C in 'a' .. 'z' then
292 return Character'Val (Character'Pos (C) - 32);
293 else
294 return C;
295 end if;
296 end To_Upper;
298 end Ada.Text_IO.Enumeration_Aux;