1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME COMPONENTS --
5 -- A D A . W I D E _ T E X T _ I O . E N U M E R A T I O N _ A U X --
10 -- Copyright (C) 1992-2002, 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
.Wide_Text_IO
.Generic_Aux
; use Ada
.Wide_Text_IO
.Generic_Aux
;
36 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
37 with Interfaces
.C_Streams
; use Interfaces
.C_Streams
;
38 with System
.WCh_Con
; use System
.WCh_Con
;
40 package body Ada
.Wide_Text_IO
.Enumeration_Aux
is
42 subtype TFT
is Ada
.Wide_Text_IO
.File_Type
;
43 -- File type required for calls to routines in Aux
45 -----------------------
46 -- Local Subprograms --
47 -----------------------
51 Buf
: out Wide_String;
52 Ptr
: in out Integer);
53 -- Store a single character in buffer, checking for overflow.
55 -- These definitions replace the ones in Ada.Characters.Handling, which
56 -- do not seem to work for some strange not understood reason ??? at
57 -- least in the OS/2 version.
59 function To_Lower
(C
: Character) return Character;
65 procedure Get_Enum_Lit
67 Buf
: out Wide_String;
75 Load_Skip
(TFT
(File
));
76 ch
:= Nextc
(TFT
(File
));
78 -- Character literal case. If the initial character is a quote, then
79 -- we read as far as we can without backup (see ACVC test CE3905L)
81 if ch
= Character'Pos (''') then
83 Store_Char
(WC
, Buf
, Buflen
);
85 ch
:= Nextc
(TFT
(File
));
87 if ch
= LM
or else ch
= EOF
then
92 Store_Char
(WC
, Buf
, Buflen
);
94 ch
:= Nextc
(TFT
(File
));
96 if ch
/= Character'Pos (''') then
101 Store_Char
(WC
, Buf
, Buflen
);
103 -- Similarly for identifiers, read as far as we can, in particular,
104 -- do read a trailing underscore (again see ACVC test CE3905L to
105 -- understand why we do this, although it seems somewhat peculiar).
108 -- Identifier must start with a letter. Any wide character value
109 -- outside the normal Latin-1 range counts as a letter for this.
111 if ch
< 255 and then not Is_Letter
(Character'Val (ch
)) then
115 -- If we do have a letter, loop through the characters quitting on
116 -- the first non-identifier character (note that this includes the
117 -- cases of hitting a line mark or page mark).
121 Store_Char
(WC
, Buf
, Buflen
);
123 ch
:= Nextc
(TFT
(File
));
127 if ch
= Character'Pos ('_') then
128 exit when Buf
(Buflen
) = '_';
130 elsif ch
= Character'Pos (ASCII
.ESC
) then
133 elsif File
.WC_Method
in WC_Upper_Half_Encoding_Method
139 exit when Is_Letter
(Character'Val (ch
))
140 and then not Is_Digit
(Character'Val (ch
));
156 Actual_Width
: constant Integer :=
157 Integer'Max (Integer (Width
), Item
'Length);
160 Check_On_One_Line
(TFT
(File
), Actual_Width
);
162 if Set
= Lower_Case
and then Item
(1) /= ''' then
164 Iteml
: Wide_String (Item
'First .. Item
'Last);
167 for J
in Item
'Range loop
168 if Is_Character
(Item
(J
)) then
170 To_Wide_Character
(To_Lower
(To_Character
(Item
(J
))));
172 Iteml
(J
) := Item
(J
);
183 for J
in 1 .. Actual_Width
- Item
'Length loop
193 (To
: out Wide_String;
194 Item
: in Wide_String;
200 if Item
'Length > To
'Length then
205 for J
in Item
'Range loop
207 and then Item
(1) /= '''
208 and then Is_Character
(Item
(J
))
211 To_Wide_Character
(To_Lower
(To_Character
(Item
(J
))));
213 To
(Ptr
) := Item
(J
);
219 while Ptr
<= To
'Last loop
230 procedure Scan_Enum_Lit
237 -- Processing for Scan_Enum_Lit
243 if Start
> From
'Last then
246 elsif Is_Character
(From
(Start
))
247 and then not Is_Blank
(To_Character
(From
(Start
)))
256 -- Character literal case. If the initial character is a quote, then
257 -- we read as far as we can without backup (see ACVC test CE3905L
258 -- which is for the analogous case for reading from a file).
260 if From
(Start
) = ''' then
263 if Stop
= From
'Last then
269 if From
(Stop
) in ' ' .. '~'
270 or else From
(Stop
) >= Wide_Character'Val (16#
80#
)
272 if Stop
= From
'Last then
277 if From
(Stop
) = ''' then
286 -- Similarly for identifiers, read as far as we can, in particular,
287 -- do read a trailing underscore (again see ACVC test CE3905L to
288 -- understand why we do this, although it seems somewhat peculiar).
291 -- Identifier must start with a letter, any wide character outside
292 -- the normal Latin-1 range is considered a letter for this test.
294 if Is_Character
(From
(Start
))
295 and then not Is_Letter
(To_Character
(From
(Start
)))
300 -- If we do have a letter, loop through the characters quitting on
301 -- the first non-identifier character (note that this includes the
302 -- cases of hitting a line mark or page mark).
305 while Stop
< From
'Last loop
306 WC
:= From
(Stop
+ 1);
311 not Is_Letter
(To_Character
(WC
))
313 not Is_Letter
(To_Character
(WC
))
315 (WC
/= '_' or else From
(Stop
- 1) = '_');
328 (WC
: Wide_Character;
329 Buf
: out Wide_String;
330 Ptr
: in out Integer)
333 if Ptr
= Buf
'Last then
345 function To_Lower
(C
: Character) return Character is
347 if C
in 'A' .. 'Z' then
348 return Character'Val (Character'Pos (C
) + 32);
354 end Ada
.Wide_Text_IO
.Enumeration_Aux
;