Trailing-Edge
-
PDP-10 Archives
-
bb-h138f-bm
-
7-sources/lsub.bli
There are 10 other files named lsub.bli in the archive. Click here to see a list.
%TITLE 'LSUB - SUBSTITUTE in one line of text'
MODULE LSUB ( ! SUBSTITUTE in one line of text
IDENT = '3-002' ! File: LSUB.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 scans a line of text for a match with the
! search string. If found, it performs the substitution.
! This is used by the line mode commands SUBSTITUTE
! and SUBSTITUTE NEXT.
!
! 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 SUBSTITUTE from the module EXEC.BLI.
! 1-002 - DJS 16-MAR-1981. Before the SUBSTITUTE search string is
! compared to part of a text line, an additional test was added
! to ensure that there is enough text left on the line to make
! a match possible. Previously, it was possible for data beyond
! the end-of-line to be included in the string match.
! 1-003 - Regularize headers. JBS 20-Mar-1981
! 1-004 - Use the new message codes. JBS 06-Aug-1981
! 1-005 - Force cursor to remain positioned less than 256 characters
! from the beginning of the line. Previously,, string substitution
! could leave the cursor after the end of the line.
! STS 17-Sep-1981
! with them. GB 22-Feb-1983
! 1-006 - Remove EDT$$A_STR_CMP. JBS 16-Jul-1982
! 1-007 - Mark the line changed in the screen data base. JBS 01-Dec-1982
! 1-008 - Change the call to EDT$$MRK_LNCHG. JBS 27-Dec-1982
! 3-001 - Use string pointers correctly and don't try to do arithmetic
! 3-002 - Make argument to RPL_LN a string ptr. GB 16-Mar-1983
! 3-003 - Add updates from V3 sources. GB 29-Apr-1983
!--
%SBTTL 'Declarations'
!
! TABLE OF CONTENTS:
!
REQUIRE 'EDTSRC:TRAROUNAM';
FORWARD ROUTINE
EDT$$SUB_NXT : NOVALUE; ! Do a substitution within one line of text
!
! INCLUDE FILES:
!
REQUIRE 'EDTSRC:EDTREQ';
!
! MACROS:
!
! NONE
!
! EQUATED SYMBOLS:
!
! NONE
!
! OWN STORAGE:
!
! NONE
!
! EXTERNAL REFERENCES:
!
! In the routine
%SBTTL 'EDT$$SUB_NXT - substitute in one line of text'
GLOBAL ROUTINE EDT$$SUB_NXT ( ! substitute in one line of text
SINGLE, ! 1 = just do one substitution
START_POS ! start searching here
) : NOVALUE =
!++
! FUNCTIONAL DESCRIPTION:
!
! Do substitutions in one line of text. This routine scans the current
! line of text, starting at the character position START_POS, looking
! for a string that matches the search string. If it is found, that string
! is replaced by the subsitute string. If the SINGLE flag is on,
! it returns after one substitution, otherwise all matches in the line are substituted.
!
! FORMAL PARAMETERS:
!
! SINGLE 1 = just do one substitution
!
! START_POS where to start the search
!
! IMPLICIT INPUTS:
!
! CUR_BUF
! LN_BUF
! SEA_STRLEN
! SEA_STR
! SUB_STR
! SUB_STRLEN
! WK_LN
! EXE_QRYQUIT
! EXE_SUBCNT
! EXE_SBITS
! EXCT_MATCH
!
! IMPLICIT OUTPUTS:
!
! LN_LEN
! EXE_SUBCNT
!
! ROUTINE VALUE:
!
! NONE
!
! SIDE EFFECTS:
!
! NONE
!
!--
BEGIN
EXTERNAL ROUTINE
EDT$$FMT_MSG,
EDT$$PUT_CH : NOVALUE,
EDT$$PROC_QRYQAL,
EDT$$RPL_LN,
EDT$$TY_CURLN,
EDT$$STR_CMP, ! Compare strings of equal length
EDT$$MRK_LNCHG : NOVALUE; ! Mark the line changed in the screen data base
EXTERNAL
CUR_BUF : REF TBCB_BLOCK,
LN_BUF : VECTOR [CH$ALLOCATION (255, BYTE_SIZE)],
LN_LEN,
SEA_STRLEN,
SEA_STR,
SUB_STR,
SUB_STRLEN,
WK_LN : REF LIN_BLOCK,
EXE_QRYQUIT,
EXE_SUBCNT, ! No. of substitutions done.
EXE_SBITS, ! The options switches.
EXCT_MATCH; ! Type of string matching
MESSAGES ((LINEXC255));
LOCAL
OLD, ! Pointer to the original line
END_LINE, ! Pointer to end of the line
OLD_LEN, ! Length of original line
REPPOINT, ! Pointer to the replacement string
NEW_POS, ! Character position after last subs.
CHANGED, ! Flag indicating this line was changed.
THIS_CHAR_CHANGED; ! Flag indicating this character was changed
!+
! Get a local pointer to the line and its length;
!-
OLD = CH$PTR (WK_LN [LIN_TEXT],, BYTE_SIZE);
OLD_LEN = .WK_LN [LIN_LENGTH];
!+
! Initialize the length of the new line, changed flag and position of
! last SUBSTITUTE.
!-
LN_LEN = 0;
CHANGED = 0;
NEW_POS = 0;
!+
! Get a pointer to the end of the old line.
!-
END_LINE = CH$PTR (WK_LN [LIN_TEXT], .WK_LN [LIN_LENGTH], BYTE_SIZE);
!+
! Loop until either we finish the line or the new line exceed 255 chars.
!-
WHILE ((CH$DIFF (.END_LINE, .OLD) GTR 0) AND (.LN_LEN LSS 256)) DO
BEGIN
THIS_CHAR_CHANGED = 0;
!+
! Look for a match if the position is greater or equal to
! start position.
!-
IF ((.LN_LEN GEQ .START_POS) AND !
((CH$DIFF (.END_LINE, .OLD) - .SEA_STRLEN) GEQ 0) AND !
( NOT .EXE_QRYQUIT) AND !
( NOT (.SINGLE AND .CHANGED)))
THEN
IF EDT$$STR_CMP (.OLD, CH$PTR (SEA_STR,, BYTE_SIZE), .SEA_STRLEN, .EXCT_MATCH)
THEN
IF EDT$$PROC_QRYQAL (.OLD, .END_LINE)
THEN
BEGIN
!+
! A match was found. Set flag indicating that a change has been
! made and increment the count.
!-
THIS_CHAR_CHANGED = 1;
CHANGED = 1;
EXE_SUBCNT = .EXE_SUBCNT + 1;
!+
! Mark the line as changed in the screen data base.
!-
EDT$$MRK_LNCHG (SCR_EDIT_MODIFY, .LN_LEN);
!+
! Get a pointer to the replacement string.
!-
REPPOINT = CH$PTR (SUB_STR,, BYTE_SIZE);
!+
! Move the replacement string into the new line buffer.
!-
INCR J FROM 1 TO .SUB_STRLEN DO
EDT$$PUT_CH (CH$RCHAR_A (REPPOINT));
NEW_POS = .LN_LEN;
!+
! Bump the old line pointer by the length of the search string.
!-
OLD = CH$PLUS (.OLD, .SEA_STRLEN);
END;
IF ( NOT .THIS_CHAR_CHANGED)
THEN
BEGIN
!+
! No match, just copy the chararacter and continue.
!-
EDT$$PUT_CH (CH$RCHAR_A (OLD));
END;
END;
!+
! Check to see if any substitutions have been done.
!-
IF .CHANGED
THEN
BEGIN
!+
! Check for overflow of the newly constructed line.
!-
IF (.LN_LEN GTR 255)
THEN
BEGIN
EDT$$FMT_MSG (EDT$_LINEXC255);
LN_LEN = 255;
END;
!+
! Also need to check if new cursor position would be after 255 characters.
!-
IF (.NEW_POS GTR 255) THEN NEW_POS = 255;
!+
! Replace the line in the buffer, and update the position to
! the position after the last substitution.
!-
EDT$$RPL_LN (CH$PTR (LN_BUF, 0, BYTE_SIZE), .LN_LEN);
CUR_BUF [TBCB_CHAR_POS] = .NEW_POS;
!+
! Unless /NOTYPE was specified, display the updated line.
!-
IF ( NOT .EXE_SBITS<OPB_NOTYP>) THEN EDT$$TY_CURLN ()
END;
END;
END
ELUDOM