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

	FindES()

	This function finds the end of the text argument to a command.
If the command is at-sign (@) modified,  the text argument may be delimited
by a special character.
	On entry,  CBfPtr points at the beginning of the text argument.
TrmChr contains the "usual" termination character for the command.  If the
ATSIGN bit of CmdMod is set,  it means the command is at-sign modified.
In that case the first character of the text argument (pointed to by CBfPtr)
is the delimiter character.
	On return,  ArgPtr points to the beginning of the true text argument
and CBfPtr points to the termination character. 

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

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

extern	DEFAULT	IncCBP();	/* increment CBfPtr */

EXTERN	char	*ArgPtr;	/* beginning of text argument */
EXTERN	BYTE	CmdMod;		/* command modifiers flags for @, :, etc */
EXTERN	char	*CBfPtr;	/* pointer into command string */


DEFAULT FindES(TrmChr)		/* find end of text argument */
char TrmChr;			/* termination char if no @ modifier */

{
#if DEBUGGING
DbgInd+=2;if(DbgLvl>=2){DbgMsg();
DbgDBf("FindES: called, string is ");
if ((CmdMod & ATSIGN) == '\0')DbgDBf("not ");
DbgDBf("at-sign modified.\015\012");DbgROf();}
#endif
	if (IncCBP() == FAILURE)
#if DEBUGGING
{if(DbgLvl>=2)
{DbgMsg();DbgDBf("FindES: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
#if DEBUGGING
}
#endif

	if (CmdMod & ATSIGN)			/* if it's colon modified */
		{
		TrmChr = *CBfPtr;
		if (IncCBP() == FAILURE)
#if DEBUGGING
{if(DbgLvl>=2)
{DbgMsg();DbgDBf("FindES: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
#if DEBUGGING
}
#endif
		}
	ArgPtr = CBfPtr;
	while (*CBfPtr != TrmChr)
		if (IncCBP() == FAILURE)
#if DEBUGGING
{if(DbgLvl>=2)
{DbgMsg();DbgDBf("FindES: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
			return(FAILURE);
#if DEBUGGING
}
#endif
#if DEBUGGING
if(DbgLvl>=2){DbgMsg();
DbgDBf("FindES: returning SUCCESS.\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
