Google
 

Trailing-Edge - PDP-10 Archives - bb-r775c-bm_tops20_ks_upd_3 - sources/fill.bli
There are 10 other files named fill.bli in the archive. Click here to see a list.
 %TITLE 'FILL - fill command'
MODULE FILL (				! Fill command
		IDENT = '2-002'			! File: FILL.BLI, Edit: GB2002
		) =
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 implements the fill command for line mode
!	or change mode.
!
! ENVIRONMENT: user mode.
!
! AUTHOR: Bob Kushlis, CREATION DATE: 11-OCT-1979
!
! MODIFIED BY:
!
! 2-001	- Regularize headers.  JBS 05-Mar-1981
! 2-002 - Fix lots of string ptrs and bad code, add BYTE_SIZE for bigger bytes.  GB 1-Mar-1983
!
!--

%SBTTL 'Declarations'
!
! TABLE OF CONTENTS:
!

REQUIRE 'EDTSRC:TRAROUNAM';

FORWARD ROUTINE
    EDT$$FILL_TXT;

!
! INCLUDE FILES:
!

REQUIRE 'EDTSRC:EDTREQ';

!
! MACROS:
!
!	NONE
!
! EQUATED SYMBOLS:
!
!	NONE
!
! OWN STORAGE:
!
!	NONE
!
! EXTERNAL REFERENCES:
!
!	In the routine
%SBTTL 'EDT$$FILL_TXT  - fill command'

GLOBAL ROUTINE EDT$$FILL_TXT (			! Fill command
	NLINES					! Number of lines to process
    ) =

!++
! FUNCTIONAL DESCRIPTION:
!
!	Do filling, in both line and change mode.
!
! FORMAL PARAMETERS:
!
!  NLINES		The number of lines to fill
!
! IMPLICIT INPUTS:
!
!	WD_WRAP
!	TI_WID
!	LN_BUF
!	LN_LEN
!	WK_LN
!
! IMPLICIT OUTPUTS:
!
!	NONE
!
! ROUTINE VALUE:
!
!	The number of lines filled.
!
! SIDE EFFECTS:
!
!	NONE
!
!--

    BEGIN

    EXTERNAL ROUTINE
	EDT$$FMT_CHWID,
	EDT$$DEL_CURLN,
	EDT$$INS_LN,
	EDT$$START_INS,
	EDT$$END_INS,
	EDT$$RD_NXTLN;

    EXTERNAL
	WD_WRAP,
	TI_WID,
	LN_BUF,
	LN_LEN,
	WK_LN : REF LIN_BLOCK;

    LABEL
	PUTLINE;

    LOCAL
	MARGIN,					! The column number of the right margin.
	COL,					! Current column of filled line buffer.
	I,					! Index into the input line.
	LC,					! Count of lines processed.
	LP,					! Pointer into filled line buffer.
	SLP,					! Start of filled line buffer
	SP,					! Pointer used when scanning back for spaces.
	REM,					! No of characters remaining after fill line.
	LEN,					! Length of input line.
	NL;					! No of new lines created.

!+
! Determine the margin.
!-

    IF (.WD_WRAP NEQ 256) THEN MARGIN = .WD_WRAP ELSE MARGIN = .TI_WID - 1;

!+
! Set the filled line buffer to empty,
! The column number to 0,
! And the count of lines processed to 0.
!-
    SLP = CH$PTR (LN_BUF, 0, BYTE_SIZE);
    LP = .SLP;
    LC = 0;
    COL = 0;
    I = .WK_LN [LIN_LENGTH];
    NL = 0;
!+
! Loop until NLINES have been processed.
!-

    INCR J FROM 1 TO .NLINES DO
	BEGIN
!+
! Strip trailing blanks and tabs
!-
	LEN = .WK_LN [LIN_LENGTH];
	SP = CH$PTR (WK_LN [LIN_TEXT], .LEN, BYTE_SIZE);

	WHILE CH$PTR_GTR (.SP, CH$PTR (WK_LN [LIN_TEXT], 0, BYTE_SIZE)) DO
	    BEGIN
	    SP = CH$PLUS (.SP, -1);

	    IF ((CH$RCHAR (.SP) NEQ %C' ') AND (CH$RCHAR (.SP) NEQ ASC_K_TAB)) THEN EXITLOOP;

	    LEN = .LEN - 1;
	    END;

	IF (.LEN NEQ 0)
	THEN
	    BEGIN

	    INCR I FROM 0 TO .LEN DO
		BEGIN

		IF (.I EQL .LEN)
		THEN
		    CH$WCHAR (%C' ', .LP)
		ELSE
		    CH$WCHAR (CH$RCHAR (CH$PTR (WK_LN [LIN_TEXT], .I, BYTE_SIZE)), .LP);

		COL = .COL + EDT$$FMT_CHWID (CH$RCHAR_A (LP), .COL);

		IF (.COL GTR .MARGIN)
		THEN
PUTLINE :
		    BEGIN
!+
! Back up to a space.
!-
		    SP = CH$PLUS (.LP, -1);

		    WHILE (CH$RCHAR (.SP) NEQ %C' ') DO

			IF CH$PTR_EQL (.SP, .SLP)
			THEN
			    LEAVE PUTLINE
			ELSE
			    SP = CH$PLUS (.SP, -1);

!+
! Insert the new line.
!-
		    EDT$$START_INS ();
		    EDT$$INS_LN (CH$PTR (LN_BUF, 0, BYTE_SIZE), CH$DIFF (.SP, .SLP));
		    EDT$$END_INS ();
		    NL = .NL + 1;
!+
! And move the remaining characters to the beginning
! of the buffer.
!-
		    SP = CH$PLUS (.SP, 1);
		    CH$MOVE (CH$DIFF (.LP, .SP), .SP, .SLP);
		    COL = 0;
		    REM = CH$DIFF (.LP, .SP);
		    LP = .SLP;

		    DECR I FROM .REM - 1 TO 0 DO
			COL = .COL + EDT$$FMT_CHWID (CH$RCHAR_A (LP), .COL);

		    END;

		END;

	    EDT$$DELCURLN ();
	    END
	ELSE
!+
! Line was blank, break the fill at this point by inserting
! whatever remains from the previous line.
!-
	    BEGIN
!+
! Insert the remainder of new line.
!-

	    IF CH$PTR_NEQ (.LP, .SLP)
	    THEN
		BEGIN
		EDT$$START_INS ();
		EDT$$INS_LN (CH$PTR (LN_BUF, 0, BYTE_SIZE), CH$DIFF (.LP, .SLP));
		EDT$$END_INS ();
		NL = .NL + 1;
		LP = .SLP;
		COL = 0;
		END;

	    EDT$$RD_NXTLN ();
	    NL = .NL + 1;
	    END

	END;

    IF CH$PTR_NEQ (.LP, .SLP)
    THEN
	BEGIN
	EDT$$START_INS ();
	EDT$$INS_LN (CH$PTR (LN_BUF, 0, BYTE_SIZE), CH$DIFF (.LP, .SLP));
	EDT$$END_INS ();
	NL = .NL + 1;
	END;

    RETURN (.NL);
    END;


END
ELUDOM