1: #include    "mille.h"
   2: #ifndef unctrl
   3: #include    "unctrl.h"
   4: #endif
   5: 
   6: # include   <sys/file.h>
   7: 
   8: # ifdef attron
   9: #	include   <term.h>
  10: #	define    _tty    cur_term->Nttyb
  11: # endif	attron
  12: 
  13: /*
  14:  * @(#)misc.c	1.2 (Berkeley) 3/28/83
  15:  */
  16: 
  17: #define NUMSAFE 4
  18: 
  19: /* VARARGS1 */
  20: error(str, arg)
  21: char    *str;
  22: {
  23:     stdscr = Score;
  24:     mvprintw(ERR_Y, ERR_X, str, arg);
  25:     clrtoeol();
  26:     putchar('');
  27:     refresh();
  28:     stdscr = Board;
  29:     return FALSE;
  30: }
  31: 
  32: CARD
  33: getcard()
  34: {
  35:     reg int     c, c1;
  36: 
  37:     for (;;) {
  38:         while ((c = readch()) == '\n' || c == '\r' || c == ' ')
  39:             continue;
  40:         if (islower(c))
  41:             c = toupper(c);
  42:         if (c == killchar() || c == erasechar())
  43:             return -1;
  44:         addstr(unctrl(c));
  45:         clrtoeol();
  46:         switch (c) {
  47:           case '1': case '2':   case '3':
  48:           case '4': case '5':   case '6':
  49:             c -= '0';
  50:             break;
  51:           case '0': case 'P':   case 'p':
  52:             c = 0;
  53:             break;
  54:           default:
  55:             putchar('');
  56:             addch('\b');
  57:             if (!isprint(c))
  58:                 addch('\b');
  59:             c = -1;
  60:             break;
  61:         }
  62:         refresh();
  63:         if (c >= 0) {
  64:             while ((c1=readch()) != '\r' && c1 != '\n' && c1 != ' ')
  65:                 if (c1 == killchar())
  66:                     return -1;
  67:                 else if (c1 == erasechar()) {
  68:                     addch('\b');
  69:                     clrtoeol();
  70:                     refresh();
  71:                     goto cont;
  72:                 }
  73:                 else
  74:                     write(0, "", 1);
  75:             return c;
  76:         }
  77: cont:       ;
  78:     }
  79: }
  80: 
  81: check_ext(forcomp)
  82: reg bool    forcomp; {
  83: 
  84: 
  85:     if (End == 700)
  86:         if (Play == PLAYER) {
  87:             if (getyn(EXTENSIONPROMPT)) {
  88: extend:
  89:                 if (!forcomp)
  90:                     End = 1000;
  91:                 return TRUE;
  92:             }
  93:             else {
  94: done:
  95:                 if (!forcomp)
  96:                     Finished = TRUE;
  97:                 return FALSE;
  98:             }
  99:         }
 100:         else {
 101:             reg PLAY    *pp, *op;
 102:             reg int     i, safe, miles;
 103: 
 104:             pp = &Player[COMP];
 105:             op = &Player[PLAYER];
 106:             for (safe = 0, i = 0; i < NUMSAFE; i++)
 107:                 if (pp->safety[i] != S_UNKNOWN)
 108:                     safe++;
 109:             if (safe < 2)
 110:                 goto done;
 111:             if (op->mileage == 0 || onecard(op)
 112:                 || (op->can_go && op->mileage >= 500))
 113:                 goto done;
 114:             for (miles = 0, i = 0; i < NUMSAFE; i++)
 115:                 if (op->safety[i] != S_PLAYED
 116:                     && pp->safety[i] == S_UNKNOWN)
 117:                     miles++;
 118:             if (miles + safe == NUMSAFE)
 119:                 goto extend;
 120:             for (miles = 0, i = 0; i < HAND_SZ; i++)
 121:                 if ((safe = pp->hand[i]) <= C_200)
 122:                     miles += Value[safe];
 123:             if (miles + (Topcard - Deck) * 3 > 1000)
 124:                 goto extend;
 125:             goto done;
 126:         }
 127:     else
 128:         goto done;
 129: }
 130: 
 131: /*
 132:  *	Get a yes or no answer to the given question.  Saves are
 133:  * also allowed.  Return TRUE if the answer was yes, FALSE if no.
 134:  */
 135: getyn(promptno)
 136: register int    promptno; {
 137: 
 138:     reg char    c;
 139: 
 140:     Saved = FALSE;
 141:     for (;;) {
 142:         leaveok(Board, FALSE);
 143:         prompt(promptno);
 144:         clrtoeol();
 145:         refresh();
 146:         switch (c = readch()) {
 147:           case 'n': case 'N':
 148:             addch('N');
 149:             refresh();
 150:             leaveok(Board, TRUE);
 151:             return FALSE;
 152:           case 'y': case 'Y':
 153:             addch('Y');
 154:             refresh();
 155:             leaveok(Board, TRUE);
 156:             return TRUE;
 157:           case 's': case 'S':
 158:             addch('S');
 159:             refresh();
 160:             Saved = save();
 161:             continue;
 162:           default:
 163:             addstr(unctrl(c));
 164:             refresh();
 165:             putchar('');
 166:             break;
 167:         }
 168:     }
 169: }
 170: 
 171: /*
 172:  *	Check to see if more games are desired.  If not, and game
 173:  * came from a saved file, make sure that they don't want to restore
 174:  * it.  Exit appropriately.
 175:  */
 176: check_more() {
 177: 
 178:     flush_input();
 179: 
 180:     On_exit = TRUE;
 181:     if (Player[PLAYER].total >= 5000 || Player[COMP].total >= 5000)
 182:         if (getyn(ANOTHERGAMEPROMPT))
 183:             return;
 184:         else {
 185:             /*
 186: 			 * must do accounting normally done in main()
 187: 			 */
 188:             if (Player[PLAYER].total > Player[COMP].total)
 189:                 Player[PLAYER].games++;
 190:             else if (Player[PLAYER].total < Player[COMP].total)
 191:                 Player[COMP].games++;
 192:             Player[COMP].total = 0;
 193:             Player[PLAYER].total = 0;
 194:         }
 195:     else
 196:         if (getyn(ANOTHERHANDPROMPT))
 197:             return;
 198:     if (!Saved && getyn(SAVEGAMEPROMPT))
 199:         if (!save())
 200:             return;
 201:     die();
 202: }
 203: 
 204: readch()
 205: {
 206:     reg int     cnt;
 207:     static char c;
 208: 
 209:     for (cnt = 0; read(0, &c, 1) <= 0; cnt++)
 210:         if (cnt > 100)
 211:             exit(1);
 212:     return c;
 213: }
 214: 
 215: flush_input()
 216: {
 217: # ifdef TIOCFLUSH
 218:     static int  ioctl_args = FREAD;
 219: 
 220:     (void) ioctl(fileno(stdin), TIOCFLUSH, &ioctl_args);
 221: # else
 222:     fflush(stdin);
 223: # endif
 224: }

Defined functions

check_ext defined in line 81; used 2 times
check_more defined in line 176; used 1 times
error defined in line 20; used 20 times
flush_input defined in line 215; used 1 times
getcard defined in line 32; used 2 times
getyn defined in line 135; used 7 times
readch defined in line 204; used 6 times

Defined macros

NUMSAFE defined in line 17; used 3 times
_tty defined in line 10; never used
Last modified: 1986-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1323
Valid CSS Valid XHTML 1.0 Strict