gdb
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / charset.c
CommitLineData
0dcd613f
AC
1/* This testcase is part of GDB, the GNU debugger.
2
4c38e0a4 3 Copyright 2001, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
0dcd613f
AC
4
5 Contributed by Red Hat, originally written by Jim Blandy.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
0dcd613f
AC
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
a9762ec7 16
0dcd613f 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>.
0dcd613f
AC
19
20 Please email any bugs, comments, and/or additions to this file to:
21 bug-gdb@gnu.org */
dea97812 22
dea97812
KB
23/* X_string is a null-terminated string in the X charset whose
24 elements are as follows. X should be the name the `set charset'
25 command uses for the character set, in lower-case, with any
26 non-identifier characters replaced with underscores. Where a
27 character set doesn't have the given character, the string should
28 contain the character 'x'.
29
30 [0] --- the `alert' character, '\a'
31 [1] --- the `backspace' character, '\b'
0dcd613f
AC
32 [2] --- the `form feed' character, '\f'
33 [3] --- the `line feed' character, '\n'
34 [4] --- the `carriage return' character, '\r'
35 [5] --- the `horizontal tab' character, '\t'
36 [6] --- the `vertical tab' character, '\v'
37 [7 .. 32] --- the uppercase letters A-Z
38 [33 .. 58] --- the lowercase letters a-z
39 [59 .. 68] --- the digits 0-9
40 [69] --- the `cent' character
41 [70] --- a control character with no defined backslash escape
dea97812
KB
42
43 Feel free to extend these as you like. */
44
0dcd613f 45#define NUM_CHARS (71)
dea97812
KB
46
47char ascii_string[NUM_CHARS];
48char iso_8859_1_string[NUM_CHARS];
49char ebcdic_us_string[NUM_CHARS];
50char ibm1047_string[NUM_CHARS];
51
6c7a06a3 52/* We make a phony wchar_t and then pretend that this platform uses
b8899f2b 53 UTF-32 (or UTF-16, depending on the size -- same difference for the
6c7a06a3
TT
54 purposes of this test). */
55typedef unsigned int wchar_t;
b8899f2b 56wchar_t utf_32_string[NUM_CHARS];
6c7a06a3
TT
57
58/* We also define a couple phony types for testing the u'' and U''
59 support. It is ok if these have the wrong size on some platforms
60 -- the test case will skip the tests in that case. */
61typedef unsigned short char16_t;
62typedef unsigned int char32_t;
63
64/* Make sure to use the typedefs. */
65char16_t uvar;
66char32_t Uvar;
dea97812 67
9a22f0d0
PM
68char16_t *String16;
69char32_t *String32;
70
85e306ed
TT
71/* A typedef to a typedef should also work. */
72typedef wchar_t my_wchar_t;
73my_wchar_t myvar;
74
dea97812
KB
75void
76init_string (char string[],
77 char x,
0dcd613f 78 char alert, char backspace, char form_feed,
dea97812
KB
79 char line_feed, char carriage_return, char horizontal_tab,
80 char vertical_tab, char cent, char misc_ctrl)
81{
6c7a06a3
TT
82 int i;
83
84 for (i = 0; i < NUM_CHARS; ++i)
85 string[i] = x;
dea97812
KB
86 string[0] = alert;
87 string[1] = backspace;
0dcd613f
AC
88 string[2] = form_feed;
89 string[3] = line_feed;
90 string[4] = carriage_return;
91 string[5] = horizontal_tab;
92 string[6] = vertical_tab;
93 string[69] = cent;
94 string[70] = misc_ctrl;
dea97812
KB
95}
96
97
98void
99fill_run (char string[], int start, int len, int first)
100{
101 int i;
102
103 for (i = 0; i < len; i++)
104 string[start + i] = first + i;
105}
106
107
6c7a06a3 108void
b8899f2b 109init_utf32 ()
6c7a06a3
TT
110{
111 int i;
112
113 for (i = 0; i < NUM_CHARS; ++i)
b8899f2b 114 utf_32_string[i] = iso_8859_1_string[i] & 0xff;
6c7a06a3
TT
115}
116
dea97812
KB
117int main ()
118{
119#ifdef usestubs
120 set_debug_traps();
121 breakpoint();
122#endif
dea97812
KB
123 /* Initialize ascii_string. */
124 init_string (ascii_string,
125 120,
0dcd613f 126 7, 8, 12,
dea97812
KB
127 10, 13, 9,
128 11, 120, 17);
0dcd613f
AC
129 fill_run (ascii_string, 7, 26, 65);
130 fill_run (ascii_string, 33, 26, 97);
131 fill_run (ascii_string, 59, 10, 48);
dea97812
KB
132
133 /* Initialize iso_8859_1_string. */
134 init_string (iso_8859_1_string,
135 120,
0dcd613f 136 7, 8, 12,
dea97812
KB
137 10, 13, 9,
138 11, 162, 17);
0dcd613f
AC
139 fill_run (iso_8859_1_string, 7, 26, 65);
140 fill_run (iso_8859_1_string, 33, 26, 97);
141 fill_run (iso_8859_1_string, 59, 10, 48);
dea97812
KB
142
143 /* Initialize ebcdic_us_string. */
144 init_string (ebcdic_us_string,
145 167,
0dcd613f 146 47, 22, 12,
dea97812
KB
147 37, 13, 5,
148 11, 74, 17);
149 /* In EBCDIC, the upper-case letters are broken into three separate runs. */
0dcd613f
AC
150 fill_run (ebcdic_us_string, 7, 9, 193);
151 fill_run (ebcdic_us_string, 16, 9, 209);
152 fill_run (ebcdic_us_string, 25, 8, 226);
dea97812 153 /* The lower-case letters are, too. */
0dcd613f
AC
154 fill_run (ebcdic_us_string, 33, 9, 129);
155 fill_run (ebcdic_us_string, 42, 9, 145);
156 fill_run (ebcdic_us_string, 51, 8, 162);
dea97812 157 /* The digits, at least, are contiguous. */
0dcd613f 158 fill_run (ebcdic_us_string, 59, 10, 240);
dea97812
KB
159
160 /* Initialize ibm1047_string. */
161 init_string (ibm1047_string,
162 167,
0dcd613f 163 47, 22, 12,
dea97812
KB
164 37, 13, 5,
165 11, 74, 17);
166 /* In EBCDIC, the upper-case letters are broken into three separate runs. */
0dcd613f
AC
167 fill_run (ibm1047_string, 7, 9, 193);
168 fill_run (ibm1047_string, 16, 9, 209);
169 fill_run (ibm1047_string, 25, 8, 226);
dea97812 170 /* The lower-case letters are, too. */
0dcd613f
AC
171 fill_run (ibm1047_string, 33, 9, 129);
172 fill_run (ibm1047_string, 42, 9, 145);
173 fill_run (ibm1047_string, 51, 8, 162);
dea97812 174 /* The digits, at least, are contiguous. */
0dcd613f 175 fill_run (ibm1047_string, 59, 10, 240);
dea97812 176
b8899f2b 177 init_utf32 ();
6c7a06a3 178
b8899f2b 179 myvar = utf_32_string[7];
85e306ed 180
6c7a06a3 181 return 0; /* all strings initialized */
dea97812 182}
This page took 0.748364 seconds and 4 git commands to generate.