]> git.sur5r.net Git - cc65/blob - test/val/cq243.c
remote TABs in doc/ and test/
[cc65] / test / val / cq243.c
1 /*
2   !!DESCRIPTION!! C-Manual Chapter 2.43: character constants
3   !!ORIGIN!!      LCC 4.1 Testsuite
4   !!LICENCE!!     own, freely distributeable for non-profit. read CPYRIGHT.LCC
5 */
6
7 #include "common.h"
8
9 struct defs {
10      int cbits;          /* No. of bits per char           */
11      int ibits;          /*                 int            */
12      int sbits;          /*                 short          */
13      int lbits;          /*                 long           */
14      int ubits;          /*                 unsigned       */
15      int fbits;          /*                 float          */
16      int dbits;          /*                 double         */
17      #ifndef NO_FLOATS
18         float fprec;        /* Smallest number that can be    */
19         float dprec;        /* significantly added to 1.      */
20      #endif
21      int flgs;           /* Print return codes, by section */
22      int flgm;           /* Announce machine dependencies  */
23      int flgd;           /* give explicit diagnostics      */
24      int flgl;           /* Report local return codes.     */
25      int rrc;            /* recent return code             */
26      int crc;            /* Cumulative return code         */
27      char rfs[8];        /* Return from section            */
28 };
29
30      int lbits;          /*                 long           */
31      int ubits;          /*                 unsigned       */
32      int fbits;          /*                 float          */
33      int dbits;          /*                 double         */
34      #ifndef NO_FLOATS
35         float fprec;        /* Smallest number that can be    */
36         float dprec;        /* significantly added to 1.      */
37      #endif
38      int flgs;           /* Print return codes, by section */
39      int flgm;           /* Announce machine dependencies  */
40      int flgd;           /* give explicit diagnostics      */
41      int flgl;           /* Report local return codes.     */
42      int rrc;            /* recent return code             */
43      int crc;            /* Cumulative return code         */
44      char rfs[8];        /* Return from section            */
45
46 /*********************************************************************************************
47         2.4.3 Character constants
48 **********************************************************************************************/
49
50 #ifndef NO_OLD_FUNC_DECL
51 zerofill(x)
52 char *x;
53 {
54 #else
55 void zerofill(char *x) {
56 #endif
57    int j;
58
59    for (j=0; j<256; j++) *x++ = 0;
60 }
61
62 #ifndef NO_OLD_FUNC_DECL
63 sumof(x)
64 char *x;
65 {
66 #else
67 int sumof(char *x) {
68 #endif
69    char *p;
70    int total, j;
71
72    p = x;
73    total = 0;
74
75    for(j=0; j<256; j++) total = total+ *p++;
76    return total;
77 }
78
79 char chars[256];
80
81 #ifndef NO_OLD_FUNC_DECL
82 s243(pd0)
83 struct defs *pd0;
84 {
85 #else
86 int s243(struct defs *pd0) {
87 #endif
88    static char s243er[] = "s243,er%d\n";
89    static char qs243[8] = "s243   ";
90    char *ps, *pt;
91    int rc;
92 /*   char chars[256]; */
93
94    rc = 0;
95    ps = qs243;
96    pt = pd0->rfs;
97    while(*pt++ = *ps++);
98
99      /* One of the problems that arises when testing character constants
100         is that of definition: What, exactly, is the character set?
101         In order to guarantee a certain amount of machine independence,
102         the character set we will use here is the set of characters writ-
103         able as escape sequences in C, plus those characters used in writ-
104         ing C programs, i.e.,
105
106         letters:
107                    ABCDEFGHIJKLMNOPQRSTUVWXYZ      26
108                    abcdefghijklmnopqrstuvwxyz      26
109         numbers:
110                    0123456789                      10
111         special characters:
112                    ~!"#%&()_=-^|{}[]+;*:<>,.?/     27
113         extra special characters:
114                    newline           \n
115                    horizontal tab    \t
116                    backspace         \b
117                    carriage return   \r
118                    form feed         \f
119                    backslash         \\
120                    single quote      \'             7
121         blank & NUL                                 2
122                                                   ---
123                                                    98
124
125         Any specific implementation of C may of course support additional
126         characters.                                       */
127
128         /* Since the value of a character constant is the numerical value
129            of the character in the machine's character set, there should
130            be a one-to-one correspondence between characters and values. */
131
132    zerofill(chars);
133
134    chars['a'] = 1;   chars['A'] = 1;   chars['~'] = 1;   chars['0'] = 1;
135    chars['b'] = 1;   chars['B'] = 1;   chars['!'] = 1;   chars['1'] = 1;
136    chars['c'] = 1;   chars['C'] = 1;   chars['"'] = 1;   chars['2'] = 1;
137    chars['d'] = 1;   chars['D'] = 1;   chars['#'] = 1;   chars['3'] = 1;
138    chars['e'] = 1;   chars['E'] = 1;   chars['%'] = 1;   chars['4'] = 1;
139    chars['f'] = 1;   chars['F'] = 1;   chars['&'] = 1;   chars['5'] = 1;
140    chars['g'] = 1;   chars['G'] = 1;   chars['('] = 1;   chars['6'] = 1;
141    chars['h'] = 1;   chars['H'] = 1;   chars[')'] = 1;   chars['7'] = 1;
142    chars['i'] = 1;   chars['I'] = 1;   chars['_'] = 1;   chars['8'] = 1;
143    chars['j'] = 1;   chars['J'] = 1;   chars['='] = 1;   chars['9'] = 1;
144    chars['k'] = 1;   chars['K'] = 1;   chars['-'] = 1;
145    chars['l'] = 1;   chars['L'] = 1;   chars['^'] = 1;
146    chars['m'] = 1;   chars['M'] = 1;   chars['|'] = 1;   chars['\n'] = 1;
147    chars['n'] = 1;   chars['N'] = 1;                     chars['\t'] = 1;
148    chars['o'] = 1;   chars['O'] = 1;   chars['{'] = 1;   chars['\b'] = 1;
149    chars['p'] = 1;   chars['P'] = 1;   chars['}'] = 1;   chars['\r'] = 1;
150    chars['q'] = 1;   chars['Q'] = 1;   chars['['] = 1;   chars['\f'] = 1;
151    chars['r'] = 1;   chars['R'] = 1;   chars[']'] = 1;
152    chars['s'] = 1;   chars['S'] = 1;   chars['+'] = 1;   chars['\\'] = 1;
153    chars['t'] = 1;   chars['T'] = 1;   chars[';'] = 1;   chars['\''] = 1;
154    chars['u'] = 1;   chars['U'] = 1;   chars['*'] = 1;
155    chars['v'] = 1;   chars['V'] = 1;   chars[':'] = 1;   chars['\0'] = 1;
156    chars['w'] = 1;   chars['W'] = 1;   chars['<'] = 1;   chars[' '] = 1;
157    chars['x'] = 1;   chars['X'] = 1;   chars['>'] = 1;
158    chars['y'] = 1;   chars['Y'] = 1;   chars[','] = 1;
159    chars['z'] = 1;   chars['Z'] = 1;   chars['.'] = 1;
160                                        chars['?'] = 1;
161                                        chars['/'] = 1;
162
163    if(sumof(chars) != 98){
164      rc = rc+1;
165      if(pd0->flgd != 0) printf(s243er,1);
166    }
167
168    #ifndef NO_BACKSLASH_CHARCODE
169
170    /* Finally, the escape \ddd consists of the backslash followed
171       by 1, 2, or 3 octal digits which are taken to specify  the
172       desired character.                           */
173
174 /*
175     this test is non portable and inaccurate, we replace it
176     by a more failproof version
177
178    if(
179         '\0'    !=   0 ||
180         '\01'   !=   1 ||
181         '\02'   !=   2 ||
182         '\03'   !=   3 ||
183         '\04'   !=   4 ||
184         '\05'   !=   5 ||
185         '\06'   !=   6 ||
186         '\07'   !=   7 ||
187         '\10'   !=   8 ||
188         '\17'   !=  15 ||
189         '\20'   !=  16 ||
190         '\77'   !=  63 ||
191         '\100'  !=  64 ||
192         '\177'  != 127
193         )
194 */
195     if(
196      ('0' != '\60') ||
197      ('9' != '\71') ||
198      ('A' != '\101') ||
199      ('Z' != '\132') ||
200      ('a' != '\141') ||
201      ('z' != '\172')
202       )
203
204         {
205      rc = rc+8;
206      if(pd0->flgd != 0)
207      {
208         printf(s243er,8);
209      }
210    }
211
212    #endif
213
214    return rc;
215 }
216
217 /*********************************************************************************************
218  the main loop that launches the sections
219 *********************************************************************************************/
220
221 #define cq_sections 1
222
223 #ifndef NO_TYPELESS_STRUCT_PTR
224         int section(int j,struct* pd0){
225 #else
226         int section(int j,void* pd0){
227 #endif
228         switch(j){
229                 case 0: return s243(pd0);
230         }
231 }
232
233 /*
234         C REFERENCE MANUAL (main)
235 */
236
237 #ifndef NO_OLD_FUNC_DECL
238 main(n,args)
239 int n;
240 char **args;
241 {
242 #else
243 int main(int n,char **args) {
244 #endif
245
246 int j;
247 static struct defs d0, *pd0;
248         
249    d0.flgs = 1;          /* These flags dictate            */
250    d0.flgm = 1;          /*     the verbosity of           */
251    d0.flgd = 1;          /*         the program.           */
252    d0.flgl = 1;
253
254    pd0 = &d0;
255
256    for (j=0; j<cq_sections; j++) {
257      d0.rrc=section(j,pd0);
258      d0.crc=d0.crc+d0.rrc;
259      if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
260    }
261
262    if(d0.crc == 0) printf("\nNo errors detected.\n");
263    else printf("\nFailed.\n");
264
265    return d0.crc;
266 }