/* This subroutine 'parses' the string passed to it. The 'word' is filled
 * in so that the calling routine may use it.
 * It returns non-zero on error and zero if everything is OK.
 *
 * $Log: parse.c,v $
 * Revision 1.2  1997/06/04 01:15:17  david
 * ANSI-fied the program.
 *
 */

#include <stdio.h>

static char *RcsId = "$Id: parse.c,v 1.2 1997/06/04 01:15:17 david Exp $";

/* length =  Max. length of word (not including NULL) */
int parse( char **string, char *word, int length, char chr )
{
char c;
   
while ( **string == ' ' || **string == '\t' ) /* Skip spaces & tabs */
   *string = *string + 1; /* Bump pointer to next character */

while ( (c = **string) != chr && length && c != '\t' && c!= '\0' )
   {
   if ( c == '\'' ) /* Special processing for apostrophe */
      do {
         *word++ = **string; /* Copy into word */
	 length--;
         *string = *string + 1; /* Bump pointer to next character */
	 c = **string;
         } while ( c != '\'' && c != '\0' && (length - 1) );
   *word++ = c; /* Copy into word */
   *string = *string + 1; /* Bump pointer to next character */
   length--;
   }
   
*word = '\0'; /* Terminate string */
if ( c != chr && c != '\t' && c != '\0' )
   return 1; /* Error */
return 0; /* Everything OK */
}
