source: trunk/athena/bin/attach/strtok.c @ 3274

Revision 3274, 1.3 KB checked in by jfc, 34 years ago (diff)
Initial revision
Line 
1#ifdef NEED_STRTOK
2/* strtok.c -- return tokens from a string, NULL if no token left */
3/* LINTLIBRARY */
4
5/*
6 * Get next token from string s1 (NULL on 2nd, 3rd, etc. calls),
7 * where tokens are nonempty strings separated by runs of
8 * chars from s2.  Writes NULs into s1 to end tokens.  s2 need not
9 * remain constant from call to call.
10 *
11 * Written by reading the System V Interface Definition, not the code.
12 *
13 * Totally public domain.
14 *
15 */
16
17#define NULL    0
18
19char *
20strtok(s1, s2)
21char *s1;
22register char *s2;
23{
24        register char *scan;
25        char *tok;
26        register char *scan2;
27        static char *scanpoint = (char *)NULL;
28
29        if (s1 == (char *)NULL && scanpoint == (char *)NULL)
30                return((char *)NULL);
31        if (s1 != (char *)NULL)
32                scan = s1;
33        else
34                scan = scanpoint;
35
36        /*
37         * Scan leading delimiters.
38         */
39        for (; *scan != '\0'; scan++) {
40                for (scan2 = s2; *scan2 != '\0'; scan2++)
41                        if (*scan == *scan2)
42                                break;
43                if (*scan2 == '\0')
44                        break;
45        }
46        if (*scan == '\0') {
47                scanpoint = (char *)NULL;
48                return((char *)NULL);
49        }
50
51        tok = scan;
52
53        /*
54         * Scan token.
55         */
56        for (; *scan != '\0'; scan++) {
57                for (scan2 = s2; *scan2 != '\0';)       /* ++ moved down. */
58                        if (*scan == *scan2++) {
59                                scanpoint = scan+1;
60                                *scan = '\0';
61                                return(tok);
62                        }
63        }
64
65        /*
66         * Reached end of string.
67         */
68        scanpoint = (char *)NULL;
69        return(tok);
70}
71
72/* strtok.c ends here */
73#endif /* NEED_STRTOK */
Note: See TracBrowser for help on using the repository browser.