diff options
author | Lieuwe Rooijakkers <lieuwerooijakkers@gmail.com> | 2024-08-19 01:40:26 +0200 |
---|---|---|
committer | Lieuwe Rooijakkers <lieuwerooijakkers@gmail.com> | 2024-08-19 01:40:26 +0200 |
commit | d7df7587213597fb2bc6c3a561bb3d7317d5b1ae (patch) | |
tree | 507b27b5361a983214eca846b7bff9eeb5c803bb /src | |
parent | d0f2a6541f90cb915b0733ac188c7e0cb332e970 (diff) |
toilet: code cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/toilet.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/toilet.c b/src/toilet.c index aab9dcc..717afa4 100644 --- a/src/toilet.c +++ b/src/toilet.c @@ -98,22 +98,19 @@ static size_t count_lines(char *fname, FILE *f) { static size_t count_words(FILE *f) { #define BUF_SIZE 4096 - size_t nwords = 0; - static char buf[BUF_SIZE]; while (!feof(f)) { + static char buf[BUF_SIZE]; const size_t n = fread(buf, 1, BUF_SIZE, f); -#define IN(i) (i < n) - for (size_t i = 0; IN(i);) { + // (c) Tom Forging + for (size_t i = 0; i<n;) { size_t previ = i; - while (IN(i) && !isspace(buf[i])) i++; + while (i<n && !isspace(buf[i])) i++; nwords += i != previ; - while (IN(i) && isspace(buf[i])) i++; + while (i<n && isspace(buf[i])) i++; } -#undef IN - } rewind(f); |