121218Sdist /* 221218Sdist * Copyright (c) 1980 Regents of the University of California. 3*33487Sbostic * All rights reserved. 4*33487Sbostic * 5*33487Sbostic * Redistribution and use in source and binary forms are permitted 6*33487Sbostic * provided that this notice is preserved and that due credit is given 7*33487Sbostic * to the University of California at Berkeley. The name of the University 8*33487Sbostic * may not be used to endorse or promote products derived from this 9*33487Sbostic * software without specific prior written permission. This software 10*33487Sbostic * is provided ``as is'' without express or implied warranty. 1121218Sdist */ 126767Srrh 1321218Sdist #ifndef lint 14*33487Sbostic static char sccsid[] = "@(#)table.c 5.2 (Berkeley) 02/16/88"; 15*33487Sbostic #endif /* not lint */ 1621218Sdist 176767Srrh #include "back.h" 186767Srrh 196767Srrh char *help2[] = { 206767Srrh " Enter moves as <s>-<f> or <s>/<r> where <s> is the starting", 216767Srrh "position, <f> is the finishing position, and <r> is the roll.", 226767Srrh "Remember, each die roll must be moved separately.", 236767Srrh 0 246767Srrh }; 256767Srrh 266767Srrh struct state { 276767Srrh char ch; 286767Srrh int fcode; 296767Srrh int newst; 306767Srrh }; 316767Srrh 326767Srrh struct state atmata[] = { 336767Srrh 346767Srrh 'R', 1, 0, '?', 7, 0, 'Q', 0, -3, 'B', 8, 25, 356767Srrh '9', 2, 25, '8', 2, 25, '7', 2, 25, '6', 2, 25, 366767Srrh '5', 2, 25, '4', 2, 25, '3', 2, 25, '2', 2, 19, 376767Srrh '1', 2, 15, '0', 2, 25, '.', 0, 0, '9', 2, 25, 386767Srrh '8', 2, 25, '7', 2, 25, '6', 2, 25, '5', 2, 25, 396767Srrh 406767Srrh '4', 2, 25, '3', 2, 25, '2', 2, 25, '1', 2, 25, 416767Srrh '0', 2, 25, '/', 0, 32, '-', 0, 39, '.', 0, 0, 426767Srrh '/', 5, 32, ' ', 6, 3, ',', 6, 3, '\n', 0, -1, 436767Srrh '6', 3, 28, '5', 3, 28, '4', 3, 28, '3', 3, 28, 446767Srrh '2', 3, 28, '1', 3, 28, '.', 0, 0, 'H', 9, 61, 456767Srrh 466767Srrh '9', 4, 61, '8', 4, 61, '7', 4, 61, '6', 4, 61, 476767Srrh '5', 4, 61, '4', 4, 61, '3', 4, 61, '2', 4, 53, 486767Srrh '1', 4, 51, '0', 4, 61, '.', 0, 0, '9', 4, 61, 496767Srrh '8', 4, 61, '7', 4, 61, '6', 4, 61, '5', 4, 61, 506767Srrh '4', 4, 61, '3', 4, 61, '2', 4, 61, '1', 4, 61, 516767Srrh 526767Srrh '0', 4, 61, ' ', 6, 3, ',', 6, 3, '-', 5, 39, 536767Srrh '\n', 0, -1, '.', 0, 0 546767Srrh }; 556767Srrh 566767Srrh checkmove (ist) 576767Srrh 586767Srrh int ist; 596767Srrh 606767Srrh { 616767Srrh register int j, n; 626767Srrh register char c; 636767Srrh char a; 646767Srrh 656767Srrh domove: 666767Srrh if (ist == 0) { 676767Srrh if (tflag) 686767Srrh curmove (curr,32); 696767Srrh else 706767Srrh writel ("\t\t"); 716767Srrh writel ("Move: "); 726767Srrh } 736767Srrh ist = mvl = ncin = 0; 746767Srrh for (j = 0; j < 5; j++) 756767Srrh p[j] = g[j] = -1; 766767Srrh 776767Srrh dochar: 786767Srrh c = readc(); 796767Srrh 806767Srrh if (c == 'S') { 816767Srrh raflag = 0; 826767Srrh save (1); 836767Srrh if (tflag) { 846767Srrh curmove (cturn == -1? 18: 19,39); 856767Srrh ist = -1; 866767Srrh goto domove; 876767Srrh } else { 886767Srrh proll (); 896767Srrh ist = 0; 906767Srrh goto domove; 916767Srrh } 926767Srrh } 936767Srrh 946767Srrh if (c == tty.sg_erase && ncin > 0) { 956767Srrh if (tflag) 966767Srrh curmove (curr,curc-1); 976767Srrh else { 986767Srrh if (tty.sg_erase == '\010') 996767Srrh writel ("\010 \010"); 1006767Srrh else 1016767Srrh writec (cin[ncin-1]); 1026767Srrh } 1036767Srrh ncin--; 1046767Srrh n = rsetbrd(); 1056767Srrh if (n == 0) { 1066767Srrh n = -1; 1076767Srrh if (tflag) 1086767Srrh refresh(); 1096767Srrh } 1106767Srrh if ((ist = n) > 0) 1116767Srrh goto dochar; 1126767Srrh goto domove; 1136767Srrh } 1146767Srrh 1156767Srrh if (c == tty.sg_kill && ncin > 0) { 1166767Srrh if (tflag) { 1176767Srrh refresh(); 1186767Srrh curmove (curr,39); 1196767Srrh ist = -1; 1206767Srrh goto domove; 1216767Srrh } else if (tty.sg_erase == '\010') { 1226767Srrh for (j = 0; j < ncin; j++) 1236767Srrh writel ("\010 \010"); 1246767Srrh ist = -1; 1256767Srrh goto domove; 1266767Srrh } else { 1276767Srrh writec ('\\'); 1286767Srrh writec ('\n'); 1296767Srrh proll (); 1306767Srrh ist = 0; 1316767Srrh goto domove; 1326767Srrh } 1336767Srrh } 1346767Srrh 1356767Srrh n = dotable(c,ist); 1366767Srrh if (n >= 0) { 1376767Srrh cin[ncin++] = c; 1386767Srrh if (n > 2) 1396767Srrh if ((! tflag) || c != '\n') 1406767Srrh writec (c); 1416767Srrh ist = n; 1426767Srrh if (n) 1436767Srrh goto dochar; 1446767Srrh else 1456767Srrh goto domove; 1466767Srrh } 1476767Srrh 1486767Srrh if (n == -1 && mvl >= mvlim) 1496767Srrh return(0); 1506767Srrh if (n == -1 && mvl < mvlim-1) 1516767Srrh return(-4); 1526767Srrh 1536767Srrh if (n == -6) { 1546767Srrh if (! tflag) { 1556767Srrh if (movokay(mvl+1)) { 1566767Srrh wrboard(); 1576767Srrh movback (mvl+1); 1586767Srrh } 1596767Srrh proll (); 1606767Srrh writel ("\t\tMove: "); 1616767Srrh for (j = 0; j < ncin;) 1626767Srrh writec (cin[j++]); 1636767Srrh } else { 1646767Srrh if (movokay(mvl+1)) { 1656767Srrh refresh(); 1666767Srrh movback (mvl+1); 1676767Srrh } else 1686767Srrh curmove (cturn == -1? 18:19,ncin+39); 1696767Srrh } 1706767Srrh ist = n = rsetbrd(); 1716767Srrh goto dochar; 1726767Srrh } 1736767Srrh 1746767Srrh if (n != -5) 1756767Srrh return(n); 1766767Srrh writec ('\007'); 1776767Srrh goto dochar; 1786767Srrh } 1796767Srrh 1806767Srrh dotable (c,i) 1816767Srrh char c; 1826767Srrh register int i; 1836767Srrh 1846767Srrh { 1856767Srrh register int a, j; 1866767Srrh int test; 1876767Srrh 1886767Srrh test = (c == 'R'); 1896767Srrh 1906767Srrh while ( (a = atmata[i].ch) != '.') { 1916767Srrh if (a == c || (test && a == '\n')) { 1926767Srrh switch (atmata[i].fcode) { 1936767Srrh 1946767Srrh case 1: 1956767Srrh wrboard(); 1966767Srrh if (tflag) { 1976767Srrh curmove (cturn == -1? 18: 19,0); 1986767Srrh proll (); 1996767Srrh writel ("\t\t"); 2006767Srrh } else 2016767Srrh proll (); 2026767Srrh break; 2036767Srrh 2046767Srrh case 2: 2056767Srrh if (p[mvl] == -1) 2066767Srrh p[mvl] = c-'0'; 2076767Srrh else 2086767Srrh p[mvl] = p[mvl]*10+c-'0'; 2096767Srrh break; 2106767Srrh 2116767Srrh case 3: 2126767Srrh if (g[mvl] != -1) { 2136767Srrh if (mvl < mvlim) 2146767Srrh mvl++; 2156767Srrh p[mvl] = p[mvl-1]; 2166767Srrh } 2176767Srrh g[mvl] = p[mvl]+cturn*(c-'0'); 2186767Srrh if (g[mvl] < 0) 2196767Srrh g[mvl] = 0; 2206767Srrh if (g[mvl] > 25) 2216767Srrh g[mvl] = 25; 2226767Srrh break; 2236767Srrh 2246767Srrh case 4: 2256767Srrh if (g[mvl] == -1) 2266767Srrh g[mvl] = c-'0'; 2276767Srrh else 2286767Srrh g[mvl] = g[mvl]*10+c-'0'; 2296767Srrh break; 2306767Srrh 2316767Srrh case 5: 2326767Srrh if (mvl < mvlim) 2336767Srrh mvl++; 2346767Srrh p[mvl] = g[mvl-1]; 2356767Srrh break; 2366767Srrh 2376767Srrh case 6: 2386767Srrh if (mvl < mvlim) 2396767Srrh mvl++; 2406767Srrh break; 2416767Srrh 2426767Srrh case 7: 2436767Srrh if (tflag) 2446767Srrh curmove (20,0); 2456767Srrh else 2466767Srrh writec ('\n'); 2476767Srrh text (help2); 2486767Srrh if (tflag) { 2496767Srrh curmove (cturn == -1? 18: 19,39); 2506767Srrh } else { 2516767Srrh writec ('\n'); 2526767Srrh proll(); 2536767Srrh writel ("\t\tMove: "); 2546767Srrh } 2556767Srrh break; 2566767Srrh 2576767Srrh case 8: 2586767Srrh p[mvl] = bar; 2596767Srrh break; 2606767Srrh 2616767Srrh case 9: 2626767Srrh g[mvl] = home; 2636767Srrh } 2646767Srrh 2656767Srrh if (! test || a != '\n') 2666767Srrh return (atmata[i].newst); 2676767Srrh else 2686767Srrh return (-6); 2696767Srrh } 2706767Srrh 2716767Srrh i++; 2726767Srrh } 2736767Srrh 2746767Srrh return (-5); 2756767Srrh } 2766767Srrh 2776767Srrh rsetbrd () { 2786767Srrh register int i, j, n; 2796767Srrh 2806767Srrh n = 0; 2816767Srrh mvl = 0; 2826767Srrh for (i = 0; i < 4; i++) 2836767Srrh p[i] = g[i] = -1; 2846767Srrh for (j = 0; j < ncin; j++) 2856767Srrh n = dotable (cin[j],n); 2866767Srrh return (n); 2876767Srrh } 288