--- gv-3.5.8.orig/source/ps.c
+++ gv-3.5.8/source/ps.c
@@ -93,6 +93,8 @@
 #define memset(a,b,c) bzero(a,c)
 #endif
 
+extern int sec_scanf(const char *, const char *, ...);
+
 /* length calculates string length at compile time */
 /* can only be used with character constants */
 #define length(a)       (sizeof((a))-1)
@@ -417,10 +419,15 @@
       struct document *retval = NULL;
       FILE *tmpfile = (FILE*)NULL;
       char *filename_unc;
+      char *quoted_filename, *quoted_filename_unc;
       char cmd[512];
       char s[512];
       filename_unc=file_getTmpFilename(NULL,filename_raw);
-      sprintf(cmd,cmd_uncompress,filename,filename_unc);
+      quoted_filename = quote_filename(filename);
+      quoted_filename_unc = quote_filename(filename_unc);
+      sprintf(cmd,cmd_uncompress,quoted_filename,quoted_filename_unc);
+      GV_XtFree(quoted_filename);
+      GV_XtFree(quoted_filename_unc);
       INFMESSAGE(is compressed)
       INFSMESSAGE(uncompress command,cmd)
       if (ps_system(cmd) || file_fileIsNotUseful(filename_unc)) {
@@ -478,7 +485,7 @@
       doc = (struct document *) PS_malloc(sizeof(struct document));
       CHECK_MALLOCED(doc);
       memset(doc, 0, sizeof(struct document));
-      sscanf(line, "%*s %s", text);
+      sec_sscanf(line, "%*s %s", text, sizeof(text));
       /*###jp###*/
       /*doc->epsf = iscomment(text, "EPSF-");*/
       doc->epsf = iscomment(text, "EPSF");
@@ -488,10 +495,35 @@
       struct document *retval = NULL;
       FILE *tmpfile = (FILE*)NULL;
       char *filename_dsc;
+      char *quoted_filename, *quoted_filename_dsc;
+      char *pdfpos;
+      char *dscpos;
       char cmd[512];
       char s[512];
-      filename_dsc=file_getTmpFilename(NULL,filename_raw);
-      sprintf(cmd,cmd_scan_pdf,filename,filename_dsc);
+      filename_dsc=file_getTmpFilename(NULL,filename_raw);      
+      quoted_filename = quote_filename(filename);
+      quoted_filename_dsc = quote_filename(filename_dsc);
+      if ((pdfpos = strstr(cmd_scan_pdf,"%pdf")) &&
+	  (dscpos = strstr(cmd_scan_pdf,"%dsc"))) {
+	cmd[0] = '\0';
+	if (pdfpos < dscpos) {
+	  strncat(cmd,cmd_scan_pdf,(pdfpos-cmd_scan_pdf));
+	  strcat(cmd,quoted_filename);
+	  strncat(cmd,pdfpos+4,(dscpos-pdfpos-4));
+	  strcat(cmd,quoted_filename_dsc);
+	  strcat(cmd,dscpos+4);
+	} else {
+	  strncat(cmd,cmd_scan_pdf,(dscpos-cmd_scan_pdf));
+	  strcat(cmd,quoted_filename_dsc);
+	  strncat(cmd,dscpos+4,(pdfpos-dscpos-4));
+	  strcat(cmd,quoted_filename);
+	  strcat(cmd,pdfpos+4);
+	}
+      } else {
+	sprintf(cmd,cmd_scan_pdf,quoted_filename,quoted_filename_dsc);
+      }
+      GV_XtFree(quoted_filename);
+      GV_XtFree(quoted_filename_dsc);
       INFMESSAGE(is PDF)
       INFSMESSAGE(scan command,cmd)
 #ifdef VMS
@@ -546,7 +578,7 @@
 	} else if (doc->date == NULL && iscomment(line+2, "CreationDate:")) {
 	    doc->date = gettextline(line+length("%%CreationDate:"));
 	} else if (bb_set == NONE && iscomment(line+2, "BoundingBox:")) {
-	    sscanf(line+length("%%BoundingBox:"), "%s", text);
+	    sec_sscanf(line+length("%%BoundingBox:"), "%s", text, sizeof(text));
 	    if (strcmp(text, "(atend)") == 0) {
 		bb_set = ATEND;
 	    } else {
@@ -578,7 +610,7 @@
 	    }
 	} else if (orientation_set == NONE &&
 		   iscomment(line+2, "Orientation:")) {
-	    sscanf(line+length("%%Orientation:"), "%s", text);
+	    sec_sscanf(line+length("%%Orientation:"), "%s", text, sizeof(text));
 	    if (strcmp(text, "(atend)") == 0) {
 		orientation_set = ATEND;
 	    } else if (strcmp(text, "Portrait") == 0) {
@@ -589,7 +621,7 @@
 		orientation_set = 1;
 	    }
 	} else if (page_order_set == NONE && iscomment(line+2, "PageOrder:")) {
-	    sscanf(line+length("%%PageOrder:"), "%s", text);
+	    sec_sscanf(line+length("%%PageOrder:"), "%s", text, sizeof(text));
 	    if (strcmp(text, "(atend)") == 0) {
 		page_order_set = ATEND;
 	    } else if (strcmp(text, "Ascend") == 0) {
@@ -603,7 +635,7 @@
 		page_order_set = 1;
 	    }
 	} else if (pages_set == NONE && iscomment(line+2, "Pages:")) {
-	    sscanf(line+length("%%Pages:"), "%s", text);
+	    sec_sscanf(line+length("%%Pages:"), "%s", text, sizeof(text));
 	    if (strcmp(text, "(atend)") == 0) {
 		pages_set = ATEND;
 	    } else {
@@ -823,7 +855,7 @@
 		/* Do nothing */
 	    } else if (doc->default_page_orientation == NONE &&
 		iscomment(line+2, "PageOrientation:")) {
-		sscanf(line+length("%%PageOrientation:"), "%s", text);
+		sec_sscanf(line+length("%%PageOrientation:"), "%s", text, sizeof(text));
 		if (strcmp(text, "Portrait") == 0) {
 		    doc->default_page_orientation = PORTRAIT;
 		} else if (strcmp(text, "Landscape") == 0) {
@@ -945,7 +977,7 @@
 		/* Do nothing */
 	    } else if (doc->default_page_orientation == NONE &&
 		iscomment(line+2, "PageOrientation:")) {
-		sscanf(line+length("%%PageOrientation:"), "%s", text);
+		sec_sscanf(line+length("%%PageOrientation:"), "%s", text, sizeof(text));
 		if (strcmp(text, "Portrait") == 0) {
 		    doc->default_page_orientation = PORTRAIT;
 		} else if (strcmp(text, "Landscape") == 0) {
@@ -1082,7 +1114,7 @@
 		/* Do nothing */
 	    } else if (doc->pages[doc->numpages].orientation == NONE &&
 		iscomment(line+2, "PageOrientation:")) {
-		sscanf(line+length("%%PageOrientation:"), "%s", text);
+		sec_sscanf(line+length("%%PageOrientation:"), "%s", text, sizeof(text));
 		if (strcmp(text, "Portrait") == 0) {
 		    doc->pages[doc->numpages].orientation = PORTRAIT;
 		} else if (strcmp(text, "Landscape") == 0) {
@@ -1114,7 +1146,7 @@
 		PS_free(cp);
 	    } else if ((page_bb_set == NONE || page_bb_set == ATEND) &&
 		       iscomment(line+2, "PageBoundingBox:")) {
-		sscanf(line+length("%%PageBoundingBox:"), "%s", text);
+		sec_sscanf(line+length("%%PageBoundingBox:"), "%s", text, sizeof(text));
 		if (strcmp(text, "(atend)") == 0) {
 		    page_bb_set = ATEND;
 		} else {
@@ -1228,14 +1260,14 @@
 	    }
 	} else if (orientation_set == ATEND &&
 		   iscomment(line+2, "Orientation:")) {
-	    sscanf(line+length("%%Orientation:"), "%s", text);
+	    sec_sscanf(line+length("%%Orientation:"), "%s", text, sizeof(text));
 	    if (strcmp(text, "Portrait") == 0) {
 		doc->orientation = PORTRAIT;
 	    } else if (strcmp(text, "Landscape") == 0) {
 		doc->orientation = LANDSCAPE;
 	    }
 	} else if (page_order_set == ATEND && iscomment(line+2, "PageOrder:")) {
-	    sscanf(line+length("%%PageOrder:"), "%s", text);
+	    sec_sscanf(line+length("%%PageOrder:"), "%s", text, sizeof(text));
 	    if (strcmp(text, "Ascend") == 0) {
 		doc->pageorder = ASCEND;
 	    } else if (strcmp(text, "Descend") == 0) {
@@ -1738,6 +1770,8 @@
            (DSCcomment(line) && iscomment(line+2,(comment)))
 #define IS_BEGIN(comment)				\
            (iscomment(line+7,(comment)))
+#define IS_END(comment)				\
+           (iscomment(line+5,(comment)))
 #define SKIP_WHILE(cond)				\
 	   while (readline(fd, &line, NULL, &nbytes) && (cond)) *line_lenP += nbytes;\
            skipped=1;
@@ -1773,7 +1807,12 @@
    else
 #endif
    if  (!IS_COMMENT("Begin"))     {} /* Do nothing */
-   else if IS_BEGIN("Document:")  SKIP_UNTIL_1("EndDocument")
+   else if IS_BEGIN("Document:")  {  /* Skip the EPS without handling its content */
+            while (line && !IS_END("Document")) {
+               line = ps_io_fgetchars(fd,-1);
+               if (line) *line_lenP += FD_LINE_LEN;
+            }
+   }
    else if IS_BEGIN("Feature:")   SKIP_UNTIL_1("EndFeature")
 #ifdef USE_ACROREAD_WORKAROUND
    else if IS_BEGIN("File")       SKIP_UNTIL_2("EndFile","EOF")
@@ -1789,7 +1828,7 @@
       INFMESSAGE(encountered "BeginData:")
       if (FD_LINE_LEN > 100) FD_BUF[100] = '\0';
       text[0] = '\0';
-      if (sscanf(line+length("%%BeginData:"), "%d %*s %s", &num, text) >= 1) {
+      if (sec_sscanf(line+length("%%BeginData:"), "%d %*s %s", &num, text, sizeof(text)) >= 1) {
          if (strcmp(text, "Lines") == 0) {
             INFIMESSAGE(number of lines to skip:,num)
             while (num) {
@@ -1888,7 +1927,7 @@
          INFMESSAGE(encountered "BeginData:")
          if (FD_LINE_LEN > 100) FD_BUF[100] = '\0';
          text[0] = '\0';
-         if (sscanf(line+length("%%BeginData:"), "%d %*s %s", &num, text) >= 1) {
+         if (sec_sscanf(line+length("%%BeginData:"), "%d %*s %s", &num, text, sizeof(text)) >= 1) {
             if (strcmp(text, "Lines") == 0) {
                INFIMESSAGE(number of lines:,num)
                while (num) {
@@ -1985,7 +2024,7 @@
           PS_free(comment);
           continue;
        }
-       sscanf(comment+length("%%Pages:"), "%s", text);
+       sec_sscanf(comment+length("%%Pages:"), "%s", text, sizeof(text));
        if (strcmp(text, "(atend)") == 0) {
           fputs(comment, dest_file);
           pages_atend = True;
--- gv-3.5.8.orig/source/misc.c
+++ gv-3.5.8/source/misc.c
@@ -301,9 +301,10 @@
 /*############################################################*/
 
 void
-misc_setPageMarker(entry,kind)
+misc_setPageMarker(entry,kind,event)
   int entry;
   int kind; /* 0 = selected, 1 = highlighted , 2 = bring selected in sight*/
+  XEvent *event;
 {
   int x,y,yl,yu,ny=99999;
   Boolean b = False;
@@ -330,9 +331,12 @@
 	ny = (int)newtocClip->core.height - ((int)newtoc->core.y + yl + 14);
         if (y>ny) b = True;
       }
-      if (b) {
+      if (event && b) {
 	INFIMESSAGE(jumping to,ny)
 	ClipWidgetSetCoordinates(newtocClip,x,ny);
+	entry = VlistEntryOfPosition(newtoc,(int)event->xbutton.y+(y-ny));
+	if (entry != VlistHighlighted(newtoc))
+		VlistChangeHighlighted(newtoc,entry,XawVlistSet);
       }
     }
   }
@@ -689,7 +693,7 @@
        }
        if (toc_text) {
 	 INFMESSAGE(marking current_page as current)
-         misc_setPageMarker(current_page,0);
+         misc_setPageMarker(current_page,0,NULL);
        }
     }
 
@@ -1131,7 +1135,10 @@
 	}
 	s[i] = '\0';
 							n=0;
-	XtSetArg(args[n], XtNvlist, s);			n++;
+	if (	(!gv_filename_old)			||
+		(strcmp(gv_filename_old, gv_filename))	||
+		(doc->numpages != olddoc->numpages)	)
+		  XtSetArg(args[n], XtNvlist, s);	n++;
 	XtSetArg(args[n], XtNlabel, toc_text);		n++;
       } else {
 	s = NULL;
@@ -1154,7 +1161,7 @@
     misc_setSensitive(w_printAllPages     , show_printAllPages     , (gv_psfile   != NULL));
     misc_setSensitive(w_checkFile         , show_checkFile         , (gv_filename != NULL));
     misc_setSensitive(w_updateFile        , show_updateFile        , (gv_filename != NULL));
-    misc_setSensitive(w_showThisPage      , show_showThisPage      , (gv_filename != NULL));
+    misc_setSensitive(w_showThisPage      , show_showThisPage      , (gv_psfile   != NULL));
     misc_setSensitive(w_prevPage          , show_prevPage          , (toc_text    != NULL));
     misc_setSensitive(w_nextPage          , show_nextPage          , (gv_filename != NULL));
     misc_setSensitive(w_toggleCurrentPage , show_toggleCurrentPage , (toc_text    != NULL));
@@ -1168,7 +1175,7 @@
     XtSetSensitive(saveAllEntry,     (gv_psfile   != NULL));
     XtSetSensitive(saveMarkedEntry,  (toc_text    != NULL));
     XtSetSensitive(nextEntry,        (gv_filename != NULL));
-    XtSetSensitive(redisplayEntry,   (gv_filename != NULL));
+    XtSetSensitive(redisplayEntry,   (gv_psfile   != NULL));
     XtSetSensitive(prevEntry,        (toc_text    != NULL));
     XtSetSensitive(currentEntry,     (toc_text    != NULL));
     XtSetSensitive(oddEntry,         (toc_text    != NULL));
@@ -1718,3 +1725,51 @@
     ENDMESSAGE(catch_Xerror)
     return 0;
 }
+
+/*############################################################*/
+/* quote_filename */
+/* Quotes special characters in filenames */
+/* (taken from bash sources) */
+/*############################################################*/
+
+char *
+quote_filename (string) 
+     char *string;
+{
+    int c;
+    char *result, *r, *s;
+
+    BEGINMESSAGE(quote_filename)
+
+    result = (char*) GV_XtMalloc((2 * strlen (string) + 1) * sizeof(char));
+
+    for (r = result, s = string; s && (c = *s); s++)
+    {
+      switch (c)
+	{
+	case ' ': case '\t': case '\n':		/* IFS white space */
+	case '\'': case '"': case '\\':		/* quoting chars */
+	case '|': case '&': case ';':		/* shell metacharacters */
+	case '(': case ')': case '<': case '>':
+	case '!': case '{': case '}':		/* reserved words */
+	case '*': case '[': case '?': case ']':	/* globbing chars */
+	case '^':
+	case '$': case '`':			/* expansion chars */
+	  *r++ = '\\';
+	  *r++ = c;
+	  break;
+	case '#':				/* comment char */
+	  if (s == string)
+	    *r++ = '\\';
+	  /* FALLTHROUGH */
+	default:
+	  *r++ = c;
+	  break;
+	}
+    }
+    *r = '\0';
+
+    ENDMESSAGE(quote_filename)
+
+    return (result);
+}
--- gv-3.5.8.orig/source/actions.c
+++ gv-3.5.8/source/actions.c
@@ -94,7 +94,7 @@
   }
   if (new_width && new_height) {
     if (width != new_width || height != new_height) {
-       misc_setPageMarker(0,2); /* bring selected in sight */
+       misc_setPageMarker(0,2,event); /* bring selected in sight */
        width = new_width;
        height=new_height;
     }
@@ -253,7 +253,7 @@
 	}
       }
       h = doc_putPageInRange(doc,h);
-      misc_setPageMarker(h,1);
+      misc_setPageMarker(h,1,event);
     }
 
     nx = x = (int)aaa->core.x;
@@ -428,7 +428,7 @@
     if (!scrolling && toc_text) {
       entry = VlistEntryOfPosition(newtoc,(int)event->xbutton.y);
       if (entry >=0 && entry < doc->numpages) {
-	misc_setPageMarker(entry,0);
+	misc_setPageMarker(entry,0,event);
         show_page(entry,NULL);
       }
     }
--- gv-3.5.8.orig/source/callbacks.c
+++ gv-3.5.8/source/callbacks.c
@@ -870,7 +870,7 @@
   char *s;
 
   BEGINMESSAGE(cb_page)
-  if (gv_psfile && client_data) {
+  if (gv_filename && client_data) {
     s = (char*)client_data;
     if (*s=='-' || *s=='+') {  
       k = 1;
@@ -894,7 +894,7 @@
 	np = np + ((k==1) ? cp : 0);
 	np=doc_putPageInRange(doc,np);
 	IIMESSAGE(np,current_page)
-	misc_setPageMarker(np,0);
+	misc_setPageMarker(np,0,NULL);
 	if (np != current_page) show_page(np,NULL);
       } else {
 	if (k==1 && np > 0) show_page(np,NULL);
--- gv-3.5.8.orig/source/config.h
+++ gv-3.5.8/source/config.h
@@ -40,7 +40,7 @@
 ----------------------------------------------------------
 */
 
-/* #define GV_RESTART_IF_BUSY */
+/*#define GV_RESTART_IF_BUSY*/
 
 /*
 ##########################################################
--- gv-3.5.8.orig/source/main.c
+++ gv-3.5.8/source/main.c
@@ -985,9 +985,9 @@
   main_setInternResource(db,&gv_gs_x11_device,"gsX11Device");
   main_setInternResource(db,&gv_gs_x11_alpha_device,"gsX11AlphaDevice");
   main_setInternResource(db,&gv_gs_arguments,"gsArguments");
-  s = resource_getResource(db,gv_class,gv_class,"gsSafer",NULL);
+  s = resource_getResource(db,gv_class,gv_name,"gsSafer",NULL);
   if (!strcasecmp(s,"true"))  gv_gs_safer = 1; else gv_gs_safer = 0;
-  s = resource_getResource(db,gv_class,gv_class,"gsQuiet",NULL);
+  s = resource_getResource(db,gv_class,gv_name,"gsQuiet",NULL);
   if (!strcasecmp(s,"true"))  gv_gs_quiet = 1; else gv_gs_quiet = 0;
   ENDMESSAGE(main_setGhostscriptResources)
 }
--- gv-3.5.8.orig/source/misc.h
+++ gv-3.5.8/source/misc.h
@@ -57,7 +57,8 @@
 extern void			misc_setPageMarker (
 #if NeedFunctionPrototypes
     int, /* entry */
-    int	 /* kind */
+    int, /* kind */
+    XEvent*
 #endif
 );
 
@@ -115,6 +116,12 @@
 #endif
 );
  
+extern char *                   quote_filename (
+#if NeedFunctionPrototypes
+    char*
+#endif
+);
+
 #endif	/* _GV_MISC_H_ */
 
 
--- gv-3.5.8.orig/source/gv_misc_res.dat
+++ gv-3.5.8/source/gv_misc_res.dat
@@ -525,9 +525,9 @@
  <LeaveWindow>:		GV_Toc(unhighlight)	\n\
  <Btn1Down>:		GV_Toc(scrollon)	\n\
  <Btn1Motion>:		GV_Toc(scroll)		\n\
- <Btn1Up>:		GV_Toc(select)		\
+ <Btn1Up>:		GV_Toc(highlight)	\
 			GV_Toc(scrolloff)	\
-			GV_Toc(highlight)	\n\
+			GV_Toc(select)		\n\
  <Btn2Down>:		GV_Toc(toggleon)	\n\
  <Btn2Motion>:		GV_Toc(toggleextend)	\
 			GV_Toc(highlight)	\n\
--- gv-3.5.8.orig/source/Vlist.c
+++ gv-3.5.8/source/Vlist.c
@@ -623,6 +623,8 @@
     if (y < 0) entry = -1;
     else       entry = (vw->vlist.entries*y)/(int)vw->label.label_height;
   }
+  if (entry >= vw->vlist.entries)
+	  entry = vw->vlist.entries-1;
   IMESSAGE(entry)
   ENDMESSAGE(VlistEntryOfPosition)
   return(entry);
--- gv-3.5.8.orig/source/file.c
+++ gv-3.5.8/source/file.c
@@ -145,6 +145,25 @@
 }
 
 /*############################################################*/
+/* file_assureDirectory */
+/*############################################################*/
+
+void
+file_assureDirectory(to,from)
+   char *to;
+   char *from;
+{
+   int len;
+   BEGINMESSAGE(file_assureDirectory)
+   strcpy(to,from);
+#  ifndef VMS
+      len = strlen(to);
+      if (to[len-1] != '/') { to[len] = '/'; to[len+1] = '\0'; }
+#  endif
+   ENDMESSAGE(file_assureDirectory)
+}
+
+/*############################################################*/
 /* file_getTmpFilename */
 /* provide some temporary file name */
 /*############################################################*/
@@ -164,11 +183,13 @@
 
    BEGINMESSAGE(file_getTmpFilename)
 
-   if (!baseDirectory) baseDirectory = app_res.scratch_dir;
-   strcpy(tmpDirBuf,baseDirectory);
-   pos = file_locateFilename(tmpDirBuf);
-   if (pos) { ++pos; *pos='\0'; }
-   else strcpy(tmpDirBuf,app_res.scratch_dir);
+   pos = NULL;
+   if (baseDirectory) {
+     strcpy(tmpDirBuf,baseDirectory); 
+     pos = file_locateFilename(tmpDirBuf);
+   }
+   if (pos) *pos='\0';
+   else file_assureDirectory(tmpDirBuf,app_res.scratch_dir);
 
    if (!baseFilename) baseFilename= ".";
    strcpy(tmpNameBuf,baseFilename);
--- gv-3.5.8.orig/source/save.c
+++ gv-3.5.8/source/save.c
@@ -112,17 +112,19 @@
    String print_filename;
 {
    String error=NULL;
+   char *print_quoted_filename;
    char *c,*p;
    Cardinal m,n;
    String printfail=GV_ERROR_PRINT_FAIL;
 
    BEGINMESSAGE(print_file)
 
+   print_quoted_filename = quote_filename(print_filename);
    p = GV_XtNewString(print_command);
    n=0;
    c=p;
    while ((c=strstr(c,"%s"))) { c+=2; n++; }
-   m = (strlen(p)+(n>0?n:1)*strlen(print_filename)+5)*sizeof(char);
+   m = (strlen(p)+(n>0?n:1)*strlen(print_quoted_filename)+5)*sizeof(char);
    c = (char*) GV_XtMalloc(m);
    if (n>0) {
      char *e,*s;
@@ -133,13 +135,13 @@
        if (s) *s='\0';
        strcat(c,e);
        if (s) {
-	 strcat(c,print_filename);
+	 strcat(c,print_quoted_filename);
          e=s+2;
        } 
        else s=NULL;
      }
    } else {
-     sprintf(c, "%s %s",p,print_filename);
+     sprintf(c, "%s %s",p,print_quoted_filename);
    }
    INFSMESSAGE(printing:,c)
    if (SYSTEM_FAILED_ON(c)) {
@@ -149,6 +151,7 @@
    }
    GV_XtFree(c);
    GV_XtFree(p);
+   GV_XtFree(print_quoted_filename);
    ENDMESSAGE(print_file)
    return(error);
 }
@@ -198,6 +201,9 @@
    char proc_name[256];
    char *error=NULL;
    char *pos;
+   char *pdfpos;
+   char *pspos;
+   char *quoted_src_fn, *quoted_conv_fn;
 
    BEGINMESSAGE(save_forkPDFToPSConversion)
 
@@ -205,7 +211,30 @@
    strcpy(proc_name,pos);
    strcat(proc_name," conversion");
 
-   sprintf(command,gv_gs_cmd_conv_pdf,sd->conv_fn,sd->src_fn);
+   quoted_src_fn = quote_filename(sd->src_fn);
+   quoted_conv_fn = quote_filename(sd->conv_fn);
+   if ((pdfpos = strstr(gv_gs_cmd_conv_pdf,"%pdf")) &&
+       (pspos = strstr(gv_gs_cmd_conv_pdf,"%ps"))) {
+     command[0] = '\0';
+     if (pdfpos < pspos) {
+       strncat(command,gv_gs_cmd_conv_pdf,(pdfpos-gv_gs_cmd_conv_pdf));
+       strcat(command,quoted_src_fn);
+       strncat(command,pdfpos+4,(pspos-pdfpos-4));
+       strcat(command,quoted_conv_fn);
+       strcat(command,pspos+3);
+     } else {
+       strncat(command,gv_gs_cmd_conv_pdf,(pspos-gv_gs_cmd_conv_pdf));
+       strcat(command,quoted_conv_fn);
+       strncat(command,pspos+3,(pdfpos-pspos-3));
+       strcat(command,quoted_src_fn);
+       strcat(command,pdfpos+4);
+     }
+   } else {
+     sprintf(command,gv_gs_cmd_conv_pdf,quoted_conv_fn,quoted_src_fn);
+   }
+   GV_XtFree(quoted_src_fn);
+   GV_XtFree(quoted_conv_fn);
+
    INFSMESSAGE(starting conversion:,command)
    process_fork(proc_name,command,save_forkPDFToPSConversionDone,(XtPointer)sd);
    ENDMESSAGE(save_forkPDFToPSConversion)
--- gv-3.5.8.orig/source/main_resources.h
+++ gv-3.5.8/source/main_resources.h
@@ -285,10 +285,10 @@
  { "-spartan"		, ".style"			, XrmoptionNoArg	, "gv_spartan.dat"},
  { "-pixmap"		, ".useBackingPixmap"		, XrmoptionNoArg	, "True"	},
  { "-nopixmap"		, ".useBackingPixmap"		, XrmoptionNoArg	, "False"	},
- { "-quiet"		, ".quiet"    		        , XrmoptionNoArg	, "True"	},
- { "-noquiet"		, ".quiet"    		        , XrmoptionNoArg	, "False"	},
- { "-safer"		, ".safer"    		        , XrmoptionNoArg	, "True"	},
- { "-nosafer"		, ".safer"    		        , XrmoptionNoArg	, "False"	},
+ { "-quiet"		, ".gsQuiet"   		        , XrmoptionNoArg	, "True"	},
+ { "-noquiet"		, ".gsQuiet"   		        , XrmoptionNoArg	, "False"	},
+ { "-safer"		, ".gsSafer"   		        , XrmoptionNoArg	, "True"	},
+ { "-nosafer"		, ".gsSafer"  		        , XrmoptionNoArg	, "False"	},
  { "-arguments"		, ".arguments"			, XrmoptionSepArg	, NULL		},
  { "-h"		        , ".help"			, XrmoptionNoArg	, "?"		},
  { "-?"		        , ".help"			, XrmoptionNoArg	, "?"		},
--- gv-3.5.8.orig/source/process.c
+++ gv-3.5.8/source/process.c
@@ -272,8 +272,7 @@
    pid = fork();
 
    if (pid == 0) { /* child */
-      int  argc=0;
-      char *argv[20];
+      char *argv[3];
       char *c;
 
       INFMESSAGE(child process)
@@ -286,15 +285,10 @@
        */
       system(c);
 #else
-      while (isspace(*c)) c++;
-      while (*c) {
-         argv[argc++] = c;
-         while (*c && !isspace(*c)) c++;
-         if (*c) *c++ = '\0';
-         while (isspace(*c)) c++;
-         SMESSAGE(argv[argc-1])
-      }
-      argv[argc] = NULL;
+      argv[0] = "sh";
+      argv[1] = "-c";
+      argv[2] = c;
+      argv[3] = NULL;
 
       INFMESSAGE(spawning conversion process)
 /*
--- gv-3.5.8.orig/source/miscmenu.c
+++ gv-3.5.8/source/miscmenu.c
@@ -60,7 +60,7 @@
 
 static MiscMenuEntryStruct miscmenu_entries[] = {
   { "update",cb_checkFile,(XtPointer)CHECK_FILE_DATE,2 },
-  { "redisplay",cb_redisplay,NULL,2 },
+  { "redisplay",cb_redisplay,NULL,3 },
   { "toggle_current" , cb_setPageMark, (XtPointer)(SPM_CURRENT|SPM_TOGGLE),1 },
   { "toggle_even"    , cb_setPageMark, (XtPointer)(SPM_EVEN|SPM_TOGGLE),1 },
   { "toggle_odd"     , cb_setPageMark, (XtPointer)(SPM_ODD|SPM_TOGGLE),1 },
--- gv-3.5.8.orig/source/gv_user_res.dat
+++ gv-3.5.8/source/gv_user_res.dat
@@ -8,7 +8,7 @@
 GV.fallbackOrientation:	portrait
 GV.swapLandscape:	False
 GV.autoCenter:		True
-GV.antialias:		False
+GV.antialias:		True
 GV.respectDSC:		True
 GV.ignoreEOF:		True
 GV.confirmPrint:	True
--- gv-3.5.8.orig/source/options_fs.c
+++ gv-3.5.8/source/options_fs.c
@@ -105,7 +105,6 @@
    Widget	w;
    XtPointer	client_data, call_data;
 {
-   BEGINMESSAGE(options_fs_cb_apply)
    Arg args[5];
    Cardinal n;
    static Boolean s_scratch_dir = False;
--- gv-3.5.8.orig/source/secscanf.c
+++ gv-3.5.8/source/secscanf.c
@@ -0,0 +1,540 @@
+/*
+ * Secure sscanf - sscanf with an additional size argument for string
+ * arguments. All format specifiers should work as in the standard
+ * scanf - except for those writing to a string buffer provided by the
+ * caller. These specifiers take an additional argument of type size_t
+ * that specifies the size of the buffer.
+ *
+ * Copyright (C) 2002, Olaf Kirch <okir@suse.de>
+ */
+
+#define _GNU_SOURCE
+
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
+
+enum {
+	CONV_ANY,
+	CONV_STR,
+	CONV_NUM,
+	CONV_INTEGER,
+	CONV_FLOAT,
+	CONV_POINTER,
+};
+
+enum {
+	SIZE_ANY,
+	SIZE_SHORT,
+	SIZE_LONG,
+	SIZE_QUAD,
+};
+
+union scan_value {
+	const char *		v_string;
+	long long		v_signed;
+	unsigned long long	v_integer;
+	long double		v_double;
+	void *			v_pointer;
+};
+
+
+static int	process_number(union scan_value *vp, const char **sp, char fmt);
+static int	process_char_class(const char **, const char **, int);
+
+static inline int
+set_conv_type(int *type, int new_type)
+{
+	switch (*type) {
+	case CONV_ANY:
+		break;
+	case CONV_NUM:
+		if (new_type == CONV_INTEGER
+		 || new_type == CONV_FLOAT
+		 || new_type == CONV_POINTER)
+		 	break;
+		/* fallthru */
+	default:
+		if (*type != new_type)
+			return 0;
+		break;
+	}
+
+	*type = new_type;
+	return 1;
+}
+
+int
+sec_sscanf(const char *s, const char *fmt, ...)
+{
+	const char	*begin = s;
+	int		num_fields = 0, fmt_empty = 1;
+	va_list		ap;
+
+	va_start(ap, fmt);
+	while (*fmt) {
+		union scan_value value;
+		const char	*pre_space_skip,
+				*value_begin;
+		int		assign = 1, allocate = 0,
+				conv_type = CONV_ANY,
+				conv_size = SIZE_ANY,
+				field_width = -1,
+				nul_terminated = 1;
+		char		c;
+
+		c = *fmt++;
+		if (isspace(c)) {
+			while (isspace(*s))
+				s++;
+			continue;
+		}
+
+		fmt_empty = 0;
+		if (c != '%') {
+			if (c != *s)
+				goto stop;
+			s++;
+			continue;
+		}
+
+		/* Each % directive implicitly skips white space
+		 * except for the %c case */
+		pre_space_skip = s;
+		while (isspace(*s))
+			s++;
+
+		while (1) {
+			int	type = CONV_ANY, size = SIZE_ANY;
+
+			switch (*fmt) {
+			case '*':
+				assign = 0;
+				break;
+			case 'a':
+				type = CONV_STR;
+				allocate = 1;
+				break;
+			case 'h':
+				type = CONV_INTEGER;
+				size = SIZE_SHORT;
+				break;
+			case 'l':
+				type = CONV_NUM;
+				size = SIZE_LONG;
+				break;
+			case 'L':
+			case 'q':
+				type = CONV_NUM;
+				size = SIZE_QUAD;
+				break;
+			case '0': case '1': case '2': case '3': case '4':
+			case '5': case '6': case '7': case '8': case '9':
+				field_width = strtol(fmt, (char **) &fmt, 10);
+				fmt--;
+				break;
+			default:
+				goto flags_done;
+			}
+
+			if (!set_conv_type(&conv_type, type))
+				goto stop;
+
+			if (size != SIZE_ANY) {
+				if (size == SIZE_LONG && conv_size == SIZE_LONG)
+					conv_size = SIZE_QUAD;
+				else
+					conv_size = size;
+			}
+
+			fmt++;
+		}
+
+	flags_done:
+		value_begin = s;
+
+		switch (*fmt++) {
+		case '%':
+			if (*s == '\0')
+				goto eof;
+			if (*s != '%')
+				goto stop;
+			continue;
+		case '[':
+			value.v_string = s;
+			if (!set_conv_type(&conv_type, CONV_STR)
+			 || !process_char_class(&fmt, &s, field_width))
+				goto stop;
+			break;
+		case 's':
+			value.v_string = s;
+			if (!set_conv_type(&conv_type, CONV_STR))
+				goto stop;
+			while (*s && !isspace(*s) && field_width-- != 0)
+				s++;
+			break;
+		case 'c':
+			if (!set_conv_type(&conv_type, CONV_STR))
+				goto stop;
+			value.v_string = s = value_begin = pre_space_skip;
+
+			if (field_width < 0)
+				s++;
+			else while (*s && field_width--)
+				s++;
+			nul_terminated = 0;
+			break;
+		case 'd':
+		case 'i':
+		case 'o':
+		case 'u':
+		case 'x':
+		case 'X':
+			if (!set_conv_type(&conv_type, CONV_INTEGER)
+			 || !process_number(&value, &s, fmt[-1]))
+				goto stop;
+			break;
+		case 'p':
+			if (!set_conv_type(&conv_type, CONV_POINTER)
+			 || !process_number(&value, &s, fmt[-1]))
+				goto stop;
+			break;
+		case 'f':
+		case 'g':
+		case 'e':
+		case 'E':
+			if (!set_conv_type(&conv_type, CONV_FLOAT)
+			 || !process_number(&value, &s, fmt[-1]))
+				goto stop;
+			break;
+		case 'n':
+			if (!set_conv_type(&conv_type, CONV_INTEGER))
+				goto stop;
+			value.v_signed = (s - begin);
+			break;
+		default:
+			goto stop;
+		}
+
+		/* We've consumed what we need to consume. Now copy */
+		if (!assign)
+			continue;
+
+		/* Make sure we've consumed at least *something* */
+		if (s == value_begin)
+			goto eof;
+
+		/* Deal with a conversion flag */
+		if (conv_type == CONV_STR && allocate) {
+			value.v_pointer = strdup(value.v_string); ((char *)value.v_pointer)[s - value.v_string] = '\0';
+			conv_type = CONV_POINTER;
+			allocate = 0;
+		}
+
+		switch (conv_type) {
+		case CONV_STR:
+			{
+				const char *string = value.v_string;
+				char	*buf;
+				size_t	size;
+
+				if (string == NULL)
+					goto stop;
+				buf = va_arg(ap, char *);
+				size = va_arg(ap, size_t) - nul_terminated;
+				if (size > s - string)
+					size = s - string;
+				strncpy(buf, string, size);
+				if (nul_terminated)
+					buf[size] = '\0';
+			}
+			break;
+
+		case CONV_POINTER:
+			{
+				void	**ptr;
+
+				ptr = va_arg(ap, void **);
+				*ptr = value.v_pointer;
+			}
+			break;
+		case CONV_INTEGER:
+			{
+				void	*ptr;
+
+				ptr = va_arg(ap, void *);
+				switch (conv_size) {
+				case SIZE_SHORT:
+					*(short *) ptr = value.v_integer;
+					break;
+				case SIZE_ANY:
+					*(int *) ptr = value.v_integer;
+					break;
+				case SIZE_LONG:
+					*(long *) ptr = value.v_integer;
+					break;
+				case SIZE_QUAD:
+					*(long long *) ptr = value.v_integer;
+					break;
+				default:
+					goto stop;
+				}
+			}
+			break;
+		case CONV_FLOAT:
+			{
+				void	*ptr;
+
+				ptr = va_arg(ap, void *);
+				switch (conv_size) {
+				case SIZE_ANY:
+					*(float *) ptr = value.v_double;
+					break;
+				case SIZE_LONG:
+					*(double *) ptr = value.v_double;
+					break;
+				case SIZE_QUAD:
+					*(long double *) ptr = value.v_double;
+					break;
+				default:
+					goto stop;
+				}
+			}
+			break;
+		default:
+			goto stop;
+		}
+
+		num_fields++;
+	}
+
+stop:	return num_fields;
+
+eof:	if (num_fields)
+		return num_fields;
+	return EOF;
+}
+
+static int
+process_number(union scan_value *vp, const char **sp, char fmt)
+{
+	const char	*s = *sp;
+
+	switch (fmt) {
+	case 'd':
+		vp->v_signed = strtoll(s, (char **) sp, 10);
+		break;
+	case 'i':
+		vp->v_signed = strtoll(s, (char **) sp, 0);
+		break;
+	case 'o':
+		vp->v_integer = strtoull(s, (char **) sp, 8);
+		break;
+	case 'u':
+		vp->v_integer = strtoull(s, (char **) sp, 10);
+		break;
+	case 'x':
+	case 'X':
+		vp->v_integer = strtoull(s, (char **) sp, 16);
+		break;
+	case 'p':
+		vp->v_pointer = (void *) strtoull(s, (char **) sp, 0);
+		break;
+	case 'f':
+	case 'g':
+	case 'e':
+	case 'E':
+		vp->v_double = strtod(s, (char **) sp);
+		break;
+	default:
+		return 0;
+	}
+
+	return 1;
+}
+
+static int
+process_char_class(const char **fmt, const char **sp, int width)
+{
+	unsigned char	*s, c, prev_char = 0;
+	unsigned char	table[255];
+	int		val = 1;
+
+	s = (unsigned char *) *fmt;
+	if (*s == '^') {
+		memset(table, 1, sizeof(table));
+		val = 0;
+		s++;
+	} else {
+		memset(table, 0, sizeof(table));
+		val = 1;
+	}
+	/* First character in set is closing bracket means add it to the
+	 * set of characters */
+	if ((c = *s) == ']') {
+		table[c] = val;
+		prev_char = c;
+		s++;
+	}
+
+	/* Any other closing bracket finishes off the set */
+	while ((c = *s++) != ']') {
+		if (prev_char) {
+			if (c == '-' && *s != '\0' && *s != ']') {
+				c = *s++;
+			} else {
+				//table[prev_char] = val;
+				prev_char = '\0';
+			}
+		}
+
+		if (c == '\0')
+			return 0;
+
+		if (prev_char) {
+			while (prev_char < c)
+				table[prev_char++] = val;
+		}
+		table[c] = val;
+		prev_char = c;
+	}
+	*fmt = (char *) s;
+
+#if 0
+	{
+		int	n;
+
+		printf("char class=");
+		for (n = 0; n < 255; n++)
+			if (table[n])
+				printf(isprint(n)? "%c" : "\\%03o", n);
+		printf("\n");
+	}
+#endif
+
+	s = (unsigned char *) *sp;
+	while ((c = *s) != '\0' && table[c] && width--)
+		s++;
+
+	*sp = (char *) s;
+	return 1;
+}
+
+#ifdef TEST
+static int	verify(const char *fmt, const char *s);
+static int	verify_s(const char *fmt, const char *s);
+
+
+
+int
+main(int argc, char **argv)
+{
+	verify("%d %d", "12 13");
+	verify("%d-%d", "12 13");
+	verify("%d-%d", "12-13");
+	verify("%u %u", "12 13");
+	verify("%o %o", "12 13");
+	verify("%x %x", "12 13");
+	verify("%X %X", "12 13");
+	verify("%hd %hd", "12 13");
+	verify("%ld %ld", "12 13");
+	verify("%lld %lld", "12 13");
+	verify("%Ld %Ld", "12 13");
+	verify("%qd %qd", "12 13");
+	verify("%f %f", "12 13");
+	verify("%lf %lf", "12 13");
+	verify("%Lf %Lf", "12 13");
+	verify("%qf %qf", "12 13");
+	verify("%*d-%d", "12-13");
+	verify("%*s %d", "12 13");
+	verify("%p", "0xdeadbeef");
+	verify("%*[a-e] %x", "deadbeef feeb");
+	verify("%*[a-f] %x", "deadbeef feeb");
+	verify("%*[^g-z] %x", "deadbeef feeb");
+	verify("%*[^ g-z] %x", "deadbeef feeb");
+	verify("%*[^ g-z-] %x", "dead-beef feeb");
+	verify("%*5s %d", "toast123 456");
+	verify("", "lalla");
+	verify("%u", "");
+
+	verify_s("%s", "aa bb");
+	verify_s("%s %s", "aa bb");
+	verify_s("%[a-z] %s", "aa bb");
+	verify_s("%c %s", "aa bb");
+	verify_s("%2c %s", " aa bb");
+	verify_s("%20c %s", " aa bb");
+
+	return 0;
+}
+
+static int
+verify(const char *fmt, const char *s)
+{
+	union scan_value vals[5], vals_ref[5], *v;
+	int	n, m;
+
+	memset(vals, 0xe5, sizeof(vals));
+	memset(vals_ref, 0xe5, sizeof(vals_ref));
+
+	v = vals;
+	n = sec_sscanf(s, fmt, v + 0, v + 1, v + 2, v + 3, v + 4);
+
+	v = vals_ref;
+	m = sscanf(s, fmt, v + 0, v + 1, v + 2, v + 3, v + 4);
+
+	if (m != n) {
+		printf("FAILED: fmt=\"%s\"\n"
+		       "        str=\"%s\"\n"
+		       "        sec_scanf returns %d, sscanf returns %d\n",
+		       fmt, s, n, m);
+		return 0;
+	}
+
+	if (memcmp(vals, vals_ref, sizeof(vals))) {
+		printf("FAILED: fmt=\"%s\"\n"
+		       "        str=\"%s\"\n"
+		       "        data differs!\n",
+		       fmt, s);
+		printf("0x%Lx != 0x%Lx\n", vals[0].v_integer, vals_ref[0].v_integer);
+		return 0;
+	}
+
+	return 1;
+}
+
+static int
+verify_s(const char *fmt, const char *s)
+{
+	char	buf[3][256], buf_ref[3][256];
+	int	n, m;
+
+	memset(buf, 0xe5, sizeof(buf));
+	memset(buf_ref, 0xe5, sizeof(buf_ref));
+
+	n = sec_sscanf(s, fmt, buf, sizeof(buf[0]), buf + 1, sizeof(buf[1]), buf + 2, sizeof(buf[2]));
+
+	m = sscanf(s, fmt, buf_ref, buf_ref + 1, buf_ref + 2);
+
+	if (m != n) {
+		printf("FAILED: fmt=\"%s\"\n"
+		       "        str=\"%s\"\n"
+		       "        sec_scanf returns %d, sscanf returns %d\n",
+		       fmt, s, n, m);
+		return 0;
+	}
+
+	if (memcmp(buf, buf_ref, sizeof(buf))) {
+		printf("FAILED: fmt=\"%s\"\n"
+		       "        str=\"%s\"\n"
+		       "        data differs!\n",
+		       fmt, s);
+		printf("%s != %s\n", buf[0], buf_ref[0]);
+		return 0;
+	}
+
+	return 1;
+}
+#endif
--- gv-3.5.8.orig/source/Imakefile
+++ gv-3.5.8/source/Imakefile
@@ -63,6 +63,7 @@
  resource.c\
  save.c\
  scale.c\
+ secscanf.c\
  signal.c\
  version.c\
  widgets_misc.c\
@@ -106,6 +107,7 @@
  resource.o\
  save.o\
  scale.o\
+ secscanf.o\
  signal.o\
  version.o\
  widgets_misc.o\
