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

	GetNmA()

	This function "gets the numeric argument".  When a command which takes
a numeric argument is executed,  it checks whether the expression stack is
empty.  If the expression stack is not empty,  this routine is called to get
the numeric argument on the expression stack into global variable Number.

	It is assumed that the calling function checked that the expression
stack is non-empty (i.e. that EStTop > EStBot).  This function checks that
the expression stack contains only a single operand.  If it does,  that
operand is moved to global variable NArgmt and the expression stack is cleared.

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

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

extern	VOID	ErrMsg();	/* display an error message */
extern	char	ZChrIt();	/* type cast LONG to char */
extern	VOID	ZDspCh();	/* output a character to the terminal */

EXTERN	struct	EStck EStack[]; /* expression stack */
EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	LONG	NArgmt;		/* numeric argument */


DEFAULT GetNmA()		/* get numeric argument */
{
#if DEBUGGING
DbgInd+=2;if(DbgLvl>=2){DbgMsg();DbgDBf("GetNmA: called.\015\012");DbgROf();}
#endif

	if ((EStTop == (EStBot + 1)) &&		/* if one guy on stack and */
	    (EStack[EStTop].ElType == OPERAND))	/* it's an operand */
		{
		NArgmt = EStack[EStTop].Elemnt;
		EStTop = EStBot;		/* clear expression stack */
#if DEBUGGING
if(DbgLvl>=2){DbgMsg();DbgDBf("GetNmA: returning SUCCESS");
DbgDBf(", NArgmt = ");MakDBf(NArgmt, 10);ZDspBf(DBfBeg, DBfPtr-DBfBeg);
DbgDBf("\015\012");DbgROf();}DbgInd-=2;
#endif
		return(SUCCESS);
		}

#if NO
	DbgROn();
	DbgDBf("GetNmA: dying with UTC, EStBot = ");
	MakDBf(EStBot, 10);ZDspBf(DBfBeg, DBfPtr-DBfBeg);
	DbgDBf(", stack holds:\015\012");
	while (EStTop > 0)
		{
		DbgDBf("GetNmA: EStack[");
		MakDBf(EStTop, 10);
		ZDspBf(DBfBeg, DBfPtr-DBfBeg);
		DbgDBf("].ElType = ");
		if (EStack[EStTop].ElType == OPERATOR)
			{
			DbgDBf("OPERATOR, EStack[");
			MakDBf(EStTop, 10);
			ZDspBf(DBfBeg, DBfPtr-DBfBeg);
			DbgDBf("].Elemnt = \"");
			ZDspCh(ZChrIt(EStack[EStTop].Elemnt));
			DbgDBf("\"\015\012");
			}
		else
			{
			DbgDBf("OPERAND, EStack[");
			MakDBf(EStTop, 10);
			ZDspBf(DBfBeg, DBfPtr-DBfBeg);
			DbgDBf("].Elemnt = ");
			MakDBf(EStack[EStTop].Elemnt, 10);
			ZDspBf(DBfBeg, DBfPtr-DBfBeg);
			DbgDBf("\015\012");
			}
		EStTop--;
		}
	DbgROf();
#endif
	ErrMsg(ERR_UTC);			/* unterminated command */
	return(FAILURE);
}
