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