ftp://ftp.uni-heidelberg.de/pub/X11/contrib/applications/xscreensaver-1.27.tar.Z
[xscreensaver] / hacks / screenhack.h
index bca3bcc5267f783e5f36df5213947575563fd709..9be436724f35c94f344a7d37996debbb4e89c05a 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 1992, 1993 Jamie Zawinski <jwz@lucid.com>
+/* xscreensaver, Copyright (c) 1992-1995 Jamie Zawinski <jwz@netscape.com>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -9,8 +9,7 @@
  * implied warranty.
  */
 
-#if 0
- * Found in Don Hopkin`s .plan file:
+/* Found in Don Hopkins' .plan file:
  *
  *   The color situation is a total flying circus.  The X approach to
  *   device independence is to treat everything like a MicroVax framebuffer
  *   WHAT IS YOUR COLORMAP?
  *         cmap = DefaultColormap(display, DefaultScreen(display));
  *   AND WHAT IS YOUR FAVORITE COLOR?
- *         favorite_color = 0; /* Black. */
- *         /* Whoops! No, I mean: */
+ *         favorite_color = 0; / * Black. * /
+ *         / * Whoops! No, I mean: * /
  *         favorite_color = BlackPixel(display, DefaultScreen(display));
- *         /* AAAYYYYEEEEE!! (client dumps core & falls into the chasm) */
+ *         / * AAAYYYYEEEEE!! (client dumps core & falls into the chasm) * /
  *
  *   WHAT IS YOUR DISPLAY?
  *         display = XOpenDisplay("unix:0");
  *                              8, PseudoColor, &vinfo) != 0)
  *            visual = vinfo.visual;
  *   AND WHAT IS THE NET SPEED VELOCITY OF AN XConfigureWindow REQUEST?
- *         /* Is that a SubStructureRedirectMask or a ResizeRedirectMask? */
- *   WHAT??! HOW AM I SUPPOSED TO KNOW THAT?
+ *         / * Is that a SubStructureRedirectMask or a ResizeRedirectMask? * /
+ *   WHAT?! HOW AM I SUPPOSED TO KNOW THAT?
  *   AAAAUUUGGGHHH!!!! (server dumps core & falls into the chasm)
- *
-#endif /* 0 */
+ */
 
 #ifndef _SCREENHACK_H_
 #define _SCREENHACK_H_
 #include <stdlib.h>
 #endif
 
+#ifdef __hpux
+ /* Which of the ten billion standards does values.h belong to?
+    What systems always have it? */
+# include <values.h>
+#endif
+
 #include <X11/Xlib.h>
 #include <X11/Xresource.h>
 #include <X11/Xos.h>
@@ -72,22 +76,11 @@ extern XrmOptionDescRec options [];
 extern int options_size;
 extern char *defaults [];
 
-#if __STDC__
-
-# define bcopy(from,to,size) memcpy((to),(from),(size))
-# define bzero(addr,size) memset((addr),0,(size))
+/* Screw it, we'll just use our own RNG.  See xscreensaver/utils/yarandom.c. */
+#include "yarandom.h"
 
-# if defined(SVR4) || defined(SYSV)
-extern int rand (void);
-extern void srand (unsigned int);
-#  define random() rand()
-#  define srandom(i) srand((unsigned int)(i))
-# else /* !totally-losing-SYSV */
-extern long random (void);
-extern void srandom (int);
-# endif /* !totally-losing-SYSV */
-#endif /* __STDC__ */
 
+#undef P
 #if __STDC__
 # define P(x)x
 #else
@@ -121,12 +114,26 @@ extern void make_color_ramp P((int h1, double s1, double v1,
                               XColor *pixels, int npixels));
 
 extern Pixmap grab_screen_image P((Display *dpy, Window window, int root_p));
+extern void copy_default_colormap_contents P((Display *dpy, Colormap to_cmap,
+                                             Visual *to_visual));
+
+#if defined (__GNUC__) && (__GNUC__ >= 2)
+ /* Implement frand using GCC's statement-expression extension. */
+
+# define frand(f)                                                      \
+  ({ double tmp = (((double) random()) /                               \
+                  (((double) ((unsigned int)~0)) / ((double) (f+f)))); \
+     tmp < 0 ? (-tmp) : tmp; })
+
+#else /* not GCC2 - implement frand using a global variable.*/
 
 static double _frand_tmp_;
-#define frand(f)                                                       \
- (_frand_tmp_ = (((double) random()) /                                         \
-                (((double) ((unsigned int)~0)) / ((double) (f+f)))),   \
-  _frand_tmp_ < 0 ? -_frand_tmp_ : _frand_tmp_)
+# define frand(f)                                                      \
+  (_frand_tmp_ = (((double) random()) /                                \
+                 (((double) ((unsigned int)~0)) / ((double) (f+f)))),  \
+   _frand_tmp_ < 0 ? (-_frand_tmp_) : _frand_tmp_)
+
+#endif /* not GCC2 */
 
 #undef P
 #endif /* _SCREENHACK_H_ */