strtok.c revision 199767f8919635c4928607450d9e0abb932109ce
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1998 Softweyr LLC. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * strtok_r, from Berkeley strtok
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Oct 13, 1998 by Wes Peters <wes@softweyr.com>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1988, 1993
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The Regents of the University of California. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notices, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notices, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 3. Neither the name of the University nor the names of its contributors
199767f8919635c4928607450d9e0abb932109ceToomas Soome * may be used to endorse or promote products derived from this software
199767f8919635c4928607450d9e0abb932109ceToomas Soome * without specific prior written permission.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
199767f8919635c4928607450d9e0abb932109ceToomas Soome * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
199767f8919635c4928607450d9e0abb932109ceToomas Soome * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic char sccsid[] = "@(#)strtok.c 8.1 (Berkeley) 6/4/93";
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* LIBC_SCCS and not lint */
199767f8919635c4928607450d9e0abb932109ceToomas Soomechar *__strtok_r(char *, const char *, char **);
199767f8919635c4928607450d9e0abb932109ceToomas Soome__strtok_r(char *s, const char *delim, char **last)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (c == 0) { /* no non-delimiter characters */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Note that delim must have one NUL; we stop if we see that, too.
199767f8919635c4928607450d9e0abb932109ceToomas Soome } while (sc != 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* NOTREACHED */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static char *last;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Test the tokenizer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function.");
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (word = strtok(test, sep); word; word = strtok(NULL, sep))
199767f8919635c4928607450d9e0abb932109ceToomas Soome strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function.");
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (phrase = strtok_r(blah, sep, &brkb); phrase;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("So far we're at %s:%s\n", word, phrase);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* DEBUG_STRTOK */