aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@FreeBSD.org>2005-02-23 20:59:03 +0000
committerRuslan Ermilov <ru@FreeBSD.org>2005-02-23 20:59:03 +0000
commit423120f127c5a170fa40eb0d2c05d0324ceca8b8 (patch)
tree9dde2523da3762bccd3a6ca7676529f1dea88178
parent8b8984d523288882c3a768a9cf11da0cf87a093d (diff)
Notes
-rw-r--r--games/fortune/unstr/Makefile2
-rw-r--r--games/fortune/unstr/unstr.c37
2 files changed, 14 insertions, 25 deletions
diff --git a/games/fortune/unstr/Makefile b/games/fortune/unstr/Makefile
index 6b5b76ec754d..0331e4bfa2a8 100644
--- a/games/fortune/unstr/Makefile
+++ b/games/fortune/unstr/Makefile
@@ -3,7 +3,7 @@
PROG= unstr
NO_MAN=
-WARNS?= 3
+WARNS?= 6
CFLAGS+= -I${.CURDIR}/../strfile
.include <bsd.prog.mk>
diff --git a/games/fortune/unstr/unstr.c b/games/fortune/unstr/unstr.c
index 9246a8e04d52..25996f4f6b95 100644
--- a/games/fortune/unstr/unstr.c
+++ b/games/fortune/unstr/unstr.c
@@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
# include <sys/endian.h>
# include <stdio.h>
# include <ctype.h>
+# include <err.h>
# include <stdlib.h>
# include <string.h>
# include "strfile.h"
@@ -75,32 +76,32 @@ char *Infile, /* name of input file */
FILE *Inf, *Dataf;
-void getargs(char *[]), order_unstr(STRFILE *);
+void order_unstr(STRFILE *);
/* ARGSUSED */
int main(int ac, char **av)
{
static STRFILE tbl; /* description table */
- getargs(av);
- if ((Inf = fopen(Infile, "r")) == NULL) {
- perror(Infile);
- exit(1);
- }
- if ((Dataf = fopen(Datafile, "r")) == NULL) {
- perror(Datafile);
+ if (ac != 2) {
+ (void)fprintf(stderr, "usage: unstr datafile\n");
exit(1);
}
+ Infile = av[1];
+ (void) strcpy(Datafile, Infile);
+ (void) strcat(Datafile, ".dat");
+ if ((Inf = fopen(Infile, "r")) == NULL)
+ err(1, "%s", Infile);
+ if ((Dataf = fopen(Datafile, "r")) == NULL)
+ err(1, "%s", Datafile);
(void) fread((char *) &tbl, sizeof tbl, 1, Dataf);
tbl.str_version = be32toh(tbl.str_version);
tbl.str_numstr = be32toh(tbl.str_numstr);
tbl.str_longlen = be32toh(tbl.str_longlen);
tbl.str_shortlen = be32toh(tbl.str_shortlen);
tbl.str_flags = be32toh(tbl.str_flags);
- if (!(tbl.str_flags & (STR_ORDERED | STR_RANDOM))) {
- fprintf(stderr, "nothing to do -- table in file order\n");
- exit(1);
- }
+ if (!(tbl.str_flags & (STR_ORDERED | STR_RANDOM)))
+ errx(1, "nothing to do -- table in file order");
Delimch = tbl.str_delim;
order_unstr(&tbl);
(void) fclose(Inf);
@@ -108,18 +109,6 @@ int main(int ac, char **av)
exit(0);
}
-void getargs(av)
-char *av[];
-{
- if (!*++av) {
- (void) fprintf(stderr, "usage: unstr datafile\n");
- exit(1);
- }
- Infile = *av;
- (void) strcpy(Datafile, Infile);
- (void) strcat(Datafile, ".dat");
-}
-
void order_unstr(tbl)
STRFILE *tbl;
{