From f7dfab9e35ee4e70b29b1dffb466c9727f0a0a16 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sat, 6 Dec 2025 05:20:57 -0500 Subject: alf: Allow setting the Atari filename with file=FILE. --- CHANGES.txt | 1 + TODO.txt | 2 -- src/alf.c | 28 +++++++++++++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 3b622d6..bf1156a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,6 @@ 0.4.0: - alf and unalf now detect duplicate Atari filenames. +- alf lets the user set the archive filename for each file (file=FILE, e.g.) - unalf can extract by file number (-n) rather than wildcards. - unalf can split an ALF file into multiple ALF files (-s option) without extracting. diff --git a/TODO.txt b/TODO.txt index 48ec376..452a435 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,3 @@ -- 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/alf.c b/src/alf.c index d485ab1..0d150bd 100644 --- a/src/alf.c +++ b/src/alf.c @@ -32,7 +32,8 @@ struct stat in_file_stat; long hdr_compsize_pos; FILE *out_file, *in_file; -const char *out_filename, *in_filename; +const char *out_filename, *atari_filename; +char in_filename[PATH_MAX + 1]; char hdr_filename[13]; @@ -66,11 +67,11 @@ void atarify_filename(char *result) { int i; char name[9] = { 0 }, ext[4] = { 0 }, *p; - p = strrchr(in_filename, '/'); + p = strrchr(atari_filename, '/'); if(p) p++; else - p = (char *)in_filename; + p = (char *)atari_filename; strncpy(name, p, 8); for(i = 0; i < 8; i++) { @@ -152,8 +153,7 @@ void update_header(void) { store_quad(15, output_len - 29); } -void open_input(const char *filename) { - in_filename = filename; +void open_input(void) { if(!(in_file = fopen(in_filename, "rb"))) { perror(in_filename); exit(1); @@ -180,14 +180,24 @@ void convert_eols(void) { } } -void crunch_file(const char *filename) { - open_input(filename); +void crunch_file(const char *filename_arg) { + strncpy(in_filename, filename_arg, PATH_MAX); + + /* 1st strtok() returns in_filename itself, whether or not there's an "=", + *and* changes the '=' to '\0' if there is one. */ + strtok(in_filename, "="); + /* 2nd returns everything after the "=", if there is one (or null if not, *or* + if it's the last char of the string) */ + atari_filename = strtok(NULL, "="); + if(!atari_filename) atari_filename = in_filename; + + open_input(); /* read in entire input, couldn't do it this way on the Atari */ input_len = fread(input_buf, 1, MAX_INPUT_SIZE - 1, in_file); if(!feof(in_file)) { - fprintf(stderr, "%s: %s: this file is too large; only compressing the first 16MB.\n", self, filename); + fprintf(stderr, "%s: %s: this file is too large; only compressing the first 16MB.\n", self, in_filename); } if(opt_txtconv) @@ -201,7 +211,7 @@ void crunch_file(const char *filename) { create_header(); if(opt_verbose) { - printf("Crunching %s as %s", filename, hdr_filename); + printf("Crunching %s as %s", in_filename, hdr_filename); } else { printf("Crunching %s", hdr_filename); } -- cgit v1.2.3