xref: /csrg-svn/lib/libc/vax/string/strsep.s (revision 61222)
142082Sbostic/*-
2*61222Sbostic * Copyright (c) 1990, 1993
3*61222Sbostic *	The Regents of the University of California.  All rights reserved.
442082Sbostic *
542082Sbostic * %sccs.include.redist.c%
642082Sbostic */
742082Sbostic
842082Sbostic#if defined(LIBC_SCCS) && !defined(lint)
9*61222Sbostic	.asciz "@(#)strsep.s	8.1 (Berkeley) 06/04/93"
1042082Sbostic#endif /* LIBC_SCCS and not lint */
1142082Sbostic
1242082Sbostic/*
1342082Sbostic * Get next word from string *stringp, where words are
1442082Sbostic * strings separated by characters from delim.
1542082Sbostic *
1642082Sbostic * Writes NULs into the string at *stringp to end tokens.
1742082Sbostic * On return, *stringp points past the last NUL written (if there might
1842082Sbostic * be further tokens), or is NULL (if there are definitely no more tokens).
1942082Sbostic *
2042082Sbostic * If *stringp is NULL, strtoken returns NULL.
2142082Sbostic *
2242082Sbostic * char *
2342082Sbostic * strtoken(stringp, delim)
2442082Sbostic *	register char **stringp;
2542082Sbostic *	register char const *delim;
2642082Sbostic */
2742082Sbostic#include "DEFS.h"
2842082Sbostic
2942082SbosticENTRY(strsep, 0)
3042082Sbostic	tstl	*4(ap)		/* if (*stringp == NULL) */
3142082Sbostic	bneq	0f
3242082Sbostic	clrl	r0		#	return (NULL);
3342082Sbostic	ret
3442082Sbostic
3542082Sbostic0:
3642082Sbostic	subl2	$32,sp		/* make room for 256 bit table */
3742082Sbostic	movc5	$0,(sp),$0,$32,(sp)
3842082Sbostic	movq	4(ap),r1	/* r1 = stringp, r2 = delim */
3942082Sbostic
4042082Sbostic	/* turn on bit for each character in s2, including '\0' */
4142082Sbostic1:
4242082Sbostic	movzbl	(r2)+,r0
4342082Sbostic	bbss	r0,(sp),1b
4442082Sbostic	bneq	1b
4542082Sbostic
4642082Sbostic	movl	(r1),r3		/* r3 = s = *stringp */
4742082Sbostic	movl	r3,r0		/* save return value */
4842082Sbostic
4942082Sbostic	/* scan for delimiters */
5042082Sbostic2:
5142082Sbostic	movzbl	(r3)+,r2	/* c = *s++ */
5242082Sbostic	bbc	r2,(sp),2b	/* loop until c is in table */
5342082Sbostic	beql	3f
5442082Sbostic	clrb	-1(r3)		/* if c!='\0', s[-1] = 0 */
5542082Sbostic	movl	r3,(r1)		/* and *stringp = s */
5642082Sbostic	ret
5742082Sbostic3:
5842082Sbostic	clrl	(r1)		/* else *stringp = NULL */
5942082Sbostic	ret
60