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-tiinau.adb < prev    next >
Text File  |  1996-09-28  |  8KB  |  288 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --              A D A . T E X T _ I O . I N T E G E R  _ A U X              --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.7 $                              --
  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. with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
  27.  
  28. with System.Img_BIU;   use System.Img_BIU;
  29. with System.Img_Int;   use System.Img_Int;
  30. with System.Img_LLB;   use System.Img_LLB;
  31. with System.Img_LLI;   use System.Img_LLI;
  32. with System.Img_LLW;   use System.Img_LLW;
  33. with System.Img_WIU;   use System.Img_WIU;
  34. with System.Val_Int;   use System.Val_Int;
  35. with System.Val_LLI;   use System.Val_LLI;
  36.  
  37. package body Ada.Text_IO.Integer_Aux is
  38.  
  39.    -----------------------
  40.    -- Local Subprograms --
  41.    -----------------------
  42.  
  43.    procedure Load_Integer
  44.      (File : in File_Type;
  45.       Buf  : out String;
  46.       Ptr  : in out Natural);
  47.    --  This is an auxiliary routine that is used to load an possibly signed
  48.    --  integer literal value from the input file into Buf, starting at Ptr + 1.
  49.    --  On return, Ptr is set to the last character stored.
  50.  
  51.    -------------
  52.    -- Get_Int --
  53.    -------------
  54.  
  55.    procedure Get_Int
  56.      (File  : in File_Type;
  57.       Item  : out Integer;
  58.       Width : in Field)
  59.    is
  60.       Buf  : String (1 .. Field'Last);
  61.       Ptr  : aliased Integer := 1;
  62.       Stop : Integer := 0;
  63.  
  64.    begin
  65.       if Width /= 0 then
  66.          Load_Width (File, Width, Buf, Stop);
  67.          String_Skip (Buf, Ptr);
  68.       else
  69.          Load_Integer (File, Buf, Stop);
  70.       end if;
  71.  
  72.       Item := Scan_Integer (Buf, Ptr'Access, Stop);
  73.       Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
  74.    end Get_Int;
  75.  
  76.    -------------
  77.    -- Get_LLI --
  78.    -------------
  79.  
  80.    procedure Get_LLI
  81.      (File  : in File_Type;
  82.       Item  : out Long_Long_Integer;
  83.       Width : in Field)
  84.    is
  85.       Buf  : String (1 .. Field'Last);
  86.       Ptr  : aliased Integer := 1;
  87.       Stop : Integer := 0;
  88.  
  89.    begin
  90.       if Width /= 0 then
  91.          Load_Width (File, Width, Buf, Stop);
  92.          String_Skip (Buf, Ptr);
  93.       else
  94.          Load_Integer (File, Buf, Stop);
  95.       end if;
  96.  
  97.       Item := Scan_Long_Long_Integer (Buf, Ptr'Access, Stop);
  98.       Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
  99.    end Get_LLI;
  100.  
  101.    --------------
  102.    -- Gets_Int --
  103.    --------------
  104.  
  105.    procedure Gets_Int
  106.      (From : in String;
  107.       Item : out Integer;
  108.       Last : out Positive)
  109.    is
  110.       Pos : aliased Integer;
  111.  
  112.    begin
  113.       String_Skip (From, Pos);
  114.       Item := Scan_Integer (From, Pos'Access, From'Last);
  115.       Last := Pos - 1;
  116.  
  117.    exception
  118.       when Constraint_Error =>
  119.          Last := Pos - 1;
  120.          raise Data_Error;
  121.    end Gets_Int;
  122.  
  123.    --------------
  124.    -- Gets_LLI --
  125.    --------------
  126.  
  127.    procedure Gets_LLI
  128.      (From : in String;
  129.       Item : out Long_Long_Integer;
  130.       Last : out Positive)
  131.    is
  132.       Pos : aliased Integer;
  133.  
  134.    begin
  135.       String_Skip (From, Pos);
  136.       Item := Scan_Long_Long_Integer (From, Pos'Access, From'Last);
  137.       Last := Pos - 1;
  138.  
  139.    exception
  140.       when Constraint_Error =>
  141.          Last := Pos - 1;
  142.          raise Data_Error;
  143.    end Gets_LLI;
  144.  
  145.    ------------------
  146.    -- Load_Integer --
  147.    ------------------
  148.  
  149.    procedure Load_Integer
  150.      (File : in File_Type;
  151.       Buf  : out String;
  152.       Ptr  : in out Natural)
  153.    is
  154.       Hash_Loc : Natural;
  155.       Loaded   : Boolean;
  156.  
  157.    begin
  158.       Load_Skip (File);
  159.       Load (File, Buf, Ptr, '+', '-');
  160.  
  161.       Load_Digits (File, Buf, Ptr, Loaded);
  162.  
  163.       if Loaded then
  164.          Load (File, Buf, Ptr, '#', ':', Loaded);
  165.  
  166.          if Loaded then
  167.             Hash_Loc := Ptr;
  168.             Load_Extended_Digits (File, Buf, Ptr);
  169.             Load (File, Buf, Ptr, Buf (Hash_Loc));
  170.          end if;
  171.  
  172.          Load (File, Buf, Ptr, 'E', 'e', Loaded);
  173.  
  174.          if Loaded then
  175.  
  176.             --  Note: it is strange to allow a minus sign, since the syntax
  177.             --  does not, but that is what ACVC test CE3704F, case (6) wants.
  178.  
  179.             Load (File, Buf, Ptr, '+', '-');
  180.             Load_Digits (File, Buf, Ptr);
  181.          end if;
  182.       end if;
  183.    end Load_Integer;
  184.  
  185.    -------------
  186.    -- Put_Int --
  187.    -------------
  188.  
  189.    procedure Put_Int
  190.      (File  : in File_Type;
  191.       Item  : in Integer;
  192.       Width : in Field;
  193.       Base  : in Number_Base)
  194.    is
  195.       Buf : String (1 .. Field'Last);
  196.       Ptr : Natural := 0;
  197.  
  198.    begin
  199.       if Base = 10 and then Width = 0 then
  200.          Set_Image_Integer (Item, Buf, Ptr);
  201.       elsif Base = 10 then
  202.          Set_Image_Width_Integer (Item, Width, Buf, Ptr);
  203.       else
  204.          Set_Image_Based_Integer (Item, Base, Width, Buf, Ptr);
  205.       end if;
  206.  
  207.       Put_Item (File, Buf (1 .. Ptr));
  208.    end Put_Int;
  209.  
  210.    -------------
  211.    -- Put_LLI --
  212.    -------------
  213.  
  214.    procedure Put_LLI
  215.      (File  : in File_Type;
  216.       Item  : in Long_Long_Integer;
  217.       Width : in Field;
  218.       Base  : in Number_Base)
  219.    is
  220.       Buf : String (1 .. Field'Last);
  221.       Ptr : Natural := 0;
  222.  
  223.    begin
  224.       if Base = 10 and then Width = 0 then
  225.          Set_Image_Long_Long_Integer (Item, Buf, Ptr);
  226.       elsif Base = 10 then
  227.          Set_Image_Width_Long_Long_Integer (Item, Width, Buf, Ptr);
  228.       else
  229.          Set_Image_Based_Long_Long_Integer (Item, Base, Width, Buf, Ptr);
  230.       end if;
  231.  
  232.       Put_Item (File, Buf (1 .. Ptr));
  233.    end Put_LLI;
  234.  
  235.    --------------
  236.    -- Puts_Int --
  237.    --------------
  238.  
  239.    procedure Puts_Int
  240.      (To   : out String;
  241.       Item : in Integer;
  242.       Base : in Number_Base)
  243.    is
  244.       Buf : String (1 .. Field'Last);
  245.       Ptr : Natural := 0;
  246.  
  247.    begin
  248.       if Base = 10 then
  249.          Set_Image_Width_Integer (Item, To'Length, Buf, Ptr);
  250.       else
  251.          Set_Image_Based_Integer (Item, Base, To'Length, Buf, Ptr);
  252.       end if;
  253.  
  254.       if Ptr > To'Length then
  255.          raise Layout_Error;
  256.       else
  257.          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
  258.       end if;
  259.    end Puts_Int;
  260.  
  261.    --------------
  262.    -- Puts_LLI --
  263.    --------------
  264.  
  265.    procedure Puts_LLI
  266.      (To   : out String;
  267.       Item : in Long_Long_Integer;
  268.       Base : in Number_Base)
  269.    is
  270.       Buf : String (1 .. Field'Last);
  271.       Ptr : Natural := 0;
  272.  
  273.    begin
  274.       if Base = 10 then
  275.          Set_Image_Width_Long_Long_Integer (Item, To'Length, Buf, Ptr);
  276.       else
  277.          Set_Image_Based_Long_Long_Integer (Item, Base, To'Length, Buf, Ptr);
  278.       end if;
  279.  
  280.       if Ptr > To'Length then
  281.          raise Layout_Error;
  282.       else
  283.          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
  284.       end if;
  285.    end Puts_LLI;
  286.  
  287. end Ada.Text_IO.Integer_Aux;
  288.