diff --git a/src/disk.c b/src/disk.c index 3f1cb227..3a15a973 100644 --- a/src/disk.c +++ b/src/disk.c @@ -90,22 +90,6 @@ static void _init_disk6(void) { } } -static inline void cut_gz(char *name) { - size_t len = strlen(name); - if (len <= _GZLEN) { - return; - } - *(name+len-_GZLEN) = '\0'; -} - -static inline bool is_gz(const char * const name) { - size_t len = strlen(name); - if (len <= _GZLEN) { - return false; - } - return strncmp(name+len-_GZLEN, DISK_EXT_GZ, _GZLEN) == 0; -} - static inline bool is_nib(const char * const name) { size_t len = strlen(name); if (len <= _NIBLEN) { @@ -1081,7 +1065,7 @@ bool disk6_loadState(StateHelper_s *helper) { break; } - snprintf(namebuf+namelen, gzlen, "%s", DISK_EXT_GZ); + snprintf(namebuf+namelen, gzlen, "%s", EXT_GZ); namebuf[namelen+gzlen] = '\0'; LOG("LOAD disk[%lu] : (%u) %s", i, namelen, namebuf); disk6_insert(i, namebuf, disk6.disk[i].is_protected); diff --git a/src/disk.h b/src/disk.h index 2d4b616e..5f040fb3 100644 --- a/src/disk.h +++ b/src/disk.h @@ -47,8 +47,6 @@ #define _POLEN (sizeof(DISK_EXT_PO)-1) #define DISK_EXT_NIB ".nib" #define _NIBLEN (sizeof(DISK_EXT_NIB)-1) -#define DISK_EXT_GZ ".gz" -#define _GZLEN (sizeof(DISK_EXT_GZ)-1) typedef struct diskette_t { char *file_name; diff --git a/src/interface.c b/src/interface.c index 91dc3e33..e8a8d5d7 100644 --- a/src/interface.c +++ b/src/interface.c @@ -222,28 +222,7 @@ void c_interface_print_submenu_centered( char *submenu, const int message_cols, /* ------------------------------------------------------------------------- */ -static int c_interface_cut_name(char *name) -{ - char *p = name + strlen(name) - 1; - int is_gz = 0; - - if (p >= name && *p == 'z') - { - p--; - if (p >= name && *p == 'g') - { - p--; - if (p >= name && *p == '.') - { - *p-- = '\0'; - is_gz = 1; - } - } - } - - return is_gz; -} - +#warning TODO FIXME : file selection and extension management should be made generic (merge similar code from disk.[hc] and possible Mac/iOS target) ... static int disk_select(const struct dirent *e) { char cmp[PATH_MAX] = { 0 }; @@ -469,8 +448,9 @@ void c_interface_select_diskette( int drive ) namelist[ ent_no ]->d_name ); } - if (c_interface_cut_name(temp)) + if (is_gz(temp)) { + cut_gz(temp); strncat(temp, " ", PATH_MAX-1); } /* write protected disk in drive? */ diff --git a/src/interface.h b/src/interface.h index f5f414f5..634805e4 100644 --- a/src/interface.h +++ b/src/interface.h @@ -89,5 +89,26 @@ extern void (*interface_setTouchMenuEnabled)(bool enabled); extern void (*interface_setTouchMenuVisibility)(float alpha); #endif +#define EXT_GZ ".gz" +#define _GZLEN (sizeof(EXT_GZ)-1) + +// ---------------------------------------------------------------------------- +// file extension handling + +static inline bool is_gz(const char * const name) { + size_t len = strlen(name); + if (len <= _GZLEN) { + return false; + } + return strncmp(name+len-_GZLEN, EXT_GZ, _GZLEN) == 0; +} + +static inline void cut_gz(char *name) { + size_t len = strlen(name); + if (len <= _GZLEN) { + return; + } + *(name+len-_GZLEN) = '\0'; +} #endif diff --git a/src/zlib-helpers.c b/src/zlib-helpers.c index 6f71b408..12692ba6 100644 --- a/src/zlib-helpers.c +++ b/src/zlib-helpers.c @@ -76,7 +76,7 @@ const char *zlib_deflate(const char* const src, const int expected_bytecount) { break; } - snprintf(dst, PATH_MAX-1, "%s%s", src, ".gz"); + snprintf(dst, PATH_MAX-1, "%s%s", src, EXT_GZ); gzdest = gzopen(dst, "wb"); if (gzdest == NULL) { @@ -167,8 +167,8 @@ const char *zlib_inflate(const char* const src, const int expected_bytecount) { size_t len = strlen(src); snprintf(dst, PATH_MAX-1, "%s", src); - if (! ( (dst[len-3] == '.') && (dst[len-2] == 'g') && (dst[len-1] == 'z') ) ) { - ERRLOG("Expected filename ending in .gz"); + if (!is_gz(dst)) { + ERRLOG("Expected filename ending in %s", EXT_GZ); break; } dst[len-3] = '\0';