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

	ExeCtI()

	This function executes a control-I command.

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

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

extern	DEFAULT	FindES();	/* find end of string */
extern	DEFAULT	GroEBf();	/* expand the edit buffer gap */
extern	VOID	ZCpyBl();	/* copy block of memory */

EXTERN	char	*ArgPtr;	/* beginning of text argument */
EXTERN	BYTE	CmdMod;		/* command modifiers flags for @, :, etc. */
EXTERN	char	*CBfPtr;	/* pointer into command string */
EXTERN	WORD	EStBot;		/* expression stack bottom */
EXTERN	WORD	EStTop;		/* expression stack top */
EXTERN	char	*GapBeg;	/* edit buffer gap begining */
EXTERN	char	*GapEnd;	/* edit buffer gap end */
EXTERN	LONG	RefLen;		/* value of ^S command */


DEFAULT ExeCtI()			/* execute control-I (tab) command */
{
#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1){DbgMsg();DbgDBf("ExeCtI: called.\015\012");DbgROf();}
#endif

	if (FindES(ESCAPE) == FAILURE)		/* find end of text arg */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeCtI: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif
	RefLen = (ArgPtr - CBfPtr) - 1L;
	if ((GapEnd-GapBeg) < -RefLen)
		if (GroEBf(-RefLen) == FAILURE)
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ExeCtI: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
#if DEBUGGING
}
#endif
	*GapBeg++ = TABCHR;			/* insert the TAB */
	ZCpyBl(-RefLen, ArgPtr, GapBeg);	/* insert the string */
	GapBeg -= RefLen;			/* adjust the gap */
	--GapBeg;

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