OSDN Git Service

Fix aliasing bug that also caused memory usage problems.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-imgcha.adb
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 --     Copyright (C) 1992,1993,1994,1995 Free Software Foundation, Inc.     --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 package body System.Img_Char is
35
36    ---------------------
37    -- Image_Character --
38    ---------------------
39
40    function Image_Character (V : Character) return String is
41       subtype Cname is String (1 .. 3);
42
43       S : Cname;
44
45       subtype C0_Range is Character
46         range Character'Val (16#00#) .. Character'Val (16#1F#);
47
48       C0 : constant array (C0_Range) of Cname :=
49               (Character'Val (16#00#) => "NUL",
50                Character'Val (16#01#) => "SOH",
51                Character'Val (16#02#) => "STX",
52                Character'Val (16#03#) => "ETX",
53                Character'Val (16#04#) => "EOT",
54                Character'Val (16#05#) => "ENQ",
55                Character'Val (16#06#) => "ACK",
56                Character'Val (16#07#) => "BEL",
57                Character'Val (16#08#) => "BS ",
58                Character'Val (16#09#) => "HT ",
59                Character'Val (16#0A#) => "LF ",
60                Character'Val (16#0B#) => "VT ",
61                Character'Val (16#0C#) => "FF ",
62                Character'Val (16#0D#) => "CR ",
63                Character'Val (16#0E#) => "SO ",
64                Character'Val (16#0F#) => "SI ",
65                Character'Val (16#10#) => "DLE",
66                Character'Val (16#11#) => "DC1",
67                Character'Val (16#12#) => "DC2",
68                Character'Val (16#13#) => "DC3",
69                Character'Val (16#14#) => "DC4",
70                Character'Val (16#15#) => "NAK",
71                Character'Val (16#16#) => "SYN",
72                Character'Val (16#17#) => "ETB",
73                Character'Val (16#18#) => "CAN",
74                Character'Val (16#19#) => "EM ",
75                Character'Val (16#1A#) => "SUB",
76                Character'Val (16#1B#) => "ESC",
77                Character'Val (16#1C#) => "FS ",
78                Character'Val (16#1D#) => "GS ",
79                Character'Val (16#1E#) => "RS ",
80                Character'Val (16#1F#) => "US ");
81
82       subtype C1_Range is Character
83         range Character'Val (16#7F#) .. Character'Val (16#9F#);
84
85       C1 : constant array (C1_Range) of Cname :=
86               (Character'Val (16#7F#) => "DEL",
87                Character'Val (16#80#) => "res",
88                Character'Val (16#81#) => "res",
89                Character'Val (16#82#) => "BPH",
90                Character'Val (16#83#) => "NBH",
91                Character'Val (16#84#) => "res",
92                Character'Val (16#85#) => "NEL",
93                Character'Val (16#86#) => "SSA",
94                Character'Val (16#87#) => "ESA",
95                Character'Val (16#88#) => "HTS",
96                Character'Val (16#89#) => "HTJ",
97                Character'Val (16#8A#) => "VTS",
98                Character'Val (16#8B#) => "PLD",
99                Character'Val (16#8C#) => "PLU",
100                Character'Val (16#8D#) => "RI ",
101                Character'Val (16#8E#) => "SS2",
102                Character'Val (16#8F#) => "SS3",
103                Character'Val (16#90#) => "DCS",
104                Character'Val (16#91#) => "PU1",
105                Character'Val (16#92#) => "PU2",
106                Character'Val (16#93#) => "STS",
107                Character'Val (16#94#) => "CCH",
108                Character'Val (16#95#) => "MW ",
109                Character'Val (16#96#) => "SPA",
110                Character'Val (16#97#) => "EPA",
111                Character'Val (16#98#) => "SOS",
112                Character'Val (16#99#) => "res",
113                Character'Val (16#9A#) => "SCI",
114                Character'Val (16#9B#) => "CSI",
115                Character'Val (16#9C#) => "ST ",
116                Character'Val (16#9D#) => "OSC",
117                Character'Val (16#9E#) => "PM ",
118                Character'Val (16#9F#) => "APC");
119
120    begin
121       --  Control characters are represented by their names (RM 3.5(32))
122
123       if V in C0_Range then
124          S := C0 (V);
125
126          if S (3) = ' ' then
127             return S (1 .. 2);
128          else
129             return S;
130          end if;
131
132       elsif V in C1_Range then
133          S := C1 (V);
134
135          if S (1) /= 'r' then
136             if S (3) = ' ' then
137                return S (1 .. 2);
138             else
139                return S;
140             end if;
141
142          --  Special case, res means RESERVED_nnn where nnn is the three digit
143          --  decimal value corresponding to the code position (more efficient
144          --  to compute than to store!)
145
146          else
147             declare
148                VP : constant Natural := Character'Pos (V);
149                St : String (1 .. 12) := "RESERVED_xxx";
150
151             begin
152                St (10) := Character'Val (48 + VP / 100);
153                St (11) := Character'Val (48 + (VP / 10) mod 10);
154                St (12) := Character'Val (48 + VP mod 10);
155                return St;
156             end;
157          end if;
158
159       --  Normal characters yield the character enlosed in quotes (RM 3.5(32))
160
161       else
162          S (1) := ''';
163          S (2) := V;
164          S (3) := ''';
165          return S;
166       end if;
167    end Image_Character;
168
169 end System.Img_Char;