]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(posixly_correct): Declare global.
authorJim Meyering <jim@meyering.net>
Tue, 20 Jul 1999 07:56:59 +0000 (07:56 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 20 Jul 1999 07:56:59 +0000 (07:56 +0000)
(write_counts): Use it to select printf formats.
(main): Set posixly_correct from the POSIXLY_CORRECT envvar.
From Peter Moulder.

src/wc.c

index 4799ee446f3c1872dd0ba84c64042cf751bbee5e..ced5300dd9018e6e146954e53e821e0d02dbaaec 100644 (file)
--- a/src/wc.c
+++ b/src/wc.c
@@ -58,6 +58,10 @@ static int have_read_stdin;
 /* The error code to return to the system. */
 static int exit_status;
 
+/* If nonzero, do not line up columns but instead separate numbers by
+   a single space as specified in Single Unix Specification and POSIX. */
+static int posixly_correct;
+
 static struct option const longopts[] =
 {
   {"bytes", no_argument, NULL, 'c'},
@@ -107,25 +111,27 @@ write_counts (uintmax_t lines,
 {
   char buf[LONGEST_HUMAN_READABLE + 1];
   char const *space = "";
+  char const *format_int = (posixly_correct ? "%s" : "%7s");
+  char const *format_sp_int = (posixly_correct ? "%s%s" : "%s%7s");
 
   if (print_lines)
     {
-      printf ("%7s", human_readable (lines, buf, 1, 1));
+      printf (format_int, human_readable (lines, buf, 1, 1));
       space = " ";
     }
   if (print_words)
     {
-      printf ("%s%7s", space, human_readable (words, buf, 1, 1));
+      printf (format_sp_int, space, human_readable (words, buf, 1, 1));
       space = " ";
     }
   if (print_chars)
     {
-      printf ("%s%7s", space, human_readable (chars, buf, 1, 1));
+      printf (format_sp_int, space, human_readable (chars, buf, 1, 1));
       space = " ";
     }
   if (print_linelength)
     {
-      printf ("%s%7s", space, human_readable (linelength, buf, 1, 1));
+      printf (format_sp_int, space, human_readable (linelength, buf, 1, 1));
     }
   if (*file)
     printf (" %s", file);
@@ -304,6 +310,7 @@ main (int argc, char **argv)
   textdomain (PACKAGE);
 
   exit_status = 0;
+  posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
   print_lines = print_words = print_chars = print_linelength = 0;
   total_lines = total_words = total_chars = max_line_length = 0;