Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / ctest / ctstruct / str.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  *
5  */
6
7 /* Author: E.G. Keizer */
8 static char rcs_id[]=   "$Id: str.c,v 2.6 1994/06/24 12:10:03 ceriel Exp $" ;
9
10 /* test for structure parameters, assignment and return */
11 # define ASIZE 26
12
13 struct w1 {
14         int w1_i ;
15 } ;
16 struct w2 {
17         int w2_i ;
18         long w2_l ;
19 } ;
20 struct w3 {
21         char w3_a[ASIZE] ;
22         unsigned w3_u ;
23 } ;
24
25 struct w1 es1 ;
26 struct w1 es2[3] ;
27
28 main() {
29         asst() ;
30         part() ;
31         callt() ;
32         return 0 ;
33
34 }
35
36 asst() {
37         /* test structure assignment */
38         struct w1 st1, st2, *st3 ;
39         struct w2 s2t1, s2t2, *s2t3 ;
40         struct w3 s3t1, s3t2, *s3t3 ;
41
42
43         register int i ;
44
45         printf("w1\n") ;
46         st1.w1_i = 506 ;
47         st2 = st1 ;
48         printf("\tst2.w1_i %d\n",st2.w1_i) ;
49         st3 = &st1 ;
50         printf("\t(*st3).w1_i %d\n",(*st3).w1_i) ;
51         es1.w1_i = 711 ;
52         st1 = st2 = es1 ;
53         printf("\tst1.w1_i %d\n",st1.w1_i) ;
54         printf("\tst2.w1_i %d\n",st2.w1_i) ;
55         es2[2] = st1 ;
56         printf("\tes2[2].w1_i %d\n",es2[2].w1_i) ;
57
58         st1.w1_i = -577 ;
59         es1.w1_i = 577 ;
60         for ( i=0 ; i<2 ; i++ ) {
61                 st2 = ( i ? st1 : es1 ) ;
62                 printf("\tst2.w1_i %d\n",st2.w1_i) ;
63         }
64
65         st1 = ( i , es1 ) ;
66         printf("\tst1.w1_i %d\n",st1.w1_i) ;
67
68         printf("w2\n") ;
69         s2t1.w2_i = 18000 ;
70         s2t1.w2_l = 31415 ;
71         s2t2 = s2t1 ;
72         printf("\ts2t2: .w2_i %d .w2_l %ld\n",s2t2.w2_i,s2t2.w2_l) ;
73         s2t3 = &s2t2 ;
74         printf("\ts2t3->w2_l %ld\n",s2t3->w2_l) ;
75
76         printf("w3\n") ;
77         for ( i = 0 ; i<ASIZE ; i++ ) {
78                 s3t1.w3_a[i]= 'a'+i ;
79         }
80         s3t1.w3_u = 0x8000 ;
81         s3t2 = s3t1 ;
82         s3t3 = &s3t1 ;
83         for ( i = 0 ; i<ASIZE ; i++ ) {
84                 printf("s3t2.w3_a[%2d] %c\n",i,s3t2.w3_a[i]) ;
85         }
86         printf("s3t2.w3_u %x\n",s3t2.w3_u) ;
87         s3t2.w3_u = 1415 ;
88         for ( i = 0 ; i<ASIZE ; i++ ) {
89                 s3t2.w3_a[i]= 'A'+i ;
90         }
91         *s3t3 = s3t2 ;
92         for ( i = 0 ; i<ASIZE ; i++ ) {
93                 printf("s3t1.w3_a[%2d] %c\n",i,s3t1.w3_a[i]) ;
94         }
95         printf("s3t1.w3_u %x",s3t1.w3_u) ;
96 }
97
98 struct w3 epars ;
99
100 part() {
101         /* test structure parameters */
102
103         struct w3 pars ;
104
105         register i ;
106
107         for ( i=0 ; i<ASIZE ; i++ ) {
108                 pars.w3_a[i]=i+1 ;
109         }
110         pars.w3_u = 281 ;
111         printf("\nstructure parameters\n") ;
112         psc(-1,pars,1000) ;
113 }
114
115 psc(before,str,after) int before, after ; struct w3 str ; {
116         register int i ;
117
118         printf("before %d\n",before) ;
119         for ( i=0 ; i<ASIZE ; i++ ) {
120                 printf("str.w3_a[%2d]\t%d\n",i,str.w3_a[i]) ;
121         }
122         printf("str.w3_u %x\n",str.w3_u) ;
123         printf("after %d\n",after) ;
124 }
125
126 callt() {
127         /* test structure valued functions */
128         extern struct w3 setp1(), setp2() ;
129         struct w3 myp ;
130         register int i ;
131
132         printf("\nStucture valued functions\n") ;
133         myp = setp1(ASIZE) ;
134         printf("myp.w3_a:\n") ;
135         for ( i=0 ; i<ASIZE ; i++ ) {
136                 printf("\t%2d\t%d\n",i,myp.w3_a[i]) ;
137         }
138
139
140         myp = setp2() ;
141         for ( i=0 ; i<ASIZE ; i++ ) {
142                 printf("\t%2d\t%d\n",i,myp.w3_a[i]) ;
143         }
144 }
145
146 struct w3 setp1(count) {
147         struct w3 myp ;
148
149         if ( count<=0 ) {
150                 return(myp) ;
151         }
152         myp = setp1(count-1) ;
153         myp.w3_a[count-1] = 99-count-1 ;
154         return(myp) ;
155 }
156
157 static struct w3 myp2 ;
158
159 struct w3 setp2() {
160         struct w3 *w3p ;
161         register i ;
162
163         for ( i=0 ; i<ASIZE ; i++ ) {
164                 myp2.w3_a[i]= 99+i ;
165         }
166         w3p = &myp2 ;
167         return(*w3p) ;
168 }