diff options
| author | B. Watson <urchlay@slackware.uk> | 2025-11-29 04:12:07 -0500 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2025-11-29 04:12:07 -0500 |
| commit | 25380d9b6846574b1bad03708226f7bf346b8391 (patch) | |
| tree | 6d5865c224c4a155f193e51ecd880572b6fefd7b /src/extract.c | |
| parent | 8b4a168475a005d7fc4a298321688fccdb2f8ba3 (diff) | |
| download | alftools-25380d9b6846574b1bad03708226f7bf346b8391.tar.gz | |
alf: Sanity-check generated Atari filenames.
Diffstat (limited to 'src/extract.c')
| -rw-r--r-- | src/extract.c | 65 |
1 files changed, 2 insertions, 63 deletions
diff --git a/src/extract.c b/src/extract.c index 6d940a2..f6b36e7 100644 --- a/src/extract.c +++ b/src/extract.c @@ -1,5 +1,6 @@ #include "unalf.h" #include "addrs.h" +#include "sanity.h" #include <time.h> #include <utime.h> @@ -17,68 +18,6 @@ u16 dpeek(int addr) { return mem[addr] | (mem[addr + 1] << 8); } -static void bad_atari_filename(const char *msg) { - char fn[50] = ""; - char xbuf[5]; - int i; - u8 c; - - 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); - } - } - - fprintf(stderr, "%s: bad Atari filename \"%s\": %s\n", self, fn, 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, uscore = 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 == '_') { - uscore++; - 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?"); - else if(uscore) - fprintf(stderr, "%s: filename has underscore, OK on Sparta/MyDOS, not Atari DOS 2.x\n", self); -} - void fix_filename(void) { char *p; @@ -89,7 +28,7 @@ void fix_filename(void) { out_filename[12] = '\0'; } - sanity_check_filename(); + sanity_check_filename(out_filename); if(opts.lowercase) { for(p = out_filename; *p; p++) |
