Debian Codegraph @

lib/cdt/dtrestore.c

raw
1 #include "config.h"
2
3 #include <cdt/dthdr.h>
4 #include <stddef.h>
5
6 /* Restore dictionary from given tree or list of elements.
7 ** There are two cases. If called from within, list is nil.
8 ** From without, list is not nil and data->size must be 0.
9 **
10 ** Written by Kiem-Phong Vo (5/25/96)
11 */
12
13 int dtrestore(Dt_t* dt, Dtlink_t* list)
14 {
15 Dtlink_t *t, **s, **ends;
16 int type;
17 Dtsearch_f searchf = dt->meth->searchf;
18
19 type = dt->data.type & DT_FLATTEN;
20 if(!list) /* restoring a flattened dictionary */
21 { if(!type)
22 return -1;
23 list = dt->data.here;
24 }
25 else /* restoring an extracted list of elements */
26 { if (dt->data.size != 0)
27 return -1;
28 type = 0;
29 }
30 dt->data.type &= ~DT_FLATTEN;
31
32 if (dt->data.type & DT_SET)
33 { dt->data.here = NULL;
34 if(type) /* restoring a flattened dictionary */
35 { for (ends = (s = dt->data.htab) + dt->data.ntab; s < ends; ++s)
36 { if((t = *s) )
37 { *s = list;
38 list = t->right;
39 t->right = NULL;
40 }
41 }
42 }
43 else /* restoring an extracted list of elements */
44 { dt->data.size = 0;
45 while(list)
46 { t = list->right;
47 searchf(dt, list, DT_RENEW);
48 list = t;
49 }
50 }
51 }
52 else
53 { if (dt->data.type & (DT_OSET|DT_OBAG))
54 dt->data.here = list;
55 else // if (dt->data.type & (DT_LIST|DT_STACK))
56 { dt->data.here = NULL;
57 dt->data.head = list;
58 }
59 if(!type)
60 --dt->data.size;
61 }
62
63 return 0;
64 }