Add hppa-openbsd target
[official-gcc.git] / gcc / ada / a-textio.ads
blob4f9469a8ffef95a935df03631f155cdbc2517e0d
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . T E X T _ I O --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- Copyright (C) 1992-2000 Free Software Foundation, Inc. --
11 -- --
12 -- This specification is derived from the Ada Reference Manual for use with --
13 -- GNAT. The copyright notice above, and the license provisions that follow --
14 -- apply solely to the contents of the part following the private keyword. --
15 -- --
16 -- GNAT is free software; you can redistribute it and/or modify it under --
17 -- terms of the GNU General Public License as published by the Free Soft- --
18 -- ware Foundation; either version 2, or (at your option) any later ver- --
19 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
20 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
21 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
22 -- for more details. You should have received a copy of the GNU General --
23 -- Public License distributed with GNAT; see file COPYING. If not, write --
24 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
25 -- MA 02111-1307, USA. --
26 -- --
27 -- As a special exception, if other files instantiate generics from this --
28 -- unit, or you link this unit with other files to produce an executable, --
29 -- this unit does not by itself cause the resulting executable to be --
30 -- covered by the GNU General Public License. This exception does not --
31 -- however invalidate any other reasons why the executable file might be --
32 -- covered by the GNU Public License. --
33 -- --
34 -- GNAT was originally developed by the GNAT team at New York University. --
35 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
36 -- --
37 ------------------------------------------------------------------------------
39 -- Note: the generic subpackages of Text_IO (Integer_IO, Float_IO, Fixed_IO,
40 -- Modular_IO, Decimal_IO and Enumeration_IO) appear as private children in
41 -- GNAT. These children are with'ed automatically if they are referenced, so
42 -- this rearrangement is invisible to user programs, but has the advantage
43 -- that only the needed parts of Text_IO are processed and loaded.
45 with Ada.IO_Exceptions;
46 with Ada.Streams;
47 with System;
48 with System.File_Control_Block;
50 package Ada.Text_IO is
51 pragma Elaborate_Body (Text_IO);
53 type File_Type is limited private;
54 type File_Mode is (In_File, Out_File, Append_File);
56 -- The following representation clause allows the use of unchecked
57 -- conversion for rapid translation between the File_Mode type
58 -- used in this package and System.File_IO.
60 for File_Mode use
61 (In_File => 0, -- System.FIle_IO.File_Mode'Pos (In_File)
62 Out_File => 2, -- System.File_IO.File_Mode'Pos (Out_File)
63 Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
65 type Count is range 0 .. Natural'Last;
66 -- The value of Count'Last must be large enough so that the assumption
67 -- enough so that the assumption that the Line, Column and Page
68 -- counts can never exceed this value is a valid assumption.
70 subtype Positive_Count is Count range 1 .. Count'Last;
72 Unbounded : constant Count := 0;
73 -- Line and page length
75 subtype Field is Integer range 0 .. 255;
76 -- Note: if for any reason, there is a need to increase this value,
77 -- then it will be necessary to change the corresponding value in
78 -- System.Img_Real in file s-imgrea.adb.
80 subtype Number_Base is Integer range 2 .. 16;
82 type Type_Set is (Lower_Case, Upper_Case);
84 ---------------------
85 -- File Management --
86 ---------------------
88 procedure Create
89 (File : in out File_Type;
90 Mode : in File_Mode := Out_File;
91 Name : in String := "";
92 Form : in String := "");
94 procedure Open
95 (File : in out File_Type;
96 Mode : in File_Mode;
97 Name : in String;
98 Form : in String := "");
100 procedure Close (File : in out File_Type);
101 procedure Delete (File : in out File_Type);
102 procedure Reset (File : in out File_Type; Mode : in File_Mode);
103 procedure Reset (File : in out File_Type);
105 function Mode (File : in File_Type) return File_Mode;
106 function Name (File : in File_Type) return String;
107 function Form (File : in File_Type) return String;
109 function Is_Open (File : in File_Type) return Boolean;
111 ------------------------------------------------------
112 -- Control of default input, output and error files --
113 ------------------------------------------------------
115 procedure Set_Input (File : in File_Type);
116 procedure Set_Output (File : in File_Type);
117 procedure Set_Error (File : in File_Type);
119 function Standard_Input return File_Type;
120 function Standard_Output return File_Type;
121 function Standard_Error return File_Type;
123 function Current_Input return File_Type;
124 function Current_Output return File_Type;
125 function Current_Error return File_Type;
127 type File_Access is access constant File_Type;
129 function Standard_Input return File_Access;
130 function Standard_Output return File_Access;
131 function Standard_Error return File_Access;
133 function Current_Input return File_Access;
134 function Current_Output return File_Access;
135 function Current_Error return File_Access;
137 --------------------
138 -- Buffer control --
139 --------------------
141 -- Note: The parameter file is IN OUT in the RM, but this is clearly
142 -- an oversight, and was intended to be IN, see AI95-00057.
144 procedure Flush (File : in File_Type);
145 procedure Flush;
147 --------------------------------------------
148 -- Specification of line and page lengths --
149 --------------------------------------------
151 procedure Set_Line_Length (File : in File_Type; To : in Count);
152 procedure Set_Line_Length (To : in Count);
154 procedure Set_Page_Length (File : in File_Type; To : in Count);
155 procedure Set_Page_Length (To : in Count);
157 function Line_Length (File : in File_Type) return Count;
158 function Line_Length return Count;
160 function Page_Length (File : in File_Type) return Count;
161 function Page_Length return Count;
163 ------------------------------------
164 -- Column, Line, and Page Control --
165 ------------------------------------
167 procedure New_Line (File : in File_Type; Spacing : in Positive_Count := 1);
168 procedure New_Line (Spacing : in Positive_Count := 1);
170 procedure Skip_Line (File : in File_Type; Spacing : in Positive_Count := 1);
171 procedure Skip_Line (Spacing : in Positive_Count := 1);
173 function End_Of_Line (File : in File_Type) return Boolean;
174 function End_Of_Line return Boolean;
176 procedure New_Page (File : in File_Type);
177 procedure New_Page;
179 procedure Skip_Page (File : in File_Type);
180 procedure Skip_Page;
182 function End_Of_Page (File : in File_Type) return Boolean;
183 function End_Of_Page return Boolean;
185 function End_Of_File (File : in File_Type) return Boolean;
186 function End_Of_File return Boolean;
188 procedure Set_Col (File : in File_Type; To : in Positive_Count);
189 procedure Set_Col (To : in Positive_Count);
191 procedure Set_Line (File : in File_Type; To : in Positive_Count);
192 procedure Set_Line (To : in Positive_Count);
194 function Col (File : in File_Type) return Positive_Count;
195 function Col return Positive_Count;
197 function Line (File : in File_Type) return Positive_Count;
198 function Line return Positive_Count;
200 function Page (File : in File_Type) return Positive_Count;
201 function Page return Positive_Count;
203 ----------------------------
204 -- Character Input-Output --
205 ----------------------------
207 procedure Get (File : in File_Type; Item : out Character);
208 procedure Get (Item : out Character);
209 procedure Put (File : in File_Type; Item : in Character);
210 procedure Put (Item : in Character);
212 procedure Look_Ahead
213 (File : in File_Type;
214 Item : out Character;
215 End_Of_Line : out Boolean);
217 procedure Look_Ahead
218 (Item : out Character;
219 End_Of_Line : out Boolean);
221 procedure Get_Immediate
222 (File : in File_Type;
223 Item : out Character);
225 procedure Get_Immediate
226 (Item : out Character);
228 procedure Get_Immediate
229 (File : in File_Type;
230 Item : out Character;
231 Available : out Boolean);
233 procedure Get_Immediate
234 (Item : out Character;
235 Available : out Boolean);
237 -------------------------
238 -- String Input-Output --
239 -------------------------
241 procedure Get (File : in File_Type; Item : out String);
242 procedure Get (Item : out String);
243 procedure Put (File : in File_Type; Item : in String);
244 procedure Put (Item : in String);
246 procedure Get_Line
247 (File : in File_Type;
248 Item : out String;
249 Last : out Natural);
251 procedure Get_Line
252 (Item : out String;
253 Last : out Natural);
255 procedure Put_Line
256 (File : in File_Type;
257 Item : in String);
259 procedure Put_Line
260 (Item : in String);
262 ---------------------------------------
263 -- Generic packages for Input-Output --
264 ---------------------------------------
266 -- The generic packages:
268 -- Ada.Text_IO.Integer_IO
269 -- Ada.Text_IO.Modular_IO
270 -- Ada.Text_IO.Float_IO
271 -- Ada.Text_IO.Fixed_IO
272 -- Ada.Text_IO.Decimal_IO
273 -- Ada.Text_IO.Enumeration_IO
275 -- are implemented as separate child packages in GNAT, so the
276 -- spec and body of these packages are to be found in separate
277 -- child units. This implementation detail is hidden from the
278 -- Ada programmer by special circuitry in the compiler that
279 -- treats these child packages as though they were nested in
280 -- Text_IO. The advantage of this special processing is that
281 -- the subsidiary routines needed if these generics are used
282 -- are not loaded when they are not used.
284 ----------------
285 -- Exceptions --
286 ----------------
288 Status_Error : exception renames IO_Exceptions.Status_Error;
289 Mode_Error : exception renames IO_Exceptions.Mode_Error;
290 Name_Error : exception renames IO_Exceptions.Name_Error;
291 Use_Error : exception renames IO_Exceptions.Use_Error;
292 Device_Error : exception renames IO_Exceptions.Device_Error;
293 End_Error : exception renames IO_Exceptions.End_Error;
294 Data_Error : exception renames IO_Exceptions.Data_Error;
295 Layout_Error : exception renames IO_Exceptions.Layout_Error;
297 private
298 -----------------------------------
299 -- Handling of Format Characters --
300 -----------------------------------
302 -- Line marks are represented by the single character ASCII.LF (16#0A#).
303 -- In DOS and similar systems, underlying file translation takes care
304 -- of translating this to and from the standard CR/LF sequences used in
305 -- these operating systems to mark the end of a line. On output there is
306 -- always a line mark at the end of the last line, but on input, this
307 -- line mark can be omitted, and is implied by the end of file.
309 -- Page marks are represented by the single character ASCII.FF (16#0C#),
310 -- The page mark at the end of the file may be omitted, and is normally
311 -- omitted on output unless an explicit New_Page call is made before
312 -- closing the file. No page mark is added when a file is appended to,
313 -- so, in accordance with the permission in (RM A.10.2(4)), there may
314 -- or may not be a page mark separating preexising text in the file
315 -- from the new text to be written.
317 -- A file mark is marked by the physical end of file. In DOS translation
318 -- mode on input, an EOF character (SUB = 16#1A#) gets translated to the
319 -- physical end of file, so in effect this character is recognized as
320 -- marking the end of file in DOS and similar systems.
322 LM : constant := Character'Pos (ASCII.LF);
323 -- Used as line mark
325 PM : constant := Character'Pos (ASCII.FF);
326 -- Used as page mark, except at end of file where it is implied
328 --------------------------------
329 -- Text_IO File Control Block --
330 --------------------------------
332 package FCB renames System.File_Control_Block;
334 type Text_AFCB;
335 type File_Type is access all Text_AFCB;
337 type Text_AFCB is new FCB.AFCB with record
338 Page : Count := 1;
339 Line : Count := 1;
340 Col : Count := 1;
341 Line_Length : Count := 0;
342 Page_Length : Count := 0;
344 Self : aliased File_Type;
345 -- Set to point to the containing Text_AFCB block. This is used to
346 -- implement the Current_{Error,Input,Output} functions which return
347 -- a File_Access, the file access value returned is a pointer to
348 -- the Self field of the corresponding file.
350 Before_LM : Boolean := False;
351 -- This flag is used to deal with the anomolies introduced by the
352 -- peculiar definition of End_Of_File and End_Of_Page in Ada. These
353 -- functions require looking ahead more than one character. Since
354 -- there is no convenient way of backing up more than one character,
355 -- what we do is to leave ourselves positioned past the LM, but set
356 -- this flag, so that we know that from an Ada point of view we are
357 -- in front of the LM, not after it. A bit of a kludge, but it works!
359 Before_LM_PM : Boolean := False;
360 -- This flag similarly handles the case of being physically positioned
361 -- after a LM-PM sequence when logically we are before the LM-PM. This
362 -- flag can only be set if Before_LM is also set.
364 end record;
366 function AFCB_Allocate (Control_Block : Text_AFCB) return FCB.AFCB_Ptr;
368 procedure AFCB_Close (File : access Text_AFCB);
369 procedure AFCB_Free (File : access Text_AFCB);
371 procedure Read
372 (File : in out Text_AFCB;
373 Item : out Ada.Streams.Stream_Element_Array;
374 Last : out Ada.Streams.Stream_Element_Offset);
375 -- Read operation used when Text_IO file is treated directly as Stream
377 procedure Write
378 (File : in out Text_AFCB;
379 Item : in Ada.Streams.Stream_Element_Array);
380 -- Write operation used when Text_IO file is treated directly as Stream
382 ------------------------
383 -- The Standard Files --
384 ------------------------
386 Null_Str : aliased constant String := "";
387 -- Used as name and form of standard files
389 Standard_Err_AFCB : aliased Text_AFCB;
390 Standard_In_AFCB : aliased Text_AFCB;
391 Standard_Out_AFCB : aliased Text_AFCB;
393 Standard_Err : aliased File_Type := Standard_Err_AFCB'Access;
394 Standard_In : aliased File_Type := Standard_In_AFCB'Access;
395 Standard_Out : aliased File_Type := Standard_Out_AFCB'Access;
396 -- Standard files
398 Current_In : aliased File_Type := Standard_In;
399 Current_Out : aliased File_Type := Standard_Out;
400 Current_Err : aliased File_Type := Standard_Err;
401 -- Current files
403 -----------------------
404 -- Local Subprograms --
405 -----------------------
407 -- These subprograms are in the private part of the spec so that they can
408 -- be shared by the routines in the body of Ada.Text_IO.Wide_Text_IO.
410 -- Note: we use Integer in these declarations instead of the more accurate
411 -- Interfaces.C_Streams.int, because we do not want to drag in the spec of
412 -- this interfaces package with the spec of Ada.Text_IO, and we know that
413 -- in fact these types are identical
415 function Getc (File : File_Type) return Integer;
416 -- Gets next character from file, which has already been checked for
417 -- being in read status, and returns the character read if no error
418 -- occurs. The result is EOF if the end of file was read.
420 function Nextc (File : File_Type) return Integer;
421 -- Returns next character from file without skipping past it (i.e. it
422 -- is a combination of Getc followed by an Ungetc).
424 procedure Putc (ch : Integer; File : File_Type);
425 -- Outputs the given character to the file, which has already been
426 -- checked for being in output status. Device_Error is raised if the
427 -- character cannot be written.
429 procedure Terminate_Line (File : File_Type);
430 -- If the file is in Write_File or Append_File mode, and the current
431 -- line is not terminated, then a line terminator is written using
432 -- New_Line. Note that there is no Terminate_Page routine, because
433 -- the page mark at the end of the file is implied if necessary.
435 procedure Ungetc (ch : Integer; File : File_Type);
436 -- Pushes back character into stream, using ungetc. The caller has
437 -- checked that the file is in read status. Device_Error is raised
438 -- if the character cannot be pushed back. An attempt to push back
439 -- and end of file character (EOF) is ignored.
441 end Ada.Text_IO;