1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME COMPONENTS --
5 -- A D A . 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.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 Getc (File : File_Type) return int is
101 ch := fgetc (File.Stream);
103 if ch = EOF and then ferror (File.Stream) /= 0 then
114 function Is_Blank (C : Character) return Boolean is
116 return C = ' ' or else C = ASCII.HT;
126 Ptr : in out Integer;
128 Loaded : out Boolean)
135 if ch = Character'Pos (Char) then
136 Store_Char (File, ch, Buf, Ptr);
147 Ptr : in out Integer;
155 if ch = Character'Pos (Char) then
156 Store_Char (File, ch, Buf, Ptr);
165 Ptr : in out Integer;
168 Loaded : out Boolean)
175 if ch = Character'Pos (Char1) or else ch = Character'Pos (Char2) then
176 Store_Char (File, ch, Buf, Ptr);
187 Ptr : in out Integer;
196 if ch = Character'Pos (Char1) or else ch = Character'Pos (Char2) then
197 Store_Char (File, ch, Buf, Ptr);
207 procedure Load_Digits
210 Ptr : in out Integer;
211 Loaded : out Boolean)
214 After_Digit : Boolean;
219 if ch not in Character'Pos ('0') .. Character'Pos ('9') then
227 Store_Char (File, ch, Buf, Ptr);
230 if ch in Character'Pos ('0') .. Character'Pos ('9') then
233 elsif ch = Character'Pos ('_') and then After_Digit then
234 After_Digit := False;
245 procedure Load_Digits
248 Ptr : in out Integer)
251 After_Digit : Boolean;
256 if ch in Character'Pos ('0') .. Character'Pos ('9') then
260 Store_Char (File, ch, Buf, Ptr);
263 if ch in Character'Pos ('0') .. Character'Pos ('9') then
266 elsif ch = Character'Pos ('_') and then After_Digit then
267 After_Digit := False;
278 --------------------------
279 -- Load_Extended_Digits --
280 --------------------------
282 procedure Load_Extended_Digits
285 Ptr : in out Integer;
286 Loaded : out Boolean)
289 After_Digit : Boolean := False;
297 if ch in Character'Pos ('0') .. Character'Pos ('9')
299 ch in Character'Pos ('a') .. Character'Pos ('f')
301 ch in Character'Pos ('A') .. Character'Pos ('F')
305 elsif ch = Character'Pos ('_') and then After_Digit then
306 After_Digit := False;
312 Store_Char (File, ch, Buf, Ptr);
317 end Load_Extended_Digits;
319 procedure Load_Extended_Digits
322 Ptr : in out Integer)
327 Load_Extended_Digits (File, Buf, Ptr, Junk);
328 end Load_Extended_Digits;
334 procedure Load_Skip (File : File_Type) is
338 FIO.Check_Read_Status (AP (File));
340 -- Loop till we find a non-blank character (note that as usual in
341 -- Text_IO, blank includes horizontal tab). Note that Get deals with
342 -- the Before_LM and Before_LM_PM flags appropriately.
346 exit when not Is_Blank (C);
349 Ungetc (Character'Pos (C), File);
350 File.Col := File.Col - 1;
361 Ptr : in out Integer)
366 FIO.Check_Read_Status (AP (File));
368 -- If we are immediately before a line mark, then we have no characters.
369 -- This is always a data error, so we may as well raise it right away.
371 if File.Before_LM then
375 for J in 1 .. Width loop
386 Store_Char (File, ch, Buf, Ptr);
396 function Nextc (File : File_Type) return int is
400 ch := fgetc (File.Stream);
403 if ferror (File.Stream) /= 0 then
419 procedure Put_Item (File : File_Type; Str : String) is
421 Check_On_One_Line (File, Str'Length);
433 Ptr : in out Integer)
436 File.Col := File.Col + 1;
438 if Ptr = Buf'Last then
442 Buf (Ptr) := Character'Val (ch);
450 procedure String_Skip (Str : String; Ptr : out Integer) is
455 if Ptr > Str'Last then
458 elsif not Is_Blank (Str (Ptr)) then
471 procedure Ungetc (ch : int; File : File_Type) is
474 if ungetc (ch, File.Stream) = EOF then
480 end Ada.Text_IO.Generic_Aux;