/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2012 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/* Change discipline.24** dt : dictionary25** disc : discipline26**27** Written by Kiem-Phong Vo (5/26/96)28*/2930#if __STD_C31static Void_t* dtmemory(Dt_t* dt, Void_t* addr, size_t size, Dtdisc_t* disc)32#else33static Void_t* dtmemory(dt, addr, size, disc)34Dt_t* dt; /* dictionary */35Void_t* addr; /* address to be manipulate */36size_t size; /* size to obtain */37Dtdisc_t* disc; /* discipline */38#endif39{40if(addr)41{ if(size == 0)42{ free(addr);43return NIL(Void_t*);44}45else return realloc(addr,size);46}47else return size > 0 ? malloc(size) : NIL(Void_t*);48}4950#if __STD_C51Dtdisc_t* dtdisc(Dt_t* dt, Dtdisc_t* disc, int type)52#else53Dtdisc_t* dtdisc(dt,disc,type)54Dt_t* dt;55Dtdisc_t* disc;56int type;57#endif58{59Dtdisc_t *old;60Dtlink_t *list;6162if(!(old = dt->disc) ) /* initialization call from dtopen() */63{ dt->disc = disc;64if(!(dt->memoryf = disc->memoryf) )65dt->memoryf = dtmemory;66return disc;67}6869if(!disc) /* only want to know current discipline */70return old;7172if(old->eventf && (*old->eventf)(dt,DT_DISC,(Void_t*)disc,old) < 0)73return NIL(Dtdisc_t*);7475if((type & (DT_SAMEHASH|DT_SAMECMP)) != (DT_SAMEHASH|DT_SAMECMP) )76list = dtextract(dt); /* grab the list of objects if any */77else list = NIL(Dtlink_t*);7879dt->disc = disc;80if(!(dt->memoryf = disc->memoryf) )81dt->memoryf = dtmemory;8283if(list ) /* reinsert extracted objects (with new discipline) */84dtrestore(dt, list);8586return old;87}888990