UilDiags.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  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: UilDiags.c /main/15 1996/10/21 11:06:46 cde-osf $"
  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 contains the procedures for issuing diagnostics
  49. ** for the UIL compiler.
  50. **
  51. **
  52. **--
  53. **/
  54. /*
  55. **
  56. ** INCLUDE FILES
  57. **
  58. **/
  59. #include <stdio.h>
  60. #include <signal.h>
  61. #include <setjmp.h>
  62. #include <X11/Intrinsic.h>
  63. #include <X11/Xos.h>
  64. #include <Xm/Xm.h>
  65. #include <stdarg.h>
  66. #include "UilDefI.h"
  67. #include "UilMessTab.h"
  68. /*
  69. **
  70. ** EXTERNAL Storage
  71. **
  72. */
  73. externaldef(uil_comp_glbl) int Uil_message_count[uil_k_max_status+1];
  74. /*
  75. **
  76. ** OWN Storage
  77. **
  78. */
  79. static boolean issuing_diagnostic;
  80. static int Uil_diag_status_delay_count;
  81. /*
  82. * Fix for CR 5534 - static storage for old signal handlers
  83. */
  84. static void (*bus_handler)();
  85. static void (*sys_handler)();
  86. static void (*fpe_handler)();
  87. /*
  88. **++
  89. ** FUNCTIONAL DESCRIPTION:
  90. **
  91. ** diag_store_handlers saves the signal handlers from the calling
  92. ** application in global variables.
  93. **
  94. ** FORMAL PARAMETERS:
  95. **
  96. ** none
  97. **
  98. ** IMPLICIT INPUTS:
  99. **
  100. ** none
  101. **
  102. ** IMPLICIT OUTPUTS:
  103. **
  104. ** none
  105. **
  106. ** FUNCTION VALUE:
  107. **
  108. ** void
  109. **
  110. ** SIDE EFFECTS:
  111. **
  112. ** the global signal handler variables are changed.
  113. **
  114. **--
  115. **/
  116. void diag_store_handlers
  117. ( void )
  118. {
  119. /*
  120. * Fix for CR 5534 - set the file variables for holding previous bus handlers
  121. * to NULL and then store the old handlers (if any) when
  122. * calling signal for the Uil handlers
  123. */
  124. bus_handler = signal( SIGBUS, diag_handler ); /* access violations */
  125. #ifdef SIGSYS
  126. sys_handler = signal( SIGSYS, diag_handler ); /* bad arguments to sys calls */
  127. #endif
  128. fpe_handler = signal( SIGFPE, diag_handler ); /* overflows */
  129. /*
  130. * End Fix for CR 5534
  131. */
  132. }
  133. /*
  134. **++
  135. ** FUNCTIONAL DESCRIPTION:
  136. **
  137. ** diag_issue_diagnostic emits a diagnostic to the listing file if
  138. ** there is one and also sends an error to standard error file.
  139. **
  140. ** FORMAL PARAMETERS:
  141. **
  142. ** d_message_number: index of the error to issue. The indices are
  143. ** defined in message.h
  144. ** a_src_rec: pointer to the source record to issue the
  145. ** diagnostic against. This data structure has
  146. ** l_start_column: position within the source line for diagnostic.
  147. ** A negative value indicates no position.
  148. ** args: a variable length parameter list that holds the
  149. ** arguments to be substituted in the diagnositic
  150. **
  151. ** IMPLICIT INPUTS:
  152. **
  153. ** diag_rz_msg_table: table of messages and their severities defined
  154. ** in message_table.h
  155. ** diag_rl_external_code: Possible OS-specific external code
  156. **
  157. ** IMPLICIT OUTPUTS:
  158. **
  159. ** messages emitted
  160. **
  161. ** FUNCTION VALUE:
  162. **
  163. ** void
  164. **
  165. ** SIDE EFFECTS:
  166. **
  167. ** message counts updated
  168. **
  169. **--
  170. **/
  171. #define buf_size (src_k_max_source_line_length + 1)
  172. void diag_issue_diagnostic
  173. ( int d_message_number, src_source_record_type *az_src_rec,
  174. int l_start_column, ...)
  175. {
  176. va_list ap; /* ptr to variable length parameter */
  177. int severity; /* severity of message */
  178. int message_number; /* message number */
  179. char msg_buffer[132]; /* buffer to construct message */
  180. char ptr_buffer[buf_size]; /* buffer to construct pointer */
  181. char loc_buffer[132]; /* buffer to construct location */
  182. char src_buffer[buf_size]; /* buffer to hold source line */
  183. /*
  184. ** check if we are in a loop issuing errors
  185. */
  186. if (issuing_diagnostic)
  187. {
  188. _debug_output( "nested diagnostics issued" );
  189. Uil_message_count[ uil_k_severe_status ]++;
  190. uil_exit( uil_k_severe_status );
  191. }
  192. issuing_diagnostic = TRUE;
  193. /*
  194. ** determine the severity of the error. For d_submit_spr we issue
  195. ** the fix previous error diagnostic, if we encountered prior errors;
  196. ** otherwise we let it thru.
  197. */
  198. message_number = d_message_number;
  199. if (message_number == d_submit_spr)
  200. if (Uil_message_count[ uil_k_error_status ] > 0)
  201. message_number = d_prev_error;
  202. severity = diag_rz_msg_table[ message_number ].l_severity;
  203. /*
  204. ** check if messages of this severity are to be reported.
  205. */
  206. switch (severity)
  207. {
  208. case uil_k_info_status:
  209. if (Uil_cmd_z_command.v_report_info_msg)
  210. break;
  211. issuing_diagnostic = FALSE;
  212. return;
  213. case uil_k_warning_status:
  214. if (Uil_cmd_z_command.v_report_warn_msg)
  215. break;
  216. issuing_diagnostic = FALSE;
  217. return;
  218. default:
  219. ;
  220. }
  221. Uil_message_count[ severity ]++;
  222. if (severity > uil_l_compile_status)
  223. uil_l_compile_status = severity;
  224. /*
  225. ** Diagnostic format varies considerably
  226. ** 1) no source
  227. ** message
  228. ** 2) source but no column
  229. ** source line
  230. ** message
  231. ** location in source message
  232. ** 3) source and column
  233. ** source line
  234. ** column pointer
  235. ** message
  236. ** location in source message
  237. ** 4) source and column but no access key
  238. ** message
  239. ** location in source message
  240. */
  241. /*
  242. ** substitute any parameters into the error message placing the
  243. ** resultant string in msg_buffer
  244. */
  245. va_start(ap, l_start_column);
  246. #ifndef NO_MESSAGE_CATALOG
  247. vsprintf( msg_buffer,
  248. catgets(uil_catd, UIL_SET1, msg_cat_table[ message_number ],
  249. diag_rz_msg_table[ message_number ].ac_text),
  250. ap );
  251. #else
  252. vsprintf( msg_buffer,
  253. diag_rz_msg_table[ message_number ].ac_text,
  254. ap );
  255. #endif
  256. va_end(ap);
  257. src_buffer[ 0 ] = 0;
  258. loc_buffer[ 0 ] = 0;
  259. ptr_buffer[ 0 ] = 0;
  260. if (az_src_rec != diag_k_no_source)
  261. {
  262. if ( !_src_null_access_key(az_src_rec->z_access_key) )
  263. {
  264. /*
  265. ** create the location line line
  266. */
  267. #ifndef NO_MESSAGE_CATALOG
  268. sprintf( loc_buffer,
  269. catgets(uil_catd, UIL_SET_MISC,
  270. UIL_MISC_0, "\t\t line: %d file: %s"),
  271. az_src_rec->w_line_number,
  272. src_get_file_name( az_src_rec ) );
  273. #else
  274. sprintf( loc_buffer,
  275. "\t\t line: %d file: %s",
  276. az_src_rec->w_line_number,
  277. src_get_file_name( az_src_rec ) );
  278. #endif
  279. /*
  280. ** retrieve the source line
  281. */
  282. src_buffer[ 0 ] = '\t';
  283. src_retrieve_source( az_src_rec, &src_buffer[ 1 ] );
  284. /*
  285. ** filter the standard unprintable characters.
  286. */
  287. lex_filter_unprintable_chars
  288. ( (unsigned char *)src_buffer, strlen( src_buffer ), 0 );
  289. /*
  290. ** create the column pointer if a source position was given
  291. */
  292. if (l_start_column != diag_k_no_column)
  293. {
  294. int i;
  295. for (i=0; i < l_start_column+1; i++)
  296. {
  297. if (src_buffer[ i ] == '\t')
  298. ptr_buffer[ i ] = '\t';
  299. else
  300. ptr_buffer[ i ] = ' ';
  301. }
  302. ptr_buffer[ i++ ] = '*';
  303. ptr_buffer[ i ] = 0;
  304. }
  305. }
  306. else /* no access key */
  307. {
  308. /*
  309. ** create the location line line
  310. */
  311. if (l_start_column != diag_k_no_column)
  312. #ifndef NO_MESSAGE_CATALOG
  313. sprintf(loc_buffer,
  314. catgets(uil_catd, UIL_SET_MISC,
  315. UIL_MISC_1,
  316. "\t\t line: %d position: %d file: %s"),
  317. az_src_rec->w_line_number,
  318. l_start_column + 1,
  319. src_get_file_name( az_src_rec ) );
  320. #else
  321. sprintf(loc_buffer,
  322. "\t\t line: %d position: %d file: %s",
  323. az_src_rec->w_line_number,
  324. l_start_column + 1,
  325. src_get_file_name( az_src_rec ) );
  326. #endif
  327. else
  328. #ifndef NO_MESSAGE_CATALOG
  329. sprintf( loc_buffer, catgets(uil_catd, UIL_SET_MISC,
  330. UIL_MISC_0,
  331. "\t\t line: %d file: %s"),
  332. az_src_rec->w_line_number,
  333. src_get_file_name( az_src_rec ) );
  334. #else
  335. sprintf( loc_buffer,
  336. "\t\t line: %d file: %s",
  337. az_src_rec->w_line_number,
  338. src_get_file_name( az_src_rec ) );
  339. #endif
  340. }
  341. }
  342. /*
  343. ** issue the error to standard error file (system specific)
  344. */
  345. write_msg_to_standard_error
  346. ( message_number, src_buffer, ptr_buffer, msg_buffer, loc_buffer );
  347. /*
  348. ** if we have a listing, place message in the source structure
  349. */
  350. if (Uil_cmd_z_command.v_listing_file)
  351. src_append_diag_info
  352. ( az_src_rec, l_start_column, msg_buffer, message_number );
  353. issuing_diagnostic = FALSE;
  354. /*
  355. ** if there are fatal errors, print the listing file and exit.
  356. */
  357. if (Uil_message_count[ uil_k_severe_status] > 0)
  358. {
  359. lst_output_listing();
  360. uil_exit( uil_k_severe_status );
  361. }
  362. }
  363. /*
  364. **++
  365. ** FUNCTIONAL DESCRIPTION:
  366. **
  367. ** diag_issue_summary emits a diagnostic summary if any diagnostics
  368. ** were issued during the compilation
  369. **
  370. ** FORMAL PARAMETERS:
  371. **
  372. ** void
  373. **
  374. ** IMPLICIT INPUTS:
  375. **
  376. ** Uil_message_count table of messages issued
  377. **
  378. ** IMPLICIT OUTPUTS:
  379. **
  380. ** messages optionally emitted
  381. **
  382. ** FUNCTION VALUE:
  383. **
  384. ** void
  385. **
  386. ** SIDE EFFECTS:
  387. **
  388. ** none
  389. **
  390. **--
  391. **/
  392. void diag_issue_summary()
  393. {
  394. if (uil_l_compile_status == uil_k_success_status)
  395. return;
  396. Uil_cmd_z_command.v_report_info_msg = TRUE;
  397. diag_issue_diagnostic
  398. ( d_summary,
  399. diag_k_no_source, diag_k_no_column,
  400. Uil_message_count[ uil_k_error_status ],
  401. Uil_message_count[ uil_k_warning_status ],
  402. Uil_message_count[ uil_k_info_status ] );
  403. return;
  404. }
  405. /*
  406. **++
  407. ** FUNCTIONAL DESCRIPTION:
  408. **
  409. ** The major constructs in the UIL language each have a data structure
  410. ** and a tag value in the first byte of that data structure. Given
  411. ** a tag value, this routine will return a string that can be substituted
  412. ** in an error message to describe that construct.
  413. **
  414. ** FORMAL PARAMETERS:
  415. **
  416. ** b_tag
  417. **
  418. ** IMPLICIT INPUTS:
  419. **
  420. ** none
  421. **
  422. ** IMPLICIT OUTPUTS:
  423. **
  424. ** none
  425. **
  426. ** FUNCTION VALUE:
  427. **
  428. ** char * text corresponding to tag
  429. **
  430. ** SIDE EFFECTS:
  431. **
  432. ** none
  433. **
  434. **--
  435. **/
  436. char *diag_tag_text( b_tag )
  437. int XmConst b_tag;
  438. {
  439. switch (b_tag)
  440. {
  441. case sym_k_value_entry:
  442. return "value";
  443. case sym_k_widget_entry:
  444. return "widget";
  445. case sym_k_gadget_entry:
  446. return "gadget";
  447. case sym_k_child_entry:
  448. return "auto child";
  449. case sym_k_module_entry:
  450. return "module";
  451. case sym_k_proc_def_entry:
  452. case sym_k_proc_ref_entry:
  453. return "procedure";
  454. case sym_k_identifier_entry:
  455. return "identifier";
  456. /* These are used by the symbol table dumper. */
  457. case sym_k_argument_entry:
  458. return "argument";
  459. case sym_k_callback_entry:
  460. return "callback";
  461. case sym_k_control_entry:
  462. return "control";
  463. case sym_k_name_entry:
  464. return "name";
  465. case sym_k_forward_ref_entry:
  466. return "forward ref";
  467. case sym_k_external_def_entry:
  468. return "external def";
  469. case sym_k_list_entry:
  470. return "list";
  471. case sym_k_root_entry:
  472. return "root";
  473. case sym_k_include_file_entry:
  474. return "include file";
  475. case sym_k_def_obj_entry:
  476. return "default variant";
  477. case sym_k_section_entry:
  478. return "section";
  479. default:
  480. #ifndef NO_MESSAGE_CATALOG
  481. return (catgets(uil_catd, UIL_VALUES, UIL_VAL_1, "** unknown **"));
  482. #else
  483. return "** unknown **";
  484. #endif
  485. }
  486. }
  487. /*
  488. **++
  489. ** FUNCTIONAL DESCRIPTION:
  490. **
  491. ** Each widget in the UIL language has a integer value. Given this
  492. ** value, this routine will return a string that can be substituted
  493. ** in an error message to describe that widget.
  494. **
  495. ** FORMAL PARAMETERS:
  496. **
  497. ** b_type integer rep of the widget type
  498. **
  499. ** IMPLICIT INPUTS:
  500. **
  501. ** none
  502. **
  503. ** IMPLICIT OUTPUTS:
  504. **
  505. ** none
  506. **
  507. ** FUNCTION VALUE:
  508. **
  509. ** char * text corresponding to type
  510. **
  511. ** SIDE EFFECTS:
  512. **
  513. ** none
  514. **
  515. **--
  516. **/
  517. char *diag_object_text( b_type )
  518. int XmConst b_type;
  519. {
  520. if ( b_type <= sym_k_error_object )
  521. #ifndef NO_MESSAGE_CATALOG
  522. return (catgets(uil_catd, UIL_VALUES, UIL_VAL_0, "** error **"));
  523. #else
  524. return "** error **";
  525. #endif
  526. if ( b_type <= uil_max_object )
  527. return uil_widget_names[b_type];
  528. #ifndef NO_MESSAGE_CATALOG
  529. return (catgets(uil_catd, UIL_VALUES, UIL_VAL_1, "** unknown **"));
  530. #else
  531. return "** unknown **";
  532. #endif
  533. }
  534. /*
  535. **++
  536. ** FUNCTIONAL DESCRIPTION:
  537. **
  538. ** Each value in the UIL language has a integer value. Given this
  539. ** value, this routine will return a string that can be substituted
  540. ** in an error message to describe that value.
  541. **
  542. ** FORMAL PARAMETERS:
  543. **
  544. ** b_type integer rep of the value type
  545. **
  546. ** IMPLICIT INPUTS:
  547. **
  548. ** none
  549. **
  550. ** IMPLICIT OUTPUTS:
  551. **
  552. ** none
  553. **
  554. ** FUNCTION VALUE:
  555. **
  556. ** char * text corresponding to type
  557. **
  558. ** SIDE EFFECTS:
  559. **
  560. ** none
  561. **
  562. **--
  563. **/
  564. char *diag_value_text( b_type )
  565. int XmConst b_type;
  566. {
  567. if ( b_type <= sym_k_error_value )
  568. #ifndef NO_MESSAGE_CATALOG
  569. return (catgets(uil_catd, UIL_VALUES, UIL_VAL_0, "** error **"));
  570. #else
  571. return "** error **";
  572. #endif
  573. if ( b_type <= sym_k_max_value )
  574. return uil_datatype_names[b_type];
  575. #ifndef NO_MESSAGE_CATALOG
  576. return (catgets(uil_catd, UIL_VALUES, UIL_VAL_1, "** unknown **"));
  577. #else
  578. return "** unknown **";
  579. #endif
  580. }
  581. /*
  582. **++
  583. ** FUNCTIONAL DESCRIPTION:
  584. **
  585. ** Each charset supported by UIL has a integer value. Given this
  586. ** value, this routine will return a string that can be substituted
  587. ** in an error message to describe that charset.
  588. **
  589. ** FORMAL PARAMETERS:
  590. **
  591. ** b_type integer rep of the charset
  592. **
  593. ** IMPLICIT INPUTS:
  594. **
  595. ** none
  596. **
  597. ** IMPLICIT OUTPUTS:
  598. **
  599. ** none
  600. **
  601. ** FUNCTION VALUE:
  602. **
  603. ** char * text corresponding to type
  604. **
  605. ** SIDE EFFECTS:
  606. **
  607. ** none
  608. **
  609. **--
  610. **/
  611. char *diag_charset_text( b_type )
  612. int XmConst b_type;
  613. {
  614. if ( b_type <= sym_k_error_charset )
  615. #ifndef NO_MESSAGE_CATALOG
  616. return (catgets(uil_catd, UIL_VALUES, UIL_VAL_0, "** error **"));
  617. #else
  618. return "** error **";
  619. #endif
  620. if ( b_type <= uil_max_charset )
  621. return uil_charset_names[b_type];
  622. #ifndef NO_MESSAGE_CATALOG
  623. return (catgets(uil_catd, UIL_VALUES, UIL_VAL_1, "** unknown **"));
  624. #else
  625. return "** unknown **";
  626. #endif
  627. }
  628. /*
  629. **++
  630. ** FUNCTIONAL DESCRIPTION:
  631. **
  632. ** This routine initializes the diagnostic system. This includes
  633. ** establishes a handler for catastrophic errors and initializing
  634. ** error tables.
  635. **
  636. ** FORMAL PARAMETERS:
  637. **
  638. ** none
  639. **
  640. ** IMPLICIT INPUTS:
  641. **
  642. ** none
  643. **
  644. ** IMPLICIT OUTPUTS:
  645. **
  646. ** Uil_message_count
  647. ** issuing_diagnostic
  648. ** Uil_diag_status_delay_count
  649. **
  650. ** FUNCTION VALUE:
  651. **
  652. ** void
  653. **
  654. ** SIDE EFFECTS:
  655. **
  656. ** error handler is supplied for SIGBUS, SIGFPE and SIGSYS errors
  657. **
  658. **--
  659. **/
  660. void diag_initialize_diagnostics()
  661. {
  662. int i;
  663. /*
  664. ** Set up a handler to be invoked if access violations or
  665. ** bad arguments to sys calls occur.
  666. ** Other errors should be processed as is standard for the OS.
  667. */
  668. /*
  669. * Fix for CR 5534 - call diag_store_handlers to save the old signal handlers.
  670. */
  671. diag_store_handlers();
  672. /*
  673. * End Fix for CR 5534
  674. */
  675. signal( SIGBUS, diag_handler ); /* access violations */
  676. #ifdef SIGSYS
  677. signal( SIGSYS, diag_handler ); /* bad arguments to sys calls */
  678. #endif
  679. signal( SIGFPE, diag_handler ); /* overflows */
  680. /*
  681. ** Reset the message counts to zero.
  682. */
  683. for (i=0; i <= uil_k_max_status; i++)
  684. Uil_message_count[ i ] = 0;
  685. /*
  686. ** Clear the flag that we used to detect recursive error reporinting.
  687. */
  688. issuing_diagnostic = FALSE;
  689. /*
  690. ** Make sure there is no delay before starting to report status.
  691. */
  692. Uil_diag_status_delay_count = 0;
  693. }
  694. /*
  695. **++
  696. ** FUNCTIONAL DESCRIPTION:
  697. **
  698. ** This routine resets the handler for detecting overflows.
  699. **
  700. ** FORMAL PARAMETERS:
  701. **
  702. ** none
  703. **
  704. ** IMPLICIT INPUTS:
  705. **
  706. ** none
  707. **
  708. ** IMPLICIT OUTPUTS:
  709. **
  710. ** none
  711. **
  712. ** FUNCTION VALUE:
  713. **
  714. ** void
  715. **
  716. ** SIDE EFFECTS:
  717. **
  718. ** error handler is supplied for SIGFPE
  719. **
  720. **--
  721. **/
  722. void diag_reset_overflow_handler()
  723. {
  724. signal( SIGFPE, diag_handler ); /* overflows */
  725. }
  726. /*
  727. **++
  728. ** FUNCTIONAL DESCRIPTION:
  729. **
  730. ** This routine is the handler for internal errors.
  731. **
  732. ** FORMAL PARAMETERS:
  733. **
  734. ** l_error type of signal being raised
  735. **
  736. ** IMPLICIT INPUTS:
  737. **
  738. ** none
  739. **
  740. ** IMPLICIT OUTPUTS:
  741. **
  742. ** none
  743. **
  744. ** FUNCTION VALUE:
  745. **
  746. ** void
  747. **
  748. ** SIDE EFFECTS:
  749. **
  750. ** image will exit (done by diag_issue_diagnostic)
  751. **
  752. **--
  753. **/
  754. void diag_handler( l_error )
  755. int l_error;
  756. {
  757. /*
  758. ** This handler is invoked for access violations, oeverflows or bad
  759. ** arguments to sys calls. Other errors are processed as is standard
  760. ** for the OS. The handler checks on overflow to see if we are trying
  761. ** to catch them at the moment. Otherwise it issues an internal error.
  762. */
  763. if (l_error == SIGFPE)
  764. {
  765. if (uil_az_error_env_valid)
  766. {
  767. longjmp( uil_az_error_env_block, 1);
  768. }
  769. }
  770. #if debug_version
  771. {
  772. char *error_text;
  773. switch (l_error)
  774. {
  775. case SIGBUS:
  776. error_text = "Access Violation";
  777. break;
  778. #ifdef SIGSYS
  779. case SIGSYS:
  780. error_text = "Bad system call";
  781. break;
  782. #endif
  783. case SIGFPE:
  784. error_text = "Overflow";
  785. break;
  786. default:
  787. error_text = "Unknown reason";
  788. }
  789. diag_issue_internal_error( error_text );
  790. }
  791. #else
  792. diag_issue_internal_error( NULL );
  793. #endif
  794. /* we don't expect to come back */
  795. }
  796. /*
  797. **++
  798. ** FUNCTIONAL DESCRIPTION:
  799. **
  800. ** This routine issues an internal error.
  801. **
  802. ** FORMAL PARAMETERS:
  803. **
  804. ** error_text In the debug version this parameter holds a
  805. ** description of the internal error. In the
  806. ** non debug version it is omitted.
  807. **
  808. ** IMPLICIT INPUTS:
  809. **
  810. ** none
  811. **
  812. ** IMPLICIT OUTPUTS:
  813. **
  814. ** none
  815. **
  816. ** FUNCTION VALUE:
  817. **
  818. ** void
  819. **
  820. ** SIDE EFFECTS:
  821. **
  822. ** image will exit (done by diag_issue_diagnostic)
  823. **
  824. **--
  825. **/
  826. void diag_issue_internal_error( error_text )
  827. char * error_text;
  828. {
  829. /*
  830. ** This routine is a focal point for issuing internal errors.
  831. ** In DEBUG mode it takes an argument that gives more information
  832. ** about the failure.
  833. */
  834. #if debug_version
  835. diag_issue_diagnostic
  836. ( d_bug_check, diag_k_no_source, diag_k_no_column , error_text );
  837. #else
  838. diag_issue_diagnostic( d_submit_spr, diag_k_no_source, diag_k_no_column );
  839. #endif
  840. /* we don't expect to come back */
  841. }
  842. /*
  843. **++
  844. ** FUNCTIONAL DESCRIPTION:
  845. **
  846. ** this routine emits a diagnostic to stderr
  847. **
  848. ** FORMAL PARAMETERS:
  849. **
  850. ** msg_number: message number
  851. ** src_buffer: ptr to source buffer for the error
  852. ** ptr_buffer: ptr to column buffer locator for the error
  853. ** msg_buffer: ptr to message buffer for the error
  854. ** loc_buffer: ptr to location buffer for the error
  855. **
  856. ** IMPLICIT INPUTS:
  857. **
  858. ** none
  859. **
  860. ** IMPLICIT OUTPUTS:
  861. **
  862. ** messages emitted
  863. **
  864. ** FUNCTION VALUE:
  865. **
  866. ** void
  867. **
  868. ** SIDE EFFECTS:
  869. **
  870. ** none
  871. **
  872. **--
  873. **/
  874. static char XmConst success_text[1] = "";
  875. static char XmConst info_text[7] = "Info: ";
  876. static char XmConst warning_text[10] = "Warning: ";
  877. static char XmConst error_text[8] = "Error: ";
  878. static char XmConst severe_text[9] = "Severe: ";
  879. static char XmConst *severity_table [] =
  880. { success_text, info_text, warning_text, error_text, severe_text, };
  881. void write_msg_to_standard_error
  882. (message_number, src_buffer, ptr_buffer, msg_buffer, loc_buffer)
  883. XmConst int message_number;
  884. XmConst char *src_buffer;
  885. XmConst char *ptr_buffer;
  886. XmConst char *msg_buffer;
  887. XmConst char *loc_buffer;
  888. {
  889. /*
  890. ** If message callback was supplied, call it with the description of the
  891. ** error instead of writing it to standard output.
  892. */
  893. if (Uil_cmd_z_command.message_cb != (Uil_continue_type(*)())NULL)
  894. {
  895. Uil_status_type return_status;
  896. /*
  897. * Fix for 5534 - restore the old signal handers before calling message_cb
  898. * and restore the Uil signal handlers immediately afterwards
  899. */
  900. diag_restore_diagnostics();
  901. return_status = (*Uil_cmd_z_command.message_cb)(
  902. Uil_cmd_z_command.message_data,
  903. message_number,
  904. diag_rz_msg_table[ message_number ].l_severity,
  905. msg_buffer,
  906. src_buffer,
  907. ptr_buffer,
  908. loc_buffer,
  909. Uil_message_count);
  910. diag_store_handlers();
  911. /*
  912. * End Fix for 5534
  913. */
  914. /*
  915. ** If request is for termination, then longjmp back to main routine
  916. ** and set the return status to reflect user abort.
  917. */
  918. if (return_status == Uil_k_terminate)
  919. uil_exit (uil_k_error_status);
  920. else
  921. return;
  922. }
  923. /* print source line */
  924. fprintf ( stderr, "\n" );
  925. if (src_buffer[ 0 ] != 0)
  926. {
  927. fprintf ( stderr, "%s\n", src_buffer );
  928. }
  929. /* print the source column locator line */
  930. if (ptr_buffer[ 0 ] != 0)
  931. {
  932. fprintf ( stderr, "%s\n", ptr_buffer );
  933. }
  934. /* print message line */
  935. #ifndef NO_MESSAGE_CATALOG
  936. fprintf ( stderr, "%s%s\n",
  937. catgets(uil_catd, UIL_SET_MISC,
  938. diag_rz_msg_table[ message_number ].l_severity,
  939. severity_table
  940. [ diag_rz_msg_table[ message_number ].l_severity ]),
  941. msg_buffer );
  942. #else
  943. fprintf ( stderr, "%s%s\n",
  944. severity_table
  945. [ diag_rz_msg_table[ message_number ].l_severity ],
  946. msg_buffer );
  947. #endif
  948. /* print location line */
  949. if (loc_buffer[ 0 ] != 0)
  950. {
  951. fprintf ( stderr, "%s\n", loc_buffer );
  952. }
  953. }
  954. /*
  955. **++
  956. ** FUNCTIONAL DESCRIPTION:
  957. **
  958. ** function to return abbreviation for a message number
  959. **
  960. ** FORMAL PARAMETERS:
  961. **
  962. ** d_message_number message number to look up
  963. **
  964. ** IMPLICIT INPUTS:
  965. **
  966. ** none
  967. **
  968. ** IMPLICIT OUTPUTS:
  969. **
  970. ** none
  971. **
  972. ** FUNCTION VALUE:
  973. **
  974. ** ptr to text for message number
  975. **
  976. ** SIDE EFFECTS:
  977. **
  978. ** none
  979. **
  980. **--
  981. **/
  982. char XmConst *diag_get_message_abbrev( d_message_number )
  983. int d_message_number;
  984. {
  985. return
  986. severity_table[ diag_rz_msg_table[ d_message_number ].l_severity ];
  987. }
  988. /*
  989. **++
  990. ** FUNCTIONAL DESCRIPTION:
  991. **
  992. ** Routine to invoke the user-supplied status callback routine. If none
  993. ** is supplied this routine returns without error. Otherwise, the user's
  994. ** delay information is processed and if the requested criteria is met the
  995. ** user's routine is invoked. with parameters to describe the progress of
  996. ** the compilation.
  997. **
  998. ** FORMAL PARAMETERS:
  999. **
  1000. ** none
  1001. **
  1002. ** IMPLICIT INPUTS:
  1003. **
  1004. ** Uil_cmd_z_command_line
  1005. **
  1006. ** IMPLICIT OUTPUTS:
  1007. **
  1008. ** Uil_diag_status_delay_count
  1009. **
  1010. ** FUNCTION VALUE:
  1011. **
  1012. ** none
  1013. **
  1014. ** SIDE EFFECTS:
  1015. **
  1016. ** none
  1017. **
  1018. **--
  1019. **/
  1020. void diag_report_status ( )
  1021. {
  1022. Uil_continue_type return_status;
  1023. /*
  1024. ** If no status callback was supplied, just return.
  1025. */
  1026. if (Uil_cmd_z_command.status_cb == (Uil_continue_type(*)())NULL) return;
  1027. /*
  1028. ** If delay is used up (less than or equal to zero) then invoke the
  1029. ** callback, and reset the delay count.
  1030. */
  1031. if (Uil_diag_status_delay_count <= 0)
  1032. {
  1033. Uil_diag_status_delay_count = Uil_cmd_z_command.status_update_delay;
  1034. /*
  1035. * Fix for CR 5534 - restore the application signal handlers before calling
  1036. * status_cb and then return the Uil signal handlers
  1037. * immediately after.
  1038. */
  1039. diag_restore_diagnostics();
  1040. return_status = (*Uil_cmd_z_command.status_cb)(
  1041. Uil_cmd_z_command.status_data,
  1042. Uil_percent_complete,
  1043. Uil_lines_processed,
  1044. Uil_current_file,
  1045. Uil_message_count);
  1046. diag_store_handlers();
  1047. /*
  1048. * End Fix for CR 5534
  1049. */
  1050. /*
  1051. ** If request is for termination, then longjmp back to main routine
  1052. ** and set the return status to reflect user abort.
  1053. */
  1054. if (return_status == Uil_k_terminate)
  1055. {
  1056. uil_exit (uil_k_error_status);
  1057. }
  1058. }
  1059. /*
  1060. ** Delay not used-up, so decrement by one.
  1061. */
  1062. else
  1063. Uil_diag_status_delay_count--;
  1064. }
  1065. /*
  1066. **++
  1067. ** FUNCTIONAL DESCRIPTION:
  1068. **
  1069. ** This routine restores the old signal handlers that were replaced by
  1070. ** Uil. This routine is only called by the callable Uil.
  1071. **
  1072. ** FORMAL PARAMETERS:
  1073. **
  1074. ** none
  1075. **
  1076. ** IMPLICIT INPUTS:
  1077. **
  1078. ** none
  1079. **
  1080. ** IMPLICIT OUTPUTS:
  1081. **
  1082. ** none
  1083. **
  1084. ** FUNCTION VALUE:
  1085. **
  1086. ** void
  1087. **
  1088. ** SIDE EFFECTS:
  1089. **
  1090. ** error handlers for SIGBUS, SIGFPE and SIGSYS errors are restored to
  1091. ** pre-Uil condition.
  1092. **
  1093. **--
  1094. **/
  1095. void
  1096. diag_restore_diagnostics(void)
  1097. {
  1098. /*
  1099. * Fix for CR 5534 - restore the old signal handlers
  1100. */
  1101. signal( SIGBUS, bus_handler );
  1102. #ifdef SIGSYS
  1103. signal( SIGSYS, sys_handler );
  1104. #endif
  1105. signal( SIGFPE, fpe_handler );
  1106. /*
  1107. * End Fix for CR 5534
  1108. */
  1109. }