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

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