From c52082c6e4811958dd741d67e1178b4e36a09923 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 5 Feb 2023 12:14:43 -0800 Subject: open-zfile: Make compress & uncompress commands optional If compress is not found, we disable writing to .Z files, but leave the rest of the compression code active. If uncompress is not found, we use gzip to read .Z files. Signed-off-by: Alan Coopersmith --- test/XpmWrite.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test') diff --git a/test/XpmWrite.c b/test/XpmWrite.c index 53e010e..10b6207 100644 --- a/test/XpmWrite.c +++ b/test/XpmWrite.c @@ -59,6 +59,22 @@ is_compressed(const char *filepath) return FALSE; } +/* + * 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 */ @@ -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,9 +140,11 @@ 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); @@ -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,9 +232,11 @@ 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); -- cgit v1.2.1