Google
 

Trailing-Edge - PDP-10 Archives - bb-h138f-bm - 7-sources/keyfmtstr.bli
There are 10 other files named keyfmtstr.bli in the archive. Click here to see a list.
 %TITLE 'KEYFMTSTR - translate a key string'
MODULE KEYFMTSTR (				! Translate a key string
		IDENT = '3-003'			! File: KEYFMTSTR.BLI Edit: CJG3003
		) =
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:
!
!	Translate a key string.
!
! ENVIRONMENT:	Runs at any access mode - AST reentrant
!
! AUTHOR: Bob Kushlis, CREATION DATE: April 7, 1979
!
! MODIFIED BY:
!
! 1-001	- Original.  DJS 24-Feb-1981.  This module was created by
!	extracting routine COM_STRING from module KEYTRAN.
!
! 1-002.  DJS 26-Feb-1981.  Handling of prompt following ? in a key
!	definition modified to allow double quotes as well as single
!	quotes to enclose a prompt string.
! 1-003	- Regularize headers.  JBS 09-Mar-1981
! 1-004	- Build in T_ADV, T_BACK and T_RESET.  JBS 31-Mar-1981
! 1-005	- Add return value for end of journal file.  JBS 02-Oct-1981
! 1-006 - Add an additional terminator when prompt is ?*. STS 21-Oct-1981
! 1-007 - If terminator of search string begins with adv or back then insert
!         this and throw away rest of key definition.   STS 16-Nov-1981
! 1-008	- Revise the call to turn on autorepeat.  JBS 30-Jan-1982
! 1-009	- Remove an unused external reference.  JBS 09-Jun-1982
! 1-010 - Modify message output. SMB 30-Jun-1982
! 1-011 - Add resetting search string and sett direction forward to RESET.
!	    STS 02-Jul-1982
! 1-012 - Only erase the last line on a reset.  SMB 15-Jul-1982
! 1-013	- Change the string match call.  JBS 19-Jul-1982
! 1-014 - Catch errors in prompt string. STS 03-Aug-1982
! 1-015 - Position cursor after error message. STS 10-Aug-1982
! 1-016	- New implementation of defined keys.  JBS 13-Aug-1982
! 1-017	- Fix a bug in recognizing ADV and BACK.  JBS 16-Aug-1982
! 1-018	- Make RESET not reset the search string.  JBS for STS 26-Aug-1982
! 1-019	- New screen update logic.  JBS 13-Sep-1982
! 1-020	- Remove external declaration of EDT$$FMT_LIT, not used.  JBS 05-Oct-1982
! 1-021	- Change the cursor positioning call, to obsolete a module.  JBS 05-Oct-1982
! 1-022	- Use partial matching for ADV and BACK.  JBS 14-Dec-1982
! 1-023	- Insert the whole text of a terminator to a prompt, if it starts with
!	   ADV or BACK.  This is for compatibility with EDT version 2.  JBS 15-Dec-1982
! 1-024	- Don't position cursor if no position recorded, and treat a cancelled command the same
!	   as an undefined key.  JBS 17-Jan-1983
! 1-025	- Put WPS support under a conditional.  JBS 10-Feb-1983
! 3-001 - Add updates from V3 source kit.  GB 27-Apr-1983
! 3-002 - Add PROMPT_LENGTH so errors point to right place. CJG 7-Oct-1983
! 3-003 - Call EDT$$TI_RDCMDLN directly. CJG 3-Jan-1983
!--

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

REQUIRE 'EDTSRC:TRAROUNAM';

FORWARD ROUTINE
    EDT$$TRN_KSTR;

!
! INCLUDE FILES:
!

REQUIRE 'EDTSRC:EDTREQ';

LIBRARY 'EDTSRC:KEYPADDEF';

!
! MACROS:
!
!	NONE
!
! EQUATED SYMBOLS:
!
!	NONE
!
! OWN STORAGE:
!
!	NONE
!
! EXTERNAL REFERENCES:
!
!	In the routine
%SBTTL 'EDT$$TRN_KSTR  - translate a key string'

GLOBAL ROUTINE EDT$$TRN_KSTR (			! Translate a key string
    K, 						! Key number
    EXPAND, 					! 1 = do prompting
    ECHO					! 1 = echo characters
    ) =

!++
! FUNCTIONAL DESCRIPTION:
!
!	This routine processes the translation string of a key placing the
!	characters in the buffer.  If a '?' is seen, and the EXPAND parameter
!	is 1, then the user is prompted for input which replaces the '?' and
!	the prompt string in the buffer.
!
! FORMAL PARAMETERS:
!
!  K			The number of the key to translate.
!
!  EXPAND		Flag indicating ? should be expanded.
!
!  ECHO			Flag indicating that the characters should be echoed.
!
! IMPLICIT INPUTS:
!
!	MESSAGE_LINE
!	CS_LNO
!	CUR_COL
!	SEL_BUF
!	CMD_BUF
!	CUR_BUF
!	TI_TYP
!	TIN_ECHOPOS
!
! IMPLICIT OUTPUTS:
!
!	CMD_PTR
!	CMD_END
!	TIN_ECHOPOS
!	TIN_ECHOFLG
!	PROMPT_LENGTH
!
! ROUTINE VALUE:
!
!	0 = definition did not end with a period
!	1 = key was null or translation was successful and definition ended with period
!	    or translation was cancelled
!	2 = end of journal file
!
! SIDE EFFECTS:
!
!	This routine calls itself recursively when an input string is terminated
!	by ADV or BACK.
!
!--

    BEGIN

    EXTERNAL ROUTINE
	EDT$$SC_ERATOEOL,
	EDT$$MSG_BELL,
	EDT$$OUT_MSG,
	EDT$$SC_REVID,
	EDT$$SC_NONREVID,
	EDT$$OUT_FMTBUF,
	EDT$$TI_RDCMDLN,
	EDT$$PUT_CMDCH : NOVALUE,	! Put a character in the command buffer
	EDT$$SC_POSCSIF : NOVALUE,
	EDT$$TI_ENBLAUTREP,		! Enable or disable autorepeat
	EDT$$TI_INPCH,
	EDT$$TI_DELK,
	EDT$$TST_KEYDEF,		! See if a key is defined as aparticular string
	EDT$$FIND_KEY;			! Find the definition of a key

    EXTERNAL
	MESSAGE_LINE,			! Message line is this + 1
	CS_LNO,				! Line on which the cursor is positioned
	CUR_COL,			! Column on which the cursor is positioned.
	SEL_BUF,			! Buffer in which the mark resides
	CMD_BUF,			! Command buffer
	CMD_PTR,			! Pointer to next char in command buffer
	CMD_END,			! Pointer to end of info in command buffer
	CUR_BUF,			! Pointer to current text buffer TBCB
	PROMPT_LENGTH,			! Length of prompt issued
	TI_TYP,				! terminal type
	TIN_ECHOFLG,			! Was a character echoed?
	TIN_ECHOPOS,			! The position on the echo line.
	DIR_MOD,			! the current direction
	DFLT_VERB,			! the current default mode
	SEA_STRLEN;			! length of the current search string

    MESSAGES ((INVSUBCOM));

    LOCAL
	C,
	TERM,
	ALT_TERM,
	TRAN_POINT,
	TRAN_END,
	KEY_PTR : REF BLOCK [] FIELD (KEY_DEF_FIELD);

!+
! Check for a key that is null.
!-

    IF ( NOT EDT$$FIND_KEY (.K, KEY_PTR))
    THEN
	BEGIN
	CMD_END = .CMD_PTR;
	RETURN (1);
	END;

!+
! Look for the string RESET, which is handled specially.
!-

    IF EDT$$TST_KEYDEF (.K, UPLIT ('RESET'), 5, 0)
    THEN
	BEGIN
!+
! Reset was seen.  Flush the buffer, and undo the select range.
!-
	CMD_PTR = CH$PTR (CMD_BUF,, BYTE_SIZE);
	CMD_END = CH$PTR (CMD_BUF,, BYTE_SIZE);

	IF (.ECHO)
	THEN
	    BEGIN
	    EDT$$SC_POSCSIF (.MESSAGE_LINE + 1, 0);	! Erase key definition
	    EDT$$SC_ERATOEOL ();
	    EDT$$OUT_FMTBUF ();
	    END;

	DFLT_VERB = VERB_K_MOVE;		! reset mode to move
	DIR_MOD = DIR_FORWARD;		! reset direction to forward

	SEL_BUF = 0;
	RETURN (1);
	END;

!+
! Get a pointer to the end of the translation string.
!-
    TRAN_POINT = CH$PTR (KEY_PTR [KEY_DEF_TEXT],, BYTE_SIZE);
    TRAN_END = CH$PLUS (.TRAN_POINT, .KEY_PTR [KEY_DEF_LEN]);
    TERM = 0;
!+
! Loop through the string.
!-

    WHILE CH$PTR_LSS (.TRAN_POINT, .TRAN_END) DO

	IF ((CH$RCHAR (.TRAN_POINT) EQL %C'?') AND .EXPAND)
	THEN
!+
! Character is ? and expand is on.
!-
	    BEGIN

	    LOCAL
		QUOTE,				! Character following ?
		P_ADDR,				! Address of prompt.
		STATUS,				! for status of kpad_inp routine
		P_LEN;				! Length of prompt.

	    TRAN_POINT = CH$PLUS (.TRAN_POINT, 1);
!+
! Look for a second ?, in which case it is literal.
!-

	    IF (CH$RCHAR (.TRAN_POINT) EQL %C'?')
	    THEN
		EDT$$PUT_CMDCH (CH$RCHAR_A (TRAN_POINT), .ECHO)
	    ELSE
!+
! Expand the ?.
!-
		BEGIN
		P_LEN = 0;
!+
! See if it's the special prompt which takes a CR.
!-

		IF (CH$RCHAR (.TRAN_POINT) EQL %C'*')
		THEN
		    BEGIN
		    TRAN_POINT = CH$PLUS (.TRAN_POINT, 1);	! point to the next char
		    ALT_TERM = ASC_K_CR;	! set up an alternative terminator of CR
		    END
		ELSE
		    ALT_TERM = ASC_K_ESC;	! otherwise we just stop at escapes

!+
! Look for a quote mark following to start the prompt.
!-
		QUOTE = CH$RCHAR (.TRAN_POINT);

		IF ((.QUOTE EQL %C'''') OR (.QUOTE EQL %C'"'))
		THEN
		    BEGIN
!+
! Get the entire prompt string.
!-
		    TRAN_POINT = CH$PLUS (.TRAN_POINT, 1);
		    P_ADDR = .TRAN_POINT;

		    WHILE (CH$PTR_GTR (.TRAN_END, .TRAN_POINT) AND (CH$RCHAR_A (TRAN_POINT) NEQ .QUOTE)) DO
			P_LEN = .P_LEN + 1;

		    END
		ELSE
		    BEGIN
		    CMD_PTR = CH$PTR (CMD_BUF,, BYTE_SIZE);
		    EDT$$MSG_BELL (EDT$_INVSUBCOM);

		    IF (.CS_LNO GEQ 0) THEN EDT$$SC_POSCSIF (.CS_LNO, .CUR_COL);

		    RETURN (0);
		    END;

!+
! Position the cursor and put out the prompt.
!-
		EDT$$OUT_MSG (.MESSAGE_LINE, 0, .P_ADDR, .P_LEN);
		EDT$$TI_ENBLAUTREP (1);
		PROMPT_LENGTH = .P_LEN - 1;
		TIN_ECHOPOS = .TIN_ECHOPOS + .P_LEN;
		TIN_ECHOFLG = 1;
!+
! Now, read up to the next escape character.
!-

		IF (EDT$$TI_INPCH (C) EQL 0) THEN RETURN (2);

		STATUS = EDT$$TI_RDCMDLN (.C, .CMD_PTR, CMD_PTR, .ALT_TERM, TERM);

		IF (.STATUS EQL 2) THEN RETURN (2);

		IF (.STATUS EQL 0)
		THEN
!+
! Command was canceled, flush the buffer and return 1.
!-
		    BEGIN
		    EDT$$SC_NONREVID ();

		    IF (.CS_LNO GEQ 0) THEN EDT$$SC_POSCSIF (.CS_LNO, .CUR_COL);

		    CMD_PTR = CH$PTR (CMD_BUF,, BYTE_SIZE);
		    CMD_END = CH$PTR (CMD_BUF,, BYTE_SIZE);
		    RETURN (1);
		    END;

!+
! Do a positioning sequence to left column so that we know
! the command has been seen.
!-
		EDT$$SC_POSCSIF (.MESSAGE_LINE, 0);
		EDT$$OUT_FMTBUF ();
		END

	    END
	ELSE
	    EDT$$PUT_CMDCH (CH$RCHAR_A (TRAN_POINT), .ECHO);

!+
! If the translation ended with a period, then remove it from the
! buffer and return a one, otherwise, return a 0.
!-

    IF (CH$RCHAR (CH$PLUS (.CMD_PTR, -1)) EQL %C'.')
    THEN
	BEGIN
	CMD_PTR = CH$PLUS (.CMD_PTR, -1);

	IF .ECHO THEN EDT$$TI_DELK (CH$RCHAR (.CMD_PTR));

!+
! If the terminator of input was advance or backup, then throw it into the buffer
! so we can implement the KED feature of hitting advance or backup after a search
! string.  For compatibility with EDT version 2, any key whose definition starts
! with ADV is considered an advance key, and any key whose definition starts with
! BACK is considered a backup key.  The entire text of the definition is inserted.
!-

	IF (EDT$$TST_KEYDEF (.TERM, UPLIT ('ADV'), 3, 1) OR 	!
	    EDT$$TST_KEYDEF (.TERM, UPLIT ('BACK'), 4, 1))
	THEN
	    EDT$$TRN_KSTR (.TERM, .EXPAND, .ECHO);

	CMD_END = .CMD_PTR;
	RETURN (1);
	END;

    RETURN (0);
    END;					! of routine EDT$$TRN_KSTR

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

ELUDOM