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-2024, 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 -----------------------
40 -- Local Subprograms --
41 -----------------------
45 Buf
: out Wide_String;
46 Ptr
: in out Integer);
47 -- Store a single character in buffer, checking for overflow
49 -- These definitions replace the ones in Ada.Characters.Handling, which
50 -- do not seem to work for some strange not understood reason ??? at
51 -- least in the OS/2 version.
53 function To_Lower
(C
: Character) return Character;
59 procedure Get_Enum_Lit
61 Buf
: out Wide_String;
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)
75 if ch
= Character'Pos (''') then
77 Store_Char
(WC
, Buf
, Buflen
);
81 if ch
= LM
or else ch
= EOF
then
86 Store_Char
(WC
, Buf
, Buflen
);
90 if ch
/= Character'Pos (''') then
95 Store_Char
(WC
, Buf
, Buflen
);
97 -- Similarly for identifiers, read as far as we can, in particular,
98 -- do read a trailing underscore (again see ACVC test CE3905L to
99 -- understand why we do this, although it seems somewhat peculiar).
102 -- Identifier must start with a letter. Any wide character value
103 -- outside the normal Latin-1 range counts as a letter for this.
105 if ch
< 255 and then not Is_Letter
(Character'Val (ch
)) then
109 -- If we do have a letter, loop through the characters quitting on
110 -- the first non-identifier character (note that this includes the
111 -- cases of hitting a line mark or page mark).
115 Store_Char
(WC
, Buf
, Buflen
);
121 if ch
= Character'Pos ('_') then
122 exit when Buf
(Buflen
) = '_';
124 elsif ch
= Character'Pos (ASCII
.ESC
) then
127 elsif File
.WC_Method
in WC_Upper_Half_Encoding_Method
133 exit when not Is_Letter
(Character'Val (ch
))
135 not Is_Digit
(Character'Val (ch
));
151 Actual_Width
: constant Integer :=
152 Integer'Max (Integer (Width
), Item
'Length);
155 Check_On_One_Line
(File
, Actual_Width
);
157 if Set
= Lower_Case
and then Item
(Item
'First) /= ''' then
159 Iteml
: Wide_String (Item
'First .. Item
'Last);
162 for J
in Item
'Range loop
163 if Is_Character
(Item
(J
)) then
165 To_Wide_Character
(To_Lower
(To_Character
(Item
(J
))));
167 Iteml
(J
) := Item
(J
);
178 for J
in 1 .. Actual_Width
- Item
'Length loop
188 (To
: out Wide_String;
195 if Item
'Length > To
'Length then
200 for J
in Item
'Range loop
202 and then Item
(Item
'First) /= '''
203 and then Is_Character
(Item
(J
))
206 To_Wide_Character
(To_Lower
(To_Character
(Item
(J
))));
208 To
(Ptr
) := Item
(J
);
214 while Ptr
<= To
'Last loop
225 procedure Scan_Enum_Lit
232 -- Processing for Scan_Enum_Lit
238 if Start
> From
'Last then
241 elsif Is_Character
(From
(Start
))
242 and then not Is_Blank
(To_Character
(From
(Start
)))
251 -- Character literal case. If the initial character is a quote, then
252 -- we read as far as we can without backup (see ACVC test CE3905L
253 -- which is for the analogous case for reading from a file).
255 if From
(Start
) = ''' then
258 if Stop
= From
'Last then
264 if From
(Stop
) in ' ' .. '~'
265 or else From
(Stop
) >= Wide_Character'Val (16#
80#
)
267 if Stop
= From
'Last then
272 if From
(Stop
) = ''' then
280 -- Similarly for identifiers, read as far as we can, in particular,
281 -- do read a trailing underscore (again see ACVC test CE3905L to
282 -- understand why we do this, although it seems somewhat peculiar).
285 -- Identifier must start with a letter, any wide character outside
286 -- the normal Latin-1 range is considered a letter for this test.
288 if Is_Character
(From
(Start
))
289 and then not Is_Letter
(To_Character
(From
(Start
)))
294 -- If we do have a letter, loop through the characters quitting on
295 -- the first non-identifier character (note that this includes the
296 -- cases of hitting a line mark or page mark).
299 while Stop
< From
'Last loop
300 WC
:= From
(Stop
+ 1);
305 not Is_Letter
(To_Character
(WC
))
307 (WC
/= '_' or else From
(Stop
- 1) = '_');
320 (WC
: Wide_Character;
321 Buf
: out Wide_String;
322 Ptr
: in out Integer)
325 if Ptr
= Buf
'Last then
337 function To_Lower
(C
: Character) return Character is
339 if C
in 'A' .. 'Z' then
340 return Character'Val (Character'Pos (C
) + 32);
346 end Ada
.Wide_Text_IO
.Enumeration_Aux
;