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 / s-imgcha.adb < prev    next >
Text File  |  2000-07-19  |  8KB  |  172 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                      S Y S T E M . I M G _ C H A R                       --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.11 $                             --
  10. --                                                                          --
  11. --     Copyright (C) 1992,1993,1994,1995 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. package body System.Img_Char is
  37.  
  38.    ---------------------
  39.    -- Image_Character --
  40.    ---------------------
  41.  
  42.    function Image_Character (V : Character) return String is
  43.       subtype Cname is String (1 .. 3);
  44.  
  45.       S : Cname;
  46.  
  47.       subtype C0_Range is Character
  48.         range Character'Val (16#00#) .. Character'Val (16#1F#);
  49.  
  50.       C0 : constant array (C0_Range) of Cname :=
  51.               (Character'Val (16#00#) => "NUL",
  52.                Character'Val (16#01#) => "SOH",
  53.                Character'Val (16#02#) => "STX",
  54.                Character'Val (16#03#) => "ETX",
  55.                Character'Val (16#04#) => "EOT",
  56.                Character'Val (16#05#) => "ENQ",
  57.                Character'Val (16#06#) => "ACK",
  58.                Character'Val (16#07#) => "BEL",
  59.                Character'Val (16#08#) => "BS ",
  60.                Character'Val (16#09#) => "HT ",
  61.                Character'Val (16#0A#) => "LF ",
  62.                Character'Val (16#0B#) => "VT ",
  63.                Character'Val (16#0C#) => "FF ",
  64.                Character'Val (16#0D#) => "CR ",
  65.                Character'Val (16#0E#) => "SO ",
  66.                Character'Val (16#0F#) => "SI ",
  67.                Character'Val (16#10#) => "DLE",
  68.                Character'Val (16#11#) => "DC1",
  69.                Character'Val (16#12#) => "DC2",
  70.                Character'Val (16#13#) => "DC3",
  71.                Character'Val (16#14#) => "DC4",
  72.                Character'Val (16#15#) => "NAK",
  73.                Character'Val (16#16#) => "SYN",
  74.                Character'Val (16#17#) => "ETB",
  75.                Character'Val (16#18#) => "CAN",
  76.                Character'Val (16#19#) => "EM ",
  77.                Character'Val (16#1A#) => "SUB",
  78.                Character'Val (16#1B#) => "ESC",
  79.                Character'Val (16#1C#) => "FS ",
  80.                Character'Val (16#1D#) => "GS ",
  81.                Character'Val (16#1E#) => "RS ",
  82.                Character'Val (16#1F#) => "US ");
  83.  
  84.       subtype C1_Range is Character
  85.         range Character'Val (16#7F#) .. Character'Val (16#9F#);
  86.  
  87.       C1 : constant array (C1_Range) of Cname :=
  88.               (Character'Val (16#7F#) => "DEL",
  89.                Character'Val (16#80#) => "res",
  90.                Character'Val (16#81#) => "res",
  91.                Character'Val (16#82#) => "BPH",
  92.                Character'Val (16#83#) => "NBH",
  93.                Character'Val (16#84#) => "res",
  94.                Character'Val (16#85#) => "NEL",
  95.                Character'Val (16#86#) => "SSA",
  96.                Character'Val (16#87#) => "ESA",
  97.                Character'Val (16#88#) => "HTS",
  98.                Character'Val (16#89#) => "HTJ",
  99.                Character'Val (16#8A#) => "VTS",
  100.                Character'Val (16#8B#) => "PLD",
  101.                Character'Val (16#8C#) => "PLU",
  102.                Character'Val (16#8D#) => "RI ",
  103.                Character'Val (16#8E#) => "SS2",
  104.                Character'Val (16#8F#) => "SS3",
  105.                Character'Val (16#90#) => "DCS",
  106.                Character'Val (16#91#) => "PU1",
  107.                Character'Val (16#92#) => "PU2",
  108.                Character'Val (16#93#) => "STS",
  109.                Character'Val (16#94#) => "CCH",
  110.                Character'Val (16#95#) => "MW ",
  111.                Character'Val (16#96#) => "SPA",
  112.                Character'Val (16#97#) => "EPA",
  113.                Character'Val (16#98#) => "SOS",
  114.                Character'Val (16#99#) => "res",
  115.                Character'Val (16#9A#) => "SCI",
  116.                Character'Val (16#9B#) => "CSI",
  117.                Character'Val (16#9C#) => "ST ",
  118.                Character'Val (16#9D#) => "OSC",
  119.                Character'Val (16#9E#) => "PM ",
  120.                Character'Val (16#9F#) => "APC");
  121.  
  122.    begin
  123.       --  Control characters are represented by their names (RM 3.5(32))
  124.  
  125.       if V in C0_Range then
  126.          S := C0 (V);
  127.  
  128.          if S (3) = ' ' then
  129.             return S (1 .. 2);
  130.          else
  131.             return S;
  132.          end if;
  133.  
  134.       elsif V in C1_Range then
  135.          S := C1 (V);
  136.  
  137.          if S (1) /= 'r' then
  138.             if S (3) = ' ' then
  139.                return S (1 .. 2);
  140.             else
  141.                return S;
  142.             end if;
  143.  
  144.          --  Special case, res means RESERVED_nnn where nnn is the three digit
  145.          --  decimal value corresponding to the code position (more efficient
  146.          --  to compute than to store!)
  147.  
  148.          else
  149.             declare
  150.                VP : constant Natural := Character'Pos (V);
  151.                St : String (1 .. 12) := "RESERVED_xxx";
  152.  
  153.             begin
  154.                St (10) := Character'Val (48 + VP / 100);
  155.                St (11) := Character'Val (48 + (VP / 10) mod 10);
  156.                St (12) := Character'Val (48 + VP mod 10);
  157.                return St;
  158.             end;
  159.          end if;
  160.  
  161.       --  Normal characters yield the character enlosed in quotes (RM 3.5(32))
  162.  
  163.       else
  164.          S (1) := ''';
  165.          S (2) := V;
  166.          S (3) := ''';
  167.          return S;
  168.       end if;
  169.    end Image_Character;
  170.  
  171. end System.Img_Char;
  172.