File: | Actions.c |
Location: | line 475, column 4 |
Description: | Assigned value is garbage or undefined |
1 | /* | |||||
2 | * Copyright (c) 1998 by The XFree86 Project, Inc. | |||||
3 | * | |||||
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |||||
5 | * copy of this software and associated documentation files (the "Software"), | |||||
6 | * to deal in the Software without restriction, including without limitation | |||||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||||
8 | * and/or sell copies of the Software, and to permit persons to whom the | |||||
9 | * Software is furnished to do so, subject to the following conditions: | |||||
10 | * | |||||
11 | * The above copyright notice and this permission notice shall be included in | |||||
12 | * all copies or substantial portions of the Software. | |||||
13 | * | |||||
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||||
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||||
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||||
17 | * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |||||
18 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF | |||||
19 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||||
20 | * SOFTWARE. | |||||
21 | * | |||||
22 | * Except as contained in this notice, the name of the XFree86 Project shall | |||||
23 | * not be used in advertising or otherwise to promote the sale, use or other | |||||
24 | * dealings in this Software without prior written authorization from the | |||||
25 | * XFree86 Project. | |||||
26 | */ | |||||
27 | ||||||
28 | #ifdef HAVE_CONFIG_H1 | |||||
29 | #include <config.h> | |||||
30 | #endif | |||||
31 | #include <ctype.h> | |||||
32 | #include <stdio.h> | |||||
33 | #include <stdlib.h> | |||||
34 | #include <string.h> | |||||
35 | #include <X11/Xmd.h> | |||||
36 | #include <X11/IntrinsicP.h> | |||||
37 | #include <X11/StringDefs.h> | |||||
38 | #include <X11/CoreP.h> | |||||
39 | #include <X11/Constraint.h> | |||||
40 | #include <X11/Xmu/CharSet.h> | |||||
41 | #include <X11/Xfuncs.h> | |||||
42 | #include "Private.h" | |||||
43 | ||||||
44 | ||||||
45 | #ifndef OLDXAW | |||||
46 | ||||||
47 | /* | |||||
48 | * Definitions | |||||
49 | */ | |||||
50 | #define ERROR-2 -2 | |||||
51 | #define END-1 -1 | |||||
52 | #define BOOLEAN0 0 | |||||
53 | #define AND'&' '&' | |||||
54 | #define OR'|' '|' | |||||
55 | #define XOR'^' '^' | |||||
56 | #define NOT'~' '~' | |||||
57 | #define LP'(' '(' | |||||
58 | #define RP')' ')' | |||||
59 | ||||||
60 | /* | |||||
61 | * Types | |||||
62 | */ | |||||
63 | /* boolean expressions */ | |||||
64 | typedef struct _XawEvalInfo { | |||||
65 | Widget widget; | |||||
66 | XawActionResList *rlist; | |||||
67 | XawActionVarList *vlist; | |||||
68 | XawParseBooleanProc parse_proc; | |||||
69 | XEvent *event; | |||||
70 | char *cp, *lp; | |||||
71 | int token; | |||||
72 | Boolint value; | |||||
73 | } XawEvalInfo; | |||||
74 | ||||||
75 | /* resources */ | |||||
76 | typedef struct _XawActionRes { | |||||
77 | XrmQuark qname; | |||||
78 | XrmQuark qtype; | |||||
79 | Cardinal size; | |||||
80 | } XawActionRes; | |||||
81 | ||||||
82 | struct _XawActionResList { | |||||
83 | WidgetClass widget_class; | |||||
84 | XawActionRes **resources; | |||||
85 | Cardinal num_common_resources; | |||||
86 | Cardinal num_constraint_resources; | |||||
87 | }; | |||||
88 | ||||||
89 | /* variables */ | |||||
90 | typedef struct _XawActionVar { | |||||
91 | XrmQuark qname; | |||||
92 | XrmQuark qvalue; | |||||
93 | } XawActionVar; | |||||
94 | ||||||
95 | struct _XawActionVarList { | |||||
96 | Widget widget; | |||||
97 | Cardinal num_variables; | |||||
98 | XawActionVar **variables; | |||||
99 | }; | |||||
100 | ||||||
101 | /* | |||||
102 | * Private methods | |||||
103 | */ | |||||
104 | /* expressions */ | |||||
105 | static int get_token(XawEvalInfo*); | |||||
106 | static Boolint expr(XawEvalInfo*); | |||||
107 | static Boolint and(XawEvalInfo*); | |||||
108 | static Boolint prim(XawEvalInfo*); | |||||
109 | ||||||
110 | /* resources */ | |||||
111 | static String XawConvertActionRes(XawActionResList*, Widget w, String); | |||||
112 | ||||||
113 | static String _XawEscapeActionVarValue(String); | |||||
114 | static String _XawUnescapeActionVarValue(String); | |||||
115 | static XawActionResList *_XawCreateActionResList(WidgetClass); | |||||
116 | static XawActionResList *_XawFindActionResList(WidgetClass); | |||||
117 | static void _XawBindActionResList(XawActionResList*); | |||||
118 | static XawActionRes *_XawFindActionRes(XawActionResList*, Widget, String); | |||||
119 | static int qcmp_action_resource_list(_Xconstconst void*, _Xconstconst void*); | |||||
120 | static int bcmp_action_resource_list(_Xconstconst void*, _Xconstconst void*); | |||||
121 | static int qcmp_action_resource(_Xconstconst void*, _Xconstconst void*); | |||||
122 | static int bcmp_action_resource(_Xconstconst void*, _Xconstconst void*); | |||||
123 | ||||||
124 | /* variables */ | |||||
125 | static String XawConvertActionVar(XawActionVarList*, String); | |||||
126 | static void XawDeclareActionVar(XawActionVarList*, String, String); | |||||
127 | ||||||
128 | static XawActionVarList *_XawCreateActionVarList(Widget); | |||||
129 | static XawActionVarList *_XawFindActionVarList(Widget); | |||||
130 | static XawActionVar *_XawCreateActionVar(XawActionVarList*, String); | |||||
131 | static XawActionVar *_XawFindActionVar(XawActionVarList*, String); | |||||
132 | static void _XawDestroyActionVarList(Widget, XtPointer, XtPointer); | |||||
133 | ||||||
134 | /* | |||||
135 | * Initialization | |||||
136 | */ | |||||
137 | /* resources */ | |||||
138 | static XawActionResList **resource_list; | |||||
139 | static Cardinal num_resource_list; | |||||
140 | ||||||
141 | /* variables */ | |||||
142 | static XawActionVarList **variable_list; | |||||
143 | static Cardinal num_variable_list; | |||||
144 | ||||||
145 | /* | |||||
146 | * Implementation | |||||
147 | */ | |||||
148 | /* | |||||
149 | * Start of Boolean Expression Evaluation Implementation Code | |||||
150 | */ | |||||
151 | Boolint | |||||
152 | XawParseBoolean(Widget w, String param, XEvent *event, Boolint *succed) | |||||
153 | { | |||||
154 | char *tmp = param; | |||||
155 | int value; | |||||
156 | ||||||
157 | if (!param) | |||||
158 | return (False0); | |||||
159 | ||||||
160 | value = (int)strtod(param, &tmp); | |||||
161 | if (*tmp == '\0') | |||||
162 | return (value); | |||||
163 | ||||||
164 | if (XmuCompareISOLatin1(param, "true") == 0 | |||||
165 | || XmuCompareISOLatin1(param, "yes") == 0 | |||||
166 | || XmuCompareISOLatin1(param, "on") == 0 | |||||
167 | || XmuCompareISOLatin1(param, "in") == 0 | |||||
168 | || XmuCompareISOLatin1(param, "up") == 0) | |||||
169 | return (True1); | |||||
170 | else if (XmuCompareISOLatin1(param, "false") == 0 | |||||
171 | || XmuCompareISOLatin1(param, "no") == 0 | |||||
172 | || XmuCompareISOLatin1(param, "off") == 0 | |||||
173 | || XmuCompareISOLatin1(param, "out") == 0 | |||||
174 | || XmuCompareISOLatin1(param, "down") == 0) | |||||
175 | ; | |||||
176 | else if (XmuCompareISOLatin1(param, "my") == 0 | |||||
177 | || XmuCompareISOLatin1(param, "mine") == 0) | |||||
178 | return (event->xany.window == XtWindow(w)((w)->core.window)); | |||||
179 | else if (XmuCompareISOLatin1(param, "faked") == 0) | |||||
180 | return (event->xany.send_event != 0); | |||||
181 | else | |||||
182 | *succed = False0; | |||||
183 | ||||||
184 | return (False0); | |||||
185 | } | |||||
186 | ||||||
187 | Boolint | |||||
188 | XawBooleanExpression(Widget w, String param, XEvent *event) | |||||
189 | { | |||||
190 | XawEvalInfo info; | |||||
191 | Boolint retval; | |||||
192 | ||||||
193 | if (!param) | |||||
194 | return (False0); | |||||
195 | ||||||
196 | info.widget = w; | |||||
197 | ||||||
198 | info.rlist = XawGetActionResList(XtClass(w)((w)->core.widget_class)); | |||||
199 | info.vlist = XawGetActionVarList(w); | |||||
200 | ||||||
201 | /* | |||||
202 | * Verify widget class, in case we will allow the parse proc procedure | |||||
203 | * as a widget class element, or if we allow overriding the default | |||||
204 | * parse boolean proc. | |||||
205 | */ | |||||
206 | info.parse_proc = XawParseBoolean; | |||||
207 | ||||||
208 | info.event = event; | |||||
209 | info.cp = info.lp = param; | |||||
210 | ||||||
211 | #ifdef DIAGNOSTIC | |||||
212 | fprintf(stderr__stderrp, "(*) Parsing expression \"%s\"\n", param); | |||||
213 | #endif | |||||
214 | ||||||
215 | (void)get_token(&info); | |||||
216 | if (info.token == ERROR-2) | |||||
217 | return (False0); | |||||
218 | retval = expr(&info); | |||||
219 | ||||||
220 | return (info.token != ERROR-2 ? retval : False0); | |||||
221 | } | |||||
222 | ||||||
223 | static int | |||||
224 | get_token(XawEvalInfo *info) | |||||
225 | { | |||||
226 | int ch; | |||||
227 | char *p, name[256]; | |||||
228 | ||||||
229 | info->lp = info->cp; | |||||
230 | ||||||
231 | /*COSTCOND*/ | |||||
232 | while (1) /* eat white spaces */ | |||||
233 | { | |||||
234 | ch = *info->cp++; | |||||
235 | if (isspace(ch)) | |||||
236 | continue; | |||||
237 | break; | |||||
238 | } | |||||
239 | ||||||
240 | switch (ch) | |||||
241 | { | |||||
242 | case AND'&': case OR'|': case XOR'^': case NOT'~': case LP'(': case RP')': | |||||
243 | return (info->token = ch); | |||||
244 | } | |||||
245 | ||||||
246 | /* It's a symbol name, resolve it. */ | |||||
247 | if (ch == XAW_PRIV_VAR_PREFIX'$' || isalnum(ch) || ch == '_' || ch == '\\') | |||||
248 | { | |||||
249 | Boolint succed = True1; | |||||
250 | ||||||
251 | p = info->cp - 1; | |||||
252 | ||||||
253 | while ((ch = *info->cp) && (isalnum(ch) || ch == '_')) | |||||
254 | ++info->cp; | |||||
255 | ||||||
256 | strncpy(name, p, XawMin((int)sizeof(name) - 1,__builtin___strncpy_chk (name, p, (((int)sizeof(name) - 1) < ((unsigned)(info->cp - p)) ? ((int)sizeof(name) - 1) : (( unsigned)(info->cp - p))), __builtin_object_size (name, 2 > 1 ? 1 : 0)) | |||||
257 | (unsigned)(info->cp - p)))__builtin___strncpy_chk (name, p, (((int)sizeof(name) - 1) < ((unsigned)(info->cp - p)) ? ((int)sizeof(name) - 1) : (( unsigned)(info->cp - p))), __builtin_object_size (name, 2 > 1 ? 1 : 0)); | |||||
258 | name[XawMin((int)sizeof(name) -1, info->cp - p)(((int)sizeof(name) -1) < (info->cp - p) ? ((int)sizeof (name) -1) : (info->cp - p))] = '\0'; | |||||
259 | ||||||
260 | if (name[0] == XAW_PRIV_VAR_PREFIX'$') | |||||
261 | { | |||||
262 | String value = XawConvertActionVar(info->vlist, name); | |||||
263 | ||||||
264 | info->value = info->parse_proc(info->widget, value, info->event, | |||||
265 | &succed) & 1; | |||||
266 | } | |||||
267 | else | |||||
268 | { | |||||
269 | info->value = info->parse_proc(info->widget, name, info->event, | |||||
270 | &succed) & 1; | |||||
271 | if (!succed) | |||||
272 | { | |||||
273 | String value = | |||||
274 | XawConvertActionRes(info->rlist, info->widget, | |||||
275 | name[0] == '\\' ? &name[1] : name); | |||||
276 | /* '\\' may have been used to escape a resource name. | |||||
277 | */ | |||||
278 | ||||||
279 | succed = True1; | |||||
280 | info->value = info->parse_proc(info->widget, value, info->event, | |||||
281 | &succed) & 1; | |||||
282 | if (!succed) | |||||
283 | { | |||||
284 | /* not a numeric value or boolean string */ | |||||
285 | info->value = True1; | |||||
286 | succed = True1; | |||||
287 | } | |||||
288 | } | |||||
289 | } | |||||
290 | if (succed) | |||||
291 | return (info->token = BOOLEAN0); | |||||
292 | } | |||||
293 | else if (ch == '\0') | |||||
294 | return (info->token = END-1); | |||||
295 | ||||||
296 | { | |||||
297 | char msg[256]; | |||||
298 | ||||||
299 | snprintf(msg, sizeof(msg), "evaluate(): bad token \"%c\" at \"%s\"",__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "evaluate(): bad token \"%c\" at \"%s\"" , ch, info->cp - 1) | |||||
300 | ch, info->cp - 1)__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "evaluate(): bad token \"%c\" at \"%s\"" , ch, info->cp - 1); | |||||
301 | ||||||
302 | XtAppWarning(XtWidgetToApplicationContext(info->widget), msg); | |||||
303 | } | |||||
304 | ||||||
305 | return (info->token = ERROR-2); | |||||
306 | } | |||||
307 | ||||||
308 | static Boolint | |||||
309 | expr(XawEvalInfo *info) | |||||
310 | { | |||||
311 | Boolint left = and(info); | |||||
312 | ||||||
313 | for (;;) | |||||
314 | switch (info->token) | |||||
315 | { | |||||
316 | case OR'|': | |||||
317 | (void)get_token(info); | |||||
318 | left |= and(info); | |||||
319 | break; | |||||
320 | case XOR'^': | |||||
321 | (void)get_token(info); | |||||
322 | left ^= and(info); | |||||
323 | break; | |||||
324 | default: | |||||
325 | return (left); | |||||
326 | } | |||||
327 | /* NOTREACHED */ | |||||
328 | } | |||||
329 | ||||||
330 | static Boolint | |||||
331 | and(XawEvalInfo *info) | |||||
332 | { | |||||
333 | Boolint left = prim(info); | |||||
334 | ||||||
335 | for (;;) | |||||
336 | switch (info->token) | |||||
337 | { | |||||
338 | case AND'&': | |||||
339 | (void)get_token(info); | |||||
340 | left &= prim(info); | |||||
341 | break; | |||||
342 | default: | |||||
343 | return (left); | |||||
344 | } | |||||
345 | /* NOTREACHED */ | |||||
346 | } | |||||
347 | ||||||
348 | static Boolint | |||||
349 | prim(XawEvalInfo *info) | |||||
350 | { | |||||
351 | Boolint e; | |||||
352 | ||||||
353 | switch (info->token) | |||||
354 | { | |||||
355 | case BOOLEAN0: | |||||
356 | e = info->value; | |||||
357 | (void)get_token(info); | |||||
358 | return (e); | |||||
359 | case NOT'~': | |||||
360 | (void)get_token(info); | |||||
361 | return (!prim(info)); | |||||
362 | case LP'(': | |||||
363 | (void)get_token(info); | |||||
364 | e = expr(info); | |||||
365 | if (info->token != RP')') | |||||
366 | { | |||||
367 | char msg[256]; | |||||
368 | ||||||
369 | info->token = ERROR-2; | |||||
370 | snprintf(msg, sizeof(msg), "evaluate(): expecting ), at \"%s\"",__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "evaluate(): expecting ), at \"%s\"" , info->lp) | |||||
371 | info->lp)__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "evaluate(): expecting ), at \"%s\"" , info->lp); | |||||
372 | XtAppWarning(XtWidgetToApplicationContext(info->widget), msg); | |||||
373 | return (False0); | |||||
374 | } | |||||
375 | (void)get_token(info); | |||||
376 | return (e); | |||||
377 | case END-1: | |||||
378 | return (True1); | |||||
379 | default: | |||||
380 | { | |||||
381 | char msg[256]; | |||||
382 | ||||||
383 | info->token = ERROR-2; | |||||
384 | snprintf(msg, sizeof(msg), "evaluate(): syntax error, at \"%s\"",__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "evaluate(): syntax error, at \"%s\"" , info->lp) | |||||
385 | info->lp)__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "evaluate(): syntax error, at \"%s\"" , info->lp); | |||||
386 | XtAppWarning(XtWidgetToApplicationContext(info->widget), msg); | |||||
387 | } return (False0); | |||||
388 | } | |||||
389 | /* NOTREACHED */ | |||||
390 | } | |||||
391 | ||||||
392 | /* | |||||
393 | * Start of Resources Implementation Code | |||||
394 | */ | |||||
395 | void | |||||
396 | XawSetValuesAction(Widget w, XEvent *event, | |||||
397 | String *params, Cardinal *num_params) | |||||
398 | { | |||||
399 | Arg *arglist; | |||||
400 | Cardinal num_args, count; | |||||
401 | XawActionResList *rlist; | |||||
402 | XawActionVarList *vlist; | |||||
403 | XawActionRes *resource; | |||||
404 | XrmValue from, to; | |||||
405 | String value; | |||||
406 | char c_1; | |||||
| ||||||
407 | short c_2; | |||||
408 | int c_4; | |||||
409 | #ifdef LONG64 | |||||
410 | long c_8; | |||||
411 | #endif | |||||
412 | ||||||
413 | if (!(*num_params & 1)) | |||||
414 | { | |||||
415 | XawPrintActionErrorMsg("set-values", w, params, num_params); | |||||
416 | return; | |||||
417 | } | |||||
418 | ||||||
419 | if (!XawBooleanExpression(w, params[0], event)) | |||||
420 | return; | |||||
421 | ||||||
422 | rlist = XawGetActionResList(XtClass(w)((w)->core.widget_class)); | |||||
423 | vlist = XawGetActionVarList(w); | |||||
424 | ||||||
425 | num_args = 0; | |||||
426 | arglist = (Arg *)XtMalloc(sizeof(Arg) * ((*num_params) >> 1)); | |||||
427 | ||||||
428 | for (count = 1; count < *num_params; count += 2) | |||||
429 | { | |||||
430 | if ((resource = _XawFindActionRes(rlist, w, params[count])) == NULL((void*)0)) | |||||
431 | { | |||||
432 | char msg[256]; | |||||
433 | ||||||
434 | snprintf(msg, sizeof(msg), "set-values(): bad resource name \"%s\"",__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "set-values(): bad resource name \"%s\"" , params[count]) | |||||
435 | params[count])__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "set-values(): bad resource name \"%s\"" , params[count]); | |||||
436 | XtAppWarning(XtWidgetToApplicationContext(w), msg); | |||||
437 | continue; | |||||
438 | } | |||||
439 | value = XawConvertActionVar(vlist, params[count + 1]); | |||||
440 | from.size = strlen(value) + 1; | |||||
441 | from.addr = value; | |||||
442 | to.size = resource->size; | |||||
443 | switch (to.size) | |||||
444 | { | |||||
445 | case 1: to.addr = (XPointer)&c_1; break; | |||||
446 | case 2: to.addr = (XPointer)&c_2; break; | |||||
447 | case 4: to.addr = (XPointer)&c_4; break; | |||||
448 | #ifdef LONG64 | |||||
449 | case 8: to.addr = (XPointer)&c_8; break; | |||||
450 | #endif | |||||
451 | default: | |||||
452 | { | |||||
453 | char msg[256]; | |||||
454 | ||||||
455 | snprintf(msg, sizeof(msg),__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "set-values(): bad resource size for \"%s\"" , params[count]) | |||||
456 | "set-values(): bad resource size for \"%s\"",__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "set-values(): bad resource size for \"%s\"" , params[count]) | |||||
457 | params[count])__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "set-values(): bad resource size for \"%s\"" , params[count]); | |||||
458 | XtAppWarning(XtWidgetToApplicationContext(w), msg); | |||||
459 | } continue; | |||||
460 | } | |||||
461 | ||||||
462 | if (strcmp(XtRString((char*)&XtStrings[1797]), XrmQuarkToString(resource->qtype)) == 0) | |||||
463 | #ifdef LONG64 | |||||
464 | c_8 = (long)from.addr; | |||||
465 | #else | |||||
466 | c_4 = (int)from.addr; | |||||
467 | #endif | |||||
468 | else if (!XtConvertAndStore(w, XtRString((char*)&XtStrings[1797]), &from, | |||||
469 | XrmQuarkToString(resource->qtype), &to)) | |||||
470 | continue; | |||||
471 | ||||||
472 | switch (to.size) | |||||
473 | { | |||||
474 | case 1: | |||||
475 | XtSetArg(arglist[num_args], XrmQuarkToString(resource->qname), c_1)((void)( (arglist[num_args]).name = (XrmQuarkToString(resource ->qname)), (arglist[num_args]).value = (XtArgVal)(c_1) )); | |||||
| ||||||
476 | break; | |||||
477 | case 2: | |||||
478 | XtSetArg(arglist[num_args], XrmQuarkToString(resource->qname), c_2)((void)( (arglist[num_args]).name = (XrmQuarkToString(resource ->qname)), (arglist[num_args]).value = (XtArgVal)(c_2) )); | |||||
479 | break; | |||||
480 | case 4: | |||||
481 | XtSetArg(arglist[num_args], XrmQuarkToString(resource->qname), c_4)((void)( (arglist[num_args]).name = (XrmQuarkToString(resource ->qname)), (arglist[num_args]).value = (XtArgVal)(c_4) )); | |||||
482 | break; | |||||
483 | #ifdef LONG64 | |||||
484 | case 8: | |||||
485 | XtSetArg(arglist[num_args], XrmQuarkToString(resource->qname), c_8)((void)( (arglist[num_args]).name = (XrmQuarkToString(resource ->qname)), (arglist[num_args]).value = (XtArgVal)(c_8) )); | |||||
486 | break; | |||||
487 | #endif | |||||
488 | } | |||||
489 | ++num_args; | |||||
490 | } | |||||
491 | ||||||
492 | XtSetValues(w, arglist, num_args); | |||||
493 | XtFree((char *)arglist); | |||||
494 | } | |||||
495 | ||||||
496 | void | |||||
497 | XawGetValuesAction(Widget w, XEvent *event, | |||||
498 | String *params, Cardinal *num_params) | |||||
499 | { | |||||
500 | XawActionResList *rlist; | |||||
501 | XawActionVarList *vlist; | |||||
502 | String value; | |||||
503 | Cardinal count; | |||||
504 | ||||||
505 | if (!(*num_params & 1)) | |||||
506 | { | |||||
507 | XawPrintActionErrorMsg("get-values", w, params, num_params); | |||||
508 | return; | |||||
509 | } | |||||
510 | if (!XawBooleanExpression(w, params[0], event)) | |||||
511 | return; | |||||
512 | ||||||
513 | rlist = XawGetActionResList(XtClass(w)((w)->core.widget_class)); | |||||
514 | vlist = XawGetActionVarList(w); | |||||
515 | ||||||
516 | for (count = 1; count < *num_params; count += 2) | |||||
517 | { | |||||
518 | if ((value = XawConvertActionRes(rlist, w, params[count + 1])) == NULL((void*)0)) | |||||
519 | continue; | |||||
520 | XawDeclareActionVar(vlist, params[count], value); | |||||
521 | } | |||||
522 | } | |||||
523 | ||||||
524 | void | |||||
525 | XawDeclareAction(Widget w, XEvent *event, | |||||
526 | String *params, Cardinal *num_params) | |||||
527 | { | |||||
528 | XawActionVarList *vlist; | |||||
529 | Cardinal count; | |||||
530 | ||||||
531 | if (!(*num_params & 1)) | |||||
532 | { | |||||
533 | XawPrintActionErrorMsg("declare", w, params, num_params); | |||||
534 | return; | |||||
535 | } | |||||
536 | if (!XawBooleanExpression(w, params[0], event)) | |||||
537 | return; | |||||
538 | ||||||
539 | vlist = XawGetActionVarList(w); | |||||
540 | ||||||
541 | for (count = 1; count < *num_params; count += 2) | |||||
542 | XawDeclareActionVar(vlist, params[count], params[count + 1]); | |||||
543 | } | |||||
544 | ||||||
545 | void | |||||
546 | XawCallProcAction(Widget w, XEvent *event, | |||||
547 | String *params, Cardinal *num_params) | |||||
548 | { | |||||
549 | String *args; | |||||
550 | Cardinal num_args; | |||||
551 | ||||||
552 | if (*num_params < 2) | |||||
553 | { | |||||
554 | XawPrintActionErrorMsg("call-proc", w, params, num_params); | |||||
555 | return; | |||||
556 | } | |||||
557 | ||||||
558 | if (*num_params && !XawBooleanExpression(w, params[0], event)) | |||||
559 | return; | |||||
560 | ||||||
561 | if (*num_params > 2) | |||||
562 | { | |||||
563 | args = ¶ms[2]; | |||||
564 | num_args = *num_params - 2; | |||||
565 | } | |||||
566 | else | |||||
567 | { | |||||
568 | args = NULL((void*)0); | |||||
569 | num_args = 0; | |||||
570 | } | |||||
571 | ||||||
572 | XtCallActionProc(w, params[1], event, args, num_args); | |||||
573 | } | |||||
574 | ||||||
575 | static String | |||||
576 | XawConvertActionRes(XawActionResList *list, Widget w, String name) | |||||
577 | { | |||||
578 | XawActionRes *resource; | |||||
579 | XrmValue from, to; | |||||
580 | Arg arg; | |||||
581 | char c_1; | |||||
582 | short c_2; | |||||
583 | int c_4; | |||||
584 | #ifdef LONG64 | |||||
585 | long c_8; | |||||
586 | #endif | |||||
587 | ||||||
588 | if ((resource = _XawFindActionRes(list, w, name)) == NULL((void*)0)) | |||||
589 | { | |||||
590 | char msg[256]; | |||||
591 | ||||||
592 | snprintf(msg, sizeof(msg), "convert(): bad resource name \"%s\"",__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "convert(): bad resource name \"%s\"" , name) | |||||
593 | name)__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "convert(): bad resource name \"%s\"" , name); | |||||
594 | XtAppWarning(XtWidgetToApplicationContext(w), msg); | |||||
595 | return (NULL((void*)0)); | |||||
596 | } | |||||
597 | ||||||
598 | from.size = resource->size; | |||||
599 | switch (from.size) | |||||
600 | { | |||||
601 | case 1: | |||||
602 | XtSetArg(arg, XrmQuarkToString(resource->qname),((void)( (arg).name = (XrmQuarkToString(resource->qname)), (arg).value = (XtArgVal)(from.addr = (XPointer)&c_1) )) | |||||
603 | from.addr = (XPointer)&c_1)((void)( (arg).name = (XrmQuarkToString(resource->qname)), (arg).value = (XtArgVal)(from.addr = (XPointer)&c_1) )); | |||||
604 | break; | |||||
605 | case 2: | |||||
606 | XtSetArg(arg, XrmQuarkToString(resource->qname),((void)( (arg).name = (XrmQuarkToString(resource->qname)), (arg).value = (XtArgVal)(from.addr = (XPointer)&c_2) )) | |||||
607 | from.addr = (XPointer)&c_2)((void)( (arg).name = (XrmQuarkToString(resource->qname)), (arg).value = (XtArgVal)(from.addr = (XPointer)&c_2) )); | |||||
608 | break; | |||||
609 | case 4: | |||||
610 | XtSetArg(arg, XrmQuarkToString(resource->qname),((void)( (arg).name = (XrmQuarkToString(resource->qname)), (arg).value = (XtArgVal)(from.addr = (XPointer)&c_4) )) | |||||
611 | from.addr = (XPointer)&c_4)((void)( (arg).name = (XrmQuarkToString(resource->qname)), (arg).value = (XtArgVal)(from.addr = (XPointer)&c_4) )); | |||||
612 | break; | |||||
613 | #ifdef LONG64 | |||||
614 | case 8: | |||||
615 | XtSetArg(arg, XrmQuarkToString(resource->qname),((void)( (arg).name = (XrmQuarkToString(resource->qname)), (arg).value = (XtArgVal)(from.addr = (XPointer)&c_8) )) | |||||
616 | from.addr = (XPointer)&c_8)((void)( (arg).name = (XrmQuarkToString(resource->qname)), (arg).value = (XtArgVal)(from.addr = (XPointer)&c_8) )); | |||||
617 | break; | |||||
618 | #endif | |||||
619 | default: | |||||
620 | { | |||||
621 | char msg[256]; | |||||
622 | ||||||
623 | snprintf(msg, sizeof(msg), "convert(): bad resource size for \"%s\"",__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "convert(): bad resource size for \"%s\"" , name) | |||||
624 | name)__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "convert(): bad resource size for \"%s\"" , name); | |||||
625 | XtAppWarning(XtWidgetToApplicationContext(w), name); | |||||
626 | } return (NULL((void*)0)); | |||||
627 | } | |||||
628 | ||||||
629 | XtGetValues(w, &arg, 1); | |||||
630 | to.size = sizeof(String); | |||||
631 | to.addr = NULL((void*)0); | |||||
632 | ||||||
633 | if (strcmp(XtRString((char*)&XtStrings[1797]), XrmQuarkToString(resource->qtype)) == 0) | |||||
634 | to.addr = *(char **)from.addr; | |||||
635 | else if (!XtConvertAndStore(w, XrmQuarkToString(resource->qtype), | |||||
636 | &from, XtRString((char*)&XtStrings[1797]), &to)) | |||||
637 | return (NULL((void*)0)); | |||||
638 | ||||||
639 | return ((String)to.addr); | |||||
640 | } | |||||
641 | ||||||
642 | void | |||||
643 | XawPrintActionErrorMsg(String action_name, Widget w, | |||||
644 | String *params, Cardinal *num_params) | |||||
645 | { | |||||
646 | char msg[1024]; | |||||
647 | unsigned int size, idx; | |||||
648 | ||||||
649 | size = snprintf(msg, sizeof(msg), "%s(): bad number of parameters.\n\t(",__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "%s(): bad number of parameters.\n\t(" , action_name) | |||||
650 | action_name)__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "%s(): bad number of parameters.\n\t(" , action_name); | |||||
651 | ||||||
652 | idx = 0; | |||||
653 | while (idx < *num_params - 1 && size < sizeof(msg)) | |||||
654 | size += snprintf(&msg[size], sizeof(msg) - size, "%s, ",__builtin___snprintf_chk (&msg[size], sizeof(msg) - size, 0, __builtin_object_size (&msg[size], 2 > 1 ? 1 : 0), "%s, ", params[idx++]) | |||||
655 | params[idx++])__builtin___snprintf_chk (&msg[size], sizeof(msg) - size, 0, __builtin_object_size (&msg[size], 2 > 1 ? 1 : 0), "%s, ", params[idx++]); | |||||
656 | if (*num_params) | |||||
657 | snprintf(&msg[size], sizeof(msg) - size, "%s)", params[idx])__builtin___snprintf_chk (&msg[size], sizeof(msg) - size, 0, __builtin_object_size (&msg[size], 2 > 1 ? 1 : 0), "%s)", params[idx]); | |||||
658 | else | |||||
659 | snprintf(&msg[size], sizeof(msg) - size, ")")__builtin___snprintf_chk (&msg[size], sizeof(msg) - size, 0, __builtin_object_size (&msg[size], 2 > 1 ? 1 : 0), ")"); | |||||
660 | XtAppWarning(XtWidgetToApplicationContext(w), msg); | |||||
661 | } | |||||
662 | ||||||
663 | XawActionResList * | |||||
664 | XawGetActionResList(WidgetClass wc) | |||||
665 | { | |||||
666 | XawActionResList *list; | |||||
667 | ||||||
668 | list = _XawFindActionResList(wc); | |||||
669 | ||||||
670 | if (!list) | |||||
671 | list = _XawCreateActionResList(wc); | |||||
672 | ||||||
673 | return (list); | |||||
674 | } | |||||
675 | ||||||
676 | static int | |||||
677 | qcmp_action_resource_list(register _Xconstconst void *left, | |||||
678 | register _Xconstconst void *right) | |||||
679 | { | |||||
680 | return ((char *)((*(XawActionResList **)left)->widget_class) - | |||||
681 | (char *)((*(XawActionResList **)right)->widget_class)); | |||||
682 | } | |||||
683 | ||||||
684 | static XawActionResList * | |||||
685 | _XawCreateActionResList(WidgetClass wc) | |||||
686 | { | |||||
687 | XawActionResList *list; | |||||
688 | ||||||
689 | list = (XawActionResList *)XtMalloc(sizeof(XawActionResList)); | |||||
690 | list->widget_class = wc; | |||||
691 | list->num_common_resources = list->num_constraint_resources = 0; | |||||
692 | list->resources = NULL((void*)0); | |||||
693 | ||||||
694 | if (!resource_list) | |||||
695 | { | |||||
696 | num_resource_list = 1; | |||||
697 | resource_list = (XawActionResList **)XtMalloc(sizeof(XawActionResList*)); | |||||
698 | resource_list[0] = list; | |||||
699 | } | |||||
700 | else | |||||
701 | { | |||||
702 | ++num_resource_list; | |||||
703 | resource_list = (XawActionResList **)XtRealloc((char *)resource_list, | |||||
704 | sizeof(XawActionResList*) | |||||
705 | * num_resource_list); | |||||
706 | resource_list[num_resource_list - 1] = list; | |||||
707 | qsort(resource_list, num_resource_list, sizeof(XawActionResList*), | |||||
708 | qcmp_action_resource_list); | |||||
709 | } | |||||
710 | ||||||
711 | _XawBindActionResList(list); | |||||
712 | ||||||
713 | return (list); | |||||
714 | } | |||||
715 | ||||||
716 | static int | |||||
717 | bcmp_action_resource_list(register _Xconstconst void *wc, | |||||
718 | register _Xconstconst void *list) | |||||
719 | { | |||||
720 | return ((char *)wc - (char *)((*(XawActionResList **)list)->widget_class)); | |||||
721 | } | |||||
722 | ||||||
723 | static XawActionResList * | |||||
724 | _XawFindActionResList(WidgetClass wc) | |||||
725 | { | |||||
726 | XawActionResList **list; | |||||
727 | ||||||
728 | if (!resource_list) | |||||
729 | return (NULL((void*)0)); | |||||
730 | ||||||
731 | list = (XawActionResList **)bsearch(wc, resource_list, | |||||
732 | num_resource_list, | |||||
733 | sizeof(XawActionResList*), | |||||
734 | bcmp_action_resource_list); | |||||
735 | ||||||
736 | return (list ? *list : NULL((void*)0)); | |||||
737 | } | |||||
738 | ||||||
739 | static int | |||||
740 | qcmp_action_resource(register _Xconstconst void *left, | |||||
741 | register _Xconstconst void *right) | |||||
742 | { | |||||
743 | return (strcmp(XrmQuarkToString((*(XawActionRes **)left)->qname), | |||||
744 | XrmQuarkToString((*(XawActionRes **)right)->qname))); | |||||
745 | } | |||||
746 | ||||||
747 | static void | |||||
748 | _XawBindActionResList(XawActionResList *list) | |||||
749 | { | |||||
750 | XtResourceList xt_list, cons_list; | |||||
751 | Cardinal i, num_xt, num_cons; | |||||
752 | ||||||
753 | #ifdef DIAGNOSTIC | |||||
754 | fprintf(stderr__stderrp, "(*) Creating resource list for class \'%s\'\n---------\n", | |||||
755 | list->widget_class->core_class.class_name); | |||||
756 | #endif | |||||
757 | ||||||
758 | XtGetResourceList(list->widget_class, &xt_list, &num_xt); | |||||
759 | XtGetConstraintResourceList(list->widget_class, &cons_list, &num_cons); | |||||
760 | list->num_common_resources = num_xt; | |||||
761 | list->num_constraint_resources = num_cons; | |||||
762 | ||||||
763 | list->resources = (XawActionRes **) | |||||
764 | XtMalloc(sizeof(XawActionRes*) * (num_xt + num_cons)); | |||||
765 | ||||||
766 | #ifdef DIAGNOSTIC | |||||
767 | fprintf(stderr__stderrp, "Common resources\n---\n"); | |||||
768 | #endif | |||||
769 | ||||||
770 | for (i = 0; i < num_xt; i++) | |||||
771 | { | |||||
772 | list->resources[i] = (XawActionRes *)XtMalloc(sizeof(XawActionRes)); | |||||
773 | list->resources[i]->qname = | |||||
774 | XrmPermStringToQuark(xt_list[i].resource_name); | |||||
775 | list->resources[i]->qtype = | |||||
776 | XrmPermStringToQuark(xt_list[i].resource_type); | |||||
777 | list->resources[i]->size = xt_list[i].resource_size; | |||||
778 | ||||||
779 | #ifdef DIAGNOSTIC | |||||
780 | fprintf(stderr__stderrp, "%-20s\t%-20s\t(%d)\n", | |||||
781 | xt_list[i].resource_name, | |||||
782 | xt_list[i].resource_type, | |||||
783 | xt_list[i].resource_size); | |||||
784 | #endif | |||||
785 | } | |||||
786 | ||||||
787 | #ifdef DIAGNOSTIC | |||||
788 | fprintf(stderr__stderrp, "---\nContraint resources\n---"); | |||||
789 | #endif | |||||
790 | ||||||
791 | for (; i < num_xt + num_cons; i++) | |||||
792 | { | |||||
793 | list->resources[i] = (XawActionRes *)XtMalloc(sizeof(XawActionRes)); | |||||
794 | list->resources[i]->qname = | |||||
795 | XrmPermStringToQuark(cons_list[i - num_xt].resource_name); | |||||
796 | list->resources[i]->qtype = | |||||
797 | XrmPermStringToQuark(cons_list[i - num_xt].resource_type); | |||||
798 | list->resources[i]->size = cons_list[i - num_xt].resource_size; | |||||
799 | ||||||
800 | #ifdef DIAGNOSTIC | |||||
801 | fprintf(stderr__stderrp, "%-20s\t%-20s\t(%d)\n", | |||||
802 | cons_list[i - num_xt].resource_name, | |||||
803 | cons_list[i - num_xt].resource_type, | |||||
804 | cons_list[i - num_xt].resource_size); | |||||
805 | #endif | |||||
806 | } | |||||
807 | ||||||
808 | #ifdef DIAGNOSTIC | |||||
809 | fprintf(stderr__stderrp, "---\n"); | |||||
810 | #endif | |||||
811 | ||||||
812 | XtFree((char *)xt_list); | |||||
813 | if (cons_list) | |||||
814 | XtFree((char *)cons_list); | |||||
815 | ||||||
816 | qsort(list->resources, list->num_common_resources, sizeof(XawActionRes*), | |||||
817 | qcmp_action_resource); | |||||
818 | if (num_cons) | |||||
819 | qsort(&list->resources[num_xt], list->num_constraint_resources, | |||||
820 | sizeof(XawActionRes*), qcmp_action_resource); | |||||
821 | } | |||||
822 | ||||||
823 | static int | |||||
824 | bcmp_action_resource(register _Xconstconst void *string, | |||||
825 | register _Xconstconst void *resource) | |||||
826 | { | |||||
827 | return (strcmp((String)string, | |||||
828 | XrmQuarkToString((*(XawActionRes **)resource)->qname))); | |||||
829 | } | |||||
830 | ||||||
831 | static XawActionRes * | |||||
832 | _XawFindActionRes(XawActionResList *list, Widget detail, String name) | |||||
833 | { | |||||
834 | XawActionRes **res; | |||||
835 | ||||||
836 | if (!list->resources) | |||||
837 | return (NULL((void*)0)); | |||||
838 | ||||||
839 | res = (XawActionRes **)bsearch(name, list->resources, | |||||
840 | list->num_common_resources, | |||||
841 | sizeof(XawActionRes*), bcmp_action_resource); | |||||
842 | ||||||
843 | if (!res && XtParent(detail)((detail)->core.parent) | |||||
844 | && XtIsSubclass(XtParent(detail)((detail)->core.parent), constraintWidgetClass)) | |||||
845 | { | |||||
846 | XawActionResList *cons = XawGetActionResList(XtClass(XtParent(detail))((((detail)->core.parent))->core.widget_class)); | |||||
847 | ||||||
848 | if (cons) | |||||
849 | res = (XawActionRes **) | |||||
850 | bsearch(name, &cons->resources[cons->num_common_resources], | |||||
851 | cons->num_constraint_resources, | |||||
852 | sizeof(XawActionRes*), bcmp_action_resource); | |||||
853 | } | |||||
854 | ||||||
855 | return (res ? *res : NULL((void*)0)); | |||||
856 | } | |||||
857 | ||||||
858 | /* | |||||
859 | * Start of Variables Implementation Code | |||||
860 | */ | |||||
861 | /* For speed, only does memory allocation when really required */ | |||||
862 | static String | |||||
863 | _XawEscapeActionVarValue(String value) | |||||
864 | { | |||||
865 | String escape; | |||||
866 | ||||||
867 | if (value[0] == '$' || value[0] == '\\') | |||||
868 | { | |||||
869 | escape = XtMalloc(strlen(value) + 2); | |||||
870 | escape[0] = '\\'; | |||||
871 | strcpy(escape + 1, value)__builtin___strcpy_chk (escape + 1, value, __builtin_object_size (escape + 1, 2 > 1 ? 1 : 0)); | |||||
872 | return (escape); | |||||
873 | } | |||||
874 | return (NULL((void*)0)); | |||||
875 | } | |||||
876 | ||||||
877 | /* For speed, only does memory allocation when really required */ | |||||
878 | static String | |||||
879 | _XawUnescapeActionVarValue(String value) | |||||
880 | { | |||||
881 | String unescape; | |||||
882 | ||||||
883 | if (value[0] == '\\') | |||||
884 | { | |||||
885 | unescape = XtMalloc(strlen(value)); | |||||
886 | strcpy(unescape, value + 1)__builtin___strcpy_chk (unescape, value + 1, __builtin_object_size (unescape, 2 > 1 ? 1 : 0)); | |||||
887 | return (unescape); | |||||
888 | } | |||||
889 | return (NULL((void*)0)); | |||||
890 | } | |||||
891 | ||||||
892 | static void | |||||
893 | XawDeclareActionVar(XawActionVarList *list, String name, String value) | |||||
894 | { | |||||
895 | XawActionVar *variable; | |||||
896 | String escape = NULL((void*)0); | |||||
897 | ||||||
898 | if (name[0] != XAW_PRIV_VAR_PREFIX'$') | |||||
899 | { | |||||
900 | char msg[256]; | |||||
901 | ||||||
902 | snprintf(msg, sizeof(msg),__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "declare(): variable name must begin with \'%c\', at %s = %s" , '$', name, value) | |||||
903 | "declare(): variable name must begin with \'%c\', at %s = %s",__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "declare(): variable name must begin with \'%c\', at %s = %s" , '$', name, value) | |||||
904 | XAW_PRIV_VAR_PREFIX, name, value)__builtin___snprintf_chk (msg, sizeof(msg), 0, __builtin_object_size (msg, 2 > 1 ? 1 : 0), "declare(): variable name must begin with \'%c\', at %s = %s" , '$', name, value); | |||||
905 | XtAppWarning(XtWidgetToApplicationContext(list->widget), msg); | |||||
906 | return; | |||||
907 | } | |||||
908 | variable = _XawFindActionVar(list, name); | |||||
909 | if (!variable) | |||||
910 | variable = _XawCreateActionVar(list, name); | |||||
911 | if (value) | |||||
912 | escape = _XawEscapeActionVarValue(value); | |||||
913 | ||||||
914 | if (variable->qvalue) | |||||
915 | { | |||||
916 | String val = escape ? escape : value; | |||||
917 | ||||||
918 | if (strcmp(XrmQuarkToString(variable->qvalue), val) == 0) | |||||
919 | { | |||||
920 | if (escape) | |||||
921 | XtFree(escape); | |||||
922 | return; | |||||
923 | } | |||||
924 | } | |||||
925 | variable->qvalue = (escape ? XrmStringToQuark(escape) : | |||||
926 | (value ? XrmStringToQuark(value) : NULLQUARK((XrmQuark) 0))); | |||||
927 | if (escape) | |||||
928 | XtFree(escape); | |||||
929 | } | |||||
930 | ||||||
931 | static String | |||||
932 | XawConvertActionVar(XawActionVarList *list, String name) | |||||
933 | { | |||||
934 | XawActionVar *variable; | |||||
935 | String unescape; | |||||
936 | XrmQuark quark; | |||||
937 | ||||||
938 | if (name[0] != XAW_PRIV_VAR_PREFIX'$') | |||||
939 | return (name); | |||||
940 | ||||||
941 | variable = _XawFindActionVar(list, name); | |||||
942 | if (!variable || variable->qvalue == NULLQUARK((XrmQuark) 0)) | |||||
943 | return (name); | |||||
944 | unescape = _XawUnescapeActionVarValue(XrmQuarkToString(variable->qvalue)); | |||||
945 | if (unescape) | |||||
946 | { | |||||
947 | quark = XrmStringToQuark(unescape); | |||||
948 | XtFree(unescape); | |||||
949 | } | |||||
950 | else | |||||
951 | quark = variable->qvalue; | |||||
952 | ||||||
953 | return (XrmQuarkToString(quark)); | |||||
954 | } | |||||
955 | ||||||
956 | XawActionVarList * | |||||
957 | XawGetActionVarList(Widget w) | |||||
958 | { | |||||
959 | XawActionVarList *list; | |||||
960 | ||||||
961 | list = _XawFindActionVarList(w); | |||||
962 | if (!list) | |||||
963 | list = _XawCreateActionVarList(w); | |||||
964 | ||||||
965 | return (list); | |||||
966 | } | |||||
967 | ||||||
968 | static int | |||||
969 | qcmp_action_variable_list(register _Xconstconst void *left, | |||||
970 | register _Xconstconst void *right) | |||||
971 | { | |||||
972 | return ((char *)((*(XawActionVarList **)left)->widget) - | |||||
973 | (char *)((*(XawActionVarList **)right)->widget)); | |||||
974 | } | |||||
975 | ||||||
976 | static XawActionVarList * | |||||
977 | _XawCreateActionVarList(Widget w) | |||||
978 | { | |||||
979 | XawActionVarList *list; | |||||
980 | ||||||
981 | #ifdef DIAGNOSTIC | |||||
982 | fprintf(stderr__stderrp, "(*) Creating action variable list for widget %s (%p)\n", | |||||
983 | XtName(w), w); | |||||
984 | #endif | |||||
985 | ||||||
986 | list = (XawActionVarList *)XtMalloc(sizeof(XawActionVarList)); | |||||
987 | list->widget = w; | |||||
988 | list->num_variables = 0; | |||||
989 | list->variables = NULL((void*)0); | |||||
990 | ||||||
991 | if (!variable_list) | |||||
992 | { | |||||
993 | num_variable_list = 1; | |||||
994 | variable_list = (XawActionVarList **)XtMalloc(sizeof(XawActionVarList*)); | |||||
995 | variable_list[0] = list; | |||||
996 | } | |||||
997 | else | |||||
998 | { | |||||
999 | ++num_variable_list; | |||||
1000 | variable_list = (XawActionVarList **) | |||||
1001 | XtRealloc((char *)variable_list, | |||||
1002 | sizeof(XawActionVarList *) * num_variable_list); | |||||
1003 | variable_list[num_variable_list - 1] = list; | |||||
1004 | qsort(variable_list, num_variable_list, sizeof(XawActionVarList*), | |||||
1005 | qcmp_action_variable_list); | |||||
1006 | } | |||||
1007 | ||||||
1008 | XtAddCallback(w, XtNdestroyCallback((char*)&XtStrings[169]), _XawDestroyActionVarList, | |||||
1009 | (XtPointer)list); | |||||
1010 | ||||||
1011 | return (list); | |||||
1012 | } | |||||
1013 | ||||||
1014 | static int | |||||
1015 | bcmp_action_variable_list(register _Xconstconst void *widget, | |||||
1016 | register _Xconstconst void *list) | |||||
1017 | { | |||||
1018 | return ((char *)widget - (char *)((*(XawActionVarList **)list)->widget)); | |||||
1019 | } | |||||
1020 | ||||||
1021 | static XawActionVarList * | |||||
1022 | _XawFindActionVarList(Widget w) | |||||
1023 | { | |||||
1024 | XawActionVarList **list; | |||||
1025 | ||||||
1026 | if (!num_variable_list) | |||||
1027 | return (NULL((void*)0)); | |||||
1028 | ||||||
1029 | list = (XawActionVarList **)bsearch(w, variable_list, num_variable_list, | |||||
1030 | sizeof(XawActionVarList*), | |||||
1031 | bcmp_action_variable_list); | |||||
1032 | ||||||
1033 | return (list ? *list : NULL((void*)0)); | |||||
1034 | } | |||||
1035 | ||||||
1036 | static int | |||||
1037 | qcmp_action_variable(register _Xconstconst void *left, | |||||
1038 | register _Xconstconst void *right) | |||||
1039 | { | |||||
1040 | return (strcmp(XrmQuarkToString((*(XawActionVar **)left)->qname), | |||||
1041 | XrmQuarkToString((*(XawActionVar **)right)->qname))); | |||||
1042 | } | |||||
1043 | ||||||
1044 | static XawActionVar * | |||||
1045 | _XawCreateActionVar(XawActionVarList *list, String name) | |||||
1046 | { | |||||
1047 | XawActionVar *variable; | |||||
1048 | ||||||
1049 | #ifdef DIAGNOSTIC | |||||
1050 | fprintf(stderr__stderrp, "(*) Creating action variable '%s' for widget %s (%p)\n", | |||||
1051 | name, XtName(list->widget), list->widget); | |||||
1052 | #endif | |||||
1053 | ||||||
1054 | variable = (XawActionVar *)XtMalloc(sizeof(XawActionVar)); | |||||
1055 | variable->qname = XrmStringToQuark(name); | |||||
1056 | variable->qvalue = NULLQUARK((XrmQuark) 0); | |||||
1057 | ||||||
1058 | if (!list->variables) | |||||
1059 | { | |||||
1060 | list->num_variables = 1; | |||||
1061 | list->variables = (XawActionVar **)XtMalloc(sizeof(XawActionVar*)); | |||||
1062 | list->variables[0] = variable; | |||||
1063 | } | |||||
1064 | else | |||||
1065 | { | |||||
1066 | ++list->num_variables; | |||||
1067 | list->variables = (XawActionVar **)XtRealloc((char *)list->variables, | |||||
1068 | sizeof(XawActionVar *) * | |||||
1069 | list->num_variables); | |||||
1070 | list->variables[list->num_variables - 1] = variable; | |||||
1071 | qsort(list->variables, list->num_variables, sizeof(XawActionVar*), | |||||
1072 | qcmp_action_variable); | |||||
1073 | } | |||||
1074 | return (variable); | |||||
1075 | } | |||||
1076 | ||||||
1077 | static int | |||||
1078 | bcmp_action_variable(register _Xconstconst void *string, | |||||
1079 | register _Xconstconst void *variable) | |||||
1080 | { | |||||
1081 | return (strcmp((String)string, | |||||
1082 | XrmQuarkToString((*(XawActionVar **)variable)->qname))); | |||||
1083 | } | |||||
1084 | ||||||
1085 | static XawActionVar * | |||||
1086 | _XawFindActionVar(XawActionVarList *list, String name) | |||||
1087 | { | |||||
1088 | XawActionVar **var; | |||||
1089 | ||||||
1090 | if (!list->variables) | |||||
1091 | return (NULL((void*)0)); | |||||
1092 | ||||||
1093 | var = (XawActionVar **)bsearch(name, list->variables, list->num_variables, | |||||
1094 | sizeof(XawActionVar*), bcmp_action_variable); | |||||
1095 | ||||||
1096 | return (var ? *var : NULL((void*)0)); | |||||
1097 | } | |||||
1098 | ||||||
1099 | /*ARGSUSED*/ | |||||
1100 | static void | |||||
1101 | _XawDestroyActionVarList(Widget w, XtPointer client_data, XtPointer call_data) | |||||
1102 | { | |||||
1103 | XawActionVarList *list = (XawActionVarList *)client_data; | |||||
1104 | Cardinal i; | |||||
1105 | ||||||
1106 | for (i = 0; i < num_variable_list; i++) | |||||
1107 | if (variable_list[i] == list) | |||||
1108 | break; | |||||
1109 | if (i >= num_variable_list || list->widget != w | |||||
1110 | || variable_list[i]->widget != w) | |||||
1111 | { | |||||
1112 | XtWarning("destroy-variable-list(): Bad widget argument."); | |||||
1113 | return; | |||||
1114 | } | |||||
1115 | if (--num_variable_list > 0) | |||||
1116 | { | |||||
1117 | memmove(&variable_list[i], &variable_list[i + 1],__builtin___memmove_chk (&variable_list[i], &variable_list [i + 1], (num_variable_list - i) * sizeof(XawActionVarList *) , __builtin_object_size (&variable_list[i], 0)) | |||||
1118 | (num_variable_list - i) * sizeof(XawActionVarList *))__builtin___memmove_chk (&variable_list[i], &variable_list [i + 1], (num_variable_list - i) * sizeof(XawActionVarList *) , __builtin_object_size (&variable_list[i], 0)); | |||||
1119 | variable_list = (XawActionVarList **) | |||||
1120 | XtRealloc((char *)variable_list, sizeof(XawActionVarList *) * | |||||
1121 | num_variable_list); | |||||
1122 | } | |||||
1123 | else | |||||
1124 | { | |||||
1125 | XtFree((char *)variable_list); | |||||
1126 | variable_list = NULL((void*)0); | |||||
1127 | } | |||||
1128 | ||||||
1129 | XtFree((char *)list->variables); | |||||
1130 | XtFree((char *)list); | |||||
1131 | } | |||||
1132 | ||||||
1133 | #endif /* OLDXAW */ |