|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)table.c 5.4 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include "back.h" ! 25: ! 26: char *help2[] = { ! 27: " Enter moves as <s>-<f> or <s>/<r> where <s> is the starting", ! 28: "position, <f> is the finishing position, and <r> is the roll.", ! 29: "Remember, each die roll must be moved separately.", ! 30: 0 ! 31: }; ! 32: ! 33: struct state { ! 34: char ch; ! 35: int fcode; ! 36: int newst; ! 37: }; ! 38: ! 39: struct state atmata[] = { ! 40: ! 41: 'R', 1, 0, '?', 7, 0, 'Q', 0, -3, 'B', 8, 25, ! 42: '9', 2, 25, '8', 2, 25, '7', 2, 25, '6', 2, 25, ! 43: '5', 2, 25, '4', 2, 25, '3', 2, 25, '2', 2, 19, ! 44: '1', 2, 15, '0', 2, 25, '.', 0, 0, '9', 2, 25, ! 45: '8', 2, 25, '7', 2, 25, '6', 2, 25, '5', 2, 25, ! 46: ! 47: '4', 2, 25, '3', 2, 25, '2', 2, 25, '1', 2, 25, ! 48: '0', 2, 25, '/', 0, 32, '-', 0, 39, '.', 0, 0, ! 49: '/', 5, 32, ' ', 6, 3, ',', 6, 3, '\n', 0, -1, ! 50: '6', 3, 28, '5', 3, 28, '4', 3, 28, '3', 3, 28, ! 51: '2', 3, 28, '1', 3, 28, '.', 0, 0, 'H', 9, 61, ! 52: ! 53: '9', 4, 61, '8', 4, 61, '7', 4, 61, '6', 4, 61, ! 54: '5', 4, 61, '4', 4, 61, '3', 4, 61, '2', 4, 53, ! 55: '1', 4, 51, '0', 4, 61, '.', 0, 0, '9', 4, 61, ! 56: '8', 4, 61, '7', 4, 61, '6', 4, 61, '5', 4, 61, ! 57: '4', 4, 61, '3', 4, 61, '2', 4, 61, '1', 4, 61, ! 58: ! 59: '0', 4, 61, ' ', 6, 3, ',', 6, 3, '-', 5, 39, ! 60: '\n', 0, -1, '.', 0, 0 ! 61: }; ! 62: ! 63: checkmove (ist) ! 64: ! 65: int ist; ! 66: ! 67: { ! 68: register int j, n; ! 69: register char c; ! 70: char a; ! 71: ! 72: domove: ! 73: if (ist == 0) { ! 74: if (tflag) ! 75: curmove (curr,32); ! 76: else ! 77: writel ("\t\t"); ! 78: writel ("Move: "); ! 79: } ! 80: ist = mvl = ncin = 0; ! 81: for (j = 0; j < 5; j++) ! 82: p[j] = g[j] = -1; ! 83: ! 84: dochar: ! 85: c = readc(); ! 86: ! 87: if (c == 'S') { ! 88: raflag = 0; ! 89: save (1); ! 90: if (tflag) { ! 91: curmove (cturn == -1? 18: 19,39); ! 92: ist = -1; ! 93: goto domove; ! 94: } else { ! 95: proll (); ! 96: ist = 0; ! 97: goto domove; ! 98: } ! 99: } ! 100: ! 101: if (c == tty.sg_erase && ncin > 0) { ! 102: if (tflag) ! 103: curmove (curr,curc-1); ! 104: else { ! 105: if (tty.sg_erase == '\010') ! 106: writel ("\010 \010"); ! 107: else ! 108: writec (cin[ncin-1]); ! 109: } ! 110: ncin--; ! 111: n = rsetbrd(); ! 112: if (n == 0) { ! 113: n = -1; ! 114: if (tflag) ! 115: refresh(); ! 116: } ! 117: if ((ist = n) > 0) ! 118: goto dochar; ! 119: goto domove; ! 120: } ! 121: ! 122: if (c == tty.sg_kill && ncin > 0) { ! 123: if (tflag) { ! 124: refresh(); ! 125: curmove (curr,39); ! 126: ist = -1; ! 127: goto domove; ! 128: } else if (tty.sg_erase == '\010') { ! 129: for (j = 0; j < ncin; j++) ! 130: writel ("\010 \010"); ! 131: ist = -1; ! 132: goto domove; ! 133: } else { ! 134: writec ('\\'); ! 135: writec ('\n'); ! 136: proll (); ! 137: ist = 0; ! 138: goto domove; ! 139: } ! 140: } ! 141: ! 142: n = dotable(c,ist); ! 143: if (n >= 0) { ! 144: cin[ncin++] = c; ! 145: if (n > 2) ! 146: if ((! tflag) || c != '\n') ! 147: writec (c); ! 148: ist = n; ! 149: if (n) ! 150: goto dochar; ! 151: else ! 152: goto domove; ! 153: } ! 154: ! 155: if (n == -1 && mvl >= mvlim) ! 156: return(0); ! 157: if (n == -1 && mvl < mvlim-1) ! 158: return(-4); ! 159: ! 160: if (n == -6) { ! 161: if (! tflag) { ! 162: if (movokay(mvl+1)) { ! 163: wrboard(); ! 164: movback (mvl+1); ! 165: } ! 166: proll (); ! 167: writel ("\t\tMove: "); ! 168: for (j = 0; j < ncin;) ! 169: writec (cin[j++]); ! 170: } else { ! 171: if (movokay(mvl+1)) { ! 172: refresh(); ! 173: movback (mvl+1); ! 174: } else ! 175: curmove (cturn == -1? 18:19,ncin+39); ! 176: } ! 177: ist = n = rsetbrd(); ! 178: goto dochar; ! 179: } ! 180: ! 181: if (n != -5) ! 182: return(n); ! 183: writec ('\007'); ! 184: goto dochar; ! 185: } ! 186: ! 187: dotable (c,i) ! 188: char c; ! 189: register int i; ! 190: ! 191: { ! 192: register int a, j; ! 193: int test; ! 194: ! 195: test = (c == 'R'); ! 196: ! 197: while ( (a = atmata[i].ch) != '.') { ! 198: if (a == c || (test && a == '\n')) { ! 199: switch (atmata[i].fcode) { ! 200: ! 201: case 1: ! 202: wrboard(); ! 203: if (tflag) { ! 204: curmove (cturn == -1? 18: 19,0); ! 205: proll (); ! 206: writel ("\t\t"); ! 207: } else ! 208: proll (); ! 209: break; ! 210: ! 211: case 2: ! 212: if (p[mvl] == -1) ! 213: p[mvl] = c-'0'; ! 214: else ! 215: p[mvl] = p[mvl]*10+c-'0'; ! 216: break; ! 217: ! 218: case 3: ! 219: if (g[mvl] != -1) { ! 220: if (mvl < mvlim) ! 221: mvl++; ! 222: p[mvl] = p[mvl-1]; ! 223: } ! 224: g[mvl] = p[mvl]+cturn*(c-'0'); ! 225: if (g[mvl] < 0) ! 226: g[mvl] = 0; ! 227: if (g[mvl] > 25) ! 228: g[mvl] = 25; ! 229: break; ! 230: ! 231: case 4: ! 232: if (g[mvl] == -1) ! 233: g[mvl] = c-'0'; ! 234: else ! 235: g[mvl] = g[mvl]*10+c-'0'; ! 236: break; ! 237: ! 238: case 5: ! 239: if (mvl < mvlim) ! 240: mvl++; ! 241: p[mvl] = g[mvl-1]; ! 242: break; ! 243: ! 244: case 6: ! 245: if (mvl < mvlim) ! 246: mvl++; ! 247: break; ! 248: ! 249: case 7: ! 250: if (tflag) ! 251: curmove (20,0); ! 252: else ! 253: writec ('\n'); ! 254: text (help2); ! 255: if (tflag) { ! 256: curmove (cturn == -1? 18: 19,39); ! 257: } else { ! 258: writec ('\n'); ! 259: proll(); ! 260: writel ("\t\tMove: "); ! 261: } ! 262: break; ! 263: ! 264: case 8: ! 265: p[mvl] = bar; ! 266: break; ! 267: ! 268: case 9: ! 269: g[mvl] = home; ! 270: } ! 271: ! 272: if (! test || a != '\n') ! 273: return (atmata[i].newst); ! 274: else ! 275: return (-6); ! 276: } ! 277: ! 278: i++; ! 279: } ! 280: ! 281: return (-5); ! 282: } ! 283: ! 284: rsetbrd () { ! 285: register int i, j, n; ! 286: ! 287: n = 0; ! 288: mvl = 0; ! 289: for (i = 0; i < 4; i++) ! 290: p[i] = g[i] = -1; ! 291: for (j = 0; j < ncin; j++) ! 292: n = dotable (cin[j],n); ! 293: return (n); ! 294: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.