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# define SET_BINARY(f) setmode (f, O_BINARY)
19#else
20# define SET_BINARY(f) (void)0
21#endif
22
23#if defined __STDC__ || defined __cplusplus
24extern struct language * in_word_set (const char *, int);
25#else
26extern struct language * in_word_set ();
27#endif
28
29#define MAX_LEN 80
30
31int
32main (argc, argv)
33     int   argc;
34     char *argv[];
35{
36  int  verbose = argc > 1 ? 1 : 0;
37  char buf[2*MAX_LEN];
38  int buflen;
39
40  /* We need to read stdin in binary mode. */
41  SET_BINARY (0);
42
43  for (;;)
44    {
45      /* Simulate gets(buf) with 2 bytes per character. */
46      char *p = buf;
47      while (fread (p, 2, 1, stdin) == 1)
48        {
49          if ((p[0] << 8) + p[1] == '\n')
50            break;
51          p += 2;
52        }
53      buflen = p - buf;
54
55      if (buflen == 0)
56        break;
57
58      if (in_word_set (buf, buflen))
59        {
60          if (verbose)
61            printf ("in word set:");
62        }
63      else
64        {
65          if (verbose)
66            printf ("NOT in word set:");
67        }
68
69      for (p = buf; p < buf + buflen; p += 2)
70        printf (" %02X%02X", (unsigned char) p[0], (unsigned char) p[1]);
71      printf("\n");
72    }
73
74  return 0;
75}
76