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

	ExeY()

	This function executes a Y command.

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

#include "ZPort.h"		/* define portability identifiers */
#include "DefError.h"		/* define identifiers for error messages */
#include "DefTeco.h"		/* define general identifiers */

extern	VOID	ErrMsg();	/* display an error message */
extern	DEFAULT	ExeEY();	/* execute an EY command */

EXTERN	DEFAULT	CurOut;		/* index of current output stream in OFiles */
EXTERN	char	*EBfBeg;	/* beginning of edit buffer */
EXTERN	char	*EBfEnd;	/* end of edit buffer */
EXTERN	WORD	EdFlag;		/* ED mode control flag */
EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	char	*GapBeg;	/* beginning of edit buffer gap */
EXTERN	char	*GapEnd;	/* end of edit buffer gap */
EXTERN	BOOLEAN	IsOpnO[];


DEFAULT ExeY()                          /* Y command */
{
#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1){DbgMsg();DbgDBf("ExeY: called.\015\012");DbgROf();}
#endif

	if (EStTop > EStBot)			/* if numeric argument */
		{
		ErrMsg(ERR_NYA);		/* numeric argument with Y */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeY: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
		}

	if ((EdFlag & ED_YANK_OK) == 0)		/* if no yank when full EBf */
		if (IsOpnO[CurOut] &&		/* if output file is open */
		    ((GapBeg != EBfBeg) || (GapEnd != EBfEnd)))
			{
			ErrMsg(ERR_YCA);	/* Y command aborted */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeY: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
			}

#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeY: returning ExeEY()\015\012");DbgROf();}DbgInd-=2;
#endif
	return(ExeEY());
}
