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 --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
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. --
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. --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 ------------------------------------------------------------------------------
35 with Ada
.Text_IO
.Generic_Aux
; use Ada
.Text_IO
.Generic_Aux
;
36 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
37 with Interfaces
.C_Streams
; use Interfaces
.C_Streams
;
39 -- Note: this package does not yet deal properly with wide characters ???
41 package body Ada
.Text_IO
.Enumeration_Aux
is
43 -----------------------
44 -- Local Subprograms --
45 -----------------------
47 -- These definitions replace the ones in Ada.Characters.Handling, which
48 -- do not seem to work for some strange not understood reason ??? at
49 -- least in the OS/2 version.
51 function To_Lower
(C
: Character) return Character;
52 function To_Upper
(C
: Character) return Character;
58 procedure Get_Enum_Lit
70 C
:= Character'Val (ch
);
72 -- Character literal case. If the initial character is a quote, then
73 -- we read as far as we can without backup (see ACVC test CE3905L)
76 Store_Char
(File
, ch
, Buf
, Buflen
);
80 if ch
in 16#
20#
.. 16#
7E#
or else ch
>= 16#
80#
then
81 Store_Char
(File
, ch
, Buf
, Buflen
);
85 if ch
= Character'Pos (''') then
86 Store_Char
(File
, ch
, Buf
, Buflen
);
95 -- Similarly for identifiers, read as far as we can, in particular,
96 -- do read a trailing underscore (again see ACVC test CE3905L to
97 -- understand why we do this, although it seems somewhat peculiar).
100 -- Identifier must start with a letter
102 if not Is_Letter
(C
) then
107 -- If we do have a letter, loop through the characters quitting on
108 -- the first non-identifier character (note that this includes the
109 -- cases of hitting a line mark or page mark).
112 C
:= Character'Val (ch
);
113 Store_Char
(File
, Character'Pos (To_Upper
(C
)), Buf
, Buflen
);
117 C
:= Character'Val (ch
);
119 exit when not Is_Letter
(C
)
120 and then not Is_Digit
(C
)
124 and then Buf
(Buflen
) = '_';
141 Actual_Width
: constant Count
:= Count
'Max (Count
(Width
), Item
'Length);
144 if Set
= Lower_Case
and then Item
(1) /= ''' then
146 Iteml
: String (Item
'First .. Item
'Last);
149 for J
in Item
'Range loop
150 Iteml
(J
) := To_Lower
(Item
(J
));
153 Put_Item
(File
, Iteml
);
157 Put_Item
(File
, Item
);
160 for J
in 1 .. Actual_Width
- Item
'Length loop
177 if Item
'Length > To
'Length then
182 for J
in Item
'Range loop
183 if Set
= Lower_Case
and then Item
(1) /= ''' then
184 To
(Ptr
) := To_Lower
(Item
(J
));
186 To
(Ptr
) := Item
(J
);
192 while Ptr
<= To
'Last loop
203 procedure Scan_Enum_Lit
210 -- Processing for Scan_Enum_Lit
213 String_Skip
(From
, Start
);
215 -- Character literal case. If the initial character is a quote, then
216 -- we read as far as we can without backup (see ACVC test CE3905L
217 -- which is for the analogous case for reading from a file).
219 if From
(Start
) = ''' then
222 if Stop
= From
'Last then
228 if From
(Stop
) in ' ' .. '~'
229 or else From
(Stop
) >= Character'Val (16#
80#
)
231 if Stop
= From
'Last then
236 if From
(Stop
) = ''' then
245 -- Similarly for identifiers, read as far as we can, in particular,
246 -- do read a trailing underscore (again see ACVC test CE3905L to
247 -- understand why we do this, although it seems somewhat peculiar).
250 -- Identifier must start with a letter
252 if not Is_Letter
(From
(Start
)) then
256 -- If we do have a letter, loop through the characters quitting on
257 -- the first non-identifier character (note that this includes the
258 -- cases of hitting a line mark or page mark).
261 while Stop
< From
'Last loop
262 C
:= From
(Stop
+ 1);
264 exit when not Is_Letter
(C
)
265 and then not Is_Digit
(C
)
269 and then From
(Stop
) = '_';
281 function To_Lower
(C
: Character) return Character is
283 if C
in 'A' .. 'Z' then
284 return Character'Val (Character'Pos (C
) + 32);
290 function To_Upper
(C
: Character) return Character is
292 if C
in 'a' .. 'z' then
293 return Character'Val (Character'Pos (C
) - 32);
299 end Ada
.Text_IO
.Enumeration_Aux
;