home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / c / help.arc / NEXT.C < prev    next >
Text File  |  1988-03-10  |  1KB  |  52 lines

  1. /*
  2.  * NEXT.C:
  3.  *
  4.  * Skip to the next delimiter seperated object
  5.  *
  6.  */
  7.  
  8. #define iswhite(c) ( (c) == ' ' || (c) == '\t' || (c) == '\n' )
  9.  
  10.  
  11. char    *next( linep, delim, esc )
  12. char    **linep;
  13. {
  14.     /* Linep is the address of a character pointer that points to
  15.      * a string containing a series of delim seperated objects.
  16.      * Next will return a pointer to the first non-white object in
  17.      * *linep, replace the first delimiter it finds with a null, and
  18.      * advance *linep to point past the null (provided that it's not
  19.      * at end of string). 0 is returned when an empty string is passed
  20.      * to next(). White space may be used as a delimiter but
  21.      * in this case whitespace won't be skipped. A delimiter preceeded
  22.      * by "esc" is ignored. Quoted strings are copied verbatum.
  23.      */ 
  24.  
  25.     register char    *start, *end ;
  26.     int        inquote = 0;
  27.  
  28.     if( !**linep )
  29.         return 0;
  30.  
  31.     start = *linep;
  32.  
  33.     if( !iswhite(delim) )
  34.         for( ; iswhite(*start) ; start++ )
  35.             ;
  36.  
  37.     for( end = start; *end && (*end != delim || inquote) ; end++ )
  38.     {
  39.         if( *end == esc  &&  *(end+1) )
  40.             end++;
  41.  
  42.          else if( *end == '"' || *end == '\'' )
  43.             inquote = ~inquote;
  44.     }
  45.  
  46.     if( *end )
  47.         *end++ = '\0';
  48.  
  49.     *linep = end;
  50.     return start;
  51. }
  52.