]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/misc.c
2 * Copyright (c) 1980 Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 /*static char sccsid[] = "from: @(#)misc.c 5.5 (Berkeley) 2/28/91";*/
36 static char rcsid
[] = "$Id: misc.c,v 1.2 1993/08/01 18:53:37 mycroft Exp $";
43 # define execsh(sh) execl(sh, shell_name[roll(1, num_names)-1], 0)
45 static char *shell_def
= "/bin/csh",
49 ".I'm really the next process down",
51 ".This space for rent",
52 ".Singin' in the rain....",
53 ".I am but a Cog in the Wheel of Life",
54 ".Look out!!! Behind you!!!!!",
55 ".Looking for a good time, sailor?",
56 ".I don't get NO respect...",
57 ".Augghh! You peeked!"
60 static int num_names
= sizeof shell_name
/ sizeof (char *);;
65 * This routine executes a truncated set of commands until a
66 * "yes or "no" answer is gotten.
74 if ((com
=getinp(prompt
, yn
)) < 2)
80 * This routine tells the player if he's out of money.
85 printf("That leaves you $%d in debt\n", -cur_p
->money
);
86 else if (cur_p
->money
== 0)
87 printf("that leaves you broke\n");
88 else if (fixing
&& !told_em
&& cur_p
->money
> 0) {
89 printf("-- You are now Solvent ---\n");
94 * This routine switches to the next player
98 player
= ++player
% num_play
;
99 cur_p
= &play
[player
];
103 * This routine gets an integer from the keyboard after the
117 for (sp
= buf
; (*sp
=getchar()) != '\n'; sp
++)
118 if (*sp
== -1) /* check for interrupted system call */
122 for (sp
= buf
; isspace(*sp
); sp
++)
124 for (; isdigit(*sp
); sp
++)
125 num
= num
* 10 + *sp
- '0';
129 printf("I can't understand that\n");
133 * This routine sets the monopoly flag from the list given.
138 reg
int num
; /* general counter */
139 reg MON
*orig
; /* remember starting monop ptr */
140 reg OWN
*op
; /* current owned prop */
141 OWN
*orig_op
; /* origianl prop before loop */
143 op
= play
[pl
].own_list
;
145 printf("op [%d] = play[pl [%d] ].own_list;\n", op
, pl
);
149 printf("op->sqr->type = %d\n", op
->sqr
->type
);
151 switch (op
->sqr
->type
) {
154 printf(" case UTIL:\n");
156 for (num
= 0; op
&& op
->sqr
->type
== UTIL
; op
= op
->next
)
158 play
[pl
].num_util
= num
;
160 printf("play[pl].num_util = num [%d];\n", num
);
165 printf(" case RR:\n");
167 for (num
= 0; op
&& op
->sqr
->type
== RR
; op
= op
->next
) {
169 printf("iter: %d\n", num
);
170 printf("op = %d, op->sqr = %d, op->sqr->type = %d\n", op
, op
->sqr
, op
->sqr
->type
);
174 play
[pl
].num_rr
= num
;
176 printf("play[pl].num_rr = num [%d];\n", num
);
181 printf(" case PRPTY:\n");
183 orig
= op
->sqr
->desc
->mon_desc
;
186 while (op
&& op
->sqr
->desc
->mon_desc
== orig
) {
188 printf("iter: %d\n", num
);
192 printf("op = op->next ");
196 printf("[%d];\n", op
);
200 printf("num = %d\n");
203 printf("panic: bad monopoly descriptor: orig = %d\n", orig
);
204 printf("player # %d\n", pl
+1);
206 printf("orig_op = %d\n", orig_op
);
207 printf("orig_op->sqr->type = %d (PRPTY)\n", op
->sqr
->type
);
208 printf("orig_op->next = %d\n", op
->next
);
209 printf("orig_op->sqr->desc = %d\n", op
->sqr
->desc
);
210 printf("op = %d\n", op
);
211 printf("op->sqr->type = %d (PRPTY)\n", op
->sqr
->type
);
212 printf("op->next = %d\n", op
->next
);
213 printf("op->sqr->desc = %d\n", op
->sqr
->desc
);
214 printf("num = %d\n", num
);
217 printf("orig->num_in = %d\n", orig
->num_in
);
219 if (num
== orig
->num_in
)
228 * This routine sets things up as if it is a new monopoly
238 mp
->num_own
= mp
->num_in
;
239 for (i
= 0; i
< mp
->num_in
; i
++)
240 mp
->sq
[i
]->desc
->monop
= TRUE
;
241 mp
->name
= mp
->mon_n
;
244 * This routine sets things up as if it is no longer a monopoly
253 for (i
= 0; i
< mp
->num_in
; i
++)
254 mp
->sq
[i
]->desc
->monop
= FALSE
;
255 mp
->name
= mp
->not_m
;
258 * This routine gives a list of the current player's routine
265 * This routine gives a list of a given players holdings
271 while ((pl
=getinp("Whose holdings do you want to see? ", name_list
)) < num_play
)
275 * This routine gives the players a chance before it exits.
281 if (getyn("Do you all really want to quit? ", yn
) == 0)
283 signal(SIGINT
, quit
);
286 * This routine copies one structure to another
289 reg
int *s1
, *s2
, size
; {
296 * This routine forks off a shell. It uses the users login shell
300 static char *shell
= NULL
;
307 signal(SIGINT
, SIG_DFL
);
317 * This routine looks up the users login shell
319 # include <sys/types.h>
327 reg
struct passwd
*pp
;
330 if ((sp
= getenv("SHELL")) == NULL
) {
331 pp
= getpwuid(getuid());
332 if (pp
->pw_shell
[0] != '\0')
336 /*return (*(pp->pw_shell) != '\0' ? pp->pw_shell : shell_def);*/
341 * This routine sets things up to ignore all the signals.
347 for (i
= 0; i
< NSIG
; i
++)
351 * This routine sets up things as they were before.
357 for (i
= 0; i
< NSIG
; i
++)
359 signal(SIGINT
, quit
);