]> git.sur5r.net Git - cc65/blob - test/val/cq61.c
remote TABs in doc/ and test/
[cc65] / test / val / cq61.c
1 /*
2   !!DESCRIPTION!! C-Manual Chapter 6.1: characters and integers
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 /*#include "cq26.c"*/ /* hardware check */
47
48 int extvar;
49
50 #ifndef NO_OLD_FUNC_DECL
51 s61(pd0)          /* Characters and integers */
52 struct defs *pd0;
53 {
54 #else
55 int s61(struct defs *pd0){
56 #endif
57    static char s61er[] = "s61,er%d\n";
58    static char s61ok[] = "s61,ok%d\n";
59    static char qs61[8] = "s61    ";
60    short from, shortint;
61    long int to, longint;
62    int rc, lrc;
63    int j;
64    char fromc, charint;
65    char *wd, *pc[6];
66
67    static char upper_alpha[]             = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
68    static char lower_alpha[]             = "abcdefghijklmnopqrstuvwxyz";
69    static char numbers[]               = "0123456789";
70    static char special_characters[]    = "~!\"#%&()_=-^|{}[]+;*:<>,.?/";
71    static char extra_special_characters[] = "\n\t\b\r\f\\\'";
72    static char blank_and_NUL[]            = " \0";
73
74    char *ps, *pt;
75    ps = qs61;
76    pt = pd0->rfs;
77    rc = 0;
78
79    printf(s61ok,0);
80
81    while (*pt++ = *ps++);
82
83 /*      A character or a short integer may be used wherever
84 an integer may be used. In all cases, the value is converted
85 to integer. This principle is extensively used throughout this
86 program, and will not be explicitly tested here.        */
87
88 /*      Conversion of a shorter integer to a longer always
89 involves sign extension.                                */
90
91    from = -19;
92    to = from;
93
94    if(to != -19){
95      rc = rc+1;
96      if(pd0->flgd != 0) printf(s61er,1);
97    }
98    else if(pd0->flgd != 0) printf(s61ok,1);
99
100 /*      It is guaranteed that a member of the standard char-
101 acter set is nonnegative.                               */
102
103    pc[0] = upper_alpha;
104    pc[1] = lower_alpha;
105    pc[2] = numbers;
106    pc[3] = special_characters;
107    pc[4] = extra_special_characters;
108    pc[5] = blank_and_NUL;
109
110    lrc = 0;
111    for (j=0; j<6; j++)
112      while(*pc[j]) if(*pc[j]++ < 0) lrc =1;
113
114    if(lrc != 0){
115      rc=rc+2;
116      if(pd0->flgd != 0) printf(s61er,2);
117    }
118    else if(pd0->flgd != 0) printf(s61ok,2);
119
120 /*      When a longer integer is converted to a shorter or
121 to  a char, it is truncated on the left; excess bits are
122 simply discarded.                                       */
123
124    longint = 1048579;           /* =2**20+3 */
125    shortint = longint;
126    charint = longint;
127
128    if((shortint != longint && shortint != 3) ||
129       (charint  != longint && charint  != 3)) {
130      rc = rc+8;
131      if(pd0->flgd != 0) printf(s61er,8);
132    }
133    else if(pd0->flgd != 0) printf(s61ok,8);
134
135    return rc;
136 }
137
138 /*********************************************************************************************
139  the main loop that launches the sections
140 *********************************************************************************************/
141
142 #ifndef NO_TYPELESS_STRUCT_PTR
143         int section(int j,struct* pd0){
144 #else
145         int section(int j,void* pd0){
146 #endif
147         switch(j){
148                 /*case 0: return s26(pd0);*/
149                 case 0: return s61(pd0);
150         }
151 }
152
153 #define cq_sections 1
154
155 /*
156         C REFERENCE MANUAL (main)
157 */
158
159 #ifndef NO_OLD_FUNC_DECL
160 main(n,args)
161 int n;
162 char **args;
163 {
164 #else
165 int main(int n,char **args) {
166 #endif
167
168 int j;
169 static struct defs d0, *pd0;
170         
171    d0.flgs = 1;          /* These flags dictate            */
172    d0.flgm = 1;          /*     the verbosity of           */
173    d0.flgd = 1;          /*         the program.           */
174    d0.flgl = 1;
175
176    pd0 = &d0;
177
178    for (j=0; j<cq_sections; j++) {
179      d0.rrc=section(j,pd0);
180      d0.crc=d0.crc+d0.rrc;
181      if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
182    }
183
184    if(d0.crc == 0) printf("\nNo errors detected.\n");
185    else printf("\nFailed.\n");
186
187    return d0.crc;
188 }