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-tiflau.adb < prev    next >
Text File  |  2000-07-19  |  7KB  |  232 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                        GNAT RUN-TIME COMPONENTS                          --
  4. --                                                                          --
  5. --                A D A . T E X T _ I O . F L O A T _ A U X                 --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.16 $                             --
  10. --                                                                          --
  11. --          Copyright (C) 1992-1998 Free Software Foundation, Inc.          --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
  37.  
  38. with System.Img_Real;  use System.Img_Real;
  39. with System.Val_Real;  use System.Val_Real;
  40.  
  41. package body Ada.Text_IO.Float_Aux is
  42.  
  43.    ---------
  44.    -- Get --
  45.    ---------
  46.  
  47.    procedure Get
  48.      (File  : in File_Type;
  49.       Item  : out Long_Long_Float;
  50.       Width : in Field)
  51.    is
  52.       Buf  : String (1 .. Field'Last);
  53.       Stop : Integer := 0;
  54.       Ptr  : aliased Integer := 1;
  55.  
  56.    begin
  57.       if Width /= 0 then
  58.          Load_Width (File, Width, Buf, Stop);
  59.          String_Skip (Buf, Ptr);
  60.       else
  61.          Load_Real (File, Buf, Stop);
  62.       end if;
  63.  
  64.       Item := Scan_Real (Buf, Ptr'Access, Stop);
  65.  
  66.       Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
  67.    end Get;
  68.  
  69.    ----------
  70.    -- Gets --
  71.    ----------
  72.  
  73.    procedure Gets
  74.      (From : in String;
  75.       Item : out Long_Long_Float;
  76.       Last : out Positive)
  77.    is
  78.       Pos : aliased Integer;
  79.  
  80.    begin
  81.       String_Skip (From, Pos);
  82.       Item := Scan_Real (From, Pos'Access, From'Last);
  83.       Last := Pos - 1;
  84.  
  85.    exception
  86.       when Constraint_Error =>
  87.          Last := Pos - 1;
  88.          raise Data_Error;
  89.    end Gets;
  90.  
  91.    ---------------
  92.    -- Load_Real --
  93.    ---------------
  94.  
  95.    procedure Load_Real
  96.      (File : in File_Type;
  97.       Buf  : out String;
  98.       Ptr  : in out Natural)
  99.    is
  100.       Loaded   : Boolean;
  101.  
  102.    begin
  103.       --  Skip initial blanks, and load possible sign
  104.  
  105.       Load_Skip (File);
  106.       Load (File, Buf, Ptr, '+', '-');
  107.  
  108.       --  Case of .nnnn
  109.  
  110.       Load (File, Buf, Ptr, '.', Loaded);
  111.  
  112.       if Loaded then
  113.          Load_Digits (File, Buf, Ptr, Loaded);
  114.  
  115.          --  Hopeless junk if no digits loaded
  116.  
  117.          if not Loaded then
  118.             return;
  119.          end if;
  120.  
  121.       --  Otherwise must have digits to start
  122.  
  123.       else
  124.          Load_Digits (File, Buf, Ptr, Loaded);
  125.  
  126.          --  Hopeless junk if no digits loaded
  127.  
  128.          if not Loaded then
  129.             return;
  130.          end if;
  131.  
  132.          --  Based cases
  133.  
  134.          Load (File, Buf, Ptr, '#', ':', Loaded);
  135.  
  136.          if Loaded then
  137.  
  138.             --  Case of nnn#.xxx#
  139.  
  140.             Load (File, Buf, Ptr, '.', Loaded);
  141.  
  142.             if Loaded then
  143.                Load_Extended_Digits (File, Buf, Ptr);
  144.  
  145.             --  Case of nnn#xxx.[xxx]# or nnn#xxx#
  146.  
  147.             else
  148.                Load_Extended_Digits (File, Buf, Ptr);
  149.                Load (File, Buf, Ptr, '.', Loaded);
  150.  
  151.                if Loaded then
  152.                   Load_Extended_Digits (File, Buf, Ptr);
  153.                end if;
  154.  
  155.                --  As usual, it seems strange to allow mixed base characters,
  156.                --  but that is what ACVC tests expect, see CE3804M, case (3).
  157.  
  158.                Load (File, Buf, Ptr, '#', ':');
  159.             end if;
  160.  
  161.          --  Case of nnn.[nnn] or nnn
  162.  
  163.          else
  164.             Load (File, Buf, Ptr, '.', Loaded);
  165.  
  166.             if Loaded then
  167.                Load_Digits (File, Buf, Ptr);
  168.             end if;
  169.          end if;
  170.       end if;
  171.  
  172.       --  Deal with exponent
  173.  
  174.       Load (File, Buf, Ptr, 'E', 'e', Loaded);
  175.  
  176.       if Loaded then
  177.          Load (File, Buf, Ptr, '+', '-');
  178.          Load_Digits (File, Buf, Ptr);
  179.       end if;
  180.    end Load_Real;
  181.  
  182.    ---------
  183.    -- Put --
  184.    ---------
  185.  
  186.    procedure Put
  187.      (File : in File_Type;
  188.       Item : in Long_Long_Float;
  189.       Fore : in Field;
  190.       Aft  : in Field;
  191.       Exp  : in Field)
  192.    is
  193.       Buf : String (1 .. 3 * Field'Last + 2);
  194.       Ptr : Natural := 0;
  195.  
  196.    begin
  197.       Set_Image_Real (Item, Buf, Ptr, Fore, Aft, Exp);
  198.       Put_Item (File, Buf (1 .. Ptr));
  199.    end Put;
  200.  
  201.    ----------
  202.    -- Puts --
  203.    ----------
  204.  
  205.    procedure Puts
  206.      (To   : out String;
  207.       Item : in Long_Long_Float;
  208.       Aft  : in Field;
  209.       Exp  : in Field)
  210.    is
  211.       Buf : String (1 .. 3 * Field'Last + 2);
  212.       Ptr : Natural := 0;
  213.  
  214.    begin
  215.       Set_Image_Real (Item, Buf, Ptr, Fore => 1, Aft => Aft, Exp => Exp);
  216.  
  217.       if Ptr > To'Length then
  218.          raise Layout_Error;
  219.  
  220.       else
  221.          for J in 1 .. Ptr loop
  222.             To (To'Last - Ptr + J) := Buf (J);
  223.          end loop;
  224.  
  225.          for J in To'First .. To'Last - Ptr loop
  226.             To (J) := ' ';
  227.          end loop;
  228.       end if;
  229.    end Puts;
  230.  
  231. end Ada.Text_IO.Float_Aux;
  232.