/******************************************************************************

	InpDel()

	This function is called when the user types the DELETE key while
typing in a command string.  What is displayed on his terminal when this
happens depends on what kind of terminal he has and what the deleted
character is.  This function displays the required character(s).

*****************************************************************************/

#include "ZPort.h"		/* define portability identifiers */
#include "DefTeco.h"		/* define general identifiers */
#include "DefChars.h"		/* define identifiers for characters */
#include "ChrMacs.h"		/* define character processing macros */
#include "DefScren.h"		/* define identifiers for screen i/o */

extern	VOID	TypBuf();	/* type a buffer */
extern	VOID	ZDspBf();	/* output a buffer to the terminal */
extern	VOID	ZDspCh();	/* output a character to the terminal */
extern	VOID	EchoIt();	/* echo a character to the terminal */
extern	VOID	ScrnOp();	/* do a screen operation */

EXTERN	char	*CBfBeg;	/* command buffer beginning */
EXTERN	char	*CBfPtr;	/* command buffer pointer */
EXTERN	LONG	CRCnt;		/* count of CRETRNs in command string */
EXTERN	WORD	EtFlag;		/* ET mode control flag */


VOID InpDel()
{
	LOCAL char *TmpPtr;		/* temporary pointer */


#if DEBUGGING
DbgInd+=2;if(DbgLvl>=4){DbgDBf("InpDel: called.\015\012");DbgROf();}
#endif
	--CBfPtr;
	if (EtFlag & ET_SCOPE)			/* if it's a scope */
		if (CBfPtr >= CBfBeg)		/* if buffer not empty */
		if (((*CBfPtr > USCHAR) &&	/* if one printable char */
		     (*CBfPtr < DELETE)) ||
		    (*CBfPtr == ESCAPE))
			ZDspBf("\010 \010", 3);	/* erase one character */
		else switch (*CBfPtr) {
			case DELETE:
				break;
			case LINEFD:
				ScrnOp(SCR_CUP);
				break;
			case VRTTAB:
			case FORMFD:
				ScrnOp(SCR_CUP);
				ScrnOp(SCR_CUP);
				ScrnOp(SCR_CUP);
				ScrnOp(SCR_CUP);
				ScrnOp(SCR_CUP);
			case TABCHR:
			case BAKSPC:
			case CRETRN:
				ZDspCh(CRETRN);
				ScrnOp(SCR_EEL);
				if (*CBfPtr == CRETRN)
					--CRCnt;
				TmpPtr = CBfPtr;
				while (TmpPtr > CBfBeg)
					{
					TmpPtr--;
					if (IsEOL(*TmpPtr))
						{
						++TmpPtr;
						break;
						}
					}
				if (TmpPtr == CBfBeg)
					ZDspCh('*');
				TypBuf(TmpPtr, CBfPtr);
				break;
			default:
				ZDspBf("\010 \010\010 \010", 6);
		} /* end switch */
	else					/* else (it's not a scope) */
		if (CBfPtr >= CBfBeg)		/* if buffer not empty */
			EchoIt(*CBfPtr);
		else				/* else (buffer empty) */
			ZDspBf("\015\012*", 3);	/* prompt */
	if (CBfPtr >= CBfBeg)
		--CBfPtr;
#if DEBUGGING
if(DbgLvl>=4){DbgMsg();
DbgDBf("InpDel: returning.\015\012");DbgROf();}DbgInd-=2;
#endif
}
