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

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

Zero redundant declarations.

  • Property mode set to 100644
File size: 1016 bytes
RevLine 
[f40a309]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
[b28a12e]13#include "ram.h"
[f40a309]14
[7258c6a]15int8_t *strtok(int8_t *string, int8_t *sepset)
[f40a309]16{
[7258c6a]17 register int8_t *p, *q, *r;
18 static int8_t *savept;
[f40a309]19
20 /* first or subsequent call ? */
21
[7848656]22 p = (string == NULL) ? savept : string;
[f40a309]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.