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

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

Unix line breaks.

  • 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();
16extern char *strpbrk();
17
18char *
19strtok(string, sepset)
20char *string, *sepset;
21{
22 register char *p, *q, *r;
23 static char *savept;
24
25 /* first or subsequent call ? */
26
27 p = (string == NULL) ? savept : string;
28
29 if (p == 0) /* return if no tokens remain */
30 return(NULL);
31
32 q = p + strspn(p, sepset); /* skip leading separators */
33
34 if (*q == '\0') /* return if no tokens remain */
35 return(NULL);
36
37 if ((r = strpbrk(q, sepset)) == NULL) /* move past token */
38 savept = 0; /* indicate this is last token */
39 else {
40 *r = '\0';
41 savept = ++r;
42 }
43
44 return(q);
45}
Note: See TracBrowser for help on using the repository browser.