2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1995-10-06 09:04:18 adam
8 * First version of scan.
18 void dict_scan_trav (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
19 int start, int *count,
20 int (*userfunc)(Dict_char *, const char *, int pos),
28 dict_bf_readp (dict->dbf, ptr, &p);
30 if (start == 0 && dir == -1)
34 indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
36 while (lo <= hi && lo >= 0 && *count > 0)
40 /* string (Dict_char *) DICT_EOS terminated */
41 /* unsigned char length of information */
42 /* char * information */
44 info = (char*)p + indxp[-lo];
45 for (j = 0; info[j] != DICT_EOS; j++)
47 str[pos+j] = DICT_EOS;
48 (*userfunc)(str, info+j*sizeof(Dict_char), *count * dir);
57 /* Dict_char sub char */
58 /* unsigned char length of information */
59 /* char * information */
61 info = (char*)p - indxp[-lo];
62 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
64 memcpy (&subptr, info, sizeof(Dict_ptr));
65 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
67 str[pos+1] = DICT_EOS;
68 (*userfunc)(str, info+sizeof(Dict_ptr)+sizeof(Dict_char),
72 if (*count > 0 && subptr)
73 dict_scan_trav (dict, subptr, pos+1, str, 0, count,
80 int dict_scan_r (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
81 int *before, int *after,
82 int (*userfunc)(Dict_char *, const char *, int))
84 int cmp = 0, mid, lo, hi, j;
89 dict_bf_readp (dict->dbf, ptr, &p);
92 indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
98 /* string (Dict_char *) DICT_EOS terminated */
99 /* unsigned char length of information */
100 /* char * information */
101 info = (char*)p + indxp[-mid];
102 cmp = dict_strcmp ((Dict_char*) info, str + pos);
105 for (j = 0; info[j++] != DICT_EOS; )
107 (*userfunc)(str, info+j*sizeof(Dict_char), *after);
117 /* Dict_ptr subptr */
118 /* Dict_char sub char */
119 /* unsigned char length of information */
120 /* char * information */
121 info = (char*)p - indxp[-mid];
122 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
126 memcpy (&subptr, info, sizeof(Dict_ptr));
127 if (str[pos+1] == DICT_EOS)
129 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
132 info+sizeof(Dict_ptr)+sizeof(Dict_char),
136 if (*after > 0 && subptr)
137 dict_scan_trav (dict, subptr, pos+1, str, 0,
140 else if (*after > 0 && subptr)
141 dict_scan_r (dict, subptr, pos+1, str, before, after,
151 if (lo>hi && cmp < 0)
154 dict_scan_trav (dict, ptr, pos, str, cmp ? mid : mid+1, after,
156 if (*before && mid > 1)
157 dict_scan_trav (dict, ptr, pos, str, mid-1, before,
162 int dict_scan (Dict dict, Dict_char *str, int *before, int *after,
163 int (*f)(Dict_char *name, const char *info, int pos))
166 i = dict_scan_r (dict, 1, 0, str, before, after, f);