|
|
1.1 root 1: /* @(#)strtok.c 1.2 */
2: /* 3.0 SID # 1.2 */
3: /*LINTLIBRARY*/
4: /*
5: * uses strpbrk and strspn to break string into tokens on
6: * sequentially subsequent calls. returns NULL when no
7: * non-separator characters remain.
8: * `subsequent' calls are calls with first argument NULL.
9: */
10:
11: #define NULL (char*)0
12:
13: extern int strspn();
14: extern char *strpbrk();
15:
16: char *
17: strtok(string, sepset)
18: char *string, *sepset;
19: {
20: register char *p, *q, *r;
21: static char *savept;
22:
23: /*first or subsequent call*/
24: p = (string == NULL)? savept: string;
25:
26: if(p == 0) /* return if no tokens remaining */
27: return(NULL);
28:
29: q = p + strspn(p, sepset); /* skip leading separators */
30:
31: if(*q == '\0') /* return if no tokens remaining */
32: return(NULL);
33:
34: if((r = strpbrk(q, sepset)) == NULL) /* move past token */
35: savept = 0; /* indicate this is last token */
36: else {
37: *r = '\0';
38: savept = ++r;
39: }
40: return(q);
41: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.