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 --
9 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
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. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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;
57 procedure Get_Enum_Lit
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)
75 Store_Char
(File
, ch
, Buf
, Buflen
);
79 if ch
in 16#
20#
.. 16#
7E#
or else ch
>= 16#
80#
then
80 Store_Char
(File
, ch
, Buf
, Buflen
);
84 if ch
= Character'Pos (''') then
85 Store_Char
(File
, ch
, Buf
, Buflen
);
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).
99 -- Identifier must start with a letter
101 if not Is_Letter
(C
) then
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).
111 C
:= Character'Val (ch
);
112 Store_Char
(File
, Character'Pos (To_Upper
(C
)), Buf
, Buflen
);
116 C
:= Character'Val (ch
);
118 exit when not Is_Letter
(C
)
119 and then not Is_Digit
(C
)
123 and then Buf
(Buflen
) = '_';
140 Actual_Width
: constant Count
:= Count
'Max (Count
(Width
), Item
'Length);
143 if Set
= Lower_Case
and then Item
(1) /= ''' then
145 Iteml
: String (Item
'First .. Item
'Last);
148 for J
in Item
'Range loop
149 Iteml
(J
) := To_Lower
(Item
(J
));
152 Put_Item
(File
, Iteml
);
156 Put_Item
(File
, Item
);
159 for J
in 1 .. Actual_Width
- Item
'Length loop
176 if Item
'Length > To
'Length then
181 for J
in Item
'Range loop
182 if Set
= Lower_Case
and then Item
(1) /= ''' then
183 To
(Ptr
) := To_Lower
(Item
(J
));
185 To
(Ptr
) := Item
(J
);
191 while Ptr
<= To
'Last loop
202 procedure Scan_Enum_Lit
209 -- Processing for Scan_Enum_Lit
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
221 if Stop
= From
'Last then
227 if From
(Stop
) in ' ' .. '~'
228 or else From
(Stop
) >= Character'Val (16#
80#
)
230 if Stop
= From
'Last then
235 if From
(Stop
) = ''' then
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).
249 -- Identifier must start with a letter
251 if not Is_Letter
(From
(Start
)) then
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).
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
)
268 and then From
(Stop
) = '_';
280 function To_Lower
(C
: Character) return Character is
282 if C
in 'A' .. 'Z' then
283 return Character'Val (Character'Pos (C
) + 32);
289 function To_Upper
(C
: Character) return Character is
291 if C
in 'a' .. 'z' then
292 return Character'Val (Character'Pos (C
) - 32);
298 end Ada
.Text_IO
.Enumeration_Aux
;