1 | #include "dthdr.h" |
2 | |
3 | /* Close a dictionary |
4 | ** |
5 | ** Written by Kiem-Phong Vo (05/25/96) |
6 | */ |
7 | int dtclose(reg Dt_t* dt) |
8 | { |
9 | Dtdisc_t *disc; |
10 | int ev = 0; |
11 | |
12 | if(!dt || dt->nview > 0 ) /* can't close if being viewed */ |
13 | return -1; |
14 | |
15 | /* announce the close event to see if we should continue */ |
16 | disc = dt->disc; |
17 | if(disc->eventf && |
18 | (ev = (*disc->eventf)(dt,DT_CLOSE,NIL(void*),disc)) < 0) |
19 | return -1; |
20 | |
21 | if(dt->view) /* turn off viewing */ |
22 | dtview(dt,NIL(Dt_t*)); |
23 | |
24 | if(ev == 0) /* release all allocated data */ |
25 | { (void)(*(dt->meth->searchf))(dt,NIL(void*),DT_CLEAR); |
26 | if(dtsize(dt) > 0) |
27 | return -1; |
28 | |
29 | if(dt->data->ntab > 0) |
30 | (*dt->memoryf)(dt,(void*)dt->data->htab,0,disc); |
31 | (*dt->memoryf)(dt,(void*)dt->data,0,disc); |
32 | } |
33 | |
34 | if(dt->type == DT_MALLOC) |
35 | free((void*)dt); |
36 | else if(ev == 0 && dt->type == DT_MEMORYF) |
37 | (*dt->memoryf)(dt, (void*)dt, 0, disc); |
38 | |
39 | if(disc->eventf) |
40 | (void)(*disc->eventf)(dt, DT_ENDCLOSE, NIL(void*), disc); |
41 | |
42 | return 0; |
43 | } |
44 | |