source: buchla-68k/libsm/strtok.c@ 0580615

Last change on this file since 0580615 was 0580615, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Point of no return.

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/*
2 =============================================================================
3 strtok.c -- tokenize a string
4 Version 1 -- 1987-06-12
5
6 Uses strpbrk and strspn to break 'string' into tokens on
7 sequentially subsequent calls. Returns NULL when no
8 non-separator characters remain.
9 'subsequent' calls are calls with first argument == NULL.
10 =============================================================================
11*/
12
13#define NULL (char *)0
14
15extern int strspn(char *string, char *charset);
16extern char *strpbrk(char *string, char *brkset);
17
18char *strtok(char *string, char *sepset)
19{
20 register char *p, *q, *r;
21 static char *savept;
22
23 /* first or subsequent call ? */
24
25 p = (string == NULL) ? savept : string;
26
27 if (p == 0) /* return if no tokens remain */
28 return(NULL);
29
30 q = p + strspn(p, sepset); /* skip leading separators */
31
32 if (*q == '\0') /* return if no tokens remain */
33 return(NULL);
34
35 if ((r = strpbrk(q, sepset)) == NULL) /* move past token */
36 savept = 0; /* indicate this is last token */
37 else {
38 *r = '\0';
39 savept = ++r;
40 }
41
42 return(q);
43}
Note: See TracBrowser for help on using the repository browser.