2 * Copyright (C) 1994-2002, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Id: scan.c,v 1.14 2002-01-14 01:52:22 adam Exp $
15 int dict_scan_trav (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
16 int start, int *count, void *client,
17 int (*userfunc)(char *, const char *, int, void *),
25 dict_bf_readp (dict->dbf, ptr, &p);
36 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
38 while (lo <= hi && lo >= 0 && *count > 0)
42 /* string (Dict_char *) DICT_EOS terminated */
43 /* unsigned char length of information */
44 /* char * information */
46 info = (char*)p + indxp[-lo];
47 for (j = 0; info[j] != DICT_EOS; j++)
49 str[pos+j] = DICT_EOS;
50 (*userfunc)((char*) str, info+(j+1)*sizeof(Dict_char),
51 *count * dir, client);
60 /* Dict_char sub char */
61 /* unsigned char length of information */
62 /* char * information */
64 info = (char*)p - indxp[-lo];
65 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
67 memcpy (&subptr, info, sizeof(Dict_ptr));
68 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
70 str[pos+1] = DICT_EOS;
71 if ((*userfunc)((char*) str,
72 info+sizeof(Dict_ptr)+sizeof(Dict_char),
73 *count * dir, client))
77 if (*count > 0 && subptr)
79 dict_scan_trav (dict, subptr, pos+1, str, -1, count,
80 client, userfunc, dir);
81 dict_bf_readp (dict->dbf, ptr, &p);
82 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
90 int dict_scan_r (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
91 int *before, int *after, void *client,
92 int (*userfunc)(char *, const char *, int, void *))
94 int cmp = 0, mid, lo, hi;
99 dict_bf_readp (dict->dbf, ptr, &p);
103 hi = DICT_nodir(p)-1;
104 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
110 /* string (Dict_char *) DICT_EOS terminated */
111 /* unsigned char length of information */
112 /* char * information */
113 info = (char*)p + indxp[-mid];
114 cmp = dict_strcmp ((Dict_char*) info, str + pos);
119 (*userfunc)((char *) str, info+
120 (dict_strlen((Dict_char*) info)+1)
133 /* Dict_ptr subptr */
134 /* Dict_char sub char */
135 /* unsigned char length of information */
136 /* char * information */
137 info = (char*)p - indxp[-mid];
138 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
142 memcpy (&subptr, info, sizeof(Dict_ptr));
143 if (str[pos+1] == DICT_EOS)
145 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
149 (*userfunc)((char*) str,
150 info+sizeof(Dict_ptr)+
156 if (*after && subptr)
157 if (dict_scan_trav (dict, subptr, pos+1, str, -1,
158 after, client, userfunc, 1))
163 if (dict_scan_r (dict, subptr, pos+1, str, before, after,
175 if (lo>hi && cmp < 0)
178 if (dict_scan_trav (dict, ptr, pos, str, cmp ? mid : mid+1, after,
179 client, userfunc, 1))
181 if (*before && mid > 0)
182 if (dict_scan_trav (dict, ptr, pos, str, mid-1, before,
183 client, userfunc, -1))
188 int dict_scan (Dict dict, char *str, int *before, int *after, void *client,
189 int (*f)(char *name, const char *info, int pos, void *client))
193 logf (LOG_DEBUG, "dict_scan");
194 for (i = 0; str[i]; i++)
196 logf (LOG_DEBUG, " %3d %c", str[i],
197 (str[i] > ' ' && str[i] < 127) ? str[i] : '?');
199 if (!dict->head.root)
201 return dict_scan_r (dict, dict->head.root, 0, (Dict_char *) str,
202 before, after, client, f);