2 !!DESCRIPTION!! structs
3 !!ORIGIN!! LCC 4.1 Testsuite
4 !!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC
7 typedef struct point { int x,y; } point;
8 typedef struct rect { point pt1, pt2; } rect;
10 #define min(a, b) ((a) < (b) ? (a) : (b))
11 #define max(a, b) ((a) > (b) ? (a) : (b))
13 #ifdef NO_FUNCS_RETURN_STRUCTS
14 # ifdef NO_FUNCS_TAKE_STRUCTS
15 /* canonicalize rectangle coordinates */
16 void canonrect(rect *d,rect *r) {
17 d->pt1.x = min(r->pt1.x, r->pt2.x);
18 d->pt1.y = min(r->pt1.y, r->pt2.y);
19 d->pt2.x = max(r->pt1.x, r->pt2.x);
20 d->pt2.y = max(r->pt1.y, r->pt2.y);
23 void addpoint(point *p, point *p1, point *p2) {
27 /* make a point from x and y components */
28 void makepoint(point *p,int x, int y) {
32 /* make a rectangle from two points */
33 void makerect(rect *d,point *p1, point *p2) {
43 #ifdef NO_SLOPPY_STRUCT_INIT
44 struct odd {char a[3]; } y = {{'a', 'b', 0 }};
46 struct odd {char a[3]; } y = {'a', 'b', 0};
51 printf("%s\n\r", x->a);
54 # else /* FUNCS_TAKE_STRUCTS */
55 /* canonicalize rectangle coordinates */
56 void canonrect(rect *d,rect r) {
57 d->pt1.x = min(r.pt1.x, r.pt2.x);
58 d->pt1.y = min(r.pt1.y, r.pt2.y);
59 d->pt2.x = max(r.pt1.x, r.pt2.x);
60 d->pt2.y = max(r.pt1.y, r.pt2.y);
63 void addpoint(point *p, point p1, point p2) {
67 /* make a point from x and y components */
68 void makepoint(point *p,int x, int y) {
72 /* make a rectangle from two points */
73 void makerect(rect *d,point p1, point p2) {
81 #ifdef NO_SLOPPY_STRUCT_INIT
82 struct odd {char a[3]; } y = {{'a', 'b', 0}};
84 struct odd {char a[3]; } y = {'a', 'b', 0};
89 printf("%s\n\r", x.a);
92 # endif /* FUNCS_TAKE_STRUCTS */
94 #else /* FUNCS_RETURN_STRUCTS */
97 point addpoint(point p1, point p2) {
102 /* canonicalize rectangle coordinates */
103 rect canonrect(rect r) {
106 temp.pt1.x = min(r.pt1.x, r.pt2.x);
107 temp.pt1.y = min(r.pt1.y, r.pt2.y);
108 temp.pt2.x = max(r.pt1.x, r.pt2.x);
109 temp.pt2.y = max(r.pt1.y, r.pt2.y);
112 /* make a point from x and y components */
113 point makepoint(int x, int y) {
121 /* make a rectangle from two points */
122 rect makerect(point p1, point p2) {
130 struct odd {char a[3]; } y =
132 #ifdef NO_SLOPPY_STRUCT_INIT
136 #ifdef NO_SLOPPY_STRUCT_INIT
145 printf("%s\n\r", x.a);
151 # ifdef NO_FUNCS_TAKE_STRUCTS
152 int ptinrect(point *p, rect *r) {
153 return p->x >= r->pt1.x && p->x < r->pt2.x
154 && p->y >= r->pt1.y && p->y < r->pt2.y;
157 int ptinrect(point p, rect r) {
158 return p.x >= r.pt1.x && p.x < r.pt2.x
159 && p.y >= r.pt1.y && p.y < r.pt2.y;
163 #ifdef NO_FUNCS_RETURN_STRUCTS
165 #ifdef NO_LOCAL_STRUCT_INIT
166 #ifdef NO_SLOPPY_STRUCT_INIT
167 point pts[] = { {-1, -1},{ 1, 1},{ 20, 300},{ 500, 400 } };
169 point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 };
171 point origin = { 0, 0 };
172 point maxpt = { 320, 320 };
179 #ifndef NO_LOCAL_STRUCT_INIT
180 point origin = { 0, 0 };
181 point maxpt = { 320, 320 };
182 #ifdef NO_SLOPPY_STRUCT_INIT
183 point pts[] = { {-1, -1},{ 1, 1},{ 20, 300},{ 500, 400 } };
185 point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 };
189 makepoint ( &x, -10, -10);
190 #ifdef NO_FUNCS_TAKE_STRUCTS
191 addpoint ( &maxpt, &maxpt, &x);
193 addpoint ( &maxpt, maxpt, x);
195 makepoint ( &x, 10, 10);
197 #ifdef NO_FUNCS_TAKE_STRUCTS
198 addpoint (&origin,&origin, &x);
199 makerect (&screen, &maxpt,&origin);
201 addpoint (&origin,origin, x);
202 makerect (&screen, maxpt,origin);
205 for (i = 0; i < sizeof pts/sizeof pts[0]; i++) {
206 makepoint(&x,pts[i].x, pts[i].y);
207 printf("(%d,%d) is ", pts[i].x, x.y);
208 #ifdef NO_FUNCS_TAKE_STRUCTS
209 if (ptinrect(&x, &screen) == 0)
211 if (ptinrect(x, screen) == 0)
216 printf("within (%d,%d; %d,%d)\n\r", screen.pt1.x, screen.pt1.y,
217 screen.pt2.x, screen.pt2.y);
219 #ifdef NO_FUNCS_TAKE_STRUCTS
228 #else /* FUNCS_RETURN_STRUCTS */
232 point x, origin = { 0, 0 }, maxpt = { 320, 320 };
234 #ifdef NO_SLOPPY_STRUCT_INIT
235 point pts[] = { {-1, -1}, {1, 1}, {20, 300}, {500, 400} };
237 point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 };
242 addpoint(maxpt, makepoint(-10, -10)),
243 addpoint(origin, makepoint(10, 10))
248 for (i = 0; i < sizeof pts/sizeof pts[0]; i++) {
249 printf("(%d,%d) is ", pts[i].x,
250 (x = makepoint(pts[i].x, pts[i].y)).y);
251 if (ptinrect(x, screen) == 0)
253 printf("within (%d,%d; %d,%d)\n\r", screen.pt1.x, screen.pt1.y,
254 screen.pt2.x, screen.pt2.y);
261 #endif /* FUNCS_RETURN_STRUCTS */