From: Eirik Nygaard Date: Wed, 3 Aug 2005 13:31:00 +0000 (+0000) Subject: Remove libraries libtermcap and libcompat from the linking. X-Git-Tag: v2.0.1~6383 X-Git-Url: https://gitweb.dragonflybsd.org/~uqs/games.git/commitdiff_plain/413c680627bdc324705d56537f6dfffd09f386c1 Remove libraries libtermcap and libcompat from the linking. style(9) cleanup WARNS?= 6 cleanup Use true, false and bool from stdbool.h instead of hand rolled versions. Submitted by: Peter Avalos Add DragonFly keywords. --- diff --git a/games/cribbage/Makefile b/games/cribbage/Makefile index f270a4aaae..7263a864e0 100644 --- a/games/cribbage/Makefile +++ b/games/cribbage/Makefile @@ -1,15 +1,16 @@ # @(#)Makefile 8.1 (Berkeley) 5/31/93 # $FreeBSD: src/games/cribbage/Makefile,v 1.7.2.5 2002/08/07 16:31:41 ru Exp $ -# $DragonFly: src/games/cribbage/Makefile,v 1.2 2003/06/17 04:25:23 dillon Exp $ +# $DragonFly: src/games/cribbage/Makefile,v 1.3 2005/08/03 13:31:00 eirikn Exp $ PROG= cribbage -DPADD= ${LIBCURSES} ${LIBTERMCAP} ${LIBCOMPAT} -LDADD= -lcurses -ltermcap -lcompat +DPADD= ${LIBCURSES} +LDADD= -lcurses SRCS= extern.c crib.c cards.c instr.c io.c score.c support.c FILES= cribbage.n FILESNAME_cribbage.n= cribbage.instr MAN= cribbage.6 HIDEGAME=hidegame +WARNS?= 6 beforeinstall: .if !exists(${DESTDIR}/var/games/criblog) diff --git a/games/cribbage/cards.c b/games/cribbage/cards.c index 34f32bb030..0411810423 100644 --- a/games/cribbage/cards.c +++ b/games/cribbage/cards.c @@ -32,24 +32,19 @@ * * @(#)cards.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/cribbage/cards.c,v 1.5 1999/11/30 03:48:44 billf Exp $ - * $DragonFly: src/games/cribbage/cards.c,v 1.2 2003/06/17 04:25:23 dillon Exp $ + * $DragonFly: src/games/cribbage/cards.c,v 1.3 2005/08/03 13:31:00 eirikn Exp $ */ -#include -#include #include -#include -#include "deck.h" #include "cribbage.h" - +static bool eq(CARD, CARD); /* * Initialize a deck of cards to contain one of each type. */ void -makedeck(d) - CARD d[]; +makedeck(CARD d[]) { int i, j, k; @@ -67,8 +62,7 @@ makedeck(d) * see Knuth, vol. 2, page 125. */ void -shuffle(d) - CARD d[]; +shuffle(CARD d[]) { int j, k; CARD c; @@ -84,9 +78,8 @@ shuffle(d) /* * return true if the two cards are equal... */ -int -eq(a, b) - CARD a, b; +static bool +eq(CARD a, CARD b) { return ((a.rank == b.rank) && (a.suit == b.suit)); } @@ -94,26 +87,22 @@ eq(a, b) /* * isone returns TRUE if a is in the set of cards b */ -int -isone(a, b, n) - CARD a, b[]; - int n; +bool +isone(CARD a, CARD b[], int n) { int i; for (i = 0; i < n; i++) if (eq(a, b[i])) - return (TRUE); - return (FALSE); + return (true); + return (false); } /* * remove the card a from the deck d of n cards */ void -cremove(a, d, n) - CARD a, d[]; - int n; +cremove(CARD a, CARD d[], int n) { int i, j; @@ -129,9 +118,7 @@ cremove(a, d, n) * Sort a hand of n cards */ void -sorthand(h, n) - CARD h[]; - int n; +sorthand(CARD h[], int n) { CARD *cp, *endp; CARD c; diff --git a/games/cribbage/crib.c b/games/cribbage/crib.c index adedd47b9e..dd4481dcf6 100644 --- a/games/cribbage/crib.c +++ b/games/cribbage/crib.c @@ -33,27 +33,34 @@ * @(#) Copyright (c) 1980, 1993 The Regents of the University of California. All rights reserved. * @(#)crib.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/cribbage/crib.c,v 1.10 1999/12/12 03:04:14 billf Exp $ - * $DragonFly: src/games/cribbage/crib.c,v 1.2 2003/06/17 04:25:23 dillon Exp $ + * $DragonFly: src/games/cribbage/crib.c,v 1.3 2005/08/03 13:31:00 eirikn Exp $ */ -#include #include #include -#include #include #include -#include "deck.h" #include "cribbage.h" #include "cribcur.h" #include "pathnames.h" +static bool cut(bool, int); +static int deal(bool); +static void discard(bool); +static void game(void); +static void gamescore(void); +static void makeboard(void); +static bool peg(bool); +static bool playhand(bool); +static void prcrib(bool, bool); +static void prtable(int); +static bool scoreh(bool); + int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { - BOOLEAN playing; + bool playing; FILE *f; int ch; @@ -65,22 +72,22 @@ main(argc, argv) while ((ch = getopt(argc, argv, "eqr")) != -1) switch (ch) { case 'e': - explain = TRUE; + explain = true; break; case 'q': - quiet = TRUE; + quiet = true; break; case 'r': - rflag = TRUE; + rflag = true; break; case '?': default: - (void) fprintf(stderr, "usage: cribbage [-eqr]\n"); + fprintf(stderr, "usage: cribbage [-eqr]\n"); exit(1); } initscr(); - (void)signal(SIGINT, rint); + signal(SIGINT, intr); crmode(); noecho(); @@ -108,7 +115,7 @@ main(argc, argv) msg("For cribbage rules, use \"man cribbage\""); } } - playing = TRUE; + playing = true; do { wclrtobot(Msgwin); msg(quiet ? "L or S? " : "Long (to 121) or Short (to 61)? "); @@ -122,25 +129,24 @@ main(argc, argv) } while (playing); if (f != NULL) { - (void)fprintf(f, "%s: won %5.5d, lost %5.5d\n", + fprintf(f, "%s: won %5.5d, lost %5.5d\n", getlogin(), cgames, pgames); - (void) fclose(f); + fclose(f); } bye(); if (!f) { - (void) fprintf(stderr, "\ncribbage: can't open %s.\n", - _PATH_LOG); + fprintf(stderr, "\ncribbage: can't open %s.\n", _PATH_LOG); exit(1); } - exit(0); + return(0); } /* * makeboard: * Print out the initial board on the screen */ -void -makeboard() +static void +makeboard(void) { mvaddstr(SCORE_Y + 0, SCORE_X, "+---------------------------------------+"); @@ -167,8 +173,8 @@ makeboard() * gamescore: * Print out the current game score */ -void -gamescore() +static void +gamescore(void) { if (pgames || cgames) { @@ -184,18 +190,17 @@ gamescore() * Play one game up to glimit points. Actually, we only ASK the * player what card to turn. We do a random one, anyway. */ -void -game() +static void +game(void) { int i, j; - BOOLEAN flag; - BOOLEAN compcrib; + bool flag, compcrib; - compcrib = FALSE; + compcrib = false; makedeck(deck); shuffle(deck); if (gamecount == 0) { - flag = TRUE; + flag = true; do { if (!rflag) { /* player cuts deck */ msg(quiet ? "Cut for crib? " : @@ -207,10 +212,10 @@ game() j = random() % CARDS; } while (j == i); addmsg(quiet ? "You cut " : "You cut the "); - msgcard(deck[i], FALSE); + msgcard(deck[i], false); endmsg(); addmsg(quiet ? "I cut " : "I cut the "); - msgcard(deck[j], FALSE); + msgcard(deck[j], false); endmsg(); flag = (deck[i].rank == deck[j].rank); if (flag) { @@ -234,7 +239,7 @@ game() } pscore = cscore = 0; - flag = TRUE; + flag = true; do { shuffle(deck); flag = !playhand(compcrib); @@ -253,7 +258,7 @@ game() msg("YOU WON!"); ++pgames; } - iwon = FALSE; + iwon = false; } else { if (glimit - pscore > 60) { msg("I DOUBLE SKUNKED YOU!"); @@ -266,7 +271,7 @@ game() msg("I WON!"); ++cgames; } - iwon = TRUE; + iwon = true; } gamescore(); } @@ -275,9 +280,8 @@ game() * playhand: * Do up one hand of the game */ -int -playhand(mycrib) - BOOLEAN mycrib; +static bool +playhand(bool mycrib) { int deckpos; @@ -288,25 +292,24 @@ playhand(mycrib) sorthand(chand, FULLHAND); sorthand(phand, FULLHAND); makeknown(chand, FULLHAND); - prhand(phand, FULLHAND, Playwin, FALSE); + prhand(phand, FULLHAND, Playwin, false); discard(mycrib); if (cut(mycrib, deckpos)) - return TRUE; + return true; if (peg(mycrib)) - return TRUE; + return true; werase(Tablewin); wrefresh(Tablewin); - if (score(mycrib)) - return TRUE; - return FALSE; + if (scoreh(mycrib)) + return true; + return false; } /* * deal cards to both players from deck */ -int -deal(mycrib) - BOOLEAN mycrib; +static int +deal(bool mycrib) { int i, j; @@ -325,27 +328,26 @@ deal(mycrib) /* * discard: * Handle players discarding into the crib... - * Note: we call cdiscard() after prining first message so player doesn't wait + * Note: we call cdiscard() after printing first message so player doesn't wait */ -void -discard(mycrib) - BOOLEAN mycrib; +static void +discard(bool mycrib) { - char *prompt; + const char *prompt; CARD crd; - prcrib(mycrib, TRUE); + prcrib(mycrib, true); prompt = (quiet ? "Discard --> " : "Discard a card --> "); cdiscard(mycrib); /* puts best discard at end */ crd = phand[infrom(phand, FULLHAND, prompt)]; cremove(crd, phand, FULLHAND); - prhand(phand, FULLHAND, Playwin, FALSE); + prhand(phand, FULLHAND, Playwin, false); crib[0] = crd; /* Next four lines same as last four except for cdiscard(). */ crd = phand[infrom(phand, FULLHAND - 1, prompt)]; cremove(crd, phand, FULLHAND - 1); - prhand(phand, FULLHAND, Playwin, FALSE); + prhand(phand, FULLHAND, Playwin, false); crib[1] = crd; crib[2] = chand[4]; crib[3] = chand[5]; @@ -357,15 +359,13 @@ discard(mycrib) * Cut the deck and set turnover. Actually, we only ASK the * player what card to turn. We do a random one, anyway. */ -int -cut(mycrib, pos) - BOOLEAN mycrib; - int pos; +static bool +cut(bool mycrib, int pos) { int i; - BOOLEAN win; + bool win; - win = FALSE; + win = false; if (mycrib) { if (!rflag) { /* random cut */ msg(quiet ? "Cut the deck? " : @@ -375,7 +375,7 @@ cut(mycrib, pos) i = random() % (CARDS - pos); turnover = deck[i + pos]; addmsg(quiet ? "You cut " : "You cut the "); - msgcard(turnover, FALSE); + msgcard(turnover, false); endmsg(); if (turnover.rank == JACK) { msg("I get two for his heels"); @@ -385,7 +385,7 @@ cut(mycrib, pos) i = random() % (CARDS - pos) + pos; turnover = deck[i]; addmsg(quiet ? "I cut " : "I cut the "); - msgcard(turnover, FALSE); + msgcard(turnover, false); endmsg(); if (turnover.rank == JACK) { msg("You get two for his heels"); @@ -393,7 +393,7 @@ cut(mycrib, pos) } } makeknown(&turnover, 1); - prcrib(mycrib, FALSE); + prcrib(mycrib, false); return (win); } @@ -401,9 +401,8 @@ cut(mycrib, pos) * prcrib: * Print out the turnover card with crib indicator */ -void -prcrib(mycrib, blank) - BOOLEAN mycrib, blank; +static void +prcrib(bool mycrib, bool blank) { int y, cardx; @@ -431,15 +430,14 @@ prcrib(mycrib, blank) static CARD Table[14]; static int Tcnt; -int -peg(mycrib) - BOOLEAN mycrib; +static bool +peg(bool mycrib) { static CARD ch[CINHAND], ph[CINHAND]; int i, j, k; int l; int cnum, pnum, sum; - BOOLEAN myturn, mego, ugo, last, played; + bool myturn, mego, ugo, last, played; CARD crd; cnum = pnum = CINHAND; @@ -449,18 +447,18 @@ peg(mycrib) } Tcnt = 0; /* index to table of cards played */ sum = 0; /* sum of cards played */ - played = mego = ugo = FALSE; + played = mego = ugo = false; myturn = !mycrib; for (;;) { - last = TRUE; /* enable last flag */ - prhand(ph, pnum, Playwin, FALSE); - prhand(ch, cnum, Compwin, TRUE); + last = true; /* enable last flag */ + prhand(ph, pnum, Playwin, false); + prhand(ch, cnum, Compwin, true); prtable(sum); if (myturn) { /* my tyrn to play */ if (!anymove(ch, cnum, sum)) { /* if no card to play */ if (!mego && cnum) { /* go for comp? */ msg("GO"); - mego = TRUE; + mego = true; } /* can player move? */ if (anymove(ph, pnum, sum)) @@ -469,13 +467,13 @@ peg(mycrib) msg(quiet ? "You get one" : "You get one point"); if (chkscr(&pscore, 1)) - return TRUE; + return (true); sum = 0; - mego = ugo = FALSE; + mego = ugo = false; Tcnt = 0; } } else { - played = TRUE; + played = true; j = -1; k = 0; /* maximize score */ @@ -495,10 +493,10 @@ peg(mycrib) if (k > 0) { addmsg(quiet ? "I get %d playing " : "I get %d points playing ", k); - msgcard(crd, FALSE); + msgcard(crd, false); endmsg(); if (chkscr(&cscore, k)) - return TRUE; + return (true); } myturn = !myturn; } @@ -506,7 +504,7 @@ peg(mycrib) if (!anymove(ph, pnum, sum)) { /* can player move? */ if (!ugo && pnum) { /* go for player */ msg("You have a GO"); - ugo = TRUE; + ugo = true; } /* can computer play? */ if (anymove(ch, cnum, sum)) @@ -516,20 +514,20 @@ peg(mycrib) "I get one point"); do_wait(); if (chkscr(&cscore, 1)) - return TRUE; + return (true); sum = 0; - mego = ugo = FALSE; + mego = ugo = false; Tcnt = 0; } } else { /* player plays */ - played = FALSE; + played = false; if (pnum == 1) { crd = ph[0]; msg("You play your last card"); } else for (;;) { prhand(ph, - pnum, Playwin, FALSE); + pnum, Playwin, false); crd = ph[infrom(ph, pnum, "Your play: ")]; if (sum + VAL(crd.rank) <= 31) @@ -546,7 +544,7 @@ peg(mycrib) msg(quiet ? "You got %d" : "You got %d points", i); if (chkscr(&pscore, i)) - return TRUE; + return (true); } myturn = !myturn; } @@ -555,15 +553,15 @@ peg(mycrib) if (!myturn) do_wait(); sum = 0; - mego = ugo = FALSE; + mego = ugo = false; Tcnt = 0; - last = FALSE; /* disable last flag */ + last = false; /* disable last flag */ } if (!pnum && !cnum) break; /* both done */ } - prhand(ph, pnum, Playwin, FALSE); - prhand(ch, cnum, Compwin, TRUE); + prhand(ph, pnum, Playwin, false); + prhand(ch, cnum, Compwin, true); prtable(sum); if (last) { if (played) { @@ -571,54 +569,52 @@ peg(mycrib) "I get one point for last"); do_wait(); if (chkscr(&cscore, 1)) - return TRUE; + return (true); } else { msg(quiet ? "You get one for last" : "You get one point for last"); if (chkscr(&pscore, 1)) - return TRUE; + return (true); } } - return (FALSE); + return (false); } /* * prtable: * Print out the table with the current score */ -void -prtable(score) - int score; +static void +prtable(int score) { - prhand(Table, Tcnt, Tablewin, FALSE); + prhand(Table, Tcnt, Tablewin, false); mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", score); wrefresh(Tablewin); } /* - * score: + * scoreh: * Handle the scoring of the hands */ -int -score(mycrib) - BOOLEAN mycrib; +static bool +scoreh(bool mycrib) { sorthand(crib, CINHAND); if (mycrib) { if (plyrhand(phand, "hand")) - return (TRUE); + return (true); if (comphand(chand, "hand")) - return (TRUE); + return (true); do_wait(); if (comphand(crib, "crib")) - return (TRUE); + return (true); } else { if (comphand(chand, "hand")) - return (TRUE); + return (true); if (plyrhand(phand, "hand")) - return (TRUE); + return (true); if (plyrhand(crib, "crib")) - return (TRUE); + return (true); } - return (FALSE); + return (false); } diff --git a/games/cribbage/cribbage.h b/games/cribbage/cribbage.h index e534ce623a..eebddf2e08 100644 --- a/games/cribbage/cribbage.h +++ b/games/cribbage/cribbage.h @@ -31,9 +31,13 @@ * SUCH DAMAGE. * * @(#)cribbage.h 8.1 (Berkeley) 5/31/93 - * $DragonFly: src/games/cribbage/cribbage.h,v 1.2 2003/11/12 14:53:52 eirikn Exp $ + * $DragonFly: src/games/cribbage/cribbage.h,v 1.3 2005/08/03 13:31:00 eirikn Exp $ */ +#include + +#include "deck.h" + extern CARD deck[ CARDS ]; /* a deck */ extern CARD phand[ FULLHAND ]; /* player's hand */ extern CARD chand[ FULLHAND ]; /* computer's hand */ @@ -52,62 +56,39 @@ extern int cgames; /* comp's games won */ extern int gamecount; /* # games played */ extern int Lastscore[2]; /* previous score for each */ -extern BOOLEAN iwon; /* if comp won last */ -extern BOOLEAN explain; /* player mistakes explained */ -extern BOOLEAN rflag; /* if all cuts random */ -extern BOOLEAN quiet; /* if suppress random mess */ -extern BOOLEAN playing; /* currently playing game */ +extern bool iwon; /* if comp won last */ +extern bool explain; /* player mistakes explained */ +extern bool rflag; /* if all cuts random */ +extern bool quiet; /* if suppress random mess */ -extern char expl[]; /* string for explanation */ +extern char explstr[]; /* string for explanation */ void addmsg (const char *, ...); -int adjust (CARD [], CARD); -int anymove (CARD [], int, int); -int anysumto (CARD [], int, int, int); +int adjust (CARD []); +bool anymove (CARD [], int, int); void bye (void); int cchose (CARD [], int, int); -void cdiscard (BOOLEAN); -int chkscr (int *, int); -int comphand (CARD [], char *); +void cdiscard (bool); +bool chkscr (int *, int); +bool comphand (CARD [], const char *); void cremove (CARD, CARD [], int); -int cut (BOOLEAN, int); -int deal (int); -void discard (BOOLEAN); void do_wait (void); void endmsg (void); -int eq (CARD, CARD); -int fifteens (CARD [], int); -void game (void); -void gamescore (void); char *getline (void); int getuchar (void); -int incard (CARD *); -int infrom (CARD [], int, char *); +int infrom (CARD [], int, const char *); void instructions (void); -int isone (CARD, CARD [], int); -void makeboard (void); +void intr (int); +bool isone (CARD, CARD [], int); void makedeck (CARD []); void makeknown (CARD [], int); void msg (const char *, ...); -int msgcard (CARD, BOOLEAN); -int msgcrd (CARD, BOOLEAN, char *, BOOLEAN); -int number (int, int, char *); -int numofval (CARD [], int, int); -int pairuns (CARD [], int); -int peg (BOOLEAN); +bool msgcard (CARD, bool); +int number (int, int, const char *); int pegscore (CARD, CARD [], int, int); -int playhand (BOOLEAN); -int plyrhand (CARD [], char *); -void prcard (WINDOW *, int, int, CARD, BOOLEAN); -void prcrib (BOOLEAN, BOOLEAN); -void prhand (CARD [], int, WINDOW *, BOOLEAN); -void printcard (WINDOW *, int, CARD, BOOLEAN); -void prpeg (int, int, BOOLEAN); -void prtable (int); -int readchar (void); -void rint (int); -int score (BOOLEAN); -int scorehand (CARD [], CARD, int, BOOLEAN, BOOLEAN); +bool plyrhand (CARD [], const char *); +void prcard (WINDOW *, int, int, CARD, bool); +void prhand (CARD [], int, WINDOW *, bool); +int scorehand (CARD [], CARD, int, bool, bool); void shuffle (CARD []); void sorthand (CARD [], int); -void wait_for (int); diff --git a/games/cribbage/cribcur.h b/games/cribbage/cribcur.h index 5e8bfd408e..e1ad69adbf 100644 --- a/games/cribbage/cribcur.h +++ b/games/cribbage/cribcur.h @@ -31,8 +31,11 @@ * SUCH DAMAGE. * * @(#)cribcur.h 8.1 (Berkeley) 5/31/93 + * $DragonFly: src/games/cribbage/cribcur.h,v 1.2 2005/08/03 13:31:00 eirikn Exp $ */ +#include + # define PLAY_Y 15 /* size of player's hand window */ # define PLAY_X 12 # define TABLE_Y 21 /* size of table window */ diff --git a/games/cribbage/deck.h b/games/cribbage/deck.h index 60a307d474..dc8bbd6f09 100644 --- a/games/cribbage/deck.h +++ b/games/cribbage/deck.h @@ -31,6 +31,7 @@ * SUCH DAMAGE. * * @(#)deck.h 8.1 (Berkeley) 5/31/93 + * $DragonFly: src/games/cribbage/deck.h,v 1.2 2005/08/03 13:31:00 eirikn Exp $ */ /* @@ -71,15 +72,7 @@ #define VAL(c) ( (c) < 9 ? (c)+1 : 10 ) /* val of rank */ -#ifndef TRUE -# define TRUE 1 -# define FALSE 0 -#endif - typedef struct { int rank; int suit; } CARD; - -typedef char BOOLEAN; - diff --git a/games/cribbage/extern.c b/games/cribbage/extern.c index 681ff92e2c..206c508486 100644 --- a/games/cribbage/extern.c +++ b/games/cribbage/extern.c @@ -32,20 +32,17 @@ * * @(#)extern.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/cribbage/extern.c,v 1.2 1999/11/30 03:48:45 billf Exp $ - * $DragonFly: src/games/cribbage/extern.c,v 1.3 2005/03/02 16:14:03 eirikn Exp $ + * $DragonFly: src/games/cribbage/extern.c,v 1.4 2005/08/03 13:31:00 eirikn Exp $ */ -#include - -#include "deck.h" #include "cribbage.h" -BOOLEAN explain = FALSE; /* player mistakes explained */ -BOOLEAN iwon = FALSE; /* if comp won last game */ -BOOLEAN quiet = FALSE; /* if suppress random mess */ -BOOLEAN rflag = FALSE; /* if all cuts random */ +bool explain = false; /* player mistakes explained */ +bool iwon = false; /* if comp won last game */ +bool quiet = false; /* if suppress random mess */ +bool rflag = false; /* if all cuts random */ -char expl[128]; /* explanation */ +char explstr[128]; /* explanation */ int cgames = 0; /* number games comp won */ int cscore = 0; /* comp score in this game */ diff --git a/games/cribbage/instr.c b/games/cribbage/instr.c index 466b69a99e..7c6682adf9 100644 --- a/games/cribbage/instr.c +++ b/games/cribbage/instr.c @@ -32,40 +32,37 @@ * * @(#)instr.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/cribbage/instr.c,v 1.5 1999/12/12 03:04:15 billf Exp $ - * $DragonFly: src/games/cribbage/instr.c,v 1.2 2003/06/17 04:25:23 dillon Exp $ + * $DragonFly: src/games/cribbage/instr.c,v 1.3 2005/08/03 13:31:00 eirikn Exp $ */ -#include #include -#include #include -#include +#include #include #include #include #include -#include "deck.h" #include "cribbage.h" #include "pathnames.h" void -instructions() +instructions(void) { struct stat sb; union wait pstat; pid_t pid; - char *pager, *path; + const char *pager, *path; if (stat(_PATH_INSTR, &sb)) { - (void)fprintf(stderr, "cribbage: %s: %s.\n", _PATH_INSTR, + fprintf(stderr, "cribbage: %s: %s.\n", _PATH_INSTR, strerror(errno)); exit(1); } switch (pid = vfork()) { case -1: - (void)fprintf(stderr, "cribbage: %s.\n", strerror(errno)); + fprintf(stderr, "cribbage: %s.\n", strerror(errno)); exit(1); case 0: if (!(path = getenv("PAGER"))) @@ -73,8 +70,8 @@ instructions() if ((pager = rindex(path, '/')) != NULL) ++pager; pager = path; - execlp(path, pager, _PATH_INSTR, (char *)NULL); - (void)fprintf(stderr, "cribbage: %s.\n", strerror(errno)); + execlp(path, pager, _PATH_INSTR, NULL); + fprintf(stderr, "cribbage: %s.\n", strerror(errno)); _exit(1); default: do { diff --git a/games/cribbage/io.c b/games/cribbage/io.c index c6e2fab054..f8fe369439 100644 --- a/games/cribbage/io.c +++ b/games/cribbage/io.c @@ -32,20 +32,16 @@ * * @(#)io.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/cribbage/io.c,v 1.5.2.2 2001/02/18 02:20:31 kris Exp $ - * $DragonFly: src/games/cribbage/io.c,v 1.3 2004/07/27 07:37:39 asmodai Exp $ + * $DragonFly: src/games/cribbage/io.c,v 1.4 2005/08/03 13:31:00 eirikn Exp $ */ #include -#include #include +#include #include #include -#include #include -#include - -#include "deck.h" #include "cribbage.h" #include "cribcur.h" @@ -58,46 +54,47 @@ char linebuf[LINESIZE]; -char *rankname[RANKS] = { +const char *const rankname[RANKS] = { "ACE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING" }; -char *rankchar[RANKS] = { +const char *const rankchar[RANKS] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K" }; -char *suitname[SUITS] = {"SPADES", "HEARTS", "DIAMONDS", "CLUBS"}; +const char *const suitname[SUITS] = {"SPADES", "HEARTS", "DIAMONDS", "CLUBS"}; + +const char *const suitchar[SUITS] = {"S", "H", "D", "C"}; -char *suitchar[SUITS] = {"S", "H", "D", "C"}; +static bool incard(CARD *); +static bool msgcrd(CARD, bool, const char *, bool); +static void printcard(WINDOW *, int, CARD, bool); +static int readchar(void); +static void wait_for(int); /* * msgcard: * Call msgcrd in one of two forms */ -int -msgcard(c, brief) - CARD c; - BOOLEAN brief; +bool +msgcard(CARD c, bool brief) { if (brief) - return (msgcrd(c, TRUE, NULL, TRUE)); + return (msgcrd(c, true, NULL, true)); else - return (msgcrd(c, FALSE, " of ", FALSE)); + return (msgcrd(c, false, " of ", false)); } /* * msgcrd: * Print the value of a card in ascii */ -int -msgcrd(c, brfrank, mid, brfsuit) - CARD c; - BOOLEAN brfrank, brfsuit; - char *mid; +static bool +msgcrd(CARD c, bool brfrank, const char *mid, bool brfsuit) { if (c.rank == EMPTY || c.suit == EMPTY) - return (FALSE); + return (false); if (brfrank) addmsg("%1.1s", rankchar[c.rank]); else @@ -108,19 +105,15 @@ msgcrd(c, brfrank, mid, brfsuit) addmsg("%1.1s", suitchar[c.suit]); else addmsg("%s", suitname[c.suit]); - return (TRUE); + return (true); } /* * printcard: * Print out a card. */ -void -printcard(win, cardno, c, blank) - WINDOW *win; - int cardno; - CARD c; - BOOLEAN blank; +static void +printcard(WINDOW *win, int cardno, CARD c, bool blank) { prcard(win, cardno * 2, cardno, c, blank); } @@ -130,11 +123,7 @@ printcard(win, cardno, c, blank) * Print out a card on the window at the specified location */ void -prcard(win, y, x, c, blank) - WINDOW *win; - int y, x; - CARD c; - BOOLEAN blank; +prcard(WINDOW *win, int y, int x, CARD c, bool blank) { if (c.rank == EMPTY) return; @@ -157,11 +146,7 @@ prcard(win, y, x, c, blank) * Print a hand of n cards */ void -prhand(h, n, win, blank) - CARD h[]; - int n; - WINDOW *win; - BOOLEAN blank; +prhand(CARD h[], int n, WINDOW *win, bool blank) { int i; @@ -173,14 +158,11 @@ prhand(h, n, win, blank) /* * infrom: - * reads a card, supposedly in hand, accepting unambigous brief + * reads a card, supposedly in hand, accepting unambiguous brief * input, returns the index of the card found... */ int -infrom(hand, n, prompt) - CARD hand[]; - int n; - char *prompt; +infrom(CARD hand[], int n, const char *prompt) { int i, j; CARD crd; @@ -232,16 +214,15 @@ infrom(hand, n, prompt) * Inputs a card in any format. It reads a line ending with a CR * and then parses it. */ -int -incard(crd) - CARD *crd; +static bool +incard(CARD *crd) { int i; int rnk, sut; char *line, *p, *p1; - BOOLEAN retval; + bool retval; - retval = FALSE; + retval = false; rnk = sut = EMPTY; if (!(line = getline())) goto gotit; @@ -272,7 +253,7 @@ incard(crd) } } if (sut != EMPTY) - retval = TRUE; + retval = true; goto gotit; } rnk = EMPTY; @@ -306,7 +287,7 @@ incard(crd) } } if (sut != EMPTY) - retval = TRUE; + retval = true; gotit: (*crd).rank = rnk; (*crd).suit = sut; @@ -318,7 +299,7 @@ gotit: * Reads and converts to upper case */ int -getuchar() +getuchar(void) { int c; @@ -335,9 +316,7 @@ getuchar() * "hi" inclusive. */ int -number(lo, hi, prompt) - int lo, hi; - char *prompt; +number(int lo, int hi, const char *prompt) { char *p; int sum; @@ -386,7 +365,7 @@ msg(const char *fmt, ...) va_list ap; va_start(ap, fmt); - (void)vsprintf(&Msgbuf[Newpos], fmt, ap); + vsprintf(&Msgbuf[Newpos], fmt, ap); va_end(ap); endmsg(); } @@ -401,7 +380,7 @@ addmsg(const char *fmt, ...) va_list ap; va_start(ap, fmt); - (void)vsprintf(&Msgbuf[Newpos], fmt, ap); + vsprintf(&Msgbuf[Newpos], fmt, ap); va_end(ap); } @@ -412,7 +391,7 @@ addmsg(const char *fmt, ...) int Lineno = 0; void -endmsg() +endmsg(void) { static int lastline = 0; int len; @@ -461,11 +440,11 @@ endmsg() * Wait for the user to type ' ' before doing anything else */ void -do_wait() +do_wait(void) { static char prompt[] = {'-', '-', 'M', 'o', 'r', 'e', '-', '-', '\0'}; - if (Mpos + sizeof prompt < MSG_X) + if (Mpos + (int)sizeof(prompt) < MSG_X) wmove(Msgwin, Lineno > 0 ? Lineno - 1 : MSG_Y - 1, Mpos); else { mvwaddch(Msgwin, Lineno, 0, ' '); @@ -482,9 +461,8 @@ do_wait() * wait_for * Sit around until the guy types the right key */ -void -wait_for(ch) - int ch; +static void +wait_for(int ch) { char c; @@ -500,8 +478,8 @@ wait_for(ch) * readchar: * Reads and returns a character, checking for gross input errors */ -int -readchar() +static int +readchar(void) { int cnt; char c; @@ -529,7 +507,7 @@ over: * compressed to one space; a space is inserted before a ',' */ char * -getline() +getline(void) { char *sp; int c, oy, ox; @@ -578,8 +556,7 @@ getline() } void -rint(signo) - int signo; +intr(__unused int signo) { bye(); exit(1); @@ -590,7 +567,7 @@ rint(signo) * Leave the program, cleaning things up as we go. */ void -bye() +bye(void) { signal(SIGINT, SIG_IGN); mvcur(0, COLS - 1, LINES - 1, 0); diff --git a/games/cribbage/score.c b/games/cribbage/score.c index 5ec4950ceb..ff12d61c63 100644 --- a/games/cribbage/score.c +++ b/games/cribbage/score.c @@ -32,24 +32,24 @@ * * @(#)score.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/cribbage/score.c,v 1.6 1999/11/30 03:48:47 billf Exp $ - * $DragonFly: src/games/cribbage/score.c,v 1.2 2003/06/17 04:25:23 dillon Exp $ + * $DragonFly: src/games/cribbage/score.c,v 1.3 2005/08/03 13:31:00 eirikn Exp $ */ -#include #include #include #include -#include "deck.h" #include "cribbage.h" +static int fifteens(CARD[], int); +static int pairuns(CARD[], int); /* * the following arrays give the sum of the scores of the (50 2)*48 = 58800 * hands obtainable for the crib given the two cards whose ranks index the * array. the two arrays are for the case where the suits are equal and * not equal respectively */ -long crbescr[169] = { +const long crbescr[169] = { -10000, 271827, 278883, 332319, 347769, 261129, 250653, 253203, 248259, 243435, 256275, 237435, 231051, -10000, -10000, 412815, 295707, 349497, 267519, 262521, 259695, 254019, 250047, 262887, 244047, 237663, -10000, @@ -71,7 +71,7 @@ long crbescr[169] = { -10000, -10000, -10000, -10000, -10000, -10000, -10000 }; -long crbnescr[169] = { +const long crbnescr[169] = { 325272, 260772, 267828, 321264, 336714, 250074, 239598, 242148, 237204, 232380, 246348, 226380, 219996, -10000, 342528, 401760, 284652, 338442, 256464, 251466, 248640, 242964, 238992, 252960, 232992, 226608, -10000, @@ -93,31 +93,28 @@ long crbnescr[169] = { -10000, -10000, -10000, -10000, -10000, -10000, 295896 }; -static int ichoose2[5] = { 0, 0, 2, 6, 12 }; +static const int ichoose2[5] = { 0, 0, 2, 6, 12 }; static int pairpoints, runpoints; /* Globals from pairuns. */ /* * scorehand: * Score the given hand of n cards and the starter card. * n must be <= 4 + * crb is true if scoring crib + * do_explain is true if must explain this hand */ int -scorehand(hand, starter, n, crb, do_explain) - CARD hand[]; - CARD starter; - int n; - BOOLEAN crb; /* true if scoring crib */ - BOOLEAN do_explain; /* true if must explain this hand */ +scorehand(CARD hand[], CARD starter, int n, bool crb, bool do_explain) { int i, k; int score; - BOOLEAN flag; + bool flag; CARD h[(CINHAND + 1)]; char buf[32]; - expl[0] = '\0'; /* initialize explanation */ + explstr[0] = '\0'; /* initialize explanation */ score = 0; - flag = TRUE; + flag = true; k = hand[0].suit; for (i = 0; i < n; i++) { /* check for flush */ flag = (flag && (hand[i].suit == k)); @@ -125,49 +122,49 @@ scorehand(hand, starter, n, crb, do_explain) if (hand[i].suit == starter.suit) { score++; if (do_explain) - strcat(expl, "His Nobs"); + strcat(explstr, "His Nobs"); } h[i] = hand[i]; } if (flag && n >= CINHAND) { - if (do_explain && expl[0] != '\0') - strcat(expl, ", "); + if (do_explain && explstr[0] != '\0') + strcat(explstr, ", "); if (starter.suit == k) { score += 5; if (do_explain) - strcat(expl, "Five-flush"); + strcat(explstr, "Five-flush"); } else if (!crb) { score += 4; - if (do_explain && expl[0] != '\0') - strcat(expl, ", Four-flush"); + if (do_explain && explstr[0] != '\0') + strcat(explstr, ", Four-flush"); else - strcpy(expl, "Four-flush"); + strcpy(explstr, "Four-flush"); } } - if (do_explain && expl[0] != '\0') - strcat(expl, ", "); + if (do_explain && explstr[0] != '\0') + strcat(explstr, ", "); h[n] = starter; sorthand(h, n + 1); /* sort by rank */ i = 2 * fifteens(h, n + 1); score += i; if (do_explain) { if (i > 0) { - (void) sprintf(buf, "%d points in fifteens", i); - strcat(expl, buf); + sprintf(buf, "%d points in fifteens", i); + strcat(explstr, buf); } else - strcat(expl, "No fifteens"); + strcat(explstr, "No fifteens"); } i = pairuns(h, n + 1); score += i; if (do_explain) { if (i > 0) { - (void) sprintf(buf, ", %d points in pairs, %d in runs", + sprintf(buf, ", %d points in pairs, %d in runs", pairpoints, runpoints); - strcat(expl, buf); + strcat(explstr, buf); } else - strcat(expl, ", No pairs/runs"); + strcat(explstr, ", No pairs/runs"); } return (score); } @@ -176,10 +173,8 @@ scorehand(hand, starter, n, crb, do_explain) * fifteens: * Return number of fifteens in hand of n cards */ -int -fifteens(hand, n) - CARD hand[]; - int n; +static int +fifteens(CARD hand[], int n) { int *sp, *np; int i; @@ -219,17 +214,15 @@ fifteens(hand, n) * this routine only works if n is strictly less than 6 * sets the globals pairpoints and runpoints appropriately */ -int -pairuns(h, n) - CARD h[]; - int n; +static int +pairuns(CARD h[], int n) { int i; int runlength, runmult, lastmult, curmult; int mult1, mult2, pair1, pair2; - BOOLEAN run; + bool run; - run = TRUE; + run = true; runlength = 1; mult1 = 1; pair1 = -1; @@ -265,7 +258,7 @@ pairuns(h, n) } else { /* only if old short */ if (runlength < 3) { - run = TRUE; + run = true; runlength = 2; runmult = 1; } @@ -275,7 +268,7 @@ pairuns(h, n) /* if just ended */ if (run) runmult *= lastmult; - run = FALSE; + run = false; } } } @@ -289,11 +282,9 @@ pairuns(h, n) * the n cards in tbl during pegging */ int -pegscore(crd, tbl, n, sum) - CARD crd, tbl[]; - int n, sum; +pegscore(CARD crd, CARD tbl[], int n, int sum) { - BOOLEAN got[RANKS]; + bool got[RANKS]; int i, j, scr; int k, lo, hi; @@ -315,13 +306,13 @@ pegscore(crd, tbl, n, sum) return (scr); lo = hi = crd.rank; for (i = 0; i < RANKS; i++) - got[i] = FALSE; - got[crd.rank] = TRUE; + got[i] = false; + got[crd.rank] = true; k = -1; for (i = n - 1; i >= 0; --i) { if (got[tbl[i].rank]) break; - got[tbl[i].rank] = TRUE; + got[tbl[i].rank] = true; if (tbl[i].rank < lo) lo = tbl[i].rank; if (tbl[i].rank > hi) @@ -344,8 +335,7 @@ pegscore(crd, tbl, n, sum) * points such a crib will get. */ int -adjust(cb, tnv) - CARD cb[], tnv; +adjust(CARD cb[]) { long scr; int i, c0, c1; diff --git a/games/cribbage/support.c b/games/cribbage/support.c index 214c6de04a..b8bca4d386 100644 --- a/games/cribbage/support.c +++ b/games/cribbage/support.c @@ -32,29 +32,30 @@ * * @(#)support.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/games/cribbage/support.c,v 1.5 1999/12/12 03:04:15 billf Exp $ - * $DragonFly: src/games/cribbage/support.c,v 1.2 2003/06/17 04:25:23 dillon Exp $ + * $DragonFly: src/games/cribbage/support.c,v 1.3 2005/08/03 13:31:00 eirikn Exp $ */ -#include +#include #include -#include "deck.h" #include "cribbage.h" #include "cribcur.h" +static int anysumto(CARD[], int, int, int); +static int numofval(CARD[], int, int); +static void prpeg(int, int, bool); + #define NTV 10 /* number scores to test */ /* score to test reachability of, and order to test them in */ -int tv[NTV] = {8, 7, 9, 6, 11, 12, 13, 14, 10, 5}; +const int tv[NTV] = {8, 7, 9, 6, 11, 12, 13, 14, 10, 5}; /* * computer chooses what to play in pegging... * only called if no playable card will score points */ int -cchose(h, n, s) - CARD h[]; - int n, s; +cchose(CARD h[], int n, int s) { int i, j, l; @@ -120,17 +121,15 @@ cchose(h, n, s) * plyrhand: * Evaluate and score a player hand or crib */ -int -plyrhand(hand, s) - CARD hand[]; - char *s; +bool +plyrhand(CARD hand[], const char *s) { static char prompt[BUFSIZ]; int i, j; - BOOLEAN win; + bool win; - prhand(hand, CINHAND, Playwin, FALSE); - (void) sprintf(prompt, "Your %s scores ", s); + prhand(hand, CINHAND, Playwin, false); + sprintf(prompt, "Your %s scores ", s); i = scorehand(hand, turnover, CINHAND, strcmp(s, "crib") == 0, explain); if ((j = number(0, 29, prompt)) == 19) j = 0; @@ -145,7 +144,7 @@ plyrhand(hand, s) msg("You should have taken %d, not %d!", i, j); } if (explain) - msg("Explanation: %s", expl); + msg("Explanation: %s", explstr); do_wait(); } else win = chkscr(&pscore, i); @@ -154,17 +153,15 @@ plyrhand(hand, s) /* * comphand: - * Handle scoring and displaying the computers hand + * Handle scoring and displaying the computer's hand */ -int -comphand(h, s) - CARD h[]; - char *s; +bool +comphand(CARD h[], const char *s) { int j; - j = scorehand(h, turnover, CINHAND, strcmp(s, "crib") == 0, FALSE); - prhand(h, CINHAND, Compwin, FALSE); + j = scorehand(h, turnover, CINHAND, strcmp(s, "crib") == 0, false); + prhand(h, CINHAND, Compwin, false); msg("My %s scores %d", s, (j == 0 ? 19 : j)); return (chkscr(&cscore, j)); } @@ -176,16 +173,15 @@ comphand(h, s) */ int Lastscore[2] = {-1, -1}; -int -chkscr(scr, inc) - int *scr, inc; +bool +chkscr(int *scr, int inc) { - BOOLEAN myturn; + bool myturn; myturn = (scr == &cscore); if (inc != 0) { - prpeg(Lastscore[myturn ? 1 : 0], '.', myturn); - Lastscore[myturn ? 1 : 0] = *scr; + prpeg(Lastscore[myturn], '.', myturn); + Lastscore[myturn] = *scr; *scr += inc; prpeg(*scr, PEG, myturn); refresh(); @@ -198,11 +194,8 @@ chkscr(scr, inc) * Put out the peg character on the score board and put the * score up on the board. */ -void -prpeg(score, peg, myturn) - int score; - int peg; - BOOLEAN myturn; +static void +prpeg(int score, int peg, bool myturn) { int y, x; @@ -238,8 +231,7 @@ prpeg(score, peg, myturn) * the crib and puts the best two cards at the end */ void -cdiscard(mycrib) - BOOLEAN mycrib; +cdiscard(bool mycrib) { CARD d[CARDS], h[FULLHAND], cb[2]; int i, j, k; @@ -266,11 +258,11 @@ cdiscard(mycrib) cremove(chand[j], h, FULLHAND - 1); for (k = 0; k < nc; k++) { sums[ns] += - scorehand(h, d[k], CINHAND, TRUE, FALSE); + scorehand(h, d[k], CINHAND, true, false); if (mycrib) - sums[ns] += adjust(cb, d[k]); + sums[ns] += adjust(cb); else - sums[ns] -= adjust(cb, d[k]); + sums[ns] -= adjust(cb); } ++ns; } @@ -290,15 +282,13 @@ cdiscard(mycrib) /* * returns true if some card in hand can be played without exceeding 31 */ -int -anymove(hand, n, sum) - CARD hand[]; - int n, sum; +bool +anymove(CARD hand[], int n, int sum) { int i, j; if (n < 1) - return (FALSE); + return (false); j = hand[0].rank; for (i = 1; i < n; i++) { if (hand[i].rank < j) @@ -311,10 +301,8 @@ anymove(hand, n, sum) * anysumto returns the index (0 <= i < n) of the card in hand that brings * the s up to t, or -1 if there is none */ -int -anysumto(hand, n, s, t) - CARD hand[]; - int n, s, t; +static int +anysumto(CARD hand[], int n, int s, int t) { int i; @@ -328,10 +316,8 @@ anysumto(hand, n, s, t) /* * return the number of cards in h having the given rank value */ -int -numofval(h, n, v) - CARD h[]; - int n, v; +static int +numofval(CARD h[], int n, int v) { int i, j; @@ -347,9 +333,7 @@ numofval(h, n, v) * makeknown remembers all n cards in h for future recall */ void -makeknown(h, n) - CARD h[]; - int n; +makeknown(CARD h[], int n) { int i;