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-wtdeio.adb < prev    next >
Text File  |  1996-09-28  |  6KB  |  171 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --   A D A . T E X T _ I O . W I D E _ T E X T _ I O . D E C I M A L _ I O  --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.2 $                              --
  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.Decimal_Aux;
  27. with System.WCh_Con; use System.WCh_Con;
  28. with System.WCh_WtS; use System.WCh_WtS;
  29.  
  30. with Ada.Unchecked_Conversion;
  31.  
  32. package body Ada.Text_IO.Wide_Text_IO.Decimal_IO is
  33.  
  34.    subtype TFT is Ada.Text_IO.File_Type;
  35.    --  File type required for calls to routines in Aux
  36.  
  37.    package Aux renames Ada.Text_IO.Decimal_Aux;
  38.    --  We can share the normal Text_IO circuits for the non-string cases
  39.    --  since numeric values involve no wide character values, and the first
  40.    --  character of a wide character value (ESC or an upper half character)
  41.    --  always looks non-numeric for the Get case). For the Wide_String cases
  42.    --  we can share the normal Text_IO circuits by converting to String.
  43.  
  44.    Scale : constant Integer := Num'Scale;
  45.  
  46.    ---------
  47.    -- Get --
  48.    ---------
  49.  
  50.    procedure Get
  51.      (File  : in File_Type;
  52.       Item  : out Num;
  53.       Width : in Field := 0)
  54.    is
  55.    begin
  56.       if Num'Size > Integer'Size then
  57.          Item := Num (Aux.Get_LLD (TFT (File), Width, Scale));
  58.          --  Item := Num'Fixed_Value (Aux.Get_LLD (TFT (File), Width, Scale));
  59.          --  above is what we should write, but gets assert error ???
  60.  
  61.       else
  62.          Item := Num (Aux.Get_Dec (TFT (File), Width, Scale));
  63.          --  Item := Num'Fixed_Value (Aux.Get_Dec (TFT (File), Width, Scale));
  64.          --  above is what we should write, but gets assert error ???
  65.       end if;
  66.  
  67.    exception
  68.       when Constraint_Error => raise Data_Error;
  69.    end Get;
  70.  
  71.    procedure Get
  72.      (Item  : out Num;
  73.       Width : in Field := 0)
  74.    is
  75.    begin
  76.       Get (Current_Input, Item, Width);
  77.    end Get;
  78.  
  79.    procedure Get
  80.      (From : in Wide_String;
  81.       Item : out Num;
  82.       Last : out Positive)
  83.    is
  84.       S : constant String := Wide_String_To_String (From, WCEM_Upper);
  85.       --  String on which we do the actual conversion. Note that the method
  86.       --  used for wide character encoding is irrelevant, since if there is
  87.       --  a character outside the Standard.Character range then the call to
  88.       --  Aux.Gets will raise Data_Error in any case.
  89.  
  90.    begin
  91.       if Num'Size > Integer'Size then
  92.          --  Item := Num'Fixed_Value
  93.          --  should write above, but gets assert error ???
  94.          Item := Num
  95.                    (Aux.Gets_LLD (S, Last'Unrestricted_Access, Scale));
  96.       else
  97.          --  Item := Num'Fixed_Value
  98.          --  should write above, but gets assert error ???
  99.          Item := Num
  100.                    (Aux.Gets_Dec (S, Last'Unrestricted_Access, Scale));
  101.       end if;
  102.  
  103.    exception
  104.       when Constraint_Error => raise Data_Error;
  105.    end Get;
  106.  
  107.    ---------
  108.    -- Put --
  109.    ---------
  110.  
  111.    procedure Put
  112.      (File : in File_Type;
  113.       Item : in Num;
  114.       Fore : in Field := Default_Fore;
  115.       Aft  : in Field := Default_Aft;
  116.       Exp  : in Field := Default_Exp)
  117.    is
  118.    begin
  119.       if Num'Size > Integer'Size then
  120.          Aux.Put_LLD
  121. --           (TFT (File), Long_Long_Integer'Integer_Value (Item),
  122. --  ???
  123.            (TFT (File), Long_Long_Integer (Item),
  124.             Fore, Aft, Exp, Scale);
  125.       else
  126.          Aux.Put_Dec
  127. --           (TFT (File), Integer'Integer_Value (Item), Fore, Aft, Exp, Scale);
  128. --  ???
  129.            (TFT (File), Integer (Item), Fore, Aft, Exp, Scale);
  130.  
  131.       end if;
  132.    end Put;
  133.  
  134.    procedure Put
  135.      (Item : in Num;
  136.       Fore : in Field := Default_Fore;
  137.       Aft  : in Field := Default_Aft;
  138.       Exp  : in Field := Default_Exp)
  139.    is
  140.    begin
  141.       Put (Current_Output, Item, Aft, Exp);
  142.    end Put;
  143.  
  144.    procedure Put
  145.      (To   : out Wide_String;
  146.       Item : in Num;
  147.       Aft  : in Field := Default_Aft;
  148.       Exp  : in Field := Default_Exp)
  149.    is
  150.       S : String (To'First .. To'Last);
  151.  
  152.    begin
  153.       if Num'Size > Integer'Size then
  154. --       Aux.Puts_LLD
  155. --         (S, Long_Long_Integer'Integer_Value (Item), Aft, Exp, Scale);
  156. --  ???
  157.          Aux.Puts_LLD
  158.            (S, Long_Long_Integer (Item), Aft, Exp, Scale);
  159.       else
  160. --       Aux.Puts_Dec (S, Integer'Integer_Value (Item), Aft, Exp, Scale);
  161. --  ???
  162.          Aux.Puts_Dec (S, Integer (Item), Aft, Exp, Scale);
  163.       end if;
  164.  
  165.       for J in S'Range loop
  166.          To (J) := Wide_Character'Val (Character'Pos (S (J)));
  167.       end loop;
  168.    end Put;
  169.  
  170. end Ada.Text_IO.Wide_Text_IO.Decimal_IO;
  171.