home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / a-textio.ads < prev    next >
Text File  |  2000-07-19  |  17KB  |  419 lines

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