]> git.sur5r.net Git - cc65/blob - test/val/cq9.c
remote TABs in doc/ and test/
[cc65] / test / val / cq9.c
1 /*
2   !!DESCRIPTION!! C-Manual Chapter 9: Statements
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 #ifndef NO_OLD_FUNC_DECL
47 s9(pd0)          /*  9  Statements  */
48 struct defs *pd0;
49 {
50 #else
51 int s9(struct defs *pd0){
52 #endif
53    static char s9er[] = "s9,er%d\n";
54    static char qs9[8] = "s9     ";
55    int rc;
56    char *ps, *pt;
57    int lrc, i;
58
59    ps = qs9;
60    pt = pd0->rfs;
61    rc = 0;
62    while (*pt++ = *ps++);
63
64         /* One would think that the section on statements would
65         provide the most variety in the entire sequence of tests.
66         As it turns out, most of the material in this section has
67         already been checked in the process of checking out
68         everything else, and the section at this point is somewhat
69         anticlimactic. For this reason, we restrict ourselves
70         to testing two features not already covered.
71
72         Compound statements are delimited by braces. They have the
73         nice property that identifiers of the auto and register
74         variety are pushed and popped. It is currently legal to
75         transfer into a block, but we wont...
76                                                                 */
77
78    lrc = 0;
79    for(i=0; i<2; i++){
80      int j;
81      register int k;
82      j = k = 2;
83        {
84        int j;
85        register int k;
86        j = k = 3;
87        if((j != 3) || (k != 3)) lrc = 1;
88        }
89      if((j != 2) || (k != 2)) lrc = 1;
90    }
91
92    if(lrc != 0){
93      if(pd0->flgd != 0) printf(s9er,1);
94      rc = rc+1;
95    }
96
97         /* Goto statements go to labeled statements, we hope.   */
98
99    goto nobarf;
100      if(pd0->flgd != 0) printf(s9er,2);
101      rc = rc+2;
102    nobarf:;
103
104    return rc;
105 }
106
107 /*********************************************************************************************
108  the main loop that launches the sections
109 *********************************************************************************************/
110
111 #ifndef NO_TYPELESS_STRUCT_PTR
112         int section(int j,struct* pd0){
113 #else
114         int section(int j,void* pd0){
115 #endif
116         switch(j){
117                 case 0: return s9(pd0);
118         }
119 }
120
121 #define cq_sections 1
122
123 /*
124         C REFERENCE MANUAL (main)
125 */
126
127 #ifndef NO_OLD_FUNC_DECL
128 main(n,args)
129 int n;
130 char **args;
131 {
132 #else
133 int main(int n,char **args) {
134 #endif
135
136 int j;
137 static struct defs d0, *pd0;
138
139    d0.flgs = 1;          /* These flags dictate            */
140    d0.flgm = 1;          /*     the verbosity of           */
141    d0.flgd = 1;          /*         the program.           */
142    d0.flgl = 1;
143
144    pd0 = &d0;
145
146    for (j=0; j<cq_sections; j++) {
147      d0.rrc=section(j,pd0);
148      d0.crc=d0.crc+d0.rrc;
149      if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
150    }
151
152    if(d0.crc == 0) printf("\nNo errors detected.\n");
153    else printf("\nFailed.\n");
154
155    return d0.crc;
156 }