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

	ExeEsc()

	This function executes an ESCAPE command.

An ESCAPE that is executed as a TECO command (as distinct from an ESCAPE
that is part of the syntax of some other TECO command) is ignored by TECO,
except that pending numeric values are discarded.  This command is useful
for discarding the value returned from a command (such as n%q) when that
value is not needed.

Two escapes cause TECO to exit from the current macro level.  If two escapes
are encountered from top level (not from within a macro),  then the command
string execution is terminated.  Both escapes must be true TECO commands
and not part of the syntax of some previous command.  That is, the first
ESCAPE cannot be part of the syntax of the preceeding TECO command.

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

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

extern	VOID	ZDspCh();	/* output a character to the terminal */

EXTERN	char	*CBfPtr;	/* pointer into command string */
EXTERN	BYTE	CmdMod;		/* command modifiers flags for @, :, etc. */
EXTERN	char	*CStEnd;	/* pointer to last char of command string */
EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	BOOLEAN	TraceM;		/* trace mode flag */


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

	if (*(CBfPtr+1) == ESCAPE)		/* if it's <ESC><ESC> */
		{
		if (TraceM)			/* if tracing is on */
			ZDspCh('$');		/* echo the escape */
		CBfPtr = CStEnd;		/* exit this macro level */
		}
	else
		{
		CmdMod = '\0';			/* clear modifiers flags */
		EStTop = EStBot;		/* clear expression stack */
		}

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