aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqorg11 <qorg@vxempire.xyz>2020-12-26 03:57:32 +0100
committerqorg11 <qorg@vxempire.xyz>2020-12-26 03:57:32 +0100
commitd716f2936bd00c1b23ff69eada519f157ad3a9cc (patch)
tree324fb1ceae4ea2650de0116136a8640405b650d2
parenta74d57d57fcb5b50d93409172f611c20f5e9848a (diff)
downloadk9core-d716f2936bd00c1b23ff69eada519f157ad3a9cc.tar.gz
k9core-d716f2936bd00c1b23ff69eada519f157ad3a9cc.zip
Add todo to wc
-rw-r--r--src/wc.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/wc.c b/src/wc.c
index 32ab4a7..7d96b9c 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -5,6 +5,14 @@
#include <errno.h>
#include <string.h>
+/* TODO: fucking make this thing read binary data
+* Possible solutions:
+* fread()
+* fgets()
+* rewrite this entire thing using read() (not a good idea
+* because it's slow as shit)
+*/
+
int show_lines, show_words, show_bytes;
struct wc_values data;
@@ -26,12 +34,16 @@ wc(const char *filename, struct wc_values *data)
return -1;
}
char c;
+ char a;
int newlines, spaces, bytes = 0;
newlines = spaces = bytes = 0;
while((c = fgetc(file)) > 0)
{
+ a = c;
+ if(!isascii(c))
+ a = toascii(c);
bytes++;
- if(c == '\n')
+ if(a == '\n')
newlines++;
if(isspace(c))
spaces++;