Add usage(), use err(3).
This commit is contained in:
parent
f87a50fadf
commit
3354e4d90e
@ -35,25 +35,36 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1990, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)fold.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define DEFLINEWIDTH 80
|
||||
|
||||
void fold __P((int));
|
||||
static void usage __P((void));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
extern int errno, optind;
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
register int ch;
|
||||
int width;
|
||||
@ -64,9 +75,7 @@ main(argc, argv)
|
||||
switch (ch) {
|
||||
case 'w':
|
||||
if ((width = atoi(optarg)) <= 0) {
|
||||
(void)fprintf(stderr,
|
||||
"fold: illegal width value.\n");
|
||||
exit(1);
|
||||
errx(1, "illegal width value");
|
||||
}
|
||||
break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
@ -80,9 +89,7 @@ main(argc, argv)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
(void)fprintf(stderr,
|
||||
"usage: fold [-w width] [file ...]\n");
|
||||
exit(1);
|
||||
usage();
|
||||
}
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
@ -93,14 +100,20 @@ main(argc, argv)
|
||||
fold(width);
|
||||
else for (; *argv; ++argv)
|
||||
if (!freopen(*argv, "r", stdin)) {
|
||||
(void)fprintf(stderr,
|
||||
"fold: %s: %s\n", *argv, strerror(errno));
|
||||
exit(1);
|
||||
err(1, "%s", *argv);
|
||||
} else
|
||||
fold(width);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "usage: fold [-w width] [file ...]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
fold(width)
|
||||
register int width;
|
||||
{
|
||||
|
@ -32,24 +32,33 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1980, 1988, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)from.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <paths.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int match __P((char *, char *));
|
||||
static void usage __P((void));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
@ -66,7 +75,7 @@ main(argc, argv)
|
||||
#endif
|
||||
|
||||
file = sender = NULL;
|
||||
while ((ch = getopt(argc, argv, "f:s:?")) != -1)
|
||||
while ((ch = getopt(argc, argv, "f:s:")) != -1)
|
||||
switch((char)ch) {
|
||||
case 'f':
|
||||
file = optarg;
|
||||
@ -79,8 +88,7 @@ main(argc, argv)
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
fprintf(stderr, "usage: from [-f file] [-s sender] [user]\n");
|
||||
exit(1);
|
||||
usage();
|
||||
}
|
||||
argv += optind;
|
||||
|
||||
@ -90,11 +98,8 @@ main(argc, argv)
|
||||
file = buf;
|
||||
} else {
|
||||
if (!(file = getenv("MAIL"))) {
|
||||
if (!(pwd = getpwuid(getuid()))) {
|
||||
(void)fprintf(stderr,
|
||||
"from: no password file entry for you.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!(pwd = getpwuid(getuid())))
|
||||
errx(1, "no password file entry for you");
|
||||
file = pwd->pw_name;
|
||||
(void)sprintf(buf,
|
||||
"%s/%s", _PATH_MAILDIR, file);
|
||||
@ -107,8 +112,7 @@ main(argc, argv)
|
||||
if (strcmp(file, "-") == 0) {
|
||||
}
|
||||
else if (!freopen(file, "r", stdin)) {
|
||||
fprintf(stderr, "from: can't read %s.\n", file);
|
||||
exit(1);
|
||||
errx(1, "can't read %s", file);
|
||||
}
|
||||
for (newline = 1; fgets(buf, sizeof(buf), stdin);) {
|
||||
if (*buf == '\n') {
|
||||
@ -123,6 +127,14 @@ main(argc, argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "usage: from [-f file] [-s sender] [user]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
match(line, sender)
|
||||
register char *line, *sender;
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user