home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / duucp-1.17 / AU-117b4-src.lha / src / lib / strtokp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-24  |  1.3 KB  |  62 lines

  1. /*
  2.  * STRTOKP.C
  3.  *
  4.  * This function will return a pointer to a token from an input string.
  5.  * The first argument is a pointer to a pointer to an input string.
  6.  * After the call is made, the pointer to the string will be advanced
  7.  * past the extracted token.  The second argument is a pointer to a string
  8.  * of characters, any of which may be used to delimit a token.
  9.  *
  10.  * date  = strtokp(&input, delims);
  11.  * time  = strtokp(&input, delims);
  12.  * place = strtokp(&input, delims);
  13.  *
  14.  * Note: This function modifies the input string by inserting a null
  15.  * character to delimit the token.
  16.  *
  17.  * This function is very much like strtok(), but it does not retain any
  18.  * internal state, elminating the problem of not being able to scan more
  19.  * than one input string at a time.
  20.  *
  21.  * History:
  22.  *     Chris Hind Genly      7/10/90         Original Version
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include "config.h"
  28.  
  29. Prototype char *strtokp (char **, char *);
  30.  
  31. char *
  32. strtokp (char **inp, char *brk)
  33. {
  34.     char
  35.         *token,
  36.         *in,
  37.         c;
  38.  
  39.     if (inp == NULL || *inp == NULL)
  40.         return NULL;
  41.  
  42.     in = *inp;
  43.  
  44.     for (in; (c = *in) && strchr (brk, *in); ++in)
  45.            continue;
  46.  
  47.     if (c == 0)
  48.         return NULL;
  49.  
  50.     token = in;
  51.  
  52.     for (in; (c = *in) && !stpchr (brk, *in); ++in)
  53.            continue;
  54.  
  55.     if (c != 0)
  56.         *in++ = 0;
  57.  
  58.     *inp = in;
  59.  
  60.     return token;
  61. }
  62.