diff options
| author | B. Watson <urchlay@slackware.uk> | 2025-12-01 07:16:52 -0500 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2025-12-01 07:16:52 -0500 |
| commit | 9072b5237c6db7a6872c8b02ff4df749a2d6b9c5 (patch) | |
| tree | c5d21083fd0d5701fdd6882e513e84b2e7e2107b /src | |
| parent | 11578e85cd04a79c8fa47e3f7ad9f09b9e55531a (diff) | |
| download | alftools-9072b5237c6db7a6872c8b02ff4df749a2d6b9c5.tar.gz | |
Add -v (verbose) option for alf.
Diffstat (limited to 'src')
| -rw-r--r-- | src/alf.c | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -26,6 +26,8 @@ long hdr_compsize_pos; FILE *out_file, *in_file; const char *out_filename, *in_filename; +char hdr_filename[13]; + void store_quad(int pos, unsigned long data) { int i; @@ -108,11 +110,9 @@ unsigned long get_msdos_date_time(void) { } void create_header(void) { - char hdr_filename[13]; unsigned long time; atarify_filename(hdr_filename); - printf("Crunching %s\n", hdr_filename); sanity_check_filename(hdr_filename); if(opt_alftime) @@ -149,7 +149,11 @@ void make_backup(void) { char bak[PATH_MAX + 2]; strncpy(bak, out_filename, PATH_MAX); strcat(bak, "~"); - rename(out_filename, bak); + if(rename(out_filename, bak) >= 0) { + if(opt_verbose > 1) { + printf(" (backed up old %s to %s) ", out_filename, bak); + } + } } void convert_eols(void) { @@ -183,6 +187,9 @@ void crunch_file(const char *filename) { memset(output_buf, 0, sizeof(output_buf)); create_header(); + printf("Crunching %s", hdr_filename); + fflush(stdout); + if(!opt_verbose) putchar('\n'); /* crunches the entire input to memory! */ crunch(); @@ -192,6 +199,8 @@ void crunch_file(const char *filename) { this avoids leaving 0-byte turds */ if(!out_file) { if(!opt_overwrite) make_backup(); + if(opt_append && opt_verbose > 1) + printf(" (appending to %s) ", out_filename); out_file = fopen(out_filename, opt_append ? "ab" : "wb"); if(!out_file) { fprintf(stderr, "%s: fatal: ", self); @@ -200,7 +209,17 @@ void crunch_file(const char *filename) { } } - fwrite(output_buf, 1, output_len, out_file); + if(fwrite(output_buf, 1, output_len, out_file) < 0) { + fprintf(stderr, "%s: fatal: ", self); + perror("write error"); + exit(1); + } + + if(opt_verbose) { + printf(" %u/%u (%d%%)\n", + input_len, output_len, + 100 - (int)((float)output_len / (float)input_len * 100.0)); + } } void usage(void) { @@ -234,7 +253,7 @@ int main(int argc, char **argv) { /* don't let getopt() print error message for us. */ opterr = 0; - while((opt = getopt(argc, argv, "aAt:oV")) != -1) { + while((opt = getopt(argc, argv, "aAt:ovV")) != -1) { switch(opt) { case 'A': opt_txtconv = 1; break; case 'a': opt_append = 1; opt_overwrite = 1; break; @@ -249,6 +268,7 @@ int main(int argc, char **argv) { exit(1); } break; + case 'v': opt_verbose++; break; case 'V': puts(VERSION); exit(0); break; default: fprintf(stderr, "%s: fatal: invalid option '-%c' (try -h or --help)\n", self, optopt); |
