Graphviz
14.1.2~dev.20260120.0924
Loading...
Searching...
No Matches
dtrestore.c
Go to the documentation of this file.
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
}
DT_OBAG
#define DT_OBAG
Definition
cdt.h:121
DT_SET
#define DT_SET
Definition
cdt.h:119
DT_RENEW
#define DT_RENEW
Definition
cdt.h:130
DT_OSET
#define DT_OSET
Definition
cdt.h:120
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:13
type
expr procedure type
Definition
exparse.y:208
NULL
node NULL
Definition
grammar.y:181
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:98
dt_s_::meth
Dtmethod_t * meth
Definition
cdt.h:102
dt_s_::data
Dtdata_t data
sharable data
Definition
cdt.h:101
dtlink_s_
Definition
cdt.h:50
dtlink_s_::right
Dtlink_t * right
Definition
cdt.h:51
s
Definition
grammar.c:90
lib
cdt
dtrestore.c
Generated by
1.9.8