1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME 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 --
9 -- Copyright (C) 1992-2017, 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
.Wide_Text_IO
.Generic_Aux
; use Ada
.Wide_Text_IO
.Generic_Aux
;
33 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
34 with Interfaces
.C_Streams
; use Interfaces
.C_Streams
;
35 with System
.WCh_Con
; use System
.WCh_Con
;
37 package body Ada
.Wide_Text_IO
.Enumeration_Aux
is
39 subtype TFT
is Ada
.Wide_Text_IO
.File_Type
;
40 -- File type required for calls to routines in Aux
42 -----------------------
43 -- Local Subprograms --
44 -----------------------
48 Buf
: out Wide_String;
49 Ptr
: in out Integer);
50 -- Store a single character in buffer, checking for overflow
52 -- These definitions replace the ones in Ada.Characters.Handling, which
53 -- do not seem to work for some strange not understood reason ??? at
54 -- least in the OS/2 version.
56 function To_Lower
(C
: Character) return Character;
62 procedure Get_Enum_Lit
64 Buf
: out Wide_String;
72 Load_Skip
(TFT
(File
));
73 ch
:= Nextc
(TFT
(File
));
75 -- Character literal case. If the initial character is a quote, then
76 -- we read as far as we can without backup (see ACVC test CE3905L)
78 if ch
= Character'Pos (''') then
80 Store_Char
(WC
, Buf
, Buflen
);
82 ch
:= Nextc
(TFT
(File
));
84 if ch
= LM
or else ch
= EOF
then
89 Store_Char
(WC
, Buf
, Buflen
);
91 ch
:= Nextc
(TFT
(File
));
93 if ch
/= Character'Pos (''') then
98 Store_Char
(WC
, Buf
, Buflen
);
100 -- Similarly for identifiers, read as far as we can, in particular,
101 -- do read a trailing underscore (again see ACVC test CE3905L to
102 -- understand why we do this, although it seems somewhat peculiar).
105 -- Identifier must start with a letter. Any wide character value
106 -- outside the normal Latin-1 range counts as a letter for this.
108 if ch
< 255 and then not Is_Letter
(Character'Val (ch
)) then
112 -- If we do have a letter, loop through the characters quitting on
113 -- the first non-identifier character (note that this includes the
114 -- cases of hitting a line mark or page mark).
118 Store_Char
(WC
, Buf
, Buflen
);
120 ch
:= Nextc
(TFT
(File
));
124 if ch
= Character'Pos ('_') then
125 exit when Buf
(Buflen
) = '_';
127 elsif ch
= Character'Pos (ASCII
.ESC
) then
130 elsif File
.WC_Method
in WC_Upper_Half_Encoding_Method
136 exit when not Is_Letter
(Character'Val (ch
))
138 not Is_Digit
(Character'Val (ch
));
154 Actual_Width
: constant Integer :=
155 Integer'Max (Integer (Width
), Item
'Length);
158 Check_On_One_Line
(TFT
(File
), Actual_Width
);
160 if Set
= Lower_Case
and then Item
(Item
'First) /= ''' then
162 Iteml
: Wide_String (Item
'First .. Item
'Last);
165 for J
in Item
'Range loop
166 if Is_Character
(Item
(J
)) then
168 To_Wide_Character
(To_Lower
(To_Character
(Item
(J
))));
170 Iteml
(J
) := Item
(J
);
181 for J
in 1 .. Actual_Width
- Item
'Length loop
191 (To
: out Wide_String;
198 if Item
'Length > To
'Length then
203 for J
in Item
'Range loop
205 and then Item
(Item
'First) /= '''
206 and then Is_Character
(Item
(J
))
209 To_Wide_Character
(To_Lower
(To_Character
(Item
(J
))));
211 To
(Ptr
) := Item
(J
);
217 while Ptr
<= To
'Last loop
228 procedure Scan_Enum_Lit
235 -- Processing for Scan_Enum_Lit
241 if Start
> From
'Last then
244 elsif Is_Character
(From
(Start
))
245 and then not Is_Blank
(To_Character
(From
(Start
)))
254 -- Character literal case. If the initial character is a quote, then
255 -- we read as far as we can without backup (see ACVC test CE3905L
256 -- which is for the analogous case for reading from a file).
258 if From
(Start
) = ''' then
261 if Stop
= From
'Last then
267 if From
(Stop
) in ' ' .. '~'
268 or else From
(Stop
) >= Wide_Character'Val (16#
80#
)
270 if Stop
= From
'Last then
275 if From
(Stop
) = ''' then
283 -- Similarly for identifiers, read as far as we can, in particular,
284 -- do read a trailing underscore (again see ACVC test CE3905L to
285 -- understand why we do this, although it seems somewhat peculiar).
288 -- Identifier must start with a letter, any wide character outside
289 -- the normal Latin-1 range is considered a letter for this test.
291 if Is_Character
(From
(Start
))
292 and then not Is_Letter
(To_Character
(From
(Start
)))
297 -- If we do have a letter, loop through the characters quitting on
298 -- the first non-identifier character (note that this includes the
299 -- cases of hitting a line mark or page mark).
302 while Stop
< From
'Last loop
303 WC
:= From
(Stop
+ 1);
308 not Is_Letter
(To_Character
(WC
))
310 (WC
/= '_' or else From
(Stop
- 1) = '_');
323 (WC
: Wide_Character;
324 Buf
: out Wide_String;
325 Ptr
: in out Integer)
328 if Ptr
= Buf
'Last then
340 function To_Lower
(C
: Character) return Character is
342 if C
in 'A' .. 'Z' then
343 return Character'Val (Character'Pos (C
) + 32);
349 end Ada
.Wide_Text_IO
.Enumeration_Aux
;