UilDB.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  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: UilDB.c /main/11 1996/11/21 20:03:11 drk $"
  36. #endif
  37. #endif
  38. /*
  39. * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
  40. /*
  41. *++
  42. * FACILITY:
  43. *
  44. * UIL Bindary Database :
  45. *
  46. * ABSTRACT:
  47. *
  48. *--
  49. */
  50. /*
  51. * This file contains routines which change the internal tables of UIL based on
  52. * a binary data base parameter in the command line
  53. */
  54. /*
  55. *
  56. * INCLUDE FILES
  57. *
  58. */
  59. #ifndef X_NOT_STDC_ENV
  60. #include <stdlib.h>
  61. #include <unistd.h>
  62. #endif
  63. #include <Mrm/MrmAppl.h>
  64. #include <Mrm/Mrm.h>
  65. #include "UilDefI.h"
  66. #define X_INCLUDE_PWD_H
  67. #define XOS_USE_XT_LOCKING
  68. #include <X11/Xos_r.h>
  69. #include <stdio.h>
  70. /*
  71. *
  72. * TABLE OF CONTENTS
  73. *
  74. *
  75. */
  76. /*
  77. *
  78. * DEFINE and MACRO DEFINITIONS
  79. *
  80. */
  81. #define _check_read( __number_returned ) \
  82. if (( (__number_returned) != 1) || (feof(dbfile)) || (ferror(dbfile)) ) \
  83. { diag_issue_diagnostic( d_bad_database, diag_k_no_source, diag_k_no_column ); }
  84. /*
  85. *
  86. * EXTERNAL VARIABLE DECLARATIONS
  87. *
  88. */
  89. /*
  90. *
  91. * GLOBAL VARIABLE DECLARATIONS
  92. *
  93. */
  94. /*
  95. *
  96. * OWN VARIABLE DECLARATIONS
  97. *
  98. */
  99. static FILE *dbfile;
  100. static int num_bits;
  101. void db_incorporate()
  102. /*
  103. *++
  104. *
  105. * PROCEDURE DESCRIPTION:
  106. *
  107. * This routine incorporate the binary database passed in the command line.
  108. *
  109. *
  110. * FORMAL PARAMETERS:
  111. *
  112. * IMPLICIT INPUTS:
  113. *
  114. * IMPLICIT OUTPUTS:
  115. *
  116. * FUNCTION VALUE:
  117. *
  118. * SIDE EFFECTS:
  119. *
  120. *--
  121. */
  122. /*
  123. * External Functions
  124. */
  125. /*
  126. * Local variables
  127. */
  128. {
  129. int return_num_items;
  130. _db_header header;
  131. _db_globals globals;
  132. db_open_file();
  133. return_num_items = fread (&globals, sizeof(_db_globals), 1, dbfile);
  134. _check_read (return_num_items);
  135. /*
  136. * Some heuristics to see if this is a reasonable database.
  137. * The magic numbers are about 10 times as big as the DXm database
  138. * for DECWindows V3. The diagnostic does a fatal exit.
  139. */
  140. if ( globals.uil_max_arg>5000 ||
  141. globals.uil_max_charset>200 ||
  142. globals.charset_lang_table_max>1000 ||
  143. globals.uil_max_object>500 ||
  144. globals.uil_max_reason>1000 ||
  145. globals.uil_max_enumval>3000 ||
  146. globals.uil_max_enumset>1000 ||
  147. globals.key_k_keyword_count>10000 ||
  148. globals.key_k_keyword_max_length>200 ||
  149. globals.uil_max_child>250)
  150. diag_issue_diagnostic (d_bad_database,
  151. diag_k_no_source,
  152. diag_k_no_column);
  153. uil_max_arg = globals.uil_max_arg ;
  154. uil_max_charset = globals.uil_max_charset ;
  155. charset_lang_table_max = globals.charset_lang_table_max ;
  156. uil_max_object = globals.uil_max_object ;
  157. uil_max_reason = globals.uil_max_reason ;
  158. uil_max_enumval = globals.uil_max_enumval ;
  159. uil_max_enumset = globals.uil_max_enumset ;
  160. key_k_keyword_count = globals.key_k_keyword_count ;
  161. key_k_keyword_max_length = globals.key_k_keyword_max_length ;
  162. uil_max_child = globals.uil_max_child;
  163. num_bits = (uil_max_object +7) / 8;
  164. if (globals.version > DB_Compiled_Version)
  165. diag_issue_diagnostic( d_future_version, diag_k_no_source, diag_k_no_column );
  166. for (;;)
  167. {
  168. return_num_items = fread (&header, sizeof(_db_header), 1, dbfile);
  169. if (feof(dbfile)) break;
  170. _check_read (return_num_items);
  171. switch (header.table_id)
  172. {
  173. case Constraint_Tab:
  174. constraint_tab = (unsigned char *) XtMalloc (header.table_size);
  175. return_num_items = fread (constraint_tab,
  176. sizeof(unsigned char) * header.num_items,
  177. 1, dbfile);
  178. _check_read (return_num_items);
  179. break;
  180. case Argument_Type_Table_Value:
  181. /*
  182. * NOTE: The first entry is not used but we copy it anyway
  183. */
  184. argument_type_table = (unsigned char *) XtMalloc (header.table_size);
  185. return_num_items = fread (argument_type_table,
  186. sizeof(unsigned char) * header.num_items,
  187. 1, dbfile);
  188. _check_read (return_num_items);
  189. break;
  190. case Child_Class_Table:
  191. /*
  192. * NOTE: The first entry is not used but we copy it anyway
  193. */
  194. child_class_table =
  195. (unsigned char *) XtMalloc (header.table_size);
  196. return_num_items =
  197. fread (child_class_table,
  198. sizeof(unsigned char) * header.num_items, 1, dbfile);
  199. _check_read (return_num_items);
  200. break;
  201. case Charset_Wrdirection_Table:
  202. charset_writing_direction_table = (unsigned char *) XtMalloc (header.table_size);
  203. return_num_items = fread (charset_writing_direction_table,
  204. sizeof(unsigned char) * header.num_items,
  205. 1, dbfile);
  206. _check_read (return_num_items);
  207. break;
  208. case Charset_Parsdirection_Table:
  209. charset_parsing_direction_table = (unsigned char *) XtMalloc (header.table_size);
  210. return_num_items = fread (charset_parsing_direction_table,
  211. sizeof(unsigned char) * header.num_items,
  212. 1, dbfile);
  213. _check_read (return_num_items);
  214. break;
  215. case Charset_Charsize_Table:
  216. charset_character_size_table = (unsigned char *) XtMalloc (header.table_size);
  217. return_num_items = fread (charset_character_size_table,
  218. sizeof(unsigned char) * header.num_items,
  219. 1, dbfile);
  220. _check_read (return_num_items);
  221. break;
  222. case Key_Table:
  223. case Key_Table_Case_Ins:
  224. db_read_ints_and_string (&header);
  225. break;
  226. case Allowed_Argument_Table:
  227. case Allowed_Child_Table:
  228. case Allowed_Control_Table:
  229. case Allowed_Reason_Table:
  230. db_read_char_table (&header);
  231. break;
  232. case Charset_Xmstring_Names_Table:
  233. case Charset_Lang_Names_Table:
  234. case Uil_Widget_Names:
  235. case Uil_Children_Names:
  236. case Uil_Argument_Names:
  237. case Uil_Reason_Names:
  238. case Uil_Enumval_names:
  239. case Uil_Charset_Names:
  240. case Uil_Widget_Funcs:
  241. case Uil_Argument_Toolkit_Names:
  242. case Uil_Reason_Toolkit_Names:
  243. db_read_length_and_string (&header);
  244. break;
  245. case Charset_Lang_Codes_Table:
  246. charset_lang_codes_table = (unsigned short int *) XtMalloc (header.table_size);
  247. return_num_items = fread (charset_lang_codes_table,
  248. header.table_size,
  249. 1, dbfile);
  250. _check_read (return_num_items);
  251. break;
  252. case Argument_Enum_Set_Table:
  253. argument_enumset_table = (unsigned short int *) XtMalloc (header.table_size);
  254. return_num_items = fread (argument_enumset_table,
  255. header.table_size,
  256. 1, dbfile);
  257. _check_read (return_num_items);
  258. break;
  259. case Related_Argument_Table:
  260. related_argument_table = (unsigned short int *) XtMalloc (header.table_size);
  261. return_num_items = fread (related_argument_table,
  262. header.table_size,
  263. 1, dbfile);
  264. _check_read (return_num_items);
  265. break;
  266. case Uil_Gadget_Funcs:
  267. uil_gadget_variants = (unsigned short int *) XtMalloc (header.table_size);
  268. return_num_items = fread (uil_gadget_variants,
  269. header.table_size,
  270. 1, dbfile);
  271. _check_read (return_num_items);
  272. break;
  273. case Uil_Urm_Nondialog_Class:
  274. uil_urm_nondialog_class = (unsigned short int *) XtMalloc (header.table_size);
  275. return_num_items = fread (uil_urm_nondialog_class,
  276. header.table_size,
  277. 1, dbfile);
  278. _check_read (return_num_items);
  279. break;
  280. case Uil_Urm_Subtree_Resource:
  281. uil_urm_subtree_resource = (unsigned short int *) XtMalloc (header.table_size);
  282. return_num_items = fread (uil_urm_subtree_resource,
  283. header.table_size,
  284. 1, dbfile);
  285. _check_read (return_num_items);
  286. break;
  287. case Enum_Set_Table:
  288. db_read_int_and_shorts(&header);
  289. break;
  290. case Enumval_Values_Table:
  291. enumval_values_table = (int *) XtMalloc (header.table_size);
  292. return_num_items = fread (enumval_values_table,
  293. header.table_size,
  294. 1, dbfile);
  295. _check_read (return_num_items);
  296. break;
  297. default:
  298. diag_issue_diagnostic( d_bad_database, diag_k_no_source, diag_k_no_column );
  299. } /* end switch */
  300. } /* end for */
  301. fclose (dbfile);
  302. return;
  303. }
  304. void db_read_ints_and_string(header)
  305. _db_header_ptr header;
  306. /*
  307. *++
  308. *
  309. * PROCEDURE DESCRIPTION:
  310. *
  311. * This routine reads in tables of integers and one string unsigned chars and places them into
  312. * memory. It will Malloc new space for the table. The tables supported
  313. * this routine are:
  314. *
  315. * Key_Table:
  316. * Key_Table_Case_Ins:
  317. *
  318. *
  319. * FORMAL PARAMETERS:
  320. *
  321. * IMPLICIT INPUTS:
  322. *
  323. * IMPLICIT OUTPUTS:
  324. *
  325. * FUNCTION VALUE:
  326. *
  327. * SIDE EFFECTS:
  328. *
  329. *--
  330. */
  331. {
  332. /*
  333. * External Functions
  334. */
  335. /*
  336. * Local variables
  337. */
  338. int return_num_items, i, string_size=0;
  339. key_keytable_entry_type *table;
  340. char *string_table;
  341. switch (header->table_id)
  342. {
  343. /*
  344. * NOTE: Calloc is used here to protect against bad
  345. * pointers.
  346. */
  347. case Key_Table:
  348. key_table = (key_keytable_entry_type *) XtCalloc (1, header->table_size);
  349. table = key_table;
  350. break;
  351. case Key_Table_Case_Ins:
  352. key_table_case_ins = (key_keytable_entry_type *) XtCalloc (1, header->table_size);
  353. table = key_table_case_ins;
  354. break;
  355. default:
  356. diag_issue_internal_error ("Bad table_id in db_read_ints_and_string");
  357. }
  358. /*
  359. * Get the entire table with one read.
  360. * Then loop through the table and up the length of the strings.
  361. * Get all the strings with one read.
  362. * Reassign the addresses
  363. */
  364. return_num_items = fread(table, header->table_size, 1, dbfile);
  365. _check_read (return_num_items);
  366. for ( i=0 ; i<header->num_items; i++)
  367. {
  368. /*
  369. * Add one for the null character on the string
  370. */
  371. string_size += table[i].b_length + 1;
  372. };
  373. string_table = XtMalloc (sizeof (char) * string_size);
  374. return_num_items = fread(string_table,
  375. sizeof(unsigned char) * string_size,
  376. 1, dbfile);
  377. _check_read (return_num_items);
  378. for ( i=0 ; i<header->num_items; i++)
  379. {
  380. table[i].at_name = string_table;
  381. string_table += table[i].b_length + 1;
  382. };
  383. return;
  384. }
  385. void db_read_char_table(header)
  386. _db_header_ptr header;
  387. /*
  388. *++
  389. *
  390. * PROCEDURE DESCRIPTION:
  391. *
  392. * This routine reads in tables of unsigned chars and places them into
  393. * memory. It will Malloc new space for the table. The tables supported
  394. * this routine are:
  395. *
  396. * Allowed_Argument_Table:
  397. * Allowed_Child_Table:
  398. * Allowed_Control_Table:
  399. * Allowed_Reason_Table:
  400. *
  401. *
  402. * FORMAL PARAMETERS:
  403. *
  404. * IMPLICIT INPUTS:
  405. *
  406. * IMPLICIT OUTPUTS:
  407. *
  408. * FUNCTION VALUE:
  409. *
  410. * SIDE EFFECTS:
  411. *
  412. *--
  413. */
  414. {
  415. /*
  416. * External Functions
  417. */
  418. /*
  419. * Local variables
  420. */
  421. unsigned char **ptr;
  422. int return_num_items, i;
  423. unsigned char *table;
  424. switch (header->table_id)
  425. {
  426. /*
  427. * NOTE: Calloc is used here to protect against bad
  428. * pointers.
  429. */
  430. case Allowed_Argument_Table:
  431. allowed_argument_table = (unsigned char **) XtCalloc (1, header->table_size);
  432. ptr = allowed_argument_table;
  433. break;
  434. case Allowed_Child_Table:
  435. allowed_child_table =
  436. (unsigned char **) XtCalloc (1, header->table_size);
  437. ptr = allowed_child_table;
  438. break;
  439. case Allowed_Control_Table:
  440. allowed_control_table = (unsigned char **) XtCalloc (1, header->table_size);
  441. ptr = allowed_control_table;
  442. break;
  443. case Allowed_Reason_Table:
  444. allowed_reason_table = (unsigned char **) XtCalloc (1, header->table_size);
  445. ptr = allowed_reason_table;
  446. break;
  447. default:
  448. diag_issue_internal_error ("Bad table_id in db_read_char_table");
  449. }
  450. /*
  451. * Read in the entire table contents in one whack.
  452. * Then go through the table and set the addresses
  453. */
  454. table = (unsigned char *) XtMalloc (sizeof (unsigned char) * header->num_items * num_bits);
  455. return_num_items = fread(table,
  456. sizeof(char) * num_bits * header->num_items,
  457. 1, dbfile);
  458. _check_read (return_num_items);
  459. for ( i=1 ; i<=header->num_items; i++ )
  460. {
  461. ptr[i] = table;
  462. table += num_bits;
  463. };
  464. return;
  465. }
  466. void db_read_length_and_string(header)
  467. _db_header_ptr header;
  468. /*
  469. *++
  470. *
  471. * PROCEDURE DESCRIPTION:
  472. *
  473. * This routine reads in length and strings of unsigned chars and places them into
  474. * memory. It will Malloc new space for the table. The tables supported
  475. * this routine are:
  476. *
  477. * Charset_Xmstring_Names_Table:
  478. * Charset_Lang_Names_Table:
  479. * Uil_Widget_Names:
  480. * Uil_Children_Names:
  481. * Uil_Argument_Names:
  482. * Uil_Reason_Names:
  483. * Uil_Enumval_names:
  484. * Uil_Charset_Names:
  485. * Uil_Widget_Funcs:
  486. * Uil_Argument_Toolkit_Names:
  487. * Uil_Reason_Toolkit_Names:
  488. *
  489. *
  490. * FORMAL PARAMETERS:
  491. *
  492. * IMPLICIT INPUTS:
  493. *
  494. * IMPLICIT OUTPUTS:
  495. *
  496. * FUNCTION VALUE:
  497. *
  498. * SIDE EFFECTS:
  499. *
  500. *--
  501. */
  502. {
  503. /*
  504. * External Functions
  505. */
  506. /*
  507. * Local variables
  508. */
  509. int return_num_items, i, string_size=0;
  510. int *lengths;
  511. char *string_table;
  512. char **table;
  513. switch (header->table_id)
  514. {
  515. /*
  516. * NOTE: Calloc is used here because it might be possible to
  517. * have a string of zero length, particularly for the
  518. * first record. Ergo we Calloc to protect against bad
  519. * pointers.
  520. */
  521. case Charset_Xmstring_Names_Table:
  522. charset_xmstring_names_table = (char **) XtCalloc (1, header->table_size);
  523. table = charset_xmstring_names_table;
  524. break;
  525. case Charset_Lang_Names_Table:
  526. charset_lang_names_table = (char **) XtCalloc (1, header->table_size);
  527. table = charset_lang_names_table;
  528. break;
  529. case Uil_Widget_Names:
  530. uil_widget_names = (char **) XtCalloc (1, header->table_size);
  531. table = uil_widget_names ;
  532. break;
  533. case Uil_Children_Names:
  534. uil_child_names = (char **) XtCalloc (1, header->table_size);
  535. table = uil_child_names ;
  536. break;
  537. case Uil_Argument_Names:
  538. uil_argument_names = (char **) XtCalloc (1, header->table_size);
  539. table = uil_argument_names;
  540. break;
  541. case Uil_Reason_Names:
  542. uil_reason_names = (char **) XtCalloc (1, header->table_size);
  543. table = uil_reason_names;
  544. break;
  545. case Uil_Enumval_names:
  546. uil_enumval_names = (char **) XtCalloc (1, header->table_size);
  547. table = uil_enumval_names;
  548. break;
  549. case Uil_Charset_Names:
  550. uil_charset_names = (char **) XtCalloc (1, header->table_size);
  551. table = uil_charset_names;
  552. break;
  553. case Uil_Widget_Funcs:
  554. uil_widget_funcs = (char **) XtCalloc (1, header->table_size);
  555. table = uil_widget_funcs;
  556. break;
  557. case Uil_Argument_Toolkit_Names:
  558. uil_argument_toolkit_names = (char **) XtCalloc (1, header->table_size);
  559. table = uil_argument_toolkit_names;
  560. break;
  561. case Uil_Reason_Toolkit_Names:
  562. uil_reason_toolkit_names = (char **) XtCalloc (1, header->table_size);
  563. table = uil_reason_toolkit_names;
  564. break;
  565. default:
  566. diag_issue_internal_error ("Bad table_id in db_read_length_and_string");
  567. }
  568. /*
  569. * Get the lengths of all the strings with one read.
  570. * Then loop through the table and up the length of the strings.
  571. * Get all the strings with one read.
  572. * Reassign the addresses using the length table and string table.
  573. * Cleanup by Freeing length table.
  574. *
  575. * NOTE: In some tables the counting starts at 1 not 0 so you
  576. * have to be carefull.
  577. */
  578. lengths = (int *) XtMalloc (sizeof (int) * (header->num_items + 1));
  579. return_num_items = fread(lengths,
  580. sizeof(int) * (header->num_items + 1),
  581. 1, dbfile);
  582. _check_read (return_num_items);
  583. for ( i=0 ; i<=header->num_items; i++)
  584. {
  585. /*
  586. * Add one for the null terminator
  587. */
  588. if (lengths[i])
  589. {
  590. string_size += lengths[i] + 1;
  591. }
  592. }
  593. string_table = XtMalloc (sizeof (unsigned char) * string_size);
  594. return_num_items = fread(string_table,
  595. sizeof(unsigned char) * string_size,
  596. 1, dbfile);
  597. _check_read (return_num_items);
  598. for ( i=0 ; i<=header->num_items; i++)
  599. {
  600. if (lengths[i])
  601. {
  602. table[i] = string_table;
  603. /* BEGIN HaL Fix CR 5618 */
  604. if ((header->table_id == Uil_Widget_Names) &&
  605. (strcmp(table[i], "user_defined") == 0))
  606. uil_sym_user_defined_object = i;
  607. /* END HaL Fix CR 5618 */
  608. string_table += lengths[i] + 1;
  609. }
  610. }
  611. XtFree ((char *)lengths);
  612. return;
  613. }
  614. void db_read_int_and_shorts(header)
  615. _db_header_ptr header;
  616. /*
  617. *++
  618. *
  619. * PROCEDURE DESCRIPTION:
  620. *
  621. * This routine reads in a structure consisting of one integer and a
  622. * pointer to a table of integer and places them into
  623. * memory. It will Malloc new space for the table. The tables supported
  624. * this routine are:
  625. *
  626. * Enum_Set_Table:
  627. *
  628. *
  629. * FORMAL PARAMETERS:
  630. *
  631. * IMPLICIT INPUTS:
  632. *
  633. * IMPLICIT OUTPUTS:
  634. *
  635. * FUNCTION VALUE:
  636. *
  637. * SIDE EFFECTS:
  638. *
  639. *--
  640. */
  641. {
  642. /*
  643. * External Functions
  644. */
  645. /*
  646. * Local variables
  647. */
  648. int return_num_items, i, int_table_size=0;
  649. UilEnumSetDescDef *table;
  650. unsigned short int *int_table;
  651. switch (header->table_id)
  652. {
  653. case Enum_Set_Table:
  654. enum_set_table = (UilEnumSetDescDef *) XtCalloc (1, header->table_size);
  655. table = enum_set_table;
  656. break;
  657. default:
  658. diag_issue_internal_error ("Bad table_id in db_read_int_shorts");
  659. }
  660. /*
  661. * Get the entire table with one read.
  662. * Then loop through the table and add up the number of ints in each int table.
  663. * Get all the integer tables with one read.
  664. * Reassign the addresses of the tables.
  665. */
  666. return_num_items = fread(table, header->table_size, 1, dbfile);
  667. _check_read (return_num_items);
  668. for ( i=0 ; i<=header->num_items; i++)
  669. {
  670. int_table_size += table[i].values_cnt;
  671. }
  672. int_table = (unsigned short int *) XtCalloc (1, sizeof (short) * int_table_size);
  673. return_num_items = fread(int_table,
  674. sizeof(short) * int_table_size,
  675. 1, dbfile);
  676. _check_read (return_num_items);
  677. for ( i=0 ; i<=header->num_items; i++)
  678. {
  679. if (table[i].values_cnt)
  680. {
  681. table[i].values = int_table;
  682. int_table += table[i].values_cnt;
  683. }
  684. }
  685. return;
  686. }
  687. void db_open_file ()
  688. /*
  689. *++
  690. *
  691. * PROCEDURE DESCRIPTION:
  692. *
  693. * This routine opens the binary database file in a platform-dependent way,
  694. * performing i18n language switching in order to do so.
  695. *
  696. * Per the latest agreement on semantics, this routine does:
  697. * - first, try to open in the local directory (that is, with
  698. * no switching).
  699. * - second, try language switching and open
  700. *
  701. * FORMAL PARAMETERS:
  702. *
  703. * name A system-dependent string specifying the IDB file
  704. * to be opened.
  705. *
  706. * IMPLICIT INPUTS:
  707. *
  708. * IMPLICIT OUTPUTS:
  709. *
  710. * FUNCTION VALUE:
  711. *
  712. * SIDE EFFECTS:
  713. *
  714. *--
  715. */
  716. {
  717. /*
  718. * External Functions
  719. */
  720. /*
  721. * Local variables
  722. */
  723. char *resolvedname; /* current resolved name */
  724. SubstitutionRec subs[3];
  725. char *wmdPath;
  726. /*
  727. * Use XtFindFile instead of XtResolvePathName. XtResolvePathName requires a
  728. * display which UIL doesn't have. At the current time there is no support for
  729. * $LANG in the path string. If such support was deamed necessary, the %L, %l,
  730. * %t, %c values would be set up as subs here using globals from the fetch of
  731. * LANG variable used to determine the default codeset (or vice versa depending
  732. * on which is called first)
  733. *
  734. * If the last 4 characters of the file name are not .bdb
  735. * then pass in the suffix of .bdb. If a file isn't found with the suffix passed
  736. * in then try without the suffix.
  737. */
  738. /*
  739. * Make sure 'S' is the last one so we can remove the suffix for the first pass.
  740. */
  741. subs[0].match = 'N';
  742. subs[0].substitution = Uil_cmd_z_command.ac_database;
  743. subs[1].match = 'T';
  744. subs[1].substitution = "wmd";
  745. subs[2].match = 'S';
  746. subs[2].substitution = ".wmd";
  747. wmdPath = init_wmd_path(Uil_cmd_z_command.ac_database);
  748. resolvedname = 0;
  749. /*
  750. * Check and see if the .wmd suffix is already on the file. If not then try to
  751. * resolve the pathname with .wmd suffix first. If that fails or the suffix is
  752. * already on the file then just try to resolve the pathname.
  753. */
  754. if ( strcmp (&Uil_cmd_z_command.ac_database[strlen(Uil_cmd_z_command.ac_database)-4],".wmd") != 0 )
  755. resolvedname = XtFindFile(wmdPath,
  756. subs,
  757. XtNumber(subs),
  758. (XtFilePredicate)NULL);
  759. /*
  760. * No .wmd suffix or a failure to resolve the pathname with the .wmd suffix
  761. * Try without the suffix.
  762. */
  763. subs[2].substitution = "";
  764. if (resolvedname == 0)
  765. resolvedname = XtFindFile(wmdPath,
  766. subs,
  767. XtNumber(subs),
  768. (XtFilePredicate)NULL);
  769. if (resolvedname == 0)
  770. {
  771. diag_issue_diagnostic( d_wmd_open,
  772. diag_k_no_source, diag_k_no_column,
  773. Uil_cmd_z_command.ac_database);
  774. }
  775. dbfile = fopen (resolvedname, "r");
  776. /* If the file is not found, a fatal error is generated. */
  777. if (dbfile == NULL)
  778. {
  779. diag_issue_diagnostic( d_src_open,
  780. diag_k_no_source, diag_k_no_column,
  781. resolvedname);
  782. }
  783. return;
  784. }
  785. String get_root_dir_name()
  786. {
  787. int uid;
  788. _Xgetpwparams pwd_buf;
  789. struct passwd *pwd_value;
  790. static char *ptr = NULL;
  791. char *outptr;
  792. if (ptr == NULL)
  793. {
  794. if((ptr = (char *)getenv("HOME")) == NULL)
  795. {
  796. if((ptr = (char *)getenv(USER_VAR)) != NULL)
  797. {
  798. pwd_value = _XGetpwnam(ptr, pwd_buf);
  799. }
  800. else
  801. {
  802. uid = getuid();
  803. pwd_value = _XGetpwuid(uid, pwd_buf);
  804. }
  805. if (pwd_value != NULL)
  806. {
  807. ptr = pwd_value->pw_dir;
  808. }
  809. else
  810. {
  811. ptr = "";
  812. }
  813. }
  814. }
  815. outptr = XtMalloc (strlen(ptr) + 2);
  816. strcpy (outptr, ptr);
  817. strcat (outptr, "/");
  818. return outptr;
  819. }
  820. /*
  821. * XAPPLRES_DEFAULT and UIDPATH_DEFAULT are intentionally split to support
  822. * SCCS. DO NOT reformat the lines else %-N-%-S could be converted by SCCS into
  823. * something totally bizarre causing MrmOpenHierarchy failures.
  824. */
  825. /* The following are usually defined in the Makefile */
  826. #ifndef LIBDIR
  827. #define LIBDIR "/usr/lib/X11"
  828. #endif
  829. #ifndef INCDIR
  830. #define INCDIR "/usr/include/X11"
  831. #endif
  832. static char libdir[] = LIBDIR;
  833. static char incdir[] = INCDIR;
  834. static char XAPPLRES_DEFAULT[] = "\
  835. %%N\
  836. %%S:\
  837. %s/%%T/%%N\
  838. %%S:\
  839. %s%%T/%%N\
  840. %%S:\
  841. %s%%N\
  842. %%S:\
  843. %s/%%T/%%N\
  844. %%S:\
  845. %s/%%T/%%N\
  846. %%S";
  847. static char WMDPATH_DEFAULT[] = "\
  848. %%N\
  849. %%S:\
  850. %s%%T/%%N\
  851. %%S:\
  852. %s%%N\
  853. %%S:\
  854. %s/%%L/%%T/%%N\
  855. %%S:\
  856. %s/%%T/%%N\
  857. %%S";
  858. static char ABSOLUTE_PATH[] = "\
  859. %N\
  860. %S";
  861. String init_wmd_path(filename)
  862. String filename ;
  863. {
  864. String path;
  865. String old_path;
  866. String homedir;
  867. String wmd_path;
  868. if (filename[0] == '/')
  869. {
  870. wmd_path = XtMalloc(strlen(ABSOLUTE_PATH));
  871. strcpy (wmd_path, ABSOLUTE_PATH);
  872. }
  873. else
  874. {
  875. path = (char *)getenv ("WMDPATH");
  876. if (path == NULL)
  877. {
  878. homedir = get_root_dir_name();
  879. old_path = (char *)getenv ("XAPPLRESDIR");
  880. if (old_path == NULL)
  881. {
  882. wmd_path = XtCalloc(1, 2*strlen(homedir) +
  883. strlen(libdir) + strlen(incdir) +
  884. strlen(WMDPATH_DEFAULT));
  885. sprintf( wmd_path, WMDPATH_DEFAULT,
  886. homedir, homedir, libdir, incdir);
  887. }
  888. else
  889. {
  890. wmd_path = XtCalloc(1, 1*strlen(old_path) + 2*strlen(homedir) +
  891. strlen(libdir) + strlen(incdir) +
  892. strlen(XAPPLRES_DEFAULT));
  893. sprintf(wmd_path, XAPPLRES_DEFAULT,
  894. old_path,
  895. homedir, homedir, libdir, incdir);
  896. }
  897. XtFree (homedir);
  898. }
  899. else
  900. {
  901. wmd_path = XtMalloc(strlen(path) + 1);
  902. strcpy (wmd_path, path);
  903. free (path);
  904. }
  905. }
  906. return (wmd_path);
  907. }