-------------------------------------------------------------------------------- ---- GNAT RUN-TIME COMPONENTS ---- ---- A D A . T E X T _ I O ---- ---- S p e c ---- ---- $Revision: 1.48 $ ---- ---- Copyright (C) 1992-1998 Free Software Foundation, Inc. ---- ---- This specification is derived from the Ada Reference Manual for use with ---- GNAT. The copyright notice above, and the license provisions that follow ---- apply solely to the contents of the part following the private keyword. ---- ---- GNAT is free software; you can redistribute it and/or modify it under ---- terms of the GNU General Public License as published by the Free Soft- ---- ware Foundation; either version 2, or (at your option) any later ver- ---- sion. GNAT is distributed in the hope that it will be useful, but WITH- ---- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ---- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ---- for more details. You should have received a copy of the GNU General ---- Public License distributed with GNAT; see file COPYING. If not, write ---- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, ---- MA 02111-1307, USA. ---- ---- As a special exception, if other files instantiate generics from this ---- unit, or you link this unit with other files to produce an executable, ---- this unit does not by itself cause the resulting executable to be ---- covered by the GNU General Public License. This exception does not ---- however invalidate any other reasons why the executable file might be ---- covered by the GNU Public License. ---- ---- GNAT was originally developed by the GNAT team at New York University. ---- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). ---- ---------------------------------------------------------------------------------- Note: the generic subpackages of Text_IO (Integer_IO, Float_IO, Fixed_IO,-- Modular_IO, Decimal_IO and Enumeration_IO) appear as private children in-- GNAT. These children are with'ed automatically if they are referenced, so-- this rearrangement is invisible to user programs, but has the advantage-- that only the needed parts of Text_IO are processed and loaded.withAda.IO_Exceptions;
withAda.Streams;
withSystem;
withSystem.File_Control_Block;
packageAda.Text_IOispragma Elaborate_Body (Text_IO);
typeFile_Typeislimitedprivate;
typeFile_Modeis (In_File, Out_File, Append_File);
-- The following representation clause allows the use of unchecked-- conversion for rapid translation between the File_Mode type-- used in this package and System.File_IO.forFile_Modeuse
(In_File => 0, -- System.FIle_IO.File_Mode'Pos (In_File)Out_File => 2, -- System.File_IO.File_Mode'Pos (Out_File)Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)typeCountisrange 0 .. Natural'Last;
-- The value of Count'Last must be large enough so that the assumption-- enough so that the assumption that the Line, Column and Page-- counts can never exceed this value is a valid assumption.subtypePositive_CountisCountrange 1 .. Count'Last;
Unbounded : constantCount := 0;
-- Line and page lengthsubtypeFieldis Integer range 0 .. 255;
-- Note: if for any reason, there is a need to increase this value,-- then it will be necessary to change the corresponding value in-- System.Img_Real in file s-imgrea.adb.subtypeNumber_Baseis Integer range 2 .. 16;
typeType_Setis (Lower_Case, Upper_Case);
----------------------- File Management -----------------------procedureCreate
(File : inoutFile_Type;
Mode : inFile_Mode := Out_File;
Name : in String := "";
Form : in String := "");
procedureOpen
(File : inoutFile_Type;
Mode : inFile_Mode;
Name : in String;
Form : in String := "");
procedureClose (File : inoutFile_Type);
procedureDelete (File : inoutFile_Type);
procedureReset (File : inoutFile_Type; Mode : inFile_Mode);
procedureReset (File : inoutFile_Type);
functionMode (File : inFile_Type) returnFile_Mode;
functionName (File : inFile_Type) return String;
functionForm (File : inFile_Type) return String;
functionIs_Open (File : inFile_Type) return Boolean;
-------------------------------------------------------- Control of default input, output and error files --------------------------------------------------------procedureSet_Input (File : inFile_Type);
procedureSet_Output (File : inFile_Type);
procedureSet_Error (File : inFile_Type);
functionStandard_InputreturnFile_Type;
functionStandard_OutputreturnFile_Type;
functionStandard_ErrorreturnFile_Type;
functionCurrent_InputreturnFile_Type;
functionCurrent_OutputreturnFile_Type;
functionCurrent_ErrorreturnFile_Type;
typeFile_AccessisaccessconstantFile_Type;
functionStandard_InputreturnFile_Access;
functionStandard_OutputreturnFile_Access;
functionStandard_ErrorreturnFile_Access;
functionCurrent_InputreturnFile_Access;
functionCurrent_OutputreturnFile_Access;
functionCurrent_ErrorreturnFile_Access;
---------------------- Buffer control ------------------------ Note: The parameter file is IN OUT in the RM, but this is clearly-- an oversight, and was intended to be IN, see AI95-00057.procedureFlush (File : inFile_Type);
procedureFlush;
---------------------------------------------- Specification of line and page lengths ----------------------------------------------procedureSet_Line_Length (File : inFile_Type; To : inCount);
procedureSet_Line_Length (To : inCount);
procedureSet_Page_Length (File : inFile_Type; To : inCount);
procedureSet_Page_Length (To : inCount);
functionLine_Length (File : inFile_Type) returnCount;
functionLine_LengthreturnCount;
functionPage_Length (File : inFile_Type) returnCount;
functionPage_LengthreturnCount;
-------------------------------------- Column, Line, and Page Control --------------------------------------procedureNew_Line (File : inFile_Type; Spacing : inPositive_Count := 1);
procedureNew_Line (Spacing : inPositive_Count := 1);
procedureSkip_Line (File : inFile_Type; Spacing : inPositive_Count := 1);
procedureSkip_Line (Spacing : inPositive_Count := 1);
functionEnd_Of_Line (File : inFile_Type) return Boolean;
functionEnd_Of_Linereturn Boolean;
procedureNew_Page (File : inFile_Type);
procedureNew_Page;
procedureSkip_Page (File : inFile_Type);
procedureSkip_Page;
functionEnd_Of_Page (File : inFile_Type) return Boolean;
functionEnd_Of_Pagereturn Boolean;
functionEnd_Of_File (File : inFile_Type) return Boolean;
functionEnd_Of_Filereturn Boolean;
procedureSet_Col (File : inFile_Type; To : inPositive_Count);
procedureSet_Col (To : inPositive_Count);
procedureSet_Line (File : inFile_Type; To : inPositive_Count);
procedureSet_Line (To : inPositive_Count);
functionCol (File : inFile_Type) returnPositive_Count;
functionColreturnPositive_Count;
functionLine (File : inFile_Type) returnPositive_Count;
functionLinereturnPositive_Count;
functionPage (File : inFile_Type) returnPositive_Count;
functionPagereturnPositive_Count;
------------------------------- Characters Input-Output -------------------------------procedureGet (File : inFile_Type; Item : out Character);
procedureGet (Item : out Character);
procedurePut (File : inFile_Type; Item : in Character);
procedurePut (Item : in Character);
procedureLook_Ahead
(File : inFile_Type;
Item : out Character;
End_Of_Line : out Boolean);
procedureLook_Ahead
(Item : out Character;
End_Of_Line : out Boolean);
procedureGet_Immediate
(File : inFile_Type;
Item : out Character);
procedureGet_Immediate
(Item : out Character);
procedureGet_Immediate
(File : inFile_Type;
Item : out Character;
Available : out Boolean);
procedureGet_Immediate
(Item : out Character;
Available : out Boolean);
---------------------------- Strings Input-Output ----------------------------procedureGet (File : inFile_Type; Item : out String);
procedureGet (Item : out String);
procedurePut (File : inFile_Type; Item : in String);
procedurePut (Item : in String);
procedureGet_Line
(File : inFile_Type;
Item : out String;
Last : out Natural);
procedureGet_Line
(Item : out String;
Last : out Natural);
procedurePut_Line
(File : inFile_Type;
Item : in String);
procedurePut_Line
(Item : in String);
-- ExceptionsStatus_Error : exceptionrenamesIO_Exceptions.Status_Error;
Mode_Error : exceptionrenamesIO_Exceptions.Mode_Error;
Name_Error : exceptionrenamesIO_Exceptions.Name_Error;
Use_Error : exceptionrenamesIO_Exceptions.Use_Error;
Device_Error : exceptionrenamesIO_Exceptions.Device_Error;
End_Error : exceptionrenamesIO_Exceptions.End_Error;
Data_Error : exceptionrenamesIO_Exceptions.Data_Error;
Layout_Error : exceptionrenamesIO_Exceptions.Layout_Error;
private------------------------------------- Handling of Format Characters --------------------------------------- Line marks are represented by the single character Ascii.LF (16#0A#).-- In DOS and similar systems, underlying file translation takes care-- of translating this to and from the standard CR/LF sequences used in-- these operating systems to mark the end of a line. On output there is-- always a line mark at the end of the last line, but on input, this-- line mark can be omitted, and is implied by the end of file.-- Page marks are represented by the single character Ascii.FF (16#0C#),-- The page mark at the end of the file may be omitted, and is normally-- omitted on output unless an explicit New_Page call is made before-- closing the file. No page mark is added when a file is appended to,-- so, in accordance with the permission in (RM A.10.2(4)), there may-- or may not be a page mark separating preexising text in the file-- from the new text to be written.-- A file mark is marked by the physical end of file. In DOS translation-- mode on input, an EOF character (SUB = 16#1A#) gets translated to the-- physical end of file, so in effect this character is recognized as-- marking the end of file in DOS and similar systems.LM : constant := Character'Pos (Ascii.LF);
-- Used as line markPM : constant := Character'Pos (Ascii.FF);
-- Used as page mark, except at end of file where it is implied---------------------------------- Text_IO File Control Block ----------------------------------packageFCBrenamesSystem.File_Control_Block;
typeText_AFCB;
typeFile_TypeisaccessallText_AFCB;
typeText_AFCBisnewFCB.AFCBwithrecord
Page : Count := 1;
Line : Count := 1;
Col : Count := 1;
Line_Length : Count := 0;
Page_Length : Count := 0;
Self : aliasedFile_Type;
-- Set to point to the containing Text_AFCB block. This is used to-- implement the Current_{Error,Input,Ouput} functions which return-- a File_Access, the file access value returned is a pointer to-- the Self field of the corresponding file.
Before_LM : Boolean := False;
-- This flag is used to deal with the anomolies introduced by the-- peculiar definition of End_Of_File and End_Of_Page in Ada. These-- functions require looking ahead more than one character. Since-- there is no convenient way of backing up more than one character,-- what we do is to leave ourselves positioned past the LM, but set-- this flag, so that we know that from an Ada point of view we are-- in front of the LM, not after it. A bit of a kludge, but it works!
Before_LM_PM : Boolean := False;
-- This flag similarly handles the case of being physically positioned-- after a LM-PM sequence when logically we are before the LM-PM. This-- flag can only be set if Before_LM is also set.endrecord;
functionAFCB_Allocate (Control_Block : Text_AFCB) returnFCB.AFCB_Ptr;
procedureAFCB_Close (File : accessText_AFCB);
procedureAFCB_Free (File : accessText_AFCB);
procedureRead
(File : inoutText_AFCB;
Item : outAda.Streams.Stream_Element_Array;
Last : outAda.Streams.Stream_Element_Offset);
-- Read operation used when Text_IO file is treated directly as StreamprocedureWrite
(File : inoutText_AFCB;
Item : inAda.Streams.Stream_Element_Array);
-- Write operation used when Text_IO file is treated directly as Stream-------------------------- The Standard Files --------------------------
Null_Str : aliasedconstant String := "";
-- Used as name and form of standard files
Standard_Err_AFCB : aliasedText_AFCB;
Standard_In_AFCB : aliasedText_AFCB;
Standard_Out_AFCB : aliasedText_AFCB;
Standard_Err : aliasedFile_Type := Standard_Err_AFCB'Access;
Standard_In : aliasedFile_Type := Standard_In_AFCB'Access;
Standard_Out : aliasedFile_Type := Standard_Out_AFCB'Access;
-- Standard filesCurrent_In : aliasedFile_Type := Standard_In;
Current_Out : aliasedFile_Type := Standard_Out;
Current_Err : aliasedFile_Type := Standard_Err;
-- Current files------------------------- Local Subprograms --------------------------- These subprograms are in the private part of the spec so that they can-- be shared by the routines in the body of Ada.Text_IO.Wide_Text_IO.-- Note: we use Integer in these declarations instead of the more accurate-- Interfaces.C_Streams.int, because we do not want to drag in the spec of-- this interfaces package with the spec of Ada.Text_IO, and we know that-- in fact these types are identicalfunctionGetc (File : File_Type) return Integer;
-- Gets next character from file, which has already been checked for-- being in read status, and returns the character read if no error-- occurs. The result is EOF if the end of file was read.functionNextc (File : File_Type) return Integer;
-- Returns next character from file without skipping past it (i.e. it-- is a combination of Getc followed by an Ungetc).procedurePutc (ch : Integer; File : File_Type);
-- Outputs the given character to the file, which has already been-- checked for being in output status. Device_Error is raised if the-- character cannot be written.procedureTerminate_Line (File : File_Type);
-- If the file is in Write_File or Append_File mode, and the current-- line is not terminated, then a line terminator is written using-- New_Line. Note that there is no Terminate_Page routine, because-- the page mark at the end of the file is implied if necessary.procedureUngetc (ch : Integer; File : File_Type);
-- Pushes back character into stream, using ungetc. The caller has-- checked that the file is in read status. Device_Error is raised-- if the character cannot be pushed back. An attempt to push back-- and end of file character (EOF) is ignored.end Ada.Text_IO;