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

	ExeM()

	This function executes an M command.

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

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

extern	DEFAULT	ExeCSt();	/* execute a command string */
extern	DEFAULT	FindQR();	/* find a q-register index */
extern	DEFAULT	IncCBP();	/* increment CBfPtr */
extern	DEFAULT	PopMac();	/* pop variables after macro call */
extern	DEFAULT	PshMac();	/* push variables for macro call */

EXTERN	char	*(*QBfBeg);	/* beginning of q-register text area */
EXTERN	char	*(*QBfPtr);	/* end of q-register text area, plus 1 */


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

	if (IncCBP() == FAILURE)		/* if no character after M */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeM: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif

	if (FindQR() == FAILURE)		/* find q-register */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeM: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif

	if (*QBfBeg == NULL)			/* if q-register is empty */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeM: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(SUCCESS);
#if DEBUGGING
}
#endif

	if (PshMac(*QBfBeg, *QBfPtr) == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeM: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif

	if (ExeCSt() == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeM: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif

#if DEBUGGING
if(DbgLvl>=1){
DbgMsg();DbgDBf("ExeM: returning PopMac()\015\012");DbgROf();}DbgInd-=2;
#endif
	return(PopMac());
}
