* terminate_token.c
 *
 * DRH	920917	Prepare for external use.
 *

define NULL '\0'
define NULLCHAR (char *)0
define TRUE	1
define FALSE	0

define SPACE	0x20
define TAB		0x09

*.< Imported Functions >*

extern char				* index();

*.< Local Functions >*
	*.< Exported >*

char *					terminate_token();
unsigned int			tokenize();
char *					eat_white_space();

	*.< Internal >*

char *					t_t_l();

*.< Local Data >*

char					tab_space_list[] = \011 ;

*======================.==< Terminate Token List >=========================*
char * t_t_l( cp, tp)

char					* cp;		* pointer to subject character string	*
char					* tp;		* pointer to string of terminator(s)	*
{

	char				* ttp;			* temporary terminator pointer *

* Starting with cp look for the next termintor.  The first one encountered 
 * is replaced with a NULL and the address of the next byte is returned.  If 
 * no terminator is found before the end of the string return NULLCHAR.
 *

	if( (cp == NULLCHAR) || (tp == NULLCHAR)) {
		return NULLCHAR;
	}
	for( ; *cp; cp++) {
		for( ttp = tp; *ttp; ttp++) {
			if( *cp == *ttp) {
				*cp++ = NULL;
				return cp;
			}
		}
	}
	return NULLCHAR;
}
*======================.====< Terminate Token  >===========================*
char * terminate_token( cp)

char					* cp;
{
	return( t_t_l( cp, tab_space_list));
}
*======================.========< Tokenize >===============================*
unsigned int tokenize( cp)

char					* cp;
{
	char				* tp;
	unsigned int		tokens;

	* Returns count of tokens and squashes string
	 *    from: ...tokenA....tokenB..0
	 *      to: tokenA0tokenB0
	 *

	for( tokens = 0; cp = NULLCHAR; cp = t_t_l( cp, tab_space_list)) {
		tp = eat_white_space( cp);
		if( *tp) {
			tokens++;
		}
		if( tp > cp) {
			strcpy( cp, tp);
		}
	}
	return( tokens);
}
*======================.======< Tokenize Quote >============================*
unsigned int tokenize_quote( cp, quote)

char					* cp;
char					* quote;
{
	char				* tp;
	unsigned int		tokens;
	char				* list;

	* Returns count of tokens and squashes string
	 *    from: ...tokenA....tokenB..0
	 *      to: tokenA0tokenB0
	 *

	for( tokens = 0; cp = NULLCHAR; cp = t_t_l( cp, list)) {
		tp = eat_white_space( cp);
		if( *tp == *quote) {
			tp++;
			list = quote;
		} else {
			list = tab_space_list;
		}
		if( *tp) {
			tokens++;
		}
		if( tp > cp) {
			strcpy( cp, tp);
		}
	}
	return( tokens);
}

*======================.====< Eat White Space  >===========================*
char * eat_white_space( cp)

char					* cp;
{
	* Advance the given pointer while it points at a SPACE or TAB.  Return
	 * the address of whatever stopped the advance.  It may be a normal
	 * character or the NULL string terminator.
	 *

	if( cp == NULLCHAR)
		return NULLCHAR;

	while( *cp) {
		if(  ( (*cp == SPACE) || (*cp == TAB))) {
			break;
		}
		cp++;
	}

	return cp;
}
QfF
VEU
UUKz(|z|t
=FVEUFV
UY]UfEEE
Et2UFVEuFEUFV	FV
U]U
f
Eu
U
U;Vu;FuU
UEEtEUuFVUUEt UFVEUEUU