From cb75653e8749dc75c5e74fe374b70190361a46c2 Mon Sep 17 00:00:00 2001 From: zrj Date: Thu, 1 Sep 2016 07:54:44 +0300 Subject: [PATCH] fortune(6): Use argc and argv. While there disable speedup in collate_range_cmp() (recall causes problems). --- games/fortune/fortune/fortune.c | 6 +++--- games/fortune/strfile/strfile.c | 8 ++----- games/fortune/unstr/unstr.c | 38 +++++++++++---------------------- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/games/fortune/fortune/fortune.c b/games/fortune/fortune/fortune.c index cc4035190a..33a86a633d 100644 --- a/games/fortune/fortune/fortune.c +++ b/games/fortune/fortune/fortune.c @@ -151,7 +151,7 @@ static int maxlen_in_list(FILEDESC *); static regex_t Re_pat; int -main(int ac, char *av[]) +main(int argc, char *argv[]) { #ifdef OK_TO_WRITE_DISK int fd; @@ -159,7 +159,7 @@ main(int ac, char *av[]) setlocale(LC_ALL, ""); - getargs(ac, av); + getargs(argc, argv); if (Match) exit(find_matches() != 0); @@ -260,7 +260,7 @@ fortlen(void) * This routine evaluates the arguments on the command line */ static void -getargs(int argc, char **argv) +getargs(int argc, char *argv[]) { int ignore_case; char *pat; diff --git a/games/fortune/strfile/strfile.c b/games/fortune/strfile/strfile.c index f91681e38c..8bc75cb3aa 100644 --- a/games/fortune/strfile/strfile.c +++ b/games/fortune/strfile/strfile.c @@ -128,7 +128,7 @@ static void usage(void); * and then seek back to the beginning to write in the table. */ int -main(int ac, char *av[]) +main(int argc, char *argv[]) { char *sp, *nsp, dc; FILE *inf, *outf; @@ -139,7 +139,7 @@ main(int ac, char *av[]) setlocale(LC_ALL, ""); - getargs(ac, av); /* evalute arguments */ + getargs(argc, argv); /* evalute arguments */ dc = Delimch; if ((inf = fopen(Infile, "r")) == NULL) { perror(Infile); @@ -352,10 +352,6 @@ collate_range_cmp (int c1, int c2) static char s1[2], s2[2]; int ret; - c1 &= UCHAR_MAX; - c2 &= UCHAR_MAX; - if (c1 == c2) - return (0); s1[0] = c1; s2[0] = c2; if ((ret = strcoll(s1, s2)) != 0) diff --git a/games/fortune/unstr/unstr.c b/games/fortune/unstr/unstr.c index 92d9f6d001..09755d916b 100644 --- a/games/fortune/unstr/unstr.c +++ b/games/fortune/unstr/unstr.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -62,34 +63,33 @@ static char Delimch; /* delimiter character */ static FILE *Inf, *Dataf; -static void getargs(char *[]); static void order_unstr(STRFILE *); /* ARGSUSED */ int -main(int ac __unused, char *av[]) +main(int argc, char *argv[]) { 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 (argc != 2) { + fprintf(stderr, "usage: unstr datafile\n"); exit(1); } + Infile = argv[1]; + strcpy(Datafile, Infile); + strcat(Datafile, ".dat"); + if ((Inf = fopen(Infile, "r")) == NULL) + err(1, "%s", Infile); + if ((Dataf = fopen(Datafile, "r")) == NULL) + err(1, "%s", Datafile); fread((char *)&tbl, sizeof(tbl), 1, Dataf); tbl.str_version = ntohl(tbl.str_version); tbl.str_numstr = ntohl(tbl.str_numstr); tbl.str_longlen = ntohl(tbl.str_longlen); tbl.str_shortlen = ntohl(tbl.str_shortlen); tbl.str_flags = ntohl(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); fclose(Inf); @@ -97,18 +97,6 @@ main(int ac __unused, char *av[]) exit(0); } -static void -getargs(char *av[]) -{ - if (!*++av) { - fprintf(stderr, "usage: unstr datafile\n"); - exit(1); - } - Infile = *av; - strcpy(Datafile, Infile); - strcat(Datafile, ".dat"); -} - static void order_unstr(STRFILE *tbl) { -- 2.41.0