about summary refs log tree commit diff
path: root/lib/colorname.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2009-04-25 23:28:52 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2009-04-25 23:28:52 +0000
commit7ba3837172510a0a6be4d4a59c60014db8dc0028 (patch)
treeeaa7b3b8410608b0a82e23115b42873d84cbbbe7 /lib/colorname.c
parentd30690e8a6d494287d655e1bddd722f5c0bee432 (diff)
downloadnetpbm-mirror-7ba3837172510a0a6be4d4a59c60014db8dc0028.tar.gz
netpbm-mirror-7ba3837172510a0a6be4d4a59c60014db8dc0028.tar.xz
netpbm-mirror-7ba3837172510a0a6be4d4a59c60014db8dc0028.zip
Have RGB_DB_PATH instead of RGB_DB1, RGB_DB2, and RGB_DB3
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@895 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/colorname.c')
-rw-r--r--lib/colorname.c66
1 files changed, 51 insertions, 15 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");