FreeBSD/usr.sbin/asf/asf.c
/*
 * Take a blank separated list of tokens and turn it into a list of
 * individual nul-delimited strings.  Build a list of pointers at
 * token, which must have enough space for the tokens.  Return the
 * number of tokens, or -1 on error (typically a missing string
 * delimiter).
 */
Take a blank separated list of tokens and turn it into a list of
individual nul-delimited strings.  Build a list of pointers at
token, which must have enough space for the tokens.  Return the
number of tokens, or -1 on error (typically a missing string
delimiter).
Take a blank separated list of tokens and turn it into a list of individual nul - delimited strings . Build a list of pointers at token which must have enough space for the tokens . Return the number of tokens or - 1 on error ( typically a missing string delimiter ) .
int
tokenize(char *cptr, char *token[], int maxtoken)
{
    char delim;				
    int tokennr;			
    for (tokennr = 0; tokennr < maxtoken;) {
	while (isspace(*cptr))
	    cptr++;			
	if ((*cptr == '\0') || (*cptr == '\n')
	    || (*cptr == '#'))		
	    return tokennr;		
	delim = *cptr;
	token[tokennr] = cptr;		
	tokennr++;			
	if (tokennr == maxtoken)	
	    return tokennr;
	if ((delim == '\'') || (delim == '"')) { 
	    for (;;) {
		cptr++;
		if ((*cptr == delim)
		    && (cptr[-1] != '\\')) { 
		    cptr++;		
		    if (!isspace(*cptr)) 
			return -1;
		    *cptr++ = '\0';	
		} else if ((*cptr == '\0')
		    || (*cptr == '\n'))	
		    return -1;
	    }
	} else {			
	    while ((*cptr != '\0') && (!isspace(*cptr)) && (*cptr != '\n'))
		cptr++;
	    if (*cptr != '\0')		
		*cptr++ = '\0';		
	}
    }
    return maxtoken;			
}
int tokenize ( char * cptr , char * token [ ] , int maxtoken ) { char delim ; int tokennr ; for ( tokennr = 0 ; tokennr < maxtoken ; ) { while ( isspace ( * cptr ) ) cptr ++ ; if ( ( * cptr == ' \0 ' ) || ( * cptr == ' \n ' ) || ( * cptr == ' ' ) ) return tokennr ; delim = * cptr ; token [ tokennr ] = cptr ; tokennr ++ ; if ( tokennr == maxtoken ) return tokennr ; if ( ( delim == ' \' ' ) || ( delim == ' ' ) ) { for ( ; ; ) { cptr ++ ; if ( ( * cptr == delim ) && ( cptr [ -1 ] != ' \\ ' ) ) { cptr ++ ; if ( ! isspace ( * cptr ) ) return -1 ; * cptr ++ = ' \0 ' ; } else if ( ( * cptr == ' \0 ' ) || ( * cptr == ' \n ' ) ) return -1 ; } } else { while ( ( * cptr != ' \0 ' ) && ( ! isspace ( * cptr ) ) && ( * cptr != ' \n ' ) ) cptr ++ ; if ( * cptr != ' \0 ' ) * cptr ++ = ' \0 ' ; } } return maxtoken ; }
Take a blank separated list of tokens and turn it into a list of
 individual nul-delimited strings.
Take a blank separated list of tokens and turn it into a list of individual nul - delimited strings .
/* delimiter to search for */ /* index of this token */ /* skip initial white space */ /* end of line */ /* return number of tokens found */ /* point to it */ /* one more */ /* run off the end? */ /* delimitered */ /* found the partner */ /* move on past */ /* no space after closing quote */ /* delimit */ /* end of line */ /* not quoted */ /* not end of the line, */ /* delimit and move to the next */ /* can't get here */