Google
 

Trailing-Edge - PDP-10 Archives - bb-h138e-bm_tops20_v6_1_distr - 6-1-sources/scrnewins.bli
There are 10 other files named scrnewins.bli in the archive. Click here to see a list.
 %TITLE 'SCRNEWINS - insert a line on the screen'
MODULE SCRNEWINS (				! Insert a line on the screen
		IDENT = '1-022'			! File: SCRNEWINS.BLI Edit: JBS1022
		) =
BEGIN
!
!			  COPYRIGHT (c) 1981, 1985 BY
!	      DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
!		ALL RIGHTS RESERVED.
!
! 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 AND 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 DIGITAL EQUIPMENT
! CORPORATION.
!
! DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR  RELIABILITY  OF  ITS
! SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
!

!++
! FACILITY:	EDT -- The DEC Standard Editor
!
! ABSTRACT:
!
!	This module updates the screen information data structure to
!	reflect the insertion of a line.
!
! ENVIRONMENT:	Runs at any access mode - AST reentrant
!
! AUTHOR: Sharon M. Burlingame, CREATION DATE: September 15, 198E
!
! MODIFIED BY:
!
! 1-001	- Original.  SMB 15-Sep-1982.
! 1-002 - Remove the position parameter and assume EOB is last line.  SMB 06-Oct-1982
! 1-003 - Remove setting of SCR_PTR.  SMB 10-Oct-1982
! 1-004	- Add support for NOTRUNCATE mode.  JBS 11-Oct-1982
! 1-005	- Return the number of lines produced.  JBS 11-Oct-1982
! 1-006	- Fix a bug found by the QA system in finding a deleted line.  JBS 12-Oct-1982
! 1-007	- In NOTRUNCATE mode, leave room for the blob in lines after the first.  JBS 12-Oct-1982
! 1-008	- Fix call to EDT$$FMT_CHWID.  JBS 13-Oct-1982
! 1-009 - Use memory allocation counter.  SMB 18-Oct-1982
! 1-010	- When deleting lines from the screen data base, delete complete records.  JBS 23-Oct-1982
! 1-011	- If we delete the [EOB] line from the screen data base, clear the EOB pointer.  JBS 23-Oct-1982
! 1-012	- Allow up to five times the number of lines on the screen of screen data blocks.  JBS 24-Oct-1982
! 1-013	- [EOB] can only be inserted at the end of the screen data base.  JBS 24-Oct-1982
! 1-014	- Correct the code that uses the earliest deleted line.  JBS 25-Oct-1982
! 1-015	- Fix another bug in the code that searches for the earliest deleted line.  JBS 28-Oct-1982
! 1-016	- Maintain SCR_EDIT_MINPOS.  JBS 28-Oct-1982
! 1-017	- Use EDT$$SC_LNDEL to free a line block.  JBS 29-Oct-1982
! 1-018 - Add two parameters to help notruncate inserts.  SMB 03-Dec-1982
! 1-019	- Change the handling of SHF.  JBS 14-Dec-1982
! 1-020	- Fix tabbing at end of line in notruncate mode.  JBS 15-Dec-1982
! 1-021	- Remove the edit buffer.  JBS 27-Dec-1982
! 1-022	- Set the rebuild flag if we delete the cursor line.  JBS 03-Jan-1983
!--
%SBTTL 'Declarations'
!
! TABLE OF CONTENTS:
!

REQUIRE 'EDTSRC:TRAROUNAM';

FORWARD ROUTINE
    EDT$$SC_LNINS;

!
! INCLUDE FILES:
!

REQUIRE 'EDTSRC:EDTREQ';

!
! MACROS:
!
!	NONE
!
! EQUATED SYMBOLS:
!
!	NONE
!
! OWN STORAGE:
!
!	NONE
!
! EXTERNAL REFERENCES:
!
!	In the routine
%SBTTL 'EDT$$SC_LNINS  - insert a line on the screen'

GLOBAL ROUTINE EDT$$SC_LNINS (			! Insert a line on the screen
    SCRPTR, 					! Location above which to insert
    REC_ADDR, 					! Address of new line
    REC_LEN					! Length of new line
    ) =

!++
! FUNCTIONAL DESCRIPTION:
!
!	A record has been inserted, update screen line information structure
!	by indicating that the line(s) need to be repainted.  Get memory
!	from heap storage or the pool of available storage as needed.
!
! FORMAL PARAMETERS:
!
!  SCRPTR		insert the new line(s) just before this line
!
!  REC_ADDR 		the address of the new record
!
!  REC_LEN 		the length of the new record
!
! IMPLICIT INPUTS:
!
!	MEM_CNT
!	WK_LN
!	EOB_LN
!	CUR_BUF
!	FST_SCRPTR
!	LST_SCRPTR
!	CUR_SCRPTR
!	TI_WID
!	SHF
!	TRUN
!	SCR_LNS
!
! IMPLICIT OUTPUTS:
!
!	MEM_CNT
!	EOB_SCRPTR
!	FST_SCRPTR
!	CSR_SCRPTR
!	CUR_SCRLN
!	LNO_EMPTY
!	SCR_REBUILD
!	LST_SCRPTR
!
! ROUTINE VALUE:
!
!	NONE
!
! SIDE EFFECTS:
!
!	NONE
!
!--

    BEGIN

    EXTERNAL ROUTINE
	EDT$$FMT_MSG : NOVALUE,			! Print a message
	EDT$$ALO_HEAP,				! Allocate heap storage
	EDT$$FMT_CHWID,				! Compute the width of a character
	EDT$$SC_LNDEL : NOVALUE;		! Free a line from the screen data base

    EXTERNAL
	MEM_CNT,				! Memory allocation count
	FST_AVLN : REF SCREEN_LINE,		! List of free screen lines
	WK_LN : REF LIN_BLOCK,			! Address of current workfile line
	EOB_LN,					! Address of EOB
	CUR_BUF : REF TBCB_BLOCK,		! Current text buffer control block
	EOB_SCRPTR : REF SCREEN_LINE,		! Pointer to EOB screen line
	FST_SCRPTR : REF SCREEN_LINE,		! Pointer to first screen line info
	LST_SCRPTR : REF SCREEN_LINE,		! Pointer to last screen line info
	CUR_SCRPTR : REF SCREEN_LINE,		! Pointer to the current screen line
	TRUN,					! 1 = truncate mode
	SHF,					! Screen shift amount
	TI_WID,					! Width of the terminal
	SCR_LNS,				! Number of lines on the screen
	CSR_SCRPTR : REF SCREEN_LINE,		! Current cursor line screen info
	CUR_SCRLN : LN_BLOCK,			! Absolute record number of that line
	LNO_EMPTY : LN_BLOCK,			! Special value for "empty" line number
	SCR_REBUILD;				! 1 = rebuild the screen data base from the work file

    MESSAGES ((INSMEM));

    MAP
	SCRPTR : REF SCREEN_LINE;

    LOCAL
	EDIT_CODE,				! Repaint or insert
	NEW_SCRPTR : REF SCREEN_LINE,		! Address of new line info
	PREV_SCRPTR : REF SCREEN_LINE,		! Address of previous line info
	INDX,					! Index for inserting multiple lines
	NEED_ANOTHER_LINE,			! 1 = another line needed for this record
	LEFT,					! Left character position for this line
	RIGHT,					! Right character position for this line
	CHAR,
	TXT,
	COL,
	LEN,
	NEW_ADDR;

    INDX = 0;					! Start with first line
    NEED_ANOTHER_LINE = 1;			! Always need at least one line
    LEFT = 0;					! Start the first line at position 0

    WHILE (.NEED_ANOTHER_LINE AND (.INDX LEQ 255)) DO
	BEGIN
!+
! If we are inserting before a line, look for deleted lines; use the earliest
! one found.
!-

	IF (.SCRPTR NEQA 0)
	THEN
	    BEGIN
	    NEW_SCRPTR = .SCRPTR [SCR_PRV_LINE];

	    IF (.NEW_SCRPTR NEQA 0)
	    THEN
		BEGIN

		IF ((.NEW_SCRPTR [SCR_EDIT_FLAGS] AND SCR_EDIT_DELLN) NEQ 0)
		THEN
		    BEGIN

		    LOCAL
			FOUND_EARLIEST;

		    FOUND_EARLIEST = 0;

		    WHILE ( NOT .FOUND_EARLIEST) DO
			BEGIN
			PREV_SCRPTR = .NEW_SCRPTR [SCR_PRV_LINE];

			IF (.PREV_SCRPTR EQLA 0)
			THEN
			    FOUND_EARLIEST = 1
			ELSE
			    BEGIN

			    IF ((.PREV_SCRPTR [SCR_EDIT_FLAGS] AND SCR_EDIT_DELLN) NEQ 0)
			    THEN
				NEW_SCRPTR = .PREV_SCRPTR
			    ELSE
				FOUND_EARLIEST = 1;

			    END;

			END;

		    EDIT_CODE = SCR_EDIT_MODIFY;
		    END
		ELSE
		    NEW_SCRPTR = 0;

		END;

	    END
	ELSE
	    NEW_SCRPTR = 0;

	IF (.NEW_SCRPTR EQLA 0)
	THEN
	    BEGIN
	    MEM_CNT = .MEM_CNT + 1;	! Incremented each time entered
!+
! Unless there is available memory, get some from heap storage for the
! new screen line information buffer.
!-

	    IF (.FST_AVLN EQLA 0)
	    THEN
		BEGIN

		IF ( NOT EDT$$ALO_HEAP (%REF (SCR_SIZE*BYTES_PER_WORD), NEW_ADDR))
		THEN
		    BEGIN
		    SCR_REBUILD = 1;
		    EDT$$FMT_MSG (EDT$_INSMEM);
		    RETURN (0);
		    END;

		NEW_SCRPTR = .NEW_ADDR;
		END
	    ELSE
		BEGIN
		NEW_SCRPTR = .FST_AVLN;
		FST_AVLN = .NEW_SCRPTR [SCR_NXT_LINE];
		END;

	    EDIT_CODE = SCR_EDIT_INSLN;
!+
! If the screen information structure is empty, then initialize
! the screen pointers. Set up the first pointer as EOB if the
! current line is at the end of the buffer.
!-

	    IF (.FST_SCRPTR EQL 0)
	    THEN
		BEGIN
		FST_SCRPTR = .NEW_SCRPTR;
		LST_SCRPTR = .NEW_SCRPTR;
		NEW_SCRPTR [SCR_NXT_LINE] = 0;
		NEW_SCRPTR [SCR_PRV_LINE] = 0;
		END
	    ELSE
		BEGIN
!+
! Perform the insert above the given SCRPTR.  If that SCRPTR is
! zero, then insert the new line below the last screen pointer.
!-

		IF (.SCRPTR EQLA 0)
		THEN
		    BEGIN
		    NEW_SCRPTR [SCR_NXT_LINE] = 0;
		    NEW_SCRPTR [SCR_PRV_LINE] = .LST_SCRPTR;
		    LST_SCRPTR [SCR_NXT_LINE] = .NEW_SCRPTR;
		    LST_SCRPTR = .NEW_SCRPTR;
!+
! If we have exceeded our maximum screen line insert count, then
! remove the top screen record.
!-

		    WHILE ((.MEM_CNT GEQ (.SCR_LNS*5)) AND 	!
			(.FST_SCRPTR NEQA .NEW_SCRPTR)) DO
			BEGIN

			DO
			    BEGIN
!+
! Check for deleting the cursor line from the data base.  If this happens we will
! have to rebuild the screen data base.
!-

			    IF (.CSR_SCRPTR EQLA .FST_SCRPTR)
			    THEN
				BEGIN
				CSR_SCRPTR = 0;
				MOVELINE (LNO_EMPTY, CUR_SCRLN);
				SCR_REBUILD = 1;
				END;

			    EDT$$SC_LNDEL (.FST_SCRPTR);
			    END
			UNTIL ((.FST_SCRPTR [SCR_LINE_IDX] EQL 0) OR 	!
			    (.FST_SCRPTR EQLA .NEW_SCRPTR))

			END;

		    END
		ELSE
		    BEGIN
		    PREV_SCRPTR = .SCRPTR [SCR_PRV_LINE];
		    NEW_SCRPTR [SCR_PRV_LINE] = .PREV_SCRPTR;
		    NEW_SCRPTR [SCR_NXT_LINE] = .SCRPTR;

		    IF (.PREV_SCRPTR NEQA 0)
		    THEN
			PREV_SCRPTR [SCR_NXT_LINE] = .NEW_SCRPTR
		    ELSE
			BEGIN
			FST_SCRPTR = .NEW_SCRPTR;
!+
! If we have exceeded our maximum screen line insert count, then
! remove the bottom screen record.
!-

			WHILE ((.MEM_CNT GEQ (.SCR_LNS*5)) AND 	!
			    (.LST_SCRPTR NEQA .NEW_SCRPTR)) DO
			    BEGIN

			    DO
				BEGIN
!+
! Check for deleting the cursor line from the data base.  If this happens we will
! have to rebuild the screen data base.
!-

				IF (.CSR_SCRPTR EQLA .LST_SCRPTR)
				THEN
				    BEGIN
				    CSR_SCRPTR = 0;
				    MOVELINE (LNO_EMPTY, CUR_SCRLN);
				    SCR_REBUILD = 1;
				    END;

				EDT$$SC_LNDEL (.LST_SCRPTR);
				END
			    UNTIL ((.FST_AVLN [SCR_LINE_IDX] EQL 0) OR 	!
				(.LST_SCRPTR EQLA .NEW_SCRPTR));

			    END;

			END;

		    SCRPTR [SCR_PRV_LINE] = .NEW_SCRPTR;
		    END;

		END;

	    END;

!+
! Initialize the fields of the screen information block for repaint.
!-
	NEW_SCRPTR [SCR_EDIT_FLAGS] = .EDIT_CODE;
	NEW_SCRPTR [SCR_LINE_IDX] = .INDX;
	NEW_SCRPTR [SCR_EDIT_MINPOS] = 0;
	NEW_SCRPTR [SCR_EDIT_MAXPOS] = 255;
	NEW_SCRPTR [SCR_CHR_FROM] = .LEFT;
!+
! Compute the right character position of the current line.
!-

	IF ( NOT .TRUN)
	THEN
	    BEGIN

	    LOCAL
		WIDTH;

	    IF (.INDX EQL 0)
	    THEN
		BEGIN
		WIDTH = .TI_WID + .SHF;
		COL = 0;
		END
	    ELSE
		BEGIN
		WIDTH = .TI_WID + .SHF;
		COL = .SHF + 2;
		END;

!+
! We must compute the width of each character to see how many will fit.
!-
	    LEN = .REC_LEN - .LEFT;
	    TXT = CH$PTR (.REC_ADDR, .LEFT, BYTE_SIZE);
	    RIGHT = .LEFT - 1;
	    CHAR = CH$RCHAR_A (TXT);

	    WHILE ((.LEN GTR 0) AND ((.COL + EDT$$FMT_CHWID (.CHAR, .COL)) LEQ .WIDTH)) DO
		BEGIN
		LEN = .LEN - 1;
		RIGHT = .RIGHT + 1;
		COL = .COL + EDT$$FMT_CHWID (.CHAR, .COL);
		CHAR = CH$RCHAR_A (TXT);
		END;

	    IF (.LEN GTR 0)
	    THEN
		BEGIN
!+
! We need another line.
!-
		NEED_ANOTHER_LINE = 1;
		LEFT = .RIGHT + 1;
		END
	    ELSE
		BEGIN
!+
! We don't need another line.
!-
		NEED_ANOTHER_LINE = 0;
		RIGHT = 255;
		END;

	    END
	ELSE
	    BEGIN
!+
! Truncate mode, we never need more than one line.
!-
	    NEED_ANOTHER_LINE = 0;
	    RIGHT = 255;
	    END;

	NEW_SCRPTR [SCR_CHR_TO] = .RIGHT;
!+
! If there is no current screen pointer, make this line the current line.
!-

	IF (.CUR_SCRPTR EQLA 0) THEN CUR_SCRPTR = .NEW_SCRPTR;

	INDX = .INDX + 1;
	END;

    IF ((.WK_LN EQLA EOB_LN) AND (.SCRPTR EQLA 0)) THEN EOB_SCRPTR = .NEW_SCRPTR;

!+
! Return the number of lines produced.
!-
    RETURN (.INDX);
    END;					! of routine EDT$$SC_LNINS

!<BLF/PAGE>
END						! of module EDT$SCRNEWINS

ELUDOM