31 #include <yaz/yaz-util.h>
32 #include <yaz/snprintf.h>
39 static int grep_handler (
char *name,
const char *info,
void *client)
46 static int scan_handler (
char *name,
const char *info,
int pos,
void *client)
52 int main (
int argc,
char **argv)
56 const char *name = NULL;
57 const char *inputfile = NULL;
58 const char *config = NULL;
59 const char *delete_term = NULL;
60 int scan_the_thing = 0;
69 char *grep_pattern = NULL;
71 int no_of_iterations = 0;
72 int no_of_new = 0, no_of_same = 0, no_of_change = 0;
73 int no_of_hits = 0, no_of_misses = 0, no_not_found = 0, no_of_deleted = 0;
79 fprintf(stderr,
"usage:\n "
80 " %s [-d] [-D t] [-S] [-r n] [-p n] [-u] [-g pat] [-s n] "
81 "[-v n] [-i f] [-w] [-c n] config file\n\n",
83 fprintf(stderr,
" -d delete instead of insert\n");
84 fprintf(stderr,
" -D t delete subtree instead of insert\n");
85 fprintf(stderr,
" -r n set regular match range\n");
86 fprintf(stderr,
" -p n set regular match start range\n");
87 fprintf(stderr,
" -u report if keys change during insert\n");
88 fprintf(stderr,
" -g p try pattern n (see -r)\n");
89 fprintf(stderr,
" -s n set info size to n (instead of 4)\n");
90 fprintf(stderr,
" -v n set logging level\n");
91 fprintf(stderr,
" -i f read file with words\n");
92 fprintf(stderr,
" -w insert/delete instead of lookup\n");
93 fprintf(stderr,
" -c n cache size (number of pages)\n");
94 fprintf(stderr,
" -S scan the dictionary\n");
97 while ((ret = options (
"D:Sdr:p:ug:s:v:i:wc:", argv, argc, &arg)) != -2)
107 yaz_log (YLOG_FATAL,
"too many files specified\n");
147 infosize = atoi(arg);
151 yaz_log_init (yaz_log_mask_str(arg),
prog, NULL);
155 yaz_log (YLOG_FATAL,
"Unknown option '-%s'", arg);
159 if (!config || !name)
161 yaz_log (YLOG_FATAL,
"no config and/or dictionary specified");
167 yaz_log (YLOG_FATAL,
"cannot open resource `%s'", config);
175 yaz_log (YLOG_FATAL,
"bfs_create fail");
181 yaz_log (YLOG_FATAL,
"dict_open fail of `%s'", name);
190 memset(infobytes, 0,
sizeof(infobytes));
192 if (!(ipf = fopen(inputfile,
"r")))
194 yaz_log (YLOG_FATAL|YLOG_ERRNO,
"cannot open %s", inputfile);
198 while (fgets (ipf_buf, 1023, ipf))
200 char *ipf_ptr = ipf_buf;
201 yaz_snprintf(infobytes,
sizeof(infobytes),
"%d", line);
202 for (;*ipf_ptr && *ipf_ptr !=
'\n';ipf_ptr++)
204 if (isalpha(*ipf_ptr) || *ipf_ptr ==
'_')
207 while (ipf_ptr[i] && (isalnum(ipf_ptr[i]) ||
225 infosize, infobytes))
233 yaz_log (YLOG_LOG,
"%s change\n", ipf_ptr);
237 yaz_log (YLOG_LOG,
"%s duplicate\n", ipf_ptr);
263 if ((no_of_iterations % 10000) == 0)
265 printf (
"."); fflush(stdout);
274 if (rw && delete_term)
276 yaz_log (YLOG_LOG,
"dict_delete_subtree %s", delete_term);
283 yaz_log (YLOG_LOG,
"Grepping '%s'", grep_pattern);
289 yaz_log (YLOG_LOG,
"Iterations.... %d", no_of_iterations);
292 yaz_log (YLOG_LOG,
"No of deleted. %d", no_of_deleted);
293 yaz_log (YLOG_LOG,
"No not found.. %d", no_not_found);
297 yaz_log (YLOG_LOG,
"No of new..... %d", no_of_new);
298 yaz_log (YLOG_LOG,
"No of change.. %d", no_of_change);
303 yaz_log (YLOG_LOG,
"Lookups....... %d", no_of_iterations);
304 yaz_log (YLOG_LOG,
"No of hits.... %d", no_of_hits);
305 yaz_log (YLOG_LOG,
"No of misses.. %d", no_of_misses);
309 char term_dict[1024];
311 int before = 1000000;
313 yaz_log (YLOG_LOG,
"dict_scan");
BFiles bfs_create(const char *spec, const char *base)
creates a Block files collection
void bfs_destroy(BFiles bfiles)
destroys a block files handle
char * dict_lookup(Dict dict, const char *p)
lookup item in dictionary
int dict_delete(Dict dict, const char *p)
deletes item from dictionary
Dict dict_open(BFiles bfs, const char *name, int cache, int rw, int compact_flag, int page_size)
open dictionary
int dict_lookup_grep(Dict dict, const char *p, int range, void *client, int *max_pos, int init_pos, int(*f)(char *name, const char *info, void *client))
regular expression search with error correction
int dict_delete_subtree(Dict dict, const char *p, void *client, int(*f)(const char *info, void *client))
delete items with a given prefix from dictionary
int dict_insert(Dict dict, const char *p, int userlen, void *userinfo)
insert item into dictionary
int dict_scan(Dict dict, char *str, int *before, int *after, void *client, int(*f)(char *name, const char *info, int pos, void *client))
dictionary scan
int dict_close(Dict dict)
closes dictionary
int main(int argc, char **argv)
static int scan_handler(char *name, const char *info, int pos, void *client)
static int grep_handler(char *name, const char *info, void *client)
ZEBRA_RES res_read_file(Res r, const char *fname)
Res res_open(Res res_def, Res over_res)
const char * res_get(Res r, const char *name)