X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fsonar.c;h=add3d6f1442bfe06997a9986221b123940449903;hb=6a1da724858673ac40aa13a9612340d8bed8c7b9;hp=1988821bd3612c32dc99aceef288711daeba2d32;hpb=8eb2873d7054e705c4e83f22d18c40946a9e2529;p=xscreensaver diff --git a/hacks/sonar.c b/hacks/sonar.c index 1988821b..add3d6f1 100644 --- a/hacks/sonar.c +++ b/hacks/sonar.c @@ -38,7 +38,7 @@ * software for any purpose. It is provided "as is" without express or * implied warranty. * - * $Revision: 1.20 $ + * $Revision: 1.25 $ * * Version 1.0 April 27, 1998. * - Initial version @@ -169,7 +169,7 @@ static long delta(struct timeval *, struct timeval *); /* * The Bogie. * - * This represents an object that is visable on the scope. + * This represents an object that is visible on the scope. */ typedef struct Bogie { @@ -205,7 +205,7 @@ typedef struct { int width, height; /* Window dimensions */ int minx, miny, maxx, maxy, /* Bounds of the scope */ centrex, centrey, radius; /* Parts of the scope circle */ - Bogie *visable; /* List of visable objects */ + Bogie *visible; /* List of visible objects */ int current; /* Current position of sweep */ int sweepnum; /* The current id of the sweep */ int delay; /* how long between each frame of the anim */ @@ -362,6 +362,7 @@ newBogie(char *name, int distance, int tick, int ttl) Bogie *new; + distance *= 1000; /* Allocate a bogie and initialize it */ if ((new = (Bogie *) calloc(1, sizeof(Bogie))) == NULL) { @@ -523,7 +524,7 @@ static void print_host (FILE *out, unsigned long ip, const char *name) { char ips[50]; - sprintf (ips, "%d.%d.%d.%d", + sprintf (ips, "%lu.%lu.%lu.%lu", (ip) & 255, (ip >> 8) & 255, (ip >> 16) & 255, @@ -787,9 +788,9 @@ subnetHostsList(int base, int subnet_width) if (subnet_width < 24) { fprintf (stderr, - "%s: pinging %u hosts is a bad idea; please use a subnet mask of 24 bits\n" + "%s: pinging %lu hosts is a bad idea; please use a subnet mask of 24 bits\n" " or more (255 hosts max.)\n", - progname, (1L << (32 - subnet_width)) - 1); + progname, (unsigned long) (1L << (32 - subnet_width)) - 1); exit (1); } else if (subnet_width > 30) @@ -860,9 +861,15 @@ subnetHostsList(int base, int subnet_width) fprintf(stderr, "%s: subnet: %s (%d.%d.%d.%d & %d.%d.%d.%d / %d)\n", progname, address, - (base>>24)&255, (base>>16)&255, (base>>8)&255, base&mask&255, - (mask>>24)&255, (mask>>16)&255, (mask>>8)&255, mask&255, - subnet_width); + (int) (base>>24)&255, + (int) (base>>16)&255, + (int) (base>> 8)&255, + (int) (base&mask&255), + (int) (mask>>24)&255, + (int) (mask>>16)&255, + (int) (mask>> 8)&255, + (int) (mask&255), + (int) subnet_width); p = address + strlen(address) + 1; sprintf(p, "%d", i); @@ -1110,7 +1117,7 @@ getping(sonar_info *si, ping_info *pi) /* Local Variables */ struct sockaddr from; - int fromlen; + unsigned int fromlen; int result; u_char packet[1024]; struct timeval now; @@ -1153,7 +1160,12 @@ getping(sonar_info *si, ping_info *pi) while (! timer_expired) { tv.tv_usec=pi->timeout; tv.tv_sec=0; +#if 0 + /* This breaks on BSD, which uses bzero() in the definition of FD_ZERO */ FD_ZERO(&rfds); +#else + memset (&rfds, 0, sizeof(rfds)); +#endif FD_SET(pi->icmpsock,&rfds); /* only wait a little while, in case we raced with the timer expiration. From Valentijn Sessink */ @@ -1339,8 +1351,8 @@ init_sim(void) return NULL; } sprintf(si->teamA[i].name, "%s%03d", si->teamAID, i+1); - si->teamA[i].nexttick = (int) (90.0 * random() / RAND_MAX); - si->teamA[i].nextdist = (int) (100.0 * random() / RAND_MAX); + si->teamA[i].nexttick = random() % 90; + si->teamA[i].nextdist = random() % 100; si->teamA[i].movedonsweep = -1; } @@ -1362,8 +1374,8 @@ init_sim(void) return NULL; } sprintf(si->teamB[i].name, "%s%03d", si->teamBID, i+1); - si->teamB[i].nexttick = (int) (90.0 * random() / RAND_MAX); - si->teamB[i].nextdist = (int) (100.0 * random() / RAND_MAX); + si->teamB[i].nexttick = random() % 90; + si->teamB[i].nextdist = random() % 100; si->teamB[i].movedonsweep = -1; } @@ -1372,6 +1384,26 @@ init_sim(void) return si; } +/* + * Creates and returns a drawing mask for the scope: + * mask out anything outside of the disc. + */ +static Pixmap +scope_mask (Display *dpy, Window win, sonar_info *si) +{ + XGCValues gcv; + Pixmap mask = XCreatePixmap(dpy, win, si->width, si->height, 1); + GC gc = XCreateGC (dpy, mask, 0, &gcv); + XSetFunction (dpy, gc, GXclear); + XFillRectangle (dpy, mask, gc, 0, 0, si->width, si->height); + XSetFunction (dpy, gc, GXset); + XFillArc(dpy, mask, gc, si->minx, si->miny, + si->maxx - si->minx, si->maxy - si->miny, + 0, 360 * 64); + return mask; +} + + /* * Initialize the Sonar. * @@ -1407,7 +1439,7 @@ init_sonar(Display *dpy, Window win) si->dpy = dpy; si->win = win; - si->visable = NULL; + si->visible = NULL; XGetWindowAttributes(dpy, win, &xwa); si->cmap = xwa.colormap; si->width = xwa.width; @@ -1452,6 +1484,14 @@ init_sonar(Display *dpy, Window win) dpy, si->cmap); si->grid = XCreateGC (dpy, win, GCForeground, &gcv); + /* Install the clip mask... */ + { + Pixmap mask = scope_mask (dpy, win, si); + XSetClipMask(dpy, si->text, mask); + XSetClipMask(dpy, si->erase, mask); + XFreePixmap (dpy, mask); /* it's been copied into the GCs */ + } + /* Compute pixel values for fading text on the display */ XParseColor(dpy, si->cmap, @@ -1513,8 +1553,8 @@ updateLocation(sim_target *t) int xdist, xtick; - xtick = (int) (3.0 * random() / RAND_MAX) - 1; - xdist = (int) (11.0 * random() / RAND_MAX) - 5; + xtick = (int) (random() % 3) - 1; + xdist = (int) (random() % 11) - 5; if (((t->nexttick + xtick) < 90) && ((t->nexttick + xtick) >= 0)) t->nexttick += xtick; else @@ -1762,13 +1802,13 @@ Sonar(sonar_info *si, Bogie *bl) Bogie *bp, *prev; int i; - /* Check for expired tagets and remove them from the visable list */ + /* Check for expired tagets and remove them from the visible list */ prev = NULL; - for (bp = si->visable; bp != NULL; bp = (bp ? bp->next : 0)) { + for (bp = si->visible; bp != NULL; bp = (bp ? bp->next : 0)) { /* - * Remove it from the visable list if it's expired or we have + * Remove it from the visible list if it's expired or we have * a new target with the same name. */ @@ -1779,7 +1819,7 @@ Sonar(sonar_info *si, Bogie *bl) DrawBogie(si, 0, bp->name, bp->tick, bp->distance, bp->ttl, bp->age); if (prev == NULL) - si->visable = bp->next; + si->visible = bp->next; else prev->next = bp->next; freeBogie(bp); @@ -1809,17 +1849,17 @@ Sonar(sonar_info *si, Bogie *bl) (4 * 64)); } - /* Move the new targets to the visable list */ + /* Move the new targets to the visible list */ for (bp = bl; bp != (Bogie *) 0; bp = bl) { bl = bl->next; - bp->next = si->visable; - si->visable = bp; + bp->next = si->visible; + si->visible = bp; } - /* Draw the visable targets */ + /* Draw the visible targets */ - for (bp = si->visable; bp != NULL; bp = bp->next) { + for (bp = si->visible; bp != NULL; bp = bp->next) { if (bp->age < bp->ttl) /* grins */ DrawBogie(si, 1, bp->name, bp->tick, bp->distance, bp->ttl,bp->age); } @@ -1835,6 +1875,7 @@ parse_mode (Bool ping_works_p) { char *source = get_string_resource ("ping", "Ping"); char *token, *end; + char dummy; ping_target *hostlist = 0; @@ -1885,8 +1926,8 @@ parse_mode (Bool ping_works_p) } #ifdef HAVE_PING - if ((4 == sscanf (token, "%d.%d.%d/%d %c", &n0,&n1,&n2, &m,&d)) || - (5 == sscanf (token, "%d.%d.%d.%d/%d %c", &n0,&n1,&n2,&n3,&m,&d))) + if ((4 == sscanf (token, "%u.%u.%u/%u %c", &n0,&n1,&n2, &m,&d)) || + (5 == sscanf (token, "%u.%u.%u.%u/%u %c", &n0,&n1,&n2,&n3,&m,&d))) { /* subnet: A.B.C.D/M subnet: A.B.C/M @@ -1894,7 +1935,7 @@ parse_mode (Bool ping_works_p) unsigned long ip = (n0 << 24) | (n1 << 16) | (n2 << 8) | n3; new = subnetHostsList(ip, m); } - else if (4 == sscanf (token, "%d.%d.%d.%d %c", &n0, &n1, &n2, &n3, &d)) + else if (4 == sscanf (token, "%u.%u.%u.%u %c", &n0, &n1, &n2, &n3, &d)) { /* IP: A.B.C.D */ @@ -1904,7 +1945,7 @@ parse_mode (Bool ping_works_p) { new = subnetHostsList(0, 24); } - else if (1 == sscanf (token, "subnet/%d %c", &m)) + else if (1 == sscanf (token, "subnet/%u %c", &m, &dummy)) { new = subnetHostsList(0, m); }