| 1 |
/* |
| 2 |
Tests the generated perfect hash function. |
| 3 |
The -v option prints diagnostics as to whether a word is in |
| 4 |
the set or not. Without -v the program is useful for timing. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <stdio.h> |
| 8 |
|
| 9 |
/* Support for SET_BINARY. */ |
| 10 |
#include <fcntl.h> |
| 11 |
#if !defined O_BINARY && defined _O_BINARY |
| 12 |
# define O_BINARY _O_BINARY |
| 13 |
#endif |
| 14 |
#ifdef __BEOS__ |
| 15 |
# undef O_BINARY |
| 16 |
#endif |
| 17 |
#if O_BINARY |
| 18 |
# include <io.h> |
| 19 |
# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__ |
| 20 |
# define SET_BINARY(f) setmode (f, O_BINARY) |
| 21 |
# else |
| 22 |
# define SET_BINARY(f) _setmode (f, O_BINARY) |
| 23 |
# endif |
| 24 |
#else |
| 25 |
# define SET_BINARY(f) (void)0 |
| 26 |
#endif |
| 27 |
|
| 28 |
extern struct language * in_word_set (const char *, size_t); |
| 29 |
|
| 30 |
#define MAX_LEN 80 |
| 31 |
|
| 32 |
int |
| 33 |
main (int argc, char *argv[]) |
| 34 |
{ |
| 35 |
int verbose = argc > 1 ? 1 : 0; |
| 36 |
char buf[2*MAX_LEN]; |
| 37 |
int buflen; |
| 38 |
|
| 39 |
/* We need to read stdin in binary mode. */ |
| 40 |
SET_BINARY (0); |
| 41 |
|
| 42 |
for (;;) |
| 43 |
{ |
| 44 |
/* Simulate gets(buf) with 2 bytes per character. */ |
| 45 |
char *p = buf; |
| 46 |
while (fread (p, 2, 1, stdin) == 1) |
| 47 |
{ |
| 48 |
if (((unsigned char) p[0] << 8) + (unsigned char) p[1] == '\n') |
| 49 |
break; |
| 50 |
p += 2; |
| 51 |
} |
| 52 |
buflen = p - buf; |
| 53 |
|
| 54 |
if (buflen == 0) |
| 55 |
break; |
| 56 |
|
| 57 |
if (in_word_set (buf, buflen)) |
| 58 |
{ |
| 59 |
if (verbose) |
| 60 |
printf ("in word set:"); |
| 61 |
} |
| 62 |
else |
| 63 |
{ |
| 64 |
if (verbose) |
| 65 |
printf ("NOT in word set:"); |
| 66 |
} |
| 67 |
|
| 68 |
for (p = buf; p < buf + buflen; p += 2) |
| 69 |
printf (" %02X%02X", (unsigned char) p[0], (unsigned char) p[1]); |
| 70 |
printf("\n"); |
| 71 |
} |
| 72 |
|
| 73 |
return 0; |
| 74 |
} |