diff options
Diffstat (limited to 'src/extract.c')
| -rw-r--r-- | src/extract.c | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/src/extract.c b/src/extract.c index dc6a4f1..af3efeb 100644 --- a/src/extract.c +++ b/src/extract.c @@ -19,41 +19,23 @@ u16 dpeek(int addr) { return mem[addr] | (mem[addr + 1] << 8); } -void fix_filename(void) { - char *p; - - if(!out_filename) return; - - if(strlen(out_filename) > 12) { - fprintf(stderr, "%s: filename in ALF header not null-terminated, fixing.\n", self); - out_filename[12] = '\0'; - } - - if(opts.lowercase) { - for(p = out_filename; *p; p++) - *p = tolower(*p); - } +static void bad_atari_filename(const char *msg) { + char fn[50] = ""; + char xbuf[5]; + int i; + u8 c; - if(!opts.keepdot) { - for(p = out_filename; *p; p++) - if(p[0] == '.' && !p[1]) - *p = '\0'; + for(i = 0; (c = (u8)out_filename[i]) && i < 12; i++) { + if(c < ' ' || c > '|') { + /* not printable, insert a hex escape */ + sprintf(xbuf, "$%02X", c); + strcat(fn, xbuf); + } else { + strncat(fn, (char *)&c, 1); + } } -} - -void make_backup(void) { - /* up to 12-char FILENAME.EXT, plus a ~, plus null terminator = 14 */ - char backup[14]; - strncpy(backup, out_filename, 13); - strncat(backup, "~", 13); - - /* silently ignore errors! */ - rename(out_filename, backup); -} - -static void bad_atari_filename(const char *msg) { - fprintf(stderr, "%s: bad Atari filename: %s\n", self, msg); + fprintf(stderr, "%s: bad Atari filename \"%s\": %s\n", self, fn, msg); } /* note to self: it's tempting to use isalpha(), isprint(), etc @@ -93,6 +75,41 @@ static void sanity_check_filename(void) { bad_atari_filename("invalid characters. corrupt ALF file?"); } +void fix_filename(void) { + char *p; + + if(!out_filename) return; + + if(strlen(out_filename) > 12) { + fprintf(stderr, "%s: filename in ALF header not null-terminated, fixing.\n", self); + out_filename[12] = '\0'; + } + + sanity_check_filename(); + + if(opts.lowercase) { + for(p = out_filename; *p; p++) + *p = tolower(*p); + } + + if(!opts.keepdot) { + for(p = out_filename; *p; p++) + if(p[0] == '.' && !p[1]) + *p = '\0'; + } +} + +void make_backup(void) { + /* up to 12-char FILENAME.EXT, plus a ~, plus null terminator = 14 */ + char backup[14]; + + strncpy(backup, out_filename, 13); + strncat(backup, "~", 13); + + /* silently ignore errors! */ + rename(out_filename, backup); +} + void extract_alf(void) { /* get ready to call fake 6502 stuff. set up memory like the Atari. */ dpoke(MEMTOP, 0xbc1f); @@ -100,7 +117,6 @@ void extract_alf(void) { while(read_alf_header()) { out_filename = (char *)(mem + alf_hdr_filename); - sanity_check_filename(); fix_filename(); if(!file_wanted(out_filename)) { |
