a7b71238c5f0cb7f09ab41c44987d1c3c0b4c6af
[platform/upstream/binutils.git] / gdb / testsuite / gdb.base / charset.c
1 /* Test GDB's character set support
2    Jim Blandy <jimb@cygnus.com> --- December 2001 */
3
4 #include <stdio.h>
5 #include <string.h>
6
7
8 /* X_string is a null-terminated string in the X charset whose
9    elements are as follows.  X should be the name the `set charset'
10    command uses for the character set, in lower-case, with any
11    non-identifier characters replaced with underscores.  Where a
12    character set doesn't have the given character, the string should
13    contain the character 'x'.
14
15    [0] --- the `alert' character, '\a'
16    [1] --- the `backspace' character, '\b'
17    [2] --- the `escape' character, '\e'
18    [3] --- the `form feed' character, '\f'
19    [4] --- the `line feed' character, '\n'
20    [5] --- the `carriage return' character, '\r'
21    [6] --- the `horizontal tab' character, '\t'
22    [7] --- the `vertical tab' character, '\v'
23    [8  .. 33] --- the uppercase letters A-Z
24    [34 .. 59] --- the lowercase letters a-z
25    [60 .. 69] --- the digits 0-9
26    [70] --- the `cent' character
27    [71] --- a control character with no defined backslash escape
28
29    Feel free to extend these as you like.  */
30
31 #define NUM_CHARS (72)
32
33 char ascii_string[NUM_CHARS];
34 char iso_8859_1_string[NUM_CHARS];
35 char ebcdic_us_string[NUM_CHARS];
36 char ibm1047_string[NUM_CHARS];
37
38
39 void
40 init_string (char string[],
41              char x,
42              char alert, char backspace, char escape, char form_feed,
43              char line_feed, char carriage_return, char horizontal_tab,
44              char vertical_tab, char cent, char misc_ctrl)
45 {
46   memset (string, x, NUM_CHARS);
47   string[0] = alert;
48   string[1] = backspace;
49   string[2] = escape;
50   string[3] = form_feed;
51   string[4] = line_feed;
52   string[5] = carriage_return;
53   string[6] = horizontal_tab;
54   string[7] = vertical_tab;
55   string[70] = cent;
56   string[71] = misc_ctrl;
57 }
58
59
60 void
61 fill_run (char string[], int start, int len, int first)
62 {
63   int i;
64
65   for (i = 0; i < len; i++)
66     string[start + i] = first + i;
67 }
68
69
70 int main ()
71 {
72 #ifdef usestubs
73   set_debug_traps();
74   breakpoint();
75 #endif
76   (void) malloc (1);
77   /* Initialize ascii_string.  */
78   init_string (ascii_string,
79                120,
80                7, 8, 27, 12,
81                10, 13, 9,
82                11, 120, 17);
83   fill_run (ascii_string, 8, 26, 65);
84   fill_run (ascii_string, 34, 26, 97);
85   fill_run (ascii_string, 60, 10, 48);
86
87   /* Initialize iso_8859_1_string.  */
88   init_string (iso_8859_1_string,
89                120,
90                7, 8, 27, 12,
91                10, 13, 9,
92                11, 162, 17);
93   fill_run (iso_8859_1_string, 8, 26, 65);
94   fill_run (iso_8859_1_string, 34, 26, 97);
95   fill_run (iso_8859_1_string, 60, 10, 48);
96
97   /* Initialize ebcdic_us_string.  */
98   init_string (ebcdic_us_string,
99                167,
100                47, 22, 39, 12,
101                37, 13, 5,
102                11, 74, 17);
103   /* In EBCDIC, the upper-case letters are broken into three separate runs.  */
104   fill_run (ebcdic_us_string, 8, 9, 193);
105   fill_run (ebcdic_us_string, 17, 9, 209);
106   fill_run (ebcdic_us_string, 26, 8, 226);
107   /* The lower-case letters are, too.  */
108   fill_run (ebcdic_us_string, 34, 9, 129);
109   fill_run (ebcdic_us_string, 43, 9, 145);
110   fill_run (ebcdic_us_string, 52, 8, 162);
111   /* The digits, at least, are contiguous.  */
112   fill_run (ebcdic_us_string, 60, 10, 240);
113
114   /* Initialize ibm1047_string.  */
115   init_string (ibm1047_string,
116                167,
117                47, 22, 39, 12,
118                37, 13, 5,
119                11, 74, 17);
120   /* In EBCDIC, the upper-case letters are broken into three separate runs.  */
121   fill_run (ibm1047_string, 8, 9, 193);
122   fill_run (ibm1047_string, 17, 9, 209);
123   fill_run (ibm1047_string, 26, 8, 226);
124   /* The lower-case letters are, too.  */
125   fill_run (ibm1047_string, 34, 9, 129);
126   fill_run (ibm1047_string, 43, 9, 145);
127   fill_run (ibm1047_string, 52, 8, 162);
128   /* The digits, at least, are contiguous.  */
129   fill_run (ibm1047_string, 60, 10, 240);
130
131   puts ("All set!");            /* all strings initialized */
132 }