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

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --         A D A . W I D E _ T E X T _ I O . C O M P L E X _ A U X          --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.3 $                              --
  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. with Ada.Wide_Text_IO.Float_Aux;
  38.  
  39. with System.Img_Real; use System.Img_Real;
  40.  
  41. package body Ada.Wide_Text_IO.Complex_Aux is
  42.  
  43.    package Aux renames Ada.Wide_Text_IO.Float_Aux;
  44.  
  45.    ---------
  46.    -- Get --
  47.    ---------
  48.  
  49.    procedure Get
  50.      (File  : in  File_Type;
  51.       ItemR : out Long_Long_Float;
  52.       ItemI : out Long_Long_Float;
  53.       Width : Field)
  54.    is
  55.       Buf   : String (1 .. Field'Last);
  56.       Stop  : Integer := 0;
  57.       Ptr   : aliased Integer;
  58.       Paren : Boolean := False;
  59.  
  60.    begin
  61.       --  General note for following code, exceptions from the calls
  62.       --  to Get for components of the complex value are propagated.
  63.  
  64.       if Width /= 0 then
  65.          Load_Width (File, Width, Buf, Stop);
  66.          Gets (Buf (1 .. Stop), ItemR, ItemI, Ptr);
  67.  
  68.          for J in Ptr + 1 .. Stop loop
  69.             if not Is_Blank (Buf (J)) then
  70.                raise Data_Error;
  71.             end if;
  72.          end loop;
  73.  
  74.       --  Case of width = 0
  75.  
  76.       else
  77.          Load_Skip (File);
  78.          Ptr := 0;
  79.          Load (File, Buf, Ptr, '(', Paren);
  80.          Aux.Get (File, ItemR, 0);
  81.          Load_Skip (File);
  82.          Load (File, Buf, Ptr, ',');
  83.          Aux.Get (File, ItemI, 0);
  84.  
  85.          if Paren then
  86.             Load_Skip (File);
  87.             Load (File, Buf, Ptr, ')', Paren);
  88.  
  89.             if not Paren then
  90.                raise Data_Error;
  91.             end if;
  92.          end if;
  93.       end if;
  94.    end Get;
  95.  
  96.    ----------
  97.    -- Gets --
  98.    ----------
  99.  
  100.    procedure Gets
  101.      (From  : in String;
  102.       ItemR : out Long_Long_Float;
  103.       ItemI : out Long_Long_Float;
  104.       Last  : out Positive)
  105.    is
  106.       Paren : Boolean;
  107.       Pos   : Integer;
  108.  
  109.    begin
  110.       String_Skip (From, Pos);
  111.  
  112.       if From (Pos) = '(' then
  113.          Pos := Pos + 1;
  114.          Paren := True;
  115.       else
  116.          Paren := False;
  117.       end if;
  118.  
  119.       Aux.Gets (From (Pos .. From'Last), ItemR, Pos);
  120.  
  121.       String_Skip (From (Pos + 1 .. From'Last), Pos);
  122.  
  123.       if From (Pos) = ',' then
  124.          Pos := Pos + 1;
  125.       end if;
  126.  
  127.       Aux.Gets (From (Pos .. From'Last), ItemI, Pos);
  128.  
  129.       if Paren then
  130.          String_Skip (From (Pos + 1 .. From'Last), Pos);
  131.  
  132.          if From (Pos) /= ')' then
  133.             raise Data_Error;
  134.          end if;
  135.       end if;
  136.  
  137.       Last := Pos;
  138.    end Gets;
  139.  
  140.    ---------
  141.    -- Put --
  142.    ---------
  143.  
  144.    procedure Put
  145.      (File  : File_Type;
  146.       ItemR : Long_Long_Float;
  147.       ItemI : Long_Long_Float;
  148.       Fore  : Field;
  149.       Aft   : Field;
  150.       Exp   : Field)
  151.    is
  152.    begin
  153.       Put (File, '(');
  154.       Aux.Put (File, ItemR, Fore, Aft, Exp);
  155.       Put (File, ',');
  156.       Aux.Put (File, ItemI, Fore, Aft, Exp);
  157.       Put (File, ')');
  158.    end Put;
  159.  
  160.    ----------
  161.    -- Puts --
  162.    ----------
  163.  
  164.    procedure Puts
  165.      (To    : out String;
  166.       ItemR : Long_Long_Float;
  167.       ItemI : Long_Long_Float;
  168.       Aft   : in  Field;
  169.       Exp   : in  Field)
  170.    is
  171.       I_String : String (1 .. 3 * Field'Last);
  172.       R_String : String (1 .. 3 * Field'Last);
  173.  
  174.       Iptr : Natural;
  175.       Rptr : Natural;
  176.  
  177.    begin
  178.       --  Both parts are initially converted with a Fore of 0
  179.  
  180.       Rptr := 0;
  181.       Set_Image_Real (ItemR, R_String, Rptr, 0, Aft, Exp);
  182.       Iptr := 0;
  183.       Set_Image_Real (ItemI, I_String, Iptr, 0, Aft, Exp);
  184.  
  185.       --  Check room for both parts plus parens plus comma (RM G.1.3(34))
  186.  
  187.       if Rptr + Iptr + 3 > To'Length then
  188.          raise Layout_Error;
  189.       end if;
  190.  
  191.       --  If there is room, layout result according to (RM G.1.3(31-33))
  192.  
  193.       To (To'First) := '(';
  194.       To (To'First + 1 .. To'First + Rptr) := R_String (1 .. Rptr);
  195.       To (To'First + Rptr + 1) := ',';
  196.  
  197.       To (To'Last) := ')';
  198.  
  199.  
  200.       To (To'Last - Iptr .. To'Last - 1) := I_String (1 .. Iptr);
  201.  
  202.       for J in To'First + Rptr + 2 .. To'Last - Iptr - 1 loop
  203.          To (J) := ' ';
  204.       end loop;
  205.    end Puts;
  206.  
  207. end Ada.Wide_Text_IO.Complex_Aux;
  208.