2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.13 1994-10-04 12:08:05 adam
8 * Some bug fixes and some optimizations.
10 * Revision 1.12 1994/10/03 17:23:03 adam
11 * First version of dictionary lookup with regular expressions and errors.
13 * Revision 1.11 1994/09/28 13:07:09 adam
14 * Use log_mask_str now.
16 * Revision 1.10 1994/09/26 10:17:24 adam
19 * Revision 1.9 1994/09/22 14:43:56 adam
20 * First functional version of lookup with error correction. A 'range'
21 * specified the maximum number of insertions+deletions+substitutions.
23 * Revision 1.8 1994/09/22 10:43:44 adam
24 * Two versions of depend. Type 1 is the tail-type compatible with
25 * all make programs. Type 2 is the GNU make with include facility.
26 * Type 2 is default. depend rule chooses current rule.
28 * Revision 1.7 1994/09/19 16:34:26 adam
29 * Depend rule change. Minor changes in dicttest.c
31 * Revision 1.6 1994/09/16 15:39:12 adam
32 * Initial code of lookup - not tested yet.
34 * Revision 1.5 1994/09/06 13:05:14 adam
35 * Further development of insertion. Some special cases are
36 * not properly handled yet! assert(0) are put here. The
37 * binary search in each page definitely reduce usr CPU.
39 * Revision 1.4 1994/09/01 17:49:37 adam
40 * Removed stupid line. Work on insertion in dictionary. Not finished yet.
42 * Revision 1.3 1994/09/01 17:44:06 adam
43 * depend include change.
45 * Revision 1.2 1994/08/18 12:40:54 adam
46 * Some development of dictionary. Not finished at all!
48 * Revision 1.1 1994/08/16 16:26:47 adam
65 static int grep_handle (Dict_char *name, char *info)
68 printf ("%s\n", name);
72 int main (int argc, char **argv)
74 const char *name = NULL;
75 const char *inputfile = NULL;
76 const char *base = NULL;
83 char *grep_pattern = NULL;
85 int no_of_iterations = 0;
86 int no_of_new = 0, no_of_same = 0, no_of_change = 0;
87 int no_of_hits = 0, no_of_misses = 0;
93 fprintf (stderr, "usage:\n "
94 " %s [-r n] [-u] [-g pat] [-s n] [-v n] [-i f] [-w] [-c n]"
99 while ((ret = options ("r:ug:s:v:i:wc:", argv, argc, &arg)) != -2)
109 log (LOG_FATAL, "too many files specified\n");
137 infosize = atoi(arg);
141 log_init (log_mask_str(arg), prog, NULL);
145 log (LOG_FATAL, "unknown option");
151 log (LOG_FATAL, "no base and/or dictionary specified");
154 common_resource = res_open (base);
155 if (!common_resource)
157 log (LOG_FATAL, "cannot open resource `%s'", base);
160 dict = dict_open (name, cache, rw);
163 log (LOG_FATAL, "dict_open fail of `%s'", name);
172 memset (infobytes, 0, 120);
174 if (!(ipf = fopen(inputfile, "r")))
176 log (LOG_FATAL|LOG_ERRNO, "cannot open %s", inputfile);
180 while (fgets (ipf_buf, 1023, ipf))
182 char *ipf_ptr = ipf_buf;
183 sprintf (infobytes, "%d", line);
184 for (;*ipf_ptr && *ipf_ptr != '\n';ipf_ptr++)
186 if (isalpha(*ipf_ptr) || *ipf_ptr == '_')
189 while (ipf_ptr[i] && (isalnum(ipf_ptr[i]) ||
196 switch(dict_insert (dict, ipf_ptr,
197 infosize, infobytes))
205 log (LOG_LOG, "%s change\n", ipf_ptr);
209 log (LOG_LOG, "%s duplicate\n", ipf_ptr);
218 cp = dict_lookup (dict, ipf_ptr);
227 dict_lookup_grep (dict, ipf_ptr, range, grep_handle);
245 log (LOG_LOG, "Grepping '%s'", grep_pattern);
246 dict_lookup_grep (dict, grep_pattern, range, grep_handle);
250 log (LOG_LOG, "Insertions.... %d", no_of_iterations);
251 log (LOG_LOG, "No of new..... %d", no_of_new);
252 log (LOG_LOG, "No of change.. %d", no_of_change);
253 log (LOG_LOG, "No of same.... %d", no_of_same);
257 log (LOG_LOG, "Lookups....... %d", no_of_iterations);
258 log (LOG_LOG, "No of hits.... %d", no_of_hits);
259 log (LOG_LOG, "No of misses.. %d", no_of_misses);
262 res_close (common_resource);