summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/toilet.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/toilet.c b/src/toilet.c
index 9f45a7d..c66896a 100644
--- a/src/toilet.c
+++ b/src/toilet.c
@@ -19,6 +19,9 @@
static int modeMap;
+// lines, words, bytes
+static size_t totals[3] = {0};
+
static void usage(FILE *f) {
fprintf(f,
"Gebruik: toilet [-nchV] [BESTAND]...\n"
@@ -118,11 +121,24 @@ static size_t get_count(enum MODE mode, struct filebuf *fb) {
}
}
+static int mlog2(int val) {
+#define C(n) case (1 << (n)): return (n);
+
+ switch (val) {
+ C(0) C(1) C(2)
+ }
+ assert(false);
+
+#undef C
+}
+
static int process(struct filebuf *fb, char *fname, bool) {
for (enum MODE mode = 1; mode <= M_BYTES; mode <<= 1) {
if (mode & modeMap) {
const size_t count = get_count(mode, fb);
printf("% 10li ", count);
+
+ totals[mlog2(mode)] += count;
}
}
printf("%s\n", fname);
@@ -140,5 +156,12 @@ int entry_toilet(int argc, char **argv) {
modeMap = INT_MAX;
}
- return loop_files(args, process);
+ const int res = loop_files(args, process);
+
+ for (size_t i = 0; i < 3; i++) {
+ printf("% 10li ", totals[i]);
+ }
+ puts("totaal");
+
+ return res;
}