1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1985-2011 AT&T Intellectual Property * 5 * and is licensed under the * 6 * Eclipse Public License, Version 1.0 * 7 * by AT&T Intellectual Property * 8 * * 9 * A copy of the License is available at * 10 * http://www.eclipse.org/org/documents/epl-v10.html * 11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) * 12 * * 13 * Information and Software Systems Research * 14 * AT&T Research * 15 * Florham Park NJ * 16 * * 17 * Glenn Fowler <gsf@research.att.com> * 18 * David Korn <dgk@research.att.com> * 19 * Phong Vo <kpv@research.att.com> * 20 * * 21 ***********************************************************************/ 22 #include "dthdr.h" 23 24 /* Change search method. 25 ** 26 ** Written by Kiem-Phong Vo (05/25/96) 27 */ 28 29 #if __STD_C 30 Dtmethod_t* dtmethod(Dt_t* dt, Dtmethod_t* meth) 31 #else 32 Dtmethod_t* dtmethod(dt, meth) 33 Dt_t* dt; 34 Dtmethod_t* meth; 35 #endif 36 { 37 Dtlink_t *list; 38 Dtdisc_t *disc = dt->disc; 39 Dtmethod_t *oldmt = dt->meth; 40 Dtdata_t *newdt, *olddt = dt->data; 41 42 if(!meth || meth == oldmt) 43 return oldmt; 44 45 /* ask discipline if switching to new method is ok */ 46 if(disc->eventf && (*disc->eventf)(dt,DT_METH,(Void_t*)meth,disc) < 0) 47 return NIL(Dtmethod_t*); 48 49 list = dtextract(dt); /* extract elements out of dictionary */ 50 51 /* try to create internal structure for new method */ 52 if(dt->searchf == oldmt->searchf) /* ie, not viewpathing */ 53 dt->searchf = meth->searchf; 54 dt->meth = meth; 55 dt->data = NIL(Dtdata_t*); 56 if((*dt->meth->eventf)(dt, DT_OPEN, NIL(Void_t*)) < 0 ) 57 newdt = NIL(Dtdata_t*); 58 else newdt = dt->data; 59 60 /* see what need to be done to data of the old method */ 61 if(dt->searchf == meth->searchf) 62 dt->searchf = oldmt->searchf; 63 dt->meth = oldmt; 64 dt->data = olddt; 65 if(newdt) /* switch was successful, remove old data */ 66 { (void)(*dt->meth->eventf)(dt, DT_CLOSE, NIL(Void_t*)); 67 68 if(dt->searchf == oldmt->searchf) 69 dt->searchf = meth->searchf; 70 dt->meth = meth; 71 dt->data = newdt; 72 dtrestore(dt, list); 73 return oldmt; 74 } 75 else /* switch failed, restore dictionary to previous states */ 76 { dtrestore(dt, list); 77 return NIL(Dtmethod_t*); 78 } 79 } 80 81 /* customize certain actions in a container data structure */ 82 int dtcustomize(Dt_t* dt, int type, int action) 83 { 84 int done = 0; 85 86 if((type&DT_SHARE) && 87 (!dt->meth->eventf || (*dt->meth->eventf)(dt, DT_SHARE, (Void_t*)((long)action)) >= 0) ) 88 { if(action <= 0 ) 89 dt->data->type &= ~DT_SHARE; 90 else dt->data->type |= DT_SHARE; 91 done |= DT_SHARE; 92 } 93 94 if((type&DT_ANNOUNCE) && 95 (!dt->meth->eventf || (*dt->meth->eventf)(dt, DT_ANNOUNCE, (Void_t*)((long)action)) >= 0) ) 96 { if(action <= 0 ) 97 dt->data->type &= ~DT_ANNOUNCE; 98 else dt->data->type |= DT_ANNOUNCE; 99 done |= DT_ANNOUNCE; 100 } 101 102 if((type&DT_OPTIMIZE) && 103 (!dt->meth->eventf || (*dt->meth->eventf)(dt, DT_OPTIMIZE, (Void_t*)((long)action)) >= 0) ) 104 done |= DT_OPTIMIZE; 105 106 return done; 107 } 108