]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
[HAVE_INTTYPES_H]: Include inttypes.h.
authorJim Meyering <jim@meyering.net>
Sat, 11 Apr 1998 18:21:24 +0000 (18:21 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 11 Apr 1998 18:21:24 +0000 (18:21 +0000)
Declare counters to be of type uintmax_t.
(write_counts): Use human_readable to format potentially-long-long
numbers.  Suggestion from Rogier Wolff.

src/wc.c

index aef35570f1a26d413397ff0dbe20106dd5ac56c3..7ee31f9beff86daa9529f7c299d3e8c63eb48133 100644 (file)
--- a/src/wc.c
+++ b/src/wc.c
    and David MacKenzie, djm@gnu.ai.mit.edu. */
 \f
 #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);