aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt6
-rw-r--r--TODO.txt4
-rw-r--r--src/Makefile4
-rw-r--r--src/alf.c1
-rw-r--r--src/dupname.c44
-rw-r--r--src/dupname.h1
-rw-r--r--src/sanity.c8
7 files changed, 64 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 27520bd..d88259b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,9 @@
+0.4.0:
+- alf and unalf now detect duplicate Atari filenames.
+
+0.3.2:
+- unalf: truncation is a fatal error again (avoids segfaults).
+
0.3.1:
- unalf: truncation is now a warning, not a fatal error.
- unalf: don't require -F for very small files.
diff --git a/TODO.txt b/TODO.txt
index 452a435..cd010ec 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,3 +1,7 @@
+- unalf: -s option (split alf file), -n (extract by number)
+
+- maybe: alf foo.alf unix.filename=ATARI.NAM ...unalf could use this too.
+
- fuzz alf and unalf with afl++ or similar. this is a work in progress,
fuzzing takes a long time.
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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+/* 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 <stdio.h>
#include <string.h>
#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);
+ }
+}