http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.14.tar.gz
[xscreensaver] / hacks / glx / starwars.c
index cfb40f8c1e2262bf7844eb0fef14e80c04b67885..5e41af2a7c8ab386ad8dfba8919fcf026b7258c0 100644 (file)
@@ -87,12 +87,17 @@ extern XtAppContext app;
 
 #ifdef USE_GL /* whole file */
 
+#include <ctype.h>
 #include <GL/glu.h>
 #include <sys/stat.h>
 #include "glutstroke.h"
 #include "glut_roman.h"
 #define GLUT_FONT (&glutStrokeRoman)
 
+#ifdef HAVE_UNAME
+# include <sys/utsname.h>
+#endif /* HAVE_UNAME */
+
 
 typedef struct {
   GLXContext *glx_context;
@@ -258,18 +263,55 @@ launch_text_generator (sws_configuration *sc)
 
   if (!strcasecmp(oprogram, "(default)"))
     {
+      oprogram = FORTUNE_PROGRAM;
+
 #ifdef __linux__
-      static int done_once = 0;
-      struct stat st;
-      char *cmd = "cat /usr/src/linux/README";
-      if (!(done_once++) && !stat (cmd+4, &st))
-        oprogram = cmd;
-      else
-#endif
-        oprogram = ZIPPY_PROGRAM;
+      {
+        static int done_once = 0;
+        if (!done_once)
+          {
+            struct utsname uts;
+            struct stat st;
+            done_once = 1;
+            if (uname (&uts) == 0)
+              {
+                static char cmd[200];
+                char *s;
+                /* strip version at the first non-digit-dash-dot, to
+                   lose any "SMP" crap at the end. */
+                for (s = uts.release; *s; s++)
+                  if (!isdigit(*s) && *s != '.' && *s != '-')
+                    *s = 0;
+                sprintf (cmd, "cat /usr/src/linux-%s/README", uts.release);
+                if (!stat (cmd+4, &st))
+                  oprogram = cmd;
+                else
+                  {
+                    /* kernel source not installed?  try X... */
+                    strcpy (cmd, "cat /usr/X11R6/lib/X11/doc/README");
+                    if (!stat (cmd+4, &st))
+                      oprogram = cmd;
+                  }
+              }
+          }
+      }
+#endif /* __linux__ */
+
+#ifdef __APPLE__   /* MacOS X + XDarwin */
+      {
+        static int done_once = 0;
+        if (!done_once)
+          {
+            struct stat st;
+            static char *cmd = "cat /usr/X11R6/README";
+            if (!stat (cmd+4, &st))
+              oprogram = cmd;
+          }
+      }
+#endif /* __APPLE__ */
     }
 
- program = (char *) malloc (strlen (oprogram) + 10);
 program = (char *) malloc (strlen (oprogram) + 10);
   strcpy (program, "( ");
   strcat (program, oprogram);
   strcat (program, " ) 2>&1");
@@ -357,12 +399,17 @@ get_more_lines (sws_configuration *sc)
           return;
         }
 
-      if (*s == '\n' || col > sc->columns)
+      if (*s == '\r' || *s == '\n' || col > sc->columns)
         {
           int L = s - sc->buf;
 
-          if (*s == '\n')
-            *s++ = 0;
+          if (*s == '\r' || *s == '\n')
+            {
+              if (*s == '\r' && s[1] == '\n')  /* swallow CRLF too */
+                *s++ = 0;
+
+              *s++ = 0;
+            }
           else
             {
               /* We wrapped -- try to back up to the previous word boundary. */
@@ -396,7 +443,7 @@ get_more_lines (sws_configuration *sc)
           if (sc->buf_tail > (s - sc->buf))
             {
               int i = sc->buf_tail - (s - sc->buf);
-              memcpy (sc->buf, s, i);
+              memmove (sc->buf, s, i);
               sc->buf_tail = i;
               sc->buf[sc->buf_tail] = 0;
             }
@@ -716,6 +763,9 @@ init_sws (ModeInfo *mi)
     }
 
   launch_text_generator (sc);
+
+  /* one more reshape, after line_height has been computed */
+  reshape_sws (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
 }
 
 
@@ -855,7 +905,9 @@ draw_sws (ModeInfo *mi)
             }
 
           if (alignment >= 0)
-            xoff = 1.0 - (glutStrokeLength(GLUT_FONT, line) * sc->font_scale);
+            xoff = 1.0 - (glutStrokeLength(GLUT_FONT,
+                                           (unsigned char *) line)
+                          * sc->font_scale);
           if (alignment == 0)
             xoff /= 2;