]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/charset.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / charset.c
CommitLineData
0dcd613f
AC
1/* This testcase is part of GDB, the GNU debugger.
2
1d506c26 3 Copyright 2001-2024 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 46
e31cf164
TY
47char ascii_string[NUM_CHARS];
48char iso_8859_1_string[NUM_CHARS];
49char ebcdic_us_string[NUM_CHARS];
50char ibm1047_string[NUM_CHARS];
dea97812 51
c3e5138d
PA
52#ifndef __cplusplus
53
6c7a06a3 54/* We make a phony wchar_t and then pretend that this platform uses
b8899f2b 55 UTF-32 (or UTF-16, depending on the size -- same difference for the
6c7a06a3
TT
56 purposes of this test). */
57typedef unsigned int wchar_t;
6c7a06a3
TT
58
59/* We also define a couple phony types for testing the u'' and U''
60 support. It is ok if these have the wrong size on some platforms
61 -- the test case will skip the tests in that case. */
62typedef unsigned short char16_t;
63typedef unsigned int char32_t;
64
c3e5138d
PA
65#endif
66
67wchar_t utf_32_string[NUM_CHARS];
68
6c7a06a3
TT
69/* Make sure to use the typedefs. */
70char16_t uvar;
71char32_t Uvar;
dea97812 72
9a22f0d0
PM
73char16_t *String16;
74char32_t *String32;
75
85e306ed
TT
76/* A typedef to a typedef should also work. */
77typedef wchar_t my_wchar_t;
78my_wchar_t myvar;
79
c50491a7
TT
80/* Some arrays for simple assignment tests. */
81short short_array[3];
82int int_array[3];
83long long_array[3];
84
bf90c83a
PA
85/* These are unsigned char so we can pass down characters >127 without
86 explicit casts or warnings. */
87
dea97812 88void
e31cf164 89init_string (char string[],
bf90c83a
PA
90 unsigned char x,
91 unsigned char alert,
92 unsigned char backspace,
93 unsigned char form_feed,
94 unsigned char line_feed,
95 unsigned char carriage_return,
96 unsigned char horizontal_tab,
97 unsigned char vertical_tab,
98 unsigned char cent,
99 unsigned char misc_ctrl)
dea97812 100{
6c7a06a3
TT
101 int i;
102
103 for (i = 0; i < NUM_CHARS; ++i)
104 string[i] = x;
dea97812
KB
105 string[0] = alert;
106 string[1] = backspace;
0dcd613f
AC
107 string[2] = form_feed;
108 string[3] = line_feed;
109 string[4] = carriage_return;
110 string[5] = horizontal_tab;
111 string[6] = vertical_tab;
112 string[69] = cent;
113 string[70] = misc_ctrl;
dea97812
KB
114}
115
116
117void
e31cf164 118fill_run (char string[], int start, int len, int first)
dea97812
KB
119{
120 int i;
121
122 for (i = 0; i < len; i++)
123 string[start + i] = first + i;
124}
125
126
6c7a06a3 127void
b8899f2b 128init_utf32 ()
6c7a06a3
TT
129{
130 int i;
131
132 for (i = 0; i < NUM_CHARS; ++i)
b8899f2b 133 utf_32_string[i] = iso_8859_1_string[i] & 0xff;
6c7a06a3
TT
134}
135
51d7d803
JK
136extern void malloc_stub (void);
137
dea97812
KB
138int main ()
139{
02e6fe6a 140
51d7d803 141 malloc_stub ();
02e6fe6a 142
dea97812
KB
143 /* Initialize ascii_string. */
144 init_string (ascii_string,
145 120,
0dcd613f 146 7, 8, 12,
dea97812
KB
147 10, 13, 9,
148 11, 120, 17);
0dcd613f
AC
149 fill_run (ascii_string, 7, 26, 65);
150 fill_run (ascii_string, 33, 26, 97);
151 fill_run (ascii_string, 59, 10, 48);
dea97812
KB
152
153 /* Initialize iso_8859_1_string. */
154 init_string (iso_8859_1_string,
155 120,
0dcd613f 156 7, 8, 12,
dea97812
KB
157 10, 13, 9,
158 11, 162, 17);
0dcd613f
AC
159 fill_run (iso_8859_1_string, 7, 26, 65);
160 fill_run (iso_8859_1_string, 33, 26, 97);
161 fill_run (iso_8859_1_string, 59, 10, 48);
dea97812
KB
162
163 /* Initialize ebcdic_us_string. */
164 init_string (ebcdic_us_string,
165 167,
0dcd613f 166 47, 22, 12,
dea97812
KB
167 37, 13, 5,
168 11, 74, 17);
169 /* In EBCDIC, the upper-case letters are broken into three separate runs. */
0dcd613f
AC
170 fill_run (ebcdic_us_string, 7, 9, 193);
171 fill_run (ebcdic_us_string, 16, 9, 209);
172 fill_run (ebcdic_us_string, 25, 8, 226);
dea97812 173 /* The lower-case letters are, too. */
0dcd613f
AC
174 fill_run (ebcdic_us_string, 33, 9, 129);
175 fill_run (ebcdic_us_string, 42, 9, 145);
176 fill_run (ebcdic_us_string, 51, 8, 162);
dea97812 177 /* The digits, at least, are contiguous. */
0dcd613f 178 fill_run (ebcdic_us_string, 59, 10, 240);
dea97812
KB
179
180 /* Initialize ibm1047_string. */
181 init_string (ibm1047_string,
182 167,
0dcd613f 183 47, 22, 12,
dea97812
KB
184 37, 13, 5,
185 11, 74, 17);
295114a6 186 /* In IBM1047, the upper-case letters are broken into three separate runs. */
0dcd613f
AC
187 fill_run (ibm1047_string, 7, 9, 193);
188 fill_run (ibm1047_string, 16, 9, 209);
189 fill_run (ibm1047_string, 25, 8, 226);
dea97812 190 /* The lower-case letters are, too. */
0dcd613f
AC
191 fill_run (ibm1047_string, 33, 9, 129);
192 fill_run (ibm1047_string, 42, 9, 145);
193 fill_run (ibm1047_string, 51, 8, 162);
dea97812 194 /* The digits, at least, are contiguous. */
0dcd613f 195 fill_run (ibm1047_string, 59, 10, 240);
dea97812 196
b8899f2b 197 init_utf32 ();
6c7a06a3 198
b8899f2b 199 myvar = utf_32_string[7];
85e306ed 200
6c7a06a3 201 return 0; /* all strings initialized */
dea97812 202}