version 1.10, 2005/04/11 07:04:47 |
version 1.11, 2005/10/19 21:49:02 |
|
|
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <sys/file.h> |
#include <sys/file.h> |
#include <unistd.h> |
#include <unistd.h> |
|
#include <util.h> |
|
|
int64_t tlinect, twordct, tcharct; |
int64_t tlinect, twordct, tcharct; |
int doline, doword, dochar; |
int doline, doword, dochar, humanchar; |
int rval; |
int rval; |
extern char *__progname; |
extern char *__progname; |
|
|
|
|
|
|
setlocale(LC_ALL, ""); |
setlocale(LC_ALL, ""); |
|
|
while ((ch = getopt(argc, argv, "lwcm")) != -1) |
while ((ch = getopt(argc, argv, "lwchm")) != -1) |
switch((char)ch) { |
switch((char)ch) { |
case 'l': |
case 'l': |
doline = 1; |
doline = 1; |
|
|
case 'm': |
case 'm': |
dochar = 1; |
dochar = 1; |
break; |
break; |
|
case 'h': |
|
humanchar = 1; |
|
break; |
case '?': |
case '?': |
default: |
default: |
(void)fprintf(stderr, |
(void)fprintf(stderr, |
"usage: %s [-c | -m] [-lw] [file ...]\n", |
"usage: %s [-c | -m] [-hlw] [file ...]\n", |
__progname); |
__progname); |
exit(1); |
exit(1); |
} |
} |
|
|
} |
} |
} |
} |
|
|
|
void |
|
format_and_print(long long v) |
|
{ |
|
if (humanchar) { |
|
char result[FMT_SCALED_STRSIZE]; |
|
|
|
(void)fmt_scaled(v, result); |
|
(void)printf("%7s", result); |
|
} else { |
|
(void)printf(" %7lld", v); |
|
} |
|
} |
|
|
void |
void |
print_counts(int64_t lines, int64_t words, int64_t chars, char *name) |
print_counts(int64_t lines, int64_t words, int64_t chars, char *name) |
{ |
{ |
|
|
if (doline) |
if (doline) |
(void)printf(" %7lld", (long long)lines); |
format_and_print((long long)lines); |
if (doword) |
if (doword) |
(void)printf(" %7lld", (long long)words); |
format_and_print((long long)words); |
if (dochar) |
if (dochar) |
(void)printf(" %7lld", (long long)chars); |
format_and_print((long long)chars); |
|
|
(void)printf(" %s\n", name); |
(void)printf(" %s\n", name); |
} |
} |