diff options
| author | B. Watson <urchlay@slackware.uk> | 2025-12-06 05:20:57 -0500 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2025-12-06 05:20:57 -0500 |
| commit | f7dfab9e35ee4e70b29b1dffb466c9727f0a0a16 (patch) | |
| tree | 29d60622f29b8f3298df6fd153589a12aaa13e86 | |
| parent | fb2672b27fc393622aebdfb19e2d8bc655670168 (diff) | |
| download | alftools-f7dfab9e35ee4e70b29b1dffb466c9727f0a0a16.tar.gz | |
alf: Allow setting the Atari filename with file=FILE.
| -rw-r--r-- | CHANGES.txt | 1 | ||||
| -rw-r--r-- | TODO.txt | 2 | ||||
| -rw-r--r-- | 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. @@ -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. @@ -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); } |
