Debian Codegraph @

gui/GraphLib/libsrc/uimxR5/src/uxdd.c

raw
1 /*---------------------------------------------------------------------
2 * $Date: 2009-08-18 15:23:20 $ $Revision: 1.3 $
3 *---------------------------------------------------------------------
4 *
5 *
6 * Copyright (c) 1992, Visual Edge Software Ltd.
7 *
8 * ALL RIGHTS RESERVED. Permission to use, copy, modify, and
9 * distribute this software and its documentation for any purpose
10 * and without fee is hereby granted, provided that the above
11 * copyright notice appear in all copies and that both that
12 * copyright notice and this permission notice appear in supporting
13 * documentation, and that the name of Visual Edge Software not be
14 * used in advertising or publicity pertaining to distribution of
15 * the software without specific, written prior permission. The year
16 * included in the notice is the year of the creation of the work.
17
18 .VERSION
19 090818 last modif
20
21 *-------------------------------------------------------------------*/
22 /*---------------------------------------------------------------------
23 * File_Description_Section
24 *--------------------------------------------------------------------*/
25
26 /*--- include files ---*/
27 #include "version.h"
28 #include <string.h>
29 #include "UxLib.h"
30 #include "UxLibP.h"
31 #include "uxdd.h"
32 #include "utype.h"
33 #include "types.h"
34 #include "uimx_cat.h"
35 #include "lib_ds.h"
36
37 /*--- macro symbolic constants ---*/
38 #define HASHSIZE 100
39 #define NO_ERROR 0
40 #define ERROR -1
41
42 /*--- macro functions ---*/
43 #define CGETS(x, y) UxCatGets (MC_LIBUIMX,(x),(y))
44
45 /*--- types ---*/
46
47 /*--- external functions ---*/
48
49 extern int UxStrEqual(), UxFindValue();
50
51 /*--- external variables ---*/
52
53 /*--- global variables ---*/
54
55 /*--- file global variables ---*/
56 M_FILE_VERSION("$Header")
57 DD *DDTable[HASHSIZE];
58 static int hash();
59 static DD *DDTableLookup();
60 static DD *DDMake();
61 static CL_ENTRY *CLMake();
62
63 /*--- forward declaration of static functions ---*/
64
65 /*------------------------------------------------------------
66 * COMMENT_BOX
67 *-----------------------------------------------------------*/
68
69
70 /*--------------------------------------------------------------------------
71 NAME: DD* *DDMake (name, ut, xt)
72 INPUT: char* name, int ut, xt
73 RETURN: return pointer to DD entry
74 DESCRIPTION: given resources name and its uimxtype Xtype, Make an DD entry
75 CREATION: 17 Nov. 1989
76 REVISIONS: --
77 --------------------------------------------------------------------------*/
78
79 static DD *DDMake (name, ut, xt)
80 char *name;
81 int ut, xt;
82 {
83 DD* dd = (DD*) UxMalloc(sizeof(DD));
84
85 strcpy(dd->name, name);
86 dd->utype= ut;
87 dd->xtype= xt;
88 dd->next_cl= (CL_ENTRY *)0;
89 dd->next = (DD *)0;
90
91 return dd;
92 }
93 /*--------------------------------------------------------------------------
94 NAME: CL_ENTRY *CLMake (xtclass, ut, xt)
95 INPUT: void* xtclass;
96 int ut, xt
97 RETURN: return pointer to CL entry
98 DESCRIPTION: given xt class and its uimxtype Xtype, Make a CL_Entry
99 CREATION: 17 Nov. 1989
100 REVISIONS: --
101 --------------------------------------------------------------------------*/
102
103 static CL_ENTRY *CLMake (xtclass, ut, xt)
104 void *xtclass;
105 int ut, xt;
106 {
107 CL_ENTRY* cle = (CL_ENTRY*) UxMalloc(sizeof(CL_ENTRY));
108
109 cle->utype= ut;
110 cle->xtype= xt;
111 cle->next_cl= (CL_ENTRY *)0;
112 cle->xtclass = xtclass;
113
114 return cle;
115 }
116
117
118 /*--------------------------------------------------------------------------
119 NAME: void UxDDInstall (name, utype, xtype)
120 INPUT: char* name, int utype, xtype
121 RETURN:
122 DESCRIPTION: Given resource name and utype, xtype, link it to the hash table
123 CREATION: 17, Nov, 1989
124 REVISIONS: --
125 --------------------------------------------------------------------------*/
126
127 void UxDDInstall (name, utype, xtype)
128 char *name;
129 int utype;
130 int xtype;
131 {
132 DD *np;
133 int hv;
134
135 if (name)
136 {
137 if ((np = DDTableLookup (name))) {
138 printf (CGETS (MS_LU_ALDRYREGISTERED,
139 DS_MS_LU_ALDRYREGISTERED), name);
140 return;
141 }
142 else {
143 np = DDMake (name, utype, xtype);
144 hv = hash (name);
145 np->next = DDTable[hv];
146 DDTable[hv] = np;
147 }
148 }
149 }
150
151 /*--------------------------------------------------------------------------
152 NAME: void UxDDAddEntry (name, xtclass, utype, xtype)
153 INPUT: char* name,*xtclass; int utype, xtype
154 RETURN:
155 DESCRIPTION: Given resource name and utype, xtype, link it to the hash table
156 CREATION: 17, Nov, 1989
157 REVISIONS: --
158 --------------------------------------------------------------------------*/
159
160 void UxDDAddEntry (name, xtclass, utype, xtype)
161 char *name;
162 void *xtclass;
163 int utype;
164 int xtype;
165 {
166 DD *np;
167 int hv;
168 CL_ENTRY *cl;
169
170 if (name)
171 {
172 if ((np = DDTableLookup (name))){
173 cl = CLMake (xtclass, utype, xtype);
174 cl->next_cl= np->next_cl;
175 np->next_cl=cl;
176 return;
177 } else {
178 np = DDMake (name, utype, xtype);
179 hv = hash (name);
180 np->next = DDTable[hv];
181 DDTable[hv] = np;
182 }
183 }
184 }
185
186
187 /*--------------------------------------------------------------------------
188 NAME: static DD* DDTableLookup (name)
189 INPUT: char* name
190 RETURN: pointer to DD Entry
191 DESCRIPTION: given an resource name return its DD entry by checking hash
192 index
193 CREATION: 17 Nov. 1989
194 REVISIONS: --
195 --------------------------------------------------------------------------*/
196 static DD *DDTableLookup (name)
197 char *name;
198 {
199 DD *np;
200
201 for (np = DDTable[hash (name)];np != (DD *)0;np = np->next)
202 if (UxStrEqual(name, np->name))
203 return np;
204 return (DD *)0;
205 }
206
207 /*--------------------------------------------------------------------------
208 NAME: static int hash (name)
209 INPUT: char* name
210 RETURN: hash table index (0-HASHSIZE)
211 DESCRIPTION: given resource name to hash function get corresponding hash
212 index
213 CREATION: 17 Nov 1989
214 REVISIONS: --
215 --------------------------------------------------------------------------*/
216 static int hash (name)
217 char *name;
218 {
219 int hv;
220
221 for (hv = 0; *name != '\0';)
222 hv += *name++;
223 return (hv % HASHSIZE);
224 }
225
226 /*--------------------------------------------------------------------------
227 NAME: DDList UxDDEntry (name)
228 INPUT: char* name
229 RETURN: DDList
230 DESCRIPTION: given an name return its DDList
231 CREATION: 25 May 1989
232 REVISIONS: 10 April 1990
233 -- Added class dependent dd entries.
234 --------------------------------------------------------------------------*/
235
236 CL_ENTRY *UxDDEntry (name, xtclass)
237 char *name;
238 void *xtclass;
239 {
240 CL_ENTRY *cl,*rcl=0;
241 DD *dd;
242
243 if ((dd= DDTableLookup (name))){
244 rcl = (CL_ENTRY *)dd;
245 if ((cl =dd->next_cl))
246 do{
247 if (cl->xtclass == xtclass){
248 rcl = cl;
249 break;
250 }
251 }while ((cl=cl->next_cl));
252 }
253 return rcl;
254 }
255 /*--------------------------------------------------------------------------
256 NAME: static int UimxToX (sw, utype, v, xtype, data, to)
257 INPUT: swidget sw;
258 int utype, xtype, to;
259 XtArgVal *v;
260 char *data;
261 RETURN: status: ERROR NO_ERROR
262 DESCRIPTION: calls uimx convertors with the appropriate data types.
263 CREATION: 25 May 1989
264 LAST REV: Jan 93 fix3820 UxCallConverter now used.
265 --------------------------------------------------------------------------*/
266 static int UimxToX (sw, utype, v, xtype, data, to)
267 swidget sw;
268 int utype, xtype, to;
269 XtArgVal *v;
270 char *data;
271 {
272 char vc;
273 short vs;
274 int stat= ERROR;
275
276 switch (u_size (utype)){
277 case sizeof (char):
278 if (to == TO_X)vc = (char)*v;
279 stat = UxCallConverter (sw , utype, (char **)&vc, xtype, data, to);
280 if (to == TO_UIMX)*v = (XtArgVal)vc;
281 break;
282 case sizeof (short):
283 if (to == TO_X)vs = (short)*v;
284 stat =UxCallConverter (sw, utype,(char **)&vs, xtype, data, to);
285 if (to == TO_UIMX)*v = (XtArgVal)vs;
286 break;
287 default:
288 stat = UxCallConverter (sw, utype, (char **)v, xtype, data, to);
289 }
290 return stat;
291 }
292
293 /*--------------------------------------------------------------------------
294 NAME: int UxDDPutProp (sw, p, v)
295 INPUT: swidget sw, char *p, XtArgVal v
296 RETURN:
297 DESCRIPTION: given swidget put its property pair (p, v) to proplist
298 CREATION: 25 May 1989
299 REVISIONS: 10 April 1990
300 -- modified to handle class dependent dd entries.
301 --------------------------------------------------------------------------*/
302 int UxDDPutProp (sw, p, v)
303 swidget sw;
304 char *p;
305 XtArgVal v;
306 {
307 CL_ENTRY *dd;
308 XtArgVal fi = v;
309 char fc = '\0';
310 int stat = ERROR;
311 short fs =0;
312
313 if (sw)
314 {
315 if ((dd = UxDDEntry (p, UxGetClass(sw))))
316 {
317 switch (x_size (dd->xtype)){
318 case sizeof (char):
319 stat= UimxToX (sw, dd->utype,&v, dd->xtype,&fc, TO_X);
320 fi = (XtArgVal)fc;
321 break;
322 case sizeof (short):
323 stat= UimxToX (sw, dd->utype,&v, dd->xtype,&fs, TO_X);
324 fi = (XtArgVal)fs;
325 break;
326 default:
327 stat= UimxToX (sw, dd->utype,&v, dd->xtype,&fi, TO_X);
328 }
329 if (stat == NO_ERROR)
330 stat= UxPutProp (sw, p, fi);
331 }
332 }
333 return stat;
334 }
335
336 /*----------------------------------------------------------------------
337 * NAME: <XtArgVal UxDDGetProp (sw, p)>
338 * DESCRIPTION: <given swidget return its property p value>
339 * PARAMETERS: swidget sw - swidget
340 * char *p - property
341 * RETURN: XtArgVal
342 * EXT REFS: globals_used
343 * EXT EFFECTS: globals or other things altered
344 * ASSUMPTIONS:
345 * REVISIONS: 25/05/92 creation
346 * Oct. 1989
347 checking widget is created or not.
348 10 April 1990
349 -- modified to handle class dependent dd entries.
350 18 Nov/91 fix3186
351 *--------------------------------------------------------------------*/
352 XtArgVal UxDDGetProp (sw, p)
353 swidget sw;
354 char *p;
355 {
356 CL_ENTRY *dd;
357 XtArgVal v= 0, fv;
358 char fc = '\0';
359 Arg arg[2];
360 short fs;
361 int err_status;
362 char *xtname = p;
363
364 /* Rename msgDialogType to dialogType so that the widget
365 understands! */
366 if (UxStrEqual(p, "msgDialogType")) {
367 xtname = "dialogType";
368 }
369
370 if (sw && (dd = UxDDEntry (p, UxGetClass(sw))))
371 {
372 Widget w = UxGetWidget (sw);
373 switch (x_size (dd->xtype)){
374 case sizeof (char):
375 if (w) {
376 XtSetArg (arg[0], xtname,&fc);
377 XtGetValues (w, arg,1);
378 }
379 else if (UxFindValue (sw, p, &v)){
380 fc = (char)v;
381 }
382 else {
383 break;
384 }
385 if (NO_ERROR == UimxToX (sw, dd->utype,&v,
386 dd->xtype,&fc, TO_UIMX))
387 return v;
388 break;
389 case sizeof (short):
390 if (w) {
391 XtSetArg (arg[0], xtname,&fs);
392 XtGetValues (w , arg,1);
393 }
394 else if (UxFindValue (sw, p, &v)) {
395 fs = (short)v;
396 }
397 else {
398 break;
399 }
400 if (NO_ERROR == UimxToX (sw, dd->utype,&v,
401 dd->xtype,&fs, TO_UIMX))
402 return v;
403 break;
404 default:
405 /* UxGet<Property> functions returning XmString go
406 through this default case. We need to free the
407 string after it was converted. To know that we
408 used XtGetValues, we check for the validity
409 of the widget 'w'. */
410
411 if (w) {
412 XtSetArg (arg[0], xtname,&fv);
413 XtGetValues (w, arg,1);
414 }
415 else if (UxFindValue (sw, p, &v)) {
416 fv = v;
417 }
418 else {
419 break;
420 }
421 err_status = UimxToX (sw, dd->utype,&v,
422 dd->xtype,&fv, TO_UIMX);
423 if (w)
424 UxFreeXValue(sw, p, fv);
425 if (err_status == NO_ERROR)
426 return v;
427 }
428 }
429 return UxGetProp (sw, p);
430 }
431