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 --
11 -- Copyright (C) 1992-2000 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 with Interfaces
.C_Streams
; use Interfaces
.C_Streams
;
38 with System
.File_Control_Block
;
40 package body Ada
.Wide_Text_IO
.Generic_Aux
is
42 package FIO
renames System
.File_IO
;
43 package FCB
renames System
.File_Control_Block
;
44 subtype AP
is FCB
.AFCB_Ptr
;
46 ------------------------
47 -- Check_End_Of_Field --
48 ------------------------
50 procedure Check_End_Of_Field
65 for J
in Ptr
.. Stop
loop
66 if not Is_Blank
(Buf
(J
)) then
71 end Check_End_Of_Field
;
73 -----------------------
74 -- Check_On_One_Line --
75 -----------------------
77 procedure Check_On_One_Line
82 FIO
.Check_Write_Status
(AP
(File
));
84 if File
.Line_Length
/= 0 then
85 if Count
(Length
) > File
.Line_Length
then
87 elsif File
.Col
+ Count
(Length
) > File
.Line_Length
+ 1 then
91 end Check_On_One_Line
;
97 function Is_Blank
(C
: Character) return Boolean is
99 return C
= ' ' or else C
= ASCII
.HT
;
109 Ptr
: in out Integer;
111 Loaded
: out Boolean)
116 if File
.Before_Wide_Character
then
123 if ch
= Character'Pos (Char
) then
124 Store_Char
(File
, ch
, Buf
, Ptr
);
136 Ptr
: in out Integer;
142 if File
.Before_Wide_Character
then
148 if ch
= Character'Pos (Char
) then
149 Store_Char
(File
, ch
, Buf
, Ptr
);
159 Ptr
: in out Integer;
162 Loaded
: out Boolean)
167 if File
.Before_Wide_Character
then
174 if ch
= Character'Pos (Char1
)
175 or else ch
= Character'Pos (Char2
)
177 Store_Char
(File
, ch
, Buf
, Ptr
);
189 Ptr
: in out Integer;
196 if File
.Before_Wide_Character
then
202 if ch
= Character'Pos (Char1
)
203 or else ch
= Character'Pos (Char2
)
205 Store_Char
(File
, ch
, Buf
, Ptr
);
216 procedure Load_Digits
219 Ptr
: in out Integer;
220 Loaded
: out Boolean)
223 After_Digit
: Boolean;
226 if File
.Before_Wide_Character
then
233 if ch
not in Character'Pos ('0') .. Character'Pos ('9') then
241 Store_Char
(File
, ch
, Buf
, Ptr
);
244 if ch
in Character'Pos ('0') .. Character'Pos ('9') then
247 elsif ch
= Character'Pos ('_') and then After_Digit
then
248 After_Digit
:= False;
260 procedure Load_Digits
263 Ptr
: in out Integer)
266 After_Digit
: Boolean;
269 if File
.Before_Wide_Character
then
275 if ch
in Character'Pos ('0') .. Character'Pos ('9') then
279 Store_Char
(File
, ch
, Buf
, Ptr
);
282 if ch
in Character'Pos ('0') .. Character'Pos ('9') then
285 elsif ch
= Character'Pos ('_') and then After_Digit
then
286 After_Digit
:= False;
298 --------------------------
299 -- Load_Extended_Digits --
300 --------------------------
302 procedure Load_Extended_Digits
305 Ptr
: in out Integer;
306 Loaded
: out Boolean)
309 After_Digit
: Boolean := False;
312 if File
.Before_Wide_Character
then
322 if ch
in Character'Pos ('0') .. Character'Pos ('9')
324 ch
in Character'Pos ('a') .. Character'Pos ('f')
326 ch
in Character'Pos ('A') .. Character'Pos ('F')
330 elsif ch
= Character'Pos ('_') and then After_Digit
then
331 After_Digit
:= False;
337 Store_Char
(File
, ch
, Buf
, Ptr
);
343 end Load_Extended_Digits
;
345 procedure Load_Extended_Digits
348 Ptr
: in out Integer)
353 Load_Extended_Digits
(File
, Buf
, Ptr
, Junk
);
354 end Load_Extended_Digits
;
360 procedure Load_Skip
(File
: File_Type
) is
364 FIO
.Check_Read_Status
(AP
(File
));
366 -- We need to explicitly test for the case of being before a wide
367 -- character (greater than 16#7F#). Since no such character can
368 -- ever legitimately be a valid numeric character, we can
369 -- immediately signal Data_Error.
371 if File
.Before_Wide_Character
then
375 -- Otherwise loop till we find a non-blank character (note that as
376 -- usual in Wide_Text_IO, blank includes horizontal tab). Note that
377 -- Get_Character deals with Before_LM/Before_LM_PM flags appropriately.
380 Get_Character
(File
, C
);
381 exit when not Is_Blank
(C
);
384 Ungetc
(Character'Pos (C
), File
);
385 File
.Col
:= File
.Col
- 1;
396 Ptr
: in out Integer)
401 Bad_Wide_C
: Boolean := False;
402 -- Set True if one of the characters read is not in range of type
403 -- Character. This is always a Data_Error, but we do not signal it
404 -- right away, since we have to read the full number of characters.
407 FIO
.Check_Read_Status
(AP
(File
));
409 -- If we are immediately before a line mark, then we have no characters.
410 -- This is always a data error, so we may as well raise it right away.
412 if File
.Before_LM
then
416 for J
in 1 .. Width
loop
417 if File
.Before_Wide_Character
then
419 Store_Char
(File
, 0, Buf
, Ptr
);
420 File
.Before_Wide_Character
:= False;
433 WC
:= Get_Wide_Char
(Character'Val (ch
), File
);
434 ch
:= Wide_Character'Pos (WC
);
441 Store_Char
(File
, ch
, Buf
, Ptr
);
456 procedure Put_Item
(File
: File_Type
; Str
: String) is
458 Check_On_One_Line
(File
, Str
'Length);
460 for J
in Str
'Range loop
461 Put
(File
, Wide_Character'Val (Character'Pos (Str
(J
))));
473 Ptr
: in out Integer)
476 File
.Col
:= File
.Col
+ 1;
478 if Ptr
= Buf
'Last then
482 Buf
(Ptr
) := Character'Val (ch
);
490 procedure String_Skip
(Str
: String; Ptr
: out Integer) is
495 if Ptr
> Str
'Last then
498 elsif not Is_Blank
(Str
(Ptr
)) then
511 procedure Ungetc
(ch
: int
; File
: File_Type
) is
514 if ungetc
(ch
, File
.Stream
) = EOF
then
520 end Ada
.Wide_Text_IO
.Generic_Aux
;