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-witeio.ads < prev    next >
Text File  |  2000-07-19  |  19KB  |  459 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUN-TIME COMPONENTS                         --
  4. --                                                                          --
  5. --                     A D A . W I D E _ T E X T _ I O                      --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.13 $
  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 Wide_Text_IO (Integer_IO, Float_IO,
  41. --  Fixed_IO, Modular_IO, Decimal_IO and Enumeration_IO) appear as private
  42. --  children in GNAT. These children are with'ed automatically if they are
  43. --  referenced, so this rearrangement is invisible to user programs, but has
  44. --  the advantage that only the needed parts of Wide_Text_IO are processed
  45. --  and loaded.
  46.  
  47. with Ada.IO_Exceptions;
  48. with Ada.Streams;
  49. with System;
  50. with System.File_Control_Block;
  51. with System.WCh_Con;
  52.  
  53. package Ada.Wide_Text_IO is
  54.  
  55.    package WCh_Con renames System.WCh_Con;
  56.  
  57.    type File_Type is limited private;
  58.    type File_Mode is (In_File, Out_File, Append_File);
  59.  
  60.    --  The following representation clause allows the use of unchecked
  61.    --  conversion for rapid translation between the File_Mode type
  62.    --  used in this package and System.File_IO.
  63.  
  64.    for File_Mode use
  65.      (In_File     => 0,  -- System.FIle_IO.File_Mode'Pos (In_File)
  66.       Out_File    => 2,  -- System.File_IO.File_Mode'Pos (Out_File)
  67.       Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
  68.  
  69.    type Count is range 0 .. Natural'Last;
  70.    --  The value of Count'Last must be large enough so that the assumption
  71.    --  enough so that the assumption that the Line, Column and Page
  72.    --  counts can never exceed this value is a valid assumption.
  73.  
  74.    subtype Positive_Count is Count range 1 .. Count'Last;
  75.  
  76.    Unbounded : constant Count := 0;
  77.    --  Line and page length
  78.  
  79.    subtype Field is Integer range 0 .. 255;
  80.    --  Note: if for any reason, there is a need to increase this value,
  81.    --  then it will be necessary to change the corresponding value in
  82.    --  System.Img_Real in file s-imgrea.adb.
  83.  
  84.    subtype Number_Base is Integer range 2 .. 16;
  85.  
  86.    type Type_Set is (Lower_Case, Upper_Case);
  87.  
  88.    ---------------------
  89.    -- File Management --
  90.    ---------------------
  91.  
  92.    procedure Create
  93.      (File : in out File_Type;
  94.       Mode : in File_Mode := Out_File;
  95.       Name : in String := "";
  96.       Form : in String := "");
  97.  
  98.    procedure Open
  99.      (File : in out File_Type;
  100.       Mode : in File_Mode;
  101.       Name : in String;
  102.       Form : in String := "");
  103.  
  104.    procedure Close  (File : in out File_Type);
  105.    procedure Delete (File : in out File_Type);
  106.    procedure Reset  (File : in out File_Type; Mode : in File_Mode);
  107.    procedure Reset  (File : in out File_Type);
  108.  
  109.    function Mode (File : in File_Type) return File_Mode;
  110.    function Name (File : in File_Type) return String;
  111.    function Form (File : in File_Type) return String;
  112.  
  113.    function Is_Open (File : in File_Type) return Boolean;
  114.  
  115.    ------------------------------------------------------
  116.    -- Control of default input, output and error files --
  117.    ------------------------------------------------------
  118.  
  119.    procedure Set_Input  (File : in File_Type);
  120.    procedure Set_Output (File : in File_Type);
  121.    procedure Set_Error  (File : in File_Type);
  122.  
  123.    function Standard_Input  return File_Type;
  124.    function Standard_Output return File_Type;
  125.    function Standard_Error  return File_Type;
  126.  
  127.    function Current_Input  return File_Type;
  128.    function Current_Output return File_Type;
  129.    function Current_Error  return File_Type;
  130.  
  131.    type File_Access is access constant File_Type;
  132.  
  133.    function Standard_Input  return File_Access;
  134.    function Standard_Output return File_Access;
  135.    function Standard_Error  return File_Access;
  136.  
  137.    function Current_Input  return File_Access;
  138.    function Current_Output return File_Access;
  139.    function Current_Error  return File_Access;
  140.  
  141.    --------------------
  142.    -- Buffer control --
  143.    --------------------
  144.  
  145.    --  Note: The paramter file is in out in the RM, but as pointed out
  146.    --  in <<95-5166.a Tucker Taft 95-6-23>> this is clearly an oversight.
  147.  
  148.    procedure Flush (File : in File_Type);
  149.    procedure Flush;
  150.  
  151.    --------------------------------------------
  152.    -- Specification of line and page lengths --
  153.    --------------------------------------------
  154.  
  155.    procedure Set_Line_Length (File : in File_Type; To : in Count);
  156.    procedure Set_Line_Length (To : in Count);
  157.  
  158.    procedure Set_Page_Length (File : in File_Type; To : in Count);
  159.    procedure Set_Page_Length (To : in Count);
  160.  
  161.    function Line_Length (File : in File_Type) return Count;
  162.    function Line_Length return Count;
  163.  
  164.    function Page_Length (File : in File_Type) return Count;
  165.    function Page_Length return Count;
  166.  
  167.    ------------------------------------
  168.    -- Column, Line, and Page Control --
  169.    ------------------------------------
  170.  
  171.    procedure New_Line (File : in File_Type; Spacing : in Positive_Count := 1);
  172.    procedure New_Line (Spacing : in Positive_Count := 1);
  173.  
  174.    procedure Skip_Line (File : in File_Type; Spacing : in Positive_Count := 1);
  175.    procedure Skip_Line (Spacing : in Positive_Count := 1);
  176.  
  177.    function End_Of_Line (File : in File_Type) return Boolean;
  178.    function End_Of_Line return Boolean;
  179.  
  180.    procedure New_Page (File : in File_Type);
  181.    procedure New_Page;
  182.  
  183.    procedure Skip_Page (File : in File_Type);
  184.    procedure Skip_Page;
  185.  
  186.    function End_Of_Page (File : in File_Type) return Boolean;
  187.    function End_Of_Page return Boolean;
  188.  
  189.    function End_Of_File (File : in File_Type) return Boolean;
  190.    function End_Of_File return Boolean;
  191.  
  192.    procedure Set_Col (File : in File_Type;  To : in Positive_Count);
  193.    procedure Set_Col (To : in Positive_Count);
  194.  
  195.    procedure Set_Line (File : in File_Type; To : in Positive_Count);
  196.    procedure Set_Line (To : in Positive_Count);
  197.  
  198.    function Col (File : in File_Type) return Positive_Count;
  199.    function Col return Positive_Count;
  200.  
  201.    function Line (File : in File_Type) return Positive_Count;
  202.    function Line return Positive_Count;
  203.  
  204.    function Page (File : in File_Type) return Positive_Count;
  205.    function Page return Positive_Count;
  206.  
  207.    -----------------------------
  208.    -- Characters Input-Output --
  209.    -----------------------------
  210.  
  211.    procedure Get (File : in File_Type; Item : out Wide_Character);
  212.    procedure Get (Item : out Wide_Character);
  213.    procedure Put (File : in File_Type; Item : in Wide_Character);
  214.    procedure Put (Item : in Wide_Character);
  215.  
  216.    procedure Look_Ahead
  217.      (File        : in File_Type;
  218.       Item        : out Wide_Character;
  219.       End_Of_Line : out Boolean);
  220.  
  221.    procedure Look_Ahead
  222.      (Item        : out Wide_Character;
  223.       End_Of_Line : out Boolean);
  224.  
  225.    procedure Get_Immediate
  226.      (File : in File_Type;
  227.       Item : out Wide_Character);
  228.  
  229.    procedure Get_Immediate
  230.      (Item : out Wide_Character);
  231.  
  232.    procedure Get_Immediate
  233.      (File      : in File_Type;
  234.       Item      : out Wide_Character;
  235.       Available : out Boolean);
  236.  
  237.    procedure Get_Immediate
  238.      (Item      : out Wide_Character;
  239.       Available : out Boolean);
  240.  
  241.    --------------------------
  242.    -- Strings Input-Output --
  243.    --------------------------
  244.  
  245.    procedure Get (File : in File_Type; Item : out Wide_String);
  246.    procedure Get (Item : out Wide_String);
  247.    procedure Put (File : in File_Type; Item : in Wide_String);
  248.    procedure Put (Item : in Wide_String);
  249.  
  250.    procedure Get_Line
  251.      (File : in File_Type;
  252.       Item : out Wide_String;
  253.       Last : out Natural);
  254.  
  255.    procedure Get_Line
  256.      (Item : out Wide_String;
  257.       Last : out Natural);
  258.  
  259.    procedure Put_Line
  260.      (File : in File_Type;
  261.       Item : in Wide_String);
  262.  
  263.    procedure Put_Line
  264.      (Item : in Wide_String);
  265.  
  266.    --  Exceptions
  267.  
  268.    Status_Error : exception renames IO_Exceptions.Status_Error;
  269.    Mode_Error   : exception renames IO_Exceptions.Mode_Error;
  270.    Name_Error   : exception renames IO_Exceptions.Name_Error;
  271.    Use_Error    : exception renames IO_Exceptions.Use_Error;
  272.    Device_Error : exception renames IO_Exceptions.Device_Error;
  273.    End_Error    : exception renames IO_Exceptions.End_Error;
  274.    Data_Error   : exception renames IO_Exceptions.Data_Error;
  275.    Layout_Error : exception renames IO_Exceptions.Layout_Error;
  276.  
  277. private
  278.    -----------------------------------
  279.    -- Handling of Format Characters --
  280.    -----------------------------------
  281.  
  282.    --  Line marks are represented by the single character ASCII.LF (16#0A#).
  283.    --  In DOS and similar systems, underlying file translation takes care
  284.    --  of translating this to and from the standard CR/LF sequences used in
  285.    --  these operating systems to mark the end of a line. On output there is
  286.    --  always a line mark at the end of the last line, but on input, this
  287.    --  line mark can be omitted, and is implied by the end of file.
  288.  
  289.    --  Page marks are represented by the single character ASCII.FF (16#0C#),
  290.    --  The page mark at the end of the file may be omitted, and is normally
  291.    --  omitted on output unless an explicit New_Page call is made before
  292.    --  closing the file. No page mark is added when a file is appended to,
  293.    --  so, in accordance with the permission in (RM A.10.2(4)), there may
  294.    --  or may not be a page mark separating preexising text in the file
  295.    --  from the new text to be written.
  296.  
  297.    --  A file mark is marked by the physical end of file. In DOS translation
  298.    --  mode on input, an EOF character (SUB = 16#1A#) gets translated to the
  299.    --  physical end of file, so in effect this character is recognized as
  300.    --  marking the end of file in DOS and similar systems.
  301.  
  302.    LM : constant := Character'Pos (ASCII.LF);
  303.    --  Used as line mark
  304.  
  305.    PM : constant := Character'Pos (ASCII.FF);
  306.    --  Used as page mark, except at end of file where it is implied
  307.  
  308.    -------------------------------------
  309.    -- Wide_Text_IO File Control Block --
  310.    -------------------------------------
  311.  
  312.    Default_WCEM : WCh_Con.WC_Encoding_Method := WCh_Con.WCEM_UTF8;
  313.    --  This gets modified during initialization (see body) using
  314.    --  the default value established in the call to Set_Globals.
  315.  
  316.    package FCB renames System.File_Control_Block;
  317.  
  318.    type Wide_Text_AFCB is new FCB.AFCB with record
  319.       Page        : Count := 1;
  320.       Line        : Count := 1;
  321.       Col         : Count := 1;
  322.       Line_Length : Count := 0;
  323.       Page_Length : Count := 0;
  324.  
  325.       Before_LM : Boolean := False;
  326.       --  This flag is used to deal with the anomolies introduced by the
  327.       --  peculiar definition of End_Of_File and End_Of_Page in Ada. These
  328.       --  functions require looking ahead more than one character. Since
  329.       --  there is no convenient way of backing up more than one character,
  330.       --  what we do is to leave ourselves positioned past the LM, but set
  331.       --  this flag, so that we know that from an Ada point of view we are
  332.       --  in front of the LM, not after it. A bit of a kludge, but it works!
  333.  
  334.       Before_LM_PM : Boolean := False;
  335.       --  This flag similarly handles the case of being physically positioned
  336.       --  after a LM-PM sequence when logically we are before the LM-PM. This
  337.       --  flag can only be set if Before_LM is also set.
  338.  
  339.       WC_Method : WCh_Con.WC_Encoding_Method := Default_WCEM;
  340.       --  Encoding method to be used for this file
  341.  
  342.       Before_Wide_Character : Boolean := False;
  343.       --  This flag is set to indicate that a wide character in the input has
  344.       --  been read by Wide_Text_IO.Look_Ahead. If it is set to True, then it
  345.       --  means that the stream is logically positioned before the character
  346.       --  but is physically positioned after it. The character involved must
  347.       --  not be in the range 16#00#-16#7F#, i.e. if the flag is set, then
  348.       --  we know the next character has a code greater than 16#7F#, and the
  349.       --  value of this character is saved in Saved_Wide_Character.
  350.  
  351.       Saved_Wide_Character : Wide_Character;
  352.       --  This field is valid only if Before_Wide_Character is set. It
  353.       --  contains a wide character read by Look_Ahead. If Look_Ahead
  354.       --  reads a character in the range 16#0000# to 16#007F#, then it
  355.       --  can use ungetc to put it back, but ungetc cannot be called
  356.       --  more than once, so for characters above this range, we don't
  357.       --  try to back up the file. Instead we save the character in this
  358.       --  field and set the flag Before_Wide_Character to indicate that
  359.       --  we are logically positioned before this character even though
  360.       --  the stream is physically positioned after it.
  361.  
  362.    end record;
  363.  
  364.    type File_Type is access all Wide_Text_AFCB;
  365.  
  366.    function AFCB_Allocate (Control_Block : Wide_Text_AFCB) return FCB.AFCB_Ptr;
  367.  
  368.    procedure AFCB_Close (File : access Wide_Text_AFCB);
  369.    procedure AFCB_Free  (File : access Wide_Text_AFCB);
  370.  
  371.    procedure Read
  372.      (File : in out Wide_Text_AFCB;
  373.       Item : out Ada.Streams.Stream_Element_Array;
  374.       Last : out Ada.Streams.Stream_Element_Offset);
  375.    --  Read operation used when Wide_Text_IO file is treated as a Stream
  376.  
  377.    procedure Write
  378.      (File : in out Wide_Text_AFCB;
  379.       Item : in Ada.Streams.Stream_Element_Array);
  380.    --  Write operation used when Wide_Text_IO file is treated as a Stream
  381.  
  382.    ------------------------
  383.    -- The Standard Files --
  384.    ------------------------
  385.  
  386.    Null_Str : aliased constant String := "";
  387.    --  Used as name and form of standard files
  388.  
  389.    Standard_Err_AFCB : aliased Wide_Text_AFCB;
  390.    Standard_In_AFCB  : aliased Wide_Text_AFCB;
  391.    Standard_Out_AFCB : aliased Wide_Text_AFCB;
  392.  
  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
  397.  
  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
  402.  
  403.    -----------------------
  404.    -- Local Subprograms --
  405.    -----------------------
  406.  
  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.
  409.  
  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
  414.  
  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.
  419.  
  420.    procedure Get_Character
  421.      (File : in File_Type;
  422.       Item : out Character);
  423.    --  This is essentially a copy of the normal Get routine from Text_IO. It
  424.    --  obtains a single character from the input file File, and places it in
  425.    --  Item. This character may be the leading character of a Wide_Character
  426.    --  sequence, but that is up to the caller to deal with.
  427.  
  428.    function Get_Wide_Char
  429.      (C    : Character;
  430.       File : File_Type)
  431.       return Wide_Character;
  432.    --  This function is shared by Get and Get_Immediate to extract a wide
  433.    --  character value from the given File. The first byte has already been
  434.    --  read and is passed in C. The wide character value is returned as the
  435.    --  result, and the file pointer is bumped past the character.
  436.  
  437.    function Nextc (File : File_Type) return Integer;
  438.    --  Returns next character from file without skipping past it (i.e. it
  439.    --  is a combination of Getc followed by an Ungetc).
  440.  
  441.    procedure Putc (ch : Integer; File : File_Type);
  442.    --  Outputs the given character to the file, which has already been
  443.    --  checked for being in output status. Device_Error is raised if the
  444.    --  character cannot be written.
  445.  
  446.    procedure Terminate_Line (File : File_Type);
  447.    --  If the file is in Write_File or Append_File mode, and the current
  448.    --  line is not terminated, then a line terminator is written using
  449.    --  New_Line. Note that there is no Terminate_Page routine, because
  450.    --  the page mark at the end of the file is implied if necessary.
  451.  
  452.    procedure Ungetc (ch : Integer; File : File_Type);
  453.    --  Pushes back character into stream, using ungetc. The caller has
  454.    --  checked that the file is in read status. Device_Error is raised
  455.    --  if the character cannot be pushed back. An attempt to push back
  456.    --  and end of file character (EOF) is ignored.
  457.  
  458. end Ada.Wide_Text_IO;
  459.