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

	ExeDgt()

	This function handles a digit encountered in a command string.
It converts the digit and any following digits into a binary value using
the current radix,  and pushes the value onto the expression stack.

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

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

extern	VOID	EchoIt();	/* echo a character to the terminal */
extern	VOID	ErrMsg();	/* display an error message */
extern	BOOLEAN	IsRadx();	/* is the character in the radix set? */
extern	DEFAULT	PushEx();	/* push onto expression stack */

EXTERN	char	*CBfPtr;	/* command modifiers flags for @, :, etc. */
EXTERN	char	*CStEnd;	/* pointer to last char of command string */
EXTERN	DEFAULT	Radix;		/* TECO's radix */
EXTERN	BOOLEAN	TraceM;		/* trace mode flag */


DEFAULT ExeDgt()		/* execute a digit command */
{
	LOCAL LONG	TmpLng;

#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1){DbgMsg();DbgDBf("ExeDgt: called.\015\012");DbgROf();}
#endif
	if ((Radix == 8) && (*CBfPtr > '7'))	/* if bad octal digit */
		{
		ErrMsg(ERR_ILN);		/* ILN = "illegal number" */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeDgt: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
		}

	TmpLng = 0L;
	do
		{
		TmpLng *= Radix;
		if (Is_Digit(*CBfPtr))
			TmpLng += *CBfPtr - '0';
		else if (Is_Upper(*CBfPtr))
			TmpLng += *CBfPtr - '\67';
		else
			TmpLng += *CBfPtr - '\127';
		if (CBfPtr == CStEnd)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeDgt: returning PushEx().\015\012");DbgROf();}DbgInd-=2;
#endif
			return(PushEx(TmpLng, OPERAND));
#if DEBUGGING
}
#endif
		++CBfPtr;
		if (IsRadx(*CBfPtr) && TraceM)
			EchoIt(*CBfPtr);
		}
	while (IsRadx(*CBfPtr) == YES);

	--CBfPtr;			/* cancel ExeCSt's ++CBfPtr */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeDgt: returning PushEx().\015\012");DbgROf();}DbgInd-=2;
#endif
	return(PushEx(TmpLng, OPERAND));
}
