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