diff options
Diffstat (limited to 'src/alf.c')
| -rw-r--r-- | src/alf.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -26,7 +26,7 @@ u8 input_buf[MAX_INPUT_SIZE]; u8 output_buf[MAX_INPUT_SIZE]; u8 byte_tokens[256]; -int input_len, output_len, out_bitpos; +unsigned int input_len, output_len, out_bitpos; int opt_append = 0; int opt_overwrite = 0; @@ -145,6 +145,7 @@ void create_header(void) { char hdr_filename[13]; atarify_filename(hdr_filename); + printf("Crunching %s\n", hdr_filename); output_buf[0] = 0x1a; output_buf[1] = 0x0f; @@ -169,12 +170,19 @@ void open_input(const char *filename) { } } +void inc_output_len(void) { + if(++output_len == MAX_INPUT_SIZE) { + fprintf(stderr, "%s: fatal: compressed file would be >16MB.\n", self); + exit(1); + } +} + void append_bit(int bit) { output_buf[output_len] |= (bit << (7 - out_bitpos)); out_bitpos++; if(out_bitpos == 8) { out_bitpos = 0; - output_len++; + inc_output_len(); } } @@ -244,18 +252,20 @@ void crunch(void) { } store_token(TOK_END); - if(out_bitpos) output_len++; + if(out_bitpos) inc_output_len(); update_header(); } void crunch_file(const char *filename) { init_table(); - printf("Crunching %s\n", filename); open_input(filename); /* 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: warning: this file is too large; only compressing the first 16MB.\n", self); + } output_len = 0; fstat(fileno(in_file), &in_file_stat); /* for timestamp */ fclose(in_file); |
