1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2009 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 static void dict_del_subtree (Dict dict, Dict_ptr ptr,
29 int (*f)(const char *, void *))
38 dict_bf_readp (dict->dbf, ptr, &p);
39 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
41 for (i = 0; i <= hi; i++)
45 /* string (Dict_char *) DICT_EOS terminated */
46 /* unsigned char length of information */
47 /* char * information */
48 char *info = (char*)p + indxp[-i];
50 (*f)(info + (dict_strlen((Dict_char*) info)+1)
51 *sizeof(Dict_char), client);
58 /* Dict_char sub char */
59 /* unsigned char length of information */
60 /* char * information */
61 char *info = (char*)p - indxp[-i];
62 memcpy (&subptr, info, sizeof(Dict_ptr));
64 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
67 (*f)(info+sizeof(Dict_ptr)+sizeof(Dict_char), client);
71 dict_del_subtree (dict, subptr, client, f);
73 /* page may be gone. reread it .. */
74 dict_bf_readp (dict->dbf, ptr, &p);
75 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
79 DICT_backptr(p) = dict->head.freelist;
80 dict->head.freelist = ptr;
81 dict_bf_touch (dict->dbf, ptr);
84 static int dict_del_string (Dict dict, const Dict_char *str, Dict_ptr ptr,
85 int sub_flag, void *client,
86 int (*f)(const char *, void *))
96 dict_bf_readp (dict->dbf, ptr, &p);
99 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
105 /* string (Dict_char *) DICT_EOS terminated */
106 /* unsigned char length of information */
107 /* char * information */
108 info = (char*)p + indxp[-mid];
110 cmp = dict_strcmp((Dict_char*) info, str);
113 /* determine if prefix match */
114 if (!dict_strncmp (str, (Dict_char*) info, dict_strlen(str)))
117 (*f)(info + (dict_strlen((Dict_char*) info)+1)
118 *sizeof(Dict_char), client);
120 hi = DICT_nodir(p)-1;
123 indxp[-mid] = indxp[-mid-1];
128 dict_bf_touch (dict->dbf, ptr);
131 /* start again (may not be the most efficient way to go)*/
137 /* normal delete: delete if equal */
140 hi = DICT_nodir(p)-1;
143 indxp[-mid] = indxp[-mid-1];
148 dict_bf_touch (dict->dbf, ptr);
158 /* Dict_ptr subptr */
159 /* Dict_char sub char */
160 /* unsigned char length of information */
161 /* char * information */
162 info = (char*)p - indxp[-mid];
163 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
167 memcpy (&subptr, info, sizeof(Dict_ptr));
168 if (*++str == DICT_EOS)
170 if (sub_flag && subptr)
173 memcpy (info, &null_ptr, sizeof(Dict_ptr));
175 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
177 info[sizeof(Dict_ptr)+sizeof(Dict_char)] = 0;
179 dict_bf_touch (dict->dbf, ptr);
182 (*f)(info+sizeof(Dict_ptr)+sizeof(Dict_char),
184 if (sub_flag && subptr)
185 dict_del_subtree (dict, subptr, client, f);
188 if (sub_flag && subptr)
191 dict_bf_touch (dict->dbf, ptr);
192 dict_del_subtree (dict, subptr, client, f);
201 dict_bf_readp (dict->dbf, ptr, &p);
203 hi = DICT_nodir(p)-1;
204 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
217 int dict_delete (Dict dict, const char *p)
219 return dict_del_string (dict, (const Dict_char*) p, dict->head.root, 0,
223 int dict_delete_subtree (Dict dict, const char *p, void *client,
224 int (*f)(const char *info, void *client))
226 return dict_del_string (dict, (const Dict_char*) p, dict->head.root, 1,
232 * c-file-style: "Stroustrup"
233 * indent-tabs-mode: nil
235 * vim: shiftwidth=4 tabstop=8 expandtab