Enable specifying loader/filter paths with environment variables

Useful for testing.
This commit is contained in:
Kim Woelders 2019-11-27 17:19:39 +01:00
parent fdbf1c49e3
commit 3bd4e8032c
6 changed files with 76 additions and 23 deletions

View File

@ -46,7 +46,6 @@ grad.h \
image.c \
image.h \
line.c \
loaderpath.h \
modules.c \
polygon.c \
rectangle.c \

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -1,3 +0,0 @@
#include "config.h"
#define SYS_LOADERS_PATH PACKAGE_LIB_DIR"/imlib2"

View File

@ -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;
}