*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
-
-/* BB_AUDIT SUSv3 compliant. */
-/* http://www.opengroup.org/onlinepubs/007904975/utilities/wc.html */
-
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Rewritten to fix a number of problems and do some size optimizations.
*
* for which 'wc -c' should output '0'.
*/
+//config:config WC
+//config: bool "wc"
+//config: default y
+//config: help
+//config: wc is used to print the number of bytes, words, and lines,
+//config: in specified files.
+//config:
+//config:config FEATURE_WC_LARGE
+//config: bool "Support very large counts"
+//config: default y
+//config: depends on WC
+//config: help
+//config: Use "unsigned long long" for counter variables.
+
+//applet:IF_WC(APPLET(wc, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_WC) += wc.o
+
+/* BB_AUDIT SUSv3 compliant. */
+/* http://www.opengroup.org/onlinepubs/007904975/utilities/wc.html */
+
#include "libbb.h"
#include "unicode.h"
//usage:
//usage:#define wc_full_usage "\n\n"
//usage: "Count lines, words, and bytes for each FILE (or stdin)\n"
-//usage: "\nOptions:"
//usage: "\n -c Count bytes"
//usage: IF_UNICODE_SUPPORT(
//usage: "\n -m Count characters"
* column order in "wc -cmlwL" output:
*/
enum {
- WC_LINES = 0,
- WC_WORDS = 1,
- WC_UNICHARS = 2,
- WC_CHARS = 3,
- WC_LENGTH = 4,
+ WC_LINES = 0, /* -l */
+ WC_WORDS = 1, /* -w */
+ WC_UNICHARS = 2, /* -m */
+ WC_BYTES = 3, /* -c */
+ WC_LENGTH = 4, /* -L */
NUM_WCS = 5,
};
init_unicode();
- print_type = getopt32(argv, "lwcmL");
+ print_type = getopt32(argv, "lwmcL");
if (print_type == 0) {
- print_type = (1 << WC_LINES) | (1 << WC_WORDS) | (1 << WC_CHARS);
+ print_type = (1 << WC_LINES) | (1 << WC_WORDS) | (1 << WC_BYTES);
}
argv += optind;
bb_simple_perror_msg(arg);
status = EXIT_FAILURE;
}
- goto DO_EOF; /* Treat an EOF as '\r'. */
+ goto DO_EOF; /* Treat an EOF as '\r'. */
}
/* Cater for -c and -m */
- ++counts[WC_CHARS];
+ ++counts[WC_BYTES];
if (unicode_status != UNICODE_ON /* every byte is a new char */
|| (c & 0xc0) != 0x80 /* it isn't a 2nd+ byte of a Unicode char */
) {
*/
if (c == '\t') {
linepos = (linepos | 7) + 1;
- } else { /* '\n', '\r', '\f', or '\v' */
+ } else { /* '\n', '\r', '\f', or '\v' */
DO_EOF:
if (linepos > counts[WC_LENGTH]) {
counts[WC_LENGTH] = linepos;
* effect of trashing the totals array after outputting it, but that's
* irrelavent since we no longer need it. */
if (num_files > 1) {
- num_files = 0; /* Make sure we don't get here again. */
+ num_files = 0; /* Make sure we don't get here again. */
arg = "total";
pcounts = totals;
--argv;