1 /* $Id: delete.c,v 1.8 2002-08-02 19:26:55 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
32 static void dict_del_subtree (Dict dict, Dict_ptr ptr,
34 int (*f)(const char *, void *))
47 dict_bf_readp (dict->dbf, ptr, &p);
49 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
51 for (i = 0; i <= hi; i++)
55 /* string (Dict_char *) DICT_EOS terminated */
56 /* unsigned char length of information */
57 /* char * information */
58 char *info = (char*)p + indxp[-i];
60 (*f)(info + (dict_strlen((Dict_char*) info)+1)
61 *sizeof(Dict_char), client);
69 /* Dict_char sub char */
70 /* unsigned char length of information */
71 /* char * information */
72 char *info = (char*)p - indxp[-i];
73 memcpy (&subptr, info, sizeof(Dict_ptr));
75 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
78 (*f)(info+sizeof(Dict_ptr)+sizeof(Dict_char), client);
82 dict_del_subtree (dict, subptr, client, f);
89 DICT_backptr(p) = dict->head.freelist;
90 dict->head.freelist = ptr;
91 dict_bf_touch (dict->dbf, ptr);
94 static int dict_del_string (Dict dict, const Dict_char *str, Dict_ptr ptr,
95 int sub_flag, void *client,
96 int (*f)(const char *, void *))
106 dict_bf_readp (dict->dbf, ptr, &p);
108 hi = DICT_nodir(p)-1;
109 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
115 /* string (Dict_char *) DICT_EOS terminated */
116 /* unsigned char length of information */
117 /* char * information */
118 info = (char*)p + indxp[-mid];
120 cmp = dict_strcmp((Dict_char*) info, str);
123 /* determine if prefix match */
124 if (!dict_strncmp (str, (Dict_char*) info, dict_strlen(str)))
127 (*f)(info + (dict_strlen((Dict_char*) info)+1)
128 *sizeof(Dict_char), client);
130 hi = DICT_nodir(p)-1;
133 indxp[-mid] = indxp[-mid-1];
138 dict_bf_touch (dict->dbf, ptr);
141 /* start again (may not be the most efficient way to go)*/
147 /* normal delete: delete if equal */
150 hi = DICT_nodir(p)-1;
153 indxp[-mid] = indxp[-mid-1];
158 dict_bf_touch (dict->dbf, ptr);
168 /* Dict_ptr subptr */
169 /* Dict_char sub char */
170 /* unsigned char length of information */
171 /* char * information */
172 info = (char*)p - indxp[-mid];
173 memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char));
177 memcpy (&subptr, info, sizeof(Dict_ptr));
178 if (*++str == DICT_EOS)
180 if (sub_flag && subptr)
183 memcpy (info, &null_ptr, sizeof(Dict_ptr));
185 if (info[sizeof(Dict_ptr)+sizeof(Dict_char)])
187 info[sizeof(Dict_ptr)+sizeof(Dict_char)] = 0;
189 dict_bf_touch (dict->dbf, ptr);
192 (*f)(info+sizeof(Dict_ptr)+sizeof(Dict_char),
194 if (sub_flag && subptr)
195 dict_del_subtree (dict, subptr, client, f);
198 if (sub_flag && subptr)
201 dict_bf_touch (dict->dbf, ptr);
202 dict_del_subtree (dict, subptr, client, f);
211 dict_bf_readp (dict->dbf, ptr, &p);
213 hi = DICT_nodir(p)-1;
214 indxp = (short*) ((char*) p+DICT_bsize(p)-sizeof(short));
227 int dict_delete (Dict dict, const char *p)
229 return dict_del_string (dict, (const Dict_char*) p, dict->head.root, 0,
233 int dict_delete_subtree (Dict dict, const char *p, void *client,
234 int (*f)(const char *info, void *client))
236 return dict_del_string (dict, (const Dict_char*) p, dict->head.root, 1,