2 /* ###--------------------------------------------------------------### */
4 /* file : beh_dict.c */
5 /* date : Jun 15 1994 */
7 /* authors : Pirouz BAZARGAN SABET */
8 /* content : low-level function */
10 /* ###--------------------------------------------------------------### */
17 #define BEH_HSZDFN 307
19 static struct beden
*BEH_DCEHED
= NULL
; /* free entries list */
20 static struct bedrd
*BEH_DCRHED
= NULL
; /* free records list */
22 /* ###--------------------------------------------------------------### */
23 /* function : beh_addent */
24 /* description : add a new entry point to the dictionary */
25 /* called func. : mbkalloc */
26 /* ###--------------------------------------------------------------### */
28 static struct beden
*beh_addent (head
, key
)
37 if (BEH_DCEHED
== NULL
)
39 BEH_DCEHED
= (struct beden
*)
40 mbkalloc (sizeof (struct beden
) * BEH_ALODFN
);
43 for (i
=1 ; i
<BEH_ALODFN
; i
++)
45 entry
->NEXT
= entry
+ 1;
52 BEH_DCEHED
= BEH_DCEHED
->NEXT
;
61 /* ###--------------------------------------------------------------### */
62 /* function : beh_addrcd */
63 /* description : add a new record to the dictionary */
64 /* called func. : mbkalloc */
65 /* ###--------------------------------------------------------------### */
67 static struct bedrd
*beh_addrcd (head
, key
)
76 if (BEH_DCRHED
== NULL
)
78 BEH_DCRHED
= (struct bedrd
*)
79 mbkalloc (sizeof (struct bedrd
) * BEH_ALODFN
);
82 for (i
=1 ; i
<BEH_ALODFN
; i
++)
84 recrd
->NEXT
= recrd
+ 1;
91 BEH_DCRHED
= BEH_DCRHED
->NEXT
;
107 /* ###--------------------------------------------------------------### */
108 /* function : beh_initab */
109 /* description : create a new dictionary */
110 /* called func. : mbkalloc */
111 /* ###--------------------------------------------------------------### */
113 struct beden
**beh_initab ()
119 head
= (struct beden
**)
120 mbkalloc (sizeof(struct beden
*) * BEH_HSZDFN
);
122 for (i
=0 ; i
<BEH_HSZDFN
; i
++)
128 /* ###--------------------------------------------------------------### */
129 /* function : beh_addtab */
130 /* description : save a data in a dictionary */
131 /* called func. : beh_addent, beh_addrcd */
132 /* ###--------------------------------------------------------------### */
134 void beh_addtab (head
, key_str
, ctx_str
, field
, valu
)
146 struct beden
*entry_pnt
;
147 struct bedrd
*recrd_pnt
;
149 key
= ((unsigned long) key_str
) + ((unsigned long) ctx_str
);
151 index
= key
% BEH_HSZDFN
;
152 entry_pnt
= head
[index
];
154 while (entry_pnt
!= NULL
)
156 if (entry_pnt
->KEY
== key_str
)
161 entry_pnt
= entry_pnt
->NEXT
;
166 head
[index
] = beh_addent (head
[index
], key_str
);
167 entry_pnt
= head
[index
];
171 recrd_pnt
= entry_pnt
->DATA
;
172 while (recrd_pnt
!= NULL
)
174 if (recrd_pnt
->KEY
== ctx_str
)
179 recrd_pnt
= recrd_pnt
->NEXT
;
184 entry_pnt
->DATA
= beh_addrcd (entry_pnt
->DATA
, ctx_str
);
185 recrd_pnt
= entry_pnt
->DATA
;
191 recrd_pnt
->FD0_VAL
= valu
; break;
193 recrd_pnt
->FD1_VAL
= valu
; break;
195 recrd_pnt
->FD2_VAL
= valu
; break;
197 recrd_pnt
->FD3_VAL
= valu
; break;
199 recrd_pnt
->FD4_VAL
= valu
; break;
201 recrd_pnt
->FD5_VAL
= valu
; break;
203 recrd_pnt
->FD6_VAL
= valu
; break;
205 recrd_pnt
->PNT_VAL
= valu
; break;
210 /* ###--------------------------------------------------------------### */
211 /* function : beh_chktab */
212 /* description : extract a data from a dictionary */
213 /* called func. : none */
214 /* ###--------------------------------------------------------------### */
216 long beh_chktab (head
, key_str
, ctx_str
, field
)
218 struct beden
**head
;
228 struct beden
*entry_pnt
;
229 struct bedrd
*recrd_pnt
;
231 key
= ((unsigned long) key_str
) + ((unsigned long) ctx_str
);
233 index
= key
% BEH_HSZDFN
;
234 entry_pnt
= head
[index
];
236 while (entry_pnt
!= NULL
)
238 if (entry_pnt
->KEY
== key_str
)
243 entry_pnt
= entry_pnt
->NEXT
;
249 recrd_pnt
= entry_pnt
->DATA
;
250 while (recrd_pnt
!= NULL
)
252 if (recrd_pnt
->KEY
== ctx_str
)
257 recrd_pnt
= recrd_pnt
->NEXT
;
264 valu
= recrd_pnt
->FD0_VAL
; break;
266 valu
= recrd_pnt
->FD1_VAL
; break;
268 valu
= recrd_pnt
->FD2_VAL
; break;
270 valu
= recrd_pnt
->FD3_VAL
; break;
272 valu
= recrd_pnt
->FD4_VAL
; break;
274 valu
= recrd_pnt
->FD5_VAL
; break;
276 valu
= recrd_pnt
->FD6_VAL
; break;
278 valu
= recrd_pnt
->PNT_VAL
; break;
286 /* ###--------------------------------------------------------------### */
287 /* function : beh_fretab */
288 /* description : release a dictionary */
289 /* called func. : mbkfree */
290 /* ###--------------------------------------------------------------### */
292 void beh_fretab (pt_hash
)
294 struct beden
**pt_hash
;
297 struct beden
*pt_entry
;
298 struct beden
*pt_nxtentry
;
299 struct bedrd
*pt_record
;
304 for (i
=0 ; i
<BEH_HSZDFN
; i
++)
306 if ((pt_entry
= pt_hash
[i
]) != NULL
)
308 while (pt_entry
!= NULL
)
310 pt_record
= pt_entry
->DATA
;
312 while (pt_record
->NEXT
!= NULL
)
313 pt_record
= pt_record
->NEXT
;
315 pt_record
->NEXT
= BEH_DCRHED
;
316 BEH_DCRHED
= pt_entry
->DATA
;
318 pt_nxtentry
= pt_entry
->NEXT
;
319 pt_entry
->NEXT
= BEH_DCEHED
;
320 BEH_DCEHED
= pt_entry
;
321 pt_entry
= pt_nxtentry
;