summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed/main.c
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-08-11 07:21:08 +0000
committercharnier <charnier@FreeBSD.org>1997-08-11 07:21:08 +0000
commitdb6e9b0f817fc362dc74d8b4273dfb5eb5a65a12 (patch)
treead568dde487c13cc2ad821266aecea23ab068b46 /usr.bin/sed/main.c
parent5555a73810e96888231ea397c55ee788055ab6c7 (diff)
downloadFreeBSD-src-db6e9b0f817fc362dc74d8b4273dfb5eb5a65a12.zip
FreeBSD-src-db6e9b0f817fc362dc74d8b4273dfb5eb5a65a12.tar.gz
Remove local redefinition for err(). Add usage().
Diffstat (limited to 'usr.bin/sed/main.c')
-rw-r--r--usr.bin/sed/main.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index 02cbfac..6e1ef35 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -36,17 +36,22 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/3/94";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/types.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <locale.h>
@@ -101,6 +106,7 @@ int lastline; /* TRUE on the last line of the last file */
static void add_compunit __P((enum e_cut, char *));
static void add_file __P((char *));
+static void usage __P((void));
int
main(argc, argv)
@@ -130,9 +136,7 @@ main(argc, argv)
break;
default:
case '?':
- (void)fprintf(stderr,
-"usage:\tsed script [-an] [file ...]\n\tsed [-an] [-e script] ... [-f script_file] ... [file ...]\n");
- exit(1);
+ usage();
}
argc -= optind;
argv += optind;
@@ -154,10 +158,19 @@ main(argc, argv)
process();
cfclose(prog, NULL);
if (fclose(stdout))
- err(FATAL, "stdout: %s", strerror(errno));
+ err(1, "stdout");
exit (0);
}
+static void
+usage()
+{
+ (void)fprintf(stderr, "%s\n%s\n",
+ "usage: sed script [-an] [file ...]",
+ " sed [-an] [-e script] ... [-f script_file] ... [file ...]");
+ exit(1);
+}
+
/*
* Like fgets, but go through the chain of compilation units chaining them
* together. Empty strings and files are ignored.
@@ -182,8 +195,7 @@ again:
switch (script->type) {
case CU_FILE:
if ((f = fopen(script->s, "r")) == NULL)
- err(FATAL,
- "%s: %s", script->s, strerror(errno));
+ err(1, "%s", script->s);
fname = script->s;
state = ST_FILE;
goto again;
@@ -243,6 +255,7 @@ again:
}
}
/* NOTREACHED */
+ return (NULL);
}
/*
@@ -272,8 +285,7 @@ mf_fgets(sp, spflag)
} else {
fname = files->fname;
if ((f = fopen(fname, "r")) == NULL)
- err(FATAL, "%s: %s",
- fname, strerror(errno));
+ err(1, "%s", fname);
}
if ((c = getc(f)) != EOF) {
(void)ungetc(c, f);
@@ -295,7 +307,7 @@ mf_fgets(sp, spflag)
*/
p = fgetln(f, &len);
if (ferror(f))
- err(FATAL, "%s: %s", fname, strerror(errno ? errno : EIO));
+ errx(1, "%s: %s", fname, strerror(errno ? errno : EIO));
cspace(sp, p, len, spflag);
linenum++;
@@ -313,7 +325,7 @@ mf_fgets(sp, spflag)
} else {
fname = files->fname;
if ((f = fopen(fname, "r")) == NULL)
- err(FATAL, "%s: %s", fname, strerror(errno));
+ err(1, "%s", fname);
}
}
(void)ungetc(c, f);
OpenPOWER on IntegriCloud