PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/nx-3.5.0/nx-X11/lib/Xt/Resources.c

#
C | 1259 lines | 991 code | 108 blank | 160 comment | 370 complexity | 6e30250fa92d5a64eab1ced60ef1b872 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
  1. /* $Xorg: Resources.c,v 1.4 2001/02/09 02:03:56 xorgcvs Exp $ */
  2. /***********************************************************
  3. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  4. Copyright 1993 by Sun Microsystems, Inc. Mountain View, CA.
  5. All Rights Reserved
  6. Permission to use, copy, modify, and distribute this software and its
  7. documentation for any purpose and without fee is hereby granted,
  8. provided that the above copyright notice appear in all copies and that
  9. both that copyright notice and this permission notice appear in
  10. supporting documentation, and that the names of Digital or Sun not be
  11. used in advertising or publicity pertaining to distribution of the
  12. software without specific, written prior permission.
  13. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  14. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  15. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  16. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  17. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  18. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  19. SOFTWARE.
  20. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  21. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  22. NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI-
  23. ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  24. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  25. PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  26. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
  27. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  28. ******************************************************************/
  29. /*
  30. Copyright 1987, 1988, 1994, 1998 The Open Group
  31. Permission to use, copy, modify, distribute, and sell this software and its
  32. documentation for any purpose is hereby granted without fee, provided that
  33. the above copyright notice appear in all copies and that both that
  34. copyright notice and this permission notice appear in supporting
  35. documentation.
  36. The above copyright notice and this permission notice shall be included in
  37. all copies or substantial portions of the Software.
  38. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  39. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  40. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  41. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  42. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  43. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  44. Except as contained in this notice, the name of The Open Group shall not be
  45. used in advertising or otherwise to promote the sale, use or other dealings
  46. in this Software without prior written authorization from The Open Group.
  47. */
  48. /* $XFree86: xc/lib/Xt/Resources.c,v 1.11tsi Exp $ */
  49. /*LINTLIBRARY*/
  50. #ifdef HAVE_CONFIG_H
  51. #include <config.h>
  52. #endif
  53. #include "IntrinsicI.h"
  54. #include "VarargsI.h"
  55. #include "Shell.h"
  56. #include "ShellP.h"
  57. #include "StringDefs.h"
  58. #include <stdio.h>
  59. static XrmClass QBoolean, QString, QCallProc, QImmediate;
  60. static XrmName QinitialResourcesPersistent, QInitialResourcesPersistent;
  61. static XrmClass QTranslations, QTranslationTable;
  62. static XrmName Qtranslations, QbaseTranslations;
  63. static XrmName Qscreen;
  64. static XrmClass QScreen;
  65. #ifdef CRAY
  66. void Cjump();
  67. char *Cjumpp = (char *) Cjump;
  68. void Cjump() {}
  69. #endif
  70. void _XtCopyFromParent(
  71. Widget widget,
  72. int offset,
  73. XrmValue *value)
  74. {
  75. if (widget->core.parent == NULL) {
  76. XtAppWarningMsg(XtWidgetToApplicationContext(widget),
  77. "invalidParent","xtCopyFromParent",XtCXtToolkitError,
  78. "CopyFromParent must have non-NULL parent",
  79. (String *)NULL, (Cardinal *)NULL);
  80. value->addr = NULL;
  81. return;
  82. }
  83. value->addr = (XPointer)(((char *)widget->core.parent) + offset);
  84. } /* _XtCopyFromParent */
  85. /* If the alignment characteristics of your machine are right, these may be
  86. faster */
  87. #ifdef UNALIGNED
  88. void _XtCopyFromArg(
  89. XtArgVal src,
  90. char* dst,
  91. register unsigned int size)
  92. {
  93. if (size == sizeof(long)) *(long *)dst = (long)src;
  94. else if (size == sizeof(short)) *(short *)dst = (short)src;
  95. else if (size == sizeof(char)) *(char *)dst = (char)src;
  96. else if (size == sizeof(XtPointer)) *(XtPointer *)dst = (XtPointer)src;
  97. else if (size == sizeof(char*)) *(char **)dst = (char*)src;
  98. else if (size == sizeof(XtArgVal)) *(XtArgVal *)dst = src;
  99. else if (size > sizeof(XtArgVal))
  100. (void) memmove((char *) dst, (char *) src, (int) size);
  101. else
  102. (void) memmove((char *) dst, (char *) &src, (int) size);
  103. } /* _XtCopyFromArg */
  104. void _XtCopyToArg(
  105. char* src,
  106. XtArgVal *dst,
  107. register unsigned int size)
  108. {
  109. if (! (*dst)) {
  110. #ifdef GETVALUES_BUG
  111. /* old GetValues semantics (storing directly into arglists) are bad,
  112. * but preserve for compatibility as long as arglist contains NULL.
  113. */
  114. if (size == sizeof(long)) *dst = (XtArgVal)*(long*)src;
  115. else if (size == sizeof(short)) *dst = (XtArgVal)*(short*)src;
  116. else if (size == sizeof(char)) *dst = (XtArgVal)*(char*)src;
  117. else if (size == sizeof(XtPointer)) *dst = (XtArgVal)*(XtPointer*)src;
  118. else if (size == sizeof(char*)) *dst = (XtArgVal)*(char**)src;
  119. else if (size == sizeof(XtArgVal)) *dst = *(XtArgVal*)src;
  120. else (void) memmove((char*)dst, (char*)src, (int)size);
  121. #else
  122. XtErrorMsg("invalidGetValues", "xtGetValues", XtCXtToolkitError,
  123. "NULL ArgVal in XtGetValues", (String*) NULL, (Cardinal*) NULL);
  124. #endif
  125. }
  126. else {
  127. /* proper GetValues semantics: argval is pointer to destination */
  128. if (size == sizeof(long)) *((long*)*dst) = *(long*)src;
  129. else if (size == sizeof(short)) *((short*)*dst) = *(short*)src;
  130. else if (size == sizeof(char)) *((char*)*dst) = *(char*)src;
  131. else if (size == sizeof(XtPointer)) *((XtPointer*)*dst) = *(XtPointer*)src;
  132. else if (size == sizeof(char*)) *((char**)*dst) = *(char**)src;
  133. else if (size == sizeof(XtArgVal)) *((XtArgVal*)*dst)= *(XtArgVal*)src;
  134. else (void) memmove((char*)*dst, (char*)src, (int)size);
  135. }
  136. } /* _XtCopyToArg */
  137. static void CopyToArg(
  138. char* src,
  139. XtArgVal *dst,
  140. register unsigned int size)
  141. {
  142. if (! (*dst)) {
  143. /* old GetValues semantics (storing directly into arglists) are bad,
  144. * but preserve for compatibility as long as arglist contains NULL.
  145. */
  146. if (size == sizeof(long)) *dst = (XtArgVal)*(long*)src;
  147. else if (size == sizeof(short)) *dst = (XtArgVal)*(short*)src;
  148. else if (size == sizeof(char)) *dst = (XtArgVal)*(char*)src;
  149. else if (size == sizeof(XtPointer)) *dst = (XtArgVal)*(XtPointer*)src;
  150. else if (size == sizeof(char*)) *dst = (XtArgVal)*(char**)src;
  151. else if (size == sizeof(XtArgVal)) *dst = *(XtArgVal*)src;
  152. else (void) memmove((char*)dst, (char*)src, (int)size);
  153. }
  154. else {
  155. /* proper GetValues semantics: argval is pointer to destination */
  156. if (size == sizeof(long)) *((long*)*dst) = *(long*)src;
  157. else if (size == sizeof(short)) *((short*)*dst) = *(short*)src;
  158. else if (size == sizeof(char)) *((char*)*dst) = *(char*)src;
  159. else if (size == sizeof(XtPointer)) *((XtPointer*)*dst) = *(XtPointer*)src;
  160. else if (size == sizeof(char*)) *((char**)*dst) = *(char**)src;
  161. else if (size == sizeof(XtArgVal)) *((XtArgVal*)*dst)= *(XtArgVal*)src;
  162. else (void) memmove((char*)*dst, (char*)src, (int)size);
  163. }
  164. } /* CopyToArg */
  165. #else
  166. void _XtCopyFromArg(
  167. XtArgVal src,
  168. char* dst,
  169. register unsigned int size)
  170. {
  171. if (size > sizeof(XtArgVal))
  172. (void) memmove((char *) dst, (char *) src, (int) size);
  173. else {
  174. union {
  175. long longval;
  176. #ifdef LONG64
  177. int intval;
  178. #endif
  179. short shortval;
  180. char charval;
  181. char* charptr;
  182. XtPointer ptr;
  183. } u;
  184. char *p = (char*)&u;
  185. if (size == sizeof(long)) u.longval = (long)src;
  186. #ifdef LONG64
  187. else if (size == sizeof(int)) u.intval = (int)src;
  188. #endif
  189. else if (size == sizeof(short)) u.shortval = (short)src;
  190. else if (size == sizeof(char)) u.charval = (char)src;
  191. else if (size == sizeof(XtPointer)) u.ptr = (XtPointer)src;
  192. else if (size == sizeof(char*)) u.charptr = (char*)src;
  193. else p = (char*)&src;
  194. (void) memmove(dst, p, (int) size);
  195. }
  196. } /* _XtCopyFromArg */
  197. void _XtCopyToArg(
  198. char* src,
  199. XtArgVal *dst,
  200. register unsigned int size)
  201. {
  202. if (!*dst) {
  203. #ifdef GETVALUES_BUG
  204. /* old GetValues semantics (storing directly into arglists) are bad,
  205. * but preserve for compatibility as long as arglist contains NULL.
  206. */
  207. union {
  208. long longval;
  209. #ifdef LONG64
  210. int intval;
  211. #endif
  212. short shortval;
  213. char charval;
  214. char* charptr;
  215. XtPointer ptr;
  216. } u;
  217. if (size <= sizeof(XtArgVal)) {
  218. (void) memmove((char*)&u, (char*)src, (int)size );
  219. if (size == sizeof(long)) *dst = (XtArgVal)u.longval;
  220. #ifdef LONG64
  221. else if (size == sizeof(int)) *dst = (XtArgVal)u.intval;
  222. #endif
  223. else if (size == sizeof(short)) *dst = (XtArgVal)u.shortval;
  224. else if (size == sizeof(char)) *dst = (XtArgVal)u.charval;
  225. else if (size == sizeof(char*)) *dst = (XtArgVal)u.charptr;
  226. else if (size == sizeof(XtPointer)) *dst = (XtArgVal)u.ptr;
  227. else (void) memmove((char*)dst, (char*)src, (int)size );
  228. }
  229. else
  230. (void) memmove((char*)dst, (char*)src, (int)size );
  231. #else
  232. XtErrorMsg("invalidGetValues", "xtGetValues", XtCXtToolkitError,
  233. "NULL ArgVal in XtGetValues", (String*) NULL, (Cardinal*) NULL);
  234. #endif
  235. }
  236. else {
  237. /* proper GetValues semantics: argval is pointer to destination */
  238. (void) memmove((char*)*dst, (char*)src, (int)size );
  239. }
  240. } /* _XtCopyToArg */
  241. static void CopyToArg(
  242. char* src,
  243. XtArgVal *dst,
  244. register unsigned int size)
  245. {
  246. if (!*dst) {
  247. /* old GetValues semantics (storing directly into arglists) are bad,
  248. * but preserve for compatibility as long as arglist contains NULL.
  249. */
  250. union {
  251. long longval;
  252. #ifdef LONG64
  253. int intval;
  254. #endif
  255. short shortval;
  256. char charval;
  257. char* charptr;
  258. XtPointer ptr;
  259. } u;
  260. if (size <= sizeof(XtArgVal)) {
  261. (void) memmove((char*)&u, (char*)src, (int)size );
  262. if (size == sizeof(long)) *dst = (XtArgVal)u.longval;
  263. #ifdef LONG64
  264. else if (size == sizeof(int)) *dst = (XtArgVal)u.intval;
  265. #endif
  266. else if (size == sizeof(short)) *dst = (XtArgVal)u.shortval;
  267. else if (size == sizeof(char)) *dst = (XtArgVal)u.charval;
  268. else if (size == sizeof(char*)) *dst = (XtArgVal)u.charptr;
  269. else if (size == sizeof(XtPointer)) *dst = (XtArgVal)u.ptr;
  270. else (void) memmove((char*)dst, (char*)src, (int)size );
  271. }
  272. else
  273. (void) memmove((char*)dst, (char*)src, (int)size );
  274. }
  275. else {
  276. /* proper GetValues semantics: argval is pointer to destination */
  277. (void) memmove((char*)*dst, (char*)src, (int)size );
  278. }
  279. } /* CopyToArg */
  280. #endif
  281. static Cardinal CountTreeDepth(
  282. Widget w)
  283. {
  284. Cardinal count;
  285. for (count = 1; w != NULL; w = (Widget) w->core.parent)
  286. count++;
  287. return count;
  288. }
  289. static void GetNamesAndClasses(
  290. register Widget w,
  291. register XrmNameList names,
  292. register XrmClassList classes)
  293. {
  294. register Cardinal length, j;
  295. register XrmQuark t;
  296. WidgetClass class;
  297. /* Return null-terminated quark arrays, with length the number of
  298. quarks (not including NULL) */
  299. LOCK_PROCESS;
  300. for (length = 0; w != NULL; w = (Widget) w->core.parent) {
  301. names[length] = w->core.xrm_name;
  302. class = XtClass(w);
  303. /* KLUDGE KLUDGE KLUDGE KLUDGE */
  304. if (w->core.parent == NULL && XtIsApplicationShell(w)) {
  305. classes[length] =
  306. ((ApplicationShellWidget) w)->application.xrm_class;
  307. } else classes[length] = class->core_class.xrm_class;
  308. length++;
  309. }
  310. UNLOCK_PROCESS;
  311. /* They're in backwards order, flop them around */
  312. for (j = 0; j < length/2; j++) {
  313. t = names[j];
  314. names[j] = names[length-j-1];
  315. names[length-j-1] = t;
  316. t = classes[j];
  317. classes[j] = classes[length-j-1];
  318. classes[length-j-1] = t;
  319. }
  320. names[length] = NULLQUARK;
  321. classes[length] = NULLQUARK;
  322. } /* GetNamesAndClasses */
  323. /* Spiffy fast compiled form of resource list. */
  324. /* XtResourceLists are compiled in-place into XrmResourceLists */
  325. /* All atoms are replaced by quarks, and offsets are -offset-1 to */
  326. /* indicate that this list has been compiled already */
  327. void _XtCompileResourceList(
  328. register XtResourceList resources,
  329. Cardinal num_resources)
  330. {
  331. register Cardinal count;
  332. #define xrmres ((XrmResourceList) resources)
  333. #define PSToQ XrmPermStringToQuark
  334. for (count = 0; count < num_resources; resources++, count++) {
  335. xrmres->xrm_name = PSToQ(resources->resource_name);
  336. xrmres->xrm_class = PSToQ(resources->resource_class);
  337. xrmres->xrm_type = PSToQ(resources->resource_type);
  338. xrmres->xrm_offset = (Cardinal)
  339. (-(int)resources->resource_offset - 1);
  340. xrmres->xrm_default_type = PSToQ(resources->default_type);
  341. }
  342. #undef PSToQ
  343. #undef xrmres
  344. } /* _XtCompileResourceList */
  345. /* Like _XtCompileResourceList, but strings are not permanent */
  346. static void XrmCompileResourceListEphem(
  347. register XtResourceList resources,
  348. Cardinal num_resources)
  349. {
  350. register Cardinal count;
  351. #define xrmres ((XrmResourceList) resources)
  352. for (count = 0; count < num_resources; resources++, count++) {
  353. xrmres->xrm_name = StringToName(resources->resource_name);
  354. xrmres->xrm_class = StringToClass(resources->resource_class);
  355. xrmres->xrm_type = StringToQuark(resources->resource_type);
  356. xrmres->xrm_offset = (Cardinal)
  357. (-(int)resources->resource_offset - 1);
  358. xrmres->xrm_default_type = StringToQuark(resources->default_type);
  359. }
  360. #undef xrmres
  361. } /* XrmCompileResourceListEphem */
  362. static void BadSize(
  363. Cardinal size,
  364. XrmQuark name)
  365. {
  366. String params[2];
  367. Cardinal num_params = 2;
  368. params[0] = (String)(long) size;
  369. params[1] = XrmQuarkToString(name);
  370. XtWarningMsg("invalidSizeOverride", "xtDependencies", XtCXtToolkitError,
  371. "Representation size %d must match superclass's to override %s",
  372. params, &num_params);
  373. } /* BadType */
  374. /*
  375. * Create a new resource list, with the class resources following the
  376. * superclass's resources. If a resource in the class list overrides
  377. * a superclass resource, then just replace the superclass entry in place.
  378. *
  379. * At the same time, add a level of indirection to the XtResourceList to
  380. * create and XrmResourceList.
  381. */
  382. void _XtDependencies(
  383. XtResourceList *class_resp, /* VAR */
  384. Cardinal *class_num_resp, /* VAR */
  385. XrmResourceList *super_res,
  386. Cardinal super_num_res,
  387. Cardinal super_widget_size)
  388. {
  389. register XrmResourceList *new_res;
  390. Cardinal new_num_res;
  391. XrmResourceList class_res = (XrmResourceList) *class_resp;
  392. Cardinal class_num_res = *class_num_resp;
  393. register Cardinal i, j;
  394. Cardinal new_next;
  395. if (class_num_res == 0) {
  396. /* Just point to superclass resource list */
  397. *class_resp = (XtResourceList) super_res;
  398. *class_num_resp = super_num_res;
  399. return;
  400. }
  401. /* Allocate and initialize new_res with superclass resource pointers */
  402. new_num_res = super_num_res + class_num_res;
  403. new_res = (XrmResourceList *) __XtMalloc(new_num_res*sizeof(XrmResourceList));
  404. if (super_num_res > 0)
  405. XtMemmove(new_res, super_res, super_num_res * sizeof(XrmResourceList));
  406. /* Put pointers to class resource entries into new_res */
  407. new_next = super_num_res;
  408. for (i = 0; i < class_num_res; i++) {
  409. if ((Cardinal)(-class_res[i].xrm_offset-1) < super_widget_size) {
  410. /* Probably an override of superclass resources--look for overlap */
  411. for (j = 0; j < super_num_res; j++) {
  412. if (class_res[i].xrm_offset == new_res[j]->xrm_offset) {
  413. /* Spec is silent on what fields subclass can override.
  414. * The only two of real concern are type & size.
  415. * Although allowing type to be over-ridden introduces
  416. * the possibility of errors, it's at present the only
  417. * reasonable way to allow a subclass to force a private
  418. * converter to be invoked for a subset of fields.
  419. */
  420. /* We do insist that size be identical to superclass */
  421. if (class_res[i].xrm_size != new_res[j]->xrm_size) {
  422. BadSize(class_res[i].xrm_size,
  423. (XrmQuark) class_res[i].xrm_name);
  424. class_res[i].xrm_size = new_res[j]->xrm_size;
  425. }
  426. new_res[j] = &(class_res[i]);
  427. new_num_res--;
  428. goto NextResource;
  429. }
  430. } /* for j */
  431. }
  432. /* Not an overlap, add an entry to new_res */
  433. new_res[new_next++] = &(class_res[i]);
  434. NextResource:;
  435. } /* for i */
  436. /* Okay, stuff new resources back into class record */
  437. *class_resp = (XtResourceList) new_res;
  438. *class_num_resp = new_num_res;
  439. } /* _XtDependencies */
  440. void _XtResourceDependencies(
  441. WidgetClass wc)
  442. {
  443. WidgetClass sc;
  444. sc = wc->core_class.superclass;
  445. if (sc == NULL) {
  446. _XtDependencies(&(wc->core_class.resources),
  447. &(wc->core_class.num_resources),
  448. (XrmResourceList *) NULL, (unsigned)0, (unsigned)0);
  449. } else {
  450. _XtDependencies(&(wc->core_class.resources),
  451. &(wc->core_class.num_resources),
  452. (XrmResourceList *) sc->core_class.resources,
  453. sc->core_class.num_resources,
  454. sc->core_class.widget_size);
  455. }
  456. } /* _XtResourceDependencies */
  457. void _XtConstraintResDependencies(
  458. ConstraintWidgetClass wc)
  459. {
  460. ConstraintWidgetClass sc;
  461. if (wc == (ConstraintWidgetClass) constraintWidgetClass) {
  462. _XtDependencies(&(wc->constraint_class.resources),
  463. &(wc->constraint_class.num_resources),
  464. (XrmResourceList *)NULL, (unsigned)0, (unsigned)0);
  465. } else {
  466. sc = (ConstraintWidgetClass) wc->core_class.superclass;
  467. _XtDependencies(&(wc->constraint_class.resources),
  468. &(wc->constraint_class.num_resources),
  469. (XrmResourceList *) sc->constraint_class.resources,
  470. sc->constraint_class.num_resources,
  471. sc->constraint_class.constraint_size);
  472. }
  473. } /* _XtConstraintResDependencies */
  474. XrmResourceList* _XtCreateIndirectionTable (
  475. XtResourceList resources,
  476. Cardinal num_resources)
  477. {
  478. register Cardinal idx;
  479. XrmResourceList* table;
  480. table = (XrmResourceList*)__XtMalloc(num_resources * sizeof(XrmResourceList));
  481. for (idx = 0; idx < num_resources; idx++)
  482. table[idx] = (XrmResourceList)(&(resources[idx]));
  483. return table;
  484. }
  485. static XtCacheRef *GetResources(
  486. Widget widget, /* Widget resources are associated with */
  487. char* base, /* Base address of memory to write to */
  488. XrmNameList names, /* Full inheritance name of widget */
  489. XrmClassList classes, /* Full inheritance class of widget */
  490. XrmResourceList* table, /* The list of resources required. */
  491. unsigned num_resources, /* number of items in resource list */
  492. XrmQuarkList quark_args, /* Arg names quarkified */
  493. ArgList args, /* ArgList to override resources */
  494. unsigned num_args, /* number of items in arg list */
  495. XtTypedArgList typed_args, /* Typed arg list to override resources */
  496. Cardinal* pNumTypedArgs, /* number of items in typed arg list */
  497. Boolean tm_hack) /* do baseTranslations */
  498. {
  499. /*
  500. * assert: *pNumTypedArgs == 0 if num_args > 0
  501. * assert: num_args == 0 if *pNumTypedArgs > 0
  502. */
  503. #define SEARCHLISTLEN 100
  504. #define MAXRESOURCES 400
  505. XrmValue value;
  506. XrmQuark rawType;
  507. XrmValue convValue;
  508. XrmHashTable stackSearchList[SEARCHLISTLEN];
  509. XrmHashTable *searchList = stackSearchList;
  510. unsigned int searchListSize = SEARCHLISTLEN;
  511. Boolean found[MAXRESOURCES];
  512. int typed[MAXRESOURCES];
  513. XtCacheRef cache_ref[MAXRESOURCES];
  514. XtCacheRef *cache_ptr, *cache_base;
  515. Boolean persistent_resources = True;
  516. Boolean found_persistence = False;
  517. int num_typed_args = *pNumTypedArgs;
  518. XrmDatabase db;
  519. Boolean do_tm_hack = False;
  520. if ((args == NULL) && (num_args != 0)) {
  521. XtAppWarningMsg(XtWidgetToApplicationContext(widget),
  522. "invalidArgCount","getResources",XtCXtToolkitError,
  523. "argument count > 0 on NULL argument list",
  524. (String *)NULL, (Cardinal *)NULL);
  525. num_args = 0;
  526. }
  527. if (num_resources == 0) {
  528. return NULL;
  529. } else if (num_resources >= MAXRESOURCES) {
  530. XtAppWarningMsg(XtWidgetToApplicationContext(widget),
  531. "invalidResourceCount","getResources",XtCXtToolkitError,
  532. "too many resources",
  533. (String *)NULL, (Cardinal *)NULL);
  534. return NULL;
  535. } else if (table == NULL) {
  536. XtAppWarningMsg(XtWidgetToApplicationContext(widget),
  537. "invalidResourceCount","getResources",XtCXtToolkitError,
  538. "resource count > 0 on NULL resource list",
  539. (String *)NULL, (Cardinal *)NULL);
  540. return NULL;
  541. }
  542. /* Mark each resource as not found on arg list */
  543. bzero((char *) found, (int) (num_resources * sizeof(Boolean)));
  544. bzero((char *) typed, (int) (num_resources * sizeof(int)));
  545. /* Copy the args into the resources, mark each as found */
  546. {
  547. register ArgList arg;
  548. register XtTypedArgList typed_arg;
  549. register XrmName argName;
  550. register Cardinal j;
  551. register int i;
  552. register XrmResourceList rx;
  553. register XrmResourceList *res;
  554. for (arg = args, i = 0; (Cardinal)i < num_args; i++, arg++) {
  555. argName = quark_args[i];
  556. if (argName == QinitialResourcesPersistent) {
  557. persistent_resources = (Boolean)arg->value;
  558. found_persistence = True;
  559. continue;
  560. }
  561. for (j = 0, res = table; j < num_resources; j++, res++) {
  562. rx = *res;
  563. if (argName == rx->xrm_name) {
  564. _XtCopyFromArg(
  565. arg->value,
  566. base - rx->xrm_offset - 1,
  567. rx->xrm_size);
  568. found[j] = TRUE;
  569. break;
  570. }
  571. }
  572. }
  573. for (typed_arg = typed_args, i = 0; i < num_typed_args;
  574. i++, typed_arg++) {
  575. register XrmRepresentation argType;
  576. argName = quark_args[i];
  577. argType = (typed_arg->type == NULL) ? NULLQUARK
  578. : XrmStringToRepresentation(typed_arg->type);
  579. if (argName == QinitialResourcesPersistent) {
  580. persistent_resources = (Boolean)typed_arg->value;
  581. found_persistence = True;
  582. break;
  583. }
  584. for (j = 0, res = table; j < num_resources; j++, res++) {
  585. rx = *res;
  586. if (argName == rx->xrm_name) {
  587. if (argType != NULLQUARK && argType != rx->xrm_type) {
  588. typed[j] = i + 1;
  589. } else {
  590. _XtCopyFromArg(
  591. typed_arg->value,
  592. base - rx->xrm_offset - 1,
  593. rx->xrm_size);
  594. }
  595. found[j] = TRUE;
  596. break;
  597. }
  598. }
  599. }
  600. }
  601. /* Ask resource manager for a list of database levels that we can
  602. do a single-level search on each resource */
  603. db = XtScreenDatabase(XtScreenOfObject(widget));
  604. while (!XrmQGetSearchList(db, names, classes,
  605. searchList, searchListSize)) {
  606. if (searchList == stackSearchList)
  607. searchList = NULL;
  608. searchList = (XrmHashTable*)XtRealloc((char*)searchList,
  609. sizeof(XrmHashTable) *
  610. (searchListSize *= 2));
  611. }
  612. if (persistent_resources)
  613. cache_base = NULL;
  614. else
  615. cache_base = cache_ref;
  616. /* geez, this is an ugly mess */
  617. if (XtIsShell(widget)) {
  618. register XrmResourceList *res;
  619. register Cardinal j;
  620. Screen *oldscreen = widget->core.screen;
  621. /* look up screen resource first, since real rdb depends on it */
  622. for (res = table, j = 0; j < num_resources; j++, res++) {
  623. if ((*res)->xrm_name != Qscreen)
  624. continue;
  625. if (typed[j]) {
  626. register XtTypedArg* arg = typed_args + typed[j] - 1;
  627. XrmQuark from_type;
  628. XrmValue from_val, to_val;
  629. from_type = StringToQuark(arg->type);
  630. from_val.size = arg->size;
  631. if ((from_type == QString) || ((unsigned) arg->size > sizeof(XtArgVal)))
  632. from_val.addr = (XPointer)arg->value;
  633. else
  634. from_val.addr = (XPointer)&arg->value;
  635. to_val.size = sizeof(Screen*);
  636. to_val.addr = (XPointer)&widget->core.screen;
  637. found[j] = _XtConvert(widget, from_type, &from_val,
  638. QScreen, &to_val, cache_base);
  639. if (cache_base && *cache_base)
  640. cache_base++;
  641. }
  642. if (!found[j]) {
  643. if (XrmQGetSearchResource(searchList, Qscreen, QScreen,
  644. &rawType, &value)) {
  645. if (rawType != QScreen) {
  646. convValue.size = sizeof(Screen*);
  647. convValue.addr = (XPointer)&widget->core.screen;
  648. (void)_XtConvert(widget, rawType, &value,
  649. QScreen, &convValue, cache_base);
  650. if (cache_base && *cache_base)
  651. cache_base++;
  652. } else {
  653. widget->core.screen = *((Screen **)value.addr);
  654. }
  655. }
  656. }
  657. break;
  658. }
  659. /* now get the database to use for the rest of the resources */
  660. if (widget->core.screen != oldscreen) {
  661. db = XtScreenDatabase(widget->core.screen);
  662. while (!XrmQGetSearchList(db, names, classes,
  663. searchList, searchListSize)) {
  664. if (searchList == stackSearchList)
  665. searchList = NULL;
  666. searchList = (XrmHashTable*)XtRealloc((char*)searchList,
  667. sizeof(XrmHashTable) *
  668. (searchListSize *= 2));
  669. }
  670. }
  671. }
  672. /* go to the resource manager for those resources not found yet */
  673. /* if it's not in the resource database use the default value */
  674. {
  675. register XrmResourceList rx;
  676. register XrmResourceList *res;
  677. register Cardinal j;
  678. register XrmRepresentation xrm_type;
  679. register XrmRepresentation xrm_default_type;
  680. char char_val;
  681. short short_val;
  682. int int_val;
  683. long long_val;
  684. char* char_ptr;
  685. if (!found_persistence) {
  686. if (XrmQGetSearchResource(searchList, QinitialResourcesPersistent,
  687. QInitialResourcesPersistent, &rawType, &value)) {
  688. if (rawType != QBoolean) {
  689. convValue.size = sizeof(Boolean);
  690. convValue.addr = (XPointer)&persistent_resources;
  691. (void)_XtConvert(widget, rawType, &value, QBoolean,
  692. &convValue, NULL);
  693. }
  694. else
  695. persistent_resources = *(Boolean*)value.addr;
  696. }
  697. }
  698. if (persistent_resources)
  699. cache_ptr = NULL;
  700. else if (cache_base)
  701. cache_ptr = cache_base;
  702. else
  703. cache_ptr = cache_ref;
  704. for (res = table, j = 0; j < num_resources; j++, res++) {
  705. rx = *res;
  706. xrm_type = rx->xrm_type;
  707. if (typed[j]) {
  708. register XtTypedArg* arg = typed_args + typed[j] - 1;
  709. /*
  710. * This resource value has been specified as a typed arg and
  711. * has to be converted. Typed arg conversions are done here
  712. * to correctly interpose them with normal resource conversions.
  713. */
  714. XrmQuark from_type;
  715. XrmValue from_val, to_val;
  716. Boolean converted;
  717. from_type = StringToQuark(arg->type);
  718. from_val.size = arg->size;
  719. if ((from_type == QString) || ((unsigned) arg->size > sizeof(XtArgVal)))
  720. from_val.addr = (XPointer)arg->value;
  721. else
  722. from_val.addr = (XPointer)&arg->value;
  723. to_val.size = rx->xrm_size;
  724. to_val.addr = base - rx->xrm_offset - 1;
  725. converted = _XtConvert(widget, from_type, &from_val,
  726. xrm_type, &to_val, cache_ptr);
  727. if (converted) {
  728. /* Copy the converted value back into the typed argument.
  729. * normally the data should be <= sizeof(XtArgVal) and
  730. * is stored directly into the 'value' field .... BUT
  731. * if the resource size is greater than sizeof(XtArgVal)
  732. * then we dynamically alloc a block of store to hold the
  733. * data and zap a copy in there !!! .... freeing it later
  734. * the size field in the typed arg is negated to indicate
  735. * that the store pointed to by the value field is
  736. * dynamic .......
  737. * "freeing" happens in the case of _XtCreate after the
  738. * CallInitialize ..... other clients of GetResources
  739. * using typed args should be aware of the need to free
  740. * this store .....
  741. */
  742. if(rx->xrm_size > sizeof(XtArgVal)) {
  743. arg->value = (XtArgVal) __XtMalloc(rx->xrm_size);
  744. arg->size = -(arg->size);
  745. } else { /* will fit - copy directly into value field */
  746. arg->value = (XtArgVal) NULL;
  747. }
  748. CopyToArg((char *)(base - rx->xrm_offset - 1),
  749. &arg->value, rx->xrm_size);
  750. } else {
  751. /* Conversion failed. Get default value. */
  752. found[j] = False;
  753. }
  754. if (cache_ptr && *cache_ptr)
  755. cache_ptr++;
  756. }
  757. if (!found[j]) {
  758. Boolean already_copied = False;
  759. Boolean have_value = False;
  760. if (XrmQGetSearchResource(searchList,
  761. rx->xrm_name, rx->xrm_class, &rawType, &value)) {
  762. if (rawType != xrm_type) {
  763. convValue.size = rx->xrm_size;
  764. convValue.addr = (XPointer)(base - rx->xrm_offset - 1);
  765. already_copied = have_value =
  766. _XtConvert(widget, rawType, &value,
  767. xrm_type, &convValue, cache_ptr);
  768. if (cache_ptr && *cache_ptr)
  769. cache_ptr++;
  770. } else have_value = True;
  771. if (have_value && rx->xrm_name == Qtranslations)
  772. do_tm_hack = True;
  773. }
  774. LOCK_PROCESS;
  775. if (!have_value
  776. && ((rx->xrm_default_type == QImmediate)
  777. || (rx->xrm_default_type == xrm_type)
  778. || (rx->xrm_default_addr != NULL))) {
  779. /* Convert default value to proper type */
  780. xrm_default_type = rx->xrm_default_type;
  781. if (xrm_default_type == QCallProc) {
  782. #ifdef CRAY
  783. if ( (int) Cjumpp != (int) Cjump)
  784. (*(XtResourceDefaultProc)
  785. (((int)(rx->xrm_default_addr))<<2))(
  786. widget,-(rx->xrm_offset+1), &value);
  787. else
  788. #endif
  789. (*(XtResourceDefaultProc)(rx->xrm_default_addr))(
  790. widget,-(rx->xrm_offset+1), &value);
  791. } else if (xrm_default_type == QImmediate) {
  792. /* XtRImmediate == XtRString for type XtRString */
  793. if (xrm_type == QString) {
  794. value.addr = rx->xrm_default_addr;
  795. } else if (rx->xrm_size == sizeof(int)) {
  796. int_val = (int)(long)rx->xrm_default_addr;
  797. value.addr = (XPointer) &int_val;
  798. } else if (rx->xrm_size == sizeof(short)) {
  799. short_val = (short)(long)rx->xrm_default_addr;
  800. value.addr = (XPointer) &short_val;
  801. } else if (rx->xrm_size == sizeof(char)) {
  802. char_val = (char)(long)rx->xrm_default_addr;
  803. value.addr = (XPointer) &char_val;
  804. } else if (rx->xrm_size == sizeof(long)) {
  805. long_val = (long)rx->xrm_default_addr;
  806. value.addr = (XPointer) &long_val;
  807. } else if (rx->xrm_size == sizeof(char*)) {
  808. char_ptr = (char*)rx->xrm_default_addr;
  809. value.addr = (XPointer) &char_ptr;
  810. } else {
  811. value.addr = (XPointer) &(rx->xrm_default_addr);
  812. }
  813. } else if (xrm_default_type == xrm_type) {
  814. value.addr = rx->xrm_default_addr;
  815. } else {
  816. value.addr = rx->xrm_default_addr;
  817. if (xrm_default_type == QString) {
  818. value.size = strlen((char *)value.addr) + 1;
  819. } else {
  820. value.size = sizeof(XtPointer);
  821. }
  822. convValue.size = rx->xrm_size;
  823. convValue.addr = (XPointer)(base - rx->xrm_offset - 1);
  824. already_copied =
  825. _XtConvert(widget, xrm_default_type, &value,
  826. xrm_type, &convValue, cache_ptr);
  827. if (!already_copied)
  828. value.addr = NULL;
  829. if (cache_ptr && *cache_ptr)
  830. cache_ptr++;
  831. }
  832. }
  833. if (!already_copied) {
  834. if (xrm_type == QString) {
  835. *((String*)(base - rx->xrm_offset - 1)) = value.addr;
  836. } else {
  837. if (value.addr != NULL) {
  838. XtMemmove(base - rx->xrm_offset - 1,
  839. value.addr, rx->xrm_size);
  840. } else {
  841. /* didn't get value, initialize to NULL... */
  842. XtBZero(base - rx->xrm_offset - 1, rx->xrm_size);
  843. }
  844. }
  845. }
  846. UNLOCK_PROCESS;
  847. if (typed[j]) {
  848. /*
  849. * This resource value was specified as a typed arg.
  850. * However, the default value is being used here since
  851. * type type conversion failed, so we compress the list.
  852. */
  853. register XtTypedArg* arg = typed_args + typed[j] - 1;
  854. register int i;
  855. for (i = num_typed_args - typed[j]; i; i--, arg++) {
  856. *arg = *(arg+1);
  857. }
  858. num_typed_args--;
  859. }
  860. }
  861. }
  862. if (tm_hack)
  863. widget->core.tm.current_state = NULL;
  864. if (tm_hack &&
  865. (!widget->core.tm.translations ||
  866. (do_tm_hack &&
  867. widget->core.tm.translations->operation != XtTableReplace)) &&
  868. XrmQGetSearchResource(searchList, QbaseTranslations,
  869. QTranslations, &rawType, &value)) {
  870. if (rawType != QTranslationTable) {
  871. convValue.size = sizeof(XtTranslations);
  872. convValue.addr = (XPointer)&widget->core.tm.current_state;
  873. (void)_XtConvert(widget, rawType, &value,
  874. QTranslationTable, &convValue, cache_ptr);
  875. if (cache_ptr && *cache_ptr)
  876. cache_ptr++;
  877. } else {
  878. *((XtTranslations *)&widget->core.tm.current_state) =
  879. *((XtTranslations *)value.addr);
  880. }
  881. }
  882. }
  883. if ((Cardinal)num_typed_args != *pNumTypedArgs) *pNumTypedArgs = num_typed_args;
  884. if (searchList != stackSearchList) XtFree((char*)searchList);
  885. if (!cache_ptr)
  886. cache_ptr = cache_base;
  887. if (cache_ptr && cache_ptr != cache_ref) {
  888. int cache_ref_size = cache_ptr - cache_ref;
  889. XtCacheRef *refs = (XtCacheRef*)
  890. __XtMalloc((unsigned)sizeof(XtCacheRef)*(cache_ref_size + 1));
  891. (void) memmove(refs, cache_ref, sizeof(XtCacheRef)*cache_ref_size );
  892. refs[cache_ref_size] = NULL;
  893. return refs;
  894. }
  895. return (XtCacheRef*)NULL;
  896. }
  897. static void CacheArgs(
  898. ArgList args,
  899. Cardinal num_args,
  900. XtTypedArgList typed_args,
  901. Cardinal num_typed_args,
  902. XrmQuarkList quark_cache,
  903. Cardinal num_quarks,
  904. XrmQuarkList *pQuarks) /* RETURN */
  905. {
  906. register XrmQuarkList quarks;
  907. register Cardinal i;
  908. register Cardinal count;
  909. count = (args != NULL) ? num_args : num_typed_args;
  910. if (num_quarks < count) {
  911. quarks = (XrmQuarkList) __XtMalloc(count * sizeof(XrmQuark));
  912. } else {
  913. quarks = quark_cache;
  914. }
  915. *pQuarks = quarks;
  916. if (args != NULL) {
  917. for (i = count; i; i--)
  918. *quarks++ = StringToQuark((args++)->name);
  919. }
  920. else {
  921. for (i = count; i; i--)
  922. *quarks++ = StringToQuark((typed_args++)->name);
  923. }
  924. }
  925. #define FreeCache(cache, pointer) \
  926. if (cache != pointer) XtFree((char *)pointer)
  927. XtCacheRef *_XtGetResources(
  928. register Widget w,
  929. ArgList args,
  930. Cardinal num_args,
  931. XtTypedArgList typed_args,
  932. Cardinal* num_typed_args)
  933. {
  934. XrmName *names, names_s[50];
  935. XrmClass *classes, classes_s[50];
  936. XrmQuark quark_cache[100];
  937. XrmQuarkList quark_args;
  938. WidgetClass wc;
  939. ConstraintWidgetClass cwc;
  940. XtCacheRef *cache_refs;
  941. Cardinal count;
  942. wc = XtClass(w);
  943. count = CountTreeDepth(w);
  944. names = (XrmName*) XtStackAlloc (count * sizeof(XrmName), names_s);
  945. classes = (XrmClass*) XtStackAlloc (count * sizeof(XrmClass), classes_s);
  946. if (names == NULL || classes == NULL) _XtAllocError(NULL);
  947. /* Get names, classes for widget and ancestors */
  948. GetNamesAndClasses(w, names, classes);
  949. /* Compile arg list into quarks */
  950. CacheArgs(args, num_args, typed_args, *num_typed_args, quark_cache,
  951. XtNumber(quark_cache), &quark_args);
  952. /* Get normal resources */
  953. LOCK_PROCESS;
  954. cache_refs = GetResources(w, (char*)w, names, classes,
  955. (XrmResourceList *) wc->core_class.resources,
  956. wc->core_class.num_resources, quark_args, args, num_args,
  957. typed_args, num_typed_args, XtIsWidget(w));
  958. if (w->core.constraints != NULL) {
  959. cwc = (ConstraintWidgetClass) XtClass(w->core.parent);
  960. (void) GetResources(w, (char*)w->core.constraints, names, classes,
  961. (XrmResourceList *) cwc->constraint_class.resources,
  962. cwc->constraint_class.num_resources,
  963. quark_args, args, num_args, typed_args, num_typed_args, False);
  964. }
  965. FreeCache(quark_cache, quark_args);
  966. UNLOCK_PROCESS;
  967. XtStackFree((XtPointer)names, names_s);
  968. XtStackFree((XtPointer)classes, classes_s);
  969. return cache_refs;
  970. } /* _XtGetResources */
  971. void _XtGetSubresources (
  972. Widget w, /* Widget "parent" of subobject */
  973. XtPointer base, /* Base address to write to */
  974. const char* name, /* name of subobject */
  975. const char* class, /* class of subobject */
  976. XtResourceList resources, /* resource list for subobject */
  977. Cardinal num_resources,
  978. ArgList args, /* arg list to override resources */
  979. Cardinal num_args,
  980. XtTypedArgList typed_args,
  981. Cardinal num_typed_args)
  982. {
  983. XrmName *names, names_s[50];
  984. XrmClass *classes, classes_s[50];
  985. XrmQuark quark_cache[100];
  986. XrmQuarkList quark_args;
  987. XrmResourceList* table;
  988. Cardinal count, ntyped_args = num_typed_args;
  989. WIDGET_TO_APPCON(w);
  990. if (num_resources == 0) return;
  991. LOCK_APP(app);
  992. count = CountTreeDepth(w);
  993. count++; /* make sure there's enough room for name and class */
  994. names = (XrmName*) XtStackAlloc(count * sizeof(XrmName), names_s);
  995. classes = (XrmClass*) XtStackAlloc(count * sizeof(XrmClass), classes_s);
  996. if (names == NULL || classes == NULL) _XtAllocError(NULL);
  997. /* Get full name, class of subobject */
  998. GetNamesAndClasses(w, names, classes);
  999. count -= 2;
  1000. names[count] = StringToName(name);
  1001. classes[count] = StringToClass(class);
  1002. count++;
  1003. names[count] = NULLQUARK;
  1004. classes[count] = NULLQUARK;
  1005. /* Compile arg list into quarks */
  1006. CacheArgs(args, num_args, typed_args, num_typed_args,
  1007. quark_cache, XtNumber(quark_cache), &quark_args);
  1008. /* Compile resource list if needed */
  1009. if (((int) resources->resource_offset) >= 0) {
  1010. XrmCompileResourceListEphem(resources, num_resources);
  1011. }
  1012. table = _XtCreateIndirectionTable(resources, num_resources);
  1013. (void) GetResources(w, (char*)base, names, classes, table, num_resources,
  1014. quark_args, args, num_args,
  1015. typed_args, &ntyped_args, False);
  1016. FreeCache(quark_cache, quark_args);
  1017. XtFree((char *)table);
  1018. XtStackFree((XtPointer)names, names_s);
  1019. XtStackFree((XtPointer)classes, classes_s);
  1020. UNLOCK_APP(app);
  1021. }
  1022. void XtGetSubresources (
  1023. Widget w, /* Widget "parent" of subobject */
  1024. XtPointer base, /* Base address to write to */
  1025. _Xconst char* name, /* name of subobject */
  1026. _Xconst char* class, /* class of subobject */
  1027. XtResourceList resources, /* resource list for subobject */
  1028. Cardinal num_resources,
  1029. ArgList args, /* arg list to override resources */
  1030. Cardinal num_args)
  1031. {
  1032. _XtGetSubresources (w, base, name, class, resources, num_resources, args, num_args, NULL, 0);
  1033. }
  1034. void _XtGetApplicationResources (
  1035. Widget w, /* Application shell widget */
  1036. XtPointer base, /* Base address to write to */
  1037. XtResourceList resources, /* resource list for subobject */
  1038. Cardinal num_resources,
  1039. ArgList args, /* arg list to override resources */
  1040. Cardinal num_args,
  1041. XtTypedArgList typed_args,
  1042. Cardinal num_typed_args)
  1043. {
  1044. XrmName *names, names_s[50];
  1045. XrmClass *classes, classes_s[50];
  1046. XrmQuark quark_cache[100];
  1047. XrmQuarkList quark_args;
  1048. XrmResourceList* table;
  1049. Cardinal count, ntyped_args = num_typed_args;
  1050. #ifdef XTHREADS
  1051. XtAppContext app;
  1052. #endif
  1053. if (num_resources == 0) return;
  1054. #ifdef XTHREADS
  1055. if (w == NULL) app = _XtDefaultAppContext();
  1056. else app = XtWidgetToApplicationContext(w);
  1057. #endif
  1058. LOCK_APP(app);
  1059. /* Get full name, class of application */
  1060. if (w == NULL) {
  1061. /* hack for R2 compatibility */
  1062. XtPerDisplay pd = _XtGetPerDisplay(_XtDefaultAppContext()->list[0]);
  1063. names = (XrmName*) XtStackAlloc (2 * sizeof(XrmName), names_s);
  1064. classes = (XrmClass*) XtStackAlloc (2 * sizeof(XrmClass), classes_s);
  1065. names[0] = pd->name;
  1066. names[1] = NULLQUARK;
  1067. classes[0] = pd->class;
  1068. classes[1] = NULLQUARK;
  1069. }
  1070. else {
  1071. count = CountTreeDepth(w);
  1072. names = (XrmName*) XtStackAlloc(count * sizeof(XrmName), names_s);
  1073. classes = (XrmClass*) XtStackAlloc(count * sizeof(XrmClass), classes_s);
  1074. if (names == NULL || classes == NULL) _XtAllocError(NULL);
  1075. GetNamesAndClasses(w, names, classes);
  1076. }
  1077. /* Compile arg list into quarks */
  1078. CacheArgs(args, num_args, typed_args, num_typed_args, quark_cache,
  1079. XtNumber(quark_cache), &quark_args);
  1080. /* Compile resource list if needed */
  1081. if (((int) resources->resource_offset) >= 0) {
  1082. #ifdef CRAY2
  1083. if (base == 0) { /* this client is non-portable, but... */
  1084. int count;
  1085. XtResourceList res = resources;
  1086. for (count = 0; count < num_resources; res++, count++) {
  1087. res->resource_offset *= sizeof(long);
  1088. }
  1089. }
  1090. #endif /* CRAY2 */
  1091. XrmCompileResourceListEphem(resources, num_resources);
  1092. }
  1093. table = _XtCreateIndirectionTable(resources,num_resources);
  1094. (void) GetResources(w, (char*)base, names, classes, table, num_resources,
  1095. quark_args, args, num_args,
  1096. typed_args, &ntyped_args, False);
  1097. FreeCache(quark_cache, quark_args);
  1098. XtFree((char *)table);
  1099. if (w != NULL) {
  1100. XtStackFree((XtPointer)names, names_s);
  1101. XtStackFree((XtPointer)classes, classes_s);
  1102. }
  1103. UNLOCK_APP(app);
  1104. }
  1105. void XtGetApplicationResources (
  1106. Widget w, /* Application shell widget */
  1107. XtPointer base, /* Base address to write to */
  1108. XtResourceList resources, /* resource list for subobject */
  1109. Cardinal num_resources,
  1110. ArgList args, /* arg list to override resources */
  1111. Cardinal num_args)
  1112. {
  1113. _XtGetApplicationResources(w, base, resources, num_resources, args, num_args, NULL, 0);
  1114. }
  1115. static Boolean initialized = FALSE;
  1116. void _XtResourceListInitialize(void)
  1117. {
  1118. LOCK_PROCESS;
  1119. if (initialized) {
  1120. XtWarningMsg("initializationError","xtInitialize",XtCXtToolkitError,
  1121. "Initializing Resource Lists twice",
  1122. (String *)NULL, (Cardinal *)NULL);
  1123. UNLOCK_PROCESS;
  1124. return;
  1125. }
  1126. initialized = TRUE;
  1127. UNLOCK_PROCESS;
  1128. QBoolean = XrmPermStringToQuark(XtCBoolean);
  1129. QString = XrmPermStringToQuark(XtCString);
  1130. QCallProc = XrmPermStringToQuark(XtRCallProc);
  1131. QImmediate = XrmPermStringToQuark(XtRImmediate);
  1132. QinitialResourcesPersistent = XrmPermStringToQuark(XtNinitialResourcesPersistent);
  1133. QInitialResourcesPersistent = XrmPermStringToQuark(XtCInitialResourcesPersistent);
  1134. Qtranslations = XrmPermStringToQuark(XtNtranslations);
  1135. QbaseTranslations = XrmPermStringToQuark("baseTranslations");
  1136. QTranslations = XrmPermStringToQuark(XtCTranslations);
  1137. QTranslationTable = XrmPermStringToQuark(XtRTranslationTable);
  1138. Qscreen = XrmPermStringToQuark(XtNscreen);
  1139. QScreen = XrmPermStringToQuark(XtCScreen);
  1140. }