aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/alf.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/alf.c b/src/alf.c
index c748cee..1c6814b 100644
--- a/src/alf.c
+++ b/src/alf.c
@@ -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);