wmlresolve.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * @OSF_COPYRIGHT@
  25. * COPYRIGHT NOTICE
  26. * Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
  27. * ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
  28. * the full copyright text.
  29. */
  30. /*
  31. * HISTORY
  32. */
  33. #ifdef REV_INFO
  34. #ifndef lint
  35. static char rcsid[] = "$XConsortium: wmlresolve.c /main/9 1995/08/29 11:11:05 drk $"
  36. #endif
  37. #endif
  38. /*
  39. * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
  40. /*
  41. * This module contains all routines which perform semantic analysis of
  42. * the parsed WML specification. It is responsible for building all
  43. * ordered structures which can be directly translated into literal
  44. * code values for the various .h files. It is responsible for performing
  45. * inheritance of resources for all classes.
  46. *
  47. * Input:
  48. * the ordered list of syntactic objects in wml_synobj_ptr
  49. *
  50. * Output:
  51. *
  52. */
  53. #include "wml.h"
  54. #if defined(__STDC__)
  55. #include <stdlib.h>
  56. #endif
  57. #include <stdio.h>
  58. /*
  59. * Routines used only in this module
  60. */
  61. void wmlResolveGenerateSymK ();
  62. void wmlResolveValidateClass ();
  63. void wmlResolvePrintReport ();
  64. void wmlResolveSymKDataType ();
  65. void wmlResolveSymKChild ();
  66. void wmlResolveSymKEnumVal ();
  67. void wmlResolveSymKEnumSet ();
  68. void wmlResolveSymKReason ();
  69. void wmlResolveSymKArgument ();
  70. void wmlResolveSymKRelated ();
  71. void wmlResolveSymKClass ();
  72. void wmlResolveSymKCtrlList ();
  73. void wmlResolveSymKCharSet ();
  74. void wmlResolveClassInherit ();
  75. void wmlResolveClearRefPointers ();
  76. void wmlResolveInitRefObj ();
  77. void wmlResolveInitChildRefObj ();
  78. void wmlResolvePrintClass ();
  79. void wmlResolvePrintClassArgs ();
  80. void wmlResolvePrintClassReasons ();
  81. ObjectPtr wmlResolveFindObject ();
  82. void wmlIssueReferenceError ();
  83. void wmlIssueIllegalReferenceError ();
  84. void wmlIssueError ();
  85. /*
  86. * The control routine for semantic analysis. It calls the various phases.
  87. */
  88. void wmlResolveDescriptors ()
  89. {
  90. /*
  91. * Perform the code assignment pass. This results in assignment of sym_k_...
  92. * codes to all entities. Also, all objects and cross-linking are validated.
  93. */
  94. wmlResolveGenerateSymK ();
  95. printf ("\nInitial validation and reference resolution complete");
  96. /*
  97. * Perform class inheritance and validation
  98. */
  99. wmlResolveValidateClass ();
  100. printf ("\nClass validation and inheritance complete");
  101. /*
  102. * Print a report
  103. */
  104. if ( wml_err_count > 0 ) return;
  105. wmlResolvePrintReport ();
  106. }
  107. /*
  108. * Routine to linearize and assign sym_k... literals for objects. Simply
  109. * a dispatching routine.
  110. */
  111. void wmlResolveGenerateSymK ()
  112. {
  113. /*
  114. * Process the datatype objects
  115. */
  116. wmlResolveSymKDataType ();
  117. /*
  118. * Process the enumeration value and enumeration sets
  119. */
  120. wmlResolveSymKEnumVal ();
  121. wmlResolveSymKEnumSet ();
  122. /*
  123. * Process the resources, producing argument and reason vectors.
  124. */
  125. wmlResolveSymKReason ();
  126. wmlResolveSymKArgument ();
  127. /*
  128. * Bind related arguments
  129. */
  130. wmlResolveSymKRelated ();
  131. /*
  132. * Process the class definitions
  133. */
  134. wmlResolveSymKClass ();
  135. /*
  136. * Process the controls list definitions
  137. */
  138. wmlResolveSymKCtrlList ();
  139. /*
  140. * Process the charset objects
  141. */
  142. wmlResolveSymKCharSet ();
  143. /* Process the child definitions. */
  144. wmlResolveSymKChild();
  145. }
  146. /*
  147. * Routine to linearize data types
  148. *
  149. * - Generate the wml_obj_datatype... vector of resolved data type objects,
  150. * ordered lexicographically.
  151. * Do name processing, and acquire links to any other objects named in
  152. * the syntactic descriptor.
  153. */
  154. void wmlResolveSymKDataType ()
  155. {
  156. WmlSynDataTypeDefPtr cursyn; /* current syntactic object */
  157. WmlDataTypeDefPtr newobj; /* new resolved object */
  158. int ndx; /* loop index */
  159. /*
  160. * Initialize the object vector. Then process the syntactic vector,
  161. * processing each datatype object encountered (the vector is ordered).
  162. * create and append a resolved object for each one encountered. This
  163. * will be ordered as well.
  164. */
  165. wmlInitHList (wml_obj_datatype_ptr, 50, TRUE);
  166. for ( ndx=0 ; ndx<wml_synobj_ptr->cnt ; ndx++ )
  167. {
  168. cursyn = (WmlSynDataTypeDefPtr) wml_synobj_ptr->hvec[ndx].objptr;
  169. if ( cursyn->validation != WmlDataTypeDefValid ) continue;
  170. /*
  171. * Create and initialize new object. Append to resolved object vector.
  172. */
  173. newobj = (WmlDataTypeDefPtr) malloc (sizeof(WmlDataTypeDef));
  174. newobj->syndef = cursyn;
  175. cursyn->rslvdef = newobj;
  176. if ( cursyn->int_lit != NULL )
  177. newobj->tkname = cursyn->int_lit;
  178. else
  179. newobj->tkname = cursyn->name;
  180. wmlInsertInHList (wml_obj_datatype_ptr, newobj->tkname, (ObjectPtr)newobj);
  181. /*
  182. * Validate any object references in the syntactic object
  183. */
  184. }
  185. }
  186. /*
  187. * Routine to linearize children
  188. *
  189. * - Generate the wml_obj_child... vector of resolved child objects,
  190. * ordered lexicographically. Assign sym_k_... values while doing so.
  191. * Link child to its class.
  192. */
  193. void wmlResolveSymKChild ()
  194. {
  195. WmlSynChildDefPtr cursyn; /* current syntactic object */
  196. WmlChildDefPtr newobj; /* new resolved object */
  197. int code; /* assigned sym_k code value */
  198. int ndx; /* loop index */
  199. /*
  200. * Initialize the object vector. Then process the syntactic vector,
  201. * processing each child object encountered (the vector is ordered).
  202. * create and append a resolved object for each one encountered. This
  203. * will be ordered as well.
  204. */
  205. wmlInitHList (wml_obj_child_ptr, 50, TRUE);
  206. for ( ndx=0 ; ndx<wml_synobj_ptr->cnt ; ndx++ )
  207. {
  208. cursyn = (WmlSynChildDefPtr) wml_synobj_ptr->hvec[ndx].objptr;
  209. if ( cursyn->validation != WmlChildDefValid ) continue;
  210. /*
  211. * Create and initialize new object. Append to resolved object vector.
  212. */
  213. newobj = (WmlChildDefPtr) malloc (sizeof(WmlChildDef));
  214. newobj->syndef = cursyn;
  215. cursyn->rslvdef = newobj;
  216. newobj->tkname = cursyn->name;
  217. wmlInsertInHList (wml_obj_child_ptr, newobj->tkname, (ObjectPtr)newobj);
  218. /* Link class to the resolved object. */
  219. if (cursyn->class != NULL)
  220. newobj->class = (WmlClassDefPtr)
  221. wmlResolveFindObject(cursyn->class, WmlClassDefValid, cursyn->name);
  222. }
  223. /*
  224. * All objects are in the vector. The order is the code order, so
  225. * process it again and assign codes to each object
  226. */
  227. code = 1;
  228. for ( ndx=0 ; ndx<wml_obj_child_ptr->cnt ; ndx++ )
  229. {
  230. newobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr;
  231. newobj->sym_code = code;
  232. code += 1;
  233. }
  234. }
  235. /*
  236. * Routine to linearize and assign sym_k values to enumeration values
  237. *
  238. * - Generate the wml_obj_datatype... vector of resolved data type objects,
  239. * ordered lexicographically. No sym_k_... values are needed for
  240. * enumeration values, so don't assign any.
  241. */
  242. void wmlResolveSymKEnumVal ()
  243. {
  244. WmlSynEnumSetDefPtr cures; /* current enumeration set */
  245. WmlSynEnumSetValDefPtr curesv; /* current enum set value */
  246. WmlSynEnumValueDefPtr cursyn; /* current syntactic object */
  247. WmlEnumValueDefPtr newobj; /* new resolved object */
  248. int ndx; /* loop index */
  249. int code; /* sym_k_... code */
  250. /*
  251. * Perform defaulting. Process all the enumeration sets, and define a
  252. * syntactic object for every enumeration value named in an enumeration set
  253. * which has no syntactic entry. If there is an error in a name, then
  254. * this error won't be detected until we attempt to compile the output .h files.
  255. */
  256. for ( ndx=0 ; ndx<wml_synobj_ptr->cnt ; ndx++ )
  257. {
  258. cures = (WmlSynEnumSetDefPtr) wml_synobj_ptr->hvec[ndx].objptr;
  259. if ( cures->validation != WmlEnumSetDefValid ) continue;
  260. for (curesv=cures->values ; curesv!=NULL ; curesv=curesv->next)
  261. if ( wmlFindInHList(wml_synobj_ptr,curesv->name) < 0 )
  262. wmlCreateEnumValue (curesv->name);
  263. }
  264. /*
  265. * Initialize the object vector. Then process the syntactic vector,
  266. * processing each enumeration value object encountered (the vector is ordered).
  267. * create and append a resolved object for each one encountered. This
  268. * will be ordered as well.
  269. */
  270. wmlInitHList (wml_obj_enumval_ptr, 50, TRUE);
  271. for ( ndx=0 ; ndx<wml_synobj_ptr->cnt ; ndx++ )
  272. {
  273. cursyn = (WmlSynEnumValueDefPtr) wml_synobj_ptr->hvec[ndx].objptr;
  274. if ( cursyn->validation != WmlEnumValueDefValid ) continue;
  275. /*
  276. * Create and initialize new object. Append to resolved object vector.
  277. */
  278. newobj = (WmlEnumValueDefPtr) malloc (sizeof(WmlEnumValueDef));
  279. newobj->syndef = cursyn;
  280. cursyn->rslvdef = newobj;
  281. wmlInsertInHList (wml_obj_enumval_ptr, cursyn->name, (ObjectPtr)newobj);
  282. }
  283. /*
  284. * All objects are in the vector. That order is the code order, so
  285. * process it again and assign codes to each object
  286. */
  287. code = 1;
  288. for ( ndx=0 ; ndx<wml_obj_enumval_ptr->cnt ; ndx++ )
  289. {
  290. newobj = (WmlEnumValueDefPtr) wml_obj_enumval_ptr->hvec[ndx].objptr;
  291. newobj->sym_code = code;
  292. code += 1;
  293. }
  294. }
  295. /*
  296. * Routine to linearize and assign sym_k values to enumeration sets
  297. *
  298. * - Generate the wml_obj_datatype... vector of resolved data type objects,
  299. * ordered lexicographically. No sym_k_... values are needed for
  300. * enumeration values, so don't assign any.
  301. */
  302. void wmlResolveSymKEnumSet ()
  303. {
  304. WmlSynEnumSetDefPtr cursyn; /* current syntactic object */
  305. WmlEnumSetDefPtr newobj; /* new resolved object */
  306. int ndx; /* loop index */
  307. int code; /* sym_k_... code */
  308. WmlSynEnumSetValDefPtr esvelm; /* current syntactic list element */
  309. WmlEnumValueDefPtr evobj; /* current enumeration value */
  310. WmlEnumSetValDefPtr esvobj; /* current list element */
  311. /*
  312. * Initialize the object vector. Then process the syntactic vector,
  313. * processing each enumeration set object encountered (the vector is ordered).
  314. * create and append a resolved object for each one encountered. This
  315. * will be ordered as well.
  316. */
  317. wmlInitHList (wml_obj_enumset_ptr, 20, TRUE);
  318. for ( ndx=0 ; ndx<wml_synobj_ptr->cnt ; ndx++ )
  319. {
  320. cursyn = (WmlSynEnumSetDefPtr) wml_synobj_ptr->hvec[ndx].objptr;
  321. if ( cursyn->validation != WmlEnumSetDefValid ) continue;
  322. /*
  323. * Create and initialize new object. Append to resolved object vector.
  324. */
  325. newobj = (WmlEnumSetDefPtr) malloc (sizeof(WmlEnumSetDef));
  326. newobj->syndef = cursyn;
  327. cursyn->rslvdef = newobj;
  328. newobj->tkname = cursyn->name;
  329. newobj->dtype_def = (WmlDataTypeDefPtr)
  330. wmlResolveFindObject (cursyn->datatype,
  331. WmlDataTypeDefValid,
  332. cursyn->name);
  333. wmlInsertInHList (wml_obj_enumset_ptr, newobj->tkname, (ObjectPtr)newobj);
  334. }
  335. /*
  336. * All objects are in the vector. That order is the code order, so
  337. * process it again and assign codes to each object. Simultaneously construct
  338. * a vector of resolved enumeration values, and count them.
  339. */
  340. code = 1;
  341. for ( ndx=0 ; ndx<wml_obj_enumset_ptr->cnt ; ndx++ )
  342. {
  343. newobj = (WmlEnumSetDefPtr) wml_obj_enumset_ptr->hvec[ndx].objptr;
  344. newobj->sym_code = code;
  345. code += 1;
  346. /*
  347. * Validate and construct a resolved enumeration value list
  348. */
  349. cursyn = newobj->syndef;
  350. newobj->values_cnt = 0;
  351. newobj->values = NULL;
  352. for ( esvelm=cursyn->values ; esvelm!=NULL ; esvelm=esvelm->next )
  353. {
  354. evobj = (WmlEnumValueDefPtr)
  355. wmlResolveFindObject (esvelm->name,
  356. WmlEnumValueDefValid,
  357. cursyn->name);
  358. if ( evobj == NULL ) continue;
  359. esvobj = (WmlEnumSetValDefPtr) malloc (sizeof(WmlEnumSetValDef));
  360. esvobj->value = evobj;
  361. esvobj->next = newobj->values;
  362. newobj->values = esvobj;
  363. newobj->values_cnt += 1;
  364. }
  365. }
  366. }
  367. /*
  368. * Routine to linearize and assign sym_k values to reasons.
  369. *
  370. * - Generate the wml_obj_reason... vector of resolved reason objects,
  371. * ordered lexicographically. Assign a sym_k_... value as this is done.
  372. * Do name processing, and acquire links to any other objects named in
  373. * the syntactic descriptor.
  374. */
  375. void wmlResolveSymKReason ()
  376. {
  377. WmlSynResourceDefPtr cursyn; /* current syntactic object */
  378. WmlResourceDefPtr newobj; /* new resolved object */
  379. int ndx; /* loop index */
  380. int code; /* assigned sym_k code value */
  381. char errmsg[300];
  382. /*
  383. * Initialize the object vector. Then process the syntactic vector,
  384. * processing each reason resource object encountered (the vector is ordered).
  385. * create and append a resolved object for each one encountered. This
  386. * will be ordered as well.
  387. */
  388. wmlInitHList (wml_obj_reason_ptr, 100, TRUE);
  389. for ( ndx=0 ; ndx<wml_synobj_ptr->cnt ; ndx++ )
  390. {
  391. cursyn = (WmlSynResourceDefPtr) wml_synobj_ptr->hvec[ndx].objptr;
  392. if ( cursyn->validation != WmlResourceDefValid ) continue;
  393. if ( cursyn->type != WmlResourceTypeReason ) continue;
  394. newobj = (WmlResourceDefPtr) malloc (sizeof(WmlResourceDef));
  395. /*
  396. * Create and initialize new object. Append to resolved object vector.
  397. */
  398. newobj->syndef = cursyn;
  399. cursyn->rslvdef = newobj;
  400. if ( cursyn->int_lit != NULL )
  401. newobj->tkname = cursyn->int_lit;
  402. else
  403. newobj->tkname = cursyn->name;
  404. newobj->dtype_def = NULL;
  405. newobj->enumset_def = NULL;
  406. newobj->related_code = 0;
  407. wmlInsertInHList (wml_obj_reason_ptr, newobj->tkname, (ObjectPtr)newobj);
  408. /*
  409. * Validate any object references in the syntactic object
  410. * Reason can't bind to some objects.
  411. */
  412. if ( cursyn->datatype != NULL )
  413. wmlIssueIllegalReferenceError (cursyn->name, "DataType");
  414. }
  415. /*
  416. * All objects are in the vector. That order is the code order, so
  417. * process it again and assign codes to each object
  418. */
  419. code = 1;
  420. for ( ndx=0 ; ndx<wml_obj_reason_ptr->cnt ; ndx++ )
  421. {
  422. newobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr;
  423. newobj->sym_code = code;
  424. code += 1;
  425. }
  426. }
  427. /*
  428. * Routine to linearize and assign sym_k values to arguments.
  429. *
  430. * - Generate the wml_obj_arg... vector of resovled reason objects,
  431. * ordered lexicographically. Assign a sym_k_... values while doing so.
  432. * validate the data type for each argument, and link it to its data type
  433. * object.
  434. * Do name processing, and acquire links to any other objects named in
  435. * the syntactic descriptor.
  436. */
  437. void wmlResolveSymKArgument ()
  438. {
  439. WmlSynResourceDefPtr cursyn; /* current syntactic object */
  440. WmlResourceDefPtr newobj; /* new resolved object */
  441. int ndx; /* loop index */
  442. int code; /* assigned sym_k code value */
  443. char errmsg[300];
  444. /*
  445. * Initialize the object vector. Then process the syntactic vector,
  446. * processing each reason resource object encountered (the vector is ordered).
  447. * create and append a resolved object for each one encountered. This
  448. * will be ordered as well.
  449. */
  450. wmlInitHList (wml_obj_arg_ptr, 500, TRUE);
  451. for ( ndx=0 ; ndx<wml_synobj_ptr->cnt ; ndx++ )
  452. {
  453. cursyn = (WmlSynResourceDefPtr) wml_synobj_ptr->hvec[ndx].objptr;
  454. if ( cursyn->validation != WmlResourceDefValid ) continue;
  455. if ( cursyn->type == WmlResourceTypeReason ) continue;
  456. newobj = (WmlResourceDefPtr) malloc (sizeof(WmlResourceDef));
  457. /*
  458. * Create and initialize new object. Append to resolved object vector.
  459. */
  460. newobj->syndef = cursyn;
  461. cursyn->rslvdef = newobj;
  462. if ( cursyn->int_lit != NULL )
  463. newobj->tkname = cursyn->int_lit;
  464. else
  465. newobj->tkname = cursyn->name;
  466. newobj->related_code = 0;
  467. newobj->enumset_def = NULL;
  468. wmlInsertInHList (wml_obj_arg_ptr, newobj->tkname, (ObjectPtr)newobj);
  469. /*
  470. * Validate any object references in the syntactic object
  471. */
  472. newobj->dtype_def = (WmlDataTypeDefPtr)
  473. wmlResolveFindObject (cursyn->datatype,
  474. WmlDataTypeDefValid,
  475. cursyn->name);
  476. if ( cursyn->enumset != NULL )
  477. newobj->enumset_def = (WmlEnumSetDefPtr)
  478. wmlResolveFindObject (cursyn->enumset,
  479. WmlEnumSetDefValid,
  480. cursyn->name);
  481. }
  482. /*
  483. * All objects are in the vector. The order is the code order, so
  484. * process it again and assign codes to each object
  485. */
  486. code = 1;
  487. for ( ndx=0 ; ndx<wml_obj_arg_ptr->cnt ; ndx++ )
  488. {
  489. newobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr;
  490. newobj->sym_code = code;
  491. code += 1;
  492. }
  493. }
  494. /*
  495. * Routine to resolve related argument references.
  496. *
  497. * Search the argument vector for any argument with its related
  498. * argument set. Find the related argument, and bind the relation.
  499. * The binding only goes one way.
  500. */
  501. void wmlResolveSymKRelated ()
  502. {
  503. WmlResourceDefPtr srcobj; /* object with related reference */
  504. WmlResourceDefPtr dstobj; /* other object in binding */
  505. WmlSynResourceDefPtr srcsynobj; /* source syntactic object */
  506. int ndx; /* loop index */
  507. /*
  508. * Scan all arguments for related argument bindings.
  509. */
  510. for ( ndx=0 ; ndx<wml_obj_arg_ptr->cnt ; ndx++ )
  511. {
  512. srcobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr;
  513. srcsynobj = srcobj->syndef;
  514. if ( srcsynobj->related != NULL )
  515. {
  516. dstobj = (WmlResourceDefPtr)
  517. wmlResolveFindObject (srcsynobj->related,
  518. WmlResourceDefValid,
  519. srcsynobj->name);
  520. if ( dstobj != NULL )
  521. srcobj->related_code = dstobj->sym_code;
  522. }
  523. }
  524. }
  525. /*
  526. * Routine to linearize and assign sym_k values to classes
  527. *
  528. * There are two linearizations of classes:
  529. * - all classes in wml_obj_allclass...
  530. * - all widgets and gadgets in wml_obj_class...
  531. * Create and linearize all class objects into these vectors. Assign sym_k
  532. * codes. Link all subclasses to their superclasses. Perform name processing
  533. * and link to any other named object.
  534. *
  535. * Resources are not inherited and linked at this time.
  536. */
  537. void wmlResolveSymKClass ()
  538. {
  539. WmlSynClassDefPtr cursyn; /* current syntactic object */
  540. WmlClassDefPtr newobj; /* new resolved object */
  541. int ndx; /* loop index */
  542. int code; /* assigned sym_k code value */
  543. char errmsg[300];
  544. /*
  545. * Initialize the object vectors. Then process the syntactic vector,
  546. * processing each class object encountered (the vector is ordered).
  547. * create and append a resolved object for each one encountered. This
  548. * will be ordered as well.
  549. */
  550. wmlInitHList (wml_obj_allclass_ptr, 200, TRUE);
  551. wmlInitHList (wml_obj_class_ptr, 200, TRUE);
  552. for ( ndx=0 ; ndx<wml_synobj_ptr->cnt ; ndx++ )
  553. {
  554. cursyn = (WmlSynClassDefPtr) wml_synobj_ptr->hvec[ndx].objptr;
  555. if ( cursyn->validation != WmlClassDefValid ) continue;
  556. /*
  557. * Create and initialize new object. Append to resolved object vector.
  558. */
  559. newobj = (WmlClassDefPtr) malloc (sizeof(WmlClassDef));
  560. newobj->syndef = cursyn;
  561. cursyn->rslvdef = newobj;
  562. newobj->superclass = NULL;
  563. newobj->parentclass = NULL;
  564. if ( cursyn->int_lit != NULL )
  565. newobj->tkname = cursyn->int_lit;
  566. else
  567. newobj->tkname = cursyn->name;
  568. newobj->inherit_done = FALSE;
  569. newobj->arguments = NULL;
  570. newobj->reasons = NULL;
  571. newobj->controls = NULL;
  572. newobj->children = NULL;
  573. newobj->variant = NULL;
  574. newobj->nondialog = NULL;
  575. newobj->ctrlmapto = NULL;
  576. switch ( cursyn->type )
  577. {
  578. case WmlClassTypeMetaclass:
  579. wmlInsertInHList
  580. (wml_obj_allclass_ptr, newobj->tkname, (ObjectPtr)newobj);
  581. break;
  582. case WmlClassTypeGadget:
  583. case WmlClassTypeWidget:
  584. wmlInsertInHList
  585. (wml_obj_allclass_ptr, newobj->tkname, (ObjectPtr)newobj);
  586. wmlInsertInHList
  587. (wml_obj_class_ptr, newobj->tkname, (ObjectPtr)newobj);
  588. break;
  589. }
  590. /*
  591. * Require a convenience function name
  592. */
  593. if ( cursyn->type != WmlClassTypeMetaclass )
  594. if ( cursyn->convfunc == NULL )
  595. {
  596. sprintf (errmsg, "Class %s does not have a convenience function",
  597. cursyn->name);
  598. wmlIssueError (errmsg);
  599. }
  600. /*
  601. * Validate any object references in the syntactic object
  602. */
  603. if ( cursyn->ctrlmapto != NULL )
  604. newobj->ctrlmapto = (WmlResourceDefPtr)
  605. wmlResolveFindObject (cursyn->ctrlmapto,
  606. WmlResourceDefValid,
  607. cursyn->name);
  608. }
  609. /*
  610. * All objects are in the vector. That order is the code order, so
  611. * process it again and assign codes to each object
  612. */
  613. code = 1;
  614. for ( ndx=0 ; ndx<wml_obj_class_ptr->cnt ; ndx++ )
  615. {
  616. newobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr;
  617. newobj->sym_code = code;
  618. code += 1;
  619. }
  620. }
  621. /*
  622. * Routine to validate controls lists
  623. *
  624. * Construct and linearize resolved controls lists. The linearized list
  625. * is used to resolve references.
  626. */
  627. void wmlResolveSymKCtrlList ()
  628. {
  629. WmlSynCtrlListDefPtr cursyn; /* current syntactic object */
  630. WmlCtrlListDefPtr newobj; /* new resolved object */
  631. WmlSynClassCtrlDefPtr refptr; /* current controls reference */
  632. WmlClassCtrlDefPtr ctrlobj; /* resolved control reference */
  633. WmlClassDefPtr classobj; /* the controlled class */
  634. int ndx; /* loop index */
  635. /*
  636. * Process each control list. Construct a resolved control list for each
  637. */
  638. wmlInitHList (wml_obj_ctrlist_ptr, 20, TRUE);
  639. for ( ndx=0 ; ndx<wml_synobj_ptr->cnt ; ndx++ )
  640. {
  641. cursyn = (WmlSynCtrlListDefPtr) wml_synobj_ptr->hvec[ndx].objptr;
  642. if ( cursyn->validation != WmlCtrlListDefValid ) continue;
  643. /*
  644. * Create and initialize new object. Append to resolved object vector.
  645. */
  646. newobj = (WmlCtrlListDefPtr) malloc (sizeof(WmlCtrlListDef));
  647. newobj->syndef = cursyn;
  648. cursyn->rslvdef = newobj;
  649. newobj->controls = NULL;
  650. wmlInsertInHList (wml_obj_ctrlist_ptr, cursyn->name, (ObjectPtr)newobj);
  651. /*
  652. * Validate and construct a resolved controls reference list.
  653. */
  654. for ( refptr=cursyn->controls ; refptr!=NULL ; refptr=refptr->next )
  655. {
  656. classobj = (WmlClassDefPtr)
  657. wmlResolveFindObject (refptr->name,
  658. WmlClassDefValid,
  659. cursyn->name);
  660. if ( classobj == NULL ) continue;
  661. ctrlobj = (WmlClassCtrlDefPtr) malloc (sizeof(WmlClassCtrlDef));
  662. ctrlobj->next = newobj->controls;
  663. newobj->controls = ctrlobj;
  664. ctrlobj->ctrl = classobj;
  665. }
  666. }
  667. }
  668. /*
  669. * Routine to linearize and assign sym_k values to character sets
  670. *
  671. * - Generate the wml_obj_charset... vector of resolved data type objects,
  672. * ordered lexicographically. Assign a sym_k... value as this is done.
  673. * Do name processing, and acquire links to any other objects named in
  674. * the syntactic descriptor.
  675. */
  676. void wmlResolveSymKCharSet ()
  677. {
  678. WmlSynCharSetDefPtr cursyn; /* current syntactic object */
  679. WmlCharSetDefPtr newobj; /* new resolved object */
  680. int ndx; /* loop index */
  681. int code; /* assigned sym_k code value */
  682. char errmsg[300];
  683. /*
  684. * Initialize the object vector. Then process the syntactic vector,
  685. * processing each charset object encountered (the vector is ordered).
  686. * create and append a resolved object for each one encountered. This
  687. * will be ordered as well.
  688. */
  689. wmlInitHList (wml_obj_charset_ptr, 50, TRUE);
  690. for ( ndx=0 ; ndx<wml_synobj_ptr->cnt ; ndx++ )
  691. {
  692. cursyn = (WmlSynCharSetDefPtr) wml_synobj_ptr->hvec[ndx].objptr;
  693. if ( cursyn->validation != WmlCharSetDefValid ) continue;
  694. /*
  695. * Create and initialize new object. Append to resolved object vector.
  696. */
  697. newobj = (WmlCharSetDefPtr) malloc (sizeof(WmlCharSetDef));
  698. newobj->syndef = cursyn;
  699. cursyn->rslvdef = newobj;
  700. if ( cursyn->int_lit != NULL )
  701. newobj->tkname = cursyn->int_lit;
  702. else
  703. newobj->tkname = cursyn->name;
  704. wmlInsertInHList (wml_obj_charset_ptr, newobj->tkname, (ObjectPtr)newobj);
  705. /*
  706. * Parsing direction defaults to writing direction if unspecified
  707. */
  708. if ( cursyn->parsedirection == WmlAttributeUnspecified )
  709. cursyn->parsedirection = cursyn->direction;
  710. /*
  711. * Require StandardsName attribute for character set
  712. */
  713. if ( cursyn->xms_name == NULL )
  714. {
  715. sprintf (errmsg, "CharacterSet %s does not have a StandardsName",
  716. cursyn->name);
  717. wmlIssueError (errmsg);
  718. }
  719. }
  720. /*
  721. * All objects are in the vector. That order is the code order, so
  722. * process it again and assign codes to each object. We start at code
  723. * 2 since 1 is reserved for sym_k_userdefined_charset
  724. */
  725. code = 2;
  726. for ( ndx=0 ; ndx<wml_obj_charset_ptr->cnt ; ndx++ )
  727. {
  728. newobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr;
  729. newobj->sym_code = code;
  730. code += 1;
  731. }
  732. }
  733. /*
  734. * Routine to perform class inheritance and validation.
  735. *
  736. * This routine has two major phases:
  737. * - Complete resolution of class references, and expand out
  738. * controls list.
  739. * - Perform inheritance of resources, partitioning them into
  740. * into arguments and reasons. When complete, the class has
  741. * a list of all its resources, including copies from a
  742. * superclass and possibly a parentclass.
  743. * Excluded resources remain in the list, and are simply marked.
  744. */
  745. void wmlResolveValidateClass ()
  746. {
  747. int ndx; /* loop index */
  748. int max; /* maximum code value */
  749. WmlClassDefPtr clsobj; /* current class object */
  750. WmlSynClassDefPtr synobj; /* syntactic class object */
  751. WmlClassDefPtr superobj; /* superclass */
  752. WmlClassDefPtr parentobj; /* parentclass */
  753. WmlClassDefPtr widgobj; /* gadget's widget class */
  754. WmlSynClassCtrlDefPtr refptr; /* current controls reference */
  755. WmlClassCtrlDefPtr ctrlobj; /* resolved control reference */
  756. int refndx; /* index in vector */
  757. WmlClassDefPtr refcls; /* referenced class object */
  758. WmlCtrlListDefPtr reflist; /* controls list object */
  759. WmlClassCtrlDefPtr listelem; /* control reference in list */
  760. char errmsg[300];
  761. /*
  762. * Acquire the superclass pointer for each widget and gadget class
  763. */
  764. for ( ndx=0 ; ndx<wml_obj_allclass_ptr->cnt ; ndx++ )
  765. {
  766. clsobj = (WmlClassDefPtr) wml_obj_allclass_ptr->hvec[ndx].objptr;
  767. synobj = clsobj->syndef;
  768. if ( synobj->superclass != NULL )
  769. {
  770. superobj = (WmlClassDefPtr)
  771. wmlResolveFindObject (synobj->superclass,
  772. WmlClassDefValid,
  773. synobj->name);
  774. if ( superobj == NULL ) continue;
  775. clsobj->superclass = superobj;
  776. }
  777. }
  778. /*
  779. * Acquire the parentclass pointer (if one exists),
  780. * for each widget and gadget class
  781. */
  782. for ( ndx=0 ; ndx<wml_obj_allclass_ptr->cnt ; ndx++ )
  783. {
  784. clsobj = (WmlClassDefPtr) wml_obj_allclass_ptr->hvec[ndx].objptr;
  785. synobj = clsobj->syndef;
  786. if ( synobj->parentclass != NULL )
  787. {
  788. parentobj = (WmlClassDefPtr)
  789. wmlResolveFindObject (synobj->parentclass,
  790. WmlClassDefValid,
  791. synobj->name);
  792. if ( parentobj == NULL ) continue;
  793. clsobj->parentclass = parentobj;
  794. }
  795. }
  796. /*
  797. * Link each gadget class with its widget class (both ways).
  798. * Link any class with a non-dialog version to the non-dialog class.
  799. */
  800. for ( ndx=0 ; ndx<wml_obj_class_ptr->cnt ; ndx++ )
  801. {
  802. clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr;
  803. synobj = clsobj->syndef;
  804. if ( synobj->type == WmlClassTypeGadget )
  805. {
  806. if ( synobj->widgetclass == NULL )
  807. {
  808. sprintf (errmsg, "Gadget class %s has no widgetclass reference",
  809. synobj->name);
  810. wmlIssueError (errmsg);
  811. }
  812. else
  813. {
  814. widgobj = (WmlClassDefPtr)
  815. wmlResolveFindObject
  816. (synobj->widgetclass,
  817. WmlClassDefValid,
  818. synobj->name);
  819. if ( widgobj != NULL )
  820. {
  821. clsobj->variant = widgobj;
  822. widgobj->variant = clsobj;
  823. }
  824. }
  825. }
  826. if ( synobj->dialog == TRUE )
  827. {
  828. clsobj->nondialog = clsobj->superclass;
  829. while ( clsobj->nondialog->syndef->dialog == TRUE )
  830. clsobj->nondialog = clsobj->nondialog->superclass;
  831. }
  832. else
  833. if ( clsobj->superclass != NULL )
  834. {
  835. synobj->dialog = clsobj->superclass->syndef->dialog;
  836. clsobj->nondialog = clsobj->superclass->nondialog;
  837. }
  838. }
  839. /*
  840. * Construct the list of resolved controls. Control lists are expanded
  841. * in place.
  842. */
  843. for ( ndx=0 ; ndx<wml_obj_class_ptr->cnt ; ndx++ )
  844. {
  845. clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr;
  846. synobj = clsobj->syndef;
  847. for ( refptr=synobj->controls ; refptr!= NULL ; refptr=refptr->next )
  848. {
  849. refndx = wmlFindInHList (wml_obj_class_ptr, refptr->name);
  850. if ( refndx >= 0 )
  851. {
  852. refcls = (WmlClassDefPtr) wml_obj_class_ptr->hvec[refndx].objptr;
  853. ctrlobj = (WmlClassCtrlDefPtr) malloc (sizeof(WmlClassCtrlDef));
  854. ctrlobj->next = clsobj->controls;
  855. clsobj->controls = ctrlobj;
  856. ctrlobj->ctrl = refcls;
  857. continue;
  858. }
  859. refndx = wmlFindInHList (wml_obj_ctrlist_ptr, refptr->name);
  860. if ( refndx >= 0 )
  861. {
  862. reflist = (WmlCtrlListDefPtr)
  863. wml_obj_ctrlist_ptr->hvec[refndx].objptr;
  864. for ( listelem=reflist->controls ;
  865. listelem!=NULL ;
  866. listelem=listelem->next)
  867. {
  868. ctrlobj = (WmlClassCtrlDefPtr)
  869. malloc (sizeof(WmlClassCtrlDef));
  870. ctrlobj->next = clsobj->controls;
  871. clsobj->controls = ctrlobj;
  872. ctrlobj->ctrl = listelem->ctrl;
  873. }
  874. continue;
  875. }
  876. wmlIssueReferenceError (synobj->name, refptr->name);
  877. continue;
  878. }
  879. }
  880. /*
  881. * Perform resource inheritance for each class. This constructs the
  882. * arguments and reasons reference vectors.
  883. */
  884. for ( ndx=0 ; ndx<wml_obj_allclass_ptr->cnt ; ndx++ )
  885. {
  886. clsobj = (WmlClassDefPtr) wml_obj_allclass_ptr->hvec[ndx].objptr;
  887. wmlResolveClassInherit (clsobj);
  888. }
  889. }
  890. /*
  891. * Routine to perform resource inheritance for a class.
  892. *
  893. * This routine constructs the argument and reason resource and child reference
  894. * vectors for a class. It first ensures the superclass (if any) has
  895. * been inited. It then makes a copy of the superclass lists. It repeats this
  896. * procedure for the parentclass (if any.) Finally, it
  897. * merges in the resources from the syntactic object. It uses the
  898. * resolved resource or child object to point to the matching reference object
  899. * in the list being created as an aid to search doing overrides. This also
  900. * detects whether a resource or child is already in the list (if so, it is
  901. * assumed to be inherited).
  902. */
  903. void wmlResolveClassInherit (clsobj)
  904. WmlClassDefPtr clsobj;
  905. {
  906. WmlClassDefPtr superobj; /* superclass object */
  907. WmlClassDefPtr parentobj; /* parentclass object */
  908. int ndx; /* loop index */
  909. WmlResourceDefPtr resobj; /* current resource object */
  910. WmlClassResDefPtr refobj; /* current resource reference */
  911. WmlClassResDefPtr srcref; /* source of copy */
  912. WmlChildDefPtr childobj; /* current child object */
  913. WmlClassChildDefPtr crefobj; /* current child reference */
  914. WmlClassChildDefPtr csrcref; /* child source of copy */
  915. WmlSynClassDefPtr synobj; /* this class' syntactic object */
  916. WmlSynClassResDefPtr refptr; /* syntactic resource reference */
  917. WmlSynClassChildDefPtr crefptr; /* syntactic child reference */
  918. /*
  919. * Done if inheritance previously performed. Ensure the superclass is
  920. * done.
  921. */
  922. if ( clsobj == NULL ) return;
  923. if ( clsobj->inherit_done ) return;
  924. superobj = clsobj->superclass;
  925. wmlResolveClassInherit (superobj);
  926. parentobj = clsobj->parentclass;
  927. wmlResolveClassInherit (parentobj);
  928. synobj = clsobj->syndef;
  929. /*
  930. * Clear the active reference pointer in the resolved resource objects.
  931. */
  932. wmlResolveClearRefPointers ();
  933. /*
  934. * Copy the superclass resources, setting the reference pointer as we go.
  935. */
  936. if ( superobj != NULL )
  937. {
  938. for ( srcref=superobj->arguments ; srcref!=NULL ; srcref=srcref->next )
  939. {
  940. refobj = (WmlClassResDefPtr) malloc (sizeof(WmlClassResDef));
  941. refobj->next = clsobj->arguments;
  942. clsobj->arguments = refobj;
  943. wmlResolveInitRefObj (refobj, srcref);
  944. }
  945. for ( srcref=superobj->reasons ; srcref!=NULL ; srcref=srcref->next )
  946. {
  947. refobj = (WmlClassResDefPtr) malloc (sizeof(WmlClassResDef));
  948. refobj->next = clsobj->reasons;
  949. clsobj->reasons = refobj;
  950. wmlResolveInitRefObj (refobj, srcref);
  951. }
  952. for (csrcref = superobj->children ; csrcref!=NULL ; csrcref=csrcref->next)
  953. {
  954. crefobj = (WmlClassChildDefPtr) malloc (sizeof(WmlClassChildDef));
  955. crefobj->next = clsobj->children;
  956. clsobj->children = crefobj;
  957. wmlResolveInitChildRefObj (crefobj, csrcref);
  958. }
  959. }
  960. /*
  961. * Copy the parentclass resources, setting the reference pointer as we go.
  962. */
  963. if ( parentobj != NULL )
  964. {
  965. for ( srcref=parentobj->arguments ; srcref!=NULL ; srcref=srcref->next )
  966. {
  967. if (srcref->act_resource->ref_ptr == NULL)
  968. {
  969. refobj = (WmlClassResDefPtr) malloc (sizeof(WmlClassResDef));
  970. refobj->next = clsobj->arguments;
  971. clsobj->arguments = refobj;
  972. wmlResolveInitRefObj (refobj, srcref);
  973. }
  974. }
  975. for ( srcref=parentobj->reasons ; srcref!=NULL ; srcref=srcref->next )
  976. {
  977. if (srcref->act_resource->ref_ptr == NULL)
  978. {
  979. refobj = (WmlClassResDefPtr) malloc (sizeof(WmlClassResDef));
  980. refobj->next = clsobj->reasons;
  981. clsobj->reasons = refobj;
  982. wmlResolveInitRefObj (refobj, srcref);
  983. }
  984. }
  985. for (csrcref = parentobj->children ; csrcref!=NULL ; csrcref=csrcref->next)
  986. {
  987. if (csrcref->act_child->ref_ptr == NULL)
  988. {
  989. crefobj = (WmlClassChildDefPtr) malloc (sizeof(WmlClassChildDef));
  990. crefobj->next = clsobj->children;
  991. clsobj->children = crefobj;
  992. wmlResolveInitChildRefObj (crefobj, csrcref);
  993. }
  994. }
  995. }
  996. /*
  997. * Process the resources belonging to this class. They may either be
  998. * new resources, or override ones already in the list. Partition them
  999. * into arguments and reasons.
  1000. */
  1001. for ( refptr=synobj->resources ; refptr!=NULL ; refptr=refptr->next )
  1002. {
  1003. resobj = (WmlResourceDefPtr) wmlResolveFindObject (refptr->name,
  1004. WmlResourceDefValid,
  1005. synobj->name);
  1006. if ( resobj == NULL ) continue;
  1007. /*
  1008. * Acquire the resolved resource object, and the resource reference.
  1009. * New references are linked in to the proper list, and have their
  1010. * defaults set.
  1011. */
  1012. if ( resobj->ref_ptr != NULL )
  1013. refobj = resobj->ref_ptr;
  1014. else
  1015. {
  1016. refobj = (WmlClassResDefPtr) malloc (sizeof(WmlClassResDef));
  1017. refobj->act_resource = resobj;
  1018. resobj->ref_ptr = refobj;
  1019. refobj->over_dtype = NULL;
  1020. refobj->dflt = NULL;
  1021. refobj->exclude = WmlAttributeUnspecified;
  1022. if ( resobj->syndef->type == WmlResourceTypeReason )
  1023. {
  1024. refobj->next = clsobj->reasons;
  1025. clsobj->reasons = refobj;
  1026. }
  1027. else
  1028. {
  1029. refobj->next = clsobj->arguments;
  1030. clsobj->arguments = refobj;
  1031. }
  1032. }
  1033. /*
  1034. * Override any values in the reference which are explicit in the
  1035. * syntactic reference.
  1036. */
  1037. if ( refptr->type != NULL )
  1038. refobj->over_dtype = (WmlDataTypeDefPtr)
  1039. wmlResolveFindObject (refptr->type,
  1040. WmlDataTypeDefValid,
  1041. synobj->name);
  1042. if ( refptr->dflt != NULL )
  1043. refobj->dflt = refptr->dflt;
  1044. if ( refptr->exclude != WmlAttributeUnspecified )
  1045. refobj->exclude = refptr->exclude;
  1046. }
  1047. /*
  1048. * Process the children belonging to this class.
  1049. */
  1050. for ( crefptr = synobj->children ; crefptr!=NULL ; crefptr = crefptr->next )
  1051. {
  1052. childobj = (WmlChildDefPtr) wmlResolveFindObject (crefptr->name,
  1053. WmlChildDefValid,
  1054. synobj->name);
  1055. if ( childobj == NULL ) continue;
  1056. /*
  1057. * Acquire the resolved child object, and the child reference.
  1058. * New references are linked in to the proper list, and have their
  1059. * defaults set.
  1060. */
  1061. if ( childobj->ref_ptr != NULL )
  1062. crefobj = childobj->ref_ptr;
  1063. else
  1064. {
  1065. crefobj = (WmlClassChildDefPtr) malloc (sizeof(WmlClassChildDef));
  1066. crefobj->act_child = childobj;
  1067. childobj->ref_ptr = crefobj;
  1068. crefobj->next = clsobj->children;
  1069. clsobj->children = crefobj;
  1070. }
  1071. }
  1072. /*
  1073. * inheritance complete
  1074. */
  1075. clsobj->inherit_done = TRUE;
  1076. }
  1077. /*
  1078. * Routine to copy a resource reference
  1079. */
  1080. void wmlResolveInitRefObj (dstobj, srcobj)
  1081. WmlClassResDefPtr dstobj;
  1082. WmlClassResDefPtr srcobj;
  1083. {
  1084. WmlResourceDefPtr resobj;
  1085. resobj = srcobj->act_resource;
  1086. dstobj->act_resource = resobj;
  1087. resobj->ref_ptr = dstobj;
  1088. dstobj->over_dtype = srcobj->over_dtype;
  1089. dstobj->dflt = srcobj->dflt;
  1090. dstobj->exclude = srcobj->exclude;
  1091. }
  1092. /*
  1093. * Routine to copy a child reference
  1094. */
  1095. void wmlResolveInitChildRefObj (dstobj, srcobj)
  1096. WmlClassChildDefPtr dstobj;
  1097. WmlClassChildDefPtr srcobj;
  1098. {
  1099. WmlChildDefPtr childobj;
  1100. childobj = srcobj->act_child;
  1101. dstobj->act_child = childobj;
  1102. childobj->ref_ptr = dstobj;
  1103. }
  1104. /*
  1105. * Routine to print a report in a file.
  1106. *
  1107. * This routine dumps the developed database into the file 'wml.report'
  1108. */
  1109. void wmlResolvePrintReport ()
  1110. {
  1111. FILE *outfil; /* output file */
  1112. int ndx; /* loop index */
  1113. WmlClassDefPtr clsobj; /* current class */
  1114. /*
  1115. * Open the output file.
  1116. */
  1117. outfil = fopen ( "wml.report", "w");
  1118. if ( outfil == NULL )
  1119. {
  1120. printf ("\nCouldn't open wml.report");
  1121. return;
  1122. }
  1123. /*
  1124. * Go through all classes. Print basic information, then dump their
  1125. * resources. The main purpose of this report is to show the actual
  1126. * resources and controls for the class.
  1127. */
  1128. for ( ndx=0 ; ndx<wml_obj_allclass_ptr->cnt ; ndx++ )
  1129. {
  1130. clsobj = (WmlClassDefPtr) wml_obj_allclass_ptr->hvec[ndx].objptr;
  1131. wmlMarkReferencePointers (clsobj);
  1132. wmlResolvePrintClass (outfil, clsobj);
  1133. }
  1134. /*
  1135. * close the output file
  1136. */
  1137. fprintf (outfil, "\n\n");
  1138. printf ("\nCreated report file wml.report");
  1139. fclose (outfil);
  1140. }
  1141. /*
  1142. * Print the information for a class
  1143. */
  1144. void wmlResolvePrintClass (outfil, clsobj)
  1145. FILE *outfil;
  1146. WmlClassDefPtr clsobj;
  1147. {
  1148. int ndx; /* loop index */
  1149. WmlSynClassDefPtr synobj; /* syntactic object */
  1150. WmlClassCtrlDefPtr ctrlref; /* controls reference */
  1151. WmlClassDefPtr ctrlobj; /* current class in control */
  1152. synobj = clsobj->syndef;
  1153. fprintf (outfil, "\n\n\nClass %s:", synobj->name);
  1154. switch ( synobj->type )
  1155. {
  1156. case WmlClassTypeMetaclass:
  1157. fprintf (outfil, "\n Type: Metaclass\t");
  1158. if ( synobj->superclass != NULL )
  1159. fprintf (outfil, "Superclass: %s\t", synobj->superclass);
  1160. if ( synobj->parentclass != NULL )
  1161. fprintf (outfil, "Parentclass: %s\t", synobj->parentclass);
  1162. break;
  1163. case WmlClassTypeWidget:
  1164. fprintf (outfil, "\n Type: Widget\t");
  1165. if ( synobj->superclass != NULL )
  1166. fprintf (outfil, "Superclass: %s\t", synobj->superclass);
  1167. if ( synobj->parentclass != NULL )
  1168. fprintf (outfil, "Parentclass: %s\t", synobj->parentclass);
  1169. if ( clsobj->variant != NULL )
  1170. fprintf (outfil, "\n Associated gadget class: %s\t",
  1171. clsobj->variant->syndef->name);
  1172. if ( synobj->convfunc != NULL )
  1173. fprintf (outfil, "Convenience function: %s", synobj->convfunc);
  1174. break;
  1175. case WmlClassTypeGadget:
  1176. fprintf (outfil, "\n Type: Gadget\t");
  1177. if ( synobj->superclass != NULL )
  1178. fprintf (outfil, "Superclass: %s\t", synobj->superclass);
  1179. if ( synobj->parentclass != NULL )
  1180. fprintf (outfil, "Parentclass: %s\t", synobj->parentclass);
  1181. if ( clsobj->variant != NULL )
  1182. fprintf (outfil, "\n Associated widget class: %s\t",
  1183. clsobj->variant->syndef->name);
  1184. if ( synobj->convfunc != NULL )
  1185. fprintf (outfil, "Convenience function: %s", synobj->convfunc);
  1186. break;
  1187. }
  1188. /*
  1189. * Print associated non-dialog class
  1190. */
  1191. if ( clsobj->nondialog != NULL )
  1192. fprintf (outfil, "\n DialogClass: True\tNon-dialog ancestor: %s\t",
  1193. clsobj->nondialog->syndef->name);
  1194. /*
  1195. * Print the arguments valid in the class. First the new resources for the
  1196. * class are printed, then each ancestor's contribution is printed. This
  1197. * is intended to match the way resources are printed in the toolkit manual,
  1198. * so that checking is as easy as possible.
  1199. */
  1200. fprintf (outfil, "\n Arguments:");
  1201. wmlResolvePrintClassArgs (outfil, clsobj);
  1202. /*
  1203. * Print the reasons valid in the class
  1204. */
  1205. fprintf (outfil, "\n Reasons:");
  1206. wmlResolvePrintClassReasons (outfil, clsobj);
  1207. /*
  1208. * Print the controls valid in the class
  1209. */
  1210. fprintf (outfil, "\n Controls:");
  1211. for ( ndx=0 ; ndx<wml_obj_class_ptr->cnt ; ndx++ )
  1212. {
  1213. ctrlobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr;
  1214. if ( ctrlobj->ref_ptr == NULL ) continue;
  1215. fprintf (outfil, "\n %s", ctrlobj->syndef->name);
  1216. }
  1217. }
  1218. /*
  1219. * Routine to print the arguments for a class
  1220. *
  1221. * This routine prints out the currently marked arguments which are
  1222. * present in this class. Each argument which is printed is remarked
  1223. * so that it won't be printed again. This routine first prints the
  1224. * superclass arguments, so that the printing order becomes the top-down
  1225. * inheritance order.
  1226. */
  1227. void wmlResolvePrintClassArgs (outfil, clsobj)
  1228. FILE *outfil;
  1229. WmlClassDefPtr clsobj;
  1230. {
  1231. int prthdr = TRUE; /* print header line */
  1232. int ndx; /* loop index */
  1233. WmlSynClassDefPtr synobj; /* syntactic object */
  1234. WmlClassResDefPtr resref; /* resource reference */
  1235. int constr = FALSE; /* check for constraints */
  1236. WmlResourceDefPtr resobj; /* current resource */
  1237. WmlSynResourceDefPtr synres; /* syntactic resource object */
  1238. /*
  1239. * Print the superclass arguments
  1240. */
  1241. if ( clsobj->superclass != NULL )
  1242. wmlResolvePrintClassArgs (outfil, clsobj->superclass);
  1243. /*
  1244. * Print the parentclass arguments
  1245. */
  1246. if ( clsobj->parentclass != NULL )
  1247. wmlResolvePrintClassArgs (outfil, clsobj->parentclass);
  1248. /*
  1249. * Print the arguments for this class. Unmark the reference so it won't
  1250. * be printed again.
  1251. */
  1252. synobj = clsobj->syndef;
  1253. for ( ndx=0 ; ndx<wml_obj_arg_ptr->cnt ; ndx++ )
  1254. {
  1255. resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr;
  1256. resref = resobj->ref_ptr;
  1257. if ( resref == NULL ) continue;
  1258. if ( wmlResolveResIsMember(resobj,clsobj->arguments) == NULL ) continue;
  1259. synres = resobj->syndef;
  1260. switch ( synres->type )
  1261. {
  1262. case WmlResourceTypeArgument:
  1263. case WmlResourceTypeSubResource:
  1264. break;
  1265. case WmlResourceTypeConstraint:
  1266. constr = TRUE;
  1267. break;
  1268. default:
  1269. continue;
  1270. break;
  1271. }
  1272. if ( prthdr )
  1273. {
  1274. fprintf (outfil, "\n %s argument set:", synobj->name);
  1275. prthdr = FALSE;
  1276. }
  1277. fprintf (outfil, "\n %s", synres->name);
  1278. fprintf (outfil, "\n\tType = %s", resobj->dtype_def->syndef->name);
  1279. if ( strcmp(synres->name,synres->resliteral) != 0 )
  1280. fprintf (outfil, "\tResourceLiteral = %s", synres->resliteral);
  1281. switch ( resref->exclude )
  1282. {
  1283. case WmlAttributeTrue:
  1284. fprintf (outfil, "\n\tExclude = True;");
  1285. break;
  1286. case WmlAttributeFalse:
  1287. fprintf (outfil, "\n\tExclude = False;");
  1288. break;
  1289. }
  1290. if ( resref->dflt != NULL )
  1291. fprintf (outfil, "\n\tDefault = \"%s\"", resref->dflt);
  1292. else
  1293. if ( synres->dflt != NULL )
  1294. fprintf (outfil, "\n\tDefault = \"%s\"", synres->dflt);
  1295. resobj->ref_ptr = NULL;
  1296. }
  1297. /*
  1298. * Print the constraints valid in the class
  1299. */
  1300. if ( constr )
  1301. {
  1302. prthdr = TRUE;
  1303. for ( ndx=0 ; ndx<wml_obj_arg_ptr->cnt ; ndx++ )
  1304. {
  1305. resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr;
  1306. resref = resobj->ref_ptr;
  1307. if ( resref == NULL ) continue;
  1308. if ( wmlResolveResIsMember(resobj,clsobj->arguments) == NULL ) continue;
  1309. synres = resobj->syndef;
  1310. switch ( synres->type )
  1311. {
  1312. case WmlResourceTypeConstraint:
  1313. break;
  1314. default:
  1315. continue;
  1316. break;
  1317. }
  1318. if ( prthdr )
  1319. {
  1320. fprintf (outfil, "\n %s constraint set:", synobj->name);
  1321. prthdr = FALSE;
  1322. }
  1323. fprintf (outfil, "\n %s", synres->name);
  1324. if ( strcmp(synres->name,synres->resliteral) != 0 )
  1325. fprintf (outfil, "\tResourceLiteral = %s", synres->resliteral);
  1326. switch ( resref->exclude )
  1327. {
  1328. case WmlAttributeTrue:
  1329. fprintf (outfil, "\n\tExclude = True;");
  1330. break;
  1331. case WmlAttributeFalse:
  1332. fprintf (outfil, "\n\tExclude = False;");
  1333. break;
  1334. }
  1335. if ( resref->dflt != NULL )
  1336. fprintf (outfil, "\n\tDefault = \"%s\"", resref->dflt);
  1337. else
  1338. if ( synres->dflt != NULL )
  1339. fprintf (outfil, "\n\tDefault = \"%s\"", synres->dflt);
  1340. resobj->ref_ptr = NULL;
  1341. }
  1342. }
  1343. }
  1344. /*
  1345. * Routine to print reasons in a class.
  1346. *
  1347. * Like printing arguments, only reasons instead.
  1348. */
  1349. void wmlResolvePrintClassReasons (outfil, clsobj)
  1350. FILE *outfil;
  1351. WmlClassDefPtr clsobj;
  1352. {
  1353. int prthdr = TRUE; /* print header flag */
  1354. int ndx; /* loop index */
  1355. WmlSynClassDefPtr synobj; /* syntactic object */
  1356. WmlClassResDefPtr resref; /* resource reference */
  1357. WmlResourceDefPtr resobj; /* current resource */
  1358. WmlSynResourceDefPtr synres; /* syntactic resource object */
  1359. /*
  1360. * Print the superclass reasons
  1361. */
  1362. if ( clsobj->superclass != NULL )
  1363. wmlResolvePrintClassReasons (outfil, clsobj->superclass);
  1364. /*
  1365. * Print the parentclass reasons
  1366. */
  1367. if ( clsobj->parentclass != NULL )
  1368. wmlResolvePrintClassReasons (outfil, clsobj->parentclass);
  1369. /*
  1370. * Print the reasons for this class. Unmark the reference so it won't
  1371. * be printed again.
  1372. */
  1373. synobj = clsobj->syndef;
  1374. for ( ndx=0 ; ndx<wml_obj_reason_ptr->cnt ; ndx++ )
  1375. {
  1376. resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr;
  1377. resref = resobj->ref_ptr;
  1378. if ( resref == NULL ) continue;
  1379. if ( wmlResolveResIsMember(resobj,clsobj->reasons) == NULL ) continue;
  1380. synres = resobj->syndef;
  1381. if ( prthdr )
  1382. {
  1383. fprintf (outfil, "\n %s reason set:", synobj->name);
  1384. prthdr = FALSE;
  1385. }
  1386. fprintf (outfil, "\n %s", synres->name);
  1387. if ( strcmp(synres->name,synres->resliteral) != 0 )
  1388. fprintf (outfil, "\tResourceLiteral = %s", synres->resliteral);
  1389. switch ( resref->exclude )
  1390. {
  1391. case WmlAttributeTrue:
  1392. fprintf (outfil, "\n\tExclude = True;");
  1393. break;
  1394. case WmlAttributeFalse:
  1395. fprintf (outfil, "\n\tExclude = False;");
  1396. break;
  1397. }
  1398. resobj->ref_ptr = NULL;
  1399. }
  1400. }
  1401. /*
  1402. * Routine to mark reference pointers for a class
  1403. *
  1404. * This routine clears all reference pointers, then marks the class and
  1405. * resource objects to flag those contained in the current class. This
  1406. * allows processing of the widget and resource vectors in order to produce
  1407. * bit masks or reports.
  1408. */
  1409. void wmlMarkReferencePointers (clsobj)
  1410. WmlClassDefPtr clsobj;
  1411. {
  1412. int ndx; /* loop index */
  1413. WmlClassDefPtr mrkcls; /* class object to mark */
  1414. WmlResourceDefPtr mrkres; /* resource object to mark */
  1415. WmlClassResDefPtr resref; /* resource reference */
  1416. WmlClassCtrlDefPtr ctrlref; /* controls reference */
  1417. /*
  1418. * Clear the reference pointers. Then go through the arguments, reasons,
  1419. * and controls lists, and mark the referenced classes.
  1420. */
  1421. wmlResolveClearRefPointers ();
  1422. for ( resref=clsobj->arguments ; resref!= NULL ; resref=resref->next )
  1423. resref->act_resource->ref_ptr = resref;
  1424. for ( resref=clsobj->reasons ; resref!= NULL ; resref=resref->next )
  1425. resref->act_resource->ref_ptr = resref;
  1426. for ( ctrlref=clsobj->controls ; ctrlref!=NULL ; ctrlref=ctrlref->next )
  1427. ctrlref->ctrl->ref_ptr = ctrlref;
  1428. }
  1429. /*
  1430. * Routine to clear reference pointers
  1431. */
  1432. void wmlResolveClearRefPointers ()
  1433. {
  1434. int ndx; /* loop index */
  1435. WmlClassDefPtr mrkcls; /* class object to mark */
  1436. WmlResourceDefPtr mrkres; /* resource object to mark */
  1437. WmlChildDefPtr mrkcld; /* child object to mark */
  1438. for ( ndx=0 ; ndx<wml_obj_allclass_ptr->cnt ; ndx++ )
  1439. {
  1440. mrkcls = (WmlClassDefPtr) wml_obj_allclass_ptr->hvec[ndx].objptr;
  1441. mrkcls->ref_ptr = NULL;
  1442. }
  1443. for ( ndx=0 ; ndx<wml_obj_reason_ptr->cnt ; ndx++ )
  1444. {
  1445. mrkres = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr;
  1446. mrkres->ref_ptr = NULL;
  1447. }
  1448. for ( ndx=0 ; ndx<wml_obj_arg_ptr->cnt ; ndx++ )
  1449. {
  1450. mrkres = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr;
  1451. mrkres->ref_ptr = NULL;
  1452. }
  1453. for ( ndx=0 ; ndx<wml_obj_child_ptr->cnt ; ndx++ )
  1454. {
  1455. mrkcld = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr;
  1456. mrkcld->ref_ptr = NULL;
  1457. }
  1458. }
  1459. /*
  1460. * Routine to find an object for binding. The name is always looked
  1461. * in the syntactic object list, since all references made by the
  1462. * user are in that list (resolved objects may be entered under
  1463. * an internal literal, and not be found). This routine always attempts to
  1464. * return a resolved object (which depends on object type). It also guarantees
  1465. * that the object it finds matches the given type.
  1466. *
  1467. * name the object to be found
  1468. * type type the object should match
  1469. * requester requester name, for error messages
  1470. *
  1471. * Returns: pointer to the object found
  1472. */
  1473. ObjectPtr wmlResolveFindObject (name, type, requester)
  1474. char *name;
  1475. int type;
  1476. char *requester;
  1477. {
  1478. int objndx; /* the object index in the list */
  1479. WmlSynDefPtr synobj; /* syntactic object */
  1480. char errmsg[300];
  1481. objndx = wmlFindInHList (wml_synobj_ptr, name);
  1482. if ( objndx < 0 )
  1483. {
  1484. wmlIssueReferenceError (requester, name);
  1485. return NULL;
  1486. }
  1487. synobj = (WmlSynDefPtr) wml_synobj_ptr ->hvec[objndx].objptr;
  1488. if ( synobj->validation != type )
  1489. {
  1490. sprintf (errmsg,
  1491. "Object %s references object %s\n\tin a context where a different type of object is required",
  1492. requester, name);
  1493. wmlIssueError (errmsg);
  1494. return NULL;
  1495. }
  1496. switch ( synobj->validation )
  1497. {
  1498. case WmlClassDefValid:
  1499. case WmlResourceDefValid:
  1500. case WmlDataTypeDefValid:
  1501. case WmlCtrlListDefValid:
  1502. case WmlEnumSetDefValid:
  1503. case WmlEnumValueDefValid:
  1504. case WmlChildDefValid:
  1505. return (ObjectPtr) synobj->rslvdef;
  1506. break;
  1507. default:
  1508. return (ObjectPtr) synobj;
  1509. }
  1510. }
  1511. /*
  1512. * Report an object reference error
  1513. *
  1514. * srcname the object making the reference
  1515. * badname the missing object
  1516. */
  1517. void wmlIssueReferenceError (srcname, badname)
  1518. char *srcname;
  1519. char *badname;
  1520. {
  1521. printf ("\nObject %s references undefined object %s", srcname, badname);
  1522. wml_err_count += 1;
  1523. }
  1524. /*
  1525. * Report an attempt to make a reference which is not supported.
  1526. */
  1527. void wmlIssueIllegalReferenceError (srcname, badname)
  1528. char *srcname;
  1529. char *badname;
  1530. {
  1531. printf ("\nObject %s cannot reference a %s object", srcname, badname);
  1532. wml_err_count += 1;
  1533. }
  1534. /*
  1535. * Report an error string.
  1536. */
  1537. void wmlIssueError (errstg)
  1538. char *errstg;
  1539. {
  1540. printf ("\n%s", errstg);
  1541. wml_err_count += 1;
  1542. }