about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--lib/colorname.c66
-rw-r--r--pm_config.in.h19
2 files changed, 57 insertions, 28 deletions
diff --git a/lib/colorname.c b/lib/colorname.c
index dcda3ab8..cfaf026a 100644
--- a/lib/colorname.c
+++ b/lib/colorname.c
@@ -43,6 +43,41 @@ pm_canonstr(char * const str) {
 
 
 
+static void
+openColornameFileSearch(const char * const searchPath,
+                        FILE **      const filePP) {
+/*----------------------------------------------------------------------------
+   Open the color name file, finding it via the search path 'searchPath'.
+
+   Return as *filePP the stream handle for it, but if we don't find it
+   (or just can open it) anywhere, return *filePP == NULL.
+-----------------------------------------------------------------------------*/
+    char * buffer;
+
+    buffer = strdup(searchPath);
+
+    if (buffer) {
+        char * cursor;
+        bool eol;
+
+        cursor = &buffer[0];
+        eol = FALSE;    /* initial value */
+        *filePP = NULL;  /* initial value */
+        while (!eol && !*filePP) {
+            const char * token;
+            token = strsepN(&cursor, ":");
+            if (token) {
+                *filePP = fopen(token, "r");
+            } else
+                eol = TRUE;
+        }
+        free(buffer);
+    } else
+        *filePP = NULL;
+}
+
+
+
 FILE *
 pm_openColornameFile(const char * const fileName, const int must_open) {
 /*----------------------------------------------------------------------------
@@ -57,31 +92,32 @@ pm_openColornameFile(const char * const fileName, const int must_open) {
    exist), exit the program with an error message.  If 'must_open' is
    false and we can't open the file, just return a null pointer.
 -----------------------------------------------------------------------------*/
-    const char *rgbdef;
     FILE *f;
 
     if (fileName == NULL) {
-        if ((rgbdef = getenv(RGBENV))==NULL) {
+        const char * rgbdef = getenv(RGBENV);
+        if (rgbdef) {
+            /* The environment variable is set */
+            f = fopen(rgbdef, "r");
+            if (f == NULL && must_open)
+                pm_error("Can't open the color names dictionary file "
+                         "named %s, per the %s environment variable.  "
+                         "errno = %d (%s)",
+                         rgbdef, RGBENV, errno, strerror(errno));
+        } else {            
             /* The environment variable isn't set, so try the hardcoded
                default color name dictionary locations.
             */
-            if ((f = fopen(RGB_DB1, "r")) == NULL &&
-                (f = fopen(RGB_DB2, "r")) == NULL &&
-                (f = fopen(RGB_DB3, "r")) == NULL && must_open) {
-                pm_error("can't open color names dictionary file named "
-                         "%s, %s, or %s "
+            openColornameFileSearch(RGB_DB_PATH, &f);
+
+            if (f == NULL && must_open) {
+                pm_error("can't open color names dictionary file from the "
+                         "path '%s' "
                          "and Environment variable %s not set.  Set %s to "
                          "the pathname of your rgb.txt file or don't use "
                          "color names.", 
-                         RGB_DB1, RGB_DB2, RGB_DB3, RGBENV, RGBENV);
+                         RGB_DB_PATH, RGBENV, RGBENV);
             }
-        } else {            
-            /* The environment variable is set */
-            if ((f = fopen(rgbdef, "r")) == NULL && must_open)
-                pm_error("Can't open the color names dictionary file "
-                         "named %s, per the %s environment variable.  "
-                         "errno = %d (%s)",
-                         rgbdef, RGBENV, errno, strerror(errno));
         }
     } else {
         f = fopen(fileName, "r");
diff --git a/pm_config.in.h b/pm_config.in.h
index cbc9348c..c822355e 100644
--- a/pm_config.in.h
+++ b/pm_config.in.h
@@ -58,19 +58,12 @@
 ** path here.  This is used by PPM to parse color names into rgb values.
 ** If you don't have such a file, comment this out and use the alternative
 ** hex and decimal forms to specify colors (see ppm/pgmtoppm.1 for details).  */
-/* There was some evidence before Netpbm 9.1 that the rgb database macros
-   might be already set right now.  I couldn't figure out how, so I changed
-   their meanings and they are now set unconditionally.  -Bryan 00.05.03.
-*/
-#ifdef VMS
-#define RGB_DB1 "PBMplus_Dir:RGB.TXT"
-#define RGB_DB2 "PBMplus_Dir:RGB.TXT"
-#define RGB_DB3 "PBMplus_Dir:RGB.TXT"
-#else
-#define RGB_DB1 "/usr/lib/X11/rgb.txt"
-#define RGB_DB2 "/usr/share/X11/rgb.txt"
-#define RGB_DB3 "/usr/X11R6/lib/X11/rgb.txt"
-#endif
+
+#define RGB_DB_PATH \
+"/usr/share/netpbm/rgb.txt:" \
+"/usr/lib/X11/rgb.txt:" \
+"/usr/share/X11/rgb.txt:" \
+"/usr/X11R6/lib/X11/rgb.txt"
 
 /* CONFIGURE: This is the name of an environment variable that tells
 ** where the color names database is.  If the environment variable isn't