DragonFly submit List (threaded) for 2005-03
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]
More games cleanups
Here are patches to make 5 more of the games WARNS 6 clean.
There should be no operational changes. Mostly constifying strings,
changing declarations, removing (void) casts.
-Craig
--
-----------------------------------------------------------------------
Craig Dooley <xlnxminusx@xxxxxxxxx>
Index: games/arithmetic/Makefile
===================================================================
RCS file: /home/dcvs/src/games/arithmetic/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- games/arithmetic/Makefile 17 Jun 2003 04:25:22 -0000 1.2
+++ games/arithmetic/Makefile 17 Mar 2005 09:45:53 -0000
@@ -5,5 +5,6 @@
PROG= arithmetic
MAN= arithmetic.6
HIDEGAME=hidegame
+WARNS?= 6
.include <bsd.prog.mk>
Index: games/arithmetic/arithmetic.c
===================================================================
RCS file: /home/dcvs/src/games/arithmetic/arithmetic.c,v
retrieving revision 1.3
diff -u -r1.3 arithmetic.c
--- games/arithmetic/arithmetic.c 12 Nov 2003 14:53:52 -0000 1.3
+++ games/arithmetic/arithmetic.c 17 Mar 2005 09:45:37 -0000
@@ -100,11 +100,7 @@
* bound is 10. After every NQUESTS questions, statistics on the performance
* so far are printed.
*/
-int
-main(argc, argv)
- int argc;
- char **argv;
-{
+int main(int argc, char **argv) {
int ch, cnt;
/* Revoke setgid privileges */
@@ -117,8 +113,7 @@
for (p = keys = optarg; *p; ++p)
if (!index(keylist, *p)) {
- (void)fprintf(stderr,
- "arithmetic: unknown key.\n");
+ fprintf(stderr, "arithmetic: unknown key.\n");
exit(1);
}
nkeys = p - optarg;
@@ -126,8 +121,7 @@
}
case 'r':
if ((rangemax = atoi(optarg)) <= 0) {
- (void)fprintf(stderr,
- "arithmetic: invalid range.\n");
+ fprintf(stderr, "arithmetic: invalid range.\n");
exit(1);
}
break;
@@ -141,7 +135,7 @@
/* Seed the random-number generator. */
srandomdev();
- (void)signal(SIGINT, intr);
+ signal(SIGINT, intr);
/* Now ask the questions. */
for (;;) {
@@ -154,26 +148,22 @@
}
/* Handle interrupt character. Print score and exit. */
-void
-intr(sig)
- int sig;
-{
+void intr(__unused int sig) {
showstats();
exit(0);
}
/* Print score. Original `arithmetic' had a delay after printing it. */
-void
-showstats()
-{
+void showstats(void) {
if (nright + nwrong > 0) {
- (void)printf("\n\nRights %d; Wrongs %d; Score %d%%",
+ printf("\n\nRights %d; Wrongs %d; Score %d%%",
nright, nwrong, (int)(100L * nright / (nright + nwrong)));
- if (nright > 0)
- (void)printf("\nTotal time %ld seconds; %.1f seconds per problem\n\n",
+ if (nright > 0) {
+ printf("\nTotal time %ld seconds; %.1f seconds per problem\n\n",
(long)qtime, (float)qtime / nright);
+ }
}
- (void)printf("\n");
+ printf("\n");
}
/*
@@ -184,9 +174,7 @@
* answer causes the numbers in the problem to be penalised, so that they are
* more likely to appear in subsequent problems.
*/
-int
-problem()
-{
+int problem(void) {
char *p;
time_t start, finish;
int left, op, right, result;
@@ -227,9 +215,9 @@
if (result < 0 || left < 0)
goto retry;
- (void)printf("%d %c %d = ", left, op, right);
- (void)fflush(stdout);
- (void)time(&start);
+ printf("%d %c %d = ", left, op, right);
+ fflush(stdout);
+ time(&start);
/*
* Keep looping until the correct answer is given, or until EOF or
@@ -237,21 +225,21 @@
*/
for (;;) {
if (!fgets(line, sizeof(line), stdin)) {
- (void)printf("\n");
+ printf("\n");
return(EOF);
}
for (p = line; *p && isspace(*p); ++p);
if (!isdigit(*p)) {
- (void)printf("Please type a number.\n");
+ printf("Please type a number.\n");
continue;
}
if (atoi(p) == result) {
- (void)printf("Right!\n");
+ printf("Right!\n");
++nright;
break;
}
/* Wrong answer; penalise and ask again. */
- (void)printf("What?\n");
+ printf("What?\n");
++nwrong;
penalise(right, op, 1);
if (op == 'x' || op == '+')
@@ -267,7 +255,7 @@
* the time you are not charged for a partially elapsed second at the
* end.
*/
- (void)time(&finish);
+ time(&finish);
qtime += finish - start;
return(0);
}
@@ -299,10 +287,7 @@
* operand number `operand' (0 or 1). If we run out of memory, we just
* forget about the penalty (how likely is this, anyway?).
*/
-void
-penalise(value, op, operand)
- int value, op, operand;
-{
+void penalise(int value, int op, int operand) {
struct penalty *p;
op = opnum(op);
@@ -320,10 +305,7 @@
* as a value, or represents a position in the penalty list. If the latter,
* we find the corresponding value and return that, decreasing its penalty.
*/
-int
-getrandom(maxval, op, operand)
- int maxval, op, operand;
-{
+int getrandom(int maxval, int op, int operand) {
int value;
struct penalty **pp, *p;
@@ -348,7 +330,7 @@
penalty[op][operand]--;
if (--(p->penalty) <= 0) {
p = p->next;
- (void)free((char *)*pp);
+ free((char *)*pp);
*pp = p;
}
return(value);
@@ -360,20 +342,17 @@
* correspond to the actual sum of penalties in the list. Provide an
* obscure message.
*/
- (void)fprintf(stderr, "arithmetic: bug: inconsistent penalties\n");
+ fprintf(stderr, "arithmetic: bug: inconsistent penalties\n");
exit(1);
/* NOTREACHED */
}
/* Return an index for the character op, which is one of [+-x/]. */
-int
-opnum(op)
- int op;
-{
+int opnum(int op) {
char *p;
if (op == 0 || (p = index(keylist, op)) == NULL) {
- (void)fprintf(stderr,
+ fprintf(stderr,
"arithmetic: bug: op %c not in keylist %s\n", op, keylist);
exit(1);
}
@@ -381,9 +360,7 @@
}
/* Print usage message and quit. */
-static void
-usage()
-{
- (void)fprintf(stderr, "usage: arithmetic [-o +-x/] [-r range]\n");
+static void usage(void) {
+ fprintf(stderr, "usage: arithmetic [-o +-x/] [-r range]\n");
exit(1);
}
Index: games/fish/Makefile
===================================================================
RCS file: /home/dcvs/src/games/fish/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- games/fish/Makefile 17 Jun 2003 04:25:23 -0000 1.2
+++ games/fish/Makefile 17 Mar 2005 10:10:41 -0000
@@ -6,5 +6,5 @@
FILES= fish.instr
MAN= fish.6
HIDEGAME=hidegame
-
+WARNS?= 6
.include <bsd.prog.mk>
Index: games/fish/fish.c
===================================================================
RCS file: /home/dcvs/src/games/fish/fish.c,v
retrieving revision 1.3
diff -u -r1.3 fish.c
--- games/fish/fish.c 12 Nov 2003 14:53:53 -0000 1.3
+++ games/fish/fish.c 17 Mar 2005 10:15:49 -0000
@@ -58,11 +58,11 @@
#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];
@@ -84,11 +84,7 @@
void usage (void);
int usermove (void);
-int
-main(argc, argv)
- int argc;
- char **argv;
-{
+int main(int argc, char **argv) {
int ch, move;
while ((ch = getopt(argc, argv, "p")) != -1)
@@ -98,7 +94,7 @@
break;
case '?':
default:
- (void)fprintf(stderr, "usage: fish [-p]\n");
+ fprintf(stderr, "usage: fish [-p]\n");
exit(1);
}
@@ -108,11 +104,11 @@
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,32 @@
return(EXIT_FAILURE);
}
-int
-usermove()
-{
+int usermove(void) {
int n;
- char **p;
+ char const**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 +167,7 @@
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,19 +176,17 @@
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()
-{
+int compmove(void) {
static int lmove;
if (promode)
@@ -206,13 +198,11 @@
}
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()
-{
+int promove(void) {
int i, max;
for (i = 0; i < RANKS; ++i)
@@ -249,11 +239,7 @@
/* NOTREACHED */
}
-int
-drawcard(player, hand)
- int player;
- int *hand;
-{
+int drawcard(int player, int *hand) {
int card;
while (deck[card = nrandom(RANKS)] == 0);
@@ -261,41 +247,33 @@
--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",
+ 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;
-{
+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;
-{
+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,64 +281,54 @@
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;
-{
+void chkwinner(int player, int *hand) {
int cb, i, ub;
for (i = 0; i < RANKS; ++i)
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;
-{
+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;
-{
+void printhand(int *hand) {
int book, i, j;
for (book = i = 0; i < RANKS; i++)
@@ -370,18 +338,15 @@
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;
-{
+int countcards(int *hand) {
int i, count;
for (count = i = 0; i < RANKS; i++)
@@ -389,10 +354,7 @@
return(count);
}
-int
-countbooks(hand)
- int *hand;
-{
+int countbooks(int *hand) {
int i, count;
for (count = i = 0; i < RANKS; i++)
@@ -401,14 +363,12 @@
PRC(i);
}
if (!count)
- (void)printf(" none");
- (void)putchar('\n');
+ printf(" none");
+ putchar('\n');
return(count);
}
-void
-init()
-{
+void init(void) {
int i, rank;
for (i = 0; i < RANKS; ++i)
@@ -425,35 +385,27 @@
}
}
-int
-nrandom(n)
- int n;
-{
-
+int nrandom(int n) {
return((int)random() % n);
}
-void
-instructions()
-{
+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()
-{
- (void)fprintf(stderr, "usage: fish [-p]\n");
+void usage(void) {
+ fprintf(stderr, "usage: fish [-p]\n");
exit(1);
}
Index: games/morse/Makefile
===================================================================
RCS file: /home/dcvs/src/games/morse/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- games/morse/Makefile 17 Jun 2003 04:25:24 -0000 1.2
+++ games/morse/Makefile 17 Mar 2005 10:18:51 -0000
@@ -4,6 +4,7 @@
PROG= morse
MAN= morse.6
+WARNS?= 6
.if ${MACHINE_ARCH} == "i386"
CFLAGS += -DSPEAKER=\"/dev/speaker\"
Index: games/morse/morse.c
===================================================================
RCS file: /home/dcvs/src/games/morse/morse.c,v
retrieving revision 1.2
diff -u -r1.2 morse.c
--- games/morse/morse.c 17 Jun 2003 04:25:24 -0000 1.2
+++ games/morse/morse.c 17 Mar 2005 10:19:29 -0000
@@ -59,8 +59,8 @@
#endif
struct morsetab {
- char inchar;
- char *morse;
+ const char inchar;
+ const char *morse;
};
static const struct morsetab mtab[] = {
Index: games/piano/Makefile
===================================================================
RCS file: /home/dcvs/src/games/piano/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- games/piano/Makefile 17 Jun 2003 04:25:24 -0000 1.2
+++ games/piano/Makefile 17 Mar 2005 09:58:50 -0000
@@ -6,5 +6,6 @@
MAN= piano.6
DPADD= ${LIBCURSES} ${LIBTERMCAP}
LDADD= -lcurses -ltermcap
+WARNS?= 6
.include <bsd.prog.mk>
Index: games/piano/piano.c
===================================================================
RCS file: /home/dcvs/src/games/piano/piano.c,v
retrieving revision 1.2
diff -u -r1.2 piano.c
--- games/piano/piano.c 17 Jun 2003 04:25:24 -0000 1.2
+++ games/piano/piano.c 17 Mar 2005 10:08:55 -0000
@@ -14,9 +14,9 @@
char *myname;
int verbose;
-static char *initcmd = "t160 o1 l16 ml";
+static const char *initcmd = "t160 o1 l16 ml";
-static char usage_msg[] =
+static const char usage_msg[] =
"simple keyboard player V0.8086\n"
"usage: %s [-v][-i str]\n"
"\t-i str defaults 't160 o1 l16 ml'\n"
@@ -28,10 +28,10 @@
struct kdef_t {
int ch;
- char *str;
+ const char *str;
};
-static char *kstr[256];
+static char const *kstr[256];
static struct kdef_t kdef[] = {
/* white key */
@@ -69,9 +69,7 @@
{ '\0', NULL }
};
-static int
-init_kstr(void)
-{
+static int init_kstr(void) {
struct kdef_t *mv = kdef;
while (mv->str != NULL) {
kstr[mv->ch] = mv->str;
@@ -80,21 +78,17 @@
return 0;
}/* init_kstr */
-static int
-fdputs(const char *s, int fd, int echo)
-{
+static int fdputs(const char *s, int fd, int output) {
int err, len = strlen(s);
write(fd, s, len);
err = write(fd, "\n", 1);
- if (echo) {
+ if (output) {
fputs(s, stdout);
}
return err;
}/* fdputs */
-static int
-outspkr(const char *s)
-{
+static int outspkr(const char *s) {
int err = -1, fd = open("/dev/speaker", O_WRONLY);
if (fd >= 0) {
fdputs(initcmd, fd, 0);
@@ -104,9 +98,7 @@
return err;
}/* outspkr */
-static int
-nain(void)
-{
+static int nain(void) {
int ch;
initscr();
noecho();
@@ -134,9 +126,7 @@
return 0;
}/* nain */
-int
-main(int argc, char *argv[])
-{
+int main(int argc, char **argv) {
int ch, ex, show_usage = 0;
myname = argv[0];
while ((ch = getopt(argc, argv, "-vi:")) != -1) {
Index: games/pig/Makefile
===================================================================
RCS file: /home/dcvs/src/games/pig/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- games/pig/Makefile 17 Jun 2003 04:25:24 -0000 1.2
+++ games/pig/Makefile 17 Mar 2005 09:48:04 -0000
@@ -4,5 +4,6 @@
PROG= pig
MAN= pig.6
+WARNS?= 6
.include <bsd.prog.mk>
Index: games/pig/pig.c
===================================================================
RCS file: /home/dcvs/src/games/pig/pig.c,v
retrieving revision 1.3
diff -u -r1.3 pig.c
--- games/pig/pig.c 12 Nov 2003 14:53:53 -0000 1.3
+++ games/pig/pig.c 17 Mar 2005 09:57:34 -0000
@@ -47,11 +47,7 @@
void pigout (char *, int);
void usage (void);
-int
-main(argc, argv)
- int argc;
- char *argv[];
-{
+int main(int argc, char **argv) {
int len;
int ch;
char buf[1024];
@@ -67,8 +63,8 @@
for (len = 0; (ch = getchar()) != EOF;) {
if (isalpha(ch)) {
- if (len >= sizeof(buf)) {
- (void)fprintf(stderr, "pig: ate too much!\n");
+ if ((unsigned int)len >= sizeof(buf)) {
+ fprintf(stderr, "pig: ate too much!\n");
exit(1);
}
buf[len++] = ch;
@@ -78,16 +74,12 @@
pigout(buf, len);
len = 0;
}
- (void)putchar(ch);
+ putchar(ch);
}
exit(0);
}
-void
-pigout(buf, len)
- char *buf;
- int len;
-{
+void pigout(char *buf, int len) {
int ch, start;
int olen;
@@ -96,7 +88,7 @@
* as a vowel if it appears first.
*/
if (index("aeiouAEIOU", buf[0]) != NULL) {
- (void)printf("%.*sway", len, buf);
+ printf("%.*sway", len, buf);
return;
}
@@ -111,12 +103,10 @@
(buf[start] == 'u' || buf[start] == 'U'))
buf[len++] = buf[start++];
}
- (void)printf("%.*say", olen, buf + start);
+ printf("%.*say", olen, buf + start);
}
-void
-usage()
-{
- (void)fprintf(stderr, "usage: pig\n");
+void usage(void) {
+ fprintf(stderr, "usage: pig\n");
exit(1);
}
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]