kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=3bd4e8032c77651d8c735fa8316bfd27b0bb620d

commit 3bd4e8032c77651d8c735fa8316bfd27b0bb620d
Author: Kim Woelders <[email protected]>
Date:   Wed Nov 27 17:19:39 2019 +0100

    Enable specifying loader/filter paths with environment variables
    
    Useful for testing.
---
 src/lib/Makefile.am       |  1 -
 src/lib/dynamic_filters.c |  2 +-
 src/lib/file.h            |  4 ++-
 src/lib/image.c           | 23 ++++++++++-------
 src/lib/loaderpath.h      |  3 ---
 src/lib/modules.c         | 66 ++++++++++++++++++++++++++++++++++++++++++-----
 6 files changed, 76 insertions(+), 23 deletions(-)

diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 4f48310..ee2064f 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -46,7 +46,6 @@ grad.h \
 image.c \
 image.h \
 line.c \
-loaderpath.h \
 modules.c \
 polygon.c \
 rectangle.c \
diff --git a/src/lib/dynamic_filters.c b/src/lib/dynamic_filters.c
index a650464..91ab6fe 100644
--- a/src/lib/dynamic_filters.c
+++ b/src/lib/dynamic_filters.c
@@ -98,7 +98,7 @@ __imlib_dynamic_filters_init()
 #ifdef FDEBUG
         printf("DEBUG: Loading Filters\n");
 #endif
-        list = __imlib_ListModules("filters", &num_filters);
+        list = __imlib_ListModules(__imlib_PathToFilters(), &num_filters);
         for (i = num_filters - 1; i >= 0; i--)
           {
              tptr = NULL;
diff --git a/src/lib/file.h b/src/lib/file.h
index 3bfa52d..bff573b 100644
--- a/src/lib/file.h
+++ b/src/lib/file.h
@@ -20,6 +20,8 @@ int                 __imlib_IsRealFile(const char *s);
 
 int                 __imlib_ItemInList(char **list, int size, char *item);
 
-char              **__imlib_ListModules(const char *what, int *num_ret);
+const char         *__imlib_PathToFilters(void);
+const char         *__imlib_PathToLoaders(void);
+char              **__imlib_ListModules(const char *path, int *num_ret);
 
 #endif
diff --git a/src/lib/image.c b/src/lib/image.c
index 8533a33..28eee8f 100644
--- a/src/lib/image.c
+++ b/src/lib/image.c
@@ -15,7 +15,6 @@
 #include "Imlib2.h"
 #include "file.h"
 #include "image.h"
-#include "loaderpath.h"
 
 static void         __imlib_LoadAllLoaders(void);
 
@@ -673,23 +672,27 @@ __imlib_RescanLoaders(void)
    current_time = time(NULL);
    if ((current_time - last_scan_time) < 5)
       return;
+
    /* ok - was the system loaders dir contents modified ? */
    last_scan_time = current_time;
-   if (__imlib_FileIsDir(SYS_LOADERS_PATH "/loaders/"))
+
+   current_time = __imlib_FileModDate(__imlib_PathToLoaders());
+   if (current_time == 0)
+      return;                   /* Loader directory not found */
+   if ((current_time > last_modified_system_time) || (!scanned))
      {
-        current_time = __imlib_FileModDate(SYS_LOADERS_PATH "/loaders/");
-        if ((current_time > last_modified_system_time) || (!scanned))
-          {
-             /* yup - set the "do_reload" flag */
-             do_reload = 1;
-             last_modified_system_time = current_time;
-          }
+        /* yup - set the "do_reload" flag */
+        do_reload = 1;
+        last_modified_system_time = current_time;
      }
+
    /* if we dont ned to reload the loaders - get out now */
    if (!do_reload)
       return;
+
    __imlib_RemoveAllLoaders();
    __imlib_LoadAllLoaders();
+
    scanned = 1;
 }
 
@@ -718,7 +721,7 @@ __imlib_LoadAllLoaders(void)
    char              **list;
 
    /* list all the loaders imlib can find */
-   list = __imlib_ListModules("loaders", &num);
+   list = __imlib_ListModules(__imlib_PathToLoaders(), &num);
    /* no loaders? well don't load anything */
    if (!list)
       return;
diff --git a/src/lib/loaderpath.h b/src/lib/loaderpath.h
deleted file mode 100644
index 8ae051f..0000000
--- a/src/lib/loaderpath.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "config.h"
-
-#define SYS_LOADERS_PATH PACKAGE_LIB_DIR"/imlib2"
diff --git a/src/lib/modules.c b/src/lib/modules.c
index 69814eb..d7afbb6 100644
--- a/src/lib/modules.c
+++ b/src/lib/modules.c
@@ -4,7 +4,61 @@
 
 #include "file.h"
 #include "image.h"
-#include "loaderpath.h"
+
+static const char  *
+__imlib_PathToModules(void)
+{
+#if 0
+   static const char  *path = NULL;
+
+   if (path)
+      return path;
+
+   path = getenv("IMLIB2_MODULE_PATH");
+   if (path && __imlib_FileIsDir(path))
+      return path;
+#endif
+
+   return PACKAGE_LIB_DIR "/imlib2";
+}
+
+const char         *
+__imlib_PathToFilters(void)
+{
+   static char        *path = NULL;
+   char                buf[1024];
+
+   if (path)
+      return path;
+
+   path = getenv("IMLIB2_FILTER_PATH");
+   if (path && __imlib_FileIsDir(path))
+      return path;
+
+   snprintf(buf, sizeof(buf), "%s/%s", __imlib_PathToModules(), "filters");
+   path = strdup(buf);
+
+   return path;
+}
+
+const char         *
+__imlib_PathToLoaders(void)
+{
+   static char        *path = NULL;
+   char                buf[1024];
+
+   if (path)
+      return path;
+
+   path = getenv("IMLIB2_LOADER_PATH");
+   if (path && __imlib_FileIsDir(path))
+      return path;
+
+   snprintf(buf, sizeof(buf), "%s/%s", __imlib_PathToModules(), "loaders");
+   path = strdup(buf);
+
+   return path;
+}
 
 static char       **
 __imlib_TrimLoaderList(char **list, int *num)
@@ -52,15 +106,14 @@ __imlib_TrimLoaderList(char **list, int *num)
 }
 
 char              **
-__imlib_ListModules(const char *what, int *num_ret)
+__imlib_ListModules(const char *path, int *num_ret)
 {
    char              **list = NULL, **l;
-   char                path[1024];
+   char                file[1024];
    int                 num, i;
 
    *num_ret = 0;
 
-   snprintf(path, sizeof(path), "%s/%s", SYS_LOADERS_PATH, what);
    l = __imlib_FileDir(path, &num);
    if (num <= 0)
       return NULL;
@@ -70,9 +123,8 @@ __imlib_ListModules(const char *what, int *num_ret)
      {
         for (i = 0; i < num; i++)
           {
-             snprintf(path, sizeof(path), "%s/%s/%s",
-                      SYS_LOADERS_PATH, what, l[i]);
-             list[i] = strdup(path);
+             snprintf(file, sizeof(file), "%s/%s", path, l[i]);
+             list[i] = strdup(file);
           }
         *num_ret = num;
      }

-- 


Reply via email to