home *** CD-ROM | disk | FTP | other *** search
/ Hacker / Hacker.iso / HACKER / DECOMP / DECAF / byteutil.ads < prev    next >
Encoding:
Text File  |  1996-09-19  |  6.8 KB  |  226 lines

  1. --
  2. -- Copyright (C) 1996 Ada Resource Association (ARA), Columbus, Ohio.
  3. -- Author: Gilles Demailly
  4. --
  5. --
  6. -- Permission to use, copy, modify, and distribute this software and its
  7. -- documentation for any purpose and without fee is hereby granted,
  8. -- provided that the above copyright and authorship notice appear in all
  9. -- copies and that both that copyright notice and this permission notice
  10. -- appear in supporting documentation.
  11. -- 
  12. -- The ARA makes no representations about the suitability of this software
  13. -- for any purpose.  It is provided "as is" without express
  14. -- or implied warranty.
  15. -- 
  16.  
  17. --
  18. -- This package provides binary file Input-Ouput services.
  19. -- These services are platform independant i.e. files manipulated
  20. -- may use Big_Endian and Little_Endian representations.
  21. --
  22. -- basic file services are based on the Ada.Sequential_IO services
  23. -- (opering, creating, closing ...)
  24. --
  25.  
  26. with Basic_Definitions;
  27. use Basic_Definitions;
  28.  
  29. with Ada.Sequential_Io;
  30.  
  31. package Byte_Utilities is
  32.  
  33.    -- definition of the subtype Byte
  34.    ---------------------------------
  35.    subtype Byte is Unsigned_8;
  36.    
  37.    -- array of Bytes
  38.    -----------------
  39.    type Bytes is array (Unsigned_32 range <>) of Byte;
  40.    
  41.    type Acc_Bytes is access Bytes;
  42.    
  43.    -- type of files manipulated by Byte_Utilities
  44.    ----------------------------------------------
  45.    type File_Type is limited private;
  46.    
  47.    -- files opening modes
  48.    ----------------------
  49.    type File_Mode is (In_File, Out_File, Append_File);
  50.    
  51.    -- underlying representation
  52.    ----------------------------
  53.    type Byte_Order_Scheme is (Big_Endian, Little_Endian);
  54.  
  55.    -- create a file
  56.    ----------------
  57.    procedure Create (File       : in out File_Type;
  58.                      Mode       : in File_Mode         := Out_File;
  59.                      Byte_Order : in Byte_Order_Scheme := Big_Endian;
  60.                      Name       : in String);
  61.                      
  62.    pragma Inline (Create);
  63.    
  64.    -- open a file
  65.    --------------
  66.    procedure Open   (File       : in out File_Type;
  67.                      Mode       : in File_Mode;
  68.                      Byte_Order : in Byte_Order_Scheme;
  69.                      Name       : in String);
  70.  
  71.    pragma Inline (Open);
  72.    
  73.    -- close a file
  74.    ---------------
  75.    procedure Close  (File : in out File_Type);
  76.  
  77.    pragma Inline (Close);
  78.    
  79.    -- delete a file
  80.    ----------------
  81.    procedure Delete (File : in out File_Type);
  82.    
  83.    pragma Inline (Delete);
  84.    
  85.    -- reset a file (may try to change mode and underlying representation)
  86.    ----------------------------------------------------------------------
  87.    procedure Reset  (File       : in out File_Type;
  88.                      Mode       : in File_mode;
  89.                      Byte_Order : in Byte_Order_Scheme);
  90.  
  91.    -- reset a file (no mode or underlying representation changes)
  92.    --------------------------------------------------------------
  93.    procedure Reset  (File : in out File_Type);
  94.  
  95.    
  96.    --
  97.    -- Read procedures for types defined in Basic_Definitions
  98.    --
  99.    
  100.    procedure Read   (File : in File_Type; Item : out Unsigned_8);
  101.    
  102.    procedure Read   (File : in File_Type; Item : out Unsigned_16);
  103.    
  104.    procedure Read   (File : in File_Type; Item : out Unsigned_32);
  105.    
  106.    procedure Read   (File : in File_Type; Item : out Unsigned_64);
  107.  
  108.    procedure Read   (File : in File_Type; Item : out Integer_8);
  109.    
  110.    procedure Read   (File : in File_Type; Item : out Integer_16);
  111.    
  112.    procedure Read   (File : in File_Type; Item : out Integer_32);
  113.    
  114.    procedure Read   (File : in File_Type; Item : out Integer_64);
  115.  
  116.    procedure Read   (File : in File_Type; Item : out Float_32);
  117.  
  118.    procedure Read   (File : in File_Type; Item : out Float_64);
  119.    
  120.    --
  121.    -- Write procedures for types defined in Basic_Definitions
  122.    --
  123.  
  124.    procedure Write  (File : in File_Type; Item : in Unsigned_8);
  125.    
  126.    procedure Write  (File : in File_Type; Item : in Unsigned_16);
  127.    
  128.    procedure Write  (File : in File_Type; Item : in Unsigned_32);
  129.    
  130.    procedure Write  (File : in File_Type; Item : in Unsigned_64);
  131.  
  132.    procedure Write  (File : in File_Type; Item : in Integer_8);
  133.    
  134.    procedure Write  (File : in File_Type; Item : in Integer_16);
  135.    
  136.    procedure Write  (File : in File_Type; Item : in Integer_32);
  137.    
  138.    procedure Write  (File : in File_Type; Item : in Integer_64);
  139.  
  140.    procedure Write  (File : in File_Type; Item : in Float_32);
  141.    
  142.    procedure Write  (File : in File_Type; Item : in Float_64);
  143.  
  144.    
  145.    --
  146.    -- Read functions for types defined in Basic_Definitions
  147.    --
  148.    
  149.    function Get_Unsigned_8
  150.                (From       : Acc_Bytes;
  151.                 Index      : Unsigned_32)
  152.             return Unsigned_8;
  153.  
  154.    function Get_Unsigned_16
  155.                (From       : Acc_Bytes;
  156.                 Index      : Unsigned_32;
  157.                 Byte_Order : Byte_Order_Scheme := Big_Endian)
  158.             return Unsigned_16;
  159.  
  160.    function Get_Unsigned_32
  161.                (From       : Acc_Bytes;
  162.                 Index      : Unsigned_32;
  163.                 Byte_Order : Byte_Order_Scheme := Big_Endian)
  164.             return Unsigned_32;
  165.  
  166.    function Get_Unsigned_64
  167.                (From       : Acc_Bytes;
  168.                 Index      : Unsigned_32;
  169.                 Byte_Order : Byte_Order_Scheme := Big_Endian)
  170.             return Unsigned_64;
  171.  
  172.    function Get_Integer_8
  173.                (From       : Acc_Bytes;
  174.                 Index      : Unsigned_32)
  175.             return Integer_8;
  176.  
  177.    function Get_Integer_16
  178.                (From       : Acc_Bytes;
  179.                 Index      : Unsigned_32;
  180.                 Byte_Order : Byte_Order_Scheme := Big_Endian)
  181.             return Integer_16;
  182.  
  183.    function Get_Integer_32
  184.                (From       : Acc_Bytes;
  185.                 Index      : Unsigned_32;
  186.                 Byte_Order : Byte_Order_Scheme := Big_Endian)
  187.             return Integer_32;
  188.  
  189.    function Get_Integer_64
  190.                (From       : Acc_Bytes;
  191.                 Index      : Unsigned_32;
  192.                 Byte_Order : Byte_Order_Scheme := Big_Endian)
  193.             return Integer_64;
  194.  
  195.    function Get_Float_32
  196.                (From       : Acc_Bytes;
  197.                 Index      : Unsigned_32;
  198.                 Byte_Order : Byte_Order_Scheme := Big_Endian)
  199.             return Float_32;
  200.  
  201.    function Get_Float_64
  202.                (From       : Acc_Bytes;
  203.                 Index      : Unsigned_32;
  204.                 Byte_Order : Byte_Order_Scheme := Big_Endian)
  205.             return Float_64;
  206.  
  207.    function Get_String
  208.                (From   : Acc_Bytes;
  209.                 Index  : Unsigned_32;
  210.                 Length : Positive)
  211.             return String;
  212.             
  213. private
  214.  
  215.    package Byte_Io is new Ada.Sequential_Io (Byte);
  216.  
  217.    -- just add the underlying representation mode
  218.    ----------------------------------------------
  219.    type File_Type is
  220.       record
  221.          File       : Byte_Io.File_Type;
  222.          Byte_Order : Byte_Order_Scheme := Big_Endian;
  223.       end record;
  224.    
  225. end Byte_Utilities;
  226.