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