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

	ExePrc()

	This function executes a % command.

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

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

extern	DEFAULT	FindQR();	/* find q-register index */
extern	DEFAULT	GetNmA();	/* get numeric argument */
extern	DEFAULT	IncCBP();	/* increment CBfPtr */
extern	DEFAULT	PushEx();	/* push onto expression stack */
extern	VOID	UMinus();	/* handle a unary minus */

EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	LONG	NArgmt;		/* numeric argument */
EXTERN	LONG	*QNumbr;	/* q-register number */


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

	if (EStTop == EStBot)			/* if no numeric argument */
		NArgmt = 1L;			/* default is 1%q */
	else
		{
		UMinus();			/* if it's -%, make it -1% */
		if (GetNmA() == FAILURE)	/* get numeric argument */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExePrc: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
#if DEBUGGING
}
#endif
		}

	if (IncCBP() == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExePrc: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif
	if (FindQR() == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExePrc: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif
	*QNumbr += NArgmt;
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExePrc: returning PushEx().\015\012");DbgROf();}DbgInd-=2;
#endif
	return(PushEx(*QNumbr, OPERAND));
}
