http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.14.tar.gz
[xscreensaver] / hacks / sonar.c
index c58f6aef69aedee357c8cabac933b2a3b893e117..00f7b3f6fc5e7d1a4da7ca874fe4b6b65212b83a 100644 (file)
@@ -38,7 +38,7 @@
  * software for any purpose.  It is provided "as is" without express or 
  * implied warranty.
  *
- * $Revision: 1.23 $
+ * $Revision: 1.29 $
  *
  * 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) {
@@ -481,7 +482,7 @@ lookupHost(ping_target *target)
                                 (ip[2] << 16) |
                                 (ip[1] <<  8) |
                                 (ip[0]));
-      hent = gethostbyaddr (ip, 4, AF_INET);
+      hent = gethostbyaddr ((const char *) ip, 4, AF_INET);
 
       if (debug_p > 1)
         fprintf (stderr, "%s:   %s => %s\n",
@@ -1011,8 +1012,13 @@ sendping(ping_info *pi, ping_target *pt)
     ICMP_CHECKSUM(icmph) = 0;
     ICMP_ID(icmph) = pi->pid;
     ICMP_SEQ(icmph) = pi->seq++;
+# ifdef GETTIMEOFDAY_TWO_ARGS
     gettimeofday((struct timeval *) &packet[sizeof(struct ICMP)],
                 (struct timezone *) 0);
+# else
+    gettimeofday((struct timeval *) &packet[sizeof(struct ICMP)]);
+# endif
+
     strcpy((char *) &packet[sizeof(struct ICMP) + sizeof(struct timeval)],
           pt->name);
     ICMP_CHECKSUM(icmph) = checksum((u_short *)packet, pcktsiz);
@@ -1116,7 +1122,7 @@ getping(sonar_info *si, ping_info *pi)
     /* Local Variables */
 
     struct sockaddr from;
-    int fromlen;
+    unsigned int fromlen;  /* Posix says socklen_t, but that's not portable */
     int result;
     u_char packet[1024];
     struct timeval now;
@@ -1174,7 +1180,11 @@ getping(sonar_info *si, ping_info *pi)
 
        /* Check the packet */
 
+# ifdef GETTIMEOFDAY_TWO_ARGS
        gettimeofday(&now, (struct timezone *) 0);
+# else
+       gettimeofday(&now);
+# endif
        ip = (struct ip *) packet;
         iphdrlen = IP_HDRLEN(ip) << 2;
        icmph = (struct ICMP *) &packet[iphdrlen];
@@ -1383,6 +1393,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.
  *
@@ -1418,7 +1448,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;
@@ -1463,6 +1493,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, 
@@ -1773,13 +1811,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.
         */
 
@@ -1790,7 +1828,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);
@@ -1820,17 +1858,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);
     }
@@ -1875,6 +1913,7 @@ parse_mode (Bool ping_works_p)
 # endif /* HAVE_PING */
 
       for (next = token;
+           *next &&
            *next != ',' && *next != ' ' && *next != '\t' && *next != '\n';
            next++)
         ;
@@ -1897,8 +1936,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
@@ -1906,7 +1945,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
            */
@@ -1916,7 +1955,7 @@ parse_mode (Bool ping_works_p)
         {
           new = subnetHostsList(0, 24);
         }
-      else if (1 == sscanf (token, "subnet/%d %c", &m, &dummy))
+      else if (1 == sscanf (token, "subnet/%u %c", &m, &dummy))
         {
           new = subnetHostsList(0, m);
         }
@@ -2003,7 +2042,11 @@ screenhack(Display *dpy, Window win)
 
        /* Call the sensor and display the results */
 
+# ifdef GETTIMEOFDAY_TWO_ARGS
        gettimeofday(&start, (struct timezone *) 0);
+# else
+       gettimeofday(&start);
+# endif
        bl = sensor(si, sensor_info);
        Sonar(si, bl);
 
@@ -2013,7 +2056,11 @@ screenhack(Display *dpy, Window win)
        if (si->current == 0)
          si->sweepnum++;
        XSync (dpy, False);
+# ifdef GETTIMEOFDAY_TWO_ARGS
        gettimeofday(&finish, (struct timezone *) 0);
+# else
+       gettimeofday(&finish);
+# endif
        sleeptime = si->delay - delta(&start, &finish);
         screenhack_handle_events (dpy);
        if (sleeptime > 0L)