]> git.sur5r.net Git - cc65/blob - test/val/cq25.c
remote TABs in doc/ and test/
[cc65] / test / val / cq25.c
1 /*
2   !!DESCRIPTION!! C-Manual Chapter 2.5: strings
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 s25(pd0)
48 struct defs *pd0;
49 {
50 #else
51 int s25(struct defs *pd0) {
52 #endif
53    char *s, *s2;
54    int rc, lrc, j;
55    static char s25er[] = "s25,er%d\n";
56    static char qs25[8] = "s25    ";
57    char *ps, *pt;
58
59    ps = qs25;
60    pt = pd0->rfs;
61    while(*pt++ = *ps++);
62    rc = 0;
63
64    /* A string is a sequence of characters surrounded by double
65       quotes, as in "...".                         */
66
67    s = "...";
68
69    /* A string has type "array of characters" and storage class
70       static and is initialized with the given characters.  */
71
72    if ( s[0] != s[1] || s[1] != s[2]
73      || s[2] != '.' ) {
74     rc = rc+1;
75      if(pd0->flgd != 0) printf(s25er,1);
76    }
77
78    /* The compiler places a null byte \0 at the end of each string
79       so the program which scans the string can find its end.   */
80
81    if( s[3] != '\0' ){
82      rc = rc+4;
83      if(pd0->flgd != 0) printf(s25er,4);
84    }
85
86    /* In a string, the double quote character " must be preceded
87       by a \.                                               */
88
89    if( ".\"."[1] != '"' ){
90     rc = rc+8;
91      if(pd0->flgd != 0) printf(s25er,8);
92    }
93
94    /* In addition, the same escapes described for character constants
95       may be used.                                            */
96
97    s = "\n\t\b\r\f\\\'";
98
99    if( s[0] != '\n'
100     || s[1] != '\t'
101     || s[2] != '\b'
102     || s[3] != '\r'
103     || s[4] != '\f'
104     || s[5] != '\\'
105     || s[6] != '\'' ){
106      rc = rc+16;
107      if( pd0->flgd != 0) printf(s25er,16);
108    }
109
110    /* Finally, a \ and an immediately following newline are ignored */
111
112    s2 = "queep!";
113    s = "queep!";
114
115    lrc = 0;
116    for (j=0; j<sizeof "queep!"; j++) if(s[j] != s2[j]) lrc = 1;
117    if (lrc != 0){
118      rc = rc+32;
119      if(pd0->flgd != 0) printf(s25er,32);
120    }
121    return rc;
122 }
123
124 /*********************************************************************************************
125  the main loop that launches the sections
126 *********************************************************************************************/
127
128 #define cq_sections 1
129
130 #ifndef NO_TYPELESS_STRUCT_PTR
131         int section(int j,struct* pd0){
132 #else
133         int section(int j,void* pd0){
134 #endif
135         switch(j){
136                 case 0: return s25(pd0);
137         }
138 }
139
140 /*
141         C REFERENCE MANUAL (main)
142 */
143
144 #ifndef NO_OLD_FUNC_DECL
145 main(n,args)
146 int n;
147 char **args;
148 {
149 #else
150 int main(int n,char **args) {
151 #endif
152
153 int j;
154 static struct defs d0, *pd0;
155         
156    d0.flgs = 1;          /* These flags dictate            */
157    d0.flgm = 1;          /*     the verbosity of           */
158    d0.flgd = 1;          /*         the program.           */
159    d0.flgl = 1;
160
161    pd0 = &d0;
162
163    for (j=0; j<cq_sections; j++) {
164      d0.rrc=section(j,pd0);
165      d0.crc=d0.crc+d0.rrc;
166      if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
167    }
168
169    if(d0.crc == 0) printf("\nNo errors detected.\n");
170    else printf("\nFailed.\n");
171
172    return d0.crc;
173 }