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-tienau.adb < prev    next >
Text File  |  2000-07-19  |  9KB  |  293 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --          A D A . T E X T _ I O . E N U M E R A T I O N _ A U X           --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.14 $                             --
  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.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
  37. with Ada.Characters.Handling; use Ada.Characters.Handling;
  38. with Interfaces.C_Streams;    use Interfaces.C_Streams;
  39.  
  40. --  Note: this package does not yet deal properly with wide characters ???
  41.  
  42. package body Ada.Text_IO.Enumeration_Aux is
  43.  
  44.    --  These definitions replace the ones in Ada.Characters.Handling, which
  45.    --  do not seem to work for some strange not understood reason ??? at
  46.    --  least in the OS/2 version.
  47.  
  48.    function To_Lower (C : Character) return Character;
  49.    function To_Upper (C : Character) return Character;
  50.  
  51.    function To_Lower (C : Character) return Character is
  52.    begin
  53.       if C in 'A' .. 'Z' then
  54.          return Character'Val (Character'Pos (C) + 32);
  55.       else
  56.          return C;
  57.       end if;
  58.    end To_Lower;
  59.  
  60.    function To_Upper (C : Character) return Character is
  61.    begin
  62.       if C in 'a' .. 'z' then
  63.          return Character'Val (Character'Pos (C) - 32);
  64.       else
  65.          return C;
  66.       end if;
  67.    end To_Upper;
  68.  
  69.    ------------------
  70.    -- Get_Enum_Lit --
  71.    ------------------
  72.  
  73.    procedure Get_Enum_Lit
  74.      (File   : File_Type;
  75.       Buf    : out String;
  76.       Buflen : out Natural)
  77.    is
  78.       ch  : int;
  79.       C   : Character;
  80.  
  81.    begin
  82.       Buflen := 0;
  83.       Load_Skip (File);
  84.       ch := Getc (File);
  85.       C := Character'Val (ch);
  86.  
  87.       --  Character literal case. If the initial character is a quote, then
  88.       --  we read as far as we can without backup (see ACVC test CE3905L)
  89.  
  90.       if C = ''' then
  91.          Store_Char (File, ch, Buf, Buflen);
  92.  
  93.          ch := Getc (File);
  94.  
  95.          if ch in 16#20# .. 16#7E# or else ch >= 16#80# then
  96.             Store_Char (File, ch, Buf, Buflen);
  97.  
  98.             ch := Getc (File);
  99.  
  100.             if ch = Character'Pos (''') then
  101.                Store_Char (File, ch, Buf, Buflen);
  102.             else
  103.                Ungetc (ch, File);
  104.             end if;
  105.  
  106.          else
  107.             Ungetc (ch, File);
  108.          end if;
  109.  
  110.       --  Similarly for identifiers, read as far as we can, in particular,
  111.       --  do read a trailing underscore (again see ACVC test CE3905L to
  112.       --  understand why we do this, although it seems somewhat peculiar).
  113.  
  114.       else
  115.          --  Identifier must start with a letter
  116.  
  117.          if not Is_Letter (C) then
  118.             Ungetc (ch, File);
  119.             return;
  120.          end if;
  121.  
  122.          --  If we do have a letter, loop through the characters quitting on
  123.          --  the first non-identifier character (note that this includes the
  124.          --  cases of hitting a line mark or page mark).
  125.  
  126.          loop
  127.             C := Character'Val (ch);
  128.             Store_Char (File, Character'Pos (To_Upper (C)), Buf, Buflen);
  129.  
  130.             ch := Getc (File);
  131.             exit when ch = EOF;
  132.             C := Character'Val (ch);
  133.  
  134.             exit when not Is_Letter (C)
  135.               and then not Is_Digit (C)
  136.               and then C /= '_';
  137.  
  138.             exit when C = '_'
  139.               and then Buf (Buflen) = '_';
  140.          end loop;
  141.  
  142.          Ungetc (ch, File);
  143.       end if;
  144.    end Get_Enum_Lit;
  145.  
  146.    -------------------
  147.    -- Scan_Enum_Lit --
  148.    -------------------
  149.  
  150.    procedure Scan_Enum_Lit
  151.      (From  : String;
  152.       Start : out Natural;
  153.       Stop  : out Natural)
  154.    is
  155.       C  : Character;
  156.  
  157.    --  Processing for Scan_Enum_Lit
  158.  
  159.    begin
  160.       String_Skip (From, Start);
  161.  
  162.       --  Character literal case. If the initial character is a quote, then
  163.       --  we read as far as we can without backup (see ACVC test CE3905L
  164.       --  which is for the analogous case for reading from a file).
  165.  
  166.       if From (Start) = ''' then
  167.          Stop := Start;
  168.  
  169.          if Stop = From'Last then
  170.             raise Data_Error;
  171.          else
  172.             Stop := Stop + 1;
  173.          end if;
  174.  
  175.          if From (Stop) in ' ' .. '~'
  176.            or else From (Stop) >= Character'Val (16#80#)
  177.          then
  178.             if Stop = From'Last then
  179.                raise Data_Error;
  180.             else
  181.                Stop := Stop + 1;
  182.  
  183.                if From (Stop) = ''' then
  184.                   return;
  185.                end if;
  186.             end if;
  187.          end if;
  188.  
  189.          Stop := Stop - 1;
  190.          raise Data_Error;
  191.  
  192.       --  Similarly for identifiers, read as far as we can, in particular,
  193.       --  do read a trailing underscore (again see ACVC test CE3905L to
  194.       --  understand why we do this, although it seems somewhat peculiar).
  195.  
  196.       else
  197.          --  Identifier must start with a letter
  198.  
  199.          if not Is_Letter (From (Start)) then
  200.             raise Data_Error;
  201.          end if;
  202.  
  203.          --  If we do have a letter, loop through the characters quitting on
  204.          --  the first non-identifier character (note that this includes the
  205.          --  cases of hitting a line mark or page mark).
  206.  
  207.          Stop := Start;
  208.          while Stop < From'Last loop
  209.             C := From (Stop + 1);
  210.  
  211.             exit when not Is_Letter (C)
  212.               and then not Is_Digit (C)
  213.               and then C /= '_';
  214.  
  215.             exit when C = '_'
  216.               and then From (Stop) = '_';
  217.  
  218.             Stop := Stop + 1;
  219.          end loop;
  220.       end if;
  221.  
  222.    end Scan_Enum_Lit;
  223.  
  224.    ---------
  225.    -- Put --
  226.    ---------
  227.  
  228.    procedure Put
  229.      (File  : File_Type;
  230.       Item  : String;
  231.       Width : Field;
  232.       Set   : Type_Set)
  233.    is
  234.       Actual_Width : constant Count := Count'Max (Count (Width), Item'Length);
  235.  
  236.    begin
  237.       if Set = Lower_Case and then Item (1) /= ''' then
  238.          declare
  239.             Iteml : String (Item'First .. Item'Last);
  240.  
  241.          begin
  242.             for J in Item'Range loop
  243.                Iteml (J) := To_Lower (Item (J));
  244.             end loop;
  245.  
  246.             Put_Item (File, Iteml);
  247.          end;
  248.  
  249.       else
  250.          Put_Item (File, Item);
  251.       end if;
  252.  
  253.       for J in 1 .. Actual_Width - Item'Length loop
  254.          Put (File, ' ');
  255.       end loop;
  256.    end Put;
  257.  
  258.    ----------
  259.    -- Puts --
  260.    ----------
  261.  
  262.    procedure Puts
  263.      (To    : out String;
  264.       Item  : in String;
  265.       Set   : Type_Set)
  266.    is
  267.       Ptr : Natural;
  268.  
  269.    begin
  270.       if Item'Length > To'Length then
  271.          raise Layout_Error;
  272.  
  273.       else
  274.          Ptr := To'First;
  275.          for J in Item'Range loop
  276.             if Set = Lower_Case and then Item (1) /= ''' then
  277.                To (Ptr) := To_Lower (Item (J));
  278.             else
  279.                To (Ptr) := Item (J);
  280.             end if;
  281.  
  282.             Ptr := Ptr + 1;
  283.          end loop;
  284.  
  285.          while Ptr <= To'Last loop
  286.             To (Ptr) := ' ';
  287.             Ptr := Ptr + 1;
  288.          end loop;
  289.       end if;
  290.    end Puts;
  291.  
  292. end Ada.Text_IO.Enumeration_Aux;
  293.