1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
23 static char* Version
= "\n@(#)$Id: cdt (AT&T Research) 2005-04-20 $\0\n";
25 /* Make a new dictionary
27 ** Written by Kiem-Phong Vo (5/25/96)
31 Dt_t
* dtopen(Dtdisc_t
* disc
, Dtmethod_t
* meth
)
33 Dt_t
* dtopen(disc
, meth
)
38 Dt_t
* dt
= (Dt_t
*)Version
; /* shut-up unuse warning */
45 /* allocate space for dictionary */
46 if(!(dt
= (Dt_t
*) malloc(sizeof(Dt_t
))))
49 /* initialize all absolutely private data */
50 dt
->searchf
= NIL(Dtsearch_f
);
51 dt
->meth
= NIL(Dtmethod_t
*);
52 dt
->disc
= NIL(Dtdisc_t
*);
56 dt
->view
= dt
->walk
= NIL(Dt_t
*);
57 dt
->user
= NIL(Void_t
*);
60 { /* if shared/persistent dictionary, get existing data */
61 data
= NIL(Dtdata_t
*);
62 if((e
= (*disc
->eventf
)(dt
,DT_OPEN
,(Void_t
*)(&data
),disc
)) < 0)
66 { if(data
->type
&meth
->type
)
75 if(!(dt
= (*disc
->memoryf
)(0, 0, sizeof(Dt_t
), disc
)) )
77 dt
->searchf
= NIL(Dtsearch_f
);
78 dt
->meth
= NIL(Dtmethod_t
*);
79 dt
->disc
= NIL(Dtdisc_t
*);
81 dt
->type
= DT_MEMORYF
;
83 dt
->view
= dt
->walk
= NIL(Dt_t
*);
87 /* allocate sharable data */
88 if(!(data
= (Dtdata_t
*)(dt
->memoryf
)(dt
,NIL(Void_t
*),sizeof(Dtdata_t
),disc
)) )
94 data
->type
= meth
->type
;
95 data
->here
= NIL(Dtlink_t
*);
96 data
->htab
= NIL(Dtlink_t
**);
97 data
->ntab
= data
->size
= data
->loop
= 0;
102 dt
->searchf
= meth
->searchf
;
106 (*disc
->eventf
)(dt
, DT_ENDOPEN
, (Void_t
*)dt
, disc
);