Subversion Repositories Kolibri OS

Rev

Rev 8793 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
  2. #include <string.h>
  3.  
  4. char* strtok(char* s, const char* delim)
  5. {
  6.     const char* spanp;
  7.     int c, sc;
  8.     char* tok;
  9.     static char* last;
  10.  
  11.     if (s == NULL && (s = last) == NULL)
  12.         return (NULL);
  13.  
  14.     /*
  15.      * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
  16.      */
  17. cont:
  18.     c = *s++;
  19.     for (spanp = delim; (sc = *spanp++) != 0;) {
  20.         if (c == sc)
  21.             goto cont;
  22.     }
  23.  
  24.     if (c == 0) { /* no non-delimiter characters */
  25.         last = NULL;
  26.         return (NULL);
  27.     }
  28.     tok = s - 1;
  29.  
  30.     /*
  31.      * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
  32.      * Note that delim must have one NUL; we stop if we see that, too.
  33.      */
  34.     for (;;) {
  35.         c = *s++;
  36.         spanp = delim;
  37.         do {
  38.             if ((sc = *spanp++) == c) {
  39.                 if (c == 0)
  40.                     s = NULL;
  41.                 else
  42.                     s[-1] = 0;
  43.                 last = s;
  44.                 return (tok);
  45.             }
  46.         } while (sc != 0);
  47.     }
  48.     /* NOTREACHED */
  49. }
  50.