wmloutkey.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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[] = "$TOG: wmloutkey.c /main/8 1997/04/14 12:55:51 dbl $"
  36. #endif
  37. #endif
  38. /*
  39. * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
  40. /*
  41. * This module contains routines responsible for writing the .h files which
  42. * define the UIL lexer's keyword (token) tables. All files are written
  43. * into the current directory.
  44. *
  45. * Input:
  46. * The resolved objects
  47. * .dat files required to specify objects defined in Uil.y:
  48. * keyword.dat
  49. * reserved.dat
  50. *
  51. * Output:
  52. * UilKeyTab.h
  53. *
  54. */
  55. #include "wml.h"
  56. #if defined(__STDC__)
  57. #include <stdlib.h>
  58. #include <string.h>
  59. #endif
  60. #include <stdio.h>
  61. /*
  62. * Routines used only in this module
  63. */
  64. void wmlKeyWBuildTables ();
  65. void wmlKeyWClassTokens ();
  66. void wmlKeyWGrammarTokens ();
  67. int wmlKeyWGrammarClass ();
  68. void wmlKeyWArgTokens ();
  69. void wmlKeyWReasonTokens ();
  70. void wmlKeyWCharsetTokens ();
  71. void wmlKeyWEnumvalTokens ();
  72. void wmlKeyWChildTokens ();
  73. void wmlKeyWMakeTokens ();
  74. void wmlOutputUilKeyTab ();
  75. void wmlOutputUilKeyTabBody ();
  76. void wmlTokenClassString ();
  77. void wmlTokenSymKString ();
  78. void wmlTokenTokenString ();
  79. void wmlOutputUilTokName ();
  80. /*
  81. * globals
  82. */
  83. static char *canned_warn =
  84. "/*\n\
  85. **\tThis file is automatically generated. Do not edit it by hand.\n\
  86. **/\n\n";
  87. #define GrTokenMax 200 /* limit on grammar tokens */
  88. static int grtok_max_val = 0;
  89. static WmlGrammarTokenPtr grtok_vec[GrTokenMax];
  90. /*
  91. * Output control routine
  92. */
  93. void wmlOutputKeyWordFiles ()
  94. {
  95. wmlKeyWBuildTables ();
  96. wmlOutputUilKeyTab ();
  97. wmlOutputUilTokName ();
  98. }
  99. /*
  100. * Routine to construct token tables for building UilKeyTab.h
  101. *
  102. * This routine constructs token entries for each token class which appears
  103. * in UilKeyTab.h (the token classes are defined in UilKeyDef.h). These
  104. * tokens are defined both by WML objects in object vectors, and by
  105. * tokens defined in Uil.y.
  106. */
  107. void wmlKeyWBuildTables ()
  108. {
  109. int ndx;
  110. /*
  111. * Initialize the token vectors
  112. */
  113. wmlInitHList (wml_tok_sens_ptr, 1000, TRUE);
  114. wmlInitHList (wml_tok_insens_ptr, 1000, TRUE);
  115. for ( ndx=0 ; ndx<GrTokenMax ; ndx++ )
  116. grtok_vec[ndx] = NULL;
  117. /*
  118. * Read and enter the tokens from Uil.y (via tokens.dat)
  119. */
  120. wmlKeyWGrammarTokens ();
  121. /*
  122. * Enter the class, argument, reason, charset, child, and enumval tokens
  123. */
  124. wmlKeyWClassTokens ();
  125. wmlKeyWArgTokens ();
  126. wmlKeyWReasonTokens ();
  127. wmlKeyWCharsetTokens ();
  128. wmlKeyWEnumvalTokens ();
  129. wmlKeyWChildTokens ();
  130. }
  131. /*
  132. * Routine to read and enter tokens defined in Uil.y into the token tables.
  133. */
  134. void wmlKeyWGrammarTokens ()
  135. {
  136. FILE *infil; /* input file (tokens.dat) */
  137. int scanres; /* result of fscanf */
  138. int lineno = 1; /* current line number */
  139. char token[100]; /* current token */
  140. char class[100]; /* current class */
  141. int tokval; /* current token id (as value) */
  142. WmlGrammarTokenPtr grtok; /* new grammar token */
  143. int ndx;
  144. char sens_name[100]; /* for case-insensitive name */
  145. /*
  146. * Read tokens.dat. Recognize and save all tokens. Some are saved in the
  147. * global tokens vector so they will be put into UilKeyTab.h. All are
  148. * saved in an ordered vector to write UilTokName.h
  149. *
  150. * Special handling is required for tokens whose yacc definition conflicts
  151. * with common literals. In these cases, the token literal does not map
  152. * directly to its keyword in the language, and must be mapped as a special
  153. * case:
  154. * UILTRUE -> true/TRUE
  155. * UILFALSE -> false/FALSE
  156. * UILfile -> file/FILE
  157. * UILeof -> eof/EOF
  158. */
  159. infil = fopen ("tokens.dat", "r");
  160. if ( infil == NULL )
  161. {
  162. printf ("\nCouldn't open tokens.dat");
  163. return;
  164. }
  165. while ( TRUE )
  166. {
  167. scanres = fscanf (infil, "%s %d %s", token, &tokval, class);
  168. if ( scanres == EOF ) break;
  169. if ( scanres != 3 )
  170. {
  171. printf ("\nBadly formatted at line %d in tokens.dat", lineno);
  172. continue;
  173. }
  174. lineno += 1;
  175. /*
  176. * Convert the token class, and construct a grammar token.
  177. */
  178. grtok = (WmlGrammarTokenPtr) malloc(sizeof(WmlGrammarToken));
  179. grtok->class = wmlKeyWGrammarClass (class);
  180. grtok->token = wmlAllocateString (token);
  181. grtok->val = tokval;
  182. /*
  183. * Save the token in the grammar token vector, indexed by its value
  184. * (for UilTokName.h)
  185. */
  186. if ( grtok->val < GrTokenMax )
  187. {
  188. grtok_vec[grtok->val] = grtok;
  189. if ( grtok->val > grtok_max_val )
  190. grtok_max_val = grtok->val;
  191. }
  192. else
  193. printf ("\nToken id %d for %s exceed GrTokenMax",
  194. grtok->val, grtok->token);
  195. /*
  196. * Enter tokens which appear in the keyword tables as keyword tokens.
  197. * These have their lower case names entered as the case-insensitive
  198. * keyword token string. Do special token literal mapping.
  199. */
  200. switch ( grtok->class )
  201. {
  202. case WmlTokenClassKeyword:
  203. case WmlTokenClassReserved:
  204. strcpy (sens_name, grtok->token);
  205. for ( ndx=0 ; ndx<(int)strlen(sens_name) ; ndx++ )
  206. sens_name[ndx] = _lower(sens_name[ndx]);
  207. if ( strcmp(sens_name,"uiltrue") == 0 )
  208. strcpy (sens_name, "true");
  209. if ( strcmp(sens_name,"uilfalse") == 0 )
  210. strcpy (sens_name, "false");
  211. if ( strcmp(sens_name,"uilfile") == 0 )
  212. strcpy (sens_name, "file");
  213. if ( strcmp(sens_name,"uileof") == 0 )
  214. strcpy (sens_name, "eof");
  215. wmlKeyWMakeTokens (sens_name, grtok->class, (ObjectPtr)grtok);
  216. }
  217. }
  218. fclose (infil);
  219. }
  220. /*
  221. * This routine translates a string identifying a token class into
  222. * its matching internal literal.
  223. */
  224. int wmlKeyWGrammarClass (token)
  225. char *token;
  226. {
  227. if ( strcmp(token,"argument") == 0 )
  228. return WmlTokenClassArgument;
  229. if ( strcmp(token,"charset") == 0 )
  230. return WmlTokenClassCharset;
  231. if ( strcmp(token,"color") == 0 )
  232. return WmlTokenClassColor;
  233. if ( strcmp(token,"enumval") == 0 )
  234. return WmlTokenClassEnumval;
  235. if ( strcmp(token,"font") == 0 )
  236. return WmlTokenClassFont;
  237. if ( strcmp(token,"identifier") == 0 )
  238. return WmlTokenClassIdentifier;
  239. if ( strcmp(token,"keyword") == 0 )
  240. return WmlTokenClassKeyword;
  241. if ( strcmp(token,"literal") == 0 )
  242. return WmlTokenClassLiteral;
  243. if ( strcmp(token,"reason") == 0 )
  244. return WmlTokenClassReason;
  245. if ( strcmp(token,"reserved") == 0 )
  246. return WmlTokenClassReserved;
  247. if ( strcmp(token,"special") == 0 )
  248. return WmlTokenClassSpecial;
  249. if ( strcmp(token,"unused") == 0 )
  250. return WmlTokenClassUnused;
  251. if ( strcmp(token,"class") == 0 )
  252. return WmlTokenClassClass;
  253. if (strcmp(token,"child") == 0) return WmlTokenClassChild;
  254. printf ("\nUnrecognized token class %s", token);
  255. return 0;
  256. }
  257. /*
  258. * Routine to process the class objects and enter them in the token tables.
  259. * Aliases are also entered, under their own names.
  260. */
  261. void wmlKeyWClassTokens ()
  262. {
  263. int ndx; /* loop index */
  264. WmlClassDefPtr clsobj; /* class object */
  265. WmlSynClassDefPtr synobj; /* syntactic object */
  266. /*
  267. * Make tokens for all class entries
  268. */
  269. for ( ndx=0 ; ndx<wml_obj_class_ptr->cnt ; ndx++ )
  270. {
  271. clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr;
  272. synobj = clsobj->syndef;
  273. wmlKeyWMakeTokens (synobj->name, WmlTokenClassClass, (ObjectPtr)clsobj);
  274. }
  275. }
  276. /*
  277. * Routine to process the argument objects and enter them in the token tables.
  278. * Aliases are also entered, under their own names.
  279. */
  280. void wmlKeyWArgTokens ()
  281. {
  282. int ndx; /* loop index */
  283. WmlResourceDefPtr resobj; /* resource object */
  284. WmlSynResourceDefPtr synobj; /* syntactic object */
  285. int alias_ndx; /* alias loop index */
  286. /*
  287. * Make tokens for all argument entries
  288. */
  289. for ( ndx=0 ; ndx<wml_obj_arg_ptr->cnt ; ndx++ )
  290. {
  291. resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr;
  292. synobj = resobj->syndef;
  293. wmlKeyWMakeTokens (synobj->name, WmlTokenClassArgument, (ObjectPtr)resobj);
  294. for ( alias_ndx=0 ; alias_ndx<synobj->alias_cnt ; alias_ndx++ )
  295. wmlKeyWMakeTokens (synobj->alias_list[alias_ndx],
  296. WmlTokenClassArgument,
  297. (ObjectPtr)resobj);
  298. }
  299. }
  300. /*
  301. * Routine to process the reason objects and enter them in the token tables.
  302. */
  303. void wmlKeyWReasonTokens ()
  304. {
  305. int ndx; /* loop index */
  306. WmlResourceDefPtr resobj; /* resource object */
  307. WmlSynResourceDefPtr synobj; /* syntactic object */
  308. int alias_ndx; /* alias loop index */
  309. /*
  310. * Make tokens for all reason entries
  311. */
  312. for ( ndx=0 ; ndx<wml_obj_reason_ptr->cnt ; ndx++ )
  313. {
  314. resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr;
  315. synobj = resobj->syndef;
  316. wmlKeyWMakeTokens (synobj->name, WmlTokenClassReason, (ObjectPtr)resobj);
  317. for ( alias_ndx=0 ; alias_ndx<synobj->alias_cnt ; alias_ndx++ )
  318. wmlKeyWMakeTokens (synobj->alias_list[alias_ndx],
  319. WmlTokenClassReason,
  320. (ObjectPtr)resobj);
  321. }
  322. }
  323. /*
  324. * Routine to process the child objects and enter them in the token tables.
  325. */
  326. void wmlKeyWChildTokens ()
  327. {
  328. int ndx; /* loop index */
  329. WmlChildDefPtr childobj; /* child object */
  330. WmlSynChildDefPtr synobj; /* syntactic object */
  331. /*
  332. * Make tokens for all child entries
  333. */
  334. for ( ndx=0 ; ndx<wml_obj_child_ptr->cnt ; ndx++ )
  335. {
  336. childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr;
  337. synobj = childobj->syndef;
  338. wmlKeyWMakeTokens (synobj->name, WmlTokenClassChild, (ObjectPtr)childobj);
  339. }
  340. }
  341. /*
  342. * Routine to process the charset objects and enter them in the token tables.
  343. */
  344. void wmlKeyWCharsetTokens ()
  345. {
  346. int ndx; /* loop index */
  347. WmlCharSetDefPtr csobj; /* character set object */
  348. WmlSynCharSetDefPtr synobj; /* syntactic object */
  349. int alias_ndx; /* alias loop index */
  350. /*
  351. * Make tokens for all charset entries
  352. */
  353. for ( ndx=0 ; ndx<wml_obj_charset_ptr->cnt ; ndx++ )
  354. {
  355. csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr;
  356. synobj = csobj->syndef;
  357. wmlKeyWMakeTokens (synobj->name, WmlTokenClassCharset, (ObjectPtr)csobj);
  358. for ( alias_ndx=0 ; alias_ndx<synobj->alias_cnt ; alias_ndx++ )
  359. wmlKeyWMakeTokens (synobj->alias_list[alias_ndx],
  360. WmlTokenClassCharset,
  361. (ObjectPtr)csobj);
  362. }
  363. }
  364. /*
  365. * Routine to process the enumval objects and enter them in the token tables.
  366. */
  367. void wmlKeyWEnumvalTokens ()
  368. {
  369. int ndx; /* loop index */
  370. WmlEnumValueDefPtr esobj; /* enumeration value object */
  371. WmlSynEnumValueDefPtr synobj; /* syntactic object */
  372. /*
  373. * Make tokens for all enumval entries
  374. */
  375. for ( ndx=0 ; ndx<wml_obj_enumval_ptr->cnt ; ndx++ )
  376. {
  377. esobj = (WmlEnumValueDefPtr) wml_obj_enumval_ptr->hvec[ndx].objptr;
  378. synobj = esobj->syndef;
  379. wmlKeyWMakeTokens (synobj->name, WmlTokenClassEnumval, (ObjectPtr)esobj);
  380. }
  381. }
  382. /*
  383. * Routine to create tokens and enter them in the token list.
  384. *
  385. * This routine constructs a case-sensitive and a case-insensitive token
  386. * and enters them the token vectors.
  387. */
  388. void wmlKeyWMakeTokens (sens_name, class, obj)
  389. char *sens_name;
  390. int class;
  391. ObjectPtr obj;
  392. {
  393. WmlKeyWTokenPtr senstok; /* case-sensitive token */
  394. WmlKeyWTokenPtr insenstok; /* case-insensitive token */
  395. char insens_name[100];
  396. int ndx;
  397. /*
  398. * Create both tokens, with one having an upper-case name. The names are
  399. * entered only in the order vector, not in the token itself.
  400. */
  401. senstok = (WmlKeyWTokenPtr) malloc (sizeof(WmlKeyWToken));
  402. insenstok = (WmlKeyWTokenPtr) malloc (sizeof(WmlKeyWToken));
  403. senstok->class = class;
  404. senstok->objdef = obj;
  405. insenstok->class = class;
  406. insenstok->objdef = obj;
  407. strcpy (insens_name, sens_name);
  408. for ( ndx=0 ; ndx<(int)strlen(insens_name) ; ndx++ )
  409. insens_name[ndx] = _upper (insens_name[ndx]);
  410. wmlInsertInKeyList(wml_tok_sens_ptr, sens_name, senstok);
  411. wmlInsertInKeyList(wml_tok_insens_ptr, insens_name, insenstok);
  412. }
  413. /*
  414. * Routine to output UilKeyTab.h
  415. *
  416. * This routine dumps the tokens defined in the token tables into
  417. * UilKeyTab.h. Both the case-sensitive and case-insensitive token
  418. * lists are used.
  419. */
  420. void wmlOutputUilKeyTab ()
  421. {
  422. char *canned1 =
  423. "\n/* case sensitive keyword table */\n\
  424. static key_keytable_entry_type key_table_vec[] =\n\
  425. {\n";
  426. char *canned2 =
  427. " };\n\
  428. externaldef(uil_sym_glbl) key_keytable_entry_type *key_table =\n\
  429. \t\tkey_table_vec;\n\n\
  430. /* Maximum length of a keyword, and table size */\n\
  431. externaldef(uil_sym_glbl) int key_k_keyword_max_length = %d;\n\
  432. externaldef(uil_sym_glbl) int key_k_keyword_count = %d;\n\n\
  433. /* case insensitive keyword table */\n\
  434. static key_keytable_entry_type key_table_case_ins_vec[] =\n\
  435. {\n";
  436. char *canned3 =
  437. " };\n\
  438. externaldef(uil_sym_glbl) key_keytable_entry_type *key_table_case_ins =\n\
  439. \t\tkey_table_case_ins_vec;\n";
  440. FILE *outfil; /* output file */
  441. int ndx; /* loop index */
  442. int maxlen = 0; /* max keyword length */
  443. int maxkey = 0; /* # entries in keyword table */
  444. /*
  445. * Open the output file.
  446. */
  447. outfil = fopen ("UilKeyTab.h", "w");
  448. if ( outfil == NULL )
  449. {
  450. printf ("\nCouldn't open UilKeyTab.h");
  451. return;
  452. }
  453. fprintf (outfil, canned_warn);
  454. /*
  455. * Print the case sensitive and insensitive tables
  456. */
  457. fprintf (outfil, canned1);
  458. wmlOutputUilKeyTabBody (outfil, wml_tok_sens_ptr, &maxlen, &maxkey);
  459. fprintf (outfil, canned2, maxlen, maxkey);
  460. wmlOutputUilKeyTabBody (outfil, wml_tok_insens_ptr, &maxlen, &maxkey);
  461. fprintf (outfil, canned3);
  462. /*
  463. * close the output file
  464. */
  465. printf ("\nCreated UilKeyTab.h");
  466. fclose (outfil);
  467. }
  468. /*
  469. * Routine to output the body of a keyword table
  470. */
  471. void wmlOutputUilKeyTabBody (outfil, tokvec, maxlen, maxkey)
  472. FILE *outfil;
  473. DynamicHandleListDefPtr tokvec;
  474. int *maxlen;
  475. int *maxkey;
  476. {
  477. int ndx; /* loop index */
  478. WmlKeyWTokenPtr tok; /* current token */
  479. char *tokstg; /* string for token (keyword) */
  480. char tkclass[100]; /* token class string */
  481. char tksym[100]; /* token sym_k string */
  482. char tktoken[100]; /* token tkn_k_num string */
  483. /*
  484. * Loop over all tokens, and put out an entry for each.
  485. */
  486. for ( ndx=0 ; ndx<tokvec->cnt ; ndx++ )
  487. {
  488. tok = (WmlKeyWTokenPtr) tokvec->hvec[ndx].objptr;
  489. tokstg = tokvec->hvec[ndx].objname;
  490. wmlTokenClassString (tkclass, tok);
  491. wmlTokenSymKString (tksym, tok);
  492. wmlTokenTokenString (tktoken, tok);
  493. fprintf (outfil, " {%s, %s, %d, %s, \"%s\"},\n",
  494. tkclass,
  495. tksym,
  496. strlen(tokstg),
  497. tktoken,
  498. tokstg);
  499. if ( (int)strlen(tokstg) > *maxlen )
  500. *maxlen = strlen (tokstg);
  501. *maxkey += 1;
  502. }
  503. }
  504. /*
  505. * Routine to return the string for a token class, tkn_k_class_...
  506. */
  507. void wmlTokenClassString (dststg, tok)
  508. char *dststg;
  509. WmlKeyWTokenPtr tok;
  510. {
  511. switch ( tok->class )
  512. {
  513. case WmlTokenClassArgument:
  514. strcpy (dststg, "tkn_k_class_argument");
  515. return;
  516. case WmlTokenClassCharset:
  517. strcpy (dststg, "tkn_k_class_charset");
  518. return;
  519. case WmlTokenClassEnumval:
  520. strcpy (dststg, "tkn_k_class_enumval");
  521. return;
  522. case WmlTokenClassKeyword:
  523. strcpy (dststg, "tkn_k_class_keyword");
  524. return;
  525. case WmlTokenClassReason:
  526. strcpy (dststg, "tkn_k_class_reason");
  527. return;
  528. case WmlTokenClassReserved:
  529. strcpy (dststg, "tkn_k_class_reserved");
  530. return;
  531. case WmlTokenClassClass:
  532. strcpy (dststg, "tkn_k_class_class");
  533. return;
  534. case WmlTokenClassChild:
  535. strcpy (dststg, "tkn_k_class_child");
  536. return;
  537. }
  538. }
  539. /*
  540. * Routine to return the string for a sym_k_... for some object
  541. */
  542. void wmlTokenSymKString (dststg, tok)
  543. char *dststg;
  544. WmlKeyWTokenPtr tok;
  545. {
  546. WmlClassDefPtr clsobj; /* class object */
  547. WmlResourceDefPtr resobj; /* resource object */
  548. WmlCharSetDefPtr csobj; /* character set object */
  549. WmlEnumValueDefPtr esobj; /* enumeration value object */
  550. WmlChildDefPtr chobj; /* child object */
  551. switch ( tok->class )
  552. {
  553. case WmlTokenClassArgument:
  554. resobj = (WmlResourceDefPtr) tok->objdef;
  555. sprintf (dststg, "sym_k_%s_arg", resobj->tkname);
  556. return;
  557. case WmlTokenClassCharset:
  558. csobj = (WmlCharSetDefPtr) tok->objdef;
  559. sprintf (dststg, "sym_k_%s_charset", csobj->syndef->name);
  560. return;
  561. case WmlTokenClassEnumval:
  562. esobj = (WmlEnumValueDefPtr) tok->objdef;
  563. sprintf (dststg, "sym_k_%s_enumval", esobj->syndef->name);
  564. return;
  565. case WmlTokenClassKeyword:
  566. strcpy (dststg, "0");
  567. return;
  568. case WmlTokenClassReason:
  569. resobj = (WmlResourceDefPtr) tok->objdef;
  570. sprintf (dststg, "sym_k_%s_reason", resobj->tkname);
  571. return;
  572. case WmlTokenClassReserved:
  573. strcpy (dststg, "0");
  574. return;
  575. case WmlTokenClassClass:
  576. clsobj = (WmlClassDefPtr) tok->objdef;
  577. sprintf (dststg, "sym_k_%s_object", clsobj->tkname);
  578. return;
  579. case WmlTokenClassChild:
  580. chobj = (WmlChildDefPtr) tok->objdef;
  581. sprintf (dststg, "sym_k_%s_child", chobj->tkname);
  582. return;
  583. }
  584. }
  585. /*
  586. * Routine to return the string for a token number, tkn_k_num_...
  587. */
  588. void wmlTokenTokenString (dststg, tok)
  589. char *dststg;
  590. WmlKeyWTokenPtr tok;
  591. {
  592. WmlGrammarTokenPtr grtok; /* grammar token */
  593. switch ( tok->class )
  594. {
  595. case WmlTokenClassArgument:
  596. strcpy (dststg, "ARGUMENT_NAME");
  597. return;
  598. case WmlTokenClassCharset:
  599. strcpy (dststg, "CHARSET_NAME");
  600. return;
  601. case WmlTokenClassEnumval:
  602. strcpy (dststg, "ENUMVAL_NAME");
  603. return;
  604. case WmlTokenClassReason:
  605. strcpy (dststg, "REASON_NAME");
  606. return;
  607. case WmlTokenClassKeyword:
  608. case WmlTokenClassReserved:
  609. grtok = (WmlGrammarTokenPtr) tok->objdef;
  610. strcpy (dststg, grtok->token);
  611. return;
  612. case WmlTokenClassClass:
  613. strcpy (dststg, "CLASS_NAME");
  614. return;
  615. case WmlTokenClassChild:
  616. strcpy (dststg, "CHILD_NAME");
  617. return;
  618. }
  619. }
  620. /*
  621. * routine to output UilTokName.h
  622. */
  623. void wmlOutputUilTokName ()
  624. {
  625. char *canned1 =
  626. "/*\tToken name table */\n\
  627. static char *tok_token_name_table_vec[] = \n\
  628. {\n";
  629. char *canned2 =
  630. " };\n\
  631. externaldef(uil_sym_glbl) char **tok_token_name_table =\n\
  632. \t\ttok_token_name_table_vec;\n\n\
  633. /*\tNumber of entries in table */\n\
  634. externaldef(uil_sym_glbl) int tok_num_tokens = %d;\n";
  635. FILE *outfil; /* output file */
  636. int ndx; /* loop index */
  637. WmlGrammarTokenPtr grtok; /* current grammar token */
  638. /*
  639. * Open the output file.
  640. */
  641. outfil = fopen ("UilTokName.h", "w");
  642. if ( outfil == NULL )
  643. {
  644. printf ("\nCouldn't open UilTokName.h");
  645. return;
  646. }
  647. fprintf (outfil, canned_warn);
  648. fprintf (outfil, canned1);
  649. /*
  650. * Print the token name entries
  651. * Note: vector size is max_val + 1 for zeroth token
  652. */
  653. for ( ndx=0 ; ndx<grtok_max_val+1 ; ndx++ )
  654. {
  655. grtok = grtok_vec[ndx];
  656. if ( grtok != NULL )
  657. fprintf (outfil, " \"%s\",\n", grtok->token);
  658. else
  659. fprintf (outfil, " \"UNKNOWN_TOKEN\",\n");
  660. }
  661. /*
  662. * close the output file
  663. */
  664. fprintf (outfil, canned2, grtok_max_val+1);
  665. printf ("\nCreated UilTokName.h");
  666. fclose (outfil);
  667. }