-/* $NetBSD: monop.c,v 1.5 1998/09/11 13:54:08 hubertf Exp $ */
+/* $NetBSD: monop.c,v 1.17 2008/02/19 09:45:02 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*
#if 0
static char sccsid[] = "@(#)monop.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: monop.c,v 1.5 1998/09/11 13:54:08 hubertf Exp $");
+__RCSID("$NetBSD: monop.c,v 1.17 2008/02/19 09:45:02 dholland Exp $");
#endif
#endif /* not lint */
#include <unistd.h>
#include "monop.def"
-int main __P((int, char *[]));
-static void getplayers __P((void));
-static void init_players __P((void));
-static void init_monops __P((void));
-static void do_quit __P((int));
+int main(int, char *[]);
+static void getplayers(void);
+static void init_players(void);
+static void init_monops(void);
+static void do_quit(int);
+void *heapstart;
/*
* This program implements a monopoly game
*/
int
main(ac, av)
-int ac;
-char *av[]; {
-
+ int ac;
+ char *av[];
+{
+ /* Revoke setgid privileges */
+ setgid(getgid());
srand(getpid());
+ heapstart = sbrk(0);
if (ac > 1) {
if (!rest_f(av[1]))
restore();
/*ARGSUSED*/
static void
do_quit(n)
- int n;
+ int n __unused;
{
quit();
}
+
/*
* This routine gets the names of the players
*/
static void
getplayers()
{
-
- char *sp;
- int i, j;
- char buf[257];
+ char *sp;
+ int i, j;
+ char buf[257];
blew_it:
for (;;) {
- if ((num_play=get_int("How many players? ")) <= 0 ||
+ if ((num_play = get_int("How many players? ")) <= 0 ||
num_play > MAX_PL)
printf("Sorry. Number must range from 1 to 9\n");
else
break;
}
cur_p = play = (PLAY *) calloc(num_play, sizeof (PLAY));
+ if (play == NULL)
+ err(1, NULL);
for (i = 0; i < num_play; i++) {
over:
printf("Player %d's name: ", i + 1);
- for (sp = buf; (*sp=getchar()) != '\n'; sp++)
+ for (sp = buf; (*sp = getchar()) != '\n'; sp++)
continue;
if (sp == buf)
goto over;
*sp++ = '\0';
- strcpy(name_list[i]=play[i].name=(char *)calloc(1,sp-buf),buf);
+ name_list[i] = play[i].name = (char *)calloc(1, sp - buf);
+ if (name_list[i] == NULL)
+ err(1, NULL);
+ strcpy(play[i].name, buf);
play[i].money = 1500;
}
name_list[i++] = "done";
for (j = i + 1; j < num_play; j++)
if (strcasecmp(name_list[i], name_list[j]) == 0) {
if (i != num_play - 1)
- printf("Hey!!! Some of those are IDENTICAL!! Let's try that again....\n");
+ printf("Hey!!! Some of those are "
+ "IDENTICAL!! Let's try that "
+ "again....\n");
else
- printf("\"done\" is a reserved word. Please try again\n");
+ printf("\"done\" is a reserved word. "
+ "Please try again\n");
for (i = 0; i < num_play; i++)
free(play[i].name);
free(play);
goto blew_it;
}
}
+
/*
* This routine figures out who goes first
*/
static void
init_players()
{
-
- int i, rl, cur_max;
- bool over = 0;
- int max_pl = 0;
+ int i, rl, cur_max;
+ bool over = 0;
+ int max_pl = 0;
again:
putchar('\n');
cur_p = &play[max_pl];
printf("%s (%d) goes first\n", cur_p->name, max_pl + 1);
}
+
/*
- * This routine initalizes the monopoly structures.
+ * This routine initializes the monopoly structures.
*/
static void
-init_monops()
+init_monops()
{
-
- MON *mp;
- int i;
+ MON *mp;
+ int i;
for (mp = mon; mp < &mon[N_MON]; mp++) {
mp->name = mp->not_m;