games/boggle/boggle/bog.c
/*
 * Check each word in the dictionary against the board
 * Delete words from the machine list that the player has found
 * Assume both the dictionary and the player's words are already sorted
 */
Check each word in the dictionary against the board
Delete words from the machine list that the player has found
Assume both the dictionary and the player's words are already sorted
Check each word in the dictionary against the board Delete words from the machine list that the player has found Assume both the dictionary and the player ' s words are already sorted
void
checkdict()
{
	register char *p, **pw, *w;
	register int i;
	int prevch, previndex, *pi, *qi, st;
	mwordsp = mwords;
	nmwords = 0;
	pw = pword;
	prevch ='a';
	qi = &wordpath[MAXWORDLEN + 1];
	(void) dictseek(dictfp, 0L, 0);
	while ((w = nextword(dictfp)) != NULL) {
		if (wordlen < minlength)
			continue;
		if (*w != prevch) {
			i = (int) (*w - 'a');
			while (i < 26 && letter_map[i][0] == -1)
				i++;
			if (i == 26)
				break;
			previndex = prevch - 'a';
			prevch = i + 'a';
			if (i != previndex + 1) {
				if (dictseek(dictfp,
				    dictindex[i].start, 0) < 0) {
					warnx("seek error in checkdict()");
					cleanup();
					exit(1);
				}
				continue;
			}
		}
		pi = wordpath;
		while (pi < qi && *pi != -1)
			*pi++ = -1;
		usedbits = 0;
		if (checkword(w, -1, wordpath) == -1)
			continue;
		st = 1;
		while (*pw != NULL && (st = strcmp(*pw, w)) < 0)
			pw++;
		if (st == 0)			
			continue;
		if (nmwords == MAXMWORDS ||
		    mwordsp + wordlen + 1 >= &mwords[MAXMSPACE]) {
			warnx("too many words!");
			cleanup();
			exit(1);
		}
		mword[nmwords++] = mwordsp;
		p = w;
		while (*mwordsp++ = *p++);
	}
}
void checkdict ( ) { register char * p , * * pw , * w ; register int i ; int prevch , previndex , * pi , * qi , st ; mwordsp = mwords ; nmwords = 0 ; pw = pword ; prevch = ' ' ; qi = & wordpath [ MAXWORDLEN + 1 ] ; ( void ) dictseek ( dictfp , 0L , 0 ) ; while ( ( w = nextword ( dictfp ) ) != NULL ) { if ( wordlen < minlength ) continue ; if ( * w != prevch ) { i = ( int ) ( * w - ' ' ) ; while ( i < 26 && letter_map [ i ] [ 0 ] == -1 ) i ++ ; if ( i == 26 ) break ; previndex = prevch - ' ' ; prevch = i + ' ' ; if ( i != previndex + 1 ) { if ( dictseek ( dictfp , dictindex [ i ] . start , 0 ) < 0 ) { warnx ( " " ) ; cleanup ( ) ; exit ( 1 ) ; } continue ; } } pi = wordpath ; while ( pi < qi && * pi != -1 ) * pi ++ = -1 ; usedbits = 0 ; if ( checkword ( w , -1 , wordpath ) == -1 ) continue ; st = 1 ; while ( * pw != NULL && ( st = strcmp ( * pw , w ) ) < 0 ) pw ++ ; if ( st == 0 ) continue ; if ( nmwords == MAXMWORDS || mwordsp + wordlen + 1 >= & mwords [ MAXMSPACE ] ) { warnx ( " " ) ; cleanup ( ) ; exit ( 1 ) ; } mword [ nmwords ++ ] = mwordsp ; p = w ; while ( * mwordsp ++ = * p ++ ) ; } }
Check each word in the dictionary against the board
 Delete words from the machine list that the player has found
 Assume both the dictionary and the player's words are already sorted
Check each word in the dictionary against the board Delete words from the machine list that the player has found Assume both the dictionary and the player ' s words are already sorted
/*
			 * If we've moved on to a word with a different first
			 * letter then we can speed things up by skipping all
			 * words starting with a letter that doesn't appear in
			 * the cube.
			 */ /*
			 * Fall through if the word's first letter appears in
			 * the cube (i.e., if we can't skip ahead), otherwise
			 * seek to the beginning of words in the dictionary
			 * starting with the next letter (alphabetically)
			 * appearing in the cube and then read the first word.
			 */ /* found it */