2 !!DESCRIPTION!! structs
3 !!ORIGIN!! LCC 4.1 Testsuite
4 !!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC
9 typedef struct point { int x,y; } point;
10 typedef struct rect { point pt1, pt2; } rect;
12 #define min(a, b) ((a) < (b) ? (a) : (b))
13 #define max(a, b) ((a) > (b) ? (a) : (b))
15 #ifdef NO_FUNCS_RETURN_STRUCTS
16 # ifdef NO_FUNCS_TAKE_STRUCTS
17 /* canonicalize rectangle coordinates */
18 void canonrect(rect *d,rect *r) {
19 d->pt1.x = min(r->pt1.x, r->pt2.x);
20 d->pt1.y = min(r->pt1.y, r->pt2.y);
21 d->pt2.x = max(r->pt1.x, r->pt2.x);
22 d->pt2.y = max(r->pt1.y, r->pt2.y);
25 void addpoint(point *p, point *p1, point *p2) {
29 /* make a point from x and y components */
30 void makepoint(point *p,int x, int y) {
34 /* make a rectangle from two points */
35 void makerect(rect *d,point *p1, point *p2) {
45 #ifdef NO_SLOPPY_STRUCT_INIT
46 struct odd {char a[3]; } y = {{'a', 'b', 0 }};
48 struct odd {char a[3]; } y = {'a', 'b', 0};
53 printf("%s\n\r", x->a);
56 # else /* FUNCS_TAKE_STRUCTS */
57 /* canonicalize rectangle coordinates */
58 void canonrect(rect *d,rect r) {
59 d->pt1.x = min(r.pt1.x, r.pt2.x);
60 d->pt1.y = min(r.pt1.y, r.pt2.y);
61 d->pt2.x = max(r.pt1.x, r.pt2.x);
62 d->pt2.y = max(r.pt1.y, r.pt2.y);
65 void addpoint(point *p, point p1, point p2) {
69 /* make a point from x and y components */
70 void makepoint(point *p,int x, int y) {
74 /* make a rectangle from two points */
75 void makerect(rect *d,point p1, point p2) {
83 #ifdef NO_SLOPPY_STRUCT_INIT
84 struct odd {char a[3]; } y = {{'a', 'b', 0}};
86 struct odd {char a[3]; } y = {'a', 'b', 0};
91 printf("%s\n\r", x.a);
94 # endif /* FUNCS_TAKE_STRUCTS */
96 #else /* FUNCS_RETURN_STRUCTS */
99 point addpoint(point p1, point p2) {
104 /* canonicalize rectangle coordinates */
105 rect canonrect(rect r) {
108 temp.pt1.x = min(r.pt1.x, r.pt2.x);
109 temp.pt1.y = min(r.pt1.y, r.pt2.y);
110 temp.pt2.x = max(r.pt1.x, r.pt2.x);
111 temp.pt2.y = max(r.pt1.y, r.pt2.y);
114 /* make a point from x and y components */
115 point makepoint(int x, int y) {
123 /* make a rectangle from two points */
124 rect makerect(point p1, point p2) {
132 struct odd {char a[3]; } y =
134 #ifdef NO_SLOPPY_STRUCT_INIT
138 #ifdef NO_SLOPPY_STRUCT_INIT
147 printf("%s\n\r", x.a);
153 # ifdef NO_FUNCS_TAKE_STRUCTS
154 int ptinrect(point *p, rect *r) {
155 return p->x >= r->pt1.x && p->x < r->pt2.x
156 && p->y >= r->pt1.y && p->y < r->pt2.y;
159 int ptinrect(point p, rect r) {
160 return p.x >= r.pt1.x && p.x < r.pt2.x
161 && p.y >= r.pt1.y && p.y < r.pt2.y;
165 #ifdef NO_FUNCS_RETURN_STRUCTS
167 #ifdef NO_LOCAL_STRUCT_INIT
168 #ifdef NO_SLOPPY_STRUCT_INIT
169 point pts[] = { {-1, -1},{ 1, 1},{ 20, 300},{ 500, 400 } };
171 point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 };
173 point origin = { 0, 0 };
174 point maxpt = { 320, 320 };
181 #ifndef NO_LOCAL_STRUCT_INIT
182 point origin = { 0, 0 };
183 point maxpt = { 320, 320 };
184 #ifdef NO_SLOPPY_STRUCT_INIT
185 point pts[] = { {-1, -1},{ 1, 1},{ 20, 300},{ 500, 400 } };
187 point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 };
191 makepoint ( &x, -10, -10);
192 #ifdef NO_FUNCS_TAKE_STRUCTS
193 addpoint ( &maxpt, &maxpt, &x);
195 addpoint ( &maxpt, maxpt, x);
197 makepoint ( &x, 10, 10);
199 #ifdef NO_FUNCS_TAKE_STRUCTS
200 addpoint (&origin,&origin, &x);
201 makerect (&screen, &maxpt,&origin);
203 addpoint (&origin,origin, x);
204 makerect (&screen, maxpt,origin);
207 for (i = 0; i < sizeof pts/sizeof pts[0]; i++) {
208 makepoint(&x,pts[i].x, pts[i].y);
209 printf("(%d,%d) is ", pts[i].x, x.y);
210 #ifdef NO_FUNCS_TAKE_STRUCTS
211 if (ptinrect(&x, &screen) == 0)
213 if (ptinrect(x, screen) == 0)
218 printf("within (%d,%d; %d,%d)\n\r", screen.pt1.x, screen.pt1.y,
219 screen.pt2.x, screen.pt2.y);
221 #ifdef NO_FUNCS_TAKE_STRUCTS
230 #else /* FUNCS_RETURN_STRUCTS */
234 point x, origin = { 0, 0 }, maxpt = { 320, 320 };
236 #ifdef NO_SLOPPY_STRUCT_INIT
237 point pts[] = { {-1, -1}, {1, 1}, {20, 300}, {500, 400} };
239 point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 };
244 addpoint(maxpt, makepoint(-10, -10)),
245 addpoint(origin, makepoint(10, 10))
250 for (i = 0; i < sizeof pts/sizeof pts[0]; i++) {
251 printf("(%d,%d) is ", pts[i].x,
252 (x = makepoint(pts[i].x, pts[i].y)).y);
253 if (ptinrect(x, screen) == 0)
255 printf("within (%d,%d; %d,%d)\n\r", screen.pt1.x, screen.pt1.y,
256 screen.pt2.x, screen.pt2.y);
263 #endif /* FUNCS_RETURN_STRUCTS */