Google
 

Trailing-Edge - PDP-10 Archives - tops20-v7-ft-dist1-clock - 7-sources/lsubs.bli
There are 10 other files named lsubs.bli in the archive. Click here to see a list.
 %TITLE 'LSUBS - SUBSTITUTE line-mode command'
MODULE LSUBS (				! SUBSTITUTE line-mode command
		IDENT = '3-002'			! File: LSUBS.BLI Edit: GB3003
		) =
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 SUBSTITUTE 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-81.  This module was created by
!	extracting the routine EDT$$LN_SUBCMD  from the module EXEC.BLI.
! 1-002	- Regularize headers.  JBS 20-Mar-1981
! 1-003	- Change substitute to EDT$$SUB_NXT .  JBS 27-Mar-1981
! 1-004 - Change paramter to FMT-STRCNT.  SMB 5-Feb-1982
! 1-005	- Give a message if there is an error setting search strings.  JBS 04-May-1982
! 1-006 - Stop processing on bad select range.  SMB 01-Jul-1982
! 1-007	- Use EDT$$FMT_CRLF instead of EDT$$OUT_FMTBUF.  JBS 05-Jul-1982
! 1-008	- Mark the screen as changed if we change anything.  JBS 07-Jul-1982
! 1-009 - Put edt$$tst_eob in line . STS 22-Sep-1982
! 1-010	- Remove EDT$$G_SCR_CHGD, new screen logic doesn't need it.  JBS 09-Oct-1982
! 1-011 - Put edt$$rng_frstln in line. STS 11-Oct-1982
! 3-001 - Start of modifications for Tops10/20.  GB Decemeber 1982.
!	  Remove moveline macro and add code to copy line number.
! 3-002 - Fix EDT$$FMT_STRCNT. CJG 22-Mar-1983
! 3-003 - Add updates from V3 sources.  GB 29-Apr-1983
!--

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

REQUIRE 'EDTSRC:TRAROUNAM';

FORWARD ROUTINE
    EDT$$LN_SUBCMD : NOVALUE;			! Process the SUBSTITUTE command

!
! INCLUDE FILES:
!

REQUIRE 'EDTSRC:EDTREQ';

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

GLOBAL ROUTINE EDT$$LN_SUBCMD 			! SUBSTITUTE line-mode command
    : NOVALUE =

!++
! FUNCTIONAL DESCRIPTION:
!
!	Command processing routine for SUBSTITUTE.   Position to the first
!	line of the range, then enter a loop getting the next line and
!	calling EDT$$SUB_NXT  to do substituions within that line.
!	If the range was null, then we do only a single substitution,
!	otherwise all are done.
!
! FORMAL PARAMETERS:
!
!	NONE
!
! IMPLICIT INPUTS:
!
!	INP_SRC
!	CUR_BUF
!	RNG_SAVPOS
!	EXE_CURCMD
!	EXE_QRYQUIT
!	EXE_SUBCNT
!	WK_LN
!
! IMPLICIT OUTPUTS:
!
!	NONE
!
! ROUTINE VALUE:
!
!	NONE
!
! SIDE EFFECTS:
!
!	NONE
!
!--

    BEGIN

    EXTERNAL ROUTINE
	EDT$$FMT_STRCNT : NOVALUE,
	EDT$$FMT_CRLF,				! Terminate an output line
	EDT$$SET_STR,
	EDT$$FMT_MSG : NOVALUE,
	EDT$$NXT_LNRNG,
    	EDT$$RNG_REPOS,
    	EDT$$RD_CURLN,
	EDT$$SUB_NXT : NOVALUE,
	EDT$$STOP_WKINGMSG : NOVALUE,		! Turn off the "working" message
	EDT$$CHK_CC;				! Check for a control C

    EXTERNAL
	LNO_ZERO : LN_BLOCK,
	INP_SRC,
	CUR_BUF : REF TBCB_BLOCK,
	RNG_SAVPOS : POS_BLOCK,
	WK_LN : REF LIN_BLOCK,
 	RNG_FRSTLN,
    	RNG_ORIGPOS : POS_BLOCK,
	EOB_LN,
	EXE_CURCMD : REF NODE_BLOCK,	! Pointer to the current command.
	EXE_QRYQUIT,			! Quit flag  for /QUERY operations.
	EXE_SUBCNT,			! No. of substitutions done.
	CC_DONE;				! Set if control C actually aborted something

    MESSAGES ((INVSTR));

    LOCAL
	STRINGS_OK,			! Flag indicating that there is a problem setting the strings
	TEMP_COUNT : LN_BLOCK,			! 6 byte count field
	SINGLE,					! Flag indicating single subs only
	FIRST,					! Flag indicating whether this is the first one.
	SEEN_CC;				! Flag indicating we have seen a control C

!+
! Get the range node.
!-

    BIND
	RANGE = .EXE_CURCMD [RANGE1] : NODE_BLOCK;

!+
! Position to the first line.
!-

    RNG_FRSTLN = 1;
    EDT$$CPY_MEM( POS_SIZE, .CUR_BUF, RNG_ORIGPOS);
    IF ( NOT EDT$$RNG_REPOS (.EXE_CURCMD [RANGE1])) THEN RETURN;

!+
! Set the single substitution flag if the range was null.
!-
    SINGLE = .RANGE [RAN_TYPE] EQL RAN_NULL;
!+
! Set flag indicating this if the first substitution, and zero the
! substitution count.
!-
    FIRST = 1;
    EXE_SUBCNT = 0;
    STRINGS_OK = 1;
    SEEN_CC = 0;
!+
! Loop over the range.
!-

    WHILE (EDT$$NXT_LNRNG (0) AND ( NOT .EXE_QRYQUIT) AND .STRINGS_OK AND ( NOT .SEEN_CC)) DO

	IF (.WK_LN NEQA EOB_LN)
	THEN
	    BEGIN
!+
! Must set up the search and replace string each time through
! in case the range involved a search string, which would clobber
! it.
!-
	    STRINGS_OK = EDT$$SET_STR ();

	    IF .STRINGS_OK
	    THEN
		BEGIN
!+
! Do substitutions in this line starting at position 0.
!-
		SEEN_CC = EDT$$CHK_CC ();

		IF ( NOT .SEEN_CC)
		THEN
		    BEGIN
		    EDT$$SUB_NXT (.SINGLE, 0);
!+
! Check to see if this was the first line in the range.
!-

		    IF .FIRST
		    THEN
!+
! Save position after first substitute so we can
! correctly reposition there.  This is nescessary since
! modifying the first line might change it's position in
! the text buffer, invalidating the previously saved position.
!-
			BEGIN
			EDT$$CPY_MEM (POS_SIZE, .CUR_BUF, RNG_SAVPOS);
			FIRST = 0;
			END;

		    END
		ELSE
		    CC_DONE = 1;

		END;

	    END;

    EDT$$STOP_WKINGMSG ();
!+
! Report a case of an invalid string.
!-

    IF ( NOT .STRINGS_OK) THEN EDT$$FMT_MSG (EDT$_INVSTR);

!+
! If the command came from the terminal, report the number of
! substitutions.
!-

    IF (.INP_SRC EQL INP_TERM)
    THEN
	BEGIN
	TEMP_COUNT [LN_LO] = .LNO_ZERO [LN_LO];
	TEMP_COUNT [LN_MD] = .LNO_ZERO [LN_MD];
	TEMP_COUNT [LN_HI] = .LNO_ZERO [LN_HI];
	TEMP_COUNT = .EXE_SUBCNT;
	EDT$$FMT_STRCNT (TEMP_COUNT, CH$PTR (UPLIT (' substitution')), 13);
	EDT$$FMT_CRLF ();
	END;

!+
! And re-position.
!-
    	EDT$$CPY_MEM(POS_SIZE, RNG_SAVPOS, .CUR_BUF);
    	EDT$$RD_CURLN();

    END;					! of routine EDT$$LN_SUBCMD


END
ELUDOM