FreeBSD/contrib/ntp/ntpq/ntpq.c
/*
 * tokenize - turn a command line into tokens
 *
 * SK: Modified to allow a quoted string
 *
 * HMS: If the first character of the first token is a ':' then (after
 * eating inter-token whitespace) the 2nd token is the rest of the line.
 */
turn a command line into tokens
SK: Modified to allow a quoted string

If the first character of the first token is a ':' then (after
eating inter-token whitespace) the 2nd token is the rest of the line.
turn a command line into tokens SK : Modified to allow a quoted string If the first character of the first token is a ' : ' then ( after eating inter - token whitespace ) the 2nd token is the rest of the line .
static void
tokenize(
	const char *line,
	char **tokens,
	int *ntok
	)
{
	register const char *cp;
	register char *sp;
	static char tspace[MAXLINE];
	sp = tspace;
	cp = line;
	for (*ntok = 0; *ntok < MAXTOKENS; (*ntok)++) {
		tokens[*ntok] = sp;
		while (ISSPACE(*cp))
		    cp++;
		if (ISEOL(*cp))
		    break;
		if (*ntok == 1 && tokens[0][0] == ':') {
			do {
				if (sp - tspace >= MAXLINE)
					goto toobig;
				*sp++ = *cp++;
			} while (!ISEOL(*cp));
		}
		else if (*cp == '\"') {
			++cp;
			do {
				if (sp - tspace >= MAXLINE)
					goto toobig;
				*sp++ = *cp++;
			} while ((*cp != '\"') && !ISEOL(*cp));
		}
		else {
			do {
				if (sp - tspace >= MAXLINE)
					goto toobig;
				*sp++ = *cp++;
			} while ((*cp != '\"') && !ISSPACE(*cp) && !ISEOL(*cp));
		}
		if (sp - tspace >= MAXLINE)
			goto toobig;
		*sp++ = '\0';
	}
	return;
  toobig:
	*ntok = 0;
	fprintf(stderr,
		"***Line `%s' is too big\n",
		line);
	return;
}
static void tokenize ( const char * line , char * * tokens , int * ntok ) { register const char * cp ; register char * sp ; static char tspace [ MAXLINE ] ; sp = tspace ; cp = line ; for ( * ntok = 0 ; * ntok < MAXTOKENS ; ( * ntok ) ++ ) { tokens [ * ntok ] = sp ; while ( ISSPACE ( * cp ) ) cp ++ ; if ( ISEOL ( * cp ) ) break ; if ( * ntok == 1 && tokens [ 0 ] [ 0 ] == ' ' ) { do { if ( sp - tspace >= MAXLINE ) goto toobig ; * sp ++ = * cp ++ ; } while ( ! ISEOL ( * cp ) ) ; } else if ( * cp == ' \" ' ) { ++ cp ; do { if ( sp - tspace >= MAXLINE ) goto toobig ; * sp ++ = * cp ++ ; } while ( ( * cp != ' \" ' ) && ! ISEOL ( * cp ) ) ; } else { do { if ( sp - tspace >= MAXLINE ) goto toobig ; * sp ++ = * cp ++ ; } while ( ( * cp != ' \" ' ) && ! ISSPACE ( * cp ) && ! ISEOL ( * cp ) ) ; } if ( sp - tspace >= MAXLINE ) goto toobig ; * sp ++ = ' \0 ' ; } return ; toobig : * ntok = 0 ; fprintf ( stderr , " \n " , line ) ; return ; }
tokenize - turn a command line into tokens
 SK: Modified to allow a quoted string
tokenize - turn a command line into tokens SK : Modified to allow a quoted string
/* Skip inter-token whitespace */ /* If we're at EOL we're done */ /* If this is the 2nd token and the first token begins
		 * with a ':', then just grab to EOL.
		 */ /* Check if this token begins with a double quote.
		 * If yes, continue reading till the next double quote
		 */ /* HMS: a missing closing " should be an error */ /* HMS: Why check for a " in the previous line? */