From c948c0582cace4ca0a573b94abcbccadcf040131 Mon Sep 17 00:00:00 2001 From: Juli Mallett Date: Sun, 30 Jun 2002 17:36:54 +0000 Subject: [PATCH] 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. --- usr.bin/from/from.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/usr.bin/from/from.c b/usr.bin/from/from.c index 5fc726fae434..d42e0bd787fa 100644 --- a/usr.bin/from/from.c +++ b/usr.bin/from/from.c @@ -59,10 +59,9 @@ int match(char *, char *); static void usage(void); int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { + FILE *mbox; struct passwd *pwd; int ch, count, newline; char *file, *sender, *p; @@ -92,10 +91,11 @@ main(argc, argv) default: usage(); } + argc -= optind; argv += optind; - if (!file) { - if (*argv) { + if (file == NULL) { + if (argc) { (void)snprintf(buf, sizeof(buf), "%s/%s", _PATH_MAILDIR, *argv); file = buf; } else { @@ -112,11 +112,12 @@ main(argc, argv) /* read from stdin */ 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); } - for (newline = 1; fgets(buf, sizeof(buf), stdin);) { + for (newline = 1; fgets(buf, sizeof(buf), mbox);) { if (*buf == '\n') { newline = 1; continue; @@ -133,21 +134,21 @@ main(argc, argv) if (count != -1) printf("There %s %d message%s in your incoming mailbox.\n", count == 1 ? "is" : "are", count, count == 1 ? "" : "s"); + fclose(mbox); exit(0); } static void -usage() +usage(void) { fprintf(stderr, "usage: from [-c] [-f file] [-s sender] [user]\n"); exit(1); } int -match(line, sender) - register char *line, *sender; +match(char *line, char *sender) { - register char ch, pch, first, *p, *t; + char ch, pch, first, *p, *t; for (first = *sender++;;) { if (isspace(ch = *line))