home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / STR / STRTOK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  918 b   |  47 lines

  1. /* strtok.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <string.h>
  5.  
  6. char *strtok (char *string1, const char *string2)
  7. {
  8.   char table[256];
  9.   unsigned char *p, *result;
  10. #if defined (__MT__)
  11.   struct _thread *tp = _thread ();
  12. #define next (tp->_th_strtok_ptr)
  13. #else
  14.     static unsigned char *next = NULL;
  15. #endif
  16.   if (string1 != NULL)
  17.     p = (unsigned char *)string1;
  18.   else
  19.     {
  20.       if (next == NULL)
  21.         return (NULL);
  22.       p = next;
  23.     }
  24.   memset (table, 0, 256);
  25.   while (*string2 != 0)
  26.     table[(unsigned char)*string2++] = 1;
  27.   table[0] = 0;
  28.   while (table[*p])
  29.     ++p;
  30.   result = p;
  31.   table[0] = 1;
  32.   while (!table[*p])
  33.     ++p;
  34.   if (*p == 0)
  35.     {
  36.       if (p == result)
  37.         {
  38.           next = NULL;
  39.           return (NULL);
  40.         }
  41.     }
  42.   else
  43.     *p++ = 0;
  44.   next = p;
  45.   return ((char *)result);
  46. }
  47.