Esempio n. 1
0
/*
=================
ParseEpair
=================
*/
epair_t *ParseEpair( script_t *script ) {
	epair_t *e;
	token_t token;

	e = GetMemory( sizeof( epair_t ) );
	memset( e, 0, sizeof( epair_t ) );

	PS_ExpectAnyToken( script, &token );
	StripDoubleQuotes( token.string );
	if ( strlen( token.string ) >= MAX_KEY - 1 ) {
		Error( "ParseEpair: token %s too long", token.string );
	}
	e->key = copystring( token.string );
	PS_ExpectAnyToken( script, &token );
	StripDoubleQuotes( token.string );
	if ( strlen( token.string ) >= MAX_VALUE - 1 ) {
		Error( "ParseEpair: token %s too long", token.string );
	}
	e->value = copystring( token.string );

	// strip trailing spaces
	StripTrailing( e->key );
	StripTrailing( e->value );

	return e;
} //end of the function ParseEpair
Esempio n. 2
0
epair_t        *ParseEPair(void)
{
	epair_t        *e;


	/* allocate and clear new epair */
	e = safe_malloc(sizeof(epair_t));
	memset(e, 0, sizeof(epair_t));

	/* handle key */
	if(strlen(token) >= (MAX_KEY - 1))
		Error("ParseEPair: token too long");

	e->key = copystring(token);
	GetToken(qfalse);

	/* handle value */
	if(strlen(token) >= MAX_VALUE - 1)
		Error("ParseEpar: token too long");
	e->value = copystring(token);

	/* strip trailing spaces that sometimes get accidentally added in the editor */
	StripTrailing(e->key);
	StripTrailing(e->value);

	/* return it */
	return e;
}
Esempio n. 3
0
/*
================
UnparseEntities

Generates the sin_dentdata string from all the entities
================
*/
void Sin_UnparseEntities( void ) {
	char    *buf, *end;
	epair_t *ep;
	char line[2048];
	int i;
	char key[1024], value[1024];

	buf = sin_dentdata;
	end = buf;
	*end = 0;

	for ( i = 0 ; i < num_entities ; i++ )
	{
		ep = entities[i].epairs;
		if ( !ep ) {
			continue;   // ent got removed

		}
		strcat( end,"{\n" );
		end += 2;

		for ( ep = entities[i].epairs ; ep ; ep = ep->next )
		{
			strcpy( key, ep->key );
			StripTrailing( key );
			strcpy( value, ep->value );
			StripTrailing( value );

			sprintf( line, "\"%s\" \"%s\"\n", key, value );
			strcat( end, line );
			end += strlen( line );
		}
		strcat( end,"}\n" );
		end += 2;

		if ( end > buf + SIN_MAX_MAP_ENTSTRING ) {
			Error( "Entity text too long" );
		}
	}
	sin_entdatasize = end - buf + 1;
} //end of the function Sin_UnparseEntities
Esempio n. 4
0
/*
=================
ParseEpair
=================
*/
epair_t *ParseEpair(void)
{
  epair_t *e;

  e = malloc(sizeof(epair_t));
  memset(e, 0, sizeof(epair_t));

  if (strlen(token) >= MAX_KEY - 1)
    Error("ParseEpar: token too long");
  e->key = copystring(token);
  GetToken(false);
  if (strlen(token) >= MAX_VALUE - 1)
    Error("ParseEpar: token too long");
  e->value = copystring(token);

  // strip trailing spaces
  StripTrailing(e->key);
  StripTrailing(e->value);

  return e;
}
Esempio n. 5
0
/*
=================
ParseEpair
=================
*/
epair_t *ParseEpair( void ) {
	epair_t	*e;

	e = malloc( sizeof(epair_t) );
	memset( e, 0, sizeof(epair_t) );
	
	if ( strlen(token) >= MAX_KEY-1 ) {
		Error ("ParseEpar: token too long");
	}
	e->key = copystring( token );
	GetToken( qfalse );
	if ( strlen(token) >= MAX_VALUE-1 ) {
		Error ("ParseEpar: token too long");
	}
	e->value = copystring( token );

	// strip trailing spaces that sometimes get accidentally
	// added in the editor
	StripTrailing( e->key );
	StripTrailing( e->value );

	return e;
}
Esempio n. 6
0
void UnparseEntities(void)
{
	int             i;
	char           *buf, *end;
	epair_t        *ep;
	char            line[2048];
	char            key[1024], value[1024];
	const char     *value2;


	/* setup */
	AUTOEXPAND_BY_REALLOC(bspEntData, 0, allocatedBSPEntData, 1024);
	buf = bspEntData;
	end = buf;
	*end = 0;

	/* run through entity list */
	for(i = 0; i < numBSPEntities && i < numEntities; i++)
	{
		{
			int             sz = end - buf;

			AUTOEXPAND_BY_REALLOC(bspEntData, sz + 65536, allocatedBSPEntData, 1024);
			buf = bspEntData;
			end = buf + sz;
		}

		/* get epair */
		ep = entities[i].epairs;
		if(ep == NULL)
			continue;			/* ent got removed */

		/* ydnar: certain entities get stripped from bsp file */
		value2 = ValueForKey(&entities[i], "classname");
		if(!Q_stricmp(value2, "misc_model") || !Q_stricmp(value2, "_decal") || !Q_stricmp(value2, "_skybox"))
			continue;

		/* add beginning brace */
		strcat(end, "{\n");
		end += 2;

		/* walk epair list */
		for(ep = entities[i].epairs; ep != NULL; ep = ep->next)
		{
			/* copy and clean */
			strcpy(key, ep->key);
			StripTrailing(key);
			strcpy(value, ep->value);
			StripTrailing(value);

			/* add to buffer */
			sprintf(line, "\"%s\" \"%s\"\n", key, value);
			strcat(end, line);
			end += strlen(line);
		}

		/* add trailing brace */
		strcat(end, "}\n");
		end += 2;

		/* check for overflow */
		if(end > buf + allocatedBSPEntData)
			Error("Entity text too long");
	}

	/* set size */
	bspEntDataSize = end - buf + 1;
}