File:  [Research Unix] / researchv10no / cmd / prefer / libux3 / strtok.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

/*LINTLIBRARY*/
/*
 * uses strpbrk and strspn to break string into tokens on
 * sequentially subsequent calls.  returns NULL at end.
 * `subsequent' calls are calls with first argument NULL.
 */

#define	NULL	(char *) 0

char *
strtok(string, sepset)
char	*string, *sepset;
{
	int	strspn();
	char	*strpbrk();
	register char	*p, *q, *r;
	static	char	*savept;

	if(string == NULL)
		p = savept;
	else
		p = string;
	if(p == 0)
		return(NULL);
	q = p + strspn(p, sepset);
	if(*q == '\0')
		return(NULL);
	if((r = strpbrk(q, sepset)) == NULL)
		savept = 0;
	else {
		*r = '\0';
		p = r + strspn(r, sepset);
		savept = (p > r)? ++p: ++r;
	}
	return(q);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.