1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME COMPONENTS --
5 -- A D A . W I D E _ T E X T _ I O . G E N E R I C _ 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 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 ------------------------------------------------------------------------------
35 with Interfaces
.C_Streams
; use Interfaces
.C_Streams
;
37 with System
.File_Control_Block
;
39 package body Ada
.Wide_Text_IO
.Generic_Aux
is
41 package FIO
renames System
.File_IO
;
42 package FCB
renames System
.File_Control_Block
;
43 subtype AP
is FCB
.AFCB_Ptr
;
45 ------------------------
46 -- Check_End_Of_Field --
47 ------------------------
49 procedure Check_End_Of_Field
63 for J
in Ptr
.. Stop
loop
64 if not Is_Blank
(Buf
(J
)) then
69 end Check_End_Of_Field
;
71 -----------------------
72 -- Check_On_One_Line --
73 -----------------------
75 procedure Check_On_One_Line
80 FIO
.Check_Write_Status
(AP
(File
));
82 if File
.Line_Length
/= 0 then
83 if Count
(Length
) > File
.Line_Length
then
85 elsif File
.Col
+ Count
(Length
) > File
.Line_Length
+ 1 then
89 end Check_On_One_Line
;
95 function Is_Blank
(C
: Character) return Boolean is
97 return C
= ' ' or else C
= ASCII
.HT
;
107 Ptr
: in out Integer;
109 Loaded
: out Boolean)
114 if File
.Before_Wide_Character
then
121 if ch
= Character'Pos (Char
) then
122 Store_Char
(File
, ch
, Buf
, Ptr
);
134 Ptr
: in out Integer;
140 if File
.Before_Wide_Character
then
146 if ch
= Character'Pos (Char
) then
147 Store_Char
(File
, ch
, Buf
, Ptr
);
157 Ptr
: in out Integer;
160 Loaded
: out Boolean)
165 if File
.Before_Wide_Character
then
172 if ch
= Character'Pos (Char1
)
173 or else ch
= Character'Pos (Char2
)
175 Store_Char
(File
, ch
, Buf
, Ptr
);
187 Ptr
: in out Integer;
194 if File
.Before_Wide_Character
then
200 if ch
= Character'Pos (Char1
)
201 or else ch
= Character'Pos (Char2
)
203 Store_Char
(File
, ch
, Buf
, Ptr
);
214 procedure Load_Digits
217 Ptr
: in out Integer;
218 Loaded
: out Boolean)
221 After_Digit
: Boolean;
224 if File
.Before_Wide_Character
then
231 if ch
not in Character'Pos ('0') .. Character'Pos ('9') then
239 Store_Char
(File
, ch
, Buf
, Ptr
);
242 if ch
in Character'Pos ('0') .. Character'Pos ('9') then
245 elsif ch
= Character'Pos ('_') and then After_Digit
then
246 After_Digit
:= False;
258 procedure Load_Digits
261 Ptr
: in out Integer)
264 After_Digit
: Boolean;
267 if File
.Before_Wide_Character
then
273 if ch
in Character'Pos ('0') .. Character'Pos ('9') then
277 Store_Char
(File
, ch
, Buf
, Ptr
);
280 if ch
in Character'Pos ('0') .. Character'Pos ('9') then
283 elsif ch
= Character'Pos ('_') and then After_Digit
then
284 After_Digit
:= False;
296 --------------------------
297 -- Load_Extended_Digits --
298 --------------------------
300 procedure Load_Extended_Digits
303 Ptr
: in out Integer;
304 Loaded
: out Boolean)
307 After_Digit
: Boolean := False;
310 if File
.Before_Wide_Character
then
320 if ch
in Character'Pos ('0') .. Character'Pos ('9')
322 ch
in Character'Pos ('a') .. Character'Pos ('f')
324 ch
in Character'Pos ('A') .. Character'Pos ('F')
328 elsif ch
= Character'Pos ('_') and then After_Digit
then
329 After_Digit
:= False;
335 Store_Char
(File
, ch
, Buf
, Ptr
);
341 end Load_Extended_Digits
;
343 procedure Load_Extended_Digits
346 Ptr
: in out Integer)
351 Load_Extended_Digits
(File
, Buf
, Ptr
, Junk
);
352 end Load_Extended_Digits
;
358 procedure Load_Skip
(File
: File_Type
) is
362 FIO
.Check_Read_Status
(AP
(File
));
364 -- We need to explicitly test for the case of being before a wide
365 -- character (greater than 16#7F#). Since no such character can
366 -- ever legitimately be a valid numeric character, we can
367 -- immediately signal Data_Error.
369 if File
.Before_Wide_Character
then
373 -- Otherwise loop till we find a non-blank character (note that as
374 -- usual in Wide_Text_IO, blank includes horizontal tab). Note that
375 -- Get_Character deals with Before_LM/Before_LM_PM flags appropriately.
378 Get_Character
(File
, C
);
379 exit when not Is_Blank
(C
);
382 Ungetc
(Character'Pos (C
), File
);
383 File
.Col
:= File
.Col
- 1;
394 Ptr
: in out Integer)
399 Bad_Wide_C
: Boolean := False;
400 -- Set True if one of the characters read is not in range of type
401 -- Character. This is always a Data_Error, but we do not signal it
402 -- right away, since we have to read the full number of characters.
405 FIO
.Check_Read_Status
(AP
(File
));
407 -- If we are immediately before a line mark, then we have no characters.
408 -- This is always a data error, so we may as well raise it right away.
410 if File
.Before_LM
then
414 for J
in 1 .. Width
loop
415 if File
.Before_Wide_Character
then
417 Store_Char
(File
, 0, Buf
, Ptr
);
418 File
.Before_Wide_Character
:= False;
431 WC
:= Get_Wide_Char
(Character'Val (ch
), File
);
432 ch
:= Wide_Character'Pos (WC
);
439 Store_Char
(File
, ch
, Buf
, Ptr
);
454 procedure Put_Item
(File
: File_Type
; Str
: String) is
456 Check_On_One_Line
(File
, Str
'Length);
458 for J
in Str
'Range loop
459 Put
(File
, Wide_Character'Val (Character'Pos (Str
(J
))));
471 Ptr
: in out Integer)
474 File
.Col
:= File
.Col
+ 1;
476 if Ptr
= Buf
'Last then
480 Buf
(Ptr
) := Character'Val (ch
);
488 procedure String_Skip
(Str
: String; Ptr
: out Integer) is
493 if Ptr
> Str
'Last then
496 elsif not Is_Blank
(Str
(Ptr
)) then
509 procedure Ungetc
(ch
: int
; File
: File_Type
) is
512 if ungetc
(ch
, File
.Stream
) = EOF
then
518 end Ada
.Wide_Text_IO
.Generic_Aux
;