Graphviz
12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
dtrestore.c
Go to the documentation of this file.
1
#include <
cdt/dthdr.h
>
2
#include <stddef.h>
3
4
/* Restore dictionary from given tree or list of elements.
5
** There are two cases. If called from within, list is nil.
6
** From without, list is not nil and data->size must be 0.
7
**
8
** Written by Kiem-Phong Vo (5/25/96)
9
*/
10
11
int
dtrestore
(
Dt_t
* dt,
Dtlink_t
* list)
12
{
13
Dtlink_t
*t, **
s
, **ends;
14
int
type
;
15
Dtsearch_f
searchf = dt->
meth
->
searchf
;
16
17
type
= dt->
data
->
type
&
DT_FLATTEN
;
18
if
(!list)
/* restoring a flattened dictionary */
19
{
if
(!
type
)
20
return
-1;
21
list = dt->
data
->
here
;
22
}
23
else
/* restoring an extracted list of elements */
24
{
if
(dt->
data
->
size
!= 0)
25
return
-1;
26
type
= 0;
27
}
28
dt->
data
->
type
&= ~DT_FLATTEN;
29
30
if
(dt->
data
->
type
&
DT_SET
)
31
{ dt->
data
->
here
=
NULL
;
32
if
(
type
)
/* restoring a flattened dictionary */
33
{
for
(ends = (
s
= dt->
data
->htab) + dt->
data
->
ntab
;
s
< ends; ++
s
)
34
{
if
((t = *
s
) )
35
{ *
s
= list;
36
list = t->
right
;
37
t->
right
=
NULL
;
38
}
39
}
40
}
41
else
/* restoring an extracted list of elements */
42
{ dt->
data
->
size
= 0;
43
while
(list)
44
{ t = list->
right
;
45
searchf(dt, list,
DT_RENEW
);
46
list = t;
47
}
48
}
49
}
50
else
51
{
if
(dt->
data
->
type
&(
DT_OSET
|
DT_OBAG
))
52
dt->
data
->
here
= list;
53
else
/*if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE))*/
54
{ dt->
data
->
here
=
NULL
;
55
dt->
data
->head = list;
56
}
57
if
(!
type
)
58
dt->
data
->
size
= -1;
59
}
60
61
return
0;
62
}
DT_OBAG
#define DT_OBAG
Definition
cdt.h:126
DT_SET
#define DT_SET
Definition
cdt.h:124
DT_RENEW
#define DT_RENEW
Definition
cdt.h:136
DT_OSET
#define DT_OSET
Definition
cdt.h:125
Dtsearch_f
void *(* Dtsearch_f)(Dt_t *, void *, int)
Definition
cdt.h:49
dthdr.h
DT_FLATTEN
#define DT_FLATTEN
Definition
dthdr.h:18
dtrestore
int dtrestore(Dt_t *dt, Dtlink_t *list)
Definition
dtrestore.c:11
type
expr procedure type
Definition
exparse.y:211
NULL
node NULL
Definition
grammar.y:149
_dt_s
Definition
cdt.h:104
_dt_s::data
Dtdata_t * data
Definition
cdt.h:106
_dt_s::meth
Dtmethod_t * meth
Definition
cdt.h:107
_dtdata_s::ntab
int ntab
Definition
cdt.h:82
_dtdata_s::here
Dtlink_t * here
Definition
cdt.h:77
_dtdata_s::type
int type
Definition
cdt.h:76
_dtdata_s::size
int size
Definition
cdt.h:83
_dtlink_s
Definition
cdt.h:55
_dtlink_s::right
Dtlink_t * right
Definition
cdt.h:55
_dtmethod_s::searchf
Dtsearch_f searchf
Definition
cdt.h:70
s
Definition
grammar.c:93
lib
cdt
dtrestore.c
Generated by
1.9.8