UilLstLst.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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: UilLstLst.c /main/20 1999/07/21 09:03:16 vipin $"
  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 managing the UIL listing.
  49. **
  50. **--
  51. **/
  52. /*
  53. **
  54. ** INCLUDE FILES
  55. **
  56. **/
  57. #include <X11/Intrinsic.h>
  58. #include <Xm/Xm.h>
  59. #include <stdarg.h>
  60. #include "UilDefI.h"
  61. /*
  62. **
  63. ** EXTERNAL storage used by the listing
  64. **
  65. */
  66. /*
  67. **
  68. ** OWN storage used by the listing
  69. **
  70. */
  71. externaldef(uil_comp_glbl) char Uil_lst_c_title2[132];
  72. static int lst_l_usable_lines;
  73. static int lst_l_lines_left;
  74. static int lst_l_page_no;
  75. static char lst_c_title1[132];
  76. static uil_fcb_type *lst_az_fcb;
  77. static boolean lst_v_listing_open = FALSE;
  78. /*
  79. **++
  80. ** FUNCTIONAL DESCRIPTION:
  81. **
  82. ** This function opens the UIL listing file to be written and
  83. ** initializes OWN storage used by the listing package.
  84. **
  85. ** FORMAL PARAMETERS:
  86. **
  87. ** none
  88. **
  89. ** IMPLICIT INPUTS:
  90. **
  91. ** none
  92. **
  93. ** IMPLICIT OUTPUTS:
  94. **
  95. ** lst_l_usable_lines number of usable lines per page
  96. ** lst_l_lines_left number of lines left on page
  97. ** lst_l_page_no current page number
  98. ** lst_c_title1 title line 1
  99. ** Uil_lst_c_title2 title line 2
  100. ** lst_v_listing_open can the listing be written to
  101. **
  102. ** FUNCTION VALUE:
  103. **
  104. ** void
  105. **
  106. ** SIDE EFFECTS:
  107. **
  108. ** listing file is opened
  109. **
  110. **--
  111. **/
  112. void lst_open_listing()
  113. {
  114. status open_status;
  115. _Xctimeparams ctime_buf;
  116. /* allocate fcb */
  117. lst_az_fcb = (uil_fcb_type *)_get_memory( sizeof( uil_fcb_type ) );
  118. /* open the listing file */
  119. open_status =
  120. create_listing_file( lst_az_fcb );
  121. if ( open_status == src_k_open_error )
  122. {
  123. diag_issue_diagnostic( d_listing_open,
  124. diag_k_no_source, diag_k_no_column,
  125. lst_az_fcb->expanded_name );
  126. /* should never return - error is fatal */
  127. return;
  128. }
  129. lst_l_lines_left = 0;
  130. lst_l_page_no = 0;
  131. lst_v_listing_open = TRUE;
  132. sprintf(lst_c_title1,
  133. "%s %s \t%s\t\t Page ",
  134. _host_compiler, _compiler_version,
  135. current_time(&ctime_buf));
  136. /*
  137. ** Haven't parsed the module yet.
  138. ** UilSarMod.c routines will fill it in.
  139. */
  140. Uil_lst_c_title2[ 0 ] = 0;
  141. }
  142. /*
  143. **++
  144. ** FUNCTIONAL DESCRIPTION:
  145. **
  146. ** This function does the clean up processing for the listing facility.
  147. **
  148. ** FORMAL PARAMETERS:
  149. **
  150. ** none
  151. **
  152. ** IMPLICIT INPUTS:
  153. **
  154. ** lst_c_title1 title line 1
  155. ** Uil_lst_c_title2 title line 2
  156. ** lst_v_listing_open can the listing be written to
  157. **
  158. ** IMPLICIT OUTPUTS:
  159. **
  160. ** none
  161. **
  162. ** FUNCTION VALUE:
  163. **
  164. ** void
  165. **
  166. ** SIDE EFFECTS:
  167. **
  168. ** dynamic memory is freed
  169. **
  170. **--
  171. **/
  172. void Uil_lst_cleanup_listing()
  173. {
  174. /*
  175. ** Check that there is a listing file requested and that
  176. ** it is not already in error.
  177. */
  178. if (!(lst_v_listing_open && Uil_cmd_z_command.v_listing_file))
  179. return;
  180. /*
  181. ** free fcb
  182. */
  183. _free_memory((char*)lst_az_fcb);
  184. lst_az_fcb = NULL;
  185. }
  186. /*
  187. **++
  188. ** FUNCTIONAL DESCRIPTION:
  189. **
  190. ** routine to create the listing file.
  191. **
  192. ** FORMAL PARAMETERS:
  193. **
  194. ** az_fcb file control block for the file
  195. **
  196. ** IMPLICIT INPUTS:
  197. **
  198. ** none
  199. **
  200. ** IMPLICIT OUTPUTS:
  201. **
  202. ** none
  203. **
  204. ** FUNCTION VALUE:
  205. **
  206. ** src_k_open_normal
  207. ** src_k_open_error
  208. **
  209. ** SIDE EFFECTS:
  210. **
  211. ** file is created
  212. **
  213. **--
  214. **/
  215. status create_listing_file( az_fcb )
  216. uil_fcb_type *az_fcb;
  217. {
  218. /* place the file name in the expanded_name buffer */
  219. strcpy(az_fcb->expanded_name, Uil_cmd_z_command.ac_listing_file);
  220. /* open the file */
  221. az_fcb->az_file_ptr = fopen(Uil_cmd_z_command.ac_listing_file, "w");
  222. if (az_fcb->az_file_ptr == NULL)
  223. return src_k_open_error;
  224. /* assume 66 lines on a page */
  225. lst_l_usable_lines = 66 - 9;
  226. return src_k_open_normal;
  227. }
  228. /*
  229. **++
  230. ** FUNCTIONAL DESCRIPTION:
  231. **
  232. ** function to write a line to the listing file.
  233. **
  234. ** FORMAL PARAMETERS:
  235. **
  236. ** ac_line text of the line to output
  237. **
  238. ** IMPLICIT INPUTS:
  239. **
  240. ** lst_l_lines_left
  241. ** lst_l_usable_lines
  242. ** lst_az_fcb
  243. ** lst_c_title1
  244. ** lst_c_title1
  245. **
  246. ** IMPLICIT OUTPUTS:
  247. **
  248. ** lst_l_lines_left
  249. **
  250. ** FUNCTION VALUE:
  251. **
  252. ** void
  253. **
  254. ** SIDE EFFECTS:
  255. **
  256. ** line output to file
  257. **
  258. **--
  259. **/
  260. void lst_output_line( ac_line, v_new_page )
  261. char *ac_line;
  262. boolean v_new_page;
  263. {
  264. status error_status;
  265. if (!lst_v_listing_open)
  266. return;
  267. /*
  268. ** Update the current file and call the Status callback routine to report
  269. ** our progress.
  270. */
  271. Uil_current_file = lst_az_fcb->expanded_name;
  272. if (Uil_cmd_z_command.status_cb != (Uil_continue_type(*)())NULL)
  273. diag_report_status();
  274. if ((lst_l_lines_left <= 0) || v_new_page)
  275. {
  276. lst_l_page_no ++;
  277. lst_l_lines_left = lst_l_usable_lines;
  278. fprintf(lst_az_fcb->az_file_ptr,
  279. "\f\n%s%d\n%s\n\n",
  280. lst_c_title1, lst_l_page_no, Uil_lst_c_title2);
  281. }
  282. error_status = fprintf(lst_az_fcb->az_file_ptr, "%s\n", ac_line);
  283. if (error_status == EOF)
  284. {
  285. lst_v_listing_open = FALSE;
  286. diag_issue_diagnostic( d_listing_write,
  287. diag_k_no_source, diag_k_no_column,
  288. lst_az_fcb->expanded_name );
  289. }
  290. lst_l_lines_left --;
  291. return;
  292. }
  293. /*
  294. **++
  295. ** FUNCTIONAL DESCRIPTION:
  296. **
  297. ** function to return ASCII date and time
  298. **
  299. ** FORMAL PARAMETERS:
  300. **
  301. ** void
  302. **
  303. ** IMPLICIT INPUTS:
  304. **
  305. ** void
  306. **
  307. ** IMPLICIT OUTPUTS:
  308. **
  309. ** void
  310. **
  311. ** FUNCTION VALUE:
  312. **
  313. ** pointer to a null terminated string
  314. **
  315. ** SIDE EFFECTS:
  316. **
  317. ** none
  318. **
  319. **--
  320. **/
  321. char *current_time(_Xctimeparams *ctime_buf)
  322. {
  323. time_t time_location;
  324. char *ascii_time;
  325. time_location = time( 0 );
  326. ascii_time = _XCtime( &time_location, *ctime_buf );
  327. ascii_time[24] = 0;
  328. return ascii_time;
  329. }
  330. /*
  331. **++
  332. ** FUNCTIONAL DESCRIPTION:
  333. **
  334. ** This function outputs the UIL listing file
  335. **
  336. ** FORMAL PARAMETERS:
  337. **
  338. **
  339. ** IMPLICIT INPUTS:
  340. **
  341. **
  342. ** IMPLICIT OUTPUTS:
  343. **
  344. **
  345. ** SIDE EFFECTS:
  346. **
  347. **
  348. **--
  349. **/
  350. void lst_output_listing()
  351. {
  352. src_source_record_type *az_src_rec;
  353. char src_buffer[ src_k_max_source_line_length+12 ];
  354. char *src_ptr;
  355. int i;
  356. /*
  357. ** Check that there is a listing file requested and that
  358. ** it is not already in error.
  359. */
  360. if (!(lst_v_listing_open &&
  361. Uil_cmd_z_command.v_listing_file)
  362. )
  363. return;
  364. /*
  365. ** Walk the list of source records.
  366. */
  367. for (az_src_rec = src_az_first_source_record;
  368. az_src_rec != NULL;
  369. az_src_rec = az_src_rec->az_next_source_record)
  370. {
  371. /*
  372. ** place the line and file number in the output buffer
  373. */
  374. sprintf(src_buffer, "%5d (%d)\t",
  375. az_src_rec->w_line_number,
  376. az_src_rec->b_file_number);
  377. src_ptr = &(src_buffer[ strlen( src_buffer ) ]);
  378. src_retrieve_source( az_src_rec, src_ptr );
  379. /*
  380. ** filter standard unprintable characters if necessary
  381. */
  382. if ( az_src_rec->b_flags & src_m_unprintable_chars)
  383. lex_filter_unprintable_chars( (unsigned char*)src_ptr, strlen( src_ptr ), 0 );
  384. /*
  385. ** replace leading formfeed with a blank
  386. */
  387. if ( az_src_rec->b_flags & src_m_form_feed)
  388. *src_ptr = ' ';
  389. lst_output_line( src_buffer,
  390. (az_src_rec->b_flags & src_m_form_feed) != 0 );
  391. /*
  392. ** if the line has messages, get them displayed
  393. */
  394. if (az_src_rec->az_message_list != NULL)
  395. {
  396. lst_output_message_ptr_line( az_src_rec, src_ptr );
  397. lst_output_messages( az_src_rec->az_message_list );
  398. }
  399. /*
  400. ** if the line has machine code, get it displayed if requested
  401. */
  402. if ( (Uil_cmd_z_command.v_show_machine_code) &&
  403. (az_src_rec->w_machine_code_cnt > 0) )
  404. {
  405. lst_output_machine_code( az_src_rec );
  406. }
  407. }
  408. /*
  409. ** output the orphan messages
  410. */
  411. if (src_az_orphan_messages != NULL)
  412. lst_output_messages( src_az_orphan_messages );
  413. /*
  414. ** output the file summary
  415. */
  416. lst_output_line( " ", FALSE );
  417. for (i = 0; i <= src_l_last_source_file_number; i++) {
  418. uil_fcb_type *az_fcb; /* file control block ptr */
  419. char buffer [132];
  420. az_fcb = src_az_source_file_table [i];
  421. sprintf (buffer,
  422. " File (%d) %s",
  423. i, az_fcb->expanded_name );
  424. lst_output_line( buffer, FALSE );
  425. }
  426. lst_output_line( " ", FALSE );
  427. return;
  428. }
  429. /*
  430. **++
  431. ** FUNCTIONAL DESCRIPTION:
  432. **
  433. ** This function outputs a list of messages to the UIL listing file
  434. **
  435. ** FORMAL PARAMETERS:
  436. **
  437. ** az_message_item ptr to start of the message list
  438. **
  439. ** IMPLICIT INPUTS:
  440. **
  441. **
  442. ** IMPLICIT OUTPUTS:
  443. **
  444. ** none
  445. **
  446. ** FUNCTION VALUE:
  447. **
  448. ** void
  449. **
  450. ** SIDE EFFECTS:
  451. **
  452. ** messages are written to the listing file
  453. **
  454. **--
  455. **/
  456. void lst_output_messages( az_message_item )
  457. src_message_item_type *az_message_item;
  458. {
  459. src_message_item_type *az_msg;
  460. char buffer[132];
  461. int msg_no;
  462. int last_pos;
  463. int current_pos;
  464. last_pos = -1;
  465. msg_no = 9;
  466. for (az_msg = az_message_item;
  467. az_msg != NULL;
  468. az_msg = az_msg->az_next_message)
  469. {
  470. current_pos = az_msg->b_source_pos;
  471. if (last_pos < current_pos)
  472. {
  473. last_pos = current_pos;
  474. if (last_pos == diag_k_no_column)
  475. msg_no = 0;
  476. else
  477. msg_no = (msg_no % 9) + 1;
  478. }
  479. sprintf(buffer, "%s (%d) %s",
  480. diag_get_message_abbrev( az_msg->l_message_number ),
  481. msg_no,
  482. az_msg->c_text);
  483. lst_output_line( buffer, FALSE );
  484. }
  485. lst_output_line( " ", FALSE );
  486. return;
  487. }
  488. /*
  489. **++
  490. ** FUNCTIONAL DESCRIPTION:
  491. **
  492. ** This function outputs a list of machine code items to the
  493. ** UIL listing file
  494. **
  495. ** FORMAL PARAMETERS:
  496. **
  497. ** az_src_rec ptr to a source record
  498. **
  499. ** IMPLICIT INPUTS:
  500. **
  501. **
  502. ** IMPLICIT OUTPUTS:
  503. **
  504. ** none
  505. **
  506. ** FUNCTION VALUE:
  507. **
  508. ** void
  509. **
  510. ** SIDE EFFECTS:
  511. **
  512. ** machine code is written to the listing file
  513. **
  514. **--
  515. **/
  516. void lst_output_machine_code ( az_src_rec )
  517. src_source_record_type *az_src_rec;
  518. {
  519. static src_machine_code_type * * mc_array = NULL;
  520. static unsigned short mc_cnt = 0;
  521. src_machine_code_type *az_code;
  522. int code_cnt, mc_i;
  523. /* Go through the machine code list, and save the entries in
  524. the array; traverse them in reverse order. Reuse the vector
  525. if it is large enough. */
  526. code_cnt = az_src_rec->w_machine_code_cnt;
  527. if ((int)mc_cnt < code_cnt) {
  528. if (mc_array != NULL) {
  529. _free_memory ((char*)mc_array);
  530. }
  531. mc_array =
  532. (src_machine_code_type * *)_get_memory (sizeof (char *) * code_cnt);
  533. mc_cnt = code_cnt;
  534. }
  535. for (az_code = az_src_rec->az_machine_code_list, mc_i = 0;
  536. az_code != NULL;
  537. az_code = az_code->az_next_machine_code, mc_i++) {
  538. mc_array [mc_i] = az_code;
  539. }
  540. for (mc_i = code_cnt - 1; mc_i >= 0; mc_i--)
  541. {
  542. #define BIT_64_LONG ((sizeof(long)*8)==64)
  543. #define OFFSET_COL (BIT_64_LONG ? 75 : 43) /*should be 75 on 64 bit mach, 43 on 32*/
  544. #define TEXT_COL (BIT_64_LONG ? 82 : 50) /*82 on 64 bit mach, 50 on 32*/
  545. #define BUF_LEN (BIT_64_LONG ? 164 : 132) /*164 on 64 bit mach. 132 on 32 bit mach.*/
  546. #define HEX_PER_WORD 4
  547. #define HEX_PER_LONG (BIT_64_LONG ? 16 : 8) /*should be 16 on 64 bit mach., 8 on 32 bit mach*/
  548. #define LONG_PER_LINE 4
  549. #define ASCII_PER_LINE (LONG_PER_LINE * sizeof (long))
  550. unsigned short long_cnt, extra_byte_cnt, text_len, code_len,
  551. line_cnt, extra_long_cnt, i, j, code_offset;
  552. unsigned char buffer[ BUF_LEN + 1 ], * text_ptr,
  553. hex_longword [HEX_PER_LONG + 1], line_written;
  554. unsigned long * code_ptr;
  555. unsigned long temp_long;
  556. static unsigned short start_hex_long [4];
  557. /*if 64-bit environment, it should have vals { 55, 38, 21, 4 };
  558. if 32 bit environment, { 31, 22, 13, 4 };
  559. */
  560. start_hex_long[0]=(BIT_64_LONG ? 55 : 31);
  561. start_hex_long[1]=(BIT_64_LONG ? 38 : 22);
  562. start_hex_long[2]=(BIT_64_LONG ? 21 : 13);
  563. start_hex_long[3]=4;
  564. az_code = mc_array [mc_i];
  565. code_ptr = (unsigned long *)az_code -> data.c_data;
  566. code_len = az_code -> w_code_len;
  567. code_offset = az_code -> w_offset;
  568. text_ptr = (unsigned char *)(& az_code -> data.c_data [code_len]);
  569. text_len = strlen ((char *)text_ptr);
  570. if (text_len > (unsigned short) (BUF_LEN - TEXT_COL + 1))
  571. text_len = BUF_LEN - TEXT_COL + 1;
  572. long_cnt = code_len / sizeof (char *);
  573. line_cnt = long_cnt / LONG_PER_LINE;
  574. extra_long_cnt = long_cnt % LONG_PER_LINE;
  575. extra_byte_cnt = code_len % sizeof (char *);
  576. _fill (buffer, ' ', sizeof buffer - 1);
  577. sprintf ((char *)hex_longword, "%04X", code_offset);
  578. _move (& buffer [OFFSET_COL - 1], hex_longword, HEX_PER_WORD);
  579. _move (& buffer [TEXT_COL - 1], text_ptr, text_len);
  580. buffer [TEXT_COL + text_len] = '\0';
  581. line_written = FALSE;
  582. /*
  583. ** Write out entire lines. Clear the text after the first line.
  584. ** Filter all non-printable characters.
  585. */
  586. for (i = 0; i < line_cnt; i++) {
  587. if (text_len == 0) {
  588. _move (& buffer [TEXT_COL - 1], code_ptr, ASCII_PER_LINE);
  589. lex_filter_unprintable_chars ((unsigned char*)
  590. & buffer [TEXT_COL - 1], ASCII_PER_LINE,
  591. lex_m_filter_tab );
  592. buffer [TEXT_COL - 1 + ASCII_PER_LINE] = '\0';
  593. }
  594. for (j = 0; j < LONG_PER_LINE; j++, code_ptr++) {
  595. if (BIT_64_LONG){
  596. sprintf ((char *)hex_longword, "%lX", (* code_ptr));
  597. }
  598. else{
  599. sprintf ((char *)hex_longword, "%08X", (* code_ptr));
  600. }
  601. _move (& buffer [start_hex_long [j]],
  602. hex_longword, HEX_PER_LONG);
  603. }
  604. lst_output_line((char*) buffer, FALSE );
  605. line_written = TRUE;
  606. code_offset += LONG_PER_LINE * sizeof (long);
  607. sprintf ((char *)hex_longword, "%04X", code_offset);
  608. _move (& buffer [OFFSET_COL - 1], hex_longword, HEX_PER_WORD);
  609. if (i == 0 && text_len > 0) {
  610. _fill (& buffer [TEXT_COL - 1], ' ', text_len);
  611. }
  612. }
  613. /* Write out a partial line. */
  614. if (extra_long_cnt > 0 || extra_byte_cnt > 0) {
  615. if (text_len == 0) {
  616. int ascii_cnt;
  617. ascii_cnt = (extra_long_cnt * sizeof (long)) + extra_byte_cnt;
  618. _move (& buffer [TEXT_COL - 1], code_ptr, ascii_cnt);
  619. lex_filter_unprintable_chars ((unsigned char*)
  620. & buffer [TEXT_COL - 1], ascii_cnt,
  621. lex_m_filter_tab );
  622. buffer [TEXT_COL - 1 + ascii_cnt] = '\0';
  623. }
  624. /* Clear code from previous lines, keeping the offset and text if
  625. it is there. */
  626. _fill (buffer, ' ', OFFSET_COL - 1);
  627. if (extra_long_cnt > 0) {
  628. /* Format the code longwords. */
  629. for (i = 0; i < extra_long_cnt; i++, code_ptr++) {
  630. unsigned long temp_long;
  631. if (BIT_64_LONG){
  632. /* _move( (char*) &temp_long, (char*) code_ptr, sizeof(temp_long));*/
  633. sprintf ((char *)hex_longword, "%lX", (* code_ptr));
  634. }
  635. else{
  636. sprintf ((char *)hex_longword, "%08X", (*code_ptr));
  637. }
  638. _move (& buffer [start_hex_long [i]],
  639. hex_longword, HEX_PER_LONG);
  640. }
  641. }
  642. /* Format the extra code bytes. */
  643. if (extra_byte_cnt > 0) {
  644. int l;
  645. unsigned char extra_bytes [sizeof (long)];
  646. _move (extra_bytes, code_ptr, extra_byte_cnt);
  647. _fill (hex_longword, ' ', HEX_PER_LONG);
  648. for (l = extra_byte_cnt - 1; l >= 0; l--) {
  649. if (BIT_64_LONG)
  650. sprintf ((char *)
  651. & hex_longword [HEX_PER_LONG - (2 * (l + 1))],
  652. "%02X", extra_bytes [l]);
  653. else
  654. sprintf ((char *)
  655. & hex_longword [HEX_PER_LONG - (2 * (l + 1))],
  656. "%02X", extra_bytes [extra_byte_cnt-l-1]);
  657. }
  658. _move (& buffer [start_hex_long [extra_long_cnt]],
  659. hex_longword, HEX_PER_LONG);
  660. }
  661. /* Output the partial line. */
  662. lst_output_line( (char*)buffer, FALSE );
  663. line_written = TRUE;
  664. }
  665. if (! line_written) {
  666. if (text_len > 0) {
  667. lst_output_line((char*) buffer, FALSE );
  668. } else {
  669. lst_output_line( " ", FALSE );
  670. }
  671. }
  672. }
  673. return;
  674. }
  675. /*
  676. **++
  677. ** FUNCTIONAL DESCRIPTION:
  678. **
  679. ** This function outputs a pointer line showing the position of
  680. ** diagnostics to the UIL listing file.
  681. **
  682. ** FORMAL PARAMETERS:
  683. **
  684. ** az_src_rec ptr to a source record
  685. **
  686. ** IMPLICIT INPUTS:
  687. **
  688. ** none
  689. **
  690. ** IMPLICIT OUTPUTS:
  691. **
  692. ** none
  693. **
  694. ** FUNCTION VALUE:
  695. **
  696. ** void
  697. **
  698. ** SIDE EFFECTS:
  699. **
  700. ** message ptr line is written to the listing file
  701. **
  702. **--
  703. **/
  704. void lst_output_message_ptr_line( az_src_rec, src_buffer )
  705. src_source_record_type *az_src_rec;
  706. char *src_buffer;
  707. {
  708. src_message_item_type *az_msg;
  709. char buffer[ src_k_max_source_line_length + 3 ];
  710. char *ptr_buffer;
  711. int msg_no;
  712. int pos;
  713. int msg_pos;
  714. char c_char;
  715. boolean v_output_line;
  716. if (_src_null_access_key( az_src_rec->z_access_key) )
  717. return;
  718. msg_no = 9;
  719. buffer[ 0 ] = '\t';
  720. buffer[ 1 ] = '\t';
  721. ptr_buffer = &buffer[ 2 ];
  722. az_msg = az_src_rec->az_message_list;
  723. if (az_msg == NULL)
  724. return;
  725. msg_pos = az_msg->b_source_pos;
  726. if (msg_pos == diag_k_no_column)
  727. return;
  728. v_output_line = FALSE;
  729. for (pos = 0; c_char = src_buffer[ pos ], c_char != 0; )
  730. {
  731. if (pos < msg_pos)
  732. {
  733. if (c_char == '\t')
  734. ptr_buffer[ pos++ ] = '\t';
  735. else
  736. ptr_buffer[ pos++ ] = ' ';
  737. continue;
  738. }
  739. msg_no = (msg_no % 9) + 1;
  740. ptr_buffer[ pos++ ] = msg_no + '0';
  741. v_output_line = TRUE;
  742. next_message:
  743. az_msg = az_msg->az_next_message;
  744. if (az_msg == NULL)
  745. goto finished_scan;
  746. msg_pos = az_msg->b_source_pos;
  747. if ((pos-1) == msg_pos) /* pos already advanced */
  748. goto next_message;
  749. if (msg_pos == diag_k_no_column)
  750. goto finished_scan;
  751. }
  752. finished_scan:
  753. ptr_buffer[ pos ] = 0;
  754. if (v_output_line)
  755. lst_output_line( buffer, FALSE );
  756. return;
  757. }
  758. /*
  759. **++
  760. ** FUNCTIONAL DESCRIPTION:
  761. **
  762. ** lst_debug_output sends debugging info to the listing file if
  763. ** there is one; if not the output goes to standard output.
  764. **
  765. ** FORMAL PARAMETERS:
  766. **
  767. ** standard Xprintf argument list
  768. **
  769. ** IMPLICIT INPUTS:
  770. **
  771. ** lst_v_listing_open
  772. **
  773. ** IMPLICIT OUTPUTS:
  774. **
  775. ** none
  776. **
  777. ** FUNCTION VALUE:
  778. **
  779. ** void
  780. **
  781. ** SIDE EFFECTS:
  782. **
  783. ** print lines either in the listing file or to standard output
  784. **
  785. **--
  786. **/
  787. static int cur_pos=0;
  788. static char buffer[132];
  789. void lst_debug_output
  790. (char *format, ...)
  791. {
  792. va_list ap; /* ptr to variable length parameter */
  793. /*
  794. ** establish the start of the parameter list
  795. */
  796. va_start(ap,format);
  797. /*
  798. ** check if the listing file is open for output
  799. */
  800. if (lst_v_listing_open)
  801. {
  802. int count;
  803. char *ptr;
  804. vsprintf( &(buffer[cur_pos]), format, ap );
  805. for ( ptr=buffer; ptr[0] != '\0'; ptr += (count+1) )
  806. {
  807. _assert( ptr <= &(buffer[132]), "Overflowed debug listing buffer" );
  808. count = strcspn( ptr, "\n" );
  809. if (count == strlen( ptr ))
  810. {
  811. cur_pos = ptr - buffer + count;
  812. return;
  813. }
  814. else
  815. {
  816. ptr[ count ] = '\0';
  817. }
  818. lst_output_line( ptr, FALSE );
  819. }
  820. cur_pos = 0;
  821. }
  822. else
  823. vprintf( format, ap );
  824. va_end(ap);
  825. }