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

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

Spaces to tabs.

  • 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 (int8_t *)0
14
15extern int16_t strspn(int8_t *string, int8_t *charset);
16extern int8_t *strpbrk(int8_t *string, int8_t *brkset);
17
18int8_t *strtok(int8_t *string, int8_t *sepset)
19{
20 register int8_t *p, *q, *r;
21 static int8_t *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.