File xscreensaver-filename.diff of Package xscreensaver

Index: xscreensaver-5.22/hacks/glx/glslideshow.c
===================================================================
--- xscreensaver-5.22.orig/hacks/glx/glslideshow.c
+++ xscreensaver-5.22/hacks/glx/glslideshow.c
@@ -72,15 +72,17 @@
 		  "*wireframe:       False                \n" \
                   "*showFPS:         False                \n" \
 	          "*fpsSolid:        True                 \n" \
 	          "*useSHM:          True                 \n" \
+	          "*basename:        2                    \n" \
 		  "*titleFont:       -*-helvetica-medium-r-normal-*-180-*\n" \
                   "*desktopGrabber:  xscreensaver-getimage -no-desktop %s\n" \
 		  "*grabDesktopImages:   False \n" \
 		  "*chooseRandomImages:  True  \n"
 
 # define refresh_slideshow 0
 # define release_slideshow 0
+# define DEF_BASENAME	    2
 # include "xlockmore.h"
 
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
@@ -314,8 +316,38 @@ alloc_image (ModeInfo *mi)
 
   return img;
 }
 
+/* Helper to return shortened filename
+ */
+static char*
+stripfilename(const char *filename, int pathlen)
+{
+  char *retstr, *s;
+  /* pathlen == 0: traditional behavior */
+  if (pathlen == 0)
+    if (filename[0] == '/')
+      {
+        /* strip filename to part between last "/" and last ".". */
+        const char* st = strrchr (filename, '/');
+	retstr = strdup (st+1);
+        s = strrchr (retstr, '.');
+        if (s) *s = 0;
+      }
+    else
+      retstr = strdup (filename);
+  else
+    {
+      const char* st;
+      for (st = filename+strlen(filename)-1; st >= filename; --st)
+	if (*st == '/' && --pathlen == 0) break;
+      retstr = strdup (st+1);
+      s = strrchr (retstr, '.');
+      if (s) *s = 0;
+    }
+  return retstr;
+}
+
 
 /* Callback that tells us that the texture has been loaded.
  */
 static void
@@ -353,9 +385,9 @@ image_loaded_cb (const char *filename, X
   img->h  = image_height;
   img->tw = texture_width;
   img->th = texture_height;
   img->geom = *geom;
-  img->title = (filename ? strdup (filename) : 0);
+  /* img->title = (filename ? strdup (filename) : 0); */
 
   /* If the image's width doesn't come back as the width of the screen,
      then the image must have been scaled down (due to insufficient
      texture memory.)  Scale up the coordinates to stretch the image
@@ -376,16 +408,12 @@ image_loaded_cb (const char *filename, X
 
   /* xscreensaver-getimage returns paths relative to the image directory
      now, so leave the sub-directory part in.  Unless it's an absolute path.
   */
-  if (img->title && img->title[0] == '/')
-    {
-      /* strip filename to part between last "/" and last ".". */
-      char *s = strrchr (img->title, '/');
-      if (s) strcpy (img->title, s+1);
-      s = strrchr (img->title, '.');
-      if (s) *s = 0;
-    }
+  if (filename)
+    img->title = stripfilename (filename, DEF_BASENAME);
+  else
+    img->title = 0;
 
   if (debug_p)
     fprintf (stderr, "%s: loaded   img %2d: \"%s\"\n",
              blurb(), img->id, (img->title ? img->title : "(null)"));
openSUSE Build Service is sponsored by