From 174cec1c80bd6d7258fb960a210d707920ccbcd9 Mon Sep 17 00:00:00 2001 From: Michael Jennings Date: Wed, 30 Jan 2002 04:47:01 +0000 Subject: [PATCH] Tue Jan 29 23:46:18 2002 Michael Jennings (mej) Improved debugging of image finding problems, and improved reporting of Imlib2 load errors. SVN revision: 5882 --- ChangeLog | 5 ++++ src/options.c | 1 - src/pixmap.c | 64 +++++++++++++++++++++++++++++++++++++++++++++------ src/pixmap.h | 1 + 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index e865e2e..a78006e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4474,3 +4474,8 @@ Also updated the version number in configure.ac for all those mor^H^H^Hpeople using Debian unstable. :-) Fixed a few compiler warnings too. ---------------------------------------------------------------------- +Tue Jan 29 23:46:18 2002 Michael Jennings (mej) + +Improved debugging of image finding problems, and improved reporting +of Imlib2 load errors. +---------------------------------------------------------------------- diff --git a/src/options.c b/src/options.c index 8cb002a..963c99c 100644 --- a/src/options.c +++ b/src/options.c @@ -2070,7 +2070,6 @@ parse_image(char *buff, void *state) return NULL; } if (!load_image(filename, images[idx].current)) { - print_error("Unable to locate image \"%s\" in the image path.\n", NONULL(filename)); images[idx].mode &= ~(MODE_IMAGE | ALLOW_IMAGE); D_PIXMAP(("New image mode is 0x%02x, iml->im is 0x%08x\n", images[idx].mode, images[idx].current->iml->im)); } diff --git a/src/pixmap.c b/src/pixmap.c index 102c0c6..cb90335 100644 --- a/src/pixmap.c +++ b/src/pixmap.c @@ -125,6 +125,30 @@ image_mode_any(unsigned char mode) } #ifdef PIXMAP_SUPPORT +const char * +imlib_strerror(Imlib_Load_Error err) +{ + switch (err) { + case IMLIB_LOAD_ERROR_NONE: return "Success"; break; + case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: return "No such file or directory"; break; + case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY: return "Is a directory"; break; + case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: return "Permission denied"; break; + case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT: return "No loader available for that file format"; break; + case IMLIB_LOAD_ERROR_PATH_TOO_LONG: return "Path too long"; break; + case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT: return "Path component does not exist"; break; + case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY: return "Path component is not a directory"; break; + case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE: return "Path points outside address space"; break; + case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS: return "Too many symbolic links in path"; break; + case IMLIB_LOAD_ERROR_OUT_OF_MEMORY: return "Out of memory"; break; + case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS: return "No more file descriptors"; break; + case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE: return "Permission denied"; break; + case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE: return "Disk full"; break; + case IMLIB_LOAD_ERROR_UNKNOWN: + default: return "Unknown error"; break; + } + ASSERT_NOTREACHED_RVAL(""); +} + unsigned short parse_pixmap_ops(char *str) { @@ -1191,8 +1215,13 @@ search_path(const char *pathlist, const char *file) } if (!S_ISDIR(fst.st_mode)) { return name; + } else { + D_OPTIONS(("%s is a directory.\n", name)); } + } else { + D_OPTIONS(("Unable to access %s -- %s\n", name, strerror(errno))); } + if ((p = strchr(file, '@')) == NULL) p = strchr(file, '\0'); len = (p - file); @@ -1208,9 +1237,18 @@ search_path(const char *pathlist, const char *file) D_OPTIONS(("Checking for file \"%s\"\n", name)); if (!access(name, R_OK)) { - stat(name, &fst); - if (!S_ISDIR(fst.st_mode)) + if (stat(name, &fst)) { + D_OPTIONS(("Unable to stat %s -- %s\n", name, strerror(errno))); + } else { + D_OPTIONS(("Stat returned mode 0x%08o, S_ISDIR() == %d\n", fst.st_mode, S_ISDIR(fst.st_mode))); + } + if (!S_ISDIR(fst.st_mode)) { return name; + } else { + D_OPTIONS(("%s is a directory.\n", name)); + } + } else { + D_OPTIONS(("Unable to access %s -- %s\n", name, strerror(errno))); } for (path = pathlist; path != NULL && *path != '\0'; path = p) { int n; @@ -1247,9 +1285,18 @@ search_path(const char *pathlist, const char *file) D_OPTIONS(("Checking for file \"%s\"\n", name)); if (!access(name, R_OK)) { - stat(name, &fst); - if (!S_ISDIR(fst.st_mode)) - return name; + if (stat(name, &fst)) { + D_OPTIONS(("Unable to stat %s -- %s\n", name, strerror(errno))); + } else { + D_OPTIONS(("Stat returned mode 0x%08o, S_ISDIR() == %d\n", fst.st_mode, S_ISDIR(fst.st_mode))); + } + if (!S_ISDIR(fst.st_mode)) { + return name; + } else { + D_OPTIONS(("%s is a directory.\n", name)); + } + } else { + D_OPTIONS(("Unable to access %s -- %s\n", name, strerror(errno))); } } } @@ -1262,6 +1309,7 @@ load_image(const char *file, simage_t *simg) { const char *f; Imlib_Image *im; + Imlib_Load_Error im_err; char *geom; ASSERT_RVAL(file != NULL, 0); @@ -1282,9 +1330,9 @@ load_image(const char *file, simage_t *simg) f = search_path(getenv(PATH_ENV), file); } if (f != NULL) { - im = imlib_load_image_immediately(f); + im = imlib_load_image_with_error_return(f, &im_err); if (im == NULL) { - print_error("Unable to load image file \"%s\"\n", file); + print_error("Unable to load image file \"%s\" -- %s\n", file, imlib_strerror(im_err)); return 0; } else { reset_simage(simg, (RESET_IMLIB_IM | RESET_PMAP_PIXMAP | RESET_PMAP_MASK)); @@ -1292,6 +1340,8 @@ load_image(const char *file, simage_t *simg) } D_PIXMAP(("Found image %8p.\n", im)); return 1; + } else { + print_error("Unable to locate file \"%s\" in image path.\n"); } } reset_simage(simg, RESET_ALL_SIMG); diff --git a/src/pixmap.h b/src/pixmap.h index 57501db..ae047ac 100644 --- a/src/pixmap.h +++ b/src/pixmap.h @@ -221,6 +221,7 @@ _XFUNCPROTOBEGIN extern const char *get_image_type(unsigned char); extern unsigned char image_mode_any(unsigned char); #ifdef PIXMAP_SUPPORT +extern const char *imlib_strerror(Imlib_Load_Error); extern unsigned short parse_pixmap_ops(char *); extern unsigned short set_pixmap_scale(const char *, pixmap_t *); extern unsigned char check_image_ipc(unsigned char);