gdb:
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / charset.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2001, 2004, 2007, 2008, 2009 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
47 char ascii_string[NUM_CHARS];
48 char iso_8859_1_string[NUM_CHARS];
49 char ebcdic_us_string[NUM_CHARS];
50 char ibm1047_string[NUM_CHARS];
51
52 /* We make a phony wchar_t and then pretend that this platform uses
53 UCS-4 (or UCS-2, depending on the size -- same difference for the
54 purposes of this test). */
55 typedef unsigned int wchar_t;
56 wchar_t ucs_4_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. */
61 typedef unsigned short char16_t;
62 typedef unsigned int char32_t;
63
64 /* Make sure to use the typedefs. */
65 char16_t uvar;
66 char32_t Uvar;
67
68 void
69 init_string (char string[],
70 char x,
71 char alert, char backspace, char form_feed,
72 char line_feed, char carriage_return, char horizontal_tab,
73 char vertical_tab, char cent, char misc_ctrl)
74 {
75 int i;
76
77 for (i = 0; i < NUM_CHARS; ++i)
78 string[i] = x;
79 string[0] = alert;
80 string[1] = backspace;
81 string[2] = form_feed;
82 string[3] = line_feed;
83 string[4] = carriage_return;
84 string[5] = horizontal_tab;
85 string[6] = vertical_tab;
86 string[69] = cent;
87 string[70] = misc_ctrl;
88 }
89
90
91 void
92 fill_run (char string[], int start, int len, int first)
93 {
94 int i;
95
96 for (i = 0; i < len; i++)
97 string[start + i] = first + i;
98 }
99
100
101 void
102 init_ucs4 ()
103 {
104 int i;
105
106 for (i = 0; i < NUM_CHARS; ++i)
107 ucs_4_string[i] = iso_8859_1_string[i] & 0xff;
108 }
109
110 int main ()
111 {
112 #ifdef usestubs
113 set_debug_traps();
114 breakpoint();
115 #endif
116 /* Initialize ascii_string. */
117 init_string (ascii_string,
118 120,
119 7, 8, 12,
120 10, 13, 9,
121 11, 120, 17);
122 fill_run (ascii_string, 7, 26, 65);
123 fill_run (ascii_string, 33, 26, 97);
124 fill_run (ascii_string, 59, 10, 48);
125
126 /* Initialize iso_8859_1_string. */
127 init_string (iso_8859_1_string,
128 120,
129 7, 8, 12,
130 10, 13, 9,
131 11, 162, 17);
132 fill_run (iso_8859_1_string, 7, 26, 65);
133 fill_run (iso_8859_1_string, 33, 26, 97);
134 fill_run (iso_8859_1_string, 59, 10, 48);
135
136 /* Initialize ebcdic_us_string. */
137 init_string (ebcdic_us_string,
138 167,
139 47, 22, 12,
140 37, 13, 5,
141 11, 74, 17);
142 /* In EBCDIC, the upper-case letters are broken into three separate runs. */
143 fill_run (ebcdic_us_string, 7, 9, 193);
144 fill_run (ebcdic_us_string, 16, 9, 209);
145 fill_run (ebcdic_us_string, 25, 8, 226);
146 /* The lower-case letters are, too. */
147 fill_run (ebcdic_us_string, 33, 9, 129);
148 fill_run (ebcdic_us_string, 42, 9, 145);
149 fill_run (ebcdic_us_string, 51, 8, 162);
150 /* The digits, at least, are contiguous. */
151 fill_run (ebcdic_us_string, 59, 10, 240);
152
153 /* Initialize ibm1047_string. */
154 init_string (ibm1047_string,
155 167,
156 47, 22, 12,
157 37, 13, 5,
158 11, 74, 17);
159 /* In EBCDIC, the upper-case letters are broken into three separate runs. */
160 fill_run (ibm1047_string, 7, 9, 193);
161 fill_run (ibm1047_string, 16, 9, 209);
162 fill_run (ibm1047_string, 25, 8, 226);
163 /* The lower-case letters are, too. */
164 fill_run (ibm1047_string, 33, 9, 129);
165 fill_run (ibm1047_string, 42, 9, 145);
166 fill_run (ibm1047_string, 51, 8, 162);
167 /* The digits, at least, are contiguous. */
168 fill_run (ibm1047_string, 59, 10, 240);
169
170 init_ucs4 ();
171
172 return 0; /* all strings initialized */
173 }
This page took 0.038522 seconds and 4 git commands to generate.