2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1995-10-06 11:06:07 adam
10 * Revision 1.2 1995/10/06 10:43:16 adam
13 * Revision 1.1 1995/10/06 09:04:18 adam
14 * First version of scan.
24 void dict_scan_trav (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
25 int start, int *count,
26 int (*userfunc)(Dict_char *, const char *, int pos),
34 dict_bf_readp (dict->dbf, ptr, &p);
36 if (start == 0 && dir == -1)
40 indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
42 while (lo <= hi && lo >= 0 && *count > 0)
46 /* string (Dict_char *) DICT_EOS terminated */
47 /* unsigned char length of information */
48 /* char * information */
50 info = (char*)p + indxp[-lo];
51 for (j = 0; info[j] != DICT_EOS; j++)
53 str[pos+j] = DICT_EOS;
54 (*userfunc)(str, info+(j+1)*sizeof(Dict_char), *count * dir);
63 /* Dict_char sub char */
64 /* unsigned char length of information */
65 /* char * information */
67 info = (char*)p - indxp[-lo];
68 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
70 memcpy (&subptr, info, sizeof(Dict_ptr));
71 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
73 str[pos+1] = DICT_EOS;
74 (*userfunc)(str, info+sizeof(Dict_ptr)+sizeof(Dict_char),
78 if (*count > 0 && subptr)
79 dict_scan_trav (dict, subptr, pos+1, str, 0, count,
86 int dict_scan_r (Dict dict, Dict_ptr ptr, int pos, Dict_char *str,
87 int *before, int *after,
88 int (*userfunc)(Dict_char *, const char *, int))
90 int cmp = 0, mid, lo, hi;
95 dict_bf_readp (dict->dbf, ptr, &p);
98 indxp = (short*) ((char*) p+DICT_pagesize(dict)-sizeof(short));
104 /* string (Dict_char *) DICT_EOS terminated */
105 /* unsigned char length of information */
106 /* char * information */
107 info = (char*)p + indxp[-mid];
108 cmp = dict_strcmp ((Dict_char*) info, str + pos);
111 (*userfunc)(str, info+(dict_strlen(info)+1)*sizeof(Dict_char)
122 /* Dict_ptr subptr */
123 /* Dict_char sub char */
124 /* unsigned char length of information */
125 /* char * information */
126 info = (char*)p - indxp[-mid];
127 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
131 memcpy (&subptr, info, sizeof(Dict_ptr));
132 if (str[pos+1] == DICT_EOS)
134 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
137 info+sizeof(Dict_ptr)+sizeof(Dict_char),
141 if (*after > 0 && subptr)
142 dict_scan_trav (dict, subptr, pos+1, str, 0,
145 else if (*after > 0 && subptr)
146 dict_scan_r (dict, subptr, pos+1, str, before, after,
156 if (lo>hi && cmp < 0)
159 dict_scan_trav (dict, ptr, pos, str, cmp ? mid : mid+1, after,
161 if (*before && mid > 1)
162 dict_scan_trav (dict, ptr, pos, str, mid-1, before,
167 int dict_scan (Dict dict, Dict_char *str, int *before, int *after,
168 int (*f)(Dict_char *name, const char *info, int pos))
171 i = dict_scan_r (dict, 1, 0, str, before, after, f);