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