2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.19 1996-02-02 13:43:50 adam
8 * The public functions simply use char instead of Dict_char to represent
9 * search strings. Dict_char is used internally only.
11 * Revision 1.18 1996/02/01 20:39:52 adam
12 * Bug fix: insert didn't work on 8-bit characters due to unsigned char
13 * compares in dict_strcmp (strcmp) and signed Dict_char. Dict_char is
16 * Revision 1.17 1995/12/06 17:48:30 adam
17 * Bug fix: delete didn't work.
19 * Revision 1.16 1995/10/09 16:18:31 adam
20 * Function dict_lookup_grep got extra client data parameter.
22 * Revision 1.15 1995/09/04 12:33:31 adam
23 * Various cleanup. YAZ util used instead.
25 * Revision 1.14 1994/10/04 17:46:55 adam
26 * Function options now returns arg with error option.
28 * Revision 1.13 1994/10/04 12:08:05 adam
29 * Some bug fixes and some optimizations.
31 * Revision 1.12 1994/10/03 17:23:03 adam
32 * First version of dictionary lookup with regular expressions and errors.
34 * Revision 1.11 1994/09/28 13:07:09 adam
35 * Use log_mask_str now.
37 * Revision 1.10 1994/09/26 10:17:24 adam
40 * Revision 1.9 1994/09/22 14:43:56 adam
41 * First functional version of lookup with error correction. A 'range'
42 * specified the maximum number of insertions+deletions+substitutions.
44 * Revision 1.8 1994/09/22 10:43:44 adam
45 * Two versions of depend. Type 1 is the tail-type compatible with
46 * all make programs. Type 2 is the GNU make with include facility.
47 * Type 2 is default. depend rule chooses current rule.
49 * Revision 1.7 1994/09/19 16:34:26 adam
50 * Depend rule change. Minor changes in dicttest.c
52 * Revision 1.6 1994/09/16 15:39:12 adam
53 * Initial code of lookup - not tested yet.
55 * Revision 1.5 1994/09/06 13:05:14 adam
56 * Further development of insertion. Some special cases are
57 * not properly handled yet! assert(0) are put here. The
58 * binary search in each page definitely reduce usr CPU.
60 * Revision 1.4 1994/09/01 17:49:37 adam
61 * Removed stupid line. Work on insertion in dictionary. Not finished yet.
63 * Revision 1.3 1994/09/01 17:44:06 adam
64 * depend include change.
66 * Revision 1.2 1994/08/18 12:40:54 adam
67 * Some development of dictionary. Not finished at all!
69 * Revision 1.1 1994/08/16 16:26:47 adam
86 static int grep_handle (char *name, const char *info, void *client)
89 printf ("%s\n", name);
93 int main (int argc, char **argv)
95 const char *name = NULL;
96 const char *inputfile = NULL;
97 const char *base = NULL;
105 char *grep_pattern = NULL;
107 int no_of_iterations = 0;
108 int no_of_new = 0, no_of_same = 0, no_of_change = 0;
109 int no_of_hits = 0, no_of_misses = 0, no_not_found = 0, no_of_deleted = 0;
115 fprintf (stderr, "usage:\n "
116 " %s [-d] [-r n] [-u] [-g pat] [-s n] [-v n] [-i f] [-w]"
117 " [-c n] base file\n\n",
119 fprintf (stderr, " -d delete instead of insert\n");
120 fprintf (stderr, " -r n set regular match range\n");
121 fprintf (stderr, " -u report if keys change during insert\n");
122 fprintf (stderr, " -g p try pattern n (see -r)\n");
123 fprintf (stderr, " -s n set info size to n (instead of 4)\n");
124 fprintf (stderr, " -v n set logging level\n");
125 fprintf (stderr, " -i f read file with words\n");
126 fprintf (stderr, " -w insert/delete instead of lookup\n");
127 fprintf (stderr, " -c n cache size (number of pages)\n");
130 while ((ret = options ("dr:ug:s:v:i:wc:", argv, argc, &arg)) != -2)
140 logf (LOG_FATAL, "too many files specified\n");
170 infosize = atoi(arg);
174 log_init (log_mask_str(arg), prog, NULL);
178 logf (LOG_FATAL, "Unknown option '-%s'", arg);
184 logf (LOG_FATAL, "no base and/or dictionary specified");
187 common_resource = res_open (base);
188 if (!common_resource)
190 logf (LOG_FATAL, "cannot open resource `%s'", base);
193 dict = dict_open (name, cache, rw);
196 logf (LOG_FATAL, "dict_open fail of `%s'", name);
205 memset (infobytes, 0, 120);
207 if (!(ipf = fopen(inputfile, "r")))
209 logf (LOG_FATAL|LOG_ERRNO, "cannot open %s", inputfile);
213 while (fgets (ipf_buf, 1023, ipf))
215 char *ipf_ptr = ipf_buf;
216 sprintf (infobytes, "%d", line);
217 for (;*ipf_ptr && *ipf_ptr != '\n';ipf_ptr++)
219 if (isalpha(*ipf_ptr) || *ipf_ptr == '_')
222 while (ipf_ptr[i] && (isalnum(ipf_ptr[i]) ||
230 switch (dict_delete (dict, ipf_ptr))
239 switch(dict_insert (dict, ipf_ptr,
240 infosize, infobytes))
248 logf (LOG_LOG, "%s change\n", ipf_ptr);
252 logf (LOG_LOG, "%s duplicate\n", ipf_ptr);
261 cp = dict_lookup (dict, ipf_ptr);
270 dict_lookup_grep (dict, ipf_ptr, range, NULL,
271 &max_pos, grep_handle);
289 logf (LOG_LOG, "Grepping '%s'", grep_pattern);
290 dict_lookup_grep (dict, grep_pattern, range, NULL, &max_pos,
295 logf (LOG_LOG, "Iterations.... %d", no_of_iterations);
298 logf (LOG_LOG, "No of deleted. %d", no_of_deleted);
299 logf (LOG_LOG, "No not found.. %d", no_not_found);
303 logf (LOG_LOG, "No of new..... %d", no_of_new);
304 logf (LOG_LOG, "No of change.. %d", no_of_change);
309 logf (LOG_LOG, "Lookups....... %d", no_of_iterations);
310 logf (LOG_LOG, "No of hits.... %d", no_of_hits);
311 logf (LOG_LOG, "No of misses.. %d", no_of_misses);
314 res_close (common_resource);