Fix gdb.base/charset.exp with Clang
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / charset.c
... / ...
CommitLineData
1/* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2001-2020 Free Software Foundation, Inc.
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
9 the Free Software Foundation; either version 3 of the License, or
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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 Please email any bugs, comments, and/or additions to this file to:
21 bug-gdb@gnu.org */
22
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'
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
42
43 Feel free to extend these as you like. */
44
45#define NUM_CHARS (71)
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
52/* We make a phony wchar_t and then pretend that this platform uses
53 UTF-32 (or UTF-16, depending on the size -- same difference for the
54 purposes of this test). */
55typedef unsigned int wchar_t;
56wchar_t utf_32_string[NUM_CHARS];
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;
67
68char16_t *String16;
69char32_t *String32;
70
71/* A typedef to a typedef should also work. */
72typedef wchar_t my_wchar_t;
73my_wchar_t myvar;
74
75/* Some arrays for simple assignment tests. */
76short short_array[3];
77int int_array[3];
78long long_array[3];
79
80/* These are unsigned char so we can pass down characters >127 without
81 explicit casts or warnings. */
82
83void
84init_string (char string[],
85 unsigned char x,
86 unsigned char alert,
87 unsigned char backspace,
88 unsigned char form_feed,
89 unsigned char line_feed,
90 unsigned char carriage_return,
91 unsigned char horizontal_tab,
92 unsigned char vertical_tab,
93 unsigned char cent,
94 unsigned char misc_ctrl)
95{
96 int i;
97
98 for (i = 0; i < NUM_CHARS; ++i)
99 string[i] = x;
100 string[0] = alert;
101 string[1] = backspace;
102 string[2] = form_feed;
103 string[3] = line_feed;
104 string[4] = carriage_return;
105 string[5] = horizontal_tab;
106 string[6] = vertical_tab;
107 string[69] = cent;
108 string[70] = misc_ctrl;
109}
110
111
112void
113fill_run (char string[], int start, int len, int first)
114{
115 int i;
116
117 for (i = 0; i < len; i++)
118 string[start + i] = first + i;
119}
120
121
122void
123init_utf32 ()
124{
125 int i;
126
127 for (i = 0; i < NUM_CHARS; ++i)
128 utf_32_string[i] = iso_8859_1_string[i] & 0xff;
129}
130
131extern void malloc_stub (void);
132
133int main ()
134{
135
136 malloc_stub ();
137
138 /* Initialize ascii_string. */
139 init_string (ascii_string,
140 120,
141 7, 8, 12,
142 10, 13, 9,
143 11, 120, 17);
144 fill_run (ascii_string, 7, 26, 65);
145 fill_run (ascii_string, 33, 26, 97);
146 fill_run (ascii_string, 59, 10, 48);
147
148 /* Initialize iso_8859_1_string. */
149 init_string (iso_8859_1_string,
150 120,
151 7, 8, 12,
152 10, 13, 9,
153 11, 162, 17);
154 fill_run (iso_8859_1_string, 7, 26, 65);
155 fill_run (iso_8859_1_string, 33, 26, 97);
156 fill_run (iso_8859_1_string, 59, 10, 48);
157
158 /* Initialize ebcdic_us_string. */
159 init_string (ebcdic_us_string,
160 167,
161 47, 22, 12,
162 37, 13, 5,
163 11, 74, 17);
164 /* In EBCDIC, the upper-case letters are broken into three separate runs. */
165 fill_run (ebcdic_us_string, 7, 9, 193);
166 fill_run (ebcdic_us_string, 16, 9, 209);
167 fill_run (ebcdic_us_string, 25, 8, 226);
168 /* The lower-case letters are, too. */
169 fill_run (ebcdic_us_string, 33, 9, 129);
170 fill_run (ebcdic_us_string, 42, 9, 145);
171 fill_run (ebcdic_us_string, 51, 8, 162);
172 /* The digits, at least, are contiguous. */
173 fill_run (ebcdic_us_string, 59, 10, 240);
174
175 /* Initialize ibm1047_string. */
176 init_string (ibm1047_string,
177 167,
178 47, 22, 12,
179 37, 13, 5,
180 11, 74, 17);
181 /* In EBCDIC, the upper-case letters are broken into three separate runs. */
182 fill_run (ibm1047_string, 7, 9, 193);
183 fill_run (ibm1047_string, 16, 9, 209);
184 fill_run (ibm1047_string, 25, 8, 226);
185 /* The lower-case letters are, too. */
186 fill_run (ibm1047_string, 33, 9, 129);
187 fill_run (ibm1047_string, 42, 9, 145);
188 fill_run (ibm1047_string, 51, 8, 162);
189 /* The digits, at least, are contiguous. */
190 fill_run (ibm1047_string, 59, 10, 240);
191
192 init_utf32 ();
193
194 myvar = utf_32_string[7];
195
196 return 0; /* all strings initialized */
197}
This page took 0.030416 seconds and 4 git commands to generate.