summaryrefslogtreecommitdiff
path: root/src/wc.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1998-04-11 18:21:24 +0000
committerJim Meyering <jim@meyering.net>1998-04-11 18:21:24 +0000
commitac7b3c4fa9ed57b536207950255f71f0d0cd3448 (patch)
treee32c9525eed1ad21e7ef59fa804f1ede0ce0deab /src/wc.c
parentb402870080b5a3c84febb6c9de0b3977d1c0f010 (diff)
downloadcoreutils-ac7b3c4fa9ed57b536207950255f71f0d0cd3448.tar.xz
[HAVE_INTTYPES_H]: Include inttypes.h.
Declare counters to be of type uintmax_t. (write_counts): Use human_readable to format potentially-long-long numbers. Suggestion from Rogier Wolff.
Diffstat (limited to 'src/wc.c')
-rw-r--r--src/wc.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/wc.c b/src/wc.c
index aef35570f..7ee31f9be 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -19,12 +19,16 @@
and David MacKenzie, djm@gnu.ai.mit.edu. */
#include <config.h>
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
#include "error.h"
+#include "human.h"
/* Size of atomic reads. */
#define BUFFER_SIZE (16 * 1024)
@@ -36,7 +40,10 @@ char *program_name;
/* Cumulative number of lines, words, and chars in all files so far.
max_line_length is the maximum over all files processed so far. */
-static unsigned long total_lines, total_words, total_chars, max_line_length;
+static uintmax_t total_lines;
+static uintmax_t total_words;
+static uintmax_t total_chars;
+static uintmax_t max_line_length;
/* Which counts to print. */
static int print_lines, print_words, print_chars, print_linelength;
@@ -94,29 +101,33 @@ read standard input.\n\
}
static void
-write_counts (long unsigned int lines, long unsigned int words,
- long unsigned int chars, long unsigned int linelength,
+write_counts (uintmax_t lines,
+ uintmax_t words,
+ uintmax_t chars,
+ uintmax_t linelength,
const char *file)
{
+ char buf[LONGEST_HUMAN_READABLE + 1];
+ char const *space = "";
+
if (print_lines)
- printf ("%7lu", lines);
+ {
+ printf ("%7s", human_readable (lines, buf, 1, 1, 0));
+ space = " ";
+ }
if (print_words)
{
- if (print_lines)
- putchar (' ');
- printf ("%7lu", words);
+ printf ("%s%7s", space, human_readable (words, buf, 1, 1, 0));
+ space = " ";
}
if (print_chars)
{
- if (print_lines || print_words)
- putchar (' ');
- printf ("%7lu", chars);
+ printf ("%s%7s", space, human_readable (chars, buf, 1, 1, 0));
+ space = " ";
}
if (print_linelength)
{
- if (print_lines || print_words || print_chars)
- putchar (' ');
- printf ("%7lu", linelength);
+ printf ("%s%7s", space, human_readable (linelength, buf, 1, 1, 0));
}
if (*file)
printf (" %s", file);