home *** CD-ROM | disk | FTP | other *** search
- /*
- * strtok.c
- *
- * By Ross Ridge
- * Public Domain
- * 92/06/04 11:40:12
- *
- */
-
- #ifdef TEST
-
- #ifndef LIBTEST
- #define USE_MYSTRTOK
- #endif
- #include <stdio.h>
-
- #else
-
- #include "defs.h"
-
- #endif
-
- #ifdef USE_MYSTRTOK
-
- #ifdef USE_SCCS_IDS
- static const char SCCSid[] = "@(#) mytinfo strtok.c 3.3 92/06/04 public domain, By Ross Ridge";
- #endif
-
- static char *
- strtok(s1, s2)
- char *s1, *s2; {
- static char *pos = NULL;
- register char *s, *d;
- char *start;
-
- if (s1 == NULL) {
- s = pos;
- if (s == NULL)
- return NULL;
- } else {
- s = s1;
- while(*s != '\0') {
- d = s2;
- while(*d != *s) {
- if (*d == '\0')
- goto first; /* Oh, no! A goto! */
- d++;
- }
- s++;
- }
- pos = NULL;
- return NULL;
- }
-
- first:
- start = s;
- while(*s != '\0') {
- d = s2;
- while(*d != '\0') {
- if (*s == *d) {
- *s++ = '\0';
- while(*s != '\0') {
- d = s2;
- while(*s != *d) {
- if (*d == '\0') {
- pos = s;
- return start;
- }
- d++;
- }
- s++;
- }
- pos = NULL;
- return start;
- }
- d++;
- }
- s++;
- }
- pos = NULL;
- return start;
- }
-
- #endif
-
- #ifdef TEST
- int main(argc, argv)
- int argc;
- char **argv; {
- char *s;
- char s1[100];
- char *s2;
-
- if (argc > 1)
- s2 = argv[1];
- else
- s2 = " ";
-
- while (gets(s1) != NULL) {
- s = strtok(s1, s2);
- while(s != NULL) {
- printf("'%s'\n", s);
- s = strtok(NULL, s2);
- }
- }
-
- return 0;
- }
- #endif
-