home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / ada / a-direio.adb < prev    next >
Text File  |  1996-09-28  |  6KB  |  224 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                        A D A . D I R E C T _ I O                         --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.13 $                             --
  10. --                                                                          --
  11. --        Copyright (c) 1992,1993,1994,1995 NYU, All Rights Reserved        --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. --  This is the generic template for Direct_IO, i.e. the code that gets
  27. --  duplicated. We absolutely minimize this code by either calling routines
  28. --  in System.File_IO (for common file functions), or in System.Direct_IO
  29. --  (for specialized Direct_IO functions)
  30.  
  31. with Interfaces.C_Streams;      use Interfaces.C_Streams;
  32. with System;                    use System;
  33. with System.File_Control_Block;
  34. with System.File_IO;
  35. with Unchecked_Conversion;
  36.  
  37. use type System.Direct_IO.Count;
  38.  
  39. package body Ada.Direct_IO is
  40.  
  41.    package FCB renames System.File_Control_Block;
  42.    package FIO renames System.File_IO;
  43.    package DIO renames System.Direct_IO;
  44.  
  45.    subtype AP      is FCB.AFCB_Ptr;
  46.    subtype FP      is DIO.File_Type;
  47.    subtype DCount  is DIO.Count;
  48.    subtype DPCount is DIO.Positive_Count;
  49.  
  50.    function To_FCB is new Unchecked_Conversion (File_Mode, FCB.File_Mode);
  51.    function To_DIO is new Unchecked_Conversion (FCB.File_Mode, File_Mode);
  52.  
  53.    -----------
  54.    -- Close --
  55.    -----------
  56.  
  57.    procedure Close (File : in out File_Type) is
  58.    begin
  59.       FIO.Close (AP (File));
  60.    end Close;
  61.  
  62.    ------------
  63.    -- Create --
  64.    ------------
  65.  
  66.    procedure Create
  67.      (File : in out File_Type;
  68.       Mode : in File_Mode := Inout_File;
  69.       Name : in String := "";
  70.       Form : in String := "")
  71.    is
  72.    begin
  73.       DIO.Create (FP (File), To_FCB (Mode), Name, Form);
  74.       File.Bytes := Bytes;
  75.    end Create;
  76.  
  77.    ------------
  78.    -- Delete --
  79.    ------------
  80.  
  81.    procedure Delete (File : in out File_Type) is
  82.    begin
  83.       FIO.Delete (AP (File));
  84.    end Delete;
  85.  
  86.    -----------------
  87.    -- End_Of_File --
  88.    -----------------
  89.  
  90.    function End_Of_File (File : in File_Type) return Boolean is
  91.    begin
  92.       return DIO.End_Of_File (FP (File));
  93.    end End_Of_File;
  94.  
  95.    ----------
  96.    -- Form --
  97.    ----------
  98.  
  99.    function Form (File : in File_Type) return String is
  100.    begin
  101.       return FIO.Form (AP (File));
  102.    end Form;
  103.  
  104.    -----------
  105.    -- Index --
  106.    -----------
  107.  
  108.    function Index (File : in File_Type) return Positive_Count is
  109.    begin
  110.       return Positive_Count (DIO.Index (FP (File)));
  111.    end Index;
  112.  
  113.    -------------
  114.    -- Is_Open --
  115.    -------------
  116.  
  117.    function Is_Open (File : in File_Type) return Boolean is
  118.    begin
  119.       return FIO.Is_Open (AP (File));
  120.    end Is_Open;
  121.  
  122.    ----------
  123.    -- Mode --
  124.    ----------
  125.  
  126.    function Mode (File : in File_Type) return File_Mode is
  127.    begin
  128.       return To_DIO (FIO.Mode (AP (File)));
  129.    end Mode;
  130.  
  131.    ----------
  132.    -- Name --
  133.    ----------
  134.  
  135.    function Name (File : in File_Type) return String is
  136.    begin
  137.       return FIO.Name (AP (File));
  138.    end Name;
  139.  
  140.    ----------
  141.    -- Open --
  142.    ----------
  143.  
  144.    procedure Open
  145.      (File : in out File_Type;
  146.       Mode : in File_Mode;
  147.       Name : in String;
  148.       Form : in String := "")
  149.    is
  150.    begin
  151.       DIO.Open (FP (File), To_FCB (Mode), Name, Form);
  152.       File.Bytes := Bytes;
  153.    end Open;
  154.  
  155.    ----------
  156.    -- Read --
  157.    ----------
  158.  
  159.    procedure Read
  160.      (File : in File_Type;
  161.       Item : out Element_Type;
  162.       From : in Positive_Count)
  163.    is
  164.    begin
  165.       DIO.Read (FP (File), Item'Address, DPCount (From));
  166.    end Read;
  167.  
  168.    procedure Read (File : in File_Type; Item : out Element_Type) is
  169.    begin
  170.       DIO.Read (FP (File), Item'Address);
  171.    end Read;
  172.  
  173.    -----------
  174.    -- Reset --
  175.    -----------
  176.  
  177.    procedure Reset (File : in out File_Type; Mode : in File_Mode) is
  178.    begin
  179.       DIO.Reset (FP (File), To_FCB (Mode));
  180.    end Reset;
  181.  
  182.    procedure Reset (File : in out File_Type) is
  183.    begin
  184.       DIO.Reset (FP (File));
  185.    end Reset;
  186.  
  187.    ---------------
  188.    -- Set_Index --
  189.    ---------------
  190.  
  191.    procedure Set_Index (File : in File_Type; To : in Positive_Count) is
  192.    begin
  193.       DIO.Set_Index (FP (File), DPCount (To));
  194.    end Set_Index;
  195.  
  196.    ----------
  197.    -- Size --
  198.    ----------
  199.  
  200.    function Size (File : in File_Type) return Count is
  201.    begin
  202.       return Count (DIO.Size (FP (File)));
  203.    end Size;
  204.  
  205.    -----------
  206.    -- Write --
  207.    -----------
  208.  
  209.    procedure Write
  210.      (File : in File_Type;
  211.       Item : in Element_Type;
  212.       To   : in Positive_Count)
  213.    is
  214.    begin
  215.       DIO.Write (FP (File), Item'Address, DPCount (To));
  216.    end Write;
  217.  
  218.    procedure Write (File : in File_Type; Item : in Element_Type) is
  219.    begin
  220.       DIO.Write (FP (File), Item'Address);
  221.    end Write;
  222.  
  223. end Ada.Direct_IO;
  224.