1*33108Sbostic /* 2*33108Sbostic * Copyright (c) 1987 Regents of the University of California. 3*33108Sbostic * All rights reserved. 4*33108Sbostic * 5*33108Sbostic * Redistribution and use in source and binary forms are permitted 6*33108Sbostic * provided that this notice is preserved and that due credit is given 7*33108Sbostic * to the University of California at Berkeley. The name of the University 8*33108Sbostic * may not be used to endorse or promote products derived from this 9*33108Sbostic * software without specific prior written permission. This software 10*33108Sbostic * is provided ``as is'' without express or implied warranty. 11*33108Sbostic */ 12*33108Sbostic 13*33108Sbostic #ifndef lint 14*33108Sbostic static char sccsid[] = "@(#)getword.c 5.1 (Berkeley) 12/22/87"; 15*33108Sbostic #endif /* not lint */ 16*33108Sbostic 17*33108Sbostic # include "hangman.h" 18*33108Sbostic 19*33108Sbostic # if pdp11 20*33108Sbostic # define RN (((off_t) rand() << 16) | (off_t) rand()) 21*33108Sbostic # else 22*33108Sbostic # define RN rand() 23*33108Sbostic # endif 24*33108Sbostic 25*33108Sbostic /* 26*33108Sbostic * getword: 27*33108Sbostic * Get a valid word out of the dictionary file 28*33108Sbostic */ 29*33108Sbostic getword() 30*33108Sbostic { 31*33108Sbostic register FILE *inf; 32*33108Sbostic register char *wp, *gp; 33*33108Sbostic 34*33108Sbostic inf = Dict; 35*33108Sbostic for (;;) { 36*33108Sbostic fseek(inf, abs(RN % Dict_size), 0); 37*33108Sbostic if (fgets(Word, BUFSIZ, inf) == NULL) 38*33108Sbostic continue; 39*33108Sbostic if (fgets(Word, BUFSIZ, inf) == NULL) 40*33108Sbostic continue; 41*33108Sbostic Word[strlen(Word) - 1] = '\0'; 42*33108Sbostic if (strlen(Word) < MINLEN) 43*33108Sbostic continue; 44*33108Sbostic for (wp = Word; *wp; wp++) 45*33108Sbostic if (!islower(*wp)) 46*33108Sbostic goto cont; 47*33108Sbostic break; 48*33108Sbostic cont: ; 49*33108Sbostic } 50*33108Sbostic gp = Known; 51*33108Sbostic wp = Word; 52*33108Sbostic while (*wp) { 53*33108Sbostic *gp++ = '-'; 54*33108Sbostic wp++; 55*33108Sbostic } 56*33108Sbostic *gp = '\0'; 57*33108Sbostic } 58*33108Sbostic 59*33108Sbostic /* 60*33108Sbostic * abs: 61*33108Sbostic * Return the absolute value of an integer 62*33108Sbostic */ 63*33108Sbostic off_t 64*33108Sbostic abs(i) 65*33108Sbostic off_t i; 66*33108Sbostic { 67*33108Sbostic if (i < 0) 68*33108Sbostic return -(off_t) i; 69*33108Sbostic else 70*33108Sbostic return (off_t) i; 71*33108Sbostic } 72