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