2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1995-11-20 11:58:04 adam
8 * Support for YAZ in standard located directories, such as /usr/local/..
10 * Revision 1.5 1995/10/09 16:18:32 adam
11 * Function dict_lookup_grep got extra client data parameter.
13 * Revision 1.4 1995/10/06 13:52:00 adam
14 * Bug fixes. Handler may abort further scanning.
16 * Revision 1.3 1995/10/06 11:06:07 adam
19 * Revision 1.2 1995/10/06 10:43:16 adam
22 * Revision 1.1 1995/10/06 09:04:18 adam
23 * First version of scan.
33 int dict_scan_trav (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
34 int start, int *count, void *client,
35 int (*userfunc)(Dict_char *, const char *, int, void *),
43 dict_bf_readp (dict->dbf, ptr, &p);
45 if (start == 0 && dir == -1)
49 indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
51 while (lo <= hi && lo >= 0 && *count > 0)
55 /* string (Dict_char *) DICT_EOS terminated */
56 /* unsigned char length of information */
57 /* char * information */
59 info = (char*)p + indxp[-lo];
60 for (j = 0; info[j] != DICT_EOS; j++)
62 str[pos+j] = DICT_EOS;
63 if ((*userfunc)(str, info+(j+1)*sizeof(Dict_char), *count * dir,
74 /* Dict_char sub char */
75 /* unsigned char length of information */
76 /* char * information */
78 info = (char*)p - indxp[-lo];
79 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
81 memcpy (&subptr, info, sizeof(Dict_ptr));
82 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
84 str[pos+1] = DICT_EOS;
85 if ((*userfunc)(str, info+sizeof(Dict_ptr)+sizeof(Dict_char),
86 *count * dir, client))
90 if (*count > 0 && subptr)
91 dict_scan_trav (dict, subptr, pos+1, str, 0, count,
92 client, userfunc, dir);
99 int dict_scan_r (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
100 int *before, int *after, void *client,
101 int (*userfunc)(Dict_char *, const char *, int, void *))
103 int cmp = 0, mid, lo, hi;
108 dict_bf_readp (dict->dbf, ptr, &p);
112 hi = DICT_nodir(p)-1;
113 indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
119 /* string (Dict_char *) DICT_EOS terminated */
120 /* unsigned char length of information */
121 /* char * information */
122 info = (char*)p + indxp[-mid];
123 cmp = dict_strcmp ((Dict_char*) info, str + pos);
128 (*userfunc)(str, info+
129 (dict_strlen(info)+1)*sizeof(Dict_char),
141 /* Dict_ptr subptr */
142 /* Dict_char sub char */
143 /* unsigned char length of information */
144 /* char * information */
145 info = (char*)p - indxp[-mid];
146 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
150 memcpy (&subptr, info, sizeof(Dict_ptr));
151 if (str[pos+1] == DICT_EOS)
153 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
158 info+sizeof(Dict_ptr)+
164 if (*after && subptr)
165 if (dict_scan_trav (dict, subptr, pos+1, str, 0,
166 after, client, userfunc, 1))
170 if (dict_scan_r (dict, subptr, pos+1, str, before, after,
181 if (lo>hi && cmp < 0)
184 if (dict_scan_trav (dict, ptr, pos, str, cmp ? mid : mid+1, after,
185 client, userfunc, 1))
187 if (*before && mid > 1)
188 if (dict_scan_trav (dict, ptr, pos, str, mid-1, before,
189 client, userfunc, -1))
194 int dict_scan (Dict dict, Dict_char *str, int *before, int *after,
196 int (*f)(Dict_char *name, const char *info, int pos,
199 return dict_scan_r (dict, 1, 0, str, before, after, client, f);