Google
 

Trailing-Edge - PDP-10 Archives - BB-H138E-BM - 6-1-sources/chmsubs.bli
There are 11 other files named chmsubs.bli in the archive. Click here to see a list.
 %TITLE 'CHMSUBS - change mode SUBSTITUTE command'
MODULE CHMSUBS (				! Change mode SUBSTITUTE command
		IDENT = '3-002'			! File: CHMSUBS.BLI Edit: CJG3002
		) =
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 executes the change mode SUBSTITUTE (S) command.
!
! ENVIRONMENT:	Runs at any access mode - AST reentrant
!
! AUTHOR: Bob Kushlis, CREATION DATE: Unknown
!
! MODIFIED BY:
!
! 1-001	- Original.  DJS 04-Feb-1981.  This module was created by
!	extracting the routine EDT$$SUB_CMD  from module CHANGE.BLI.
! 1-002	- Regularize headers.  JBS 04-Mar-1981
! 1-003	- Use new message codes.  JBS 04-Aug-1981
! 1-004 - New cursor position on backwards substitute.  SMB 28-Oct-1981
! 1-005	- Delete initial blank line by running through PRETTY.  JBS 02-Nov-1981
! 1-006 - Rework edit 1-004 to accomplish the same thing without changing
!	  the cursor position from V2.  SMB 17-Aug-1982
! 1-007	- Remove EDT$$G_LN_NO for new screen update logic.  JBS 29-Sep-1982
! 1-008	- Pass the correct number of lines to EDT$$DEL_TXTLN.  JBS 08-Oct-1982
! 3-001 - Add updates from V3 sources.  GB 27-Apr-1983
! 3-002 - Fix insertion of replacement string. CJG 6-Oct-1983
!--

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

REQUIRE 'EDTSRC:TRAROUNAM';

FORWARD ROUTINE
    EDT$$SUB_CMD;				! Execute the SUBSTITUTE command

!
! INCLUDE FILES:
!

REQUIRE 'EDTSRC:EDTREQ';

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

GLOBAL ROUTINE EDT$$SUB_CMD 			! Change mode SUBSTITUTE command
    =

!++
! FUNCTIONAL DESCRIPTION:
!
!	This routine implements the SUBSTITUTE command.  Just search for the
!	search string, delete it and insert the replace string.
!
! FORMAL PARAMETERS:
!
!	NONE
!
! IMPLICIT INPUTS:
!
!	DIRN
!	LN_PTR
!	SEA_STRLEN
!	SEA_STR
!	SUB_STRLEN
!    	SUB_STR
!
! IMPLICIT OUTPUTS:
!
!	NONE
!
! ROUTINE VALUE:
!
!	1 = substitution made, 0 = not made (string not found, or control C)
!
! SIDE EFFECTS:
!
!	NONE
!
!--

    BEGIN

    EXTERNAL ROUTINE
	EDT$$DEL_TXTLN : NOVALUE,	! Delete whole lines of text
	EDT$$INS_CHS,			! Insert a string of characters which may include carriage returns
	EDT$$MSG_BELL : NOVALUE,	! Output a message to the terminal with a warning bell
	EDT$$STR_SEACMD,		! Search for a specific string
	EDT$$CS_LEFT,			! Move left a character
	EDT$$CS_RIGHT;			! Move right a character

    EXTERNAL
	LNO0,				! 1
	DIRN,				! The current direction.
	LN_PTR,				! Current character pointer
	SEA_STRLEN,			! Length of current search string
	SEA_STR,			! Current search string
	SUB_STRLEN,			! Length of subs string
	SUB_STR,			! Current SUBSTITUTE string
	CUR_BUF : REF TBCB_BLOCK;	! Current text buffer control block

    MESSAGES ((STRNOTFND, BADRANGE));

    LOCAL
	STS,
	NUM_LINES : LN_BLOCK,
	END_POS;

!+
! Search for the string.
!-
    IF (.DIRN EQL DIR_BACKWARD)
    THEN
!+
! Move back one position before starting the search
!-
	STS = EDT$$STR_SEACMD (SEA_STR, .SEA_STRLEN, 1, .DIRN)
    ELSE
	STS = EDT$$STR_SEACMD (SEA_STR, .SEA_STRLEN, 0, .DIRN);

    IF (.STS EQL 1)
    THEN
!+
! String was found, do the SUBSTITUTE.
!-
	BEGIN
!+
! Move to the end of the string, counting the lines involved.
!-
	MOVELINE (CUR_BUF [TBCB_CUR_LIN], NUM_LINES);

	DECR I FROM .SEA_STRLEN - 1 TO 0 DO
	    EDT$$CS_RIGHT ();

	SUBLINE (NUM_LINES, CUR_BUF [TBCB_CUR_LIN], NUM_LINES);
	ADDLINE (LNO0, NUM_LINES, NUM_LINES);
	END_POS = .LN_PTR;

!+
! Move back to the beginning.
!-

	DECR I FROM .SEA_STRLEN - 1 TO 0 DO
	    EDT$$CS_LEFT ();

!+
! Make sure the string isn't too long.
!-

	IF ((.NUM_LINES [LN_HI] NEQU 0) OR (.NUM_LINES [LN_MD] NEQU 0))
	THEN
	    BEGIN
	    EDT$$MSG_BELL (EDT$_BADRANGE);
	    RETURN (0);
	    END;

!+
! Delete the string.
!-
	EDT$$DEL_TXTLN (.NUM_LINES [LN_LO], .END_POS);
!+
! Insert the replacement string.
!-
	EDT$$INS_CHS (CH$PTR (SUB_STR,, BYTE_SIZE), .SUB_STRLEN);
!+
! If we are moving backward, then move back across the string
!-

	IF (.DIRN EQL DIR_BACKWARD)
	THEN

	    DECR I FROM .SUB_STRLEN TO 1 DO
		EDT$$CS_LEFT ();

	RETURN (1);
	END
    ELSE
	BEGIN
!+
! String was not found, EDT$$MSG_BELL  an error.
!-

	IF (.STS EQL 0) THEN EDT$$MSG_BELL (EDT$_STRNOTFND);

	RETURN (0);
	END;

    END;


END
ELUDOM