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

	ExeER()

	This function executes an ER command.

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

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

extern	DEFAULT	BldStr();	/* build a string */
extern	DEFAULT	PushEx();	/* push onto expression stack */
extern	DEFAULT	ZOpInp();	/* open input file */

EXTERN	BYTE	CmdMod;		/* command modifiers flags for @, :, etc. */
EXTERN	DEFAULT	CurInp;		/* index of current input stream in IFiles */
EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	char	FBfBeg[];	/* beginning of file specification buffer */
EXTERN	char	*FBfEnd;	/* end of file specification buffer */
EXTERN	char	*FBfPtr;	/* pointer into file specification buffer */


DEFAULT ExeER()			/* execute an ER command */
{
#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1){DbgMsg();DbgDBf("ExeER: called.\015\012");DbgROf();}
#endif
	if (BldStr(FBfBeg, FBfEnd, &FBfPtr) == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeER: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif
	if (FBfPtr == FBfBeg)			/* if it's ER$ */
		{
		CurInp = PINPFL;
		CmdMod = '\0';			/* clear modifiers flags */
		EStTop = EStBot;		/* clear expression stack */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeER: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(SUCCESS);
		}

	if (ZOpInp(CurInp, NO) == FAILURE)
		{
		if (CmdMod & COLON)		/* if it's :ER */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeER: returning PushEx(0).\015\012");DbgROf();}DbgInd-=2;
#endif
			return(PushEx(0L, OPERAND));
#if DEBUGGING
}
#endif
		else
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeER: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
		}

	if (CmdMod & COLON)			/* if it's :ER */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeER: returning PushEx(-1).\015\012");DbgROf();}DbgInd-=2;
#endif
		return(PushEx(-1L, OPERAND));
#if DEBUGGING
}
#endif
	CmdMod = '\0';				/* clear modifiers flags */
	EStTop = EStBot;			/* clear expression stack */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeER: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
