Graphviz
13.0.0~dev.20241220.2304
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))
54
{ dt->
data
.
here
=
NULL
;
55
dt->
data
.head = list;
56
}
57
if
(!
type
)
58
--dt->
data
.
size
;
59
}
60
61
return
0;
62
}
DT_OBAG
#define DT_OBAG
Definition
cdt.h:122
DT_SET
#define DT_SET
Definition
cdt.h:120
DT_RENEW
#define DT_RENEW
Definition
cdt.h:131
DT_OSET
#define DT_OSET
Definition
cdt.h:121
Dtsearch_f
void *(* Dtsearch_f)(Dt_t *, void *, int)
Definition
cdt.h:45
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:208
NULL
node NULL
Definition
grammar.y:163
Dtdata_t::size
int size
Definition
cdt.h:79
Dtdata_t::here
Dtlink_t * here
Definition
cdt.h:73
Dtdata_t::type
int type
Definition
cdt.h:72
Dtdata_t::ntab
int ntab
Definition
cdt.h:78
Dtmethod_t::searchf
Dtsearch_f searchf
Definition
cdt.h:66
dt_s_
Definition
cdt.h:100
dt_s_::meth
Dtmethod_t * meth
Definition
cdt.h:103
dt_s_::data
Dtdata_t data
sharable data
Definition
cdt.h:102
dtlink_s_
Definition
cdt.h:51
dtlink_s_::right
Dtlink_t * right
Definition
cdt.h:51
s
Definition
grammar.c:93
lib
cdt
dtrestore.c
Generated by
1.9.8