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

	DoEvEs()

	This function "does" what's specified by the EV (edit verify) or
ES (search verify) flag.  The ES and EV flags are mode control flags that
allow the user to cause TECO to display a part of the edit buffer after
executing a command string (edit verify) or after a search (search verify).
Both the ES and EV flags are 0 by default,  which means don't do anything.
This function is only called when the ES or EV flag is non-zero.
	The flag is passed to this function for decoding.  This function
examines the flag and acts accordingly.  Both the ES and EV flags have the
following meaning:

	-1	do a 1V command to display the current line
	0	do nothing (this function is not even called)
	1-31	type out current line with line feed at CP
	32-126	type out current line with ASCII character (32-126) at CP
	else	bottom byte as above, top byte is argument to V command

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

#include "ZPort.h"		/* define portability identifiers */
#include "DefChars.h"		/* define identifiers for characters */
#include "DefTeco.h"		/* define general identifiers */

extern	LONG	Ln2Chr();	/* convert line offset to character offset */
extern	VOID	TypBuf();	/* type a buffer */
extern	VOID	ZDspCh();	/* output a character to the terminal */

EXTERN	char	*GapBeg;	/* edit buffer gap beginning */
EXTERN	char	*GapEnd;	/* edit buffer gap end */


VOID DoEvEs(Flag)		/* EV or ES flag code */
WORD Flag;
{
	char	LSByte;			/* least significant byte */
	char	MSByte;			/* most significant byte */

	if (Flag == -1)				/* -1 means do a 1V command */
		{
		MSByte = '\001';
		LSByte = '\0';
		}
	else
		{
		LSByte = (char)Flag;
		MSByte = (char)(Flag >> 8);
		if (MSByte == '\0')		/* be sure it's at least 1 */
			MSByte = '\001';
		}

	TypBuf(GapBeg+Ln2Chr((LONG)('\001'-MSByte)), GapBeg);

	if ((LSByte >= '\001') && (LSByte <= '\037'))
		ZDspCh(LINEFD);
	else if ((LSByte >= '\040') && (LSByte <= '\176'))
		ZDspCh(LSByte);

	TypBuf(GapEnd+1L, GapEnd+Ln2Chr((LONG)MSByte)+1L);
}
