From 01a98f38c7baf87cf384136efa1f9f44634f1984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20B=C3=B6hm?=
Date: Tue, 11 Feb 2014 19:34:42 +0100 Subject: [PATCH] wc: added -q,--quiet option * src/wc.wc: Suppress the printing of the filename if requested to do so. --- src/wc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/wc.c b/src/wc.c index 4909d9f..06486a5 100644 --- a/src/wc.c +++ b/src/wc.c @@ -64,6 +64,7 @@ static uintmax_t max_line_length; /* Which counts to print. */ static bool print_lines, print_words, print_chars, print_bytes; static bool print_linelength; +static bool print_quiet; /* The print width of each count. */ static int number_width; @@ -95,6 +96,7 @@ static struct option const longopts[] = {"chars", no_argument, NULL, 'm'}, {"lines", no_argument, NULL, 'l'}, {"words", no_argument, NULL, 'w'}, + {"quiet", no_argument, NULL, 'q'}, {"files0-from", required_argument, NULL, FILES0_FROM_OPTION}, {"max-line-length", no_argument, NULL, 'L'}, {GETOPT_HELP_OPTION_DECL}, @@ -126,6 +128,7 @@ the following order: newline, word, character, byte, maximum line length.\n\ -l, --lines print the newline counts\n\ "), stdout); fputs (_("\ + -q, --quiet don't print the filename\n\ --files0-from=F read input from the files specified by\n\ NUL-terminated names in file F;\n\ If F is - then read names from standard input\n\ @@ -177,7 +180,7 @@ write_counts (uintmax_t lines, { printf (format_int, number_width, umaxtostr (linelength, buf)); } - if (file) + if (file&&(!print_quiet)) printf (" %s", file); putchar ('\n'); } @@ -612,9 +615,10 @@ main (int argc, char **argv) print_lines = print_words = print_chars = print_bytes = false; print_linelength = false; + print_quiet = false; total_lines = total_words = total_chars = total_bytes = max_line_length = 0; - while ((optc = getopt_long (argc, argv, "clLmw", longopts, NULL)) != -1) + while ((optc = getopt_long (argc, argv, "clLmqw", longopts, NULL)) != -1) switch (optc) { case 'c': @@ -633,6 +637,10 @@ main (int argc, char **argv) print_words = true; break; + case 'q': + print_quiet = true; + break; + case 'L': print_linelength = true; break; -- 1.8.3.2