version 1.27, 2021/10/24 21:24:18 |
version 1.28, 2021/11/16 23:34:24 |
|
|
int rval; |
int rval; |
extern char *__progname; |
extern char *__progname; |
|
|
static void print_counts(int64_t, int64_t, int64_t, char *); |
static void print_counts(int64_t, int64_t, int64_t, const char *); |
static void format_and_print(int64_t); |
static void format_and_print(int64_t); |
static void cnt(char *); |
static void cnt(const char *); |
|
|
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
|
|
} |
} |
|
|
static void |
static void |
cnt(char *file) |
cnt(const char *path) |
{ |
{ |
static char *buf; |
static char *buf; |
static size_t bufsz; |
static size_t bufsz; |
|
|
FILE *stream; |
FILE *stream; |
|
const char *file; |
char *C; |
char *C; |
wchar_t wc; |
wchar_t wc; |
short gotsp; |
short gotsp; |
|
|
|
|
linect = wordct = charct = 0; |
linect = wordct = charct = 0; |
stream = NULL; |
stream = NULL; |
if (file) { |
if (path != NULL) { |
|
file = path; |
if ((fd = open(file, O_RDONLY)) == -1) { |
if ((fd = open(file, O_RDONLY)) == -1) { |
warn("%s", file); |
warn("%s", file); |
rval = 1; |
rval = 1; |
return; |
return; |
} |
} |
} else { |
} else { |
|
file = "(stdin)"; |
fd = STDIN_FILENO; |
fd = STDIN_FILENO; |
} |
} |
|
|
|
|
} |
} |
} |
} |
} else { |
} else { |
if (file == NULL) |
if (path == NULL) |
stream = stdin; |
stream = stdin; |
else if ((stream = fdopen(fd, "r")) == NULL) { |
else if ((stream = fdopen(fd, "r")) == NULL) { |
warn("%s", file); |
warn("%s", file); |
|
|
} |
} |
} |
} |
|
|
print_counts(linect, wordct, charct, file); |
print_counts(linect, wordct, charct, path); |
|
|
/* |
/* |
* Don't bother checking doline, doword, or dochar -- speeds |
* Don't bother checking doline, doword, or dochar -- speeds |
|
|
} |
} |
|
|
static void |
static 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, const char *name) |
{ |
{ |
if (doline) |
if (doline) |
format_and_print(lines); |
format_and_print(lines); |