X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/94b5353c71e7246077d468afe68d51ce85fc213d..9e7fd816e02e66962d482b02209f112e1d5789fc:/monop/misc.c diff --git a/monop/misc.c b/monop/misc.c index 1a71653b..3f881072 100644 --- a/monop/misc.c +++ b/monop/misc.c @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.4 1995/03/23 08:34:47 cgd Exp $ */ +/* $NetBSD: misc.c,v 1.21 2009/08/12 08:10:49 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -12,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -33,38 +29,47 @@ * SUCH DAMAGE. */ +#include #ifndef lint #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 $"; +__RCSID("$NetBSD: misc.c,v 1.21 2009/08/12 08:10:49 dholland Exp $"); #endif #endif /* not lint */ -# include "monop.ext" -# include -# include +#include +#include +#include +#include + +#include "monop.h" + +static void is_monop(MON *, int); /* * 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; + const char *prompt; +{ + int com; for (;;) - if ((com=getinp(prompt, yn)) < 2) + if ((com=getinp(prompt, yncoms)) < 2) return com; else (*func[com-2])(); } + /* * 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) @@ -74,59 +79,63 @@ notify() { told_em = TRUE; } } + /* * This routine switches to the next player */ -next_play() { - - player = ++player % num_play; +void +next_play() +{ + player = (player + 1) % num_play; cur_p = &play[player]; num_doub = 0; } + /* * 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; - char buf[257]; + const char *prompt; +{ + long num; + char *sp; + char buf[257]; for (;;) { -inter: - printf(prompt); - num = 0; - for (sp = buf; (*sp=getchar()) != '\n'; sp++) - if (*sp == -1) /* check for interrupted system call */ - goto inter; - if (sp == buf) - continue; - for (sp = buf; isspace(*sp); sp++) - continue; - for (; isdigit(*sp); sp++) - num = num * 10 + *sp - '0'; - if (*sp == '\n') - return num; - else + printf("%s", prompt); + fgets(buf, sizeof(buf), stdin); + if (feof(stdin)) + return 0; + sp = strchr(buf, '\n'); + if (sp) + *sp = '\0'; + errno = 0; + num = strtol(buf, &sp, 10); + if (errno || strlen(sp) > 0 || num < 0 || num >= INT_MAX) { printf("I can't understand that\n"); + continue; + } + return num; } } + /* * 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 */ - OWN *orig_op; /* origianl prop before loop */ + int pl; +{ + int num; /* general counter */ + MON *orig; /* remember starting monop ptr */ + OWN *op; /* current owned prop */ + OWN *orig_op; /* original 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 @@ -137,7 +146,8 @@ int pl; { #ifdef DEBUG printf(" case UTIL:\n"); #endif - for (num = 0; op && op->sqr->type == UTIL; op = op->next) + for (num = 0; op && op->sqr->type == UTIL; + op = op->next) num++; play[pl].num_util = num; #ifdef DEBUG @@ -148,10 +158,13 @@ int pl; { #ifdef DEBUG printf(" case RR:\n"); #endif - for (num = 0; op && op->sqr->type == RR; op = op->next) { + 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++; } @@ -177,25 +190,36 @@ int pl; { #endif op = op->next; #ifdef DEBUG - printf("[%d];\n", op); + printf("[%p];\n", op); #endif } #ifdef DEBUG - printf("num = %d\n"); + printf("num = %d\n", num); #endif - if (orig == 0) { - printf("panic: bad monopoly descriptor: orig = %d\n", orig); + if (orig == NULL) { + 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->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("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("orig_op = %p\n", orig_op); + if (orig_op) { + printf("orig_op->sqr->type = %d (PRPTY)\n", + orig_op->sqr->type); + printf("orig_op->next = %p\n", + orig_op->next); + printf("orig_op->sqr->desc = %p\n", + orig_op->sqr->desc); + } + printf("op = %p\n", op); + if (op) { + printf("op->sqr->type = %d (PRPTY)\n", + op->sqr->type); + printf("op->next = %p\n", op->next); + printf("op->sqr->desc = %p\n", + op->sqr->desc); + } printf("num = %d\n", num); + exit(1); } #ifdef DEBUG printf("orig->num_in = %d\n", orig->num_in); @@ -203,20 +227,21 @@ int pl; { if (num == orig->num_in) is_monop(orig, pl); else - isnot_monop(orig); + is_not_monop(orig); break; } } } + /* * This routine sets things up as if it is a new monopoly */ +static 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; @@ -224,55 +249,51 @@ int pl; { mp->sq[i]->desc->monop = TRUE; mp->name = mp->mon_n; } + /* * This routine sets things up as if it is no longer a monopoly */ -isnot_monop(mp) -reg MON *mp; { - - reg char *sp; - reg int i; +void +is_not_monop(mp) + MON *mp; +{ + int i; mp->owner = -1; for (i = 0; i < mp->num_in; i++) mp->sq[i]->desc->monop = FALSE; mp->name = mp->not_m; } + /* * 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) + while ((pl = getinp("Whose holdings do you want to see? ", name_list)) + < num_play) printhold(pl); } + /* * 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++; }