1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME COMPONENTS --
5 -- A D A . T E X T _ I O . E N U M E R A T I O N _ A U X --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 with Ada
.Text_IO
.Generic_Aux
; use Ada
.Text_IO
.Generic_Aux
;
37 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
38 with Interfaces
.C_Streams
; use Interfaces
.C_Streams
;
40 -- Note: this package does not yet deal properly with wide characters ???
42 package body Ada
.Text_IO
.Enumeration_Aux
is
44 -----------------------
45 -- Local Subprograms --
46 -----------------------
48 -- These definitions replace the ones in Ada.Characters.Handling, which
49 -- do not seem to work for some strange not understood reason ??? at
50 -- least in the OS/2 version.
52 function To_Lower
(C
: Character) return Character;
53 function To_Upper
(C
: Character) return Character;
59 procedure Get_Enum_Lit
71 C
:= Character'Val (ch
);
73 -- Character literal case. If the initial character is a quote, then
74 -- we read as far as we can without backup (see ACVC test CE3905L)
77 Store_Char
(File
, ch
, Buf
, Buflen
);
81 if ch
in 16#
20#
.. 16#
7E#
or else ch
>= 16#
80#
then
82 Store_Char
(File
, ch
, Buf
, Buflen
);
86 if ch
= Character'Pos (''') then
87 Store_Char
(File
, ch
, Buf
, Buflen
);
96 -- Similarly for identifiers, read as far as we can, in particular,
97 -- do read a trailing underscore (again see ACVC test CE3905L to
98 -- understand why we do this, although it seems somewhat peculiar).
101 -- Identifier must start with a letter
103 if not Is_Letter
(C
) then
108 -- If we do have a letter, loop through the characters quitting on
109 -- the first non-identifier character (note that this includes the
110 -- cases of hitting a line mark or page mark).
113 C
:= Character'Val (ch
);
114 Store_Char
(File
, Character'Pos (To_Upper
(C
)), Buf
, Buflen
);
118 C
:= Character'Val (ch
);
120 exit when not Is_Letter
(C
)
121 and then not Is_Digit
(C
)
125 and then Buf
(Buflen
) = '_';
142 Actual_Width
: constant Count
:= Count
'Max (Count
(Width
), Item
'Length);
145 if Set
= Lower_Case
and then Item
(1) /= ''' then
147 Iteml
: String (Item
'First .. Item
'Last);
150 for J
in Item
'Range loop
151 Iteml
(J
) := To_Lower
(Item
(J
));
154 Put_Item
(File
, Iteml
);
158 Put_Item
(File
, Item
);
161 for J
in 1 .. Actual_Width
- Item
'Length loop
178 if Item
'Length > To
'Length then
183 for J
in Item
'Range loop
184 if Set
= Lower_Case
and then Item
(1) /= ''' then
185 To
(Ptr
) := To_Lower
(Item
(J
));
187 To
(Ptr
) := Item
(J
);
193 while Ptr
<= To
'Last loop
204 procedure Scan_Enum_Lit
211 -- Processing for Scan_Enum_Lit
214 String_Skip
(From
, Start
);
216 -- Character literal case. If the initial character is a quote, then
217 -- we read as far as we can without backup (see ACVC test CE3905L
218 -- which is for the analogous case for reading from a file).
220 if From
(Start
) = ''' then
223 if Stop
= From
'Last then
229 if From
(Stop
) in ' ' .. '~'
230 or else From
(Stop
) >= Character'Val (16#
80#
)
232 if Stop
= From
'Last then
237 if From
(Stop
) = ''' then
246 -- Similarly for identifiers, read as far as we can, in particular,
247 -- do read a trailing underscore (again see ACVC test CE3905L to
248 -- understand why we do this, although it seems somewhat peculiar).
251 -- Identifier must start with a letter
253 if not Is_Letter
(From
(Start
)) then
257 -- If we do have a letter, loop through the characters quitting on
258 -- the first non-identifier character (note that this includes the
259 -- cases of hitting a line mark or page mark).
262 while Stop
< From
'Last loop
263 C
:= From
(Stop
+ 1);
265 exit when not Is_Letter
(C
)
266 and then not Is_Digit
(C
)
270 and then From
(Stop
) = '_';
282 function To_Lower
(C
: Character) return Character is
284 if C
in 'A' .. 'Z' then
285 return Character'Val (Character'Pos (C
) + 32);
291 function To_Upper
(C
: Character) return Character is
293 if C
in 'a' .. 'z' then
294 return Character'Val (Character'Pos (C
) - 32);
300 end Ada
.Text_IO
.Enumeration_Aux
;