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

	ExeEN()

	This function executes an EN command.

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

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

extern	DEFAULT	BldStr();	/* build a string */
extern	VOID	ErrMsg();	/* display an error message */
extern	DEFAULT	PushEx();	/* push onto expression stack */
extern	DEFAULT	ZPWild();	/* preset the wildcard lookup filespec */
extern	DEFAULT	ZSWild();	/* search for next wildcard filespec */

EXTERN	BYTE	CmdMod;		/* command modifiers flags for :, @, etc. */
EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	char	FBfBeg[];	/* beginning of file specification buffer */
EXTERN	char	WBfBeg[];	/* beginning of wildcard filespec buffer */
EXTERN	char	*WBfEnd;	/* end of wildcard filespec buffer */
EXTERN	char	*WBfPtr;	/* pointer into wildcard filespec buffer */


DEFAULT ExeEN()			/* execute an EN command */
{

#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1){DbgMsg();DbgDBf("ExeEN: called.\015\012");DbgROf();}
#endif

	if (BldStr(WBfBeg, WBfEnd, &WBfPtr) == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEN: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif

	if (WBfPtr == WBfBeg)			/* if it's EN$ or :EN$ */
		switch (ZSWild()) {
		case FAILURE:
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEN: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
#if DEBUGGING
}
#endif
		case FILENF:
			if (CmdMod & COLON)	/* if it's :EN */
				{
				EStTop = EStBot;/* clear expression stack */
				CmdMod = '\0';	/* clear modifiers flags */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEN: returning PushEx(0L).\015\012");DbgROf();}DbgInd-=2;
#endif
				return(PushEx(0L, OPERAND));
				}
			else
				{
				ErrMsg(ERR_FNF, "\0");	/* file not found */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEN: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
				return(FAILURE);
				}
		case SUCCESS:
			if (CmdMod & COLON)	/* if it's :EN */
				{
				CmdMod = '\0';	/* clear modifiers flags */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEN: returning PushEx(-1L).\015\012");DbgROf();}DbgInd-=2;
#endif
				return(PushEx(-1L, OPERAND));
				}
			else
				{
				EStTop = EStBot;/* clear expression stack */
				CmdMod = '\0';	/* clear modifiers flags */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEN: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
				return(SUCCESS);
				}
		}

	if (ZPWild() == FAILURE)		/* preset wildcard filepsec */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEN: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif

	EStTop = EStBot;			/* clear expression stack */
	CmdMod = '\0';				/* clear modifiers flags */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEN: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
