Graphviz  2.41.20171026.1811
dtopen.c
Go to the documentation of this file.
1 #include "dthdr.h"
2 static char* Version = "\n@(#)$Id$\0\n";
3 
4 /* Make a new dictionary
5 **
6 ** Written by Kiem-Phong Vo (5/25/96)
7 */
8 
9 Dt_t* dtopen(Dtdisc_t* disc, Dtmethod_t* meth)
10 {
11  Dt_t* dt = (Dt_t*)Version; /* shut-up unuse warning */
12  reg int e;
13  Dtdata_t* data;
14 
15  if(!disc || !meth)
16  return NIL(Dt_t*);
17 
18  /* allocate space for dictionary */
19  if(!(dt = (Dt_t*) malloc(sizeof(Dt_t))))
20  return NIL(Dt_t*);
21 
22  /* initialize all absolutely private data */
23  dt->searchf = NIL(Dtsearch_f);
24  dt->meth = NIL(Dtmethod_t*);
25  dt->disc = NIL(Dtdisc_t*);
26  dtdisc(dt,disc,0);
27  dt->type = DT_MALLOC;
28  dt->nview = 0;
29  dt->view = dt->walk = NIL(Dt_t*);
30  dt->user = NIL(void*);
31 
32  if(disc->eventf)
33  { /* if shared/persistent dictionary, get existing data */
34  data = NIL(Dtdata_t*);
35  if((e = (*disc->eventf)(dt,DT_OPEN,(void*)(&data),disc)) < 0)
36  goto err_open;
37  else if(e > 0)
38  { if(data)
39  { if(data->type&meth->type)
40  goto done;
41  else goto err_open;
42  }
43 
44  if(!disc->memoryf)
45  goto err_open;
46 
47  free((void*)dt);
48  if(!(dt = (*disc->memoryf)(0, 0, sizeof(Dt_t), disc)) )
49  return NIL(Dt_t*);
50  dt->searchf = NIL(Dtsearch_f);
51  dt->meth = NIL(Dtmethod_t*);
52  dt->disc = NIL(Dtdisc_t*);
53  dtdisc(dt,disc,0);
54  dt->type = DT_MEMORYF;
55  dt->nview = 0;
56  dt->view = dt->walk = NIL(Dt_t*);
57  }
58  }
59 
60  /* allocate sharable data */
61  if(!(data = (Dtdata_t*)(dt->memoryf)(dt,NIL(void*),sizeof(Dtdata_t),disc)) )
62  { err_open:
63  free((void*)dt);
64  return NIL(Dt_t*);
65  }
66 
67  data->type = meth->type;
68  data->here = NIL(Dtlink_t*);
69  data->htab = NIL(Dtlink_t**);
70  data->ntab = data->size = data->loop = 0;
71  data->minp = 0;
72 
73 done:
74  dt->data = data;
75  dt->searchf = meth->searchf;
76  dt->meth = meth;
77 
78  if(disc->eventf)
79  (*disc->eventf)(dt, DT_ENDOPEN, (void*)dt, disc);
80 
81  return dt;
82 }
Dtdisc_t * disc
Definition: cdt.h:101
Dtsearch_f searchf
Definition: cdt.h:100
int type
Definition: cdt.h:105
Dtmemory_f memoryf
Definition: cdt.h:88
int type
Definition: cdt.h:61
#define reg
Definition: dthdr.h:14
Dtevent_f eventf
Definition: cdt.h:89
Definition: cdt.h:65
CDT_API Dtdisc_t * dtdisc(Dt_t *dt, Dtdisc_t *, int)
Definition: dtdisc.c:22
Definition: cdt.h:80
#define DT_ENDOPEN
Definition: cdt.h:160
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
Definition: dtopen.c:9
Dt_t * walk
Definition: cdt.h:108
#define DT_MALLOC
Definition: dthdr.h:26
int size
Definition: cdt.h:73
#define NIL(t)
Definition: dthdr.h:13
#define DT_OPEN
Definition: cdt.h:156
#define DT_MEMORYF
Definition: dthdr.h:27
void * user
Definition: cdt.h:109
void *(* Dtsearch_f)(Dt_t *, void *, int)
Definition: cdt.h:37
Dtsearch_f searchf
Definition: cdt.h:60
Dt_t * view
Definition: cdt.h:107
int nview
Definition: cdt.h:106
Dtlink_t * here
Definition: cdt.h:67
Dtmethod_t * meth
Definition: cdt.h:104
int ntab
Definition: cdt.h:72
Definition: cdt.h:99
int minp
Definition: cdt.h:75
Dtdata_t * data
Definition: cdt.h:102
int type
Definition: cdt.h:66
EXTERN char * Version
Definition: globals.h:55
int loop
Definition: cdt.h:74
Dtmemory_f memoryf
Definition: cdt.h:103
Definition: legal.c:60