| 1 |
#include "config.h" |
| 2 |
|
| 3 |
#include <cdt/dthdr.h> |
| 4 |
#include <stddef.h> |
| 5 |
|
| 6 |
/* Change discipline. |
| 7 |
** dt : dictionary |
| 8 |
** disc : discipline |
| 9 |
** |
| 10 |
** Written by Kiem-Phong Vo (5/26/96) |
| 11 |
*/ |
| 12 |
|
| 13 |
Dtdisc_t *dtdisc(Dt_t *dt, Dtdisc_t *disc) { |
| 14 |
Dtsearch_f searchf; |
| 15 |
Dtlink_t *r, *t; |
| 16 |
char* k; |
| 17 |
Dtdisc_t* old; |
| 18 |
|
| 19 |
if(!(old = dt->disc) ) /* initialization call from dtopen() */ |
| 20 |
{ dt->disc = disc; |
| 21 |
return disc; |
| 22 |
} |
| 23 |
|
| 24 |
if(!disc) /* only want to know current discipline */ |
| 25 |
return old; |
| 26 |
|
| 27 |
searchf = dt->meth->searchf; |
| 28 |
|
| 29 |
UNFLATTEN(dt); |
| 30 |
|
| 31 |
dt->disc = disc; |
| 32 |
|
| 33 |
r = dtflatten(dt); |
| 34 |
dt->data.type &= ~DT_FLATTEN; |
| 35 |
dt->data.here = NULL; |
| 36 |
dt->data.size = 0; |
| 37 |
|
| 38 |
if (dt->data.type & DT_SET) |
| 39 |
{ Dtlink_t **s, **ends; |
| 40 |
ends = (s = dt->data.htab) + dt->data.ntab; |
| 41 |
while(s < ends) |
| 42 |
*s++ = NULL; |
| 43 |
} |
| 44 |
|
| 45 |
/* reinsert them */ |
| 46 |
while(r) |
| 47 |
{ t = r->right; |
| 48 |
k = _DTOBJ(r,disc->link); |
| 49 |
k = _DTKEY(k, disc->key, disc->size); |
| 50 |
r->hash = dtstrhash(k, disc->size); |
| 51 |
(void)searchf(dt, r, DT_RENEW); |
| 52 |
r = t; |
| 53 |
} |
| 54 |
|
| 55 |
return old; |
| 56 |
} |