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

	ExeEqu()

	This function executes the following forms of the = command:

		n=	display n in decimal,  with carriage return
		n==	display n in octal,  with carriage return
		n===	display n in hexadecimal,  with carriage return
		n:=	display n in decimal,  without carriage return
		n:==	display n in octal,  without carriage return
		n:===	display n in hexadecimal,  without carriage return

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

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

extern	VOID	ErrMsg();	/* display error message */
extern	DEFAULT	GetNmA();	/* get numeric argument */
extern	DEFAULT	IncCBP();	/* increment CBfPtr */
extern	VOID	MakDBf();	/* make ASCII number in digit buffer (DBf) */
extern	VOID	ZDspBf();	/* display a buffer on the terminal */

EXTERN	BYTE	CmdMod;		/* command modifiers flags for @, :, etc. */
EXTERN	char	*CBfPtr;	/* pointer into command string */
EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	char	*DBfBeg;	/* digit buffer beginning */
EXTERN	char	*DBfPtr;	/* digit buffer pointer */
EXTERN	LONG	NArgmt;		/* numeric argument */


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

	if (EStTop == EStBot)			/* if no numeric argument */
		{
		ErrMsg(ERR_NAE);		/* NAE = "No arg before =" */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEqu: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
		}

	if (GetNmA() == FAILURE)		/* get the numeric argument */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEqu: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif

	if (*(CBfPtr+1) != '=')			/* if next char not = */
		MakDBf(NArgmt, 10);		/* make string in decimal */
	else
		{
		if (IncCBP() == FAILURE)	/* move to next char */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEqu: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
#if DEBUGGING
}
#endif
		if (*(CBfPtr+1) != '=')		/* if next char not = */
			MakDBf(NArgmt, 8);	/* make string in octal */
		else
			{
			if (IncCBP() == FAILURE)/* move to next char */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEqu: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
				return(FAILURE);
#if DEBUGGING
}
#endif
			MakDBf(NArgmt, 16);	/* make string in hex */
			}
		}

	if ((CmdMod & COLON) == '\0')		/* if no colon modifier */
		{
		*DBfPtr++ = CRETRN;		/* append a carriage return */
		*DBfPtr++ = LINEFD;		/* append a line feed */
		}

	ZDspBf(DBfBeg, DBfPtr-DBfBeg);		/* display the string */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeEqu: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
