From b697d0594268023c24db5855130f8f6af28b250b Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 4 Dec 2025 16:15:27 -0500 Subject: alf and unalf: Detect dup Atari filenames. --- src/Makefile | 4 ++-- src/alf.c | 1 + src/dupname.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/dupname.h | 1 + src/sanity.c | 8 ++++++-- 5 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 src/dupname.c create mode 100644 src/dupname.h (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 45016a9..7ebbb71 100644 --- a/src/Makefile +++ b/src/Makefile @@ -43,9 +43,9 @@ CFLAGS=-DVERSION='"$(VERSION)"' -Wall -I../f65 $(COPT) BINS=alf alfsum unalf MANS=alf.1 alfsum.1 unalf.1 -UNALF_OBJS=unalf.o io.o listalf.o extract.o f65.o glob.o opts.o usage.o self.o asmcode.o sanity.o +UNALF_OBJS=unalf.o io.o listalf.o extract.o f65.o glob.o opts.o usage.o self.o asmcode.o sanity.o dupname.o ALFSUM_OBJS=alfsum.o self.o -ALF_OBJS=alf.o self.o alfusage.o sanity.o crunch.o +ALF_OBJS=alf.o self.o alfusage.o sanity.o crunch.o dupname.o .PHONY: all clean install crosswin windows windows-upload realclean diff --git a/src/alf.c b/src/alf.c index 702837e..d485ab1 100644 --- a/src/alf.c +++ b/src/alf.c @@ -12,6 +12,7 @@ #include "sanity.h" #include "self.h" #include "crunch.h" +#include "dupname.h" int opt_append = 0; int opt_overwrite = 0; diff --git a/src/dupname.c b/src/dupname.c new file mode 100644 index 0000000..532e14c --- /dev/null +++ b/src/dupname.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +/* only check this many filenames */ +#define MAX_FNAMES 1024 + +/* FILENAME.EXT\0 = 13 */ +#define FNAME_LEN 13 + +// #define DUPNAME_DEBUG + +static char filenames[MAX_FNAMES][FNAME_LEN]; +static int fncount; + +/* linear search, slow, but only happens once at startup */ +int is_dup_filename(const char *newname) { + int i; + + for(i = 0; i < fncount; i++) + if(strncmp(newname, filenames[i], FNAME_LEN - 1) == 0) + return 1; + + strncpy(filenames[fncount++], newname, FNAME_LEN - 1); + + return 0; +} + +#ifdef DUPNAME_DEBUG +int main(int argc, char **argv) { + int i; + + while(++argv, --argc) + printf("%s: %d\n", *argv, is_dup_filename(*argv)); + + printf("filenames[]\n"); + + for(i = 0; i < fncount; i++) + printf(" %s\n", filenames[i]); + + return 0; +} +#endif diff --git a/src/dupname.h b/src/dupname.h new file mode 100644 index 0000000..f051c22 --- /dev/null +++ b/src/dupname.h @@ -0,0 +1 @@ +int is_dup_filename(const char *newname); diff --git a/src/sanity.c b/src/sanity.c index df3cbe2..c542aec 100644 --- a/src/sanity.c +++ b/src/sanity.c @@ -1,6 +1,7 @@ #include #include #include "u816.h" +#include "dupname.h" extern const char *self; @@ -64,6 +65,9 @@ void sanity_check_filename(const char *fname) { bad_atari_filename(fname, "invalid characters."); else if(uscore) fprintf(stderr, "%s: filename has underscore, OK on Sparta/MyDOS, not Atari DOS 2.x\n", self); -} - + if(is_dup_filename(fname)) { + fprintf(stderr, "%s: warning: duplicate Atari filename %s\n", + self, fname); + } +} -- cgit v1.2.3