2
0

wmldbcreate.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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: wmldbcreate.c /main/8 1997/04/14 12:55:30 dbl $"
  36. #endif
  37. #endif
  38. /*
  39. * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
  40. /*
  41. * This is the program creates binary databases from WML output.
  42. */
  43. #include <stdio.h>
  44. #ifndef X_NOT_STDC_ENV
  45. #include <stdlib.h>
  46. #endif
  47. #include <Mrm/MrmWidget.h>
  48. #include <Xm/Xm.h>
  49. #include <Xm/MwmUtil.h>
  50. #include <Dt/Editor.h>
  51. #include <Dt/Help.h>
  52. #include <Dt/HelpDialog.h>
  53. #include <Dt/HelpQuickD.h>
  54. #include <Dt/MenuButton.h>
  55. #include <Dt/Print.h>
  56. #include <Dt/TermPrim.h>
  57. #include <Dt/Term.h>
  58. /*
  59. * User supplied widget public.h and/or private.h files are to be added here
  60. * #ifdef for automatic use in uilwmdcreate script file
  61. */
  62. /*
  63. * End of User supplied widget files
  64. */
  65. #include "UilDBDef.h"
  66. #include "UilLexPars.h"
  67. #include "UilSymGen.h" /* from WML */
  68. #include "UilSymArTy.h" /* from WML */
  69. #include "UilSymRArg.h" /* from WML */
  70. #include "UilSymArTa.h" /* from WML */
  71. #include "UilSymReas.h" /* from WML */
  72. #include "UilSymCtl.h" /* from WML */
  73. #include "UilConst.h" /* from WML */
  74. #include "UilSymNam.h" /* from WML */
  75. #include "UilSymEnum.h" /* from WML */
  76. #include "UilSymCSet.h" /* from WML */
  77. #include "UilUrmClas.h" /* from WML */
  78. #include "UilKeyTab.h" /* from WML */
  79. #include "UilSymChCl.h" /* from WML */
  80. #include "UilSymChTa.h" /* from WML */
  81. void emit_globals();
  82. void emit_header(_db_header_ptr header);
  83. void emit_chars(int table_id);
  84. void emit_ints_and_string( int table_id);
  85. void emit_char_table( int table_id);
  86. void emit_length_and_string( int table_id);
  87. void emit_shorts( int table_id);
  88. void emit_int_and_table_shorts( int table_id);
  89. void emit_ints( int table_id);
  90. FILE *bfile, *afile;
  91. int DEBUG=FALSE;
  92. char outfilename[80];
  93. char debugfilename[80];
  94. main(argc, argv)
  95. int argc;
  96. char **argv;
  97. {
  98. _db_header header;
  99. strcpy(outfilename, "motif.wmd");
  100. strcpy(debugfilename, "motif.dbg");
  101. for (argc--, argv++; argc; argc--, argv++)
  102. {
  103. if (strcmp("-debug", *argv) == 0)
  104. {
  105. DEBUG=TRUE;
  106. }
  107. else if ((strcmp("-o", *argv) == 0))
  108. {
  109. strcpy(outfilename, argv[1]);
  110. }
  111. }
  112. bfile = fopen(outfilename, "w");
  113. if (bfile == (FILE *) NULL)
  114. {
  115. printf("\nCouldnt't open %s", outfilename);
  116. exit (1);
  117. }
  118. if (DEBUG)
  119. {
  120. afile = fopen(debugfilename, "w");
  121. if (afile == (FILE *) NULL)
  122. {
  123. printf("\nCouldn't open %s", debugfilename);
  124. exit (1);
  125. }
  126. }
  127. emit_globals();
  128. /*
  129. * UilConst
  130. * UilSymArty
  131. * UilSymCset - parts of it
  132. * UilSymChCl
  133. */
  134. emit_chars(Constraint_Tab);
  135. emit_chars(Argument_Type_Table_Value);
  136. emit_chars(Charset_Wrdirection_Table);
  137. emit_chars(Charset_Parsdirection_Table);
  138. emit_chars(Charset_Charsize_Table);
  139. emit_chars(Child_Class_Table);
  140. /*
  141. * UilKeyTab
  142. */
  143. emit_ints_and_string (Key_Table);
  144. emit_ints_and_string (Key_Table_Case_Ins);
  145. /*
  146. * UilSymArTa
  147. * UilSymCtl
  148. * UilSymReas
  149. * UilSymChTa
  150. */
  151. emit_char_table (Allowed_Argument_Table);
  152. emit_char_table (Allowed_Control_Table);
  153. emit_char_table (Allowed_Reason_Table);
  154. emit_char_table (Allowed_Child_Table);
  155. /*
  156. * UilSymCset
  157. * UilSymNam
  158. * UilUrmClas
  159. */
  160. emit_length_and_string (Charset_Xmstring_Names_Table);
  161. emit_length_and_string (Charset_Lang_Names_Table);
  162. emit_length_and_string (Uil_Widget_Names);
  163. emit_length_and_string (Uil_Argument_Names);
  164. emit_length_and_string (Uil_Reason_Names);
  165. emit_length_and_string (Uil_Enumval_names);
  166. emit_length_and_string (Uil_Charset_Names);
  167. emit_length_and_string (Uil_Widget_Funcs);
  168. emit_length_and_string (Uil_Argument_Toolkit_Names);
  169. emit_length_and_string (Uil_Reason_Toolkit_Names);
  170. emit_length_and_string (Uil_Children_Names);
  171. /*
  172. * UilSymCset
  173. * UilSymEnum
  174. * UilSymRArg
  175. * UilUrmClas
  176. */
  177. emit_shorts (Charset_Lang_Codes_Table);
  178. emit_shorts (Argument_Enum_Set_Table);
  179. emit_shorts (Related_Argument_Table);
  180. emit_shorts (Uil_Gadget_Funcs);
  181. emit_shorts (Uil_Urm_Nondialog_Class);
  182. emit_shorts (Uil_Urm_Subtree_Resource);
  183. /*
  184. * UilSymEnum
  185. */
  186. emit_int_and_table_shorts(Enum_Set_Table);
  187. /*
  188. * UilSymEnum
  189. */
  190. emit_ints (Enumval_Values_Table);
  191. exit (0);
  192. }
  193. void emit_globals()
  194. {
  195. _db_globals globals;
  196. globals.version = DB_Compiled_Version;
  197. globals.uil_max_arg = uil_max_arg;
  198. globals.uil_max_charset = uil_max_charset;
  199. globals.charset_lang_table_max = charset_lang_table_max;
  200. globals.uil_max_object = uil_max_object;
  201. globals.uil_max_reason = uil_max_reason;
  202. globals.uil_max_enumval = uil_max_enumval;
  203. globals.uil_max_enumset = uil_max_enumset;
  204. globals.key_k_keyword_count = key_k_keyword_count;
  205. globals.key_k_keyword_max_length = key_k_keyword_max_length;
  206. globals.uil_max_child = uil_max_child;
  207. fwrite (&globals, sizeof (_db_globals), 1, bfile);
  208. if (DEBUG)
  209. fprintf(afile, "%d %d %d %d %d %d %d %d %d %d ", globals.version,
  210. globals.uil_max_arg, globals.uil_max_charset,
  211. globals.charset_lang_table_max, globals.uil_max_object,
  212. globals.uil_max_reason, globals.uil_max_enumval,
  213. globals.uil_max_enumset, globals.key_k_keyword_count,
  214. globals.key_k_keyword_max_length);
  215. }
  216. void emit_header(header)
  217. _db_header_ptr header;
  218. {
  219. fwrite (header, sizeof(_db_header), 1, bfile);
  220. if (DEBUG)
  221. fprintf(afile,
  222. "\n\nTableId=%d, NumEntries=%d, TableSize=%d \n",
  223. header->table_id, header->num_items, header->table_size);
  224. }
  225. void emit_chars(table_id)
  226. int table_id;
  227. {
  228. _db_header header;
  229. unsigned char *ptr;
  230. int i;
  231. switch (table_id)
  232. {
  233. case Constraint_Tab:
  234. /*
  235. * NOTE: The first entry is not used but we copy it anyway
  236. */
  237. header.table_size = sizeof(constraint_tab_vec);
  238. header.num_items = header.table_size;
  239. header.table_id = Constraint_Tab;
  240. ptr = constraint_tab;
  241. break;
  242. case Argument_Type_Table_Value:
  243. /*
  244. * NOTE: The first entry is not used but we copy it anyway
  245. */
  246. header.table_size = sizeof(argument_type_table_vec);
  247. header.num_items = header.table_size;
  248. header.table_id = Argument_Type_Table_Value;
  249. ptr = argument_type_table;
  250. break;
  251. case Charset_Wrdirection_Table:
  252. /*
  253. * NOTE: The first entry is not used but we copy it anyway
  254. */
  255. header.table_size = sizeof(charset_wrdirection_table_vec);
  256. header.num_items = header.table_size;
  257. header.table_id = Charset_Wrdirection_Table;
  258. ptr = charset_writing_direction_table;
  259. break;
  260. case Charset_Parsdirection_Table:
  261. /*
  262. * NOTE: The first entry is not used but we copy it anyway
  263. */
  264. header.table_size = sizeof(charset_parsdirection_table_vec);
  265. header.num_items = header.table_size;
  266. header.table_id = Charset_Parsdirection_Table;
  267. ptr = charset_parsing_direction_table;
  268. break;
  269. case Charset_Charsize_Table:
  270. /*
  271. * NOTE: The first entry is not used but we copy it anyway
  272. */
  273. header.table_size = sizeof(charset_charsize_table_vec);
  274. header.num_items = header.table_size;
  275. header.table_id = Charset_Charsize_Table;
  276. ptr = charset_character_size_table;
  277. break;
  278. case Child_Class_Table:
  279. /*
  280. * NOTE: The first entry is not used but we copy it anyway
  281. */
  282. header.table_size = sizeof(child_class_table_vec);
  283. header.num_items = header.table_size;
  284. header.table_id = Child_Class_Table;
  285. ptr = child_class_table;
  286. break;
  287. }
  288. emit_header(&header);
  289. fwrite (ptr, header.table_size, 1, bfile);
  290. if (DEBUG)
  291. {
  292. for (i=0; i<=header.num_items; i++)
  293. {
  294. fprintf(afile, "%d ", ptr[i]);
  295. }
  296. }
  297. }
  298. void emit_ints_and_string(table_id)
  299. int table_id;
  300. {
  301. _db_header header;
  302. key_keytable_entry_type *table;
  303. int i;
  304. switch (table_id)
  305. {
  306. /*
  307. * All tables are zero based unless otherwise noted
  308. */
  309. case Key_Table:
  310. header.table_size = sizeof(key_table_vec);
  311. header.num_items = key_k_keyword_count;
  312. header.table_id = Key_Table;
  313. table = key_table;
  314. break;
  315. case Key_Table_Case_Ins:
  316. header.table_size = sizeof(key_table_case_ins_vec);
  317. header.num_items = key_k_keyword_count;
  318. header.table_id = Key_Table_Case_Ins;
  319. table = key_table_case_ins;
  320. break;
  321. }
  322. emit_header(&header);
  323. fwrite (table, header.table_size, 1, bfile);
  324. for (i=0; i<header.num_items; i++)
  325. {
  326. fwrite (table[i].at_name, table[i].b_length + 1, 1, bfile);
  327. if (DEBUG)
  328. fprintf (afile, "%d %d %d %d %s", table[i].b_class, table[i].b_subclass,
  329. table[i].b_length, table[i].b_token, table[i].at_name);
  330. }
  331. }
  332. void emit_char_table(table_id)
  333. int table_id;
  334. {
  335. unsigned char **table;
  336. _db_header header;
  337. unsigned char *entry_vec;
  338. int i, j;
  339. int num_bits = (uil_max_object + 7) / 8;
  340. switch (table_id)
  341. {
  342. /*
  343. * All tables are 1 based unless otherwise specified
  344. */
  345. case Allowed_Argument_Table:
  346. header.table_size = sizeof(allowed_argument_table_vec);
  347. header.num_items = uil_max_arg;
  348. header.table_id = Allowed_Argument_Table;
  349. table = allowed_argument_table;
  350. break;
  351. case Allowed_Control_Table:
  352. header.table_size = sizeof(allowed_control_table_vec);
  353. header.num_items = uil_max_object;
  354. header.table_id = Allowed_Control_Table;
  355. table = allowed_control_table;
  356. break;
  357. case Allowed_Reason_Table:
  358. header.table_size = sizeof(allowed_reason_table_vec);
  359. header.num_items = uil_max_reason;
  360. header.table_id = Allowed_Reason_Table;
  361. table = allowed_reason_table;
  362. break;
  363. case Allowed_Child_Table:
  364. header.table_size = sizeof(allowed_child_table_vec);
  365. header.num_items = uil_max_child;
  366. header.table_id = Allowed_Child_Table;
  367. table = allowed_child_table;
  368. break;
  369. }
  370. emit_header(&header);
  371. for (i=1; i<=header.num_items; i++) /* First not used */
  372. {
  373. entry_vec = table[i];
  374. fwrite (entry_vec, sizeof (char) * num_bits, 1, bfile);
  375. if (DEBUG)
  376. {
  377. for (j=0; j<num_bits; j++)
  378. {
  379. fprintf (afile, "%d, ", entry_vec[j]);
  380. }
  381. fprintf (afile, "\n");
  382. }
  383. }
  384. }
  385. void emit_length_and_string(table_id)
  386. int table_id;
  387. {
  388. _db_header header;
  389. int *lengths;
  390. char *string_table;
  391. char **table;
  392. int i;
  393. switch (table_id)
  394. {
  395. /*
  396. * all the tables are 1 based unless otherwise documented
  397. */
  398. case Charset_Xmstring_Names_Table:
  399. header.table_size = sizeof(charset_xmstring_names_table_vec);
  400. header.num_items = uil_max_charset;
  401. header.table_id = Charset_Xmstring_Names_Table;
  402. table = charset_xmstring_names_table;
  403. break;
  404. case Charset_Lang_Names_Table:
  405. /*
  406. * This table is 0 based
  407. */
  408. header.table_size = sizeof(charset_lang_names_table_vec);
  409. header.num_items = charset_lang_table_max - 1;
  410. header.table_id = Charset_Lang_Names_Table;
  411. table = charset_lang_names_table;
  412. break;
  413. case Uil_Widget_Names:
  414. header.table_size = sizeof(uil_widget_names_vec);
  415. header.num_items = uil_max_object;
  416. header.table_id = Uil_Widget_Names;
  417. table = uil_widget_names ;
  418. break;
  419. case Uil_Argument_Names:
  420. header.table_size = sizeof(uil_argument_names_vec);
  421. header.num_items = uil_max_arg;
  422. header.table_id = Uil_Argument_Names;
  423. table = uil_argument_names;
  424. break;
  425. case Uil_Reason_Names:
  426. header.table_size = sizeof(uil_reason_names_vec);
  427. header.num_items = uil_max_reason;
  428. header.table_id = Uil_Reason_Names;
  429. table = uil_reason_names;
  430. break;
  431. case Uil_Enumval_names:
  432. header.table_size = sizeof(uil_enumval_names_vec);
  433. header.num_items = uil_max_enumval;
  434. header.table_id = Uil_Enumval_names;
  435. table = uil_enumval_names;
  436. break;
  437. case Uil_Charset_Names:
  438. header.table_size = sizeof(uil_charset_names_vec);
  439. header.num_items = uil_max_charset;
  440. header.table_id = Uil_Charset_Names;
  441. table = uil_charset_names;
  442. break;
  443. case Uil_Widget_Funcs:
  444. header.table_size = sizeof(uil_widget_funcs_vec);
  445. header.num_items = uil_max_object;
  446. header.table_id = Uil_Widget_Funcs;
  447. table = uil_widget_funcs;
  448. break;
  449. case Uil_Argument_Toolkit_Names:
  450. header.table_size = sizeof(uil_argument_toolkit_names_vec);
  451. header.num_items = uil_max_arg;
  452. header.table_id = Uil_Argument_Toolkit_Names;
  453. table = uil_argument_toolkit_names;
  454. break;
  455. case Uil_Reason_Toolkit_Names:
  456. header.table_size = sizeof(uil_reason_toolkit_names_vec);
  457. header.num_items = uil_max_reason;
  458. header.table_id = Uil_Reason_Toolkit_Names;
  459. table = uil_reason_toolkit_names;
  460. break;
  461. case Uil_Children_Names:
  462. header.table_size = sizeof(uil_child_names_vec);
  463. header.num_items = uil_max_child;
  464. header.table_id = Uil_Children_Names;
  465. table = uil_child_names ;
  466. break;
  467. }
  468. emit_header(&header);
  469. lengths = (int *) malloc (sizeof (int) * (header.num_items + 1));
  470. for (i=0; i<=header.num_items; i++)
  471. {
  472. if (table[i] != NULL)
  473. {
  474. /*
  475. * Add one to the length for the null terminator
  476. */
  477. lengths[i] = strlen(table[i]) + 1;
  478. }
  479. else
  480. {
  481. lengths[i] = 0;
  482. }
  483. if (DEBUG)
  484. fprintf (afile, "%d ", lengths[i]);
  485. }
  486. fwrite (lengths, sizeof (int) * (header.num_items + 1), 1, bfile);
  487. for (i=0; i<=header.num_items; i++)
  488. {
  489. if (lengths[i])
  490. {
  491. /*
  492. * assumed lengths[i] = lengths[i] * sizeof(char)
  493. * Add one for the null terminator
  494. */
  495. fwrite (table[i], lengths[i] + 1, 1, bfile);
  496. if (DEBUG)
  497. fprintf (afile, "%s ", table[i]);
  498. }
  499. }
  500. free (lengths);
  501. }
  502. void emit_shorts(table_id)
  503. int table_id;
  504. {
  505. _db_header header;
  506. unsigned short int *ptr;
  507. int i;
  508. switch (table_id)
  509. {
  510. /*
  511. * All tables are 1 based unless otherwise noted
  512. */
  513. case Charset_Lang_Codes_Table:
  514. /*
  515. * 0 based table
  516. */
  517. header.table_size = sizeof(charset_lang_codes_table_vec);
  518. header.num_items = charset_lang_table_max - 1;
  519. header.table_id = Charset_Lang_Codes_Table;
  520. ptr = charset_lang_codes_table;
  521. break;
  522. case Argument_Enum_Set_Table:
  523. header.table_size = sizeof(argument_enumset_table_vec);
  524. header.num_items = uil_max_arg;
  525. header.table_id = Argument_Enum_Set_Table;
  526. ptr = argument_enumset_table;
  527. break;
  528. case Related_Argument_Table:
  529. header.table_size = sizeof(related_argument_table_vec);
  530. header.num_items = uil_max_arg;
  531. header.table_id = Related_Argument_Table;
  532. ptr = related_argument_table;
  533. break;
  534. case Uil_Gadget_Funcs:
  535. header.table_size = sizeof(uil_gadget_variants_vec);
  536. header.num_items = uil_max_object;
  537. header.table_id = Uil_Gadget_Funcs;
  538. ptr = uil_gadget_variants;
  539. break;
  540. case Uil_Urm_Nondialog_Class:
  541. header.table_size = sizeof(uil_urm_nondialog_class_vec);
  542. header.num_items = uil_max_object;
  543. header.table_id = Uil_Urm_Nondialog_Class;
  544. ptr = uil_urm_nondialog_class;
  545. break;
  546. case Uil_Urm_Subtree_Resource:
  547. header.table_size = sizeof(uil_urm_subtree_resource_vec);
  548. header.num_items = uil_max_object;
  549. header.table_id = Uil_Urm_Subtree_Resource;
  550. ptr = uil_urm_subtree_resource;
  551. break;
  552. }
  553. emit_header(&header);
  554. fwrite (ptr, header.table_size, 1, bfile);
  555. if (DEBUG)
  556. {
  557. for (i=0; i<header.num_items; i++)
  558. {
  559. fprintf(afile, "%d ", ptr[i]);
  560. }
  561. }
  562. }
  563. void emit_int_and_table_shorts(table_id)
  564. int table_id;
  565. {
  566. _db_header header;
  567. UilEnumSetDescDef *table;
  568. int j, i;
  569. unsigned short int *value_vec;
  570. switch (table_id)
  571. {
  572. /*
  573. * All tables are 1 based unless otherwise noted
  574. */
  575. case Enum_Set_Table:
  576. header.table_size = sizeof(enum_set_table_vec);
  577. header.num_items = uil_max_enumset;
  578. header.table_id = Enum_Set_Table;
  579. table = enum_set_table;
  580. break;
  581. }
  582. emit_header(&header);
  583. fwrite (table, header.table_size, 1, bfile);
  584. for (i=0; i<=header.num_items; i++) /* first is not used */
  585. {
  586. if (table[i].values_cnt)
  587. {
  588. fwrite (table[i].values, sizeof (short) * table[i].values_cnt, 1, bfile);
  589. }
  590. }
  591. }
  592. void emit_ints(table_id)
  593. int table_id;
  594. {
  595. _db_header header;
  596. int *ptr;
  597. int i;
  598. switch (table_id)
  599. /*
  600. * all tables are 1 based unless otherwise noted
  601. */
  602. {
  603. case Enumval_Values_Table:
  604. header.table_size = sizeof(enumval_values_table_vec);
  605. header.num_items = uil_max_enumval;
  606. header.table_id = Enumval_Values_Table;
  607. ptr = enumval_values_table;
  608. break;
  609. }
  610. emit_header(&header);
  611. fwrite (ptr, header.table_size, 1, bfile);
  612. if (DEBUG)
  613. {
  614. for (i=0; i<header.num_items; i++)
  615. {
  616. fprintf(afile, "%d ", ptr[i]);
  617. }
  618. }
  619. }