View | Details | Raw Unified | Return to bug 225867 | Differences between
and this patch

Collapse All | Expand All

(-)Makefile (-10 / +16 lines)
Lines 5-27 Link Here
5
PORTVERSION=	4.4
5
PORTVERSION=	4.4
6
PORTREVISION=	2
6
PORTREVISION=	2
7
CATEGORIES=	games
7
CATEGORIES=	games
8
MASTER_SITES=	http://www.skysmurf.nl/comp/FreeBSD/distfiles/
8
MASTER_SITES=	https://cyber.dabamos.de/pub/distfiles/
9
DISTNAME=	${PORTNAME}
9
DISTNAME=	${PORTNAME}
10
MAN6=	xroach.6
10
11
11
MAINTAINER=	ports@FreeBSD.org
12
DPADD+=		${LOCALBASE}/lib/libX11.a ${LIBM}
12
COMMENT=	Cockroaches hide under your windows
13
CFLAGS+=	-I${LOCALBASE}/include
14
LDADD+=		-L${LOCALBASE}/lib -lX11 -lm
13
15
14
BROKEN=		unfetchable (apparently abandoned upstream)
16
MANDIR=${LOCALBASE}/man/man
15
DEPRECATED=	Broken for more than 6 months
16
EXPIRATION_DATE=	2017-08-23
17
17
18
USE_XORG=	x11
18
BINOWN=		bin
19
PLIST_FILES=	bin/xroach man/man6/xroach.6.gz
19
BINDIR=		${LOCALBASE}/bin
20
BINMODE=	755
20
21
21
WRKSRC=		${WRKDIR}/pub/bsd-sources/4.4BSD-Lite/usr/src/games/xroach
22
MAINTAINER=	kidon@posteo.de
23
COMMENT=	Cockroaches hide under your windows
22
24
25
USES=		imake
26
USE_XORG=	x11 xext
27
PLIST_FILES=bin/xroach man/man6/xroach.6.gz
28
23
do-install:
29
do-install:
24
	${INSTALL_PROGRAM} -s ${WRKSRC}/xroach ${STAGEDIR}${PREFIX}/bin
30
	${INSTALL_PROGRAM} -s ${WRKSRC}/xroach ${STAGEDIR}${PREFIX}/bin
25
	${INSTALL_MAN} ${WRKSRC}/xroach.6 ${STAGEDIR}${MAN6PREFIX}/man/man6
31
	${INSTALL_MAN} ${WRKSRC}/${PORTNAME}.man ${STAGEDIR}${MAN6PREFIX}/man/man6/${PORTNAME}.6
26
32
27
.include <bsd.port.mk>
33
.include <bsd.port.mk>
(-)distinfo (-2 / +2 lines)
Lines 1-2 Link Here
1
SHA256 (xroach.tar.gz) = 88a4e436b7d93d34b062e548366af1eda62a1402518793b14339e9f5fde4b0da
1
SHA256 (xroach.tar.gz) = 819ee19f8c333d9adaa4ab58829445112e1865b85a6ca82296d66399af344e07
2
SIZE (xroach.tar.gz) = 15404
2
SIZE (xroach.tar.gz) = 21694
(-)files/patch-Makefile (-24 lines)
Lines 1-24 Link Here
1
--- Makefile.orig	Tue Jun  8 19:12:04 1993
2
+++ Makefile	Sun Sep  8 03:45:39 2002
3
@@ -1,9 +1,16 @@
4
-#	@(#)Makefile	8.1 (Berkeley) 6/8/93
5
+#	@(#)Makefile	8.1 (Berkeley) 5/31/93
6
 
7
 PROG=	xroach
8
-MAN6=	xroach.0
9
-CFLAGS+= -I${.CURDIR}/bitmaps
10
-DPADD=	${LIBX} ${LIBM}
11
-LDADD=	-lX11/X11 -lm
12
+MAN6=	xroach.6
13
+
14
+DPADD+=		${LOCALBASE}/lib/libX11.a ${LIBM}
15
+CFLAGS+=	-I${LOCALBASE}/include -I${.CURDIR}/bitmaps
16
+LDADD+=		-L${LOCALBASE}/lib -lX11 -lm
17
+
18
+MANDIR=        ${LOCALBASE}/man/man
19
+
20
+BINOWN=        bin
21
+BINDIR=        ${LOCALBASE}/bin
22
+BINMODE=       755
23
 
24
 .include <bsd.prog.mk>
(-)files/patch-xroach.c (-37 / +1289 lines)
Lines 1-58 Link Here
1
--- xroach.c.orig	1993-06-04 21:47:09.000000000 +0200
1
--- xroach.c.orig	1991-06-06 14:12:07.000000000 +0200
2
+++ xroach.c	2011-12-20 19:03:53.816175581 +0100
2
+++ xroach.c	2018-02-13 16:23:28.812243000 +0100
3
@@ -77,7 +77,7 @@
3
@@ -1,23 +1,31 @@
4
 /*
5
     Xroach - A game of skill.  Try to find the roaches under your windows.
6
-    
7
+
8
     Copyright 1991 by J.T. Anderson
9
 
10
     jta@locus.com
11
-    
12
+
13
     This program may be freely distributed provided that all
14
     copyright notices are retained.
15
 
16
     To build:
17
-      cc -o xroach roach.c -lX11 [-lsocketorwhatever] [-lm] [-l...]
18
+      cc -o xroach -lX11 -lm -I/usr/local/include/ -L/usr/local/lib xroach.c
19
+
20
+    To run:
21
+      ./xroach -speed 2 -squish -rc brown -rgc yellowgreen
22
+
23
+    Dedicated to Greg McFarlane (gregm@otc.otca.oz.au).
24
+
25
+    Squish option contributed by Rick Petkiewizc (rick@locus.com).
26
 
27
-    Dedicated to Greg McFarlane.   (gregm@otc.otca.oz.au)
28
-    
29
-    Squish option contributed by Rick Petkiewizc (rick@locus.com)
30
-    
31
     Virtual root code adapted from patch sent by Colin Rafferty who
32
-    borrowed it from Tom LaStrange.  Several other folks sent similar
33
+    borrowed it from Tom LaStrange. Several other folks sent similar
34
     fixes.
35
+
36
+    Some glitches removed by patch from Guus Sliepen (guus@sliepen.warande.net)
37
+    in 2001 (see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=102668#5).
38
+
39
+    Last update: 2018-JAN-22
40
 */
41
 
42
 /* @(#)xroach.c	1.5 4/2/91 11:53:31 */
43
@@ -28,17 +36,9 @@
44
 #include <X11/Xatom.h>
45
 
46
 #include <stdio.h>
47
-#include <math.h>
48
-#include <malloc.h>
49
-#include <signal.h>
50
-
51
-#if __STDC__
52
 #include <stdlib.h>
53
-#else
54
-long strtol();
55
-double strtod();
56
-char *getenv();
57
-#endif
58
+#include <signal.h>
59
+#include <math.h>
60
 
61
 char Copyright[] = "Xroach\nCopyright 1991 J.T. Anderson";
62
 
63
@@ -47,30 +47,31 @@
64
 typedef unsigned long Pixel;
65
 typedef int ErrorHandler();
66
 
67
-#define SCAMPER_EVENT	(LASTEvent + 1)
68
+#define SCAMPER_EVENT (LASTEvent + 1)
69
 
70
 #if !defined(GRAB_SERVER)
71
-#define GRAB_SERVER	0
72
+#define GRAB_SERVER    0
73
 #endif
74
 
75
+char *display_name = NULL;
76
 Display *display;
77
-int screen;
78
-Window rootWin;
79
-unsigned int display_width, display_height;
80
-int center_x, center_y;
81
 GC gc;
82
 GC gutsGC;
83
-char *display_name = NULL;
84
-Pixel black, white;
85
+int screen;
86
+Pixel black;
87
+unsigned int display_height;
88
+unsigned int display_width;
89
+Window rootWin;
90
 
91
+Bool squishRoach = False;
92
+Bool squishWinUp = False;
93
 int done = 0;
94
-int eventBlock = 0;
95
 int errorVal = 0;
96
-Bool squishRoach = False;
97
+int eventBlock = 0;
98
 Pixmap squishMap;
99
-Bool squishWinUp = False;
100
 
101
-typedef struct Roach {
102
+typedef struct Roach
103
+{
104
     RoachMap *rp;
105
     int index;
106
     float x;
107
@@ -86,69 +87,72 @@
108
 int maxRoaches = 10;
109
 int curRoaches = 0;
110
 float roachSpeed = 20.0;
111
+float turnSpeed = 10.0;
112
 
113
 Region rootVisible = NULL;
114
 
115
 void Usage();
116
 void SigHandler();
117
+Window FindRootWindow();
118
+int RandInt(int maxVal);
119
+int RoachInRect(Roach *roach, int rx, int ry, int x, int y, unsigned int width, unsigned int height);
120
+int RoachOverRect(Roach *roach, int rx, int ry, int x, int y, unsigned int width, unsigned int height);
121
 void AddRoach();
122
-void MoveRoach();
123
+void TurnRoach(Roach *roach);
124
+void MoveRoach(int rx);
125
 void DrawRoaches();
126
 void CoverRoot();
127
+int RoachErrors(XErrorEvent *err);
128
 int CalcRootVisible();
4
 int MarkHiddenRoaches();
129
 int MarkHiddenRoaches();
5
 Pixel AllocNamedColor();
130
-Pixel AllocNamedColor();
131
-Window FindRootWindow();
132
+Pixel AllocNamedColor(char *colorName, Pixel dfltPix);
133
+void checkSquish(XButtonEvent *buttonEvent);
6
 
134
 
7
-void
135
-void
8
+int
136
-main(ac, av)
9
 main(ac, av)
137
-int ac;
10
 int ac;
138
-char *av[];
11
 char *av[];
139
+int main(int ac, char *av[])
12
@@ -96,19 +96,23 @@
140
 {
141
-    XGCValues xgcv;
142
-    int ax;
143
     char *arg;
144
-    RoachMap *rp;
145
-    int rx;
146
-    float angle;
147
-    XEvent ev;
148
-    char *roachColor = "black";
149
     char *gutsColor = NULL;
150
-    int nVis;
151
+    char *roachColor = "black";
152
+    float angle;
153
     int needCalc;
154
+    int nVis;
155
+    RoachMap *rp;
156
     Window squishWin;
157
+    XEvent ev;
158
+    XGCValues xgcv;
159
     XSetWindowAttributes xswa;
160
-    
161
+
13
     /*
162
     /*
14
        Process command line options.
163
        Process command line options.
15
     */
164
     */
16
-    for (ax=1; ax<ac; ax++) {
165
-    for (ax=1; ax<ac; ax++) {
17
-	arg = av[ax];
166
-	arg = av[ax];
18
+    for (ax=1; ax<ac; ) {
167
-	if (strcmp(arg, "-display") == 0) {
19
+	arg = av[ax++];
20
+
21
+	if (ax >= ac)
22
+	    Usage();
23
+
24
 	if (strcmp(arg, "-display") == 0) {
25
-	    display_name = av[++ax];
168
-	    display_name = av[++ax];
26
+	    display_name = av[ax++];
169
-	}
27
 	}
170
-	else if (strcmp(arg, "-rc") == 0) {
28
 	else if (strcmp(arg, "-rc") == 0) {
29
-	    roachColor = av[++ax];
171
-	    roachColor = av[++ax];
30
+	    roachColor = av[ax++];
172
-	}
31
 	}
173
-	else if (strcmp(arg, "-speed") == 0) {
32
 	else if (strcmp(arg, "-speed") == 0) {
174
-	    roachSpeed = strtod(av[++ax], (char **)NULL);
33
-	    roachSpeed = atof(av[++ax]);
175
-	}
34
+	    roachSpeed = atof(av[ax++]);
176
-	else if (strcmp(arg, "-roaches") == 0) {
35
 	}
36
 	else if (strcmp(arg, "-roaches") == 0) {
37
-	    maxRoaches = strtol(av[++ax], (char **)NULL, 0);
177
-	    maxRoaches = strtol(av[++ax], (char **)NULL, 0);
38
+	    maxRoaches = strtol(av[ax++], (char **)NULL, 0);
178
-	}
39
 	}
179
-	else if (strcmp(arg, "-squish") == 0) {
40
 	else {
180
-	    squishRoach = True;
41
 	    Usage();
181
-	}
42
@@ -212,6 +216,7 @@
182
-	else if (strcmp(arg, "-rgc") == 0) {
183
-	    gutsColor = av[++ax];
184
-	}
185
-	else {
186
-	    Usage();
187
-	}
188
+    for (int ax = 1; ax < ac; ax++)
189
+    {
190
+        arg = av[ax];
191
+
192
+        if (strcmp(arg, "-display") == 0)
193
+            display_name = av[++ax];
194
+        else if (strcmp(arg, "-rc") == 0)
195
+            roachColor = av[++ax];
196
+        else if (strcmp(arg, "-speed") == 0)
197
+            roachSpeed = (float) strtod(av[++ax], (char **) NULL);
198
+        else if (strcmp(arg, "-roaches") == 0)
199
+            maxRoaches = (int) strtol(av[++ax], (char **) NULL, 0);
200
+        else if (strcmp(arg, "-squish") == 0)
201
+            squishRoach = True;
202
+        else if (strcmp(arg, "-rgc") == 0)
203
+            gutsColor = av[++ax];
204
+        else
205
+            Usage();
206
     }
207
 
208
-    srand((int)time((long *)NULL));
209
-    
210
+    /* Compensate rate of turning for speed of movement. */
211
+    turnSpeed = 200 / roachSpeed;
212
+
213
+    if (turnSpeed < 1)
214
+        turnSpeed = 1;
215
+
216
+    srand((unsigned int) time((time_t *) NULL));
217
+
218
     /*
219
        Catch some signals so we can erase any visible roaches.
220
     */
221
@@ -158,144 +162,180 @@
222
     signal(SIGHUP, SigHandler);
223
 
224
     display = XOpenDisplay(display_name);
225
-    if (display == NULL) {
226
-	if (display_name == NULL) display_name = getenv("DISPLAY");
227
-	(void) fprintf(stderr, "%s: cannot connect to X server %s\n", av[0],
228
-	    display_name ? display_name : "(default)");
229
-	exit(1);
230
+
231
+    if (display == NULL)
232
+    {
233
+        if (display_name == NULL)
234
+            display_name = getenv("DISPLAY");
235
+
236
+        fprintf(stderr,
237
+                "%s: cannot connect to X server %s\n",
238
+                av[0],
239
+                display_name ? display_name : "(default)");
240
+        exit(1);
241
     }
242
 
243
     screen = DefaultScreen(display);
244
     rootWin = FindRootWindow();
245
     black = BlackPixel(display, screen);
246
-    white = WhitePixel(display, screen);
247
 
248
-    display_width = DisplayWidth(display, screen);
249
-    display_height = DisplayHeight(display, screen);
250
-    center_x = display_width / 2;
251
-    center_y = display_height / 2;
252
-    
253
+    display_width = (unsigned int) DisplayWidth(display, screen);
254
+    display_height = (unsigned int) DisplayHeight(display, screen);
255
+
256
     /*
257
        Create roach pixmaps at several orientations.
258
     */
259
-    for (ax=0; ax<360; ax+=ROACH_ANGLE) {
260
-	rx = ax / ROACH_ANGLE;
261
-	angle = rx * 0.261799387799;
262
-	rp = &roachPix[rx];
263
-	rp->pixmap = XCreateBitmapFromData(display, rootWin,
264
-	    rp->roachBits, rp->width, rp->height);
265
-	rp->sine = sin(angle);
266
-	rp->cosine = cos(angle);
267
+    for (int ax = 0; ax < 360; ax += ROACH_ANGLE)
268
+    {
269
+        int rx = ax / ROACH_ANGLE;
270
+        angle = (float) (rx * 0.261799387799);
271
+        rp = &roachPix[rx];
272
+        rp->pixmap = XCreateBitmapFromData(display,
273
+                                           rootWin,
274
+                                           rp->roachBits,
275
+                                           (unsigned int) rp->width,
276
+                                           (unsigned int) rp->height);
277
+        rp->sine = (float) sin(angle);
278
+        rp->cosine = (float) cos(angle);
279
     }
280
 
281
     /*
282
       Create the squished pixmap
283
     */
284
-    if (squishRoach) {
285
-    	squishMap = XCreateBitmapFromData(display, rootWin,
286
-		squish_bits, squish_width, squish_height);
287
-    }
288
+    if (squishRoach)
289
+        squishMap = XCreateBitmapFromData(display,
290
+                                          rootWin,
291
+                                          squish_bits,
292
+                                          squish_width,
293
+                                          squish_height);
294
 
295
-    roaches = (Roach *)malloc(sizeof(Roach) * maxRoaches);
296
+    roaches = (Roach *) malloc(sizeof(Roach) * maxRoaches);
297
 
298
     gc = XCreateGC(display, rootWin, 0L, &xgcv);
299
     XSetForeground(display, gc, AllocNamedColor(roachColor, black));
300
     XSetFillStyle(display, gc, FillStippled);
301
 
302
-    if (squishRoach && gutsColor != NULL) {
303
+    if (squishRoach && gutsColor != NULL)
304
+    {
305
         gutsGC = XCreateGC(display, rootWin, 0L, &xgcv);
306
         XSetForeground(display, gutsGC, AllocNamedColor(gutsColor, black));
307
         XSetFillStyle(display, gutsGC, FillStippled);
308
     }
309
     else
310
-	gutsGC = gc;
311
-    
312
+    {
313
+        gutsGC = gc;
314
+    }
315
+
316
     while (curRoaches < maxRoaches)
317
-	AddRoach();
318
-    
319
+        AddRoach();
320
+
321
     XSelectInput(display, rootWin, ExposureMask | SubstructureNotifyMask);
322
 
323
-    if (squishRoach) {
324
-	xswa.event_mask = ButtonPressMask;
325
-	xswa.override_redirect = True;
326
-	squishWin = XCreateWindow(display, rootWin, 0, 0,
327
-			display_width, display_height, 0,
328
-			CopyFromParent, InputOnly, CopyFromParent,
329
-			CWOverrideRedirect | CWEventMask, &xswa);
330
-	XLowerWindow(display, squishWin);
331
+    if (squishRoach)
332
+    {
333
+        xswa.event_mask = ButtonPressMask;
334
+        xswa.override_redirect = True;
335
+        squishWin = XCreateWindow(display,
336
+                                  rootWin,
337
+                                  0, 0,
338
+                                  display_width, display_height,
339
+                                  0,
340
+                                  CopyFromParent, InputOnly, CopyFromParent,
341
+                                  CWOverrideRedirect | CWEventMask,
342
+                                  &xswa);
343
+        XLowerWindow(display, squishWin);
344
     }
345
-    
346
+
347
     needCalc = 1;
348
-    while (!done) {
349
-	if (XPending(display)) {
350
-	    XNextEvent(display, &ev);
351
-	}
352
-	else {
353
-	    if (needCalc) {
354
-		needCalc = CalcRootVisible();
355
-	    }
356
-	    if (needCalc)
357
-		nVis = 0;
358
-	    else
359
-	    	nVis = MarkHiddenRoaches();
360
-	    if (nVis) {
361
-		ev.type = SCAMPER_EVENT;
362
-		if (!squishWinUp && squishRoach) {
363
-		    XMapWindow(display, squishWin);
364
-		    squishWinUp = True;
365
-		}
366
-	    }
367
-	    else {
368
-		if (squishWinUp && squishRoach) {
369
-		    XUnmapWindow(display, squishWin);
370
-		    squishWinUp = False;
371
-		}
372
-		if (needCalc == 0)
373
-		    DrawRoaches();
374
-		eventBlock = 1;
375
-		XNextEvent(display, &ev);
376
-		eventBlock = 0;
377
-	    }
378
-	}
379
-	
380
-	switch (ev.type) {
381
-	    
382
-	    case SCAMPER_EVENT:
383
-		for (rx=0; rx<curRoaches; rx++) {
384
-		    if (!roaches[rx].hidden)
385
-			MoveRoach(rx);
386
-		}
387
-		DrawRoaches();
388
-		XSync(display, False);
389
-		break;
390
-		
391
-	    case UnmapNotify:
392
-		if (ev.xunmap.window != squishWin)
393
-		    needCalc = 1;
394
-		break;
395
-
396
-	    case MapNotify:
397
-	    case Expose:
398
-	    case ConfigureNotify:
399
-		needCalc = 1;
400
-		break;
401
-	
402
-	    case ButtonPress:
403
-		checkSquish(&ev);
404
-		break;
405
-		
406
-	}
407
+
408
+    while (!done)
409
+    {
410
+        if (XPending(display))
411
+        {
412
+            XNextEvent(display, &ev);
413
+        }
414
+        else
415
+        {
416
+            if (needCalc)
417
+                needCalc = CalcRootVisible();
418
+
419
+            if (needCalc)
420
+                nVis = 0;
421
+            else
422
+                nVis = MarkHiddenRoaches();
423
+
424
+            ev.type = SCAMPER_EVENT;
425
+
426
+            if (nVis)
427
+            {
428
+                if (!squishWinUp && squishRoach)
429
+                {
430
+                    XMapWindow(display, squishWin);
431
+                    squishWinUp = True;
432
+                }
433
+            }
434
+            else
435
+            {
436
+                if (squishWinUp && squishRoach)
437
+                {
438
+                    XUnmapWindow(display, squishWin);
439
+                    squishWinUp = False;
440
+                }
441
+
442
+                /*
443
+                if (needCalc == 0)
444
+                    DrawRoaches();
445
+
446
+                eventBlock = 1;
447
+                XNextEvent(display, &ev);
448
+                eventBlock = 0;
449
+                */
450
+            }
451
+        }
452
+
453
+        switch (ev.type)
454
+        {
455
+            case SCAMPER_EVENT:
456
+                for (int rx = 0; rx < curRoaches; rx++)
457
+                    if (!roaches[rx].hidden)
458
+                        MoveRoach(rx);
459
+
460
+                DrawRoaches();
461
+                XFlush(display);
462
+                usleep(20000);
463
+                XSync(display, False);
464
+                break;
465
+
466
+            case UnmapNotify:
467
+                if (ev.xunmap.window != squishWin)
468
+                    needCalc = 1;
469
+                break;
470
+
471
+            case MapNotify:
472
+            case Expose:
473
+            case ConfigureNotify:
474
+                needCalc = 1;
475
+                break;
476
+
477
+            case ButtonPress:
478
+                checkSquish(&ev);
479
+                done = !curRoaches;     /* Stop program if there are no more roaches */
480
+                break;
481
+
482
+            default:
483
+                break;
484
+        }
485
     }
486
-    
487
+
43
     CoverRoot();
488
     CoverRoot();
44
     
489
-    
45
     XCloseDisplay(display);
490
     XCloseDisplay(display);
46
+    return(0);
491
+    free(roaches);
492
+    return 0;
47
 }
493
 }
48
 
494
 
49
 #define USEPRT(msg) fprintf(stderr, msg)
495
 #define USEPRT(msg) fprintf(stderr, msg)
50
@@ -465,7 +470,7 @@
496
 
497
-void
498
-Usage()
499
+void Usage()
500
 {
501
     USEPRT("Usage: xroach [options]\n\n");
502
     USEPRT("Options:\n");
503
@@ -305,314 +345,345 @@
504
     USEPRT("       -speed   roachspeed\n");
505
     USEPRT("       -squish\n");
506
     USEPRT("       -rgc     roachgutscolor\n");
507
-    
508
+
509
     exit(1);
510
 }
511
 
512
-void
513
-SigHandler()
514
+void SigHandler()
515
 {
516
-       
517
     /*
518
        If we are blocked, no roaches are visible and we can just bail
519
        out.  If we are not blocked, then let the main procedure clean
520
        up the root window.
521
     */
522
-    if (eventBlock) {
523
-	XCloseDisplay(display);
524
-	exit(0);
525
+    if (eventBlock)
526
+    {
527
+        XCloseDisplay(display);
528
+        exit(0);
529
     }
530
-    else {
531
-	done = 1;
532
+    else
533
+    {
534
+        done = 1;
535
     }
536
 }
537
 
538
 /*
539
    Find the root or virtual root window.
540
 */
541
-Window
542
-FindRootWindow()
543
+Window FindRootWindow()
544
 {
545
-    Window rootWin;
546
-    Window realRoot;
547
+    Atom actualType;
548
     Atom swmVroot;
549
-    Window rootReturn, parentReturn, *children;
550
+    int actualFormat;
551
+    unsigned char *newRoot;
552
     unsigned int numChildren;
553
-    int cx;
554
-    Atom actualType;
555
-    Atom actualFormat;
556
-    unsigned long nItems;
557
     unsigned long bytesAfter;
558
-    Window *newRoot;
559
-    
560
+    unsigned long nItems;
561
+    Window *children;
562
+    Window parentReturn;
563
+    Window realRoot;
564
+    Window rootReturn;
565
+    Window rootWin;
566
+
567
     /*
568
        Get real root window.
569
     */
570
     realRoot = rootWin = RootWindow(display, screen);
571
-    
572
+
573
     /*
574
        Get atom for virtual root property.  If the atom doesn't
575
        exist, we can assume the corresponding property does not
576
        exist. 
577
     */
578
     swmVroot = XInternAtom(display, "__SWM_VROOT", True);
579
-    
580
+
581
     if (swmVroot == None)
582
-	return rootWin;
583
-    
584
+        return rootWin;
585
+
586
     /*
587
        Run children of root, looking for a virtual root.
588
     */
589
-    XQueryTree(display, rootWin, &rootReturn, &parentReturn, 
590
-		    &children, &numChildren);
591
-    for (cx=0; cx<numChildren; cx++) {
592
-	newRoot = NULL;
593
-	nItems = 0;
594
-	if (XGetWindowProperty(display, children[cx], swmVroot, 0L, 1L, False,
595
-	    XA_WINDOW, &actualType, &actualFormat, &nItems,
596
-	    &bytesAfter, &newRoot) == Success && actualFormat != None) {
597
-		if (nItems >= 1) {
598
-		    rootWin = *newRoot;
599
-		}
600
-		if (newRoot) {
601
-		    XFree(newRoot);
602
-		}
603
-	}
604
-	if (rootWin != realRoot) break;
605
+    XQueryTree(display,
606
+               rootWin,
607
+               &rootReturn,
608
+               &parentReturn,
609
+               &children,
610
+               &numChildren);
611
+
612
+    for (int cx = 0; cx < numChildren; cx++)
613
+    {
614
+        newRoot = NULL;
615
+        nItems = 0;
616
+
617
+        if (XGetWindowProperty(display,
618
+                               children[cx],
619
+                               swmVroot,
620
+                               0,
621
+                               1,
622
+                               False,
623
+                               XA_WINDOW,
624
+                               &actualType,
625
+                               &actualFormat,
626
+                               &nItems,
627
+                               &bytesAfter,
628
+                               &newRoot) == Success && actualFormat != None)
629
+        {
630
+            if (nItems >= 1)
631
+                rootWin = *newRoot;
632
+
633
+            if (newRoot)
634
+                XFree(newRoot);
635
+        }
636
+
637
+        if (rootWin != realRoot)
638
+            break;
639
     }
640
+
641
     XFree(children);
642
-    
643
+
644
     return rootWin;
645
 }
646
 
647
 /*
648
    Generate random integer between 0 and maxVal-1.
649
 */
650
-int
651
-RandInt(maxVal)
652
-int maxVal;
653
+int RandInt(int maxVal)
654
 {
655
-	return rand() % maxVal;
656
+    return rand() % maxVal;
657
 }
658
 
659
 /*
660
    Check for roach completely in specified rectangle.
661
 */
662
-int
663
-RoachInRect(roach, rx, ry, x, y, width, height)
664
-Roach *roach;
665
-int rx;
666
-int ry;
667
-int x;
668
-int y;
669
-unsigned int width;
670
-unsigned int height;
671
-{
672
-    if (rx < x) return 0;
673
-    if ((rx + roach->rp->width) > (x + width)) return 0;
674
-    if (ry < y) return 0;
675
-    if ((ry + roach->rp->height) > (y + height)) return 0;
676
-    
677
+int RoachInRect(Roach *roach, int rx, int ry, int x, int y, unsigned int width, unsigned int height)
678
+{
679
+    if (rx < x)
680
+        return 0;
681
+
682
+    if ((rx + roach->rp->width) > (x + width))
683
+        return 0;
684
+
685
+    if (ry < y)
686
+        return 0;
687
+
688
+    if ((ry + roach->rp->height) > (y + height))
689
+        return 0;
690
+
691
     return 1;
692
 }
693
 
694
 /*
695
    Check for roach overlapping specified rectangle.
696
 */
697
-int
698
-RoachOverRect(roach, rx, ry, x, y, width, height)
699
-Roach *roach;
700
-int rx;
701
-int ry;
702
-int x;
703
-int y;
704
-unsigned int width;
705
-unsigned int height;
706
-{
707
-    if (rx >= (x + width)) return 0;
708
-    if ((rx + roach->rp->width) <= x) return 0;
709
-    if (ry >= (y + height)) return 0;
710
-    if ((ry + roach->rp->height) <= y) return 0;
711
-    
712
+int RoachOverRect(Roach *roach, int rx, int ry, int x, int y, unsigned int width, unsigned int height)
713
+{
714
+    if (rx >= (x + width))
715
+        return 0;
716
+
717
+    if ((rx + roach->rp->width) <= x)
718
+        return 0;
719
+
720
+    if (ry >= (y + height))
721
+        return 0;
722
+
723
+    if ((ry + roach->rp->height) <= y)
724
+        return 0;
725
+
726
     return 1;
727
 }
728
 
729
 /*
730
    Give birth to a roach.
731
 */
732
-void
733
-AddRoach()
734
+void AddRoach()
735
 {
736
     Roach *r;
737
-    
738
-    if (curRoaches < maxRoaches) {
739
-	r = &roaches[curRoaches++];
740
-	r->index = RandInt(ROACH_HEADINGS);
741
-	r->rp = &roachPix[r->index];
742
-	r->x = RandInt(display_width - r->rp->width);
743
-	r->y = RandInt(display_height - r->rp->height);
744
-	r->intX = -1;
745
-	r->intY = -1;
746
-	r->hidden = 0;
747
-	r->steps = RandInt(200);
748
-	r->turnLeft = RandInt(100) >= 50;
749
+
750
+    if (curRoaches < maxRoaches)
751
+    {
752
+        r = &roaches[curRoaches++];
753
+        r->index = RandInt(ROACH_HEADINGS);
754
+        r->rp = &roachPix[r->index];
755
+        r->x = RandInt(display_width - r->rp->width);
756
+        r->y = RandInt(display_height - r->rp->height);
757
+        r->intX = -1;
758
+        r->intY = -1;
759
+        r->hidden = 0;
760
+        r->steps = RandInt((int) turnSpeed);
761
+        r->turnLeft = RandInt(100) >= 50;
762
     }
763
 }
764
 
765
 /*
766
    Turn a roach.
767
 */
768
-void
769
-TurnRoach(roach)
770
-Roach *roach;
771
-{
772
-    if (roach->index != (roach->rp - roachPix)) return;
773
-
774
-    if (roach->turnLeft) {
775
-	roach->index += (RandInt(30) / 10) + 1;
776
-	if (roach->index >= ROACH_HEADINGS)
777
-	    roach->index -= ROACH_HEADINGS;
778
-    }
779
-    else {
780
-	roach->index -= (RandInt(30) / 10) + 1;
781
-	if (roach->index < 0)
782
-	    roach->index += ROACH_HEADINGS;
783
+void TurnRoach(Roach *roach)
784
+{
785
+    if (roach->index != (roach->rp - roachPix))
786
+        return;
787
+
788
+    if (roach->turnLeft)
789
+    {
790
+        roach->index += (RandInt(30) / 10) + 1;
791
+
792
+        if (roach->index >= ROACH_HEADINGS)
793
+            roach->index -= ROACH_HEADINGS;
794
+    } else
795
+    {
796
+        roach->index -= (RandInt(30) / 10) + 1;
797
+
798
+        if (roach->index < 0)
799
+            roach->index += ROACH_HEADINGS;
800
     }
801
 }
802
 
803
 /*
804
    Move a roach.
805
 */
806
-void
807
-MoveRoach(rx)
808
-int rx;
809
+void MoveRoach(int rx)
810
 {
811
-    Roach *roach;
812
-    Roach *r2;
813
     float newX;
814
     float newY;
815
-    int ii;
816
-    
817
+    Roach *roach;
818
+
819
     roach = &roaches[rx];
820
     newX = roach->x + (roachSpeed * roach->rp->cosine);
821
     newY = roach->y - (roachSpeed * roach->rp->sine);
822
-    
823
-    if (RoachInRect(roach, (int)newX, (int)newY, 
824
-			    0, 0, display_width, display_height)) {
825
-	
826
-	roach->x = newX;
827
-	roach->y = newY;
828
-
829
-	if (roach->steps-- <= 0) {
830
-	    TurnRoach(roach);
831
-	    roach->steps = RandInt(200);
832
-	}
833
-
834
-	for (ii=rx+1; ii<curRoaches; ii++) {
835
-	    r2 = &roaches[ii];
836
-	    if (RoachOverRect(roach, (int)newX, (int)newY,
837
-		r2->intX, r2->intY, r2->rp->width, r2->rp->height)) {
838
-	
839
-		TurnRoach(roach);
840
-	    }
841
-	}
842
+
843
+    if (RoachInRect(roach,
844
+                    (int) newX, (int) newY,
845
+                    0, 0,
846
+                    display_width, display_height))
847
+    {
848
+        roach->x = newX;
849
+        roach->y = newY;
850
+
851
+        if (roach->steps-- <= 0)
852
+        {
853
+            TurnRoach(roach);
854
+            roach->steps = RandInt((int) turnSpeed);
855
+
856
+            /*
857
+               Previously, roaches would just go around in circles.
858
+               This makes their movement more interesting (and disgusting too!).
859
+            */
860
+            if (RandInt(100) >= 80)
861
+                roach->turnLeft ^= 1;
862
+        }
863
+
864
+        /* This is a kind of anti-collision algorithm which doesn't do what it is supposed to do,
865
+           it eats CPU time and sometimes makes roaches spin around very crazy. Therefore it is
866
+           commented out.
867
+
868
+        for (int ii = rx + 2; ii < curRoaches; ii++) {
869
+            r2 = &roaches[ii];
870
+
871
+            if (RoachOverRect(roach,
872
+                              (int) newX, (int) newY,
873
+                              r2->intX, r2->intY,
874
+                              (unsigned int) r2->rp->width, (unsigned int) r2->rp->height))
875
+                TurnRoach(roach);
876
+
877
+        }
878
+        */
879
     }
880
-    else {
881
-	TurnRoach(roach);
882
+    else
883
+    {
884
+        TurnRoach(roach);
885
     }
886
 }
887
-    
888
+
889
 /*
890
    Draw all roaches.
891
 */
892
-void
893
-DrawRoaches()
894
+void DrawRoaches()
895
 {
896
     Roach *roach;
897
-    int rx;
898
-    
899
-    for (rx=0; rx<curRoaches; rx++) {
900
-	roach = &roaches[rx];
901
-	
902
-	if (roach->intX >= 0 && roach->rp != NULL) {
903
-	    XClearArea(display, rootWin, roach->intX, roach->intY,
904
-		roach->rp->width, roach->rp->height, False);
905
-	}
906
-    }
907
-    
908
-    for (rx=0; rx<curRoaches; rx++) {
909
-	roach = &roaches[rx];
910
-	
911
-	if (!roach->hidden) {
912
-	    roach->intX = roach->x;
913
-	    roach->intY = roach->y;
914
-	    roach->rp = &roachPix[roach->index];
915
-    
916
-	    XSetStipple(display, gc, roach->rp->pixmap);
917
-	    XSetTSOrigin(display, gc, roach->intX, roach->intY);
918
-	    XFillRectangle(display, rootWin, gc,
919
-		roach->intX, roach->intY, roach->rp->width, roach->rp->height);
920
-	}
921
-	else {
922
-	    roach->intX = -1;
923
-	}
924
+
925
+    for (int rx = 0; rx < curRoaches; rx++)
926
+    {
927
+        roach = &roaches[rx];
928
+
929
+        if (!roach->hidden)
930
+        {
931
+            XClearArea(display,
932
+                       rootWin,
933
+                       roach->intX,
934
+                       roach->intY,
935
+                       (unsigned int) roach->rp->width,
936
+                       (unsigned int) roach->rp->height,
937
+                       False);
938
+
939
+            roach->intX = (int) roach->x;
940
+            roach->intY = (int) roach->y;
941
+            roach->rp = &roachPix[roach->index];
942
+
943
+            XSetStipple(display, gc, roach->rp->pixmap);
944
+            XSetTSOrigin(display, gc, roach->intX, roach->intY);
945
+            XFillRectangle(display,
946
+                           rootWin,
947
+                           gc,
948
+                           roach->intX,
949
+                           roach->intY,
950
+                           (unsigned int) roach->rp->width,
951
+                           (unsigned int) roach->rp->height);
952
+        }
953
+        else
954
+        {
955
+            roach->intX = -1;
956
+        }
957
     }
958
 }
959
 
960
 /*
961
    Cover root window to erase roaches.
962
 */
963
-void
964
-CoverRoot()
965
+void CoverRoot()
966
 {
967
-    XSetWindowAttributes xswa;
968
     long wamask;
969
     Window roachWin;
970
-    
971
+    XSetWindowAttributes xswa;
972
+
973
     xswa.background_pixmap = ParentRelative;
974
     xswa.override_redirect = True;
975
     wamask = CWBackPixmap | CWOverrideRedirect;
976
-    roachWin = XCreateWindow(display, rootWin, 0, 0,
977
-		    display_width, display_height, 0, CopyFromParent,
978
-		    InputOutput, CopyFromParent, wamask, &xswa);
979
+    roachWin = XCreateWindow(display, rootWin,
980
+                             0, 0,
981
+                             display_width, display_height,
982
+                             0,
983
+                             CopyFromParent, InputOutput, CopyFromParent,
984
+                             (unsigned long) wamask, &xswa);
985
     XLowerWindow(display, roachWin);
986
     XMapWindow(display, roachWin);
987
     XFlush(display);
988
-}    
989
+}
990
 
991
 #if !GRAB_SERVER
992
-
993
-int
994
-RoachErrors(dpy, err)
995
-Display *dpy;
996
-XErrorEvent *err;
997
+int RoachErrors(XErrorEvent *err)
998
 {
999
     errorVal = err->error_code;
1000
-    
1001
+
1002
     return 0;
1003
 }
1004
-
1005
 #endif /* GRAB_SERVER */
1006
 
1007
 /*
1008
-   Calculate Visible region of root window.
1009
+   Calculate visible region of root window.
1010
 */
1011
-int
1012
-CalcRootVisible()
1013
+int CalcRootVisible()
1014
 {
1015
+    int winX, winY;
51
     Region covered;
1016
     Region covered;
52
     Region visible;
1017
     Region visible;
1018
+    unsigned int borderWidth;
1019
+    unsigned int depth;
1020
+    unsigned int nChildren;
1021
+    unsigned int winHeight, winWidth;
53
     Window *children;
1022
     Window *children;
54
-    int nChildren;
1023
-    int nChildren;
55
+    unsigned int nChildren;
56
     Window dummy;
1024
     Window dummy;
57
     XWindowAttributes wa;
1025
-    XWindowAttributes wa;
58
     int wx;
1026
-    int wx;
1027
     XRectangle rect;
1028
-    int winX, winY;
1029
-    unsigned int winHeight, winWidth;
1030
-    unsigned int borderWidth;
1031
-    unsigned int depth;
1032
-    
1033
+    XWindowAttributes wa;
1034
+
1035
     /*
1036
        If we don't grab the server, the XGetWindowAttribute or XGetGeometry
1037
        calls can abort us.  On the other hand, the server grabs can make for
1038
@@ -628,64 +699,83 @@
1039
        Get children of root.
1040
     */
1041
     XQueryTree(display, rootWin, &dummy, &dummy, &children, &nChildren);
1042
-    
1043
+
1044
     /*
1045
        For each mapped child, add the window rectangle to the covered
1046
        region.
1047
     */
1048
     covered = XCreateRegion();
1049
-    for (wx=0; wx<nChildren; wx++) {
1050
-	if (XEventsQueued(display, QueuedAlready)) {
1051
-	    XDestroyRegion(covered);
1052
-	    return 1;
1053
-	}
1054
-	errorVal = 0;
1055
-	XGetWindowAttributes(display, children[wx], &wa);
1056
-	if (errorVal) continue;
1057
-	if (wa.class == InputOutput && wa.map_state == IsViewable) {
1058
-	    XGetGeometry(display, children[wx], &dummy, &winX, &winY,
1059
-		&winWidth, &winHeight, &borderWidth, &depth);
1060
-	    if (errorVal) continue;
1061
-	    rect.x = winX;
1062
-	    rect.y = winY;
1063
-	    rect.width = winWidth + (borderWidth * 2);
1064
-	    rect.height = winHeight + (borderWidth * 2);
1065
-	    XUnionRectWithRegion(&rect, covered, covered);
1066
-	}
1067
+
1068
+    for (int wx = 0; wx < nChildren; wx++)
1069
+    {
1070
+        if (XEventsQueued(display, QueuedAlready))
1071
+        {
1072
+            XDestroyRegion(covered);
1073
+            return 1;
1074
+        }
1075
+
1076
+        errorVal = 0;
1077
+        XGetWindowAttributes(display, children[wx], &wa);
1078
+
1079
+        if (errorVal)
1080
+            continue;
1081
+
1082
+        if (wa.class == InputOutput && wa.map_state == IsViewable)
1083
+        {
1084
+            XGetGeometry(display, children[wx], &dummy,
1085
+                         &winX, &winY,
1086
+                         &winWidth, &winHeight,
1087
+                         &borderWidth, &depth);
1088
+
1089
+            if (errorVal)
1090
+                continue;
1091
+
1092
+            rect.x = (short) winX;
1093
+            rect.y = (short) winY;
1094
+
1095
+            rect.width = (unsigned short) (winWidth + (borderWidth * 2));
1096
+            rect.height = (unsigned short) (winHeight + (borderWidth * 2));
1097
+
1098
+            XUnionRectWithRegion(&rect, covered, covered);
1099
+        }
1100
     }
1101
+
1102
     XFree(children);
1103
 
1104
 #if GRAB_SERVER
1105
     XUngrabServer(display);
1106
 #else
1107
-    XSetErrorHandler((ErrorHandler *)NULL);
1108
+    XSetErrorHandler((ErrorHandler *) NULL);
1109
 #endif
1110
-    
1111
+
1112
     /*
1113
        Subtract the covered region from the root window region.
1114
     */
1115
     visible = XCreateRegion();
1116
+
1117
     rect.x = 0;
1118
     rect.y = 0;
1119
-    rect.width = display_width;
1120
-    rect.height = display_height;
1121
+
1122
+    rect.width = (unsigned short) display_width;
1123
+    rect.height = (unsigned short) display_height;
1124
+
1125
     XUnionRectWithRegion(&rect, visible, visible);
1126
     XSubtractRegion(visible, covered, visible);
1127
     XDestroyRegion(covered);
1128
-    
1129
+
1130
     /*
1131
        Save visible region globally.
1132
     */
1133
     if (rootVisible)
1134
-	XDestroyRegion(rootVisible);
1135
+        XDestroyRegion(rootVisible);
1136
+
1137
     rootVisible = visible;
1138
-    
1139
-    
1140
+
1141
     /*
1142
        Mark all roaches visible.
1143
     */
1144
-    for (wx=0; wx<curRoaches; wx++) 
1145
-	roaches[wx].hidden = 0;
1146
+    for (int wx = 0; wx < curRoaches; wx++)
1147
+        roaches[wx].hidden = 0;
1148
 
1149
     return 0;
1150
 }
1151
@@ -693,91 +783,92 @@
1152
 /*
1153
    Mark hidden roaches.
1154
 */
1155
-int
1156
-MarkHiddenRoaches()
1157
+int MarkHiddenRoaches()
1158
 {
1159
-    int rx;
1160
-    Roach *r;
1161
     int nVisible;
1162
-    
1163
+    Roach *r;
1164
+
1165
     nVisible = 0;
1166
-    for (rx=0; rx<curRoaches; rx++) {
1167
-	r = &roaches[rx];
1168
-	
1169
-	if (!r->hidden) {
1170
-	    if (r->intX > 0 && XRectInRegion(rootVisible, r->intX, r->intY,
1171
-			    r->rp->width, r->rp->height) == RectangleOut) {
1172
-		r->hidden = 1;
1173
-	    }
1174
-	    else {
1175
-		nVisible++;
1176
-	    }
1177
-	}
1178
+
1179
+    for (int rx = 0; rx < curRoaches; rx++)
1180
+    {
1181
+        r = &roaches[rx];
1182
+
1183
+        if (!r->hidden)
1184
+        {
1185
+            if (r->intX > 0 && XRectInRegion(rootVisible,
1186
+                                             r->intX,
1187
+                                             r->intY,
1188
+                                             (unsigned int) r->rp->width,
1189
+                                             (unsigned int) r->rp->height) == RectangleOut)
1190
+                r->hidden = 1;
1191
+            else
1192
+                nVisible++;
1193
+        }
1194
     }
1195
-    
1196
+
1197
     return nVisible;
1198
 }
1199
 
1200
 /*
1201
    Allocate a color by name.
1202
 */
1203
-Pixel
1204
-AllocNamedColor(colorName, dfltPix)
1205
-char *colorName;
1206
-Pixel dfltPix;
1207
+Pixel AllocNamedColor(char *colorName, Pixel dfltPix)
1208
 {
1209
-	Pixel pix;
1210
-	XColor scrncolor;
1211
-	XColor exactcolor;
1212
-
1213
-	if (XAllocNamedColor(display, DefaultColormap(display, screen),
1214
-		colorName, &scrncolor, &exactcolor)) {
1215
-		pix = scrncolor.pixel;
1216
-	}
1217
-	else {
1218
-		pix = dfltPix;
1219
-	}
1220
+    Pixel pix;
1221
+    XColor exactcolor;
1222
+    XColor scrncolor;
1223
+
1224
+    if (XAllocNamedColor(display,
1225
+                         DefaultColormap(display, screen),
1226
+                         colorName,
1227
+                         &scrncolor,
1228
+                         &exactcolor))
1229
+        pix = scrncolor.pixel;
1230
+    else
1231
+        pix = dfltPix;
1232
 
1233
-	return pix;
1234
+    return pix;
1235
 }
1236
 
1237
 /*
1238
- *	squishCheck - Check to see if we have to squish any roaches.
1239
+ *	Check to see if we have to squish any roaches.
1240
  */
1241
-checkSquish(buttonEvent)
1242
-XButtonEvent *buttonEvent;
1243
+void checkSquish(XButtonEvent *buttonEvent)
1244
 {
1245
-    int x, y;
1246
-    int i;
1247
-    int rx;
1248
+    int x;
1249
+    int y;
1250
     Roach *r;
1251
-/* */
1252
+
1253
     x = buttonEvent->x;
1254
     y = buttonEvent->y;
1255
 
1256
-    for (rx=0; rx<curRoaches; rx++) {
1257
-	r = &roaches[rx];
1258
-	if (r->rp == NULL) continue;
1259
-
1260
-	if (x > r->intX &&
1261
-	    x < (r->intX + r->rp->width) &&
1262
-	    y > r->intY &&
1263
-	    y < (r->intY + r->rp->height)) {
1264
-	    XSetStipple(display, gutsGC, squishMap);
1265
-	    XSetTSOrigin(display, gutsGC, r->intX, r->intY);
1266
-	    XFillRectangle(display, rootWin, gutsGC,
1267
-		r->intX, r->intY, squish_width, squish_height);
1268
-
1269
-	    /*
1270
-	     * Delete the roach
1271
-	     */
1272
-	    for (i = rx; i < curRoaches - 1; i++)
1273
-	        roaches[i] = roaches[i + 1];
1274
-	
1275
-	    curRoaches--;
1276
-	    rx--;
1277
-	}
1278
+    for (int rx = 0; rx < curRoaches; rx++)
1279
+    {
1280
+        r = &roaches[rx];
1281
+
1282
+        if (r->rp == NULL)
1283
+            continue;
1284
+
1285
+        if (x > r->intX && x < (r->intX + r->rp->width) && y > r->intY && y < (r->intY + r->rp->height))
1286
+        {
1287
+            XSetStipple(display, gutsGC, squishMap);
1288
+            XSetTSOrigin(display, gutsGC, r->intX, r->intY);
1289
+            XFillRectangle(display,
1290
+                           rootWin,
1291
+                           gutsGC,
1292
+                           r->intX,
1293
+                           r->intY,
1294
+                           squish_width,
1295
+                           squish_height);
1296
+            /*
1297
+            * Delete the roach
1298
+            */
1299
+            for (int i = rx; i < curRoaches - 1; i++)
1300
+                roaches[i] = roaches[i + 1];
1301
+
1302
+            curRoaches--;
1303
+            rx--;
1304
+        }
1305
     }
1306
-
1307
-    return;
1308
-}
1309
+}
1310
\ No newline at end of file

Return to bug 225867