OSDN Git Service

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