2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1995-10-09 16:18:32 adam
8 * Function dict_lookup_grep got extra client data parameter.
10 * Revision 1.4 1995/10/06 13:52:00 adam
11 * Bug fixes. Handler may abort further scanning.
13 * Revision 1.3 1995/10/06 11:06:07 adam
16 * Revision 1.2 1995/10/06 10:43:16 adam
19 * Revision 1.1 1995/10/06 09:04:18 adam
20 * First version of scan.
30 int dict_scan_trav (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
31 int start, int *count, void *client,
32 int (*userfunc)(Dict_char *, const char *, int, void *),
40 dict_bf_readp (dict->dbf, ptr, &p);
42 if (start == 0 && dir == -1)
46 indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
48 while (lo <= hi && lo >= 0 && *count > 0)
52 /* string (Dict_char *) DICT_EOS terminated */
53 /* unsigned char length of information */
54 /* char * information */
56 info = (char*)p + indxp[-lo];
57 for (j = 0; info[j] != DICT_EOS; j++)
59 str[pos+j] = DICT_EOS;
60 if ((*userfunc)(str, info+(j+1)*sizeof(Dict_char), *count * dir,
71 /* Dict_char sub char */
72 /* unsigned char length of information */
73 /* char * information */
75 info = (char*)p - indxp[-lo];
76 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
78 memcpy (&subptr, info, sizeof(Dict_ptr));
79 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
81 str[pos+1] = DICT_EOS;
82 if ((*userfunc)(str, info+sizeof(Dict_ptr)+sizeof(Dict_char),
83 *count * dir, client))
87 if (*count > 0 && subptr)
88 dict_scan_trav (dict, subptr, pos+1, str, 0, count,
89 client, userfunc, dir);
96 int dict_scan_r (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
97 int *before, int *after, void *client,
98 int (*userfunc)(Dict_char *, const char *, int, void *))
100 int cmp = 0, mid, lo, hi;
105 dict_bf_readp (dict->dbf, ptr, &p);
107 hi = DICT_nodir(p)-1;
108 indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
114 /* string (Dict_char *) DICT_EOS terminated */
115 /* unsigned char length of information */
116 /* char * information */
117 info = (char*)p + indxp[-mid];
118 cmp = dict_strcmp ((Dict_char*) info, str + pos);
123 (*userfunc)(str, info+
124 (dict_strlen(info)+1)*sizeof(Dict_char),
136 /* Dict_ptr subptr */
137 /* Dict_char sub char */
138 /* unsigned char length of information */
139 /* char * information */
140 info = (char*)p - indxp[-mid];
141 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
145 memcpy (&subptr, info, sizeof(Dict_ptr));
146 if (str[pos+1] == DICT_EOS)
148 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
153 info+sizeof(Dict_ptr)+
159 if (*after && subptr)
160 if (dict_scan_trav (dict, subptr, pos+1, str, 0,
161 after, client, userfunc, 1))
165 if (dict_scan_r (dict, subptr, pos+1, str, before, after,
176 if (lo>hi && cmp < 0)
179 if (dict_scan_trav (dict, ptr, pos, str, cmp ? mid : mid+1, after,
180 client, userfunc, 1))
182 if (*before && mid > 1)
183 if (dict_scan_trav (dict, ptr, pos, str, mid-1, before,
184 client, userfunc, -1))
189 int dict_scan (Dict dict, Dict_char *str, int *before, int *after,
191 int (*f)(Dict_char *name, const char *info, int pos,
195 i = dict_scan_r (dict, 1, 0, str, before, after, client, f);