aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-12-01 21:36:24 -0500
committerB. Watson <urchlay@slackware.uk>2025-12-01 21:36:24 -0500
commit8f24787dda80d39733aba0950b2894986e574bfd (patch)
tree5d1b133bfdadff781987806b5cc94fab37534a77 /src
parent6973590e54425f07764147923aadd78294fd21d3 (diff)
downloadalftools-8f24787dda80d39733aba0950b2894986e574bfd.tar.gz
alf -vv: Print total bytes in/out, total ratio, elapsed time.
Diffstat (limited to 'src')
-rw-r--r--src/alf.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/alf.c b/src/alf.c
index ece8570..dcf9e4e 100644
--- a/src/alf.c
+++ b/src/alf.c
@@ -6,6 +6,7 @@
#include <limits.h>
#include <sys/stat.h>
#include <time.h>
+#include <sys/time.h>
#include "u816.h"
#include "sanity.h"
@@ -20,6 +21,12 @@ int opt_gmtime = 0;
int opt_txtconv = 0;
int opt_verbose = 0;
+int backup_msg = 0;
+int file_count = 0;
+unsigned int total_in = 0;
+unsigned int total_out = 0;
+struct timeval start_time;
+
struct stat in_file_stat;
long hdr_compsize_pos;
@@ -150,9 +157,7 @@ void make_backup(void) {
strncpy(bak, out_filename, PATH_MAX);
strcat(bak, "~");
if(rename(out_filename, bak) >= 0) {
- if(opt_verbose > 1) {
- printf(" (backed up old %s to %s) ", out_filename, bak);
- }
+ backup_msg = 1;
}
}
@@ -224,6 +229,9 @@ void crunch_file(const char *filename) {
input_len, output_len,
100 - (int)((float)output_len / (float)input_len * 100.0));
}
+
+ total_in += input_len;
+ total_out += output_len;
}
void usage(void) {
@@ -240,9 +248,27 @@ void usage(void) {
exit(0);
}
+float tv_to_float(struct timeval *tv) {
+ return ((float)tv->tv_sec) + (((float)tv->tv_usec) / 1000000.0);
+}
+
+void print_elapsed_time(void) {
+ struct timeval end_time;
+ float s, e;
+
+ gettimeofday(&end_time, 0);
+ end_time.tv_sec -= start_time.tv_sec;
+ start_time.tv_sec = 0;
+ s = tv_to_float(&start_time);
+ e = tv_to_float(&end_time);
+
+ printf("Elapsed time: %.3fs\n", e - s);
+}
+
int main(int argc, char **argv) {
int opt;
+ gettimeofday(&start_time, 0);
set_self(argv[0]);
if(argc < 2 || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) {
@@ -296,9 +322,25 @@ int main(int argc, char **argv) {
while(optind < argc) {
crunch_file(argv[optind++]);
+ file_count++;
}
if(out_file) fclose(out_file);
+ if(opt_verbose > 1) {
+ printf("Compressed %d file%s: ", file_count, file_count == 1 ? "" : "s");
+ printf("%u/%u (%d%%)\n",
+ total_in, total_out,
+ 100 - (int)((float)total_out / (float)total_in * 100.0));
+ print_elapsed_time();
+ if(backup_msg) {
+ printf("Backed up old '%s' to '%s~'.\n", out_filename, out_filename);
+ } else if(opt_append) {
+ printf("Appended to '%s'.\n", out_filename);
+ } else {
+ printf("Created '%s'.\n", out_filename);
+ }
+ }
+
exit(0);
}