1) De-K&R-ify function declarations, add const where necessary and bump
authorSascha Wildner <swildner@dragonflybsd.org>
Sun, 31 Jul 2005 20:40:26 +0000 (20:40 +0000)
committerSascha Wildner <swildner@dragonflybsd.org>
Sun, 31 Jul 2005 20:40:26 +0000 (20:40 +0000)
   WARNS to 6.

2) Remove duplicate CVS tag.

3) Remove unnecessary void casts.

4) Remove parameter names from function prototypes and make functions static.

5) Really use the usage() function.

6) Minor style cleanup.

(1) submitted by: Peter Avalos <pavalos@theshell.com>

games/fish/Makefile
games/fish/fish.c

index 8e46137..e6c5d1d 100644 (file)
@@ -1,10 +1,11 @@
 #      @(#)Makefile    8.1 (Berkeley) 5/31/93
 # $FreeBSD: src/games/fish/Makefile,v 1.4.6.3 2002/02/18 16:02:41 ru Exp $
-# $DragonFly: src/games/fish/Makefile,v 1.2 2003/06/17 04:25:23 dillon Exp $
+# $DragonFly: src/games/fish/Makefile,v 1.3 2005/07/31 20:40:26 swildner Exp $
 
 PROG=  fish
 FILES= fish.instr
 MAN=   fish.6
 HIDEGAME=hidegame
+WARNS?=        6
 
 .include <bsd.prog.mk>
index 9274f74..eec43e5 100644 (file)
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/games/fish/fish.c,v 1.9 1999/12/10 16:21:50 billf Exp $
- * $DragonFly: src/games/fish/fish.c,v 1.3 2003/11/12 14:53:53 eirikn Exp $
+ * $DragonFly: src/games/fish/fish.c,v 1.4 2005/07/31 20:40:26 swildner Exp $
  *
  * @(#) Copyright (c) 1990, 1993 The Regents of the University of California.  All rights reserved.
  * @(#)fish.c  8.1 (Berkeley) 5/31/93
- * $FreeBSD: src/games/fish/fish.c,v 1.9 1999/12/10 16:21:50 billf Exp $
  */
 
 #include <sys/types.h>
 #define        COMPUTER        0
 #define        OTHER(a)        (1 - (a))
 
-char *cards[] = {
+const char *cards[] = {
        "A", "2", "3", "4", "5", "6", "7",
        "8", "9", "10", "J", "Q", "K", NULL,
 };
-#define        PRC(card)       (void)printf(" %s", cards[card])
+#define        PRC(card)       printf(" %s", cards[card])
 
 int promode;
 int asked[RANKS], comphand[RANKS], deck[RANKS];
 int userasked[RANKS], userhand[RANKS];
 
-void   chkwinner (int player, int *hand);
-int    compmove (void);
-int    countbooks (int *hand);
-int    countcards (int *hand);
-int    drawcard (int player, int *hand);
-int    gofish (int askedfor, int player, int *hand);
-void   goodmove (int player, int move, int *hand, int *opphand);
-void   init (void);
-void   instructions (void);
-int    nrandom (int n);
-void   printhand (int *hand);
-void   printplayer (int player);
-int    promove (void);
-void   usage (void);
-int    usermove (void);
+static void    chkwinner(int, int *);
+static int     compmove(void);
+static int     countbooks(int *);
+static int     countcards(int *);
+static int     drawcard(int, int *);
+static int     gofish(int, int, int *);
+static void    goodmove(int, int, int *, int *);
+static void    init(void);
+static void    instructions(void);
+static int     nrandom(int);
+static void    printhand(int *);
+static void    printplayer(int);
+static int     promove(void);
+static void    usage(void);
+static int     usermove(void);
 
 int
-main(argc, argv)
-       int argc;
-       char **argv;
+main(int argc, char **argv)
 {
        int ch, move;
 
@@ -98,8 +95,7 @@ main(argc, argv)
                        break;
                case '?':
                default:
-                       (void)fprintf(stderr, "usage: fish [-p]\n");
-                       exit(1);
+                       usage();
                }
 
        srandomdev();
@@ -108,11 +104,11 @@ main(argc, argv)
 
        if (nrandom(2) == 1) {
                printplayer(COMPUTER);
-               (void)printf("get to start.\n");
+               printf("get to start.\n");
                goto istart;
        }
        printplayer(USER);
-       (void)printf("get to start.\n");
+       printf("get to start.\n");
 
        for (;;) {
                move = usermove();
@@ -137,34 +133,34 @@ istart:           for (;;) {
        return(EXIT_FAILURE);
 }
 
-int
-usermove()
+static int
+usermove(void)
 {
        int n;
-       char **p;
+       const char **p;
        char buf[256];
 
-       (void)printf("\nYour hand is:");
+       printf("\nYour hand is:");
        printhand(userhand);
 
        for (;;) {
-               (void)printf("You ask me for: ");
-               (void)fflush(stdout);
+               printf("You ask me for: ");
+               fflush(stdout);
                if (fgets(buf, sizeof(buf), stdin) == NULL)
                        exit(0);
                if (buf[0] == '\0')
                        continue;
                if (buf[0] == '\n') {
-                       (void)printf("%d cards in my hand, %d in the pool.\n",
+                       printf("%d cards in my hand, %d in the pool.\n",
                            countcards(comphand), countcards(deck));
-                       (void)printf("My books:");
-                       (void)countbooks(comphand);
+                       printf("My books:");
+                       countbooks(comphand);
                        continue;
                }
                buf[strlen(buf) - 1] = '\0';
                if (!strcasecmp(buf, "p") && !promode) {
                        promode = 1;
-                       (void)printf("Entering pro mode.\n");
+                       printf("Entering pro mode.\n");
                        continue;
                }
                if (!strcasecmp(buf, "quit"))
@@ -173,7 +169,7 @@ usermove()
                        if (!strcasecmp(*p, buf))
                                break;
                if (!*p) {
-                       (void)printf("I don't understand!\n");
+                       printf("I don't understand!\n");
                        continue;
                }
                n = p - cards;
@@ -182,18 +178,18 @@ usermove()
                        return(n);
                }
                if (nrandom(3) == 1)
-                       (void)printf("You don't have any of those!\n");
+                       printf("You don't have any of those!\n");
                else
-                       (void)printf("You don't have any %s's!\n", cards[n]);
+                       printf("You don't have any %s's!\n", cards[n]);
                if (nrandom(4) == 1)
-                       (void)printf("No cheating!\n");
-               (void)printf("Guess again.\n");
+                       printf("No cheating!\n");
+               printf("Guess again.\n");
        }
        /* NOTREACHED */
 }
 
-int
-compmove()
+static int
+compmove(void)
 {
        static int lmove;
 
@@ -206,18 +202,17 @@ compmove()
        }
        asked[lmove] = 1;
 
-       (void)printf("I ask you for: %s.\n", cards[lmove]);
+       printf("I ask you for: %s.\n", cards[lmove]);
        return(lmove);
 }
 
-int
-promove()
+static int
+promove(void)
 {
        int i, max;
 
        for (i = 0; i < RANKS; ++i)
-               if (userasked[i] &&
-                   comphand[i] > 0 && comphand[i] < CARDS) {
+               if (userasked[i] && comphand[i] > 0 && comphand[i] < CARDS) {
                        userasked[i] = 0;
                        return(i);
                }
@@ -228,8 +223,7 @@ promove()
                                break;
                        }
                while (++i < RANKS)
-                       if (comphand[i] != CARDS &&
-                           comphand[i] > comphand[max])
+                       if (comphand[i] != CARDS && comphand[i] > comphand[max])
                                max = i;
                return(max);
        }
@@ -240,8 +234,7 @@ promove()
        }
        for (;;) {
                for (i = 0; i < RANKS; ++i)
-                       if (comphand[i] && comphand[i] != CARDS &&
-                           !asked[i])
+                       if (comphand[i] && comphand[i] != CARDS && !asked[i])
                                return(i);
                for (i = 0; i < RANKS; ++i)
                        asked[i] = 0;
@@ -249,10 +242,8 @@ promove()
        /* NOTREACHED */
 }
 
-int
-drawcard(player, hand)
-       int player;
-       int *hand;
+static int
+drawcard(int player, int *hand)
 {
        int card;
 
@@ -261,41 +252,36 @@ drawcard(player, hand)
        --deck[card];
        if (player == USER || hand[card] == CARDS) {
                printplayer(player);
-               (void)printf("drew %s", cards[card]);
+               printf("drew %s", cards[card]);
                if (hand[card] == CARDS) {
-                       (void)printf(" and made a book of %s's!\n",
-                            cards[card]);
+                       printf(" and made a book of %s's!\n", cards[card]);
                        chkwinner(player, hand);
                } else
-                       (void)printf(".\n");
+                       printf(".\n");
        }
        return(card);
 }
 
-int
-gofish(askedfor, player, hand)
-       int askedfor, player;
-       int *hand;
+static int
+gofish(int askedfor, int player, int *hand)
 {
        printplayer(OTHER(player));
-       (void)printf("say \"GO FISH!\"\n");
+       printf("say \"GO FISH!\"\n");
        if (askedfor == drawcard(player, hand)) {
                printplayer(player);
-               (void)printf("drew the guess!\n");
+               printf("drew the guess!\n");
                printplayer(player);
-               (void)printf("get to ask again!\n");
+               printf("get to ask again!\n");
                return(1);
        }
        return(0);
 }
 
-void
-goodmove(player, move, hand, opphand)
-       int player, move;
-       int *hand, *opphand;
+static void
+goodmove(int player, int move, int *hand, int *opphand)
 {
        printplayer(OTHER(player));
-       (void)printf("have %d %s%s.\n",
+       printf("have %d %s%s.\n",
            opphand[move], cards[move], opphand[move] == 1 ? "": "'s");
 
        hand[move] += opphand[move];
@@ -303,20 +289,18 @@ goodmove(player, move, hand, opphand)
 
        if (hand[move] == CARDS) {
                printplayer(player);
-               (void)printf("made a book of %s's!\n", cards[move]);
+               printf("made a book of %s's!\n", cards[move]);
                chkwinner(player, hand);
        }
 
        chkwinner(OTHER(player), opphand);
 
        printplayer(player);
-       (void)printf("get another guess!\n");
+       printf("get another guess!\n");
 }
 
-void
-chkwinner(player, hand)
-       int player;
-       int *hand;
+static void
+chkwinner(int player, int *hand)
 {
        int cb, i, ub;
 
@@ -324,42 +308,40 @@ chkwinner(player, hand)
                if (hand[i] > 0 && hand[i] < CARDS)
                        return;
        printplayer(player);
-       (void)printf("don't have any more cards!\n");
-       (void)printf("My books:");
+       printf("don't have any more cards!\n");
+       printf("My books:");
        cb = countbooks(comphand);
-       (void)printf("Your books:");
+       printf("Your books:");
        ub = countbooks(userhand);
-       (void)printf("\nI have %d, you have %d.\n", cb, ub);
+       printf("\nI have %d, you have %d.\n", cb, ub);
        if (ub > cb) {
-               (void)printf("\nYou win!!!\n");
+               printf("\nYou win!!!\n");
                if (nrandom(1024) == 0723)
-                       (void)printf("Cheater, cheater, pumpkin eater!\n");
+                       printf("Cheater, cheater, pumpkin eater!\n");
        } else if (cb > ub) {
-               (void)printf("\nI win!!!\n");
+               printf("\nI win!!!\n");
                if (nrandom(1024) == 0723)
-                       (void)printf("Hah!  Stupid peasant!\n");
+                       printf("Hah!  Stupid peasant!\n");
        } else
-               (void)printf("\nTie!\n");
+               printf("\nTie!\n");
        exit(0);
 }
 
-void
-printplayer(player)
-       int player;
+static void
+printplayer(int player)
 {
        switch (player) {
        case COMPUTER:
-               (void)printf("I ");
+               printf("I ");
                break;
        case USER:
-               (void)printf("You ");
+               printf("You ");
                break;
        }
 }
 
-void
-printhand(hand)
-       int *hand;
+static void
+printhand(int *hand)
 {
        int book, i, j;
 
@@ -370,17 +352,16 @@ printhand(hand)
                else
                        ++book;
        if (book) {
-               (void)printf(" + Book%s of", book > 1 ? "s" : "");
+               printf(" + Book%s of", book > 1 ? "s" : "");
                for (i = 0; i < RANKS; i++)
                        if (hand[i] == CARDS)
                                PRC(i);
        }
-       (void)putchar('\n');
+       putchar('\n');
 }
 
-int
-countcards(hand)
-       int *hand;
+static int
+countcards(int *hand)
 {
        int i, count;
 
@@ -389,9 +370,8 @@ countcards(hand)
        return(count);
 }
 
-int
-countbooks(hand)
-       int *hand;
+static int
+countbooks(int *hand)
 {
        int i, count;
 
@@ -401,13 +381,13 @@ countbooks(hand)
                        PRC(i);
                }
        if (!count)
-               (void)printf(" none");
-       (void)putchar('\n');
+               printf(" none");
+       putchar('\n');
        return(count);
 }
 
-void
-init()
+static void
+init(void)
 {
        int i, rank;
 
@@ -425,35 +405,34 @@ init()
        }
 }
 
-int
-nrandom(n)
-       int n;
+static int
+nrandom(int n)
 {
 
        return((int)random() % n);
 }
 
-void
-instructions()
+static void
+instructions(void)
 {
        int input;
        char buf[1024];
 
-       (void)printf("Would you like instructions (y or n)? ");
+       printf("Would you like instructions (y or n)? ");
        input = getchar();
        while (getchar() != '\n');
        if (input != 'y')
                return;
 
-       (void)sprintf(buf, "%s %s", _PATH_MORE, _PATH_INSTR);
-       (void)system(buf);
-       (void)printf("Hit return to continue...\n");
+       sprintf(buf, "%s %s", _PATH_MORE, _PATH_INSTR);
+       system(buf);
+       printf("Hit return to continue...\n");
        while ((input = getchar()) != EOF && input != '\n');
 }
 
-void
-usage()
+static void
+usage(void)
 {
-       (void)fprintf(stderr, "usage: fish [-p]\n");
+       fprintf(stderr, "usage: fish [-p]\n");
        exit(1);
 }