diff options
| -rw-r--r-- | src/extract.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/extract.c b/src/extract.c index 515d2dd..dc6a4f1 100644 --- a/src/extract.c +++ b/src/extract.c @@ -52,6 +52,47 @@ void make_backup(void) { rename(out_filename, backup); } +static void bad_atari_filename(const char *msg) { + fprintf(stderr, "%s: bad Atari filename: %s\n", self, msg); +} + +/* note to self: it's tempting to use isalpha(), isprint(), etc + from ctype.h... but those are locale-aware. we want ASCII-only + versions. */ +static void sanity_check_filename(void) { + u8 c; + unsigned int i, bad = 0, dots = 0; + + c = out_filename[0]; + if(!c) { + bad_atari_filename("empty! corrupt ALF file?"); + return; + } else if(c < 'A' || c > 'Z') { + bad_atari_filename("does not begin with A-Z"); + } + + for(i = 0; (c = out_filename[i]) && i < 12; i++) { + if(c >= 'A' && c <= 'Z') + continue; + if(c >= '0' && c <= '9') + continue; + if(c == '.') { + dots++; + continue; + } + bad++; + } + + if(!dots) { + bad_atari_filename("no \".\""); + } else if(dots > 1) { + bad_atari_filename("more than one \".\""); + } + + if(bad) + bad_atari_filename("invalid characters. corrupt ALF file?"); +} + void extract_alf(void) { /* get ready to call fake 6502 stuff. set up memory like the Atari. */ dpoke(MEMTOP, 0xbc1f); @@ -59,6 +100,7 @@ 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)) { |
