/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#include "dthdr.h"2223/* Close a dictionary24**25** Written by Kiem-Phong Vo (11/15/2010)26*/27#if __STD_C28int dtclose(Dt_t* dt)29#else30int dtclose(dt)31Dt_t* dt;32#endif33{34int ev, type;35Dt_t pdt;36Dtdisc_t *disc = dt->disc;3738if(!dt || dt->nview > 0 ) /* can't close if being viewed */39return -1;4041if(disc && disc->eventf) /* announce closing event */42ev = (*disc->eventf)(dt, DT_CLOSE, (Void_t*)1, disc);43else ev = 0;44if(ev < 0) /* cannot close */45return -1;4647if(dt->view) /* turn off viewing at this point */48dtview(dt,NIL(Dt_t*));4950type = dt->data->type; /* save before memory is freed */51memcpy(&pdt, dt, sizeof(Dt_t));5253if(ev == 0 ) /* release all allocated data */54{ (void)(*(dt->meth->searchf))(dt,NIL(Void_t*),DT_CLEAR);55(void)(*dt->meth->eventf)(dt, DT_CLOSE, (Void_t*)0);56/**/DEBUG_ASSERT(!dt->data);57}58if(!(type&DT_INDATA) )59(void)free(dt);6061if(disc && disc->eventf) /* announce end of closing activities */62(void)(*disc->eventf)(&pdt, DT_ENDCLOSE, (Void_t*)0, disc);6364return 0;65}666768