MODULE sca$report_output IDENT "T4.5-1" !************************************************************************* ! * ! © 2000 BY * ! COMPAQ COMPUTER CORPORATION * ! © 1996, 2000 BY * ! ELECTRONIC DATA SYSTEMS LIMITED * ! * ! THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED * ! ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE * ! INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER * ! COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY * ! OTHER PERSON. NO TITLE TO OR OWNERSHIP OF THE SOFTWARE IS HEREBY * ! TRANSFERRED. * ! * ! THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE * ! AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY COMPAQ COMPUTER * ! CORPORATION OR EDS. * ! * ! NEITHER COMPAQ NOR EDS ASSUME ANY RESPONSIBILITY FOR THE USE OR * ! RELIABILITY OF THIS SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY * ! COMPAQ. * ! * !************************************************************************* ! !+ ! Facility: ! ! SCA - Source Code Analyzer ! REPORT - Report Subfacility ! ! Abstract: ! ! This module contains the routines that deal with the output buffer. ! ! DESIGN ISSUES: ! ! Reports are generated into a TPU buffer. The buffer is dumped periodically ! during the generation of the report (typically at the end of processing a ! compilation unit). ! ! Each of the output routines is responsible for positioning itself to the ! output buffer, writing whatever there is to write, and returning to the ! original position. We make no promises concerning the current position in ! the output buffer. Therefore each routine must be sure to position itself ! properly, which usually means to the end of the output buffer. ! ! The global variable SCA$REPORT_OUTPUT_BUFFER always points to the output ! buffer. !- PROCEDURE sca$report_append_text (text_block, add_line_break) !++ ! FUNCTIONAL DESCRIPTION: ! ! This procedure writes a block of text to the output buffer. It optionally ! adds a trailing line break if the text block does not end in a line break. ! ! FORMAL PARAMETERS: ! ! text_block ! ! The block of text to write, as a string, range, or buffer. It may ! contain embedded line breaks. IN parameter. ! ! add_line_break ! ! If TRUE, the procedure will make sure that the text block ends in a ! line break, adding one if necessary. If FALSE, the procedure will not ! add a line break. ! ! IMPLICIT INPUTS: ! ! sca$report_output_buffer ! ! The buffer to use for output. !-- LOCAL saved_position; ON_ERROR [OTHERWISE] : sca$report_common_error_cleanup('SCA$REPORT_APPEND_TEXT'); ENDON_ERROR; saved_position := MARK(FREE_CURSOR); POSITION(sca$report_output_buffer); COPY_TEXT(text_block); IF add_line_break AND (CURRENT_OFFSET > 0) THEN SPLIT_LINE ENDIF; POSITION(saved_position); ENDPROCEDURE PROCEDURE sca$report_blank_line !++ ! FUNCTIONAL DESCRIPTION: ! ! This procedure appends a blank line to the output buffer. ! ! FORMAL PARAMETERS: ! ! NONE ! ! IMPLICIT INPUTS: ! ! sca$report_output_buffer ! ! The buffer to use for output. !-- LOCAL saved_position; ON_ERROR [OTHERWISE] : sca$report_common_error_cleanup('SCA$REPORT_BLANK_LINE'); ENDON_ERROR; saved_position := MARK(FREE_CURSOR); POSITION(sca$report_output_buffer); SPLIT_LINE; POSITION(saved_position); RETURN ENDPROCEDURE PROCEDURE sca$report_get_current_output_position (output_position) !++ ! FUNCTIONAL DESCRIPTION: ! ! This procedure gets the current output position. We do this with a ! procedure to preserve modularity. This way all explicit references to the ! output buffer are contained within this module. ! ! FORMAL PARAMETERS: ! ! output_position ! ! On returning from this procedure, this parameter will contain the ! current position in the output buffer, for use with a subsequent call to ! sca$report_set_output_position. OUT parameter. !-- LOCAL saved_position; ON_ERROR [OTHERWISE] : sca$report_common_error_cleanup('SCA$REPORT_GET_CURRENT_OUTPUT_POSITION'); ENDON_ERROR; saved_position := MARK(FREE_CURSOR); POSITION(sca$report_output_buffer); MOVE_HORIZONTAL(-1); output_position := MARK(FREE_CURSOR); MOVE_HORIZONTAL(1); POSITION(saved_position) ENDPROCEDURE PROCEDURE sca$report_open_buffer (buffer_name, buffer_variable) !++ ! FUNCTIONAL DESCRIPTION: ! ! This procedure sets up a TPU buffer that will contain the result of the ! report. ! ! FORMAL PARAMETERS: ! ! buffer_name ! ! The name to use for the buffer. IN parameter. ! ! buffer_variable ! ! A variable that will be assigned the value of the buffer that ! was created. INOUT parameter. ! ! SIDE EFFECTS: ! ! A new buffer will be created. !-- ON_ERROR [OTHERWISE] : sca$report_common_error_cleanup('SCA$REPORT_OPEN_BUFFER'); ENDON_ERROR; IF GET_INFO (buffer_variable,"TYPE") = UNSPECIFIED THEN buffer_variable := CREATE_BUFFER (buffer_name); SET (SYSTEM, buffer_variable); SET (NO_WRITE, buffer_variable); SET (MODIFIABLE, buffer_variable, ON); SET (LSE$MAX_UNDO,buffer_variable, 0); ENDIF; ENDPROCEDURE PROCEDURE sca$report_reset_output_position !++ ! FUNCTIONAL DESCRIPTION: ! ! This procedure resets the output position to what it was before the most ! recent call on sca$report_set_output_position. ! ! FORMAL PARAMETERS: ! ! None !-- LOCAL saved_position; ON_ERROR [OTHERWISE] : sca$report_common_error_cleanup('SCA$REPORT_RESET_OUTPUT_POSITION'); ENDON_ERROR; saved_position := MARK(FREE_CURSOR); POSITION(sca$report_output_buffer); POSITION(sca$report_output_buffer_position); POSITION(saved_position) ENDPROCEDURE PROCEDURE sca$report_set_output_position (output_position) !++ ! FUNCTIONAL DESCRIPTION: ! ! This procedure changes the output position. ! ! FORMAL PARAMETERS: ! ! output_position ! ! The new position. This must be a marker that was set via a call on ! sca$report_get_output_position. IN parameter. !-- LOCAL saved_position; ON_ERROR [OTHERWISE] : sca$report_common_error_cleanup('SCA$REPORT_SET_OUTPUT_POSITION'); ENDON_ERROR; saved_position := MARK(FREE_CURSOR); POSITION(sca$report_output_buffer); sca$report_output_buffer_position := MARK(FREE_CURSOR); POSITION(output_position); MOVE_HORIZONTAL(1); POSITION(saved_position) ENDPROCEDURE PROCEDURE sca$report_write_buffer !++ ! FUNCTIONAL DESCRIPTION: ! ! This procedure appends the current contents of the output buffer to the ! output file. ! ! FORMAL PARAMETERS: ! ! None !-- LOCAL success_state; ON_ERROR [TPU$_OPENOUT, TPU$_NOFILEACCESS, TPU$_WRITEERR] : ! Catch bad filespec errors - this is due to the user specifying ! a bad /OUTPUT qualifier, and shouldn't give a traceback. ! sca$report_status_message(ERROR_TEXT); ABORT; [OTHERWISE] : sca$report_common_error_cleanup('SCA$REPORT_WRITE_BUFFER'); ENDON_ERROR; ! Check for an empty buffer ! IF BEGINNING_OF(sca$report_output_buffer) = END_OF(sca$report_output_buffer) THEN RETURN; ENDIF; ! Disable success messages for the append operation. ! success_state := GET_INFO (SYSTEM, 'success'); set (success,off); ! Dump the buffer and, if necessary, append the resulting file to the ! output file. ! IF sca$report_work_file_spec = '' THEN ! The output file has not yet been created. Just write the report ! buffer to the target file. ! sca$report_work_file_spec := WRITE_FILE(sca$report_output_buffer, sca$report_work_file_name); ELSE ! The output file has already been created. Dump the buffer to ! a temporary file and then append that file to the output file. ! sca$report_temp_file_spec := WRITE_FILE (sca$report_output_buffer, sca$report_temp_file_name); SEND ('APPEND/NOCONFIRM/NOLOG -',sca$report_subprocess_id); SEND (sca$report_temp_file_spec + ' -', sca$report_subprocess_id); SEND (sca$report_work_file_spec, sca$report_subprocess_id); SEND ('DELETE/NOCONFIRM/NOLOG -', sca$report_subprocess_id); SEND (sca$report_temp_file_spec, sca$report_subprocess_id); ENDIF; ! Restore message setting ! IF success_state = 1 THEN set (success,on); ENDIF; ! Clear the contents of the report output buffer. ! ERASE (sca$report_output_buffer); ENDPROCEDURE ENDMODULE