From abb8ca2455f3efd6f8f0eed78c54829bf0a9001e Mon Sep 17 00:00:00 2001 From: Felix Janda Date: Thu, 8 Nov 2012 11:19:07 -0600 Subject: wc -m only cares about counting characters. Attached is a try on implementing it and some test cases for it. The test cases are only for UTF-8 locales. --- toys/posix/wc.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'toys') diff --git a/toys/posix/wc.c b/toys/posix/wc.c index 7a5e5a30..3896b73a 100644 --- a/toys/posix/wc.c +++ b/toys/posix/wc.c @@ -6,22 +6,24 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/wc.html -USE_WC(NEWTOY(wc, "cwl", TOYFLAG_USR|TOYFLAG_BIN)) +USE_WC(NEWTOY(wc, "mcwl", TOYFLAG_USR|TOYFLAG_BIN)) config WC bool "wc" default y help - usage: wc -lwc [FILE...] + usage: wc -lwcm [FILE...] Count lines, words, and characters in input. -l show lines -w show words - -c show characters + -c show bytes + -m show characters - By default outputs lines, words, characters, and filename for each - argument (or from stdin if none). + By default outputs lines, words, bytes, and filename for each + argument (or from stdin if none). Displays only either bytes + or characters. */ #define FOR_wc @@ -47,7 +49,8 @@ static void show_lengths(unsigned long *lengths, char *name) static void do_wc(int fd, char *name) { - int i, len; + int i, len, clen=1, space; + wchar_t wchar; unsigned long word=0, lengths[]={0,0,0}; for (;;) { @@ -57,9 +60,24 @@ static void do_wc(int fd, char *name) toys.exitval = EXIT_FAILURE; } if (len<1) break; - for (i=0; i>1; loopfiles(toys.optargs, do_wc); if (toys.optc>1) show_lengths(TT.totals, "total"); } -- cgit v1.2.3