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-wtmoau.adb < prev    next >
Text File  |  2000-07-19  |  10KB  |  310 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --         A D A . W I D E _ T E X T _ I O . M O D U L A R  _ A U X         --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.2 $                              --
  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.Generic_Aux; use Ada.Wide_Text_IO.Generic_Aux;
  37.  
  38. with System.Img_BIU;   use System.Img_BIU;
  39. with System.Img_Uns;   use System.Img_Uns;
  40. with System.Img_LLB;   use System.Img_LLB;
  41. with System.Img_LLU;   use System.Img_LLU;
  42. with System.Img_LLW;   use System.Img_LLW;
  43. with System.Img_WIU;   use System.Img_WIU;
  44. with System.Val_Uns;   use System.Val_Uns;
  45. with System.Val_LLU;   use System.Val_LLU;
  46.  
  47. package body Ada.Wide_Text_IO.Modular_Aux is
  48.  
  49.    use System.Unsigned_Types;
  50.  
  51.    -----------------------
  52.    -- Local Subprograms --
  53.    -----------------------
  54.  
  55.    procedure Load_Modular
  56.      (File : in File_Type;
  57.       Buf  : out String;
  58.       Ptr  : in out Natural);
  59.    --  This is an auxiliary routine that is used to load an possibly signed
  60.    --  modular literal value from the input file into Buf, starting at Ptr + 1.
  61.    --  Ptr is left set to the last character stored.
  62.  
  63.    -------------
  64.    -- Get_Uns --
  65.    -------------
  66.  
  67.    procedure Get_Uns
  68.      (File  : in File_Type;
  69.       Item  : out Unsigned;
  70.       Width : in Field)
  71.    is
  72.       Buf  : String (1 .. Field'Last);
  73.       Stop : Integer := 0;
  74.       Ptr  : aliased Integer := 1;
  75.  
  76.    begin
  77.       if Width /= 0 then
  78.          Load_Width (File, Width, Buf, Stop);
  79.          String_Skip (Buf, Ptr);
  80.       else
  81.          Load_Modular (File, Buf, Stop);
  82.       end if;
  83.  
  84.       Item := Scan_Unsigned (Buf, Ptr'Access, Stop);
  85.       Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
  86.    end Get_Uns;
  87.  
  88.    -------------
  89.    -- Get_LLU --
  90.    -------------
  91.  
  92.    procedure Get_LLU
  93.      (File  : in File_Type;
  94.       Item  : out Long_Long_Unsigned;
  95.       Width : in Field)
  96.    is
  97.       Buf  : String (1 .. Field'Last);
  98.       Stop : Integer := 0;
  99.       Ptr  : aliased Integer := 1;
  100.  
  101.    begin
  102.       if Width /= 0 then
  103.          Load_Width (File, Width, Buf, Stop);
  104.          String_Skip (Buf, Ptr);
  105.       else
  106.          Load_Modular (File, Buf, Stop);
  107.       end if;
  108.  
  109.       Item := Scan_Long_Long_Unsigned (Buf, Ptr'Access, Stop);
  110.       Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
  111.    end Get_LLU;
  112.  
  113.    --------------
  114.    -- Gets_Uns --
  115.    --------------
  116.  
  117.    procedure Gets_Uns
  118.      (From : in String;
  119.       Item : out Unsigned;
  120.       Last : out Positive)
  121.    is
  122.       Pos : aliased Integer;
  123.  
  124.    begin
  125.       String_Skip (From, Pos);
  126.       Item := Scan_Unsigned (From, Pos'Access, From'Last);
  127.       Last := Pos - 1;
  128.  
  129.    exception
  130.       when Constraint_Error =>
  131.          Last := Pos - 1;
  132.          raise Data_Error;
  133.  
  134.    end Gets_Uns;
  135.  
  136.    --------------
  137.    -- Gets_LLU --
  138.    --------------
  139.  
  140.    procedure Gets_LLU
  141.      (From : in String;
  142.       Item : out Long_Long_Unsigned;
  143.       Last : out Positive)
  144.    is
  145.       Pos : aliased Integer;
  146.  
  147.    begin
  148.       String_Skip (From, Pos);
  149.       Item := Scan_Long_Long_Unsigned (From, Pos'Access, From'Last);
  150.       Last := Pos - 1;
  151.  
  152.    exception
  153.       when Constraint_Error =>
  154.          Last := Pos - 1;
  155.          raise Data_Error;
  156.  
  157.    end Gets_LLU;
  158.  
  159.    ------------------
  160.    -- Load_Modular --
  161.    ------------------
  162.  
  163.    procedure Load_Modular
  164.      (File : in File_Type;
  165.       Buf  : out String;
  166.       Ptr  : in out Natural)
  167.    is
  168.       Hash_Loc : Natural;
  169.       Loaded   : Boolean;
  170.  
  171.    begin
  172.       Load_Skip (File);
  173.  
  174.       --  Note: it is a bit strange to allow a minus sign here, but it seems
  175.       --  consistent with the general behavior expected by the ACVC tests
  176.       --  which is to scan past junk and then signal data error, see ACVC
  177.       --  test CE3704F, case (6), which is for signed integer exponents,
  178.       --  which seems a similar case.
  179.  
  180.       Load (File, Buf, Ptr, '+', '-');
  181.       Load_Digits (File, Buf, Ptr, Loaded);
  182.  
  183.       if Loaded then
  184.          Load (File, Buf, Ptr, '#', ':', Loaded);
  185.  
  186.          if Loaded then
  187.             Hash_Loc := Ptr;
  188.             Load_Extended_Digits (File, Buf, Ptr);
  189.             Load (File, Buf, Ptr, Buf (Hash_Loc));
  190.          end if;
  191.  
  192.          Load (File, Buf, Ptr, 'E', 'e', Loaded);
  193.  
  194.          if Loaded then
  195.  
  196.             --  Note: it is strange to allow a minus sign, since the syntax
  197.             --  does not, but that is what ACVC test CE3704F, case (6) wants
  198.             --  for the signed case, and there seems no good reason to treat
  199.             --  exponents differently for the signed and unsigned cases.
  200.  
  201.             Load (File, Buf, Ptr, '+', '-');
  202.             Load_Digits (File, Buf, Ptr);
  203.          end if;
  204.       end if;
  205.    end Load_Modular;
  206.  
  207.    -------------
  208.    -- Put_Uns --
  209.    -------------
  210.  
  211.    procedure Put_Uns
  212.      (File  : in File_Type;
  213.       Item  : in Unsigned;
  214.       Width : in Field;
  215.       Base  : in Number_Base)
  216.    is
  217.       Buf : String (1 .. Field'Last);
  218.       Ptr : Natural := 0;
  219.  
  220.    begin
  221.       if Base = 10 and then Width = 0 then
  222.          Set_Image_Unsigned (Item, Buf, Ptr);
  223.       elsif Base = 10 then
  224.          Set_Image_Width_Unsigned (Item, Width, Buf, Ptr);
  225.       else
  226.          Set_Image_Based_Unsigned (Item, Base, Width, Buf, Ptr);
  227.       end if;
  228.  
  229.       Put_Item (File, Buf (1 .. Ptr));
  230.    end Put_Uns;
  231.  
  232.    -------------
  233.    -- Put_LLU --
  234.    -------------
  235.  
  236.    procedure Put_LLU
  237.      (File  : in File_Type;
  238.       Item  : in Long_Long_Unsigned;
  239.       Width : in Field;
  240.       Base  : in Number_Base)
  241.    is
  242.       Buf : String (1 .. Field'Last);
  243.       Ptr : Natural := 0;
  244.  
  245.    begin
  246.       if Base = 10 and then Width = 0 then
  247.          Set_Image_Long_Long_Unsigned (Item, Buf, Ptr);
  248.       elsif Base = 10 then
  249.          Set_Image_Width_Long_Long_Unsigned (Item, Width, Buf, Ptr);
  250.       else
  251.          Set_Image_Based_Long_Long_Unsigned (Item, Base, Width, Buf, Ptr);
  252.       end if;
  253.  
  254.       Put_Item (File, Buf (1 .. Ptr));
  255.    end Put_LLU;
  256.  
  257.    --------------
  258.    -- Puts_Uns --
  259.    --------------
  260.  
  261.    procedure Puts_Uns
  262.      (To   : out String;
  263.       Item : in Unsigned;
  264.       Base : in Number_Base)
  265.    is
  266.       Buf : String (1 .. Field'Last);
  267.       Ptr : Natural := 0;
  268.  
  269.    begin
  270.       if Base = 10 then
  271.          Set_Image_Width_Unsigned (Item, To'Length, Buf, Ptr);
  272.       else
  273.          Set_Image_Based_Unsigned (Item, Base, To'Length, Buf, Ptr);
  274.       end if;
  275.  
  276.       if Ptr > To'Length then
  277.          raise Layout_Error;
  278.       else
  279.          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
  280.       end if;
  281.    end Puts_Uns;
  282.  
  283.    --------------
  284.    -- Puts_LLU --
  285.    --------------
  286.  
  287.    procedure Puts_LLU
  288.      (To   : out String;
  289.       Item : in Long_Long_Unsigned;
  290.       Base : in Number_Base)
  291.    is
  292.       Buf : String (1 .. Field'Last);
  293.       Ptr : Natural := 0;
  294.  
  295.    begin
  296.       if Base = 10 then
  297.          Set_Image_Width_Long_Long_Unsigned (Item, To'Length, Buf, Ptr);
  298.       else
  299.          Set_Image_Based_Long_Long_Unsigned (Item, Base, To'Length, Buf, Ptr);
  300.       end if;
  301.  
  302.       if Ptr > To'Length then
  303.          raise Layout_Error;
  304.       else
  305.          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
  306.       end if;
  307.    end Puts_LLU;
  308.  
  309. end Ada.Wide_Text_IO.Modular_Aux;
  310.