engine/cmdlib.c
/*	Parse a token out of a string
*/
Parse a token out of a string
Parse a token out of a string
char *COM_Parse(char *data)
{
	int		c,len;
	len = 0;
	com_token[0] = 0;
	if (!data)
		return NULL;
skipwhite:
	while ( (c = *data) <= ' ')
	{
		if (c == 0)
		{
			com_eof = true;
			return NULL;			
		}
		data++;
	}
	if (c=='/' && data[1] == '/')
	{
		while (*data && *data != '\n')
			data++;
		goto skipwhite;
	}
	if (c=='/' && data[1] == '*')
	{
		while (*data && (*data != '*' || data[1] != '/'))
			data++;
		goto skipwhite;
	}
	if (c == '\"')
	{
		data++;
		do
		{
			c = *data++;
			if (c=='\"')
			{
				com_token[len] = 0;
				return data;
			}
			com_token[len] = (char)c;
			len++;
		} while (1);
	}
	if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
	{
		com_token[len] = (char)c;
		len++;
		com_token[len] = 0;
		return data+1;
	}
	do
	{
		com_token[len] = (char)c;
		data++;
		len++;
		c = *data;
	if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
			break;
	} while (c>32);
	com_token[len] = 0;
	return data;
}
char * COM_Parse ( char * data ) { int c , len ; len = 0 ; com_token [ 0 ] = 0 ; if ( ! data ) return NULL ; skipwhite : while ( ( c = * data ) <= ' ' ) { if ( c == 0 ) { com_eof = true ; return NULL ; } data ++ ; } if ( c == ' ' && data [ 1 ] == ' ' ) { while ( * data && * data != ' \n ' ) data ++ ; goto skipwhite ; } if ( c == ' ' && data [ 1 ] == ' ' ) { while ( * data && ( * data != ' ' || data [ 1 ] != ' ' ) ) data ++ ; goto skipwhite ; } if ( c == ' \" ' ) { data ++ ; do { c = * data ++ ; if ( c == ' \" ' ) { com_token [ len ] = 0 ; return data ; } com_token [ len ] = ( char ) c ; len ++ ; } while ( 1 ) ; } if ( c == ' ' || c == ' ' || c == ' ' || c == ' ' || c == ' \' ' || c == ' ' ) { com_token [ len ] = ( char ) c ; len ++ ; com_token [ len ] = 0 ; return data + 1 ; } do { com_token [ len ] = ( char ) c ; data ++ ; len ++ ; c = * data ; if ( c == ' ' || c == ' ' || c == ' ' || c == ' ' || c == ' \' ' || c == ' ' ) break ; } while ( c > 32 ) ; com_token [ len ] = 0 ; return data ; }
Parse a token out of a string
Parse a token out of a string
// Skip whitespace // end of file; // skip // comments // Skip /* comments // handle quoted strings specially // parse single characters // parse a regular word