2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
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.
35 static char rcsid[] = "$TOG: UilLstLst.c /main/20 1999/07/21 09:03:16 vipin $"
40 * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
46 ** User Interface Language Compiler (UIL)
50 ** This module contains the procedures for managing the UIL listing.
62 #include <X11/Intrinsic.h>
72 ** EXTERNAL storage used by the listing
79 ** OWN storage used by the listing
83 externaldef(uil_comp_glbl) char Uil_lst_c_title2[132];
85 static int lst_l_usable_lines;
86 static int lst_l_lines_left;
87 static int lst_l_page_no;
88 static char lst_c_title1[132];
89 static uil_fcb_type *lst_az_fcb;
90 static boolean lst_v_listing_open = FALSE;
95 ** FUNCTIONAL DESCRIPTION:
97 ** This function opens the UIL listing file to be written and
98 ** initializes OWN storage used by the listing package.
100 ** FORMAL PARAMETERS:
110 ** lst_l_usable_lines number of usable lines per page
111 ** lst_l_lines_left number of lines left on page
112 ** lst_l_page_no current page number
113 ** lst_c_title1 title line 1
114 ** Uil_lst_c_title2 title line 2
115 ** lst_v_listing_open can the listing be written to
123 ** listing file is opened
128 void lst_open_listing()
131 _Xctimeparams ctime_buf;
135 lst_az_fcb = (uil_fcb_type *)_get_memory( sizeof( uil_fcb_type ) );
137 /* open the listing file */
140 create_listing_file( lst_az_fcb );
142 if ( open_status == src_k_open_error )
144 diag_issue_diagnostic( d_listing_open,
145 diag_k_no_source, diag_k_no_column,
146 lst_az_fcb->expanded_name );
147 /* should never return - error is fatal */
152 lst_l_lines_left = 0;
154 lst_v_listing_open = TRUE;
156 sprintf(lst_c_title1,
157 "%s %s \t%s\t\t Page ",
158 _host_compiler, _compiler_version,
159 current_time(&ctime_buf));
162 ** Haven't parsed the module yet.
163 ** UilSarMod.c routines will fill it in.
166 Uil_lst_c_title2[ 0 ] = 0;
172 ** FUNCTIONAL DESCRIPTION:
174 ** This function does the clean up processing for the listing facility.
176 ** FORMAL PARAMETERS:
182 ** lst_c_title1 title line 1
183 ** Uil_lst_c_title2 title line 2
184 ** lst_v_listing_open can the listing be written to
196 ** dynamic memory is freed
201 void Uil_lst_cleanup_listing()
204 ** Check that there is a listing file requested and that
205 ** it is not already in error.
208 if (!(lst_v_listing_open && Uil_cmd_z_command.v_listing_file))
215 _free_memory((char*)lst_az_fcb);
227 ** FUNCTIONAL DESCRIPTION:
229 ** routine to create the listing file.
231 ** FORMAL PARAMETERS:
233 ** az_fcb file control block for the file
255 status create_listing_file( az_fcb )
257 uil_fcb_type *az_fcb;
260 /* place the file name in the expanded_name buffer */
262 strcpy(az_fcb->expanded_name, Uil_cmd_z_command.ac_listing_file);
266 az_fcb->az_file_ptr = fopen(Uil_cmd_z_command.ac_listing_file, "w");
268 if (az_fcb->az_file_ptr == NULL)
269 return src_k_open_error;
271 /* assume 66 lines on a page */
273 lst_l_usable_lines = 66 - 9;
275 return src_k_open_normal;
281 ** FUNCTIONAL DESCRIPTION:
283 ** function to write a line to the listing file.
285 ** FORMAL PARAMETERS:
287 ** ac_line text of the line to output
292 ** lst_l_usable_lines
307 ** line output to file
313 void lst_output_line( ac_line, v_new_page )
321 if (!lst_v_listing_open)
325 ** Update the current file and call the Status callback routine to report
328 Uil_current_file = lst_az_fcb->expanded_name;
329 if (Uil_cmd_z_command.status_cb != (Uil_continue_type(*)())NULL)
330 diag_report_status();
333 if ((lst_l_lines_left <= 0) || v_new_page)
336 lst_l_lines_left = lst_l_usable_lines;
338 fprintf(lst_az_fcb->az_file_ptr,
340 lst_c_title1, lst_l_page_no, Uil_lst_c_title2);
343 error_status = fprintf(lst_az_fcb->az_file_ptr, "%s\n", ac_line);
345 if (error_status == EOF)
347 lst_v_listing_open = FALSE;
348 diag_issue_diagnostic( d_listing_write,
349 diag_k_no_source, diag_k_no_column,
350 lst_az_fcb->expanded_name );
361 ** FUNCTIONAL DESCRIPTION:
363 ** function to return ASCII date and time
365 ** FORMAL PARAMETERS:
379 ** pointer to a null terminated string
388 char *current_time(_Xctimeparams *ctime_buf)
390 time_t time_location;
393 time_location = time( 0 );
395 ascii_time = _XCtime( &time_location, *ctime_buf );
405 ** FUNCTIONAL DESCRIPTION:
407 ** This function outputs the UIL listing file
409 ** FORMAL PARAMETERS:
424 void lst_output_listing()
427 src_source_record_type *az_src_rec;
428 char src_buffer[ src_k_max_source_line_length+12 ];
433 ** Check that there is a listing file requested and that
434 ** it is not already in error.
437 if (!(lst_v_listing_open &&
438 Uil_cmd_z_command.v_listing_file)
443 ** Walk the list of source records.
446 for (az_src_rec = src_az_first_source_record;
448 az_src_rec = az_src_rec->az_next_source_record)
452 ** place the line and file number in the output buffer
455 sprintf(src_buffer, "%5d (%d)\t",
456 az_src_rec->w_line_number,
457 az_src_rec->b_file_number);
459 src_ptr = &(src_buffer[ strlen( src_buffer ) ]);
461 src_retrieve_source( az_src_rec, src_ptr );
464 ** filter standard unprintable characters if necessary
467 if ( az_src_rec->b_flags & src_m_unprintable_chars)
468 lex_filter_unprintable_chars( (unsigned char*)src_ptr, strlen( src_ptr ), 0 );
471 ** replace leading formfeed with a blank
474 if ( az_src_rec->b_flags & src_m_form_feed)
477 lst_output_line( src_buffer,
478 (az_src_rec->b_flags & src_m_form_feed) != 0 );
481 ** if the line has messages, get them displayed
484 if (az_src_rec->az_message_list != NULL)
486 lst_output_message_ptr_line( az_src_rec, src_ptr );
487 lst_output_messages( az_src_rec->az_message_list );
491 ** if the line has machine code, get it displayed if requested
494 if ( (Uil_cmd_z_command.v_show_machine_code) &&
495 (az_src_rec->w_machine_code_cnt > 0) )
497 lst_output_machine_code( az_src_rec );
503 ** output the orphan messages
506 if (src_az_orphan_messages != NULL)
507 lst_output_messages( src_az_orphan_messages );
510 ** output the file summary
513 lst_output_line( " ", FALSE );
515 for (i = 0; i <= src_l_last_source_file_number; i++) {
517 uil_fcb_type *az_fcb; /* file control block ptr */
520 az_fcb = src_az_source_file_table [i];
523 i, az_fcb->expanded_name );
524 lst_output_line( buffer, FALSE );
527 lst_output_line( " ", FALSE );
534 ** FUNCTIONAL DESCRIPTION:
536 ** This function outputs a list of messages to the UIL listing file
538 ** FORMAL PARAMETERS:
540 ** az_message_item ptr to start of the message list
555 ** messages are written to the listing file
560 void lst_output_messages( az_message_item )
562 src_message_item_type *az_message_item;
565 src_message_item_type *az_msg;
574 for (az_msg = az_message_item;
576 az_msg = az_msg->az_next_message)
578 current_pos = az_msg->b_source_pos;
580 if (last_pos < current_pos)
582 last_pos = current_pos;
583 if (last_pos == diag_k_no_column)
586 msg_no = (msg_no % 9) + 1;
590 sprintf(buffer, "%s (%d) %s",
591 diag_get_message_abbrev( az_msg->l_message_number ),
595 lst_output_line( buffer, FALSE );
598 lst_output_line( " ", FALSE );
605 ** FUNCTIONAL DESCRIPTION:
607 ** This function outputs a list of machine code items to the
610 ** FORMAL PARAMETERS:
612 ** az_src_rec ptr to a source record
627 ** machine code is written to the listing file
632 void lst_output_machine_code ( az_src_rec )
634 src_source_record_type *az_src_rec;
638 static src_machine_code_type * * mc_array = NULL;
639 static unsigned short mc_cnt = 0;
641 src_machine_code_type *az_code;
644 /* Go through the machine code list, and save the entries in
645 the array; traverse them in reverse order. Reuse the vector
646 if it is large enough. */
650 code_cnt = az_src_rec->w_machine_code_cnt;
652 if ((int)mc_cnt < code_cnt) {
653 if (mc_array != NULL) {
654 _free_memory ((char*)mc_array);
657 (src_machine_code_type * *)_get_memory (sizeof (char *) * code_cnt);
661 for (az_code = az_src_rec->az_machine_code_list, mc_i = 0;
663 az_code = az_code->az_next_machine_code, mc_i++) {
664 mc_array [mc_i] = az_code;
667 for (mc_i = code_cnt - 1; mc_i >= 0; mc_i--)
670 #define BIT_64_LONG ((sizeof(long)*8)==64)
672 #define OFFSET_COL (BIT_64_LONG ? 75 : 43) /*should be 75 on 64 bit mach, 43 on 32*/
673 #define TEXT_COL (BIT_64_LONG ? 82 : 50) /*82 on 64 bit mach, 50 on 32*/
674 #define BUF_LEN (BIT_64_LONG ? 164 : 132) /*164 on 64 bit mach. 132 on 32 bit mach.*/
675 #define HEX_PER_WORD 4
676 #define HEX_PER_LONG (BIT_64_LONG ? 16 : 8) /*should be 16 on 64 bit mach., 8 on 32 bit mach*/
678 #define LONG_PER_LINE 4
679 #define ASCII_PER_LINE (LONG_PER_LINE * sizeof (long))
681 unsigned short long_cnt, extra_byte_cnt, text_len, code_len,
682 line_cnt, extra_long_cnt, i, j, code_offset;
683 unsigned char buffer[ BUF_LEN + 1 ], * text_ptr,
684 hex_longword [HEX_PER_LONG + 1], line_written;
685 unsigned long * code_ptr;
687 unsigned long temp_long;
688 static unsigned short start_hex_long [4];
689 /*if 64-bit environment, it should have vals { 55, 38, 21, 4 };
690 if 32 bit environment, { 31, 22, 13, 4 };
692 start_hex_long[0]=(BIT_64_LONG ? 55 : 31);
693 start_hex_long[1]=(BIT_64_LONG ? 38 : 22);
694 start_hex_long[2]=(BIT_64_LONG ? 21 : 13);
698 az_code = mc_array [mc_i];
700 code_ptr = (unsigned long *)az_code -> data.c_data;
701 code_len = az_code -> w_code_len;
702 code_offset = az_code -> w_offset;
703 text_ptr = (unsigned char *)(& az_code -> data.c_data [code_len]);
704 text_len = strlen ((char *)text_ptr);
705 if (text_len > (unsigned short) (BUF_LEN - TEXT_COL + 1))
706 text_len = BUF_LEN - TEXT_COL + 1;
708 long_cnt = code_len / sizeof (char *);
709 line_cnt = long_cnt / LONG_PER_LINE;
710 extra_long_cnt = long_cnt % LONG_PER_LINE;
711 extra_byte_cnt = code_len % sizeof (char *);
713 _fill (buffer, ' ', sizeof buffer - 1);
716 sprintf ((char *)hex_longword, "%04X", code_offset);
717 _move (& buffer [OFFSET_COL - 1], hex_longword, HEX_PER_WORD);
719 _move (& buffer [TEXT_COL - 1], text_ptr, text_len);
720 buffer [TEXT_COL + text_len] = '\0';
722 line_written = FALSE;
725 ** Write out entire lines. Clear the text after the first line.
726 ** Filter all non-printable characters.
729 for (i = 0; i < line_cnt; i++) {
732 _move (& buffer [TEXT_COL - 1], code_ptr, ASCII_PER_LINE);
733 lex_filter_unprintable_chars ((unsigned char*)
734 & buffer [TEXT_COL - 1], ASCII_PER_LINE,
736 buffer [TEXT_COL - 1 + ASCII_PER_LINE] = '\0';
739 for (j = 0; j < LONG_PER_LINE; j++, code_ptr++) {
744 sprintf ((char *)hex_longword, "%lX", (* code_ptr));
747 sprintf ((char *)hex_longword, "%08X", (* code_ptr));
750 _move (& buffer [start_hex_long [j]],
751 hex_longword, HEX_PER_LONG);
756 lst_output_line((char*) buffer, FALSE );
759 code_offset += LONG_PER_LINE * sizeof (long);
760 sprintf ((char *)hex_longword, "%04X", code_offset);
761 _move (& buffer [OFFSET_COL - 1], hex_longword, HEX_PER_WORD);
763 if (i == 0 && text_len > 0) {
764 _fill (& buffer [TEXT_COL - 1], ' ', text_len);
768 /* Write out a partial line. */
770 if (extra_long_cnt > 0 || extra_byte_cnt > 0) {
775 ascii_cnt = (extra_long_cnt * sizeof (long)) + extra_byte_cnt;
776 _move (& buffer [TEXT_COL - 1], code_ptr, ascii_cnt);
777 lex_filter_unprintable_chars ((unsigned char*)
778 & buffer [TEXT_COL - 1], ascii_cnt,
780 buffer [TEXT_COL - 1 + ascii_cnt] = '\0';
783 /* Clear code from previous lines, keeping the offset and text if
786 _fill (buffer, ' ', OFFSET_COL - 1);
788 if (extra_long_cnt > 0) {
790 /* Format the code longwords. */
792 for (i = 0; i < extra_long_cnt; i++, code_ptr++) {
793 unsigned long temp_long;
795 /* _move( (char*) &temp_long, (char*) code_ptr, sizeof(temp_long));*/
796 sprintf ((char *)hex_longword, "%lX", (* code_ptr));
799 sprintf ((char *)hex_longword, "%08X", (*code_ptr));
802 _move (& buffer [start_hex_long [i]],
803 hex_longword, HEX_PER_LONG);
807 /* Format the extra code bytes. */
809 if (extra_byte_cnt > 0) {
811 unsigned char extra_bytes [sizeof (long)];
813 _move (extra_bytes, code_ptr, extra_byte_cnt);
814 _fill (hex_longword, ' ', HEX_PER_LONG);
815 for (l = extra_byte_cnt - 1; l >= 0; l--) {
818 & hex_longword [HEX_PER_LONG - (2 * (l + 1))],
819 "%02X", extra_bytes [l]);
822 & hex_longword [HEX_PER_LONG - (2 * (l + 1))],
823 "%02X", extra_bytes [extra_byte_cnt-l-1]);
826 _move (& buffer [start_hex_long [extra_long_cnt]],
827 hex_longword, HEX_PER_LONG);
830 /* Output the partial line. */
832 lst_output_line( (char*)buffer, FALSE );
838 if (! line_written) {
840 lst_output_line((char*) buffer, FALSE );
842 lst_output_line( " ", FALSE );
855 ** FUNCTIONAL DESCRIPTION:
857 ** This function outputs a pointer line showing the position of
858 ** diagnostics to the UIL listing file.
860 ** FORMAL PARAMETERS:
862 ** az_src_rec ptr to a source record
878 ** message ptr line is written to the listing file
883 void lst_output_message_ptr_line( az_src_rec, src_buffer )
885 src_source_record_type *az_src_rec;
889 src_message_item_type *az_msg;
890 char buffer[ src_k_max_source_line_length + 3 ];
896 boolean v_output_line;
898 if (_src_null_access_key( az_src_rec->z_access_key) )
905 ptr_buffer = &buffer[ 2 ];
907 az_msg = az_src_rec->az_message_list;
910 msg_pos = az_msg->b_source_pos;
911 if (msg_pos == diag_k_no_column)
914 v_output_line = FALSE;
916 for (pos = 0; c_char = src_buffer[ pos ], c_char != 0; )
921 ptr_buffer[ pos++ ] = '\t';
923 ptr_buffer[ pos++ ] = ' ';
928 msg_no = (msg_no % 9) + 1;
929 ptr_buffer[ pos++ ] = msg_no + '0';
930 v_output_line = TRUE;
933 az_msg = az_msg->az_next_message;
936 msg_pos = az_msg->b_source_pos;
937 if ((pos-1) == msg_pos) /* pos already advanced */
939 if (msg_pos == diag_k_no_column)
945 ptr_buffer[ pos ] = 0;
948 lst_output_line( buffer, FALSE );
956 ** FUNCTIONAL DESCRIPTION:
958 ** lst_debug_output sends debugging info to the listing file if
959 ** there is one; if not the output goes to standard output.
961 ** FORMAL PARAMETERS:
963 ** standard Xprintf argument list
967 ** lst_v_listing_open
979 ** print lines either in the listing file or to standard output
984 static int cur_pos=0;
985 static char buffer[132];
987 void lst_debug_output
991 va_list ap; /* ptr to variable length parameter */
994 ** establish the start of the parameter list
1000 ** check if the listing file is open for output
1003 if (lst_v_listing_open)
1008 vsprintf( &(buffer[cur_pos]), format, ap );
1010 for ( ptr=buffer; ptr[0] != '\0'; ptr += (count+1) )
1012 _assert( ptr <= &(buffer[132]), "Overflowed debug listing buffer" );
1013 count = strcspn( ptr, "\n" );
1014 if (count == strlen( ptr ))
1016 cur_pos = ptr - buffer + count;
1021 ptr[ count ] = '\0';
1023 lst_output_line( ptr, FALSE );
1029 vprintf( format, ap );