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