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

	ExeSCl()

	This function executes a semi-colon (:) command.

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

#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	DEFAULT	FlowEL();	/* flow to end of loop */
extern	DEFAULT	GetNmA();	/* get numeric argument */

EXTERN	BYTE	CmdMod;		/* command modifiers flags for @, :, etc. */
EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	WORD	LStBot;		/* bottom of loop stack */
EXTERN	WORD	LStTop;		/* top of loop stack */
EXTERN	LONG	NArgmt;		/* numeric argument */


DEFAULT ExeSCl()			/* execute semi-colon command */
{
#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1){DbgMsg();DbgDBf("ExeSCl: called.\015\012");DbgROf();}
#endif
	if (LStTop == LStBot)			/* if not in a loop */
		{
		ErrMsg(ERR_SNI);		/* ; not in iteration */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeSCl: returning FAILURE\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
		}

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

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

/*
  If not colon-modified and numeric arg is greater than zero OR
     colon-modified and numeric argument is less than zero
	flow to the end of the loop
	decrement the loop stack pointer (we're leaving the loop)
*/

	if (
	    (((CmdMod & COLON) == 0) && (NArgmt >= 0L)) ||
	    ((CmdMod & COLON) && (NArgmt < 0L))
	   )
		if (FlowEL() == FAILURE)	/* flow to end of loop */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeSCl: returning FAILURE\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
#if DEBUGGING
}
#endif

	CmdMod = '\0';				/* clear modifiers flags */
	EStTop = EStBot;			/* clear expression stack */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeSCl: returning SUCCESS\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
