Minor cleanup: ANSI C function declarations, use argc after getopt(3) to check

for remaining arguments, rather than checking for *argv being a boolean truth.
Instead of using an empty case to check for -f- to mean "read stdin", and have
stdin reopned otherwise, use a FILE* for the mbox, and assign it to stdin when
we mean to use stdin, otherwise fopen(3).  Kill `register' qualifier.
This commit is contained in:
Juli Mallett 2002-06-30 17:36:54 +00:00
parent bff4151c28
commit c948c0582c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=99143

View File

@ -59,10 +59,9 @@ int match(char *, char *);
static void usage(void); static void usage(void);
int int
main(argc, argv) main(int argc, char **argv)
int argc;
char **argv;
{ {
FILE *mbox;
struct passwd *pwd; struct passwd *pwd;
int ch, count, newline; int ch, count, newline;
char *file, *sender, *p; char *file, *sender, *p;
@ -92,10 +91,11 @@ main(argc, argv)
default: default:
usage(); usage();
} }
argc -= optind;
argv += optind; argv += optind;
if (!file) { if (file == NULL) {
if (*argv) { if (argc) {
(void)snprintf(buf, sizeof(buf), "%s/%s", _PATH_MAILDIR, *argv); (void)snprintf(buf, sizeof(buf), "%s/%s", _PATH_MAILDIR, *argv);
file = buf; file = buf;
} else { } else {
@ -112,11 +112,12 @@ main(argc, argv)
/* read from stdin */ /* read from stdin */
if (strcmp(file, "-") == 0) { if (strcmp(file, "-") == 0) {
mbox = stdin;
} }
else if (!freopen(file, "r", stdin)) { else if ((mbox = fopen(file, "r")) == NULL) {
errx(1, "can't read %s", file); errx(1, "can't read %s", file);
} }
for (newline = 1; fgets(buf, sizeof(buf), stdin);) { for (newline = 1; fgets(buf, sizeof(buf), mbox);) {
if (*buf == '\n') { if (*buf == '\n') {
newline = 1; newline = 1;
continue; continue;
@ -133,21 +134,21 @@ main(argc, argv)
if (count != -1) if (count != -1)
printf("There %s %d message%s in your incoming mailbox.\n", printf("There %s %d message%s in your incoming mailbox.\n",
count == 1 ? "is" : "are", count, count == 1 ? "" : "s"); count == 1 ? "is" : "are", count, count == 1 ? "" : "s");
fclose(mbox);
exit(0); exit(0);
} }
static void static void
usage() usage(void)
{ {
fprintf(stderr, "usage: from [-c] [-f file] [-s sender] [user]\n"); fprintf(stderr, "usage: from [-c] [-f file] [-s sender] [user]\n");
exit(1); exit(1);
} }
int int
match(line, sender) match(char *line, char *sender)
register char *line, *sender;
{ {
register char ch, pch, first, *p, *t; char ch, pch, first, *p, *t;
for (first = *sender++;;) { for (first = *sender++;;) {
if (isspace(ch = *line)) if (isspace(ch = *line))