Graphviz 2.29.20120208.0545
lib/cdt/dtclose.c
Go to the documentation of this file.
00001 #include        "dthdr.h"
00002 
00003 /*      Close a dictionary
00004 **
00005 **      Written by Kiem-Phong Vo (05/25/96)
00006 */
00007 #if __STD_C
00008 int dtclose(reg Dt_t* dt)
00009 #else
00010 int dtclose(dt)
00011 reg Dt_t*       dt;
00012 #endif
00013 {
00014         Dtdisc_t        *disc;
00015         int             ev = 0;
00016 
00017         if(!dt || dt->nview > 0 ) /* can't close if being viewed */
00018                 return -1;
00019 
00020         /* announce the close event to see if we should continue */
00021         disc = dt->disc;
00022         if(disc->eventf &&
00023            (ev = (*disc->eventf)(dt,DT_CLOSE,NIL(Void_t*),disc)) < 0)
00024                 return -1;
00025 
00026         if(dt->view)    /* turn off viewing */
00027                 dtview(dt,NIL(Dt_t*));
00028 
00029         if(ev == 0) /* release all allocated data */
00030         {       (void)(*(dt->meth->searchf))(dt,NIL(Void_t*),DT_CLEAR);
00031                 if(dtsize(dt) > 0)
00032                         return -1;
00033 
00034                 if(dt->data->ntab > 0)
00035                         (*dt->memoryf)(dt,(Void_t*)dt->data->htab,0,disc);
00036                 (*dt->memoryf)(dt,(Void_t*)dt->data,0,disc);
00037         }
00038 
00039         if(dt->type == DT_MALLOC)
00040                 free((Void_t*)dt);
00041         else if(ev == 0 && dt->type == DT_MEMORYF)
00042                 (*dt->memoryf)(dt, (Void_t*)dt, 0, disc);
00043 
00044         if(disc->eventf)
00045                 (void)(*disc->eventf)(dt, DT_ENDCLOSE, NIL(Void_t*), disc);
00046 
00047         return 0;
00048 }