http://svn.poeml.de/viewvc/ppc/src-unpacked/xscreensaver/xscreensaver-4.12.tar.bz2...
[xscreensaver] / driver / xscreensaver-getimage.c
index 599c50cd4d10e5cab70dd98ca47c21ddeb4e1011..8dc800a40ed97709d542c4106d46dce3258cab1b 100644 (file)
@@ -43,6 +43,7 @@
 #include "colorbars.h"
 #include "visual.h"
 #include "prefs.h"
+#include "version.h"
 #include "vroot.h"
 
 #ifdef HAVE_GDK_PIXBUF
 #endif
 
 
+#ifdef __GNUC__
+ __extension__     /* shut up about "string length is greater than the length
+                      ISO C89 compilers are required to support" when including
+                      the .ad file... */
+#endif
+
 static char *defaults[] = {
 #include "../driver/XScreenSaver_ad.h"
  0
@@ -183,7 +190,10 @@ compute_image_scaling (int src_w, int src_h,
       int th = src_h * r;
       int pct = (r * 100);
 
+#if 0
+      /* this optimization breaks things */
       if (pct < 95 || pct > 105)  /* don't scale if it's close */
+#endif
         {
           if (verbose_p)
             fprintf (stderr, "%s: scaling image by %d%% (%dx%d -> %dx%d)\n",
@@ -574,8 +584,7 @@ maybe_read_ppm (Screen *screen, Visual *visual,
   ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, 0,
                          w, h, 8, 0);
   if (ximage)
-    ximage->data = (unsigned char *)
-      calloc (ximage->height, ximage->bytes_per_line);
+    ximage->data = (char *) calloc (ximage->height, ximage->bytes_per_line);
   if (!ximage || !ximage->data)
     {
       fprintf (stderr, "%s: out of memory loading %dx%d PPM file %s\n",
@@ -721,8 +730,7 @@ read_jpeg_ximage (Screen *screen, Visual *visual, Drawable drawable,
                          cinfo.output_width, cinfo.output_height,
                          8, 0);
   if (ximage)
-    ximage->data = (unsigned char *)
-      calloc (ximage->height, ximage->bytes_per_line);
+    ximage->data = (char *) calloc (ximage->height, ximage->bytes_per_line);
 
   if (ximage && ximage->data)
     scanbuf = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE,
@@ -813,8 +821,7 @@ scale_ximage (Screen *screen, Visual *visual,
   XImage *ximage2 = XCreateImage (dpy, visual, depth,
                                   ZPixmap, 0, 0,
                                   new_width, new_height, 8, 0);
-  ximage2->data = (unsigned char *)
-    calloc (ximage2->height, ximage2->bytes_per_line);
+  ximage2->data = (char *) calloc (ximage2->height, ximage2->bytes_per_line);
 
   if (!ximage2->data)
     {
@@ -1331,7 +1338,9 @@ mapper (XrmDatabase *db, XrmBindingList bindings, XrmQuarkList quarks,
 
 #define USAGE "usage: %s [ -options... ] window-id [pixmap-id]\n"            \
    "\n"                                                                              \
-   "    This program puts an image on the given window or pixmap.\n"         \
+   "    %s\n"                                                                \
+   "\n"                                                                              \
+   "    %s puts an image on the given window or pixmap.\n"                   \
    "\n"                                                                              \
    "    It is used by those xscreensaver demos that operate on images.\n"     \
    "    The image may be a file loaded from disk, a frame grabbed from\n"     \
@@ -1362,6 +1371,7 @@ main (int argc, char **argv)
   Screen *screen;
   char *oprogname = progname;
   char *file = 0;
+  char version[255];
 
   Window window = (Window) 0;
   Drawable drawable = (Drawable) 0;
@@ -1382,6 +1392,20 @@ main (int argc, char **argv)
 #  error Error!  This file definitely needs vroot.h!
 # endif
 
+  /* Get the version number, for error messages. */
+  {
+    char *v = (char *) strdup(strchr(screensaver_id, ' '));
+    char *s1, *s2, *s3, *s4;
+    s1 = (char *) strchr(v,  ' '); s1++;
+    s2 = (char *) strchr(s1, ' ');
+    s3 = (char *) strchr(v,  '('); s3++;
+    s4 = (char *) strchr(s3, ')');
+    *s2 = 0;
+    *s4 = 0;
+    sprintf (version, "Part of XScreenSaver %s -- %s.", s1, s3);
+    free(v);
+  }
+
   /* We must read exactly the same resources as xscreensaver.
      That means we must have both the same progclass *and* progname,
      at least as far as the resource database is concerned.  So,
@@ -1444,7 +1468,7 @@ main (int argc, char **argv)
           window = (Window) RootWindowOfScreen (screen);
         }
       else if ((1 == sscanf (argv[i], " 0x%lx %c", &w, &dummy) ||
-                1 == sscanf (argv[i], " %ld %c",   &w, &dummy)) &&
+                1 == sscanf (argv[i], " %lu %c",   &w, &dummy)) &&
                w != 0)
         {
           if (drawable)
@@ -1473,7 +1497,12 @@ main (int argc, char **argv)
             fprintf (stderr, "\n%s: unparsable window/pixmap ID: \"%s\"\n",
                      progname, argv[i]);
         LOSE:
-          fprintf (stderr, USAGE, progname);
+# ifdef __GNUC__
+          __extension__   /* don't warn about "string length is greater than
+                             the length ISO C89 compilers are required to
+                             support" in the usage string... */
+# endif
+          fprintf (stderr, USAGE, progname, version, progname);
           exit (1);
         }
     }