2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1995-10-06 13:52:00 adam
8 * Bug fixes. Handler may abort further scanning.
10 * Revision 1.3 1995/10/06 11:06:07 adam
13 * Revision 1.2 1995/10/06 10:43:16 adam
16 * Revision 1.1 1995/10/06 09:04:18 adam
17 * First version of scan.
27 int dict_scan_trav (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
28 int start, int *count,
29 int (*userfunc)(Dict_char *, const char *, int pos),
37 dict_bf_readp (dict->dbf, ptr, &p);
39 if (start == 0 && dir == -1)
43 indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
45 while (lo <= hi && lo >= 0 && *count > 0)
49 /* string (Dict_char *) DICT_EOS terminated */
50 /* unsigned char length of information */
51 /* char * information */
53 info = (char*)p + indxp[-lo];
54 for (j = 0; info[j] != DICT_EOS; j++)
56 str[pos+j] = DICT_EOS;
57 if ((*userfunc)(str, info+(j+1)*sizeof(Dict_char), *count * dir))
67 /* Dict_char sub char */
68 /* unsigned char length of information */
69 /* char * information */
71 info = (char*)p - indxp[-lo];
72 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
74 memcpy (&subptr, info, sizeof(Dict_ptr));
75 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
77 str[pos+1] = DICT_EOS;
78 if ((*userfunc)(str, info+sizeof(Dict_ptr)+sizeof(Dict_char),
83 if (*count > 0 && subptr)
84 dict_scan_trav (dict, subptr, pos+1, str, 0, count,
92 int dict_scan_r (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
93 int *before, int *after,
94 int (*userfunc)(Dict_char *, const char *, int))
96 int cmp = 0, mid, lo, hi;
101 dict_bf_readp (dict->dbf, ptr, &p);
103 hi = DICT_nodir(p)-1;
104 indxp = (short*) ((char*) p+DICT_pagesize(dict)-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)(str, info+
120 (dict_strlen(info)+1)*sizeof(Dict_char),
132 /* Dict_ptr subptr */
133 /* Dict_char sub char */
134 /* unsigned char length of information */
135 /* char * information */
136 info = (char*)p - indxp[-mid];
137 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
141 memcpy (&subptr, info, sizeof(Dict_ptr));
142 if (str[pos+1] == DICT_EOS)
144 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
149 info+sizeof(Dict_ptr)+
155 if (*after && subptr)
156 if (dict_scan_trav (dict, subptr, pos+1, str, 0,
161 if (dict_scan_r (dict, subptr, pos+1, str, before, after,
172 if (lo>hi && cmp < 0)
175 if (dict_scan_trav (dict, ptr, pos, str, cmp ? mid : mid+1, after,
178 if (*before && mid > 1)
179 if (dict_scan_trav (dict, ptr, pos, str, mid-1, before,
185 int dict_scan (Dict dict, Dict_char *str, int *before, int *after,
186 int (*f)(Dict_char *name, const char *info, int pos))
189 i = dict_scan_r (dict, 1, 0, str, before, after, f);