Improved disk prefix utility functions

This commit is contained in:
Aaron Culliney 2015-10-09 21:32:04 -07:00
parent 57b7d930d6
commit 52d74aa43c
2 changed files with 43 additions and 25 deletions

View File

@ -79,42 +79,49 @@ static void _initialize_reverse_translate(void) {
} }
} }
static void cut_gz(char *name) { static inline void cut_gz(char *name) {
char *p = name + strlen(name) - 1; size_t len = strlen(name);
p--; if (len <= _GZLEN) {
p--; return;
*p = '\0'; }
*(name+len-_GZLEN) = '\0';
} }
static bool is_gz(const char * const name) { static inline bool is_gz(const char * const name) {
size_t len = strlen(name); size_t len = strlen(name);
if (len > 3) { if (len <= _GZLEN) {
return (strcmp(name+len-3, ".gz") == 0);
}
return false; return false;
} }
return strncmp(name+len-_GZLEN, DISK_EXT_GZ, _GZLEN) == 0;
}
static bool is_nib(const char * const name) { static inline bool is_nib(const char * const name) {
size_t len = strlen(name); size_t len = strlen(name);
if (len <= _NIBLEN) {
return false;
}
if (is_gz(name)) { if (is_gz(name)) {
len -= 3; if (len <= _NIBLEN+_GZLEN) {
}
if (!strncmp(name + len - 4, ".nib", 4)) {
return true;
}
return false; return false;
} }
len -= _GZLEN;
}
return strncmp(name+len-_NIBLEN, DISK_EXT_NIB, _NIBLEN) == 0;
}
static bool is_po(const char * const name) { static inline bool is_po(const char * const name) {
size_t len = strlen( name ); size_t len = strlen( name );
if (is_gz(name)) { if (len <= _POLEN) {
len -= 3;
}
if (!strncmp(name + len - 3, ".po", 3)) {
return true;
}
return false; return false;
} }
if (is_gz(name)) {
if (len <= _POLEN+_GZLEN) {
return false;
}
len -= _GZLEN;
}
return strncmp(name+len-_POLEN, DISK_EXT_PO, _POLEN) == 0;
}
#define SIXBIT_MASK 0x3F // 111111 #define SIXBIT_MASK 0x3F // 111111
#define SIXBIT_EXTRA_BYTES 0x56 // 86 #define SIXBIT_EXTRA_BYTES 0x56 // 86

View File

@ -36,6 +36,17 @@
#define DSK_VOLUME 254 #define DSK_VOLUME 254
#define FILE_NAME_SZ (PATH_MAX>>2) #define FILE_NAME_SZ (PATH_MAX>>2)
#define DISK_EXT_DSK ".dsk"
#define _DSKLEN (sizeof(DISK_EXT_DSK)-1)
#define DISK_EXT_DO ".do"
#define _DOLEN (sizeof(DISK_EXT_DO)-1)
#define DISK_EXT_PO ".po"
#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 { typedef struct diskette_t {
uint8_t track_image[NIB_TRACK_SIZE]; uint8_t track_image[NIB_TRACK_SIZE];
char file_name[FILE_NAME_SZ]; char file_name[FILE_NAME_SZ];