The attached patches are taken from the upstream repository. r11352 has been backported to GPL ghostscript 8.71. The other patch file contains the documentation update done by upstream.

Greetings

Markus Steinborn
GNU gv maintainer
diff -u trunk/gs/man/gs.1 trunk/gs/man/gs.1
--- trunk/gs/man/gs.1	(Revision 11390)
+++ trunk/gs/man/gs.1	(Revision 11496)
@@ -208,6 +208,13 @@
 .br
 	/name (35) def
 .TP
+.B \-P
+Makes Ghostscript to look first in the current directory for library files.
+By default, Ghostscript no longer looks in the current directory,
+unless, of course, the first explicitly supplied directory is "." in \fB-I\fR.
+See also the \fBINITIALIZATION FILES\fR section below, and bundled 
+\fBUse.htm\fR for detailed discussion on search paths and how Ghostcript finds files.
+.TP
 .B \-q
 Quiet startup: suppress normal startup messages, and also do the
 equivalent of \fB\-dQUIET\fR.
diff --git a/ghostscript-8.71/psi/zfile.c b/ghostscript-8.71/psi/zfile.c
index 294bccd..52669b8 100644
--- a/ghostscript-8.71/psi/zfile.c
+++ b/ghostscript-8.71/psi/zfile.c
@@ -903,6 +903,91 @@ check_file_permissions_aux(i_ctx_t *i_ctx_p, char *fname, uint flen)
 }
 
 
+/* return zero for success, -ve for error, +1 for continue */
+static int
+lib_file_open_search_with_no_combine(gs_file_path_ptr  lib_path, const gs_memory_t *mem, i_ctx_t *i_ctx_p,
+                                     const char *fname, uint flen, char *buffer, int blen, uint *pclen, ref *pfile,
+                                     gx_io_device *iodev, bool starting_arg_file, char *fmode)
+{
+    stream *s;
+    uint blen1 = blen;
+    if (gp_file_name_reduce(fname, flen, buffer, &blen1) != gp_combine_success)
+      goto skip;
+    if (iodev_os_open_file(iodev, (const char *)buffer, blen1,
+                           (const char *)fmode, &s, (gs_memory_t *)mem) == 0) {
+      if (starting_arg_file ||
+          check_file_permissions_aux(i_ctx_p, buffer, blen1) >= 0) {
+        *pclen = blen1;
+        make_stream_file(pfile, s, "r");
+        return 0;
+      }
+      sclose(s);
+      return_error(e_invalidfileaccess);
+    }
+ skip:;
+    return 1;
+}
+
+/* return zero for success, -ve for error, +1 for continue */
+static int
+lib_file_open_search_with_combine(gs_file_path_ptr  lib_path, const gs_memory_t *mem, i_ctx_t *i_ctx_p,
+                                  const char *fname, uint flen, char *buffer, int blen, uint *pclen, ref *pfile,
+                                  gx_io_device *iodev, bool starting_arg_file, char *fmode)
+{
+    stream *s;
+    const gs_file_path *pfpath = lib_path;
+    uint pi;
+
+    for (pi = 0; pi < r_size(&pfpath->list); ++pi) {
+        const ref *prdir = pfpath->list.value.refs + pi;
+        const char *pstr = (const char *)prdir->value.const_bytes;
+        uint plen = r_size(prdir), blen1 = blen;
+        gs_parsed_file_name_t pname;
+        gp_file_name_combine_result r;
+
+        /* We need to concatenate and parse the file name here
+         * if this path has a %device% prefix.              */
+        if (pstr[0] == '%') {
+            int code;
+
+            /* We concatenate directly since gp_file_name_combine_*
+             * rules are not correct for other devices such as %rom% */
+            code = gs_parse_file_name(&pname, pstr, plen);
+            if (code < 0)
+                continue;
+            memcpy(buffer, pname.fname, pname.len);
+            memcpy(buffer+pname.len, fname, flen);
+            code = pname.iodev->procs.open_file(pname.iodev, buffer, pname.len + flen, fmode,
+                                          &s, (gs_memory_t *)mem);
+            if (code < 0)
+                continue;
+            make_stream_file(pfile, s, "r");
+            /* fill in the buffer with the device concatenated */
+            memcpy(buffer, pstr, plen);
+            memcpy(buffer+plen, fname, flen);
+            *pclen = plen + flen;
+            return 0;
+        } else {
+            r = gp_file_name_combine(pstr, plen,
+                    fname, flen, false, buffer, &blen1);
+            if (r != gp_combine_success)
+                continue;
+            if (iodev_os_open_file(iodev, (const char *)buffer, blen1, (const char *)fmode,
+                                    &s, (gs_memory_t *)mem) == 0) {
+                if (starting_arg_file ||
+                    check_file_permissions_aux(i_ctx_p, buffer, blen1) >= 0) {
+                    *pclen = blen1;
+                    make_stream_file(pfile, s, "r");
+                    return 0;
+                }
+                sclose(s);
+                return_error(e_invalidfileaccess);
+            }
+        }
+    }
+    return 1;
+}
+
 /* Return a file object of of the file searched for using the search paths. */
 /* The fname cannot contain a device part (%...%) but the lib paths might. */
 /* The startup code calls this to open the initialization file gs_init.ps. */
@@ -917,8 +1002,9 @@ lib_file_open(gs_file_path_ptr  lib_path, const gs_memory_t *mem, i_ctx_t *i_ctx
     bool search_with_no_combine = false;
     bool search_with_combine = false;
     char fmode[4] = { 'r', 0, 0, 0 };		/* room for binary suffix */
-    stream *s;
     gx_io_device *iodev = iodev_default;
+    gs_main_instance *minst = get_minst_from_memory(mem);
+    int code;
 
     /* when starting arg files (@ files) iodev_default is not yet set */
     if (iodev == 0)
@@ -932,76 +1018,37 @@ lib_file_open(gs_file_path_ptr  lib_path, const gs_memory_t *mem, i_ctx_t *i_ctx
        search_with_no_combine = starting_arg_file;
        search_with_combine = true;
     }
-    if (search_with_no_combine) {
-	uint blen1 = blen;
-
-	if (gp_file_name_reduce(fname, flen, buffer, &blen1) != gp_combine_success)
-	    goto skip;
-	if (iodev_os_open_file(iodev, (const char *)buffer, blen1,
-				(const char *)fmode, &s, (gs_memory_t *)mem) == 0) {
-	    if (starting_arg_file ||
-			check_file_permissions_aux(i_ctx_p, buffer, blen1) >= 0) {
-		*pclen = blen1;
-		make_stream_file(pfile, s, "r");
-		return 0;
-	    }
-	    sclose(s);
-	    return_error(e_invalidfileaccess);
-	}
-	skip:;
+    if (minst->search_here_first) {
+      if (search_with_no_combine) {
+        code = lib_file_open_search_with_no_combine(lib_path, mem, i_ctx_p,
+                                                    fname, flen, buffer, blen, pclen, pfile,
+                                                    iodev, starting_arg_file, fmode);
+        if (code <= 0) /* +ve means continue continue */
+          return code;
+      }
+      if (search_with_combine) {
+        code = lib_file_open_search_with_combine(lib_path, mem, i_ctx_p,
+                                                 fname, flen, buffer, blen, pclen, pfile,
+                                                 iodev, starting_arg_file, fmode);
+        if (code <= 0) /* +ve means continue searching */
+          return code;
+      }
+    } else {
+      if (search_with_combine) {
+        code = lib_file_open_search_with_combine(lib_path, mem, i_ctx_p,
+                                                 fname, flen, buffer, blen, pclen, pfile,
+                                                 iodev, starting_arg_file, fmode);
+        if (code <= 0) /* +ve means continue searching */
+          return code;
+      }
+      if (search_with_no_combine) {
+        code = lib_file_open_search_with_no_combine(lib_path, mem, i_ctx_p,
+                                                    fname, flen, buffer, blen, pclen, pfile,
+                                                    iodev, starting_arg_file, fmode);
+        if (code <= 0) /* +ve means continue searching */
+          return code;
+      }
     } 
-    if (search_with_combine) {
-	const gs_file_path *pfpath = lib_path;
-	uint pi;
-
-	for (pi = 0; pi < r_size(&pfpath->list); ++pi) {
-	    const ref *prdir = pfpath->list.value.refs + pi;
-	    const char *pstr = (const char *)prdir->value.const_bytes;
-	    uint plen = r_size(prdir), blen1 = blen;
-    	    gs_parsed_file_name_t pname;
-	    gp_file_name_combine_result r;
-
-	    /* We need to concatenate and parse the file name here
-	     * if this path has a %device% prefix.		*/
-	    if (pstr[0] == '%') {
-		int code;
-
-		/* We concatenate directly since gp_file_name_combine_*
-		 * rules are not correct for other devices such as %rom% */
-		code = gs_parse_file_name(&pname, pstr, plen);
-		if (code < 0)
-		    continue;
-		memcpy(buffer, pname.fname, pname.len);
-		memcpy(buffer+pname.len, fname, flen);
-		code = pname.iodev->procs.open_file(pname.iodev, buffer, pname.len + flen, fmode,
-					      &s, (gs_memory_t *)mem);
-		if (code < 0)
-		    continue;
-		make_stream_file(pfile, s, "r");
-		/* fill in the buffer with the device concatenated */
-		memcpy(buffer, pstr, plen);
-		memcpy(buffer+plen, fname, flen);
-		*pclen = plen + flen;
-		return 0;
-	    } else {
-		r = gp_file_name_combine(pstr, plen, 
-			fname, flen, false, buffer, &blen1);
-		if (r != gp_combine_success)
-		    continue;
-		if (iodev_os_open_file(iodev, (const char *)buffer, blen1, (const char *)fmode,
-					&s, (gs_memory_t *)mem) == 0) {
-		    if (starting_arg_file ||
-			check_file_permissions_aux(i_ctx_p, buffer, blen1) >= 0) {
-			*pclen = blen1;
-			make_stream_file(pfile, s, "r");
-			return 0;
-		    }
-		    sclose(s);
-		    return_error(e_invalidfileaccess);
-		}
-	    }
-	}
-    }
     return_error(e_undefinedfilename);
 }
 

Reply via email to