aboutsummaryrefslogtreecommitdiff
path: root/src/alf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alf.c')
-rw-r--r--src/alf.c28
1 files changed, 19 insertions, 9 deletions
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);
}