home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / strpbrk.c < prev    next >
C/C++ Source or Header  |  1993-10-14  |  2KB  |  85 lines

  1. /*
  2.  * GT CLIPPER STANDARD HEADER
  3.  *
  4.  * File......: strpbrk.c
  5.  * Author....: Andy M Leighton
  6.  * BBS.......: The Dark Knight Returns
  7.  * Net/Node..: 050/069
  8.  * User Name.: Andy Leighton
  9.  * Date......: 23/05/93
  10.  * Revision..: 1.00
  11.  *
  12.  * This is an original work by Andy Leighton and is placed in the
  13.  * public domain.
  14.  *
  15.  * Modification history:
  16.  * ---------------------
  17.  *
  18.  * $Log$
  19.  *
  20.  */
  21.  
  22. /*
  23.  *  $DOC$
  24.  *  $FUNCNAME$
  25.  *      GT_STRPBRK()
  26.  *  $CATEGORY$
  27.  *      String
  28.  *  $ONELINER$
  29.  *      Return string after 1st char from a set
  30.  *  $SYNTAX$
  31.  *      GT_StrpBrk(<cStr>, <cSet>) --> cString
  32.  *  $ARGUMENTS$
  33.  *      <cStr>   - The input string
  34.  *      <cSet>   - The set of characters to find
  35.  *  $RETURNS$
  36.  *      cString  - The input string after the first occurance of any
  37.  *                 character from <cSet>
  38.  *  $DESCRIPTION$
  39.  *      Return a string after the first occurance of any character from
  40.  *      the input set <cSet>.
  41.  *  $EXAMPLES$
  42.  *
  43.  *      ? GT_Strpbrk("This is a test", "sa ")  // prints "s is a test"
  44.  *      ? GT_Strpbrk("This is a test", "et")   // prints "test"
  45.  *
  46.  *  $END$
  47.  */
  48.  
  49.  
  50. #include "extend.h"
  51.  
  52.  
  53. CLIPPER
  54. GT_strpbrk()
  55. {
  56.   char *string;
  57.   char *cset;
  58.   int l1, l2;
  59.   int p1, p2;
  60.  
  61.   if (ISCHAR(1) && ISCHAR(2)) {
  62.     string = _parc(1);
  63.     cset   = _parc(2);
  64.     l1     = _parclen(1);
  65.     l2     = _parclen(2);
  66.     p1     = p2 = 0;
  67.  
  68.     do {
  69.       for (p2 = 0; (p2 < l2) && (cset[p2] != string[p1]); ++p2)
  70.          ;
  71.       if (p2 < l2) {
  72.          _retc(string + p1);
  73.          break;
  74.       }
  75.     } while (p1++ < l1);
  76.  
  77.     if (p2 >= l2)
  78.       _retc((char *) NULL);
  79.  
  80.   } else {
  81.     _retc((char *) NULL);               // parameter mismatch - error NullStr
  82.   }
  83. }
  84.  
  85.