Google
 

Trailing-Edge - PDP-10 Archives - tops20-v7-ft-dist1-clock - 7-sources/ltadj.bli
There are 10 other files named ltadj.bli in the archive. Click here to see a list.
 %TITLE 'LTADJ - TABS ADJUST line-mode command'
MODULE LTADJ (				! TABS ADJUST line-mode command
		IDENT = '3-002'			! File: LTADJ.BLI Edit: GB3002
		) =
BEGIN
!COPYRIGHT (c) DIGITAL EQUIPMENT CORPORATION 1981, 1988.  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 THAT IS NOT SUPPLIED BY DIGITAL.
!
!
!++
! FACILITY:	EDT -- The DEC Standard Editor
!
! ABSTRACT:
!
!	This module executes the line mode TAB ADJUST command.
!
! ENVIRONMENT:	Runs at any access mode - AST reentrant
!
! AUTHOR: Bob Kushlis, CREATION DATE: February 3, 1978
!
! MODIFIED BY:
!
! 1-001	- Original.  DJS 30-JAN-1981.  This module was created by
!	extracting the routine EDT$$TSADJ_CMD  from the module EXEC.BLI.
! 1-002	- Regularize headers.  JBS 20-Mar-1981
! 1-003 - Stop processing on bad select range.  SMB 01-Jul-1982
! 1-004	- Mark the screen changed, unless we get an error.  JBS 07-Jul-1982
! 1-005 - Put EDT$$TST_EOB in line. STS 22-Sep-1982
! 1-006	- Remove EDT$$G_SCR_CHGD, the new screen logic doesn't need it.  JBS 09-Oct-1982
! 1-007 - Put code for edt$$rng_posfrst in line. STS 11-Oct-1982
! 1-008	- Can't restore from saved position because we are modifying the work file,
!	   so the saved position may be invalid.  Also, mark lines as changed in case
!	   we are under EXT.  JBS 21-Dec-1982
! 1-009	- Change the call to EDT$$MRK_LNCHG.  JBS 27-Dec-1982
! 1-010	- Don't forget to initialize NLINES.  JBS 17-Jan-1983
! 3-001 - Fix argument to PUT_CH and introduce BYTE_SIZE for greater than 7 bit bytes.  GB 1-Mar-1983
! 3-002 - Make argument to RPL_LN a string ptr.  GB 16-Mar-1983
!--

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

REQUIRE 'EDTSRC:TRAROUNAM';

FORWARD ROUTINE
    EDT$$TSADJ_CMD : NOVALUE;			! Process the TABS ADJUST command

!
! INCLUDE FILES:
!

REQUIRE 'EDTSRC:EDTREQ';

!
! MACROS:
!
!	NONE
!
! EQUATED SYMBOLS:
!
!	NONE
!
! OWN STORAGE:
!
!	NONE
!
! EXTERNAL REFERENCES:
!
!	In the routine
%SBTTL 'EDT$$TSADJ_CMD  - TABS ADJUST line-mode command'

GLOBAL ROUTINE EDT$$TSADJ_CMD 			! TABS ADJUST line-mode command
    : NOVALUE =

!++
! FUNCTIONAL DESCRIPTION:
!
!	Command processing routine for TABS ADJUST.
!
!	Process each line in the range as follows:
!
!		1. Count the leading tabs and spaces.
!		2. Remove them all.
!		3. Add the tab increment value.
!		4. Re-insert a standard sequence of tabs and spaces.
!
! FORMAL PARAMETERS:
!
!	NONE
!
! IMPLICIT INPUTS:
!
!	TAB_SIZ
!	LN_BUF
!	WK_LN
!	EXE_CURCMD
!	EXT_MOD
!
! IMPLICIT OUTPUTS:
!
!	LN_LEN
!	SCR_CHGD
!
! ROUTINE VALUE:
!
!	NONE
!
! SIDE EFFECTS:
!
!	NONE
!
!--

    BEGIN

    EXTERNAL ROUTINE
	EDT$$FMT_CHWID,				! Compute the width of a character
	EDT$$PUT_CH : NOVALUE,
	EDT$$NXT_LNRNG,				! Get next line in range
	EDT$$RNG_REPOS,
	EDT$$RPL_LN,				! Replace a line in the work file
	EDT$$RD_PRVLN,				! Read the previous line from the work file
	EDT$$MRK_LNCHG : NOVALUE;		! Mark a line as changed

    EXTERNAL
	TAB_SIZ,
	RNG_FRSTLN,
	RNG_SAVPOS : POS_BLOCK,
	CUR_BUF : REF TBCB_BLOCK,
	RNG_ORIGPOS : POS_BLOCK,
	LN_BUF : VECTOR [CH$ALLOCATION (255, BYTE_SIZE)],
	LN_LEN,
	EOB_LN,
	WK_LN : REF LIN_BLOCK,
	EXE_CURCMD : REF NODE_BLOCK;	! Pointer to the current command.

    LOCAL
	RANGE : REF NODE_BLOCK,			! The range block
	CP,					! Character position
	EP,					! Position of end of line
	TC,					! Column number
	NLINES;					! Number of lines processed

!+
! Examine the range and, if null, default to SELECT.
!-
    RANGE = .EXE_CURCMD [RANGE1];

    IF (.RANGE [RAN_TYPE] EQL RAN_NULL) THEN RANGE [RAN_TYPE] = RAN_SELECT;

!+
! Position to the first line in the range.
!-

     RNG_FRSTLN = 1;
    EDT$$CPY_MEM (POS_SIZE, .CUR_BUF, RNG_ORIGPOS);

    IF ( NOT EDT$$RNG_REPOS (.RANGE)) THEN RETURN;

!+
! Process each line in the range.
!-

    NLINES = 0;

    WHILE (EDT$$NXT_LNRNG (0) AND (.WK_LN NEQA EOB_LN)) DO
	BEGIN
!+
! Initialize pointers to the beginning and end of the current line.
!-
	CP = CH$PTR (WK_LN [LIN_TEXT], 0, BYTE_SIZE);
	EP = CH$PLUS (.CP, .WK_LN [LIN_LENGTH]);
!+
! Initialize the current column number.
!-
	TC = 0;
!+
! Look for the first non-blank, non-tab character.
!-

	WHILE CH$PTR_NEQ (.CP, .EP) DO
	    BEGIN

	    SELECTONE CH$RCHAR (.CP) OF
		SET

		[%C' '] :
		    TC = .TC + 1;

		[ASC_K_TAB] :
		    TC = .TC + EDT$$FMT_CHWID (ASC_K_TAB, .TC);

		[OTHERWISE] :
		    EXITLOOP;
		TES;

	    CP = CH$PLUS (.CP, 1);
	    END;

!+
! Determine the number of columns the line should be indented.  Do
! not let it go below zero.
!-
	TC = MAX (0, .TC + .EXE_CURCMD [TAB_COUNT]*.TAB_SIZ);
	LN_LEN = 0;
!+
! Insert tabs and spaces into the new line.
!-

	INCR I FROM 1 TO .TC/8 DO
	    EDT$$PUT_CH (ASC_K_TAB);

	INCR I FROM 1 TO .TC MOD 8 DO
	    EDT$$PUT_CH (%C' ');

!+
! And move the remainder of the old line.
!-
	CH$MOVE (CH$DIFF (.EP, .CP), .CP, CH$PTR (LN_BUF, .LN_LEN, BYTE_SIZE));
	LN_LEN = .LN_LEN + CH$DIFF (.EP, .CP);
!+
! Replace it in the text buffer.
!-
	EDT$$RPL_LN (CH$PTR (LN_BUF, 0, BYTE_SIZE), .LN_LEN);
	END;

!+
! Re-position to first line in the range.
!-
! We cannot used the saved position because we have modified the work file,
! so any saved position will be inaccurate.
!-
    NLINES = .NLINES - 1;

    WHILE (.NLINES GTR 0) DO
	BEGIN
	EDT$$RD_PRVLN ();
	NLINES = .NLINES - 1;
	END;

    END;					! of routine EDT$$TSADJ_CMD

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

ELUDOM