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

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

Zero redundant declarations.

  • Property mode set to 100644
File size: 1016 bytes
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#include "ram.h"
14
15int8_t *strtok(int8_t *string, int8_t *sepset)
16{
17 register int8_t *p, *q, *r;
18 static int8_t *savept;
19
20 /* first or subsequent call ? */
21
22 p = (string == NULL) ? savept : string;
23
24 if (p == 0) /* return if no tokens remain */
25 return(NULL);
26
27 q = p + strspn(p, sepset); /* skip leading separators */
28
29 if (*q == '\0') /* return if no tokens remain */
30 return(NULL);
31
32 if ((r = strpbrk(q, sepset)) == NULL) /* move past token */
33 savept = 0; /* indicate this is last token */
34 else {
35 *r = '\0';
36 savept = ++r;
37 }
38
39 return(q);
40}
Note: See TracBrowser for help on using the repository browser.