19895Ssam #ifndef lint 2*20195Smckusick static char sccsid[] = "@(#)boggle.c 4.2 05/13/85"; 39895Ssam #endif 49895Ssam 59895Ssam #include <ctype.h> 69895Ssam #include <errno.h> 79895Ssam #include <setjmp.h> 89895Ssam #include <sgtty.h> 99895Ssam #include <signal.h> 109895Ssam #include <stdio.h> 119895Ssam 129895Ssam /* basic parameters */ 139895Ssam #define N 4 149895Ssam #define SSIZE 200 159895Ssam #define MAXWORDS 1000 169895Ssam #define CWIDTH 10 179895Ssam #define LWIDTH 80 189895Ssam 199895Ssam /* parameters defined in terms of above */ 209895Ssam #define BSIZE (N*N) 219895Ssam #define row(x) (x/N) 229895Ssam #define col(x) (x%N) 239895Ssam 249895Ssam /* word being searched for */ 259895Ssam int wlength; 269895Ssam int numsame; 279895Ssam char wbuff [BSIZE+1]; 289895Ssam 299895Ssam /* tty and process control */ 309895Ssam extern int errno; 319895Ssam int status; 329895Ssam int pipefd[2]; 339895Ssam int super = 0; 349895Ssam int delct = 1; 359895Ssam int zero = 0; 369895Ssam int master = 1; 379895Ssam int column; 389895Ssam int *timept; 399895Ssam int timeint[] = {60,60,50,7,1,1,1,0}; 409895Ssam long timein; 419895Ssam extern long int time(); 429895Ssam struct sgttyb origttyb, tempttyb; 439895Ssam int ctlecho = 0; 449895Ssam int lctlech = LCTLECH; 459895Ssam jmp_buf env; 469895Ssam 479895Ssam /* monitoring variables */ 489895Ssam int games; 499895Ssam int logfile = -1; 509895Ssam long logloc; 519895Ssam char logbuff[100] = {"inst\t"}; 529895Ssam extern char *ctime(), *getlogin(); 539895Ssam extern long lseek(); 549895Ssam 559895Ssam /* dictionary interface */ 569895Ssam char defname[] = "/usr/games/bogdict"; 579895Ssam char *dictname = &defname[0]; 589895Ssam FILE *dict; 599895Ssam 609895Ssam /* structures for doing matching */ 619895Ssam struct frame { 629895Ssam struct frame *parent; 639895Ssam int place; 649895Ssam }; 659895Ssam struct frame stack [SSIZE]; 669895Ssam struct frame *level [BSIZE+1]; 679895Ssam 689895Ssam /* the board and subsidiary structures */ 699895Ssam char present [BSIZE+1]; 709895Ssam char board [BSIZE]; 719895Ssam char olink [BSIZE]; 729895Ssam char adj [BSIZE+1][BSIZE]; 739895Ssam char occurs [26]; 749895Ssam 759895Ssam /* the boggle cubes */ 769895Ssam char *cube [BSIZE] = { 779895Ssam "forixb", "moqabj", "gurilw", "setupl", 789895Ssam "cmpdae", "acitao", "slcrae", "romash", 799895Ssam "nodesw", "hefiye", "onudtk", "tevign", 809895Ssam "anedvz", "pinesh", "abilyt", "gkyleu" 819895Ssam }; 829895Ssam 839895Ssam 849895Ssam /* storage for words found */ 859895Ssam int ubotch, ustart, wcount; 869895Ssam char *word [MAXWORDS]; 879895Ssam char *freesp; 889895Ssam char space[10000]; 899895Ssam 909895Ssam endline () 919895Ssam { 929895Ssam if (column != 0) { 939895Ssam putchar('\n'); 949895Ssam column = 0; 959895Ssam } 969895Ssam } 979895Ssam 989895Ssam timeout () 999895Ssam { 1009895Ssam if (*timept > 0) { 1019895Ssam signal (SIGALRM, timeout); 1029895Ssam alarm(*timept++); 1039895Ssam } 1049895Ssam putchar('\007'); 1059895Ssam } 1069895Ssam 1079895Ssam interrupt () 1089895Ssam { 1099895Ssam signal(SIGINT, interrupt); 1109895Ssam if (delct++ >= 1) 1119895Ssam longjmp(env, 1); 1129895Ssam timept = &zero; 1139895Ssam } 1149895Ssam 1159895Ssam goodbye (stat) 1169895Ssam int stat; 1179895Ssam { 1189895Ssam if (master != 0) { 1199895Ssam wait(&status); 1209895Ssam if ( ctlecho & LCTLECH ) { 1219895Ssam ioctl( fileno(stdin), TIOCLBIS, &lctlech ); 1229895Ssam } 1239895Ssam stty(fileno(stdin), &origttyb); 1249895Ssam } 1259895Ssam exit(stat); 1269895Ssam } 1279895Ssam 1289895Ssam clearscreen () 1299895Ssam { 1309895Ssam stty (fileno(stdin), &tempttyb); 1319895Ssam printf("\n\033\f\r"); 1329895Ssam } 1339895Ssam 1349895Ssam compare (a, b) 1359895Ssam char **a, **b; 1369895Ssam { 1379895Ssam return(wordcomp(*a, *b)); 1389895Ssam } 1399895Ssam 1409895Ssam wordcomp (p, q) 1419895Ssam register char *p, *q; 1429895Ssam { 1439895Ssam if (*p=='0' && *q!='0') 1449895Ssam return(-1); 1459895Ssam if (*p!='0' && *q=='0') 1469895Ssam return(1); 1479895Ssam while (*++p == *++q && isalpha(*p)) ; 1489895Ssam if (!isalpha(*p)) 1499895Ssam return(-isalpha(*q)); 1509895Ssam if (!isalpha(*q)) 1519895Ssam return(1); 1529895Ssam return(*p-*q); 1539895Ssam } 1549895Ssam 1559895Ssam printinst () 1569895Ssam { 1579895Ssam stty (fileno(stdin), &tempttyb); 1589895Ssam printf("instructions?"); 1599895Ssam if (getchar() == 'y') { 1609895Ssam clearscreen(); 1619895Ssam printf(" The object of Boggle (TM Parker Bros.) is to find, within 3\n"); 1629895Ssam printf("minutes, as many words as possible in a 4 by 4 grid of letters. Words\n"); 1639895Ssam printf("may be formed from any sequence of 3 or more adjacent letters in the\n"); 1649895Ssam printf("grid. The letters may join horizontally, vertically, or diagonally.\n"); 1659895Ssam printf("However, no position in the grid may be used more than once within any\n"); 1669895Ssam printf("one word. In competitive play amongst humans, each player is given\n"); 1679895Ssam printf("credit for those of his words which no other player has found.\n"); 1689895Ssam printf(" This program is intended for people wishing to sharpen their\n"); 1699895Ssam printf("skills at Boggle. If you invoke the program with 4 arguments of 4\n"); 1709895Ssam printf("letters each, (e.g. \"boggle appl epie moth erhd\") the program forms the\n"); 1719895Ssam printf("obvious Boggle grid and lists all the words from /usr/dict/words found\n"); 1729895Ssam printf("therein. If you invoke the program without arguments, it will generate\n"); 1739895Ssam printf("a board for you, let you enter words for 3 minutes, and then tell you\n"); 1749895Ssam printf("how well you did relative to /usr/dict/words.\n"); 1759895Ssam printf(" In interactive play, enter your words separated by spaces, tabs,\n"); 1769895Ssam printf("or newlines. A bell will ring when there is 2:00, 1:00, 0:10, 0:02,\n"); 1779895Ssam printf("0:01, and 0:00 time left. You may complete any word started before the\n"); 1789895Ssam printf("expiration of time. You can surrender before time is up by hitting\n"); 1799895Ssam printf("'break'. While entering words, your erase character is only effective\n"); 1809895Ssam printf("within the current word and your line kill character is ignored.\n"); 1819895Ssam printf(" Advanced players may wish to invoke the program with 1 or 2 +'s as\n"); 182*20195Smckusick printf("the first argument. The first + removes the restriction that positions\n"); 1839895Ssam printf("can only be used once in each word. The second + causes a position to\n"); 1849895Ssam printf("be considered adjacent to itself as well as its (up to) 8 neighbors.\n"); 1859895Ssam printf("Hit any key to begin.\n"); 1869895Ssam stty (fileno(stdin), &tempttyb); 1879895Ssam getchar(); 1889895Ssam } 1899895Ssam stty (fileno(stdin), &tempttyb); 1909895Ssam } 1919895Ssam 1929895Ssam setup () 1939895Ssam { 1949895Ssam register int i, j; 1959895Ssam int rd, cd, k; 1969895Ssam for (i=0; i<BSIZE; i++) { 1979895Ssam adj[i][i] = super>=2 ? 1 : 0; 1989895Ssam adj[BSIZE][i] = 1; 1999895Ssam for (j=0; j<i; j++) { 2009895Ssam rd = row(i)-row(j); 2019895Ssam cd = col(i)-col(j); 2029895Ssam k = 0; 2039895Ssam switch (rd) { 2049895Ssam case -1: 2059895Ssam case 1: 2069895Ssam if (-1<=cd && cd<=1) 2079895Ssam k = 1; 2089895Ssam break; 2099895Ssam case 0: 2109895Ssam if (cd==-1 || cd==1) 2119895Ssam k = 1; 2129895Ssam break; 2139895Ssam } 2149895Ssam adj[i][j] = adj[j][i] = k; 2159895Ssam } 2169895Ssam } 2179895Ssam stack[0].parent = &stack[0]; 2189895Ssam stack[0].place = BSIZE; 2199895Ssam level[0] = &stack[0]; 2209895Ssam level[1] = &stack[1]; 2219895Ssam } 2229895Ssam 2239895Ssam makelists () 2249895Ssam { 2259895Ssam register int i, c; 2269895Ssam for (i=0; i<26; i++) 2279895Ssam occurs[i] = BSIZE; 2289895Ssam for (i=0; i<BSIZE; i++) { 2299895Ssam c = board[i]; 2309895Ssam olink[i] = occurs[c-'a']; 2319895Ssam occurs[c-'a'] = i; 2329895Ssam } 2339895Ssam } 2349895Ssam 2359895Ssam genboard () 2369895Ssam { 2379895Ssam register int i, j; 2389895Ssam for (i=0; i<BSIZE; i++) 2399895Ssam board[i] = 0; 2409895Ssam for (i=0; i<BSIZE; i++) { 2419895Ssam j = rand()%BSIZE; 2429895Ssam while (board[j] != 0) 2439895Ssam j = (j+1)%BSIZE; 2449895Ssam board[j] = cube[i][rand()%6]; 2459895Ssam } 2469895Ssam } 2479895Ssam 2489895Ssam printboard () 2499895Ssam { 2509895Ssam register int i, j; 2519895Ssam for (i=0; i<N; i++) { 2529895Ssam printf("\t\t\t\t\b\b"); 2539895Ssam for (j=0; j<N; j++) { 2549895Ssam putchar ((putchar(board[i*N+j]) == 'q') ? 'u' : ' '); 2559895Ssam putchar(' '); 2569895Ssam } 2579895Ssam putchar('\n'); 2589895Ssam } 2599895Ssam putchar('\n'); 2609895Ssam } 2619895Ssam 2629895Ssam getdword () 2639895Ssam { 2649895Ssam /* input: numsame = # chars same as last word */ 2659895Ssam /* output: numsame = # same chars for next word */ 2669895Ssam /* word in wbuff[0]...wbuff[wlength-1] */ 2679895Ssam register int c; 2689895Ssam register char *p; 2699895Ssam if (numsame == EOF) 2709895Ssam return (0); 2719895Ssam p = &wbuff[numsame]+1; 2729895Ssam while ((*p++ = c = getc(dict)) != EOF && isalpha(c)) ; 2739895Ssam numsame = c; 2749895Ssam wlength = p - &wbuff[2]; 2759895Ssam return (1); 2769895Ssam } 2779895Ssam 2789895Ssam getuword () 2799895Ssam { 2809895Ssam int c; 2819895Ssam register char *p, *q, *r; 2829895Ssam numsame = 0; 2839895Ssam while (*timept>0 && (isspace(c=getchar()) || c==EOF)); 2849895Ssam if (*timept == 0) 2859895Ssam return(0); 2869895Ssam word[wcount++] = freesp; 2879895Ssam *freesp++ = '0'; 2889895Ssam r = &wbuff[1]; 2899895Ssam q = p = freesp; 2909895Ssam *p++ = c; 2919895Ssam while (!isspace(c = getchar())) { 2929895Ssam if (c == EOF) 2939895Ssam continue; 2949895Ssam if (c == origttyb.sg_erase) { 2959895Ssam if (p > q) 2969895Ssam p--; 2979895Ssam continue; 2989895Ssam } 2999895Ssam *p++ = c; 3009895Ssam } 3019895Ssam freesp = p; 3029895Ssam for (p=q; p<freesp && r<&wbuff[BSIZE]; ) 3039895Ssam if (islower(c = *p++) && (*r++ = *q++ = c) == 'q' && *p == 'u') 3049895Ssam p++; 3059895Ssam *(freesp = q) = '0'; 3069895Ssam wlength = r-&wbuff[1]; 3079895Ssam return(1); 3089895Ssam } 3099895Ssam 3109895Ssam aputuword (ways) 3119895Ssam int ways; 3129895Ssam { 3139895Ssam *word[wcount-1] = ways>=10 ? '*' : '0'+ways; 3149895Ssam } 3159895Ssam 3169895Ssam aputword (ways) 3179895Ssam int ways; 3189895Ssam { 3199895Ssam /* store (wbuff, ways) in next slot in space */ 3209895Ssam register int i; 3219895Ssam *freesp++ = ways>=10 ? '*' : '0'+ways; 3229895Ssam for (i=1; i<= wlength; i++) 3239895Ssam *freesp++ = wbuff[i]; 3249895Ssam word[++wcount] = freesp; 3259895Ssam } 3269895Ssam 3279895Ssam tputword (ways) 3289895Ssam int ways; 3299895Ssam { 3309895Ssam /* print (wbuff, ways) on terminal */ 3319895Ssam wbuff[wlength+1] = '0'; 3329895Ssam wbuff[0] = ways>=10 ? '*' : '0'+ways; 3339895Ssam outword(&wbuff[0]); 3349895Ssam } 3359895Ssam 3369895Ssam outword (p) 3379895Ssam register char *p; 3389895Ssam { 3399895Ssam register int newcol; 3409895Ssam register char *q; 3419895Ssam for (q=p+1; isalpha(*q); ) { 3429895Ssam putchar(*q); 3439895Ssam if (*q++ == 'q') { 3449895Ssam putchar('u'); 3459895Ssam column++; 3469895Ssam } 3479895Ssam } 3489895Ssam column += q-p-1; 3499895Ssam if (column > LWIDTH-CWIDTH) { 3509895Ssam putchar('\n'); 3519895Ssam column = 0; 3529895Ssam return; 3539895Ssam } 3549895Ssam newcol = ((column+CWIDTH)/CWIDTH)*CWIDTH; 3559895Ssam while (((column+8)/8)*8 <= newcol) { 3569895Ssam putchar('\t'); 3579895Ssam column = ((column+8)/8)*8; 3589895Ssam } 3599895Ssam while (column < newcol) { 3609895Ssam putchar(' '); 3619895Ssam column++; 3629895Ssam } 3639895Ssam } 3649895Ssam 3659895Ssam printdiff () 3669895Ssam { 3679895Ssam register int c, d, u; 3689895Ssam char both, donly, uonly; 3699895Ssam word[wcount] = freesp; 3709895Ssam *freesp = '0'; 3719895Ssam both = donly = uonly = column = d = 0; 3729895Ssam u = ustart; 3739895Ssam while (d < ubotch) { 3749895Ssam c = u<wcount ? wordcomp (word[d], word[u]) : -1; 3759895Ssam if (c == 0) { 3769895Ssam /* dict and user found same word */ 3779895Ssam if (both == 0) { 3789895Ssam both = 1; 3799895Ssam printf("\t\t\t we both found:\n"); 3809895Ssam } 3819895Ssam outword(word[d]); 3829895Ssam word[d++] = NULL; 3839895Ssam word[u++] = NULL; 3849895Ssam } else if (c < 0) { 3859895Ssam /* dict found it, user didn't */ 3869895Ssam donly = 1; 3879895Ssam d++; 3889895Ssam } else { 3899895Ssam /* user found it, dict didn't */ 3909895Ssam uonly = 1; 3919895Ssam u++; 3929895Ssam } 3939895Ssam } 3949895Ssam endline(); 3959895Ssam if (donly) { 3969895Ssam printf("\n\t\t\tI alone found these:\n"); 3979895Ssam for (d=0; d<ubotch; d++) 3989895Ssam if (word[d] != NULL) 3999895Ssam outword(word[d]); 4009895Ssam endline(); 4019895Ssam } 4029895Ssam if (uonly) { 4039895Ssam printf("\n\t\t\tyou alone found these:\n"); 4049895Ssam for (u=ustart; u<wcount; u++) 4059895Ssam if (word[u] != NULL) 4069895Ssam outword(word[u]); 4079895Ssam endline(); 4089895Ssam } 4099895Ssam if (ubotch < ustart) { 4109895Ssam printf("\n\t\t\t you botched these:\n"); 4119895Ssam for (u=ubotch; u<ustart; u++) 4129895Ssam outword(word[u]); 4139895Ssam endline(); 4149895Ssam } 4159895Ssam } 4169895Ssam 4179895Ssam numways (leaf, last) 4189895Ssam register struct frame *leaf; 4199895Ssam struct frame *last; 4209895Ssam { 4219895Ssam int count; 4229895Ssam register char *p; 4239895Ssam register struct frame *node; 4249895Ssam if (super > 0) 4259895Ssam return(last-leaf); 4269895Ssam count = 0; 4279895Ssam present[BSIZE] = 1; 4289895Ssam while (leaf < last) { 4299895Ssam for (p = &present[0]; p < &present[BSIZE]; *p++ = 0); 4309895Ssam for (node = leaf; present[node->place]++ == 0; node = node->parent); 4319895Ssam if (node == &stack[0]) 4329895Ssam count++; 4339895Ssam leaf++; 4349895Ssam } 4359895Ssam return(count); 4369895Ssam } 4379895Ssam 4389895Ssam evalboard (getword, putword) 4399895Ssam int (*getword)(), (*putword)(); 4409895Ssam { 4419895Ssam register struct frame *top; 4429895Ssam register int l, q; 4439895Ssam int fo, found; 4449895Ssam struct frame *parent, *lastparent; 4459895Ssam char *padj; 4469895Ssam 4479895Ssam numsame = found = 0; 4489895Ssam makelists (); 4499895Ssam 4509895Ssam while (1) { 4519895Ssam l = numsame; 4529895Ssam if (!(*getword) ()) 4539895Ssam break; 4549895Ssam top = level[l+1]; 4559895Ssam 4569895Ssam while (1) { 4579895Ssam level[l+1] = lastparent = top; 4589895Ssam /* wbuff[1]...wbuff[l] have been matched */ 4599895Ssam /* level[0],...,level[l] of tree built */ 4609895Ssam if (l == wlength) { 4619895Ssam if (wlength >= 3 && (q = numways(level[l], top)) != 0) { 4629895Ssam (*putword) (q); 4639895Ssam found++; 4649895Ssam } 4659895Ssam l = BSIZE+1; 4669895Ssam break; 4679895Ssam } 4689895Ssam if ((fo = occurs[wbuff[++l]-'a']) == BSIZE) 4699895Ssam break; 4709895Ssam /* wbuff[1]...wbuff[l-1] have been matched */ 4719895Ssam /* level[0],...,level[l-1] of tree built */ 4729895Ssam for (parent=level[l-1]; parent<lastparent; parent++) { 4739895Ssam padj = &adj[parent->place][0]; 4749895Ssam for (q=fo; q!=BSIZE; q=olink[q]) 4759895Ssam if (padj[q]) { 4769895Ssam top->parent = parent; 4779895Ssam top->place = q; 4789895Ssam if (++top >= &stack[SSIZE]) { 4799895Ssam printf("stack overflow\n"); 4809895Ssam goodbye(1); 4819895Ssam } 4829895Ssam } 4839895Ssam } 4849895Ssam /* were any nodes added? */ 4859895Ssam if (top == lastparent) 4869895Ssam break; 4879895Ssam } 4889895Ssam 4899895Ssam /* advance until first l characters of next word are different */ 4909895Ssam while (numsame >= l && (*getword)()) ; 4919895Ssam } 4929895Ssam return(found); 4939895Ssam } 4949895Ssam 4959895Ssam main (argc, argv) 4969895Ssam int argc; 4979895Ssam char **argv; 4989895Ssam { 4999895Ssam char *q; 5009895Ssam register char *p; 5019895Ssam register int i, c; 5029895Ssam 5039895Ssam gtty (fileno(stdin), &origttyb); 5049895Ssam setbuf(stdin, NULL); 5059895Ssam tempttyb = origttyb; 5069895Ssam if (setjmp(env) != 0) 5079895Ssam goodbye(0); 5089895Ssam signal (SIGINT, interrupt); 5099895Ssam timein = time(0L); 5109895Ssam if (argv[0][0] != 'a' && (logfile = open("/usr/games/boglog", 1)) >= 0) { 5119895Ssam p = &logbuff[5]; 5129895Ssam q = getlogin(); 5139895Ssam while (*p++ = *q++); 5149895Ssam p[-1] = '\t'; 5159895Ssam q = ctime(&timein); 5169895Ssam while (*p++ = *q++); 5179895Ssam logloc = lseek(logfile, 0L, 2); 5189895Ssam write(logfile, &logbuff[0], p-&logbuff[1]); 5199895Ssam } 5209895Ssam if ((dict = fopen(dictname, "r")) == NULL) { 5219895Ssam printf("can't open %s\n", dictname); 5229895Ssam goodbye (2); 5239895Ssam } 5249895Ssam while ( argc > 1 && ( argv[1][0] == '+' || argv[1][0] == '-' ) ) { 5259895Ssam if (argv[1][0]=='+') { 5269895Ssam while(*(argv[1]++) == '+') 5279895Ssam super++; 5289895Ssam argc--; 5299895Ssam argv++; 5309895Ssam } 5319895Ssam if ( argv[1][0] == '-' ) { 5329895Ssam timeint[0] = 60 * ( atol( &argv[1][1] ) - 2 ); 5339895Ssam if ( timeint[0] <= 0 ) { 5349895Ssam timeint[0] = 60; 5359895Ssam } 5369895Ssam argc--; 5379895Ssam argv++; 5389895Ssam } 5399895Ssam } 5409895Ssam setup (); 5419895Ssam switch (argc) { 5429895Ssam default: punt: 5439895Ssam printf("usage: boggle [+[+]] [row1 row2 row3 row4]\n"); 5449895Ssam goodbye (3); 5459895Ssam case 5: 5469895Ssam for (i=0; i<BSIZE; i++) { 5479895Ssam board[i] = c = argv[row(i)+1][col(i)]; 5489895Ssam if (!islower(c)) { 5499895Ssam printf("bad board\n"); 5509895Ssam goto punt; 5519895Ssam } 5529895Ssam } 5539895Ssam printboard(); 5549895Ssam column = 0; 5559895Ssam evalboard(getdword, tputword); 5569895Ssam endline(); 5579895Ssam if (logfile >= 0) { 5589895Ssam strncpy(&logbuff[0], "eval", 4); 5599895Ssam lseek(logfile, logloc, 0); 5609895Ssam write(logfile, &logbuff[0], 4); 5619895Ssam } 5629895Ssam goodbye(0); 5639895Ssam case 1: 5649895Ssam tempttyb.sg_flags |= CBREAK; 5659895Ssam if ( ioctl( fileno(stdin), TIOCLGET, &ctlecho ) == 0 ) { 5669895Ssam if ( ctlecho & LCTLECH ) { 5679895Ssam ioctl( fileno(stdin), TIOCLBIC, &lctlech ); 5689895Ssam } 5699895Ssam } 5709895Ssam printinst(); 5719895Ssam srand((int) timein); 5729895Ssam while (setjmp(env) == 0) { 5739895Ssam errno = 0; 5749895Ssam if (pipe(&pipefd[0]) != 0) { 5759895Ssam printf("can't create pipe\n"); 5769895Ssam goodbye(4); 5779895Ssam } 5789895Ssam genboard(); 5799895Ssam delct = wcount = 0; 5809895Ssam word[0] = freesp = &space[0]; 5819895Ssam if ((master = fork()) == 0) { 5829895Ssam close(pipefd[0]); 5839895Ssam clearscreen(); 5849895Ssam printboard(); 5859895Ssam signal(SIGALRM, timeout); 5869895Ssam timept = &timeint[0]; 5879895Ssam alarm(*timept++); 5889895Ssam evalboard(getuword, aputuword); 5899895Ssam clearscreen(); 5909895Ssam qsort(&word[0], wcount, sizeof (int), compare); 5919895Ssam for (i=0; i<wcount; i++) 5929895Ssam if (i==0 || wordcomp(word[i], word[i-1])!=0) { 5939895Ssam p = word[i]; 5949895Ssam while (isalpha(*++p)) ; 5959895Ssam write (pipefd[1], word[i], p-word[i]); 5969895Ssam } 5979895Ssam close(pipefd[1]); 5989895Ssam goodbye(0); 5999895Ssam } 6009895Ssam close(pipefd[1]); 6019895Ssam rewind(dict); 6029895Ssam getc(dict); 6039895Ssam evalboard(getdword, aputword); 6049895Ssam p = freesp; 6059895Ssam while ((i = read(pipefd[0], freesp, 512)) != 0) { 6069895Ssam if (i < 0) 6079895Ssam if (errno != EINTR) 6089895Ssam break; 6099895Ssam else 6109895Ssam i = 0; 6119895Ssam freesp += i; 6129895Ssam } 6139895Ssam close(pipefd[0]); 6149895Ssam ustart = ubotch = wcount; 6159895Ssam while (p < freesp) { 6169895Ssam word[wcount++] = p; 6179895Ssam if (*p == '0') 6189895Ssam ustart = wcount; 6199895Ssam while (isalpha(*++p)); 6209895Ssam } 6219895Ssam wait(&status); 6229895Ssam if (status != 0) 6239895Ssam goodbye (5); 6249895Ssam delct = 1; 6259895Ssam printdiff(); 6269895Ssam printboard(); 6279895Ssam games++; 6289895Ssam if (logfile >= 0) { 6299895Ssam sprintf(&logbuff[0], "%4d", games); 6309895Ssam lseek(logfile, logloc, 0); 6319895Ssam write(logfile, &logbuff[0], 4); 6329895Ssam } 6339895Ssam stty (fileno(stdin), &tempttyb); 6349895Ssam printf("\nanother game?"); 6359895Ssam if (getchar() != 'y') { 6369895Ssam putchar('\n'); 6379895Ssam break; 6389895Ssam } 6399895Ssam stty (fileno(stdin), &tempttyb); 6409895Ssam } 6419895Ssam goodbye(0); 6429895Ssam } 6439895Ssam } 644