2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-10-06 10:43:16 adam
10 * Revision 1.1 1995/10/06 09:04:18 adam
11 * First version of scan.
21 void dict_scan_trav (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
22 int start, int *count,
23 int (*userfunc)(Dict_char *, const char *, int pos),
31 dict_bf_readp (dict->dbf, ptr, &p);
33 if (start == 0 && dir == -1)
37 indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
39 while (lo <= hi && lo >= 0 && *count > 0)
43 /* string (Dict_char *) DICT_EOS terminated */
44 /* unsigned char length of information */
45 /* char * information */
47 info = (char*)p + indxp[-lo];
48 for (j = 0; info[j] != DICT_EOS; j++)
50 str[pos+j] = DICT_EOS;
51 (*userfunc)(str, info+j*sizeof(Dict_char), *count * dir);
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 (*userfunc)(str, info+sizeof(Dict_ptr)+sizeof(Dict_char),
75 if (*count > 0 && subptr)
76 dict_scan_trav (dict, subptr, pos+1, str, 0, count,
83 int dict_scan_r (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
84 int *before, int *after,
85 int (*userfunc)(Dict_char *, const char *, int))
87 int cmp = 0, mid, lo, hi;
92 dict_bf_readp (dict->dbf, ptr, &p);
95 indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
101 /* string (Dict_char *) DICT_EOS terminated */
102 /* unsigned char length of information */
103 /* char * information */
104 info = (char*)p + indxp[-mid];
105 cmp = dict_strcmp ((Dict_char*) info, str + pos);
108 (*userfunc)(str, str, *after);
118 /* Dict_ptr subptr */
119 /* Dict_char sub char */
120 /* unsigned char length of information */
121 /* char * information */
122 info = (char*)p - indxp[-mid];
123 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
127 memcpy (&subptr, info, sizeof(Dict_ptr));
128 if (str[pos+1] == DICT_EOS)
130 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
133 info+sizeof(Dict_ptr)+sizeof(Dict_char),
137 if (*after > 0 && subptr)
138 dict_scan_trav (dict, subptr, pos+1, str, 0,
141 else if (*after > 0 && subptr)
142 dict_scan_r (dict, subptr, pos+1, str, before, after,
152 if (lo>hi && cmp < 0)
155 dict_scan_trav (dict, ptr, pos, str, cmp ? mid : mid+1, after,
157 if (*before && mid > 1)
158 dict_scan_trav (dict, ptr, pos, str, mid-1, before,
163 int dict_scan (Dict dict, Dict_char *str, int *before, int *after,
164 int (*f)(Dict_char *name, const char *info, int pos))
167 i = dict_scan_r (dict, 1, 0, str, before, after, f);