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

	ExePW()

	This function executes a PW command.

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

#include "ZPort.h"		/* define portability identifiers */
#include "DefTeco.h"		/* define general identifiers */

extern	VOID	StCopy();	/* string copy */
extern	DEFAULT	GetAra();	/* get m,n area */
extern	DEFAULT	WrPage();	/* write to output file */

EXTERN	char	*AraBeg;	/* beginning of m,n area */
EXTERN	DEFAULT	CurOut;		/* index of current output stream in OFiles */
EXTERN	char	*EBfBeg;	/* beginning of edit buffer */
EXTERN	char	*GapBeg;	/* beginning of edit buffer gap */
EXTERN	char	*CBfPtr;	/* pointer into command string */
EXTERN	BYTE	CmdMod;		/* command modifiers flags for @, :, etc. */
EXTERN	char	*AraEnd;	/* end of m,n area */
EXTERN	char	*EBfEnd;	/* end of edit buffer */
EXTERN	char	*GapEnd;	/* end of edit buffer gap */
EXTERN	char	ErrTxt[];	/* holds part of error message */
EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	LONG	MArgmt;		/* m part of m,n numeric arguments */
EXTERN	LONG	NArgmt;		/* numeric argument */


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

	if (CmdMod & MARGIS)			/* if it's m,nPW */
		{
		if (MArgmt != NArgmt)		/* if m != n */
			{
			StCopy(ErrTxt,
				((*CBfPtr == 'W') || (*CBfPtr == 'w'))
						? "m,nPW" : "m,nP");
			if (GetAra() == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExePW: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
				return(FAILURE);
#if DEBUGGING
}
#endif
			if (WrPage(CurOut,AraBeg, AraEnd, 0L) == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExePW: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
				return(FAILURE);
#if DEBUGGING
}
#endif
			}
		}
	else					/* else it's nPW */
		while (NArgmt-- > 0L)
			if (WrPage(CurOut, EBfBeg, EBfEnd, -1L) == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExePW: 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("ExePW: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
