[gs-cvs] rev 8339 - trunk/gs/src

giles at ghostscript.com giles at ghostscript.com
Wed Oct 31 10:01:00 PDT 2007


Author: giles
Date: 2007-10-31 10:00:59 -0700 (Wed, 31 Oct 2007)
New Revision: 8339

Modified:
   trunk/gs/src/Makefile.in
   trunk/gs/src/gs.mak
   trunk/gs/src/gscdef.c
   trunk/gs/src/gscdefs.h
   trunk/gs/src/gsdevice.c
Log:
Add a new GS_DEV_DEFAULT makefile variable for passing a preferred list
of default devices, in order of priority. These are passed through to
the C code, and searched for in gs_getdefaultdevice().


Modified: trunk/gs/src/Makefile.in
===================================================================
--- trunk/gs/src/Makefile.in	2007-10-31 17:00:55 UTC (rev 8338)
+++ trunk/gs/src/Makefile.in	2007-10-31 17:00:59 UTC (rev 8339)
@@ -405,7 +405,11 @@
 
 STDIO_IMPLEMENTATION=c
 
-# Override the default device.  This is set to 'display' by 
+# List of default devices, in order of priority. They need not be 
+# present in the actual build.
+GS_DEV_DEFAULT="x11alpha x11 bbox"
+
+# Fallback default device.  This is set to 'display' by 
 # unix-dll.mak when building a shared object.
 DISPLAY_DEV=$(DD)bbox.dev
 

Modified: trunk/gs/src/gs.mak
===================================================================
--- trunk/gs/src/gs.mak	2007-10-31 17:00:55 UTC (rev 8338)
+++ trunk/gs/src/gs.mak	2007-10-31 17:00:59 UTC (rev 8339)
@@ -26,6 +26,8 @@
 #	GS - the name of the executable (without the extension, if any).
 #	GS_LIB_DEFAULT - the default directory/ies for searching for the
 #	    initialization and font files at run time.
+#	GS_DEV_DEFAULT - array of default device names, in order of
+#	    preference. If empty the first DEVICE_DEV will be used.
 #	GS_CACHE_DIR - the default directory for caching data between
 #	    ghostscript invocations.
 #	SEARCH_HERE_FIRST - the default setting of -P (whether or not to
@@ -435,6 +437,7 @@
 # save our set of makefile variables that are defined in every build (paths, etc.)
 $(gconfigd_h) : $(ECHOGS_XE) $(GS_MAK) $(TOP_MAKEFILES) $(GLSRCDIR)/version.mak
 	$(EXP)$(ECHOGS_XE) -w $(gconfigd_h) -x 23 define -s -u GS_LIB_DEFAULT -x 2022 $(GS_LIB_DEFAULT) -x 22
+	$(EXP)$(ECHOGS_XE) -a $(gconfigd_h) -x 23 define -s -u GS_DEV_DEFAULT -x 2022 $(GS_DEV_DEFAULT) -x 22
 	$(EXP)$(ECHOGS_XE) -a $(gconfigd_h) -x 23 define -s -u GS_CACHE_DIR -x 2022 $(GS_CACHE_DIR) -x 22
 	$(EXP)$(ECHOGS_XE) -a $(gconfigd_h) -x 23 define -s -u SEARCH_HERE_FIRST -s $(SEARCH_HERE_FIRST)
 	$(EXP)$(ECHOGS_XE) -a $(gconfigd_h) -x 23 define -s -u GS_DOCDIR -x 2022 $(GS_DOCDIR) -x 22

Modified: trunk/gs/src/gscdef.c
===================================================================
--- trunk/gs/src/gscdef.c	2007-10-31 17:00:55 UTC (rev 8338)
+++ trunk/gs/src/gscdef.c	2007-10-31 17:00:59 UTC (rev 8339)
@@ -83,3 +83,9 @@
 
 /* Define the interpreter initialization file. */
 const char *const gs_init_file = GS_INIT;
+
+/* Define the default devices list. */
+#ifndef GS_DEV_DEFAULT
+#define GS_DEV_DEFAULT ""
+#endif
+const char *const gs_dev_defaults = GS_DEV_DEFAULT;

Modified: trunk/gs/src/gscdefs.h
===================================================================
--- trunk/gs/src/gscdefs.h	2007-10-31 17:00:55 UTC (rev 8338)
+++ trunk/gs/src/gscdefs.h	2007-10-31 17:00:59 UTC (rev 8339)
@@ -48,6 +48,7 @@
 extern const char *const gs_doc_directory;
 extern const char *const gs_lib_default_path;
 extern const char *const gs_init_file;
+extern const char *const gs_dev_defaults;
 
 /* Resource tables.  In order to avoid importing a large number of types, */
 /* we only provide macros for some externs, not the externs themselves. */

Modified: trunk/gs/src/gsdevice.c
===================================================================
--- trunk/gs/src/gsdevice.c	2007-10-31 17:00:55 UTC (rev 8338)
+++ trunk/gs/src/gsdevice.c	2007-10-31 17:00:59 UTC (rev 8339)
@@ -210,6 +210,34 @@
 const gx_device *
 gs_getdefaultdevice(void)
 {
+    gs_memory_t *mem = gs_lib_ctx_get_non_gc_memory_t();
+    const gx_device *const *list;
+    int count = gs_lib_device_list(&list, NULL);
+    int i;
+    char *token, *search, *end;
+    char *name;
+
+    /* Search the compiled in device list for a known device name */
+    token = gs_dev_defaults;
+    end = token + strlen(token);
+    while (token < end) {
+      while ((token < end) && (token[0] == ' ')) token++;
+      search = token;
+      while ((search < end) && (search[0] != ' ')) search++;
+      name = gs_alloc_bytes(mem, search - token + 1, "gs_getdefaultdevice");
+      memcpy(name, token, search - token);
+      name[search-token] = '\0';
+      for (i = 0; i < count; i++)
+	/* return any matches */
+	if (!memcmp(name, list[i]->dname, search - token))
+	  return gs_getdevice(i);
+      gs_free_object(mem, name, "gs_getdefaultdevice");
+
+      /* otherwise, try the next device name */
+      token = search;
+    }
+
+    /* Fall back the first device in the list. */
     return gs_getdevice(0);
 }
 



More information about the gs-cvs mailing list