1 /* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 05/31/93"; 10 #endif /* not lint */ 11 12 #include "back.h" 13 14 char *help2[] = { 15 " Enter moves as <s>-<f> or <s>/<r> where <s> is the starting", 16 "position, <f> is the finishing position, and <r> is the roll.", 17 "Remember, each die roll must be moved separately.", 18 0 19 }; 20 21 struct state { 22 char ch; 23 int fcode; 24 int newst; 25 }; 26 27 struct state atmata[] = { 28 29 'R', 1, 0, '?', 7, 0, 'Q', 0, -3, 'B', 8, 25, 30 '9', 2, 25, '8', 2, 25, '7', 2, 25, '6', 2, 25, 31 '5', 2, 25, '4', 2, 25, '3', 2, 25, '2', 2, 19, 32 '1', 2, 15, '0', 2, 25, '.', 0, 0, '9', 2, 25, 33 '8', 2, 25, '7', 2, 25, '6', 2, 25, '5', 2, 25, 34 35 '4', 2, 25, '3', 2, 25, '2', 2, 25, '1', 2, 25, 36 '0', 2, 25, '/', 0, 32, '-', 0, 39, '.', 0, 0, 37 '/', 5, 32, ' ', 6, 3, ',', 6, 3, '\n', 0, -1, 38 '6', 3, 28, '5', 3, 28, '4', 3, 28, '3', 3, 28, 39 '2', 3, 28, '1', 3, 28, '.', 0, 0, 'H', 9, 61, 40 41 '9', 4, 61, '8', 4, 61, '7', 4, 61, '6', 4, 61, 42 '5', 4, 61, '4', 4, 61, '3', 4, 61, '2', 4, 53, 43 '1', 4, 51, '0', 4, 61, '.', 0, 0, '9', 4, 61, 44 '8', 4, 61, '7', 4, 61, '6', 4, 61, '5', 4, 61, 45 '4', 4, 61, '3', 4, 61, '2', 4, 61, '1', 4, 61, 46 47 '0', 4, 61, ' ', 6, 3, ',', 6, 3, '-', 5, 39, 48 '\n', 0, -1, '.', 0, 0 49 }; 50 51 checkmove (ist) 52 53 int ist; 54 55 { 56 register int j, n; 57 register char c; 58 char a; 59 60 domove: 61 if (ist == 0) { 62 if (tflag) 63 curmove (curr,32); 64 else 65 writel ("\t\t"); 66 writel ("Move: "); 67 } 68 ist = mvl = ncin = 0; 69 for (j = 0; j < 5; j++) 70 p[j] = g[j] = -1; 71 72 dochar: 73 c = readc(); 74 75 if (c == 'S') { 76 raflag = 0; 77 save (1); 78 if (tflag) { 79 curmove (cturn == -1? 18: 19,39); 80 ist = -1; 81 goto domove; 82 } else { 83 proll (); 84 ist = 0; 85 goto domove; 86 } 87 } 88 89 if (c == tty.sg_erase && ncin > 0) { 90 if (tflag) 91 curmove (curr,curc-1); 92 else { 93 if (tty.sg_erase == '\010') 94 writel ("\010 \010"); 95 else 96 writec (cin[ncin-1]); 97 } 98 ncin--; 99 n = rsetbrd(); 100 if (n == 0) { 101 n = -1; 102 if (tflag) 103 refresh(); 104 } 105 if ((ist = n) > 0) 106 goto dochar; 107 goto domove; 108 } 109 110 if (c == tty.sg_kill && ncin > 0) { 111 if (tflag) { 112 refresh(); 113 curmove (curr,39); 114 ist = -1; 115 goto domove; 116 } else if (tty.sg_erase == '\010') { 117 for (j = 0; j < ncin; j++) 118 writel ("\010 \010"); 119 ist = -1; 120 goto domove; 121 } else { 122 writec ('\\'); 123 writec ('\n'); 124 proll (); 125 ist = 0; 126 goto domove; 127 } 128 } 129 130 n = dotable(c,ist); 131 if (n >= 0) { 132 cin[ncin++] = c; 133 if (n > 2) 134 if ((! tflag) || c != '\n') 135 writec (c); 136 ist = n; 137 if (n) 138 goto dochar; 139 else 140 goto domove; 141 } 142 143 if (n == -1 && mvl >= mvlim) 144 return(0); 145 if (n == -1 && mvl < mvlim-1) 146 return(-4); 147 148 if (n == -6) { 149 if (! tflag) { 150 if (movokay(mvl+1)) { 151 wrboard(); 152 movback (mvl+1); 153 } 154 proll (); 155 writel ("\t\tMove: "); 156 for (j = 0; j < ncin;) 157 writec (cin[j++]); 158 } else { 159 if (movokay(mvl+1)) { 160 refresh(); 161 movback (mvl+1); 162 } else 163 curmove (cturn == -1? 18:19,ncin+39); 164 } 165 ist = n = rsetbrd(); 166 goto dochar; 167 } 168 169 if (n != -5) 170 return(n); 171 writec ('\007'); 172 goto dochar; 173 } 174 175 dotable (c,i) 176 char c; 177 register int i; 178 179 { 180 register int a, j; 181 int test; 182 183 test = (c == 'R'); 184 185 while ( (a = atmata[i].ch) != '.') { 186 if (a == c || (test && a == '\n')) { 187 switch (atmata[i].fcode) { 188 189 case 1: 190 wrboard(); 191 if (tflag) { 192 curmove (cturn == -1? 18: 19,0); 193 proll (); 194 writel ("\t\t"); 195 } else 196 proll (); 197 break; 198 199 case 2: 200 if (p[mvl] == -1) 201 p[mvl] = c-'0'; 202 else 203 p[mvl] = p[mvl]*10+c-'0'; 204 break; 205 206 case 3: 207 if (g[mvl] != -1) { 208 if (mvl < mvlim) 209 mvl++; 210 p[mvl] = p[mvl-1]; 211 } 212 g[mvl] = p[mvl]+cturn*(c-'0'); 213 if (g[mvl] < 0) 214 g[mvl] = 0; 215 if (g[mvl] > 25) 216 g[mvl] = 25; 217 break; 218 219 case 4: 220 if (g[mvl] == -1) 221 g[mvl] = c-'0'; 222 else 223 g[mvl] = g[mvl]*10+c-'0'; 224 break; 225 226 case 5: 227 if (mvl < mvlim) 228 mvl++; 229 p[mvl] = g[mvl-1]; 230 break; 231 232 case 6: 233 if (mvl < mvlim) 234 mvl++; 235 break; 236 237 case 7: 238 if (tflag) 239 curmove (20,0); 240 else 241 writec ('\n'); 242 text (help2); 243 if (tflag) { 244 curmove (cturn == -1? 18: 19,39); 245 } else { 246 writec ('\n'); 247 proll(); 248 writel ("\t\tMove: "); 249 } 250 break; 251 252 case 8: 253 p[mvl] = bar; 254 break; 255 256 case 9: 257 g[mvl] = home; 258 } 259 260 if (! test || a != '\n') 261 return (atmata[i].newst); 262 else 263 return (-6); 264 } 265 266 i++; 267 } 268 269 return (-5); 270 } 271 272 rsetbrd () { 273 register int i, j, n; 274 275 n = 0; 276 mvl = 0; 277 for (i = 0; i < 4; i++) 278 p[i] = g[i] = -1; 279 for (j = 0; j < ncin; j++) 280 n = dotable (cin[j],n); 281 return (n); 282 } 283