diff options
author | 1998-09-20 23:36:48 +0000 | |
---|---|---|
committer | 1998-09-20 23:36:48 +0000 | |
commit | bb3b10f20733800fb553c3e62ef7e64f06c84d62 (patch) | |
tree | 1f5c3cf73805ec4af3b9ad432540a8b5c4b2f114 /games/monop/misc.c | |
parent | Checked in without subdirectory. Removed from here to avoid duplication. (diff) | |
download | wireguard-openbsd-bb3b10f20733800fb553c3e62ef7e64f06c84d62.tar.xz wireguard-openbsd-bb3b10f20733800fb553c3e62ef7e64f06c84d62.zip |
rand -> random; handle EOF; don't overflow on user input; check for calloc()
success; OpenBSD tags; some reformatting and ridding of unused variables.
Diffstat (limited to 'games/monop/misc.c')
-rw-r--r-- | games/monop/misc.c | 133 |
1 files changed, 69 insertions, 64 deletions
diff --git a/games/monop/misc.c b/games/monop/misc.c index b2e89a4c31f..2ba193c67d3 100644 --- a/games/monop/misc.c +++ b/games/monop/misc.c @@ -1,3 +1,4 @@ +/* $OpenBSD: misc.c,v 1.3 1998/09/20 23:36:51 pjanzen Exp $ */ /* $NetBSD: misc.c,v 1.4 1995/03/23 08:34:47 cgd Exp $ */ /* @@ -37,22 +38,23 @@ #if 0 static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: misc.c,v 1.4 1995/03/23 08:34:47 cgd Exp $"; +static char rcsid[] = "$OpenBSD: misc.c,v 1.3 1998/09/20 23:36:51 pjanzen Exp $"; #endif #endif /* not lint */ -# include "monop.ext" -# include <ctype.h> -# include <signal.h> +#include "monop.ext" +#include <ctype.h> +#include <signal.h> /* * This routine executes a truncated set of commands until a * "yes or "no" answer is gotten. */ +int getyn(prompt) -reg char *prompt; { - - reg int com; + char *prompt; +{ + int com; for (;;) if ((com=getinp(prompt, yn)) < 2) @@ -63,8 +65,9 @@ reg char *prompt; { /* * This routine tells the player if he's out of money. */ -notify() { - +void +notify() +{ if (cur_p->money < 0) printf("That leaves you $%d in debt\n", -cur_p->money); else if (cur_p->money == 0) @@ -77,8 +80,9 @@ notify() { /* * This routine switches to the next player */ -next_play() { - +void +next_play() +{ player = ++player % num_play; cur_p = &play[player]; num_doub = 0; @@ -87,21 +91,30 @@ next_play() { * This routine gets an integer from the keyboard after the * given prompt. */ +int get_int(prompt) -reg char *prompt; { - - reg int num; - reg char *sp; - int c; - char buf[257]; + char *prompt; +{ + int num; + char *sp; + int c, i; + char buf[257]; for (;;) { -inter: printf(prompt); num = 0; - for (sp = buf; (c = getchar()) != '\n'; *sp++ = c) - if (c == -1) /* check for interrupted system call */ - goto inter; + i = 0; + for (sp = buf; (c = getchar()) != '\n';) { + if (c == EOF) { + printf("user closed input stream, quitting...\n"); + exit(0); + } + *sp = c; + if (i < sizeof(buf)) { + i++; + sp++; + } + } *sp = c; if (sp == buf) continue; @@ -118,17 +131,18 @@ inter: /* * This routine sets the monopoly flag from the list given. */ +void set_ownlist(pl) -int pl; { - - reg int num; /* general counter */ - reg MON *orig; /* remember starting monop ptr */ - reg OWN *op; /* current owned prop */ + int pl; +{ + int num; /* general counter */ + MON *orig; /* remember starting monop ptr */ + OWN *op; /* current owned prop */ OWN *orig_op; /* origianl prop before loop */ op = play[pl].own_list; #ifdef DEBUG - printf("op [%d] = play[pl [%d] ].own_list;\n", op, pl); + printf("op [%p] = play[pl [%d] ].own_list;\n", op, pl); #endif while (op) { #ifdef DEBUG @@ -153,7 +167,7 @@ int pl; { for (num = 0; op && op->sqr->type == RR; op = op->next) { #ifdef DEBUG printf("iter: %d\n", num); - printf("op = %d, op->sqr = %d, op->sqr->type = %d\n", op, op->sqr, op->sqr->type); + printf("op = %p, op->sqr = %p, op->sqr->type = %d\n", op, op->sqr, op->sqr->type); #endif num++; } @@ -179,24 +193,24 @@ int pl; { #endif op = op->next; #ifdef DEBUG - printf("[%d];\n", op); + printf("[%p];\n", op); #endif } #ifdef DEBUG printf("num = %d\n"); #endif if (orig == 0) { - printf("panic: bad monopoly descriptor: orig = %d\n", orig); + printf("panic: bad monopoly descriptor: orig = %p\n", orig); printf("player # %d\n", pl+1); printhold(pl); - printf("orig_op = %d\n", orig_op); + printf("orig_op = %p\n", orig_op); printf("orig_op->sqr->type = %d (PRPTY)\n", op->sqr->type); - printf("orig_op->next = %d\n", op->next); - printf("orig_op->sqr->desc = %d\n", op->sqr->desc); - printf("op = %d\n", op); + printf("orig_op->next = %p\n", op->next); + printf("orig_op->sqr->desc = %p\n", op->sqr->desc); + printf("op = %p\n", op); printf("op->sqr->type = %d (PRPTY)\n", op->sqr->type); - printf("op->next = %d\n", op->next); - printf("op->sqr->desc = %d\n", op->sqr->desc); + printf("op->next = %p\n", op->next); + printf("op->sqr->desc = %p\n", op->sqr->desc); printf("num = %d\n", num); } #ifdef DEBUG @@ -213,12 +227,12 @@ int pl; { /* * This routine sets things up as if it is a new monopoly */ +void is_monop(mp, pl) -reg MON *mp; -int pl; { - - reg char *sp; - reg int i; + MON *mp; + int pl; +{ + int i; mp->owner = pl; mp->num_own = mp->num_in; @@ -229,11 +243,11 @@ int pl; { /* * This routine sets things up as if it is no longer a monopoly */ +void isnot_monop(mp) -reg MON *mp; { - - reg char *sp; - reg int i; + MON *mp; +{ + int i; mp->owner = -1; for (i = 0; i < mp->num_in; i++) @@ -243,16 +257,18 @@ reg MON *mp; { /* * This routine gives a list of the current player's routine */ -list() { - +void +list() +{ printhold(player); } /* * This routine gives a list of a given players holdings */ -list_all() { - - reg int pl; +void +list_all() +{ + int pl; while ((pl=getinp("Whose holdings do you want to see? ", name_list)) < num_play) printhold(pl); @@ -261,20 +277,9 @@ list_all() { * This routine gives the players a chance before it exits. */ void -quit() { - +quit() +{ putchar('\n'); - if (getyn("Do you all really want to quit? ", yn) == 0) + if (getyn("Do you all really want to quit? ") == 0) exit(0); - signal(SIGINT, quit); -} -/* - * This routine copies one structure to another - */ -cpy_st(s1, s2, size) -reg int *s1, *s2, size; { - - size /= 2; - while (size--) - *s1++ = *s2++; } |