*** wc.c.orig 2006-09-18 14:09:49.000000000 -0400 --- wc.c 2006-09-18 16:23:11.000000000 -0400 *************** *** 49,54 **** --- 49,55 ---- #include "error.h" #include "inttostr.h" #include "safe-read.h" + #include "human.h" #ifndef HAVE_DECL_WCWIDTH "this configure-time declaration test was not run" *************** static uintmax_t max_line_length; *** 86,91 **** --- 87,95 ---- static bool print_lines, print_words, print_chars, print_bytes; static bool print_linelength; + /* Human-readable options for output. */ + static int human_output_opts = 0; + /* The print width of each count. */ static int number_width; *************** static struct option const longopts[] = *** 111,116 **** --- 115,121 ---- {"lines", no_argument, NULL, 'l'}, {"words", no_argument, NULL, 'w'}, {"max-line-length", no_argument, NULL, 'L'}, + {"human-readable", no_argument, NULL, 'h'}, {GETOPT_HELP_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL}, {NULL, 0, NULL, 0} *************** read standard input.\n\ *** 139,144 **** --- 144,150 ---- fputs (_("\ -L, --max-line-length print the length of the longest line\n\ -w, --words print the word counts\n\ + -h, --human-readable print byte count in human readable format\n\ "), stdout); fputs (HELP_OPTION_DESCRIPTION, stdout); fputs (VERSION_OPTION_DESCRIPTION, stdout); *************** write_counts (uintmax_t lines, *** 185,190 **** --- 191,202 ---- { printf (format_int, number_width, umaxtostr (linelength, buf)); } + if (human_output_opts) + { + printf(format_int, number_width, human_readable + (bytes, buf, human_output_opts, 1, 1)); + format_int = format_sp_int; + } if (file) printf (" %s", file); putchar ('\n'); *************** main (int argc, char **argv) *** 607,613 **** print_linelength = false; total_lines = total_words = total_chars = total_bytes = max_line_length = 0; ! while ((optc = getopt_long (argc, argv, "clLmw", longopts, NULL)) != -1) switch (optc) { case 'c': --- 619,625 ---- print_linelength = false; total_lines = total_words = total_chars = total_bytes = max_line_length = 0; ! while ((optc = getopt_long (argc, argv, "clLmwh", longopts, NULL)) != -1) switch (optc) { case 'c': *************** main (int argc, char **argv) *** 630,635 **** --- 642,651 ---- print_linelength = true; break; + case 'h': + human_output_opts = human_autoscale | human_SI | human_base_1024; + break; + case_GETOPT_HELP_CHAR; case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); *************** main (int argc, char **argv) *** 639,645 **** } if (! (print_lines | print_words | print_chars | print_bytes ! | print_linelength)) print_lines = print_words = print_bytes = true; nfiles = argc - optind; --- 655,661 ---- } if (! (print_lines | print_words | print_chars | print_bytes ! | print_linelength | human_output_opts)) print_lines = print_words = print_bytes = true; nfiles = argc - optind;