1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME 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-2009, 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 3, 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Ada
.Text_IO
.Generic_Aux
; use Ada
.Text_IO
.Generic_Aux
;
33 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
35 -- Note: this package does not yet deal properly with wide characters ???
37 package body Ada
.Text_IO
.Enumeration_Aux
is
43 procedure Get_Enum_Lit
55 C
:= Character'Val (ch
);
57 -- Character literal case. If the initial character is a quote, then
58 -- we read as far as we can without backup (see ACVC test CE3905L)
61 Store_Char
(File
, ch
, Buf
, Buflen
);
65 if ch
in 16#
20#
.. 16#
7E#
or else ch
>= 16#
80#
then
66 Store_Char
(File
, ch
, Buf
, Buflen
);
70 if ch
= Character'Pos (''') then
71 Store_Char
(File
, ch
, Buf
, Buflen
);
80 -- Similarly for identifiers, read as far as we can, in particular,
81 -- do read a trailing underscore (again see ACVC test CE3905L to
82 -- understand why we do this, although it seems somewhat peculiar).
85 -- Identifier must start with a letter
87 if not Is_Letter
(C
) then
92 -- If we do have a letter, loop through the characters quitting on
93 -- the first non-identifier character (note that this includes the
94 -- cases of hitting a line mark or page mark).
97 C
:= Character'Val (ch
);
98 Store_Char
(File
, Character'Pos (To_Upper
(C
)), Buf
, Buflen
);
101 exit when ch
= EOF_Char
;
102 C
:= Character'Val (ch
);
104 exit when not Is_Letter
(C
)
105 and then not Is_Digit
(C
)
109 and then Buf
(Buflen
) = '_';
126 Actual_Width
: constant Count
:= Count
'Max (Count
(Width
), Item
'Length);
129 if Set
= Lower_Case
and then Item
(Item
'First) /= ''' then
131 Iteml
: String (Item
'First .. Item
'Last);
134 for J
in Item
'Range loop
135 Iteml
(J
) := To_Lower
(Item
(J
));
138 Put_Item
(File
, Iteml
);
142 Put_Item
(File
, Item
);
145 for J
in 1 .. Actual_Width
- Item
'Length loop
162 if Item
'Length > To
'Length then
167 for J
in Item
'Range loop
168 if Set
= Lower_Case
and then Item
(Item
'First) /= ''' then
169 To
(Ptr
) := To_Lower
(Item
(J
));
171 To
(Ptr
) := Item
(J
);
177 while Ptr
<= To
'Last loop
188 procedure Scan_Enum_Lit
195 -- Processing for Scan_Enum_Lit
198 String_Skip
(From
, Start
);
200 -- Character literal case. If the initial character is a quote, then
201 -- we read as far as we can without backup (see ACVC test CE3905L
202 -- which is for the analogous case for reading from a file).
204 if From
(Start
) = ''' then
207 if Stop
= From
'Last then
213 if From
(Stop
) in ' ' .. '~'
214 or else From
(Stop
) >= Character'Val (16#
80#
)
216 if Stop
= From
'Last then
221 if From
(Stop
) = ''' then
229 -- Similarly for identifiers, read as far as we can, in particular,
230 -- do read a trailing underscore (again see ACVC test CE3905L to
231 -- understand why we do this, although it seems somewhat peculiar).
234 -- Identifier must start with a letter
236 if not Is_Letter
(From
(Start
)) then
240 -- If we do have a letter, loop through the characters quitting on
241 -- the first non-identifier character (note that this includes the
242 -- cases of hitting a line mark or page mark).
245 while Stop
< From
'Last loop
246 C
:= From
(Stop
+ 1);
248 exit when not Is_Letter
(C
)
249 and then not Is_Digit
(C
)
253 and then From
(Stop
) = '_';
260 end Ada
.Text_IO
.Enumeration_Aux
;