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

	ExeCtT()

	This function executes a control-T command.

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

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

extern	VOID	EchoIt();	/* echo a character to to terminal */
extern	VOID	ErrMsg();	/* display an error message */
extern	DEFAULT	GetNmA();	/* get numeric argument */
extern	DEFAULT	PushEx();	/* push onto expression stack */
extern	char	ZChIn();	/* input a character from the terminal */
extern	char	ZChrIt();	/* type-convert a char to a long */
extern	VOID	ZDspCh();	/* output a character to the terminal */

EXTERN	BYTE	CmdMod;		/* command modifiers flags for @, :, etc. */
EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	WORD	EtFlag;		/* ET mode control flag */
EXTERN	BOOLEAN	GotCtC;		/* YES if the user just hit a CTRL_C */
EXTERN	BOOLEAN	NoWait;		/* tells ZChin whether to wait or not */
EXTERN	LONG	NArgmt;		/* numeric argument */


DEFAULT ExeCtT()		/* execute a ^T (control-T) command */
{
	LOCAL char Charac;

#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1){DbgMsg();DbgDBf("ExeCtT: called.\015\012");DbgROf();}
#endif
	if (EStTop > EStBot)			/* if numeric argument */
		{
		if (GetNmA() == FAILURE)	/* get numeric arg */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeCtT: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
#if DEBUGGING
}
#endif
		if ((NArgmt < 0L) || (NArgmt > 127L))
			{
			ErrMsg(ERR_ARG);	/* "improper arguments" */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeCtT: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
			}
		ZDspCh(ZChrIt(NArgmt));
		CmdMod = '\0';			/* clear modifiers flags */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeCtT: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(SUCCESS);
		}

	if (EtFlag & ET_NO_WAIT)		/* if read with no wait */
		NoWait = YES;			/* tell ZChin not to wait */

	Charac = ZChIn();			/* read a character */
	NoWait = NO;				/* reset to default state */
	if (GotCtC)				/* if got a control-C */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeCtT: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif

	if (((EtFlag & ET_NO_ECHO) == 0) &&	/* if supposed to echo and */
	     (Charac != '\0'))			/* it's worth echoing */
		EchoIt(Charac);			/* then echo it */

#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeCtT: returning PushEx().\015\012");DbgROf();}DbgInd-=2;
#endif
	return(PushEx((LONG)Charac, OPERAND));
}
