1: # include   "monop.ext"
   2: # include   <ctype.h>
   3: # include   <signal.h>
   4: 
   5: # define    execsh(sh)  execl(sh, shell_name[roll(1, num_names)-1], 0)
   6: 
   7: static char *shell_def  = "/bin/csh",
   8:         *shell_name[]   = {
   9:             ".Hi Mom!",
  10:             ".Kick Me",
  11:             ".I'm really the next process down",
  12:             ".Hi Kids!",
  13:             ".This space for rent",
  14:             ".Singin' in the rain....",
  15:             ".I am but a Cog in the Wheel of Life",
  16:             ".Look out!!! Behind you!!!!!",
  17:             ".Looking for a good time, sailor?",
  18:             ".I don't get NO respect...",
  19:             ".Augghh!  You peeked!"
  20:         };
  21: 
  22: static int  num_names   = sizeof shell_name / sizeof (char *);;
  23: 
  24: char    *shell_in();
  25: 
  26: /*
  27:  *	This routine executes a truncated set of commands until a
  28:  * "yes or "no" answer is gotten.
  29:  */
  30: getyn(prompt)
  31: reg char    *prompt; {
  32: 
  33:     reg int com;
  34: 
  35:     for (;;)
  36:         if ((com=getinp(prompt, yn)) < 2)
  37:             return com;
  38:         else
  39:             (*func[com-2])();
  40: }
  41: /*
  42:  *	This routine tells the player if he's out of money.
  43:  */
  44: notify() {
  45: 
  46:     if (cur_p->money < 0)
  47:         printf("That leaves you $%d in debt\n", -cur_p->money);
  48:     else if (cur_p->money == 0)
  49:         printf("that leaves you broke\n");
  50:     else if (fixing && !told_em && cur_p->money > 0) {
  51:         printf("-- You are now Solvent ---\n");
  52:         told_em = TRUE;
  53:     }
  54: }
  55: /*
  56:  *	This routine switches to the next player
  57:  */
  58: next_play() {
  59: 
  60:     player = ++player % num_play;
  61:     cur_p = &play[player];
  62:     num_doub = 0;
  63: }
  64: /*
  65:  *	This routine gets an integer from the keyboard after the
  66:  * given prompt.
  67:  */
  68: get_int(prompt)
  69: reg char    *prompt; {
  70: 
  71:     reg int     num;
  72:     reg char    *sp;
  73:     char        buf[257];
  74: 
  75:     for (;;) {
  76: inter:
  77:         printf(prompt);
  78:         num = 0;
  79:         for (sp = buf; (*sp=getchar()) != '\n' && !feof(stdin); sp++)
  80:             if (*sp == -1)  /* check for interrupted system call */
  81:                 goto inter;
  82:         if (feof(stdin)) {
  83:             clearerr(stdin);
  84:             continue;
  85:         }
  86:         if (sp == buf)
  87:             continue;
  88:         for (sp = buf; isspace(*sp); sp++)
  89:             continue;
  90:         for (; isdigit(*sp); sp++)
  91:             num = num * 10 + *sp - '0';
  92:         if (*sp == '\n')
  93:             return num;
  94:         else
  95:             printf("I can't understand that\n");
  96:     }
  97: }
  98: /*
  99:  *	This routine sets the monopoly flag from the list given.
 100:  */
 101: set_ownlist(pl)
 102: int pl; {
 103: 
 104:     reg int num;        /* general counter		*/
 105:     reg MON *orig;      /* remember starting monop ptr	*/
 106:     reg OWN *op;        /* current owned prop		*/
 107:     OWN *orig_op;       /* origianl prop before loop	*/
 108: 
 109:     op = play[pl].own_list;
 110: #ifdef DEBUG
 111:     printf("op [%d] = play[pl [%d] ].own_list;\n", op, pl);
 112: #endif
 113:     while (op) {
 114: #ifdef DEBUG
 115:         printf("op->sqr->type = %d\n", op->sqr->type);
 116: #endif
 117:         switch (op->sqr->type) {
 118:           case UTIL:
 119: #ifdef DEBUG
 120:             printf("  case UTIL:\n");
 121: #endif
 122:             for (num = 0; op && op->sqr->type == UTIL; op = op->next)
 123:                 num++;
 124:             play[pl].num_util = num;
 125: #ifdef DEBUG
 126:             printf("play[pl].num_util = num [%d];\n", num);
 127: #endif
 128:             break;
 129:           case RR:
 130: #ifdef DEBUG
 131:             printf("  case RR:\n");
 132: #endif
 133:             for (num = 0; op && op->sqr->type == RR; op = op->next) {
 134: #ifdef DEBUG
 135:                 printf("iter: %d\n", num);
 136:                 printf("op = %d, op->sqr = %d, op->sqr->type = %d\n", op, op->sqr, op->sqr->type);
 137: #endif
 138:                 num++;
 139:             }
 140:             play[pl].num_rr = num;
 141: #ifdef DEBUG
 142:             printf("play[pl].num_rr = num [%d];\n", num);
 143: #endif
 144:             break;
 145:           case PRPTY:
 146: #ifdef DEBUG
 147:             printf("  case PRPTY:\n");
 148: #endif
 149:             orig = op->sqr->desc->mon_desc;
 150:             orig_op = op;
 151:             num = 0;
 152:             while (op && op->sqr->desc->mon_desc == orig) {
 153: #ifdef DEBUG
 154:                 printf("iter: %d\n", num);
 155: #endif
 156:                 num++;
 157: #ifdef DEBUG
 158:                 printf("op = op->next ");
 159: #endif
 160:                 op = op->next;
 161: #ifdef DEBUG
 162:                 printf("[%d];\n", op);
 163: #endif
 164:             }
 165: #ifdef DEBUG
 166:             printf("num = %d\n");
 167: #endif
 168:             if (orig == 0) {
 169:                 printf("panic:  bad monopoly descriptor: orig = %d\n", orig);
 170:                 printf("player # %d\n", pl+1);
 171:                 printhold(pl);
 172:                 printf("orig_op = %d\n", orig_op);
 173:                 printf("orig_op->sqr->type = %d (PRPTY)\n", op->sqr->type);
 174:                 printf("orig_op->next = %d\n", op->next);
 175:                 printf("orig_op->sqr->desc = %d\n", op->sqr->desc);
 176:                 printf("op = %d\n", op);
 177:                 printf("op->sqr->type = %d (PRPTY)\n", op->sqr->type);
 178:                 printf("op->next = %d\n", op->next);
 179:                 printf("op->sqr->desc = %d\n", op->sqr->desc);
 180:                 printf("num = %d\n", num);
 181:             }
 182: #ifdef DEBUG
 183:             printf("orig->num_in = %d\n", orig->num_in);
 184: #endif
 185:             if (num == orig->num_in)
 186:                 is_monop(orig, pl);
 187:             else
 188:                 isnot_monop(orig);
 189:             break;
 190:         }
 191:     }
 192: }
 193: /*
 194:  *	This routine sets things up as if it is a new monopoly
 195:  */
 196: is_monop(mp, pl)
 197: reg MON *mp;
 198: int pl; {
 199: 
 200:     reg char    *sp;
 201:     reg int     i;
 202: 
 203:     mp->owner = pl;
 204:     mp->num_own = mp->num_in;
 205:     for (i = 0; i < mp->num_in; i++)
 206:         mp->sq[i]->desc->monop = TRUE;
 207:     mp->name = mp->mon_n;
 208: }
 209: /*
 210:  *	This routine sets things up as if it is no longer a monopoly
 211:  */
 212: isnot_monop(mp)
 213: reg MON *mp; {
 214: 
 215:     reg char    *sp;
 216:     reg int     i;
 217: 
 218:     mp->owner = -1;
 219:     for (i = 0; i < mp->num_in; i++)
 220:         mp->sq[i]->desc->monop = FALSE;
 221:     mp->name = mp->not_m;
 222: }
 223: /*
 224:  *	This routine gives a list of the current player's routine
 225:  */
 226: list() {
 227: 
 228:     printhold(player);
 229: }
 230: /*
 231:  *	This routine gives a list of a given players holdings
 232:  */
 233: list_all() {
 234: 
 235:     reg int pl;
 236: 
 237:     while ((pl=getinp("Whose holdings do you want to see? ", name_list)) < num_play)
 238:         printhold(pl);
 239: }
 240: /*
 241:  *	This routine gives the players a chance before it exits.
 242:  */
 243: quit() {
 244: 
 245:     putchar('\n');
 246:     if (getyn("Do you all really want to quit? ", yn) == 0)
 247:         exit(0);
 248:     signal(2, quit);
 249: }
 250: /*
 251:  *	This routine copies one structure to another
 252:  */
 253: cpy_st(s1, s2, size)
 254: reg int *s1, *s2, size; {
 255: 
 256:     size /= 2;
 257:     while (size--)
 258:         *s1++ = *s2++;
 259: }
 260: /*
 261:  *	This routine forks off a shell.  It uses the users login shell
 262:  */
 263: shell_out() {
 264: 
 265:     static char *shell = NULL;
 266: 
 267:     printline();
 268:     if (shell == NULL)
 269:         shell = shell_in();
 270:     fflush();
 271:     if (!fork()) {
 272:         signal(SIGINT, SIG_DFL);
 273:         execsh(shell);
 274:     }
 275:     ignoresigs();
 276:     wait();
 277:     resetsigs();
 278:     putchar('\n');
 279:     printline();
 280: }
 281: /*
 282:  *	This routine looks up the users login shell
 283:  */
 284: # include   <pwd.h>
 285: 
 286: struct passwd   *getpwuid();
 287: 
 288: char        *getenv();
 289: 
 290: char *
 291: shell_in() {
 292: 
 293:     reg struct passwd   *pp;
 294:     reg char        *sp;
 295: 
 296:     if ((sp = getenv("SHELL")) == NULL) {
 297:         pp = getpwuid(getuid());
 298:         if (pp->pw_shell[0] != '\0')
 299:             return pp->pw_shell;
 300:         else
 301:             return shell_def;
 302:         /*return (*(pp->pw_shell) != '\0' ? pp->pw_shell : shell_def);*/
 303:     }
 304:     return sp;
 305: }
 306: /*
 307:  *	This routine sets things up to ignore all the signals.
 308:  */
 309: ignoresigs() {
 310: 
 311:     reg int i;
 312: 
 313:     for (i = 0; i < NSIG; i++)
 314:         signal(i, SIG_IGN);
 315: }
 316: /*
 317:  *	This routine sets up things as they were before.
 318:  */
 319: resetsigs() {
 320: 
 321:     reg int i;
 322: 
 323:     for (i = 0; i < NSIG; i++)
 324:         signal(i, SIG_DFL);
 325:     signal(2, quit);
 326: }

Defined functions

cpy_st defined in line 253; used 1 times
ignoresigs defined in line 309; used 1 times
is_monop defined in line 196; used 1 times
isnot_monop defined in line 212; used 2 times
list defined in line 226; never used
list_all defined in line 233; never used
next_play defined in line 58; used 2 times
quit defined in line 243; used 2 times
resetsigs defined in line 319; used 1 times
set_ownlist defined in line 101; used 2 times
shell_in defined in line 290; used 2 times
shell_out defined in line 263; never used

Defined variables

num_names defined in line 22; used 1 times
  • in line 5
shell_def defined in line 7; used 1 times

Defined macros

execsh defined in line 5; used 1 times
Last modified: 1987-08-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3955
Valid CSS Valid XHTML 1.0 Strict