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

	Mung()

	This function executes a TECO program.  It is called if the command
line used to invoke TECO-C contained the "-p" switch.
	If the command used to invoke TECOC contained a -d switch,  then the
text following the "-d" (pointed to by DArg) is inserted into the edit buffer.
Then the TmpEI function is called to execute an EI command for the file in the
FBF buffer.

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

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

extern	DEFAULT	ExeCSt();	/* execute a command string */
extern	VOID	TmpEI();	/* execute temporary EI command */
extern	VOID	ZDspBf();	/* display a buffer on the terminal */

EXTERN	char	*CBfPtr;	/* pointer into command buffer */
EXTERN	char	*CStEnd;	/* pointer to last char of command string */
EXTERN	char	*DArg;		/* argument part of D command line switch */
EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	WORD	EtFlag;		/* ET mode control flag */
EXTERN	char	FBfBeg[];	/* file specification buffer */
EXTERN	char	*FBfPtr;	/* pointer into file specification buffer */
EXTERN	BOOLEAN	Swit_D;		/* was a D command line switch parsed? */



VOID Mung()			/* execute TECO program */
{
	char	MngBeg[256];	/* temporary command string (mung) buffer */
	char	*MngPtr;	/* pointer into mung buffer */
	char	*TmpPtr;	/* temporary pointer */

#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1){DbgMsg();DbgDBf("Mung: called\015\012");DbgROf();}
#endif

	EtFlag |= ET_MUNG_MODE;		/* turn on "mung mode" flag */
	if (Swit_D)
		{
		MngPtr = MngBeg;
		*MngPtr++ = 'i';
		while (*MngPtr++ = *DArg++)
			;
		*MngPtr++ = ESCAPE;	/* terminate the ... */
		*MngPtr = ESCAPE;	/* ... command string */
		CBfPtr = MngBeg;	/* command string start */
		CStEnd = MngPtr;	/* command string end */
		EStTop = EStBot;	/* clear expression stack */
		ExeCSt();		/* execute command string */
		}
	TmpEI();
	EtFlag &= ~ET_MUNG_MODE;	/* turn off "mung mode" flag */
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("Mung: returning\015\012");DbgROf();}DbgInd-=2;
#endif
}
