Graphviz  2.41.20171026.1811
dtclose.c
Go to the documentation of this file.
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 }
CDT_API int dtclose(Dt_t *)
#define DT_CLEAR
Definition: cdt.h:146
#define reg
Definition: dthdr.h:14
CDT_API Dt_t * dtview(Dt_t *, Dt_t *)
Dtevent_f eventf
Definition: cdt.h:89
Definition: cdt.h:80
#define DT_MALLOC
Definition: dthdr.h:26
#define NIL(t)
Definition: dthdr.h:13
#define DT_MEMORYF
Definition: dthdr.h:27
CDT_API int dtsize(Dt_t *)
Definition: dtsize.c:12
#define DT_CLOSE
Definition: cdt.h:157
Definition: cdt.h:99
#define DT_ENDCLOSE
Definition: cdt.h:161