]> git.sur5r.net Git - cc65/blob - test/val/cq61.c
Merge pull request #135 from ikorb/patch1
[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 struct defs {
8      int cbits;          /* No. of bits per char           */
9      int ibits;          /*                 int            */
10      int sbits;          /*                 short          */
11      int lbits;          /*                 long           */
12      int ubits;          /*                 unsigned       */
13      int fbits;          /*                 float          */
14      int dbits;          /*                 double         */
15      #ifndef NO_FLOATS
16         float fprec;        /* Smallest number that can be    */
17         float dprec;        /* significantly added to 1.      */
18      #endif
19      int flgs;           /* Print return codes, by section */
20      int flgm;           /* Announce machine dependencies  */
21      int flgd;           /* give explicit diagnostics      */
22      int flgl;           /* Report local return codes.     */
23      int rrc;            /* recent return code             */
24      int crc;            /* Cumulative return code         */
25      char rfs[8];        /* Return from section            */
26 };
27
28      int lbits;          /*                 long           */
29      int ubits;          /*                 unsigned       */
30      int fbits;          /*                 float          */
31      int dbits;          /*                 double         */
32      #ifndef NO_FLOATS
33         float fprec;        /* Smallest number that can be    */
34         float dprec;        /* significantly added to 1.      */
35      #endif
36      int flgs;           /* Print return codes, by section */
37      int flgm;           /* Announce machine dependencies  */
38      int flgd;           /* give explicit diagnostics      */
39      int flgl;           /* Report local return codes.     */
40      int rrc;            /* recent return code             */
41      int crc;            /* Cumulative return code         */
42      char rfs[8];        /* Return from section            */
43
44 /*#include "cq26.c"*/ /* hardware check */
45
46 int extvar;
47
48 #ifndef NO_OLD_FUNC_DECL
49 s61(pd0)          /* Characters and integers */
50 struct defs *pd0;
51 {
52 #else
53 int s61(struct defs *pd0){
54 #endif
55    static char s61er[] = "s61,er%d\n";
56    static char s61ok[] = "s61,ok%d\n";
57    static char qs61[8] = "s61    ";
58    short from, shortint;
59    long int to, longint;
60    int rc, lrc;
61    int j;
62    char fromc, charint;
63    char *wd, *pc[6];
64
65    static char upper_alpha[]             = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
66    static char lower_alpha[]             = "abcdefghijklmnopqrstuvwxyz";
67    static char numbers[]               = "0123456789";
68    static char special_characters[]    = "~!\"#%&()_=-^|{}[]+;*:<>,.?/";
69    static char extra_special_characters[] = "\n\t\b\r\f\\\'";
70    static char blank_and_NUL[]            = " \0";
71
72    char *ps, *pt;
73    ps = qs61;
74    pt = pd0->rfs;
75    rc = 0;
76
77    printf(s61ok,0);
78
79    while (*pt++ = *ps++);
80
81 /*      A character or a short integer may be used wherever
82 an integer may be used. In all cases, the value is converted
83 to integer. This principle is extensively used throughout this
84 program, and will not be explicitly tested here.        */
85
86 /*      Conversion of a shorter integer to a longer always
87 involves sign extension.                                */
88
89    from = -19;
90    to = from;
91
92    if(to != -19){
93      rc = rc+1;
94      if(pd0->flgd != 0) printf(s61er,1);
95    }
96    else if(pd0->flgd != 0) printf(s61ok,1);
97
98 /*      It is guaranteed that a member of the standard char-
99 acter set is nonnegative.                               */
100
101    pc[0] = upper_alpha;
102    pc[1] = lower_alpha;
103    pc[2] = numbers;
104    pc[3] = special_characters;
105    pc[4] = extra_special_characters;
106    pc[5] = blank_and_NUL;
107
108    lrc = 0;
109    for (j=0; j<6; j++)
110      while(*pc[j]) if(*pc[j]++ < 0) lrc =1;
111
112    if(lrc != 0){
113      rc=rc+2;
114      if(pd0->flgd != 0) printf(s61er,2);
115    }
116    else if(pd0->flgd != 0) printf(s61ok,2);
117
118 /*      When a longer integer is converted to a shorter or
119 to  a char, it is truncated on the left; excess bits are
120 simply discarded.                                       */
121
122    longint = 1048579;           /* =2**20+3 */
123    shortint = longint;
124    charint = longint;
125
126    if((shortint != longint && shortint != 3) ||
127       (charint  != longint && charint  != 3)) {
128      rc = rc+8;
129      if(pd0->flgd != 0) printf(s61er,8);
130    }
131    else if(pd0->flgd != 0) printf(s61ok,8);
132
133    return rc;
134 }
135
136 /*********************************************************************************************
137  the main loop that launches the sections
138 *********************************************************************************************/
139
140 #ifndef NO_TYPELESS_STRUCT_PTR
141         int section(int j,struct* pd0){
142 #else
143         int section(int j,void* pd0){
144 #endif
145         switch(j){
146                 /*case 0: return s26(pd0);*/
147                 case 0: return s61(pd0);
148         }
149 }
150
151 #define cq_sections 1
152
153 /*
154         C REFERENCE MANUAL (main)
155 */
156
157 #ifndef NO_OLD_FUNC_DECL
158 main(n,args)
159 int n;
160 char **args;
161 {
162 #else
163 int main(int n,char **args) {
164 #endif
165
166 int j;
167 static struct defs d0, *pd0;
168         
169    d0.flgs = 1;          /* These flags dictate            */
170    d0.flgm = 1;          /*     the verbosity of           */
171    d0.flgd = 1;          /*         the program.           */
172    d0.flgl = 1;
173
174    pd0 = &d0;
175
176    for (j=0; j<cq_sections; j++) {
177      d0.rrc=section(j,pd0);
178      d0.crc=d0.crc+d0.rrc;
179      if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
180    }
181
182    if(d0.crc == 0) printf("\nNo errors detected.\n");
183    else printf("\nFailed.\n");
184
185    return d0.crc;
186 }