UilMain.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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: UilMain.c /main/14 1996/06/03 15:49:20 pascale $"
  36. #endif
  37. #endif
  38. /*
  39. * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
  40. /*
  41. **++
  42. ** FACILITY:
  43. **
  44. ** User Interface Language Compiler (UIL)
  45. **
  46. ** ABSTRACT:
  47. **
  48. ** This module is the main procedure of the UIL Compiler.
  49. **
  50. **--
  51. **/
  52. /*
  53. **
  54. ** INCLUDE FILES
  55. **
  56. */
  57. #include <X11/Xlocale.h>
  58. /* Sun's locale.h defines ON && OFF, which is also defined in UilLexPars.h */
  59. #ifdef ON
  60. #undef ON
  61. #endif
  62. #ifdef OFF
  63. #undef OFF
  64. #endif
  65. #ifndef X_NOT_STDC_ENV
  66. #include <stdlib.h>
  67. #endif
  68. #include "UilDefI.h"
  69. #include <setjmp.h>
  70. /*
  71. **
  72. ** TABLE OF CONTENTS
  73. **
  74. */
  75. /*
  76. ** FORWARD DECLARATIONS
  77. */
  78. extern int main _ARGUMENTS(( int l_argc , char *rac_argv []));
  79. static void common_main _ARGUMENTS(( void ));
  80. static void common_cleanup _ARGUMENTS(( void ));
  81. #ifdef CALLABLE
  82. static void UilWrapup _ARGUMENTS((Uil_compile_desc_type *compile_desc));
  83. #endif /* CALLABLE */
  84. /*
  85. **
  86. ** EXTERNAL Definitions
  87. **
  88. */
  89. #ifndef NO_MESSAGE_CATALOG
  90. #include <nl_types.h>
  91. #if !defined(NL_CAT_LOCALE)
  92. #define NL_CAT_LOCALE 0
  93. #endif
  94. externaldef(uilmsg) nl_catd uil_catd = NULL;
  95. #endif
  96. /*
  97. **
  98. ** MODULE Definitions
  99. **
  100. */
  101. static status return_status = 0;
  102. static jmp_buf environment;
  103. static unsigned module_flags = 0;
  104. static unsigned doing_exit = 0;
  105. /* Bit definitions for module_flags */
  106. #define compiler_called (1 << 0)
  107. /*
  108. **++
  109. ** FUNCTIONAL DESCRIPTION:
  110. **
  111. ** This is the common part of the main routine.
  112. **
  113. ** FORMAL PARAMETERS:
  114. **
  115. ** none
  116. **
  117. ** IMPLICIT INPUTS:
  118. **
  119. ** none
  120. **
  121. ** IMPLICIT OUTPUTS:
  122. **
  123. ** none
  124. **
  125. ** FUNCTION VALUE:
  126. **
  127. ** void
  128. **
  129. ** SIDE EFFECTS:
  130. **
  131. ** compilation occurs
  132. **
  133. **--
  134. **/
  135. static void common_main()
  136. {
  137. #ifndef NO_MESSAGE_CATALOG
  138. if (uil_catd == NULL)
  139. uil_catd = catopen("Uil", NL_CAT_LOCALE);
  140. #endif
  141. /* Initialize the X toolkit. */
  142. XtToolkitInitialize();
  143. /* use the user supplied data base instead */
  144. if (Uil_cmd_z_command.v_database)
  145. db_incorporate();
  146. /* initialize the diagnostic system */
  147. diag_initialize_diagnostics();
  148. /* initialize the symbol table */
  149. sym_initialize_storage();
  150. /* initialize the source */
  151. src_initialize_source();
  152. /* open listing file if requested */
  153. if (Uil_cmd_z_command.v_listing_file)
  154. lst_open_listing();
  155. /* initialize the lexical analyzer */
  156. lex_initialize_analyzer();
  157. /* initialize the keyword table */
  158. key_initialize();
  159. /* initialize the sar data structures */
  160. sar_initialize();
  161. /* call YACC to parse the source file */
  162. /* return 0 for success, 1 for failure */
  163. /* Make sure the root entry sections pointer is filled in */
  164. if (yyparse() != 0)
  165. diag_issue_diagnostic
  166. (d_inv_module, diag_k_no_source, diag_k_no_column);
  167. sym_az_root_entry->sections = sym_az_current_section_entry;
  168. /* call forward reference resolver */
  169. sem_resolve_forward_refs();
  170. /* call semantic validation */
  171. sem_validation ();
  172. /* call the output phase if requested */
  173. if (Uil_cmd_z_command.v_resource_file)
  174. sem_output_uid_file();
  175. /* call symbol table dumper - if requested */
  176. #if debug_version
  177. if (uil_v_dump_symbols == TRUE)
  178. sym_dump_symbols();
  179. #endif
  180. /* write compilation summary */
  181. diag_issue_summary();
  182. /* write listing file if requested */
  183. if (Uil_cmd_z_command.v_listing_file)
  184. lst_output_listing();
  185. /* Storage is not cleaned up, since we will exit */
  186. uil_exit( uil_l_compile_status );
  187. }
  188. /*
  189. **++
  190. ** FUNCTIONAL DESCRIPTION:
  191. **
  192. ** This is the image termination procedure for the UIL compiler.
  193. **
  194. ** FORMAL PARAMETERS:
  195. **
  196. ** severity status of compilation on exit
  197. **
  198. ** IMPLICIT INPUTS:
  199. **
  200. ** none
  201. **
  202. ** IMPLICIT OUTPUTS:
  203. **
  204. ** none
  205. **
  206. ** FUNCTION VALUE:
  207. **
  208. ** void
  209. **
  210. ** SIDE EFFECTS:
  211. **
  212. ** never return from this procedure
  213. **
  214. **--
  215. **/
  216. void uil_exit(severity)
  217. int severity;
  218. {
  219. /* Prevent multiple looping through this routine */
  220. if ( doing_exit ) return;
  221. doing_exit = 1;
  222. return_status = (severity >= uil_k_error_status);
  223. /* Close and remove the uid file if it's still open. */
  224. /* It will only be open if a severe error occurred during the output */
  225. /* of the uid file. */
  226. if (out_az_idbfile_id != NULL)
  227. UrmIdbCloseFile (out_az_idbfile_id, FALSE);
  228. /* If compiler called, return to calling program rather than */
  229. /* exiting process */
  230. if (module_flags & compiler_called)
  231. longjmp (environment, 1);
  232. /* RAP FIX for listing files */
  233. common_cleanup();
  234. exit(return_status);
  235. }
  236. #ifndef CALLABLE
  237. /*
  238. **++
  239. ** FUNCTIONAL DESCRIPTION:
  240. **
  241. ** This is the main routine
  242. **
  243. ** FORMAL PARAMETERS:
  244. **
  245. ** l_argc: the number of command line arguments
  246. ** rac_argv: an array of pointers to character array arguments
  247. **
  248. ** IMPLICIT INPUTS:
  249. **
  250. ** none
  251. **
  252. ** IMPLICIT OUTPUTS:
  253. **
  254. ** none
  255. **
  256. ** COMPLETION CODES:
  257. **
  258. ** 1 if errors; 0 otherwise
  259. **
  260. ** SIDE EFFECTS:
  261. **
  262. ** produce possibly a resource file and a listing file
  263. **--
  264. **/
  265. int main( l_argc, rac_argv )
  266. int l_argc;
  267. char *rac_argv[ ];
  268. {
  269. setlocale(LC_ALL, "");
  270. /* call routine to parse the command line */
  271. cmd_decode_command_line( l_argc, rac_argv );
  272. /* call common main routine */
  273. common_main();
  274. }
  275. #endif /* !CALLABLE */
  276. /*
  277. **++
  278. ** FUNCTIONAL DESCRIPTION:
  279. **
  280. ** This is the dynamic memory cleanup routine. It calls all facility
  281. ** provided cleanup routines so that dynamic structures can be released.
  282. **
  283. ** FORMAL PARAMETERS:
  284. **
  285. ** none
  286. **
  287. ** IMPLICIT INPUTS:
  288. **
  289. ** none
  290. **
  291. ** IMPLICIT OUTPUTS:
  292. **
  293. ** none
  294. **
  295. ** FUNCTION VALUE:
  296. **
  297. ** void
  298. **
  299. ** SIDE EFFECTS:
  300. **
  301. ** all dynamic memory is freed
  302. **
  303. **--
  304. **/
  305. static void common_cleanup()
  306. {
  307. /* cleanup the source file information */
  308. Uil_src_cleanup_source();
  309. /* cleanup listing facility */
  310. Uil_lst_cleanup_listing();
  311. /* cleanup the lexical analyzer */
  312. Uil_lex_cleanup_analyzer();
  313. return;
  314. }
  315. #ifdef CALLABLE
  316. /*
  317. **++
  318. ** FUNCTIONAL DESCRIPTION:
  319. **
  320. ** This is the callable entry point for the UIL Compiler.
  321. **
  322. ** FORMAL PARAMETERS:
  323. **
  324. ** command_desc pointer to data structure defining UIL command line
  325. **
  326. ** compile_desc pointer to data structure describing the results of
  327. ** the compilation.
  328. **
  329. ** message_cb callback routine to process messages
  330. **
  331. ** message_data user-data passed to the message_cb
  332. **
  333. ** status_cb callback routine to process messages
  334. **
  335. ** status_data user-data passed to the status_cb
  336. **
  337. **
  338. ** IMPLICIT INPUTS:
  339. **
  340. ** none
  341. **
  342. ** IMPLICIT OUTPUTS:
  343. **
  344. ** none
  345. **
  346. ** COMPLETION CODES:
  347. **
  348. ** uil$_normal if no errors; uil$_no_output otherwise
  349. **
  350. ** SIDE EFFECTS:
  351. **
  352. ** none
  353. **--
  354. **/
  355. Uil_status_type Uil
  356. (Uil_command_type *command_desc,
  357. Uil_compile_desc_type *compile_desc,
  358. Uil_continue_type (*message_cb)(),
  359. char *message_data,
  360. Uil_continue_type (*status_cb)(),
  361. char *status_data)
  362. {
  363. /* Indicate compiler called rather than being started via command line */
  364. module_flags = module_flags | compiler_called;
  365. doing_exit = 0;
  366. /* Initialize command line data structure */
  367. Uil_cmd_z_command.ac_database = command_desc -> database;
  368. Uil_cmd_z_command.v_database = command_desc -> database_flag;
  369. Uil_cmd_z_command.ac_source_file = command_desc -> source_file;
  370. Uil_cmd_z_command.ac_resource_file = command_desc -> resource_file;
  371. Uil_cmd_z_command.ac_listing_file = command_desc -> listing_file;
  372. Uil_cmd_z_command.include_dir_count = command_desc -> include_dir_count;
  373. Uil_cmd_z_command.ac_include_dir = command_desc -> include_dir;
  374. Uil_cmd_z_command.v_listing_file = command_desc -> listing_file_flag;
  375. Uil_cmd_z_command.v_resource_file = command_desc -> resource_file_flag;
  376. Uil_cmd_z_command.v_show_machine_code = command_desc -> machine_code_flag;
  377. Uil_cmd_z_command.v_report_info_msg = command_desc -> report_info_msg_flag;
  378. Uil_cmd_z_command.v_report_warn_msg = command_desc -> report_warn_msg_flag;
  379. Uil_cmd_z_command.v_parse_tree = command_desc -> parse_tree_flag;
  380. Uil_cmd_z_command.v_use_setlocale = command_desc -> use_setlocale_flag;
  381. Uil_cmd_z_command.v_issue_summary = command_desc -> issue_summary;
  382. Uil_cmd_z_command.status_update_delay = command_desc -> status_update_delay;
  383. Uil_cmd_z_command.message_cb = message_cb;
  384. Uil_cmd_z_command.message_data = message_data;
  385. Uil_cmd_z_command.status_cb = status_cb;
  386. Uil_cmd_z_command.status_data = status_data;
  387. /* The setjmp function allows us to unwind from a fatal error setjmp is */
  388. /* nonzero if we are returning from a fatal error */
  389. if (setjmp(environment) == 0) {
  390. /* use the user supplied data base instead. If no source file
  391. is given (this call is only to change the database), return at
  392. this point with a success. */
  393. if ( Uil_cmd_z_command.v_database )
  394. {
  395. db_incorporate ();
  396. if ( Uil_cmd_z_command.ac_source_file == NULL )
  397. uil_exit (uil_k_success_status);
  398. }
  399. /* initialize the diagnostic system */
  400. uil_l_compile_status = uil_k_success_status;
  401. diag_initialize_diagnostics();
  402. /* initialize the symbol table */
  403. sym_initialize_storage();
  404. /* initialize the source */
  405. src_initialize_source();
  406. /* open listing file if requested */
  407. if (Uil_cmd_z_command.v_listing_file)
  408. lst_open_listing();
  409. /* initialize the lexical analyzer */
  410. lex_initialize_analyzer();
  411. /* initialize the keyword table */
  412. key_initialize();
  413. /* initialize the sar data structures */
  414. sar_initialize();
  415. /* call YACC to parse the source file */
  416. /* return 0 for success, 1 for failure */
  417. /* Make sure the root entry sections pointer is filled in */
  418. if (yyparse() != 0)
  419. diag_issue_diagnostic
  420. (d_inv_module, diag_k_no_source, diag_k_no_column);
  421. sym_az_root_entry->sections = sym_az_current_section_entry;
  422. /* call forward reference resolver */
  423. sem_resolve_forward_refs();
  424. /* call semantic validation */
  425. sem_validation ();
  426. /* call the output phase if requested */
  427. if (Uil_cmd_z_command.v_resource_file)
  428. sem_output_uid_file();
  429. /* call symbol table dumper - if requested */
  430. #if debug_version
  431. if (uil_v_dump_symbols == TRUE)
  432. sym_dump_symbols();
  433. #endif
  434. /* Perform standard wrapup processing */
  435. UilWrapup (compile_desc);
  436. /*
  437. * Fix for CR 5534 - call the routine to restore the old signal handlers
  438. */
  439. diag_restore_diagnostics();
  440. /*
  441. * End Fix for CR 5534
  442. */
  443. /* exit with the compile status */
  444. return uil_l_compile_status;
  445. }
  446. /*
  447. ** longjmp return from setjmp. This is the case of a return via
  448. ** uil_exit the value return_status is set by uil_exit.
  449. */
  450. else
  451. {
  452. /* Do standard compiler wrapup */
  453. UilWrapup (compile_desc);
  454. /* return the status set by uil_exit */
  455. return uil_l_compile_status;
  456. }
  457. }
  458. /*
  459. * Local function to provide compiler wrapup processing. It is called both
  460. * from the longjmp and sequential paths in the callable compiler above.
  461. */
  462. static void UilWrapup (compile_desc)
  463. Uil_compile_desc_type *compile_desc;
  464. {
  465. int i; /* loop index for copying message counts */
  466. /* write compilation summary if requested */
  467. if ( Uil_cmd_z_command.v_issue_summary )
  468. diag_issue_summary();
  469. /* write listing file if requested */
  470. if (Uil_cmd_z_command.v_listing_file)
  471. lst_output_listing();
  472. /*
  473. ** fill in the "parse tree root" in the compile descriptor,
  474. ** and set the version for the compiler and the symbol table
  475. ** structure.
  476. */
  477. compile_desc->parse_tree_root = (char *)sym_az_root_entry;
  478. compile_desc->data_version = _data_version;
  479. compile_desc->compiler_version = _compiler_version_int;
  480. /* Fill in the message_summary array in the compile_desc */
  481. for (i = uil_k_min_status; i <= uil_k_max_status; i++)
  482. compile_desc->message_count[i] = Uil_message_count[i];
  483. /* If there are any error/severe messages, then don't return */
  484. /* a symbol table for the callable compiler - clean up here */
  485. if ( Uil_message_count[Uil_k_error_status]>0 ||
  486. Uil_message_count[Uil_k_severe_status]>0 )
  487. {
  488. Uil_cmd_z_command.v_parse_tree = FALSE;
  489. compile_desc->parse_tree_root = NULL;
  490. }
  491. /* Call the cleanup routine to free dynamic memory */
  492. common_cleanup();
  493. /* Cleanup storage; what is cleaned up depends on whether compiler */
  494. /* was called or not */
  495. Uil_sym_cleanup_storage (Uil_cmd_z_command.v_parse_tree!=1);
  496. }
  497. #endif /* CALLABLE */
  498. #ifdef NO_MEMMOVE
  499. /*
  500. **++
  501. ** FUNCTIONAL DESCRIPTION:
  502. **
  503. ** This is a memmove function that explicitly handles
  504. ** overlapping memory areas. Written in response to
  505. ** CR 4851.
  506. **
  507. ** FORMAL PARAMETERS:
  508. **
  509. ** same as memcpy
  510. **
  511. ** COMPLETION CODES:
  512. **
  513. ** same as memcpy
  514. **
  515. ** SIDE EFFECTS:
  516. **
  517. **--
  518. **/
  519. char *uil_mmove(s1, s2, n)
  520. char *s1, *s2;
  521. int n;
  522. {
  523. char *temp;
  524. if(s2 == s1)
  525. return(s2);
  526. if(s2 < s1 && s1 <= s2 + n){
  527. if(temp = (char *)malloc(n)){
  528. memcpy(temp, s2, n);
  529. memcpy(s1, temp, n);
  530. free(temp);
  531. return(s1);
  532. }
  533. printf("uil_mmove: Memory allocation failed!\n");
  534. exit(-1);
  535. }
  536. return((char *)memcpy(s1, s2, n));
  537. }
  538. #endif /* NO_MEMMOVE */