level/cmdlib.c
/*
==============
COM_Parse

Parse a token out of a string
==============
*/
COM_Parse
Parse a token out of a string
COM_Parse Parse a token out of a string
char *COM_Parse (char *data)
{
  int		c;
  int		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] == '*')
	{
		data += 2;
		for(;;)
		{
			if (!*data)
				break;
			if (*data != '*' || *(data+1) != '/')
				data++;
			else
			{
				data += 2;
				break;
			}
		}
		goto skipwhite;
	}
	if (c == '\"')
	{
		data++;
		do
		{
			c = *data++;
			if (c=='\"')
			{
				if (len == MAXTOKEN)
					len = 0;
				com_token[len] = 0;
				return data;
			}
			if (len < MAXTOKEN)
				com_token[len++] = (char)c;
		} while (1);
	}
  if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
	{
	  if (len < MAXTOKEN)
		  com_token[len++] = (char)c;
	  if (len == MAXTOKEN)
		  len = 0;
	  com_token[len] = 0;
	  return data+1;
	}
  do
	{
	  if (len < MAXTOKEN)
		  com_token[len++] = (char)c;
	  data++;
	  c = *data;
	  if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
	break;
	} while (c>32);
  if (len == MAXTOKEN)
	  len = 0;
  com_token[len] = 0;
  return data;
}
char * COM_Parse ( char * data ) { int c ; int 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 ] == ' ' ) { data += 2 ; for ( ; ; ) { if ( ! * data ) break ; if ( * data != ' ' || * ( data + 1 ) != ' ' ) data ++ ; else { data += 2 ; break ; } } goto skipwhite ; } if ( c == ' \" ' ) { data ++ ; do { c = * data ++ ; if ( c == ' \" ' ) { if ( len == MAXTOKEN ) len = 0 ; com_token [ len ] = 0 ; return data ; } if ( len < MAXTOKEN ) com_token [ len ++ ] = ( char ) c ; } while ( 1 ) ; } if ( c == ' ' || c == ' ' || c == ' ' || c == ' ' || c == ' \' ' || c == ' ' ) { if ( len < MAXTOKEN ) com_token [ len ++ ] = ( char ) c ; if ( len == MAXTOKEN ) len = 0 ; com_token [ len ] = 0 ; return data + 1 ; } do { if ( len < MAXTOKEN ) com_token [ len ++ ] = ( char ) c ; data ++ ; c = * data ; if ( c == ' ' || c == ' ' || c == ' ' || c == ' ' || c == ' \' ' || c == ' ' ) break ; } while ( c > 32 ) ; if ( len == MAXTOKEN ) len = 0 ; com_token [ len ] = 0 ; return data ; }
COM_Parse
Parse a token out of a string
COM_Parse 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