summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac17
-rw-r--r--src/RdFToI.c4
-rw-r--r--src/WrFFrI.c4
-rw-r--r--test/XpmWrite.c23
4 files changed, 43 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index 61a5f08..60f959c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,9 +52,8 @@ AM_CONDITIONAL(USE_GETTEXT, test "x$USE_GETTEXT" = "xyes")
dnl Helper macro to find absolute path to program and add a #define for it
AC_DEFUN([XPM_PATH_PROG],[
AC_PATH_PROG([$1], [$2], [])
-AS_IF([test "x$$1" = "x"],
- [AC_MSG_ERROR([$2 not found, set $1 or use --disable-open-zfile])])
-AC_DEFINE_UNQUOTED([$1], ["$$1"], [Path to $2])
+AS_IF([test "x$$1" = "x"], [$3],
+ [AC_DEFINE_UNQUOTED([$1], ["$$1"], [Path to $2])])
]) dnl End of AC_DEFUN([XPM_PATH_PROG]...
# Optional feature: When a filename ending in .Z or .gz is requested,
@@ -74,9 +73,17 @@ AM_CONDITIONAL(COMPRESSED_PIXMAPS, test "x$OPEN_ZFILE" = "xyes")
if test x$OPEN_ZFILE = xno ; then
AC_DEFINE(NO_ZPIPE, 1, [Define to 1 to disable decompression via pipes])
else
- XPM_PATH_PROG([XPM_PATH_COMPRESS], [compress])
+ # gzip is absolutely required for the compressed file handling code
+ XPM_PATH_PROG([XPM_PATH_GZIP], [gzip],
+ [AC_MSG_ERROR([gzip not found, set XPM_PATH_GZIP or use --disable-open-zfile])])
+
+ # if compress is not found, we disable writing to .Z files,
+ # but leave the rest of the compression code active
+ XPM_PATH_PROG([XPM_PATH_COMPRESS], [compress],
+ [AC_MSG_WARN([compress not found, disabling writing of .Z files])])
+ # if uncompress is not found, we use gzip to read .Z files
XPM_PATH_PROG([XPM_PATH_UNCOMPRESS], [uncompress])
- XPM_PATH_PROG([XPM_PATH_GZIP], [gzip])
+
AC_CHECK_FUNCS([closefrom close_range], [break])
fi
diff --git a/src/RdFToI.c b/src/RdFToI.c
index 141c485..a16af88 100644
--- a/src/RdFToI.c
+++ b/src/RdFToI.c
@@ -246,7 +246,11 @@ OpenReadFile(
if ( ext && !strcmp(ext, ".Z") )
{
mdata->type = XPMPIPE;
+#ifdef XPM_PATH_UNCOMPRESS
mdata->stream.file = xpmPipeThrough(fd, XPM_PATH_UNCOMPRESS, "-c", "r");
+#else
+ mdata->stream.file = xpmPipeThrough(fd, XPM_PATH_GZIP, "-dqc", "r");
+#endif
}
else if ( ext && !strcmp(ext, ".gz") )
{
diff --git a/src/WrFFrI.c b/src/WrFFrI.c
index d59098f..234197a 100644
--- a/src/WrFFrI.c
+++ b/src/WrFFrI.c
@@ -342,7 +342,11 @@ OpenWriteFile(
#ifndef NO_ZPIPE
len = strlen(filename);
if (len > 2 && !strcmp(".Z", filename + (len - 2))) {
+#ifdef XPM_PATH_COMPRESS
mdata->stream.file = xpmPipeThrough(fd, XPM_PATH_COMPRESS, NULL, "w");
+#else
+ mdata->stream.file = NULL;
+#endif
mdata->type = XPMPIPE;
} else if (len > 3 && !strcmp(".gz", filename + (len - 3))) {
mdata->stream.file = xpmPipeThrough(fd, XPM_PATH_GZIP, "-q", "w");
diff --git a/test/XpmWrite.c b/test/XpmWrite.c
index 53e010e..10b6207 100644
--- a/test/XpmWrite.c
+++ b/test/XpmWrite.c
@@ -60,6 +60,22 @@ is_compressed(const char *filepath)
}
/*
+ * If a filename ends in ".Z" or ".gz", remove that extension to avoid
+ * confusing libXpm into applying compression when not desired.
+ */
+static inline void
+strip_compress_ext(char *filepath)
+{
+ char *ext = strrchr(filepath, '.');
+
+ if ((ext != NULL) &&
+ (((ext[1] == 'Z') && (ext[2] == 0)) ||
+ ((ext[1] == 'g') && (ext[2] == 'z') && (ext[3] == 0)))) {
+ *ext = '\0';
+ }
+}
+
+/*
* XpmWriteFileFromXpmImage - Write XPM files without requiring an X Display
*/
static void
@@ -114,6 +130,7 @@ TestWriteFileFromXpmImage(const gchar *filepath)
g_assert_no_error(err);
filename = g_path_get_basename(filepath);
+ strip_compress_ext(filename);
newfilepath = g_build_filename(testdir, filename, NULL);
test_WFFXI_helper(newfilepath, &imageA, &infoA);
@@ -123,10 +140,12 @@ TestWriteFileFromXpmImage(const gchar *filepath)
test_WFFXI_helper(cmpfilepath, &imageA, &infoA);
g_free(cmpfilepath);
+#ifdef XPM_PATH_COMPRESS
cmpfilepath = g_strdup_printf("%s.Z", newfilepath);
test_WFFXI_helper(cmpfilepath, &imageA, &infoA);
g_free(cmpfilepath);
#endif
+#endif
XpmFreeXpmImage(&imageA);
XpmFreeXpmInfo(&infoA);
@@ -203,6 +222,7 @@ TestWriteFileFromData(const gchar *filepath)
g_assert_no_error(err);
filename = g_path_get_basename(filepath);
+ strip_compress_ext(filename);
newfilepath = g_build_filename(testdir, filename, NULL);
test_WFFXD_helper(newfilepath, data);
@@ -212,10 +232,12 @@ TestWriteFileFromData(const gchar *filepath)
test_WFFXD_helper(cmpfilepath, data);
g_free(cmpfilepath);
+#ifdef XPM_PATH_COMPRESS
cmpfilepath = g_strdup_printf("%s.Z", newfilepath);
test_WFFXD_helper(cmpfilepath, data);
g_free(cmpfilepath);
#endif
+#endif
XpmFree(data);
@@ -259,6 +281,7 @@ TestWriteFileFromBuffer(const gchar *filepath)
g_assert_no_error(err);
filename = g_path_get_basename(filepath);
+ strip_compress_ext(filename);
newfilepath = g_build_filename(testdir, filename, NULL);
g_test_message("...writing %s", newfilepath);