2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.11 1994-09-28 13:07:09 adam
8 * Use log_mask_str now.
10 * Revision 1.10 1994/09/26 10:17:24 adam
13 * Revision 1.9 1994/09/22 14:43:56 adam
14 * First functional version of lookup with error correction. A 'range'
15 * specified the maximum number of insertions+deletions+substitutions.
17 * Revision 1.8 1994/09/22 10:43:44 adam
18 * Two versions of depend. Type 1 is the tail-type compatible with
19 * all make programs. Type 2 is the GNU make with include facility.
20 * Type 2 is default. depend rule chooses current rule.
22 * Revision 1.7 1994/09/19 16:34:26 adam
23 * Depend rule change. Minor changes in dicttest.c
25 * Revision 1.6 1994/09/16 15:39:12 adam
26 * Initial code of lookup - not tested yet.
28 * Revision 1.5 1994/09/06 13:05:14 adam
29 * Further development of insertion. Some special cases are
30 * not properly handled yet! assert(0) are put here. The
31 * binary search in each page definitely reduce usr CPU.
33 * Revision 1.4 1994/09/01 17:49:37 adam
34 * Removed stupid line. Work on insertion in dictionary. Not finished yet.
36 * Revision 1.3 1994/09/01 17:44:06 adam
37 * depend include change.
39 * Revision 1.2 1994/08/18 12:40:54 adam
40 * Some development of dictionary. Not finished at all!
42 * Revision 1.1 1994/08/16 16:26:47 adam
59 static int lookup_handle (Dict_char *name)
62 printf ("%s\n", name);
66 int main (int argc, char **argv)
68 const char *name = NULL;
69 const char *inputfile = NULL;
70 const char *base = NULL;
78 int no_of_iterations = 0;
79 int no_of_new = 0, no_of_same = 0, no_of_change = 0;
80 int no_of_hits = 0, no_of_misses = 0;
86 fprintf (stderr, "usage:\n "
87 " %s [-r n] [-u] [-s n] [-v n] [-i f] [-w] [-c n]"
92 while ((ret = options ("r:us:v:i:wc:", argv, argc, &arg)) != -2)
102 log (LOG_FATAL, "too many files specified\n");
126 infosize = atoi(arg);
130 log_init (log_mask_str(arg), prog, NULL);
134 log (LOG_FATAL, "unknown option");
140 log (LOG_FATAL, "no base and/or dictionary specified");
143 common_resource = res_open (base);
144 if (!common_resource)
146 log (LOG_FATAL, "cannot open resource `%s'", base);
149 dict = dict_open (name, cache, rw);
152 log (LOG_FATAL, "dict_open fail of `%s'", name);
161 memset (infobytes, 0, 120);
163 if (!(ipf = fopen(inputfile, "r")))
165 log (LOG_FATAL|LOG_ERRNO, "cannot open %s", inputfile);
169 while (fgets (ipf_buf, 1023, ipf))
171 char *ipf_ptr = ipf_buf;
172 sprintf (infobytes, "%d", line);
173 for (;*ipf_ptr && *ipf_ptr != '\n';ipf_ptr++)
175 if (isalpha(*ipf_ptr) || *ipf_ptr == '_')
178 while (ipf_ptr[i] && (isalnum(ipf_ptr[i]) ||
185 switch(dict_insert (dict, ipf_ptr,
186 infosize, infobytes))
194 log (LOG_LOG, "%s change\n", ipf_ptr);
198 log (LOG_LOG, "%s duplicate\n", ipf_ptr);
207 cp = dict_lookup (dict, ipf_ptr);
216 dict_lookup_ec (dict, ipf_ptr, range, lookup_handle);
232 log (LOG_LOG, "Insertions.... %d", no_of_iterations);
233 log (LOG_LOG, "No of new..... %d", no_of_new);
234 log (LOG_LOG, "No of change.. %d", no_of_change);
235 log (LOG_LOG, "No of same.... %d", no_of_same);
239 log (LOG_LOG, "Lookups....... %d", no_of_iterations);
240 log (LOG_LOG, "No of hits.... %d", no_of_hits);
241 log (LOG_LOG, "No of misses.. %d", no_of_misses);
244 res_close (common_resource);