2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
// q_shared.c -- stateless support routines that are included in each code dll
|
|
|
|
#include "q_shared.h"
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GROWLISTS
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
// malloc / free all in one place for debugging
|
|
|
|
extern "C" void *Com_Allocate( int bytes );
|
|
|
|
extern "C" void Com_Dealloc( void *ptr );
|
|
|
|
|
|
|
|
void Com_InitGrowList( growList_t *list, int maxElements ) {
|
|
|
|
list->maxElements = maxElements;
|
|
|
|
list->currentElements = 0;
|
|
|
|
list->elements = (void **)Com_Allocate( list->maxElements * sizeof( void * ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
int Com_AddToGrowList( growList_t *list, void *data ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
void **old;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
if ( list->currentElements != list->maxElements ) {
|
|
|
|
list->elements[list->currentElements] = data;
|
|
|
|
return list->currentElements++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// grow, reallocate and move
|
|
|
|
old = list->elements;
|
|
|
|
|
|
|
|
if ( list->maxElements < 0 ) {
|
|
|
|
Com_Error( ERR_FATAL, "Com_AddToGrowList: maxElements = %i", list->maxElements );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( list->maxElements == 0 ) {
|
|
|
|
// initialize the list to hold 100 elements
|
|
|
|
Com_InitGrowList( list, 100 );
|
|
|
|
return Com_AddToGrowList( list, data );
|
|
|
|
}
|
|
|
|
|
|
|
|
list->maxElements *= 2;
|
|
|
|
|
|
|
|
Com_DPrintf( "Resizing growlist to %i maxElements\n", list->maxElements );
|
|
|
|
|
|
|
|
list->elements = (void **)Com_Allocate( list->maxElements * sizeof( void * ) );
|
|
|
|
|
|
|
|
if ( !list->elements ) {
|
|
|
|
Com_Error( ERR_DROP, "Growlist alloc failed" );
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy( list->elements, old, list->currentElements * sizeof( void * ) );
|
|
|
|
|
|
|
|
Com_Dealloc( old );
|
|
|
|
|
|
|
|
return Com_AddToGrowList( list, data );
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Com_GrowListElement( const growList_t *list, int index ) {
|
|
|
|
if ( index < 0 || index >= list->currentElements ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
Com_Error( ERR_DROP, "Com_GrowListElement: %i out of range of %i",
|
|
|
|
index, list->currentElements );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
return list->elements[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
int Com_IndexForGrowListElement( const growList_t *list, const void *element ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
int i;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
for ( i = 0 ; i < list->currentElements ; i++ ) {
|
|
|
|
if ( list->elements[i] == element ) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
float Com_Clamp( float min, float max, float value ) {
|
|
|
|
if ( value < min ) {
|
|
|
|
return min;
|
|
|
|
}
|
|
|
|
if ( value > max ) {
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
Com_StringContains
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
const char *Com_StringContains( const char *str1, const char *str2, int casesensitive ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
int len, i, j;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
len = strlen( str1 ) - strlen( str2 );
|
|
|
|
for ( i = 0; i <= len; i++, str1++ ) {
|
|
|
|
for ( j = 0; str2[j]; j++ ) {
|
|
|
|
if ( casesensitive ) {
|
|
|
|
if ( str1[j] != str2[j] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( toupper( str1[j] ) != toupper( str2[j] ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !str2[j] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return str1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
Com_Filter
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
int Com_Filter( const char *filter, const char *name, int casesensitive ){
|
2007-11-04 03:51:54 +00:00
|
|
|
char buf[MAX_TOKEN_CHARS];
|
|
|
|
const char *ptr;
|
|
|
|
int i, found;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( *filter ) {
|
|
|
|
if ( *filter == '*' ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
filter++;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; *filter; i++ ) {
|
|
|
|
if ( *filter == '*' || *filter == '?' ) {
|
|
|
|
break;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
buf[i] = *filter;
|
|
|
|
filter++;
|
|
|
|
}
|
|
|
|
buf[i] = '\0';
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strlen( buf ) ) {
|
|
|
|
ptr = Com_StringContains( name, buf, casesensitive );
|
|
|
|
if ( !ptr ) {
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
name = ptr + strlen( buf );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( *filter == '?' ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
filter++;
|
|
|
|
name++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( *filter == '[' && *( filter + 1 ) == '[' ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
filter++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( *filter == '[' ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
filter++;
|
|
|
|
found = qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( *filter && !found ) {
|
|
|
|
if ( *filter == ']' && *( filter + 1 ) != ']' ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( *( filter + 1 ) == '-' && *( filter + 2 ) && ( *( filter + 2 ) != ']' || *( filter + 3 ) == ']' ) ) {
|
|
|
|
if ( casesensitive ) {
|
|
|
|
if ( *name >= *filter && *name <= *( filter + 2 ) ) {
|
|
|
|
found = qtrue;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( toupper( *name ) >= toupper( *filter ) &&
|
|
|
|
toupper( *name ) <= toupper( *( filter + 2 ) ) ) {
|
|
|
|
found = qtrue;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
filter += 3;
|
|
|
|
}
|
|
|
|
else {
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( casesensitive ) {
|
|
|
|
if ( *filter == *name ) {
|
|
|
|
found = qtrue;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( toupper( *filter ) == toupper( *name ) ) {
|
|
|
|
found = qtrue;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
filter++;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !found ) {
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
while ( *filter ) {
|
|
|
|
if ( *filter == ']' && *( filter + 1 ) != ']' ) {
|
|
|
|
break;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
filter++;
|
|
|
|
}
|
|
|
|
filter++;
|
|
|
|
name++;
|
|
|
|
}
|
|
|
|
else {
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( casesensitive ) {
|
|
|
|
if ( *filter != *name ) {
|
|
|
|
return qfalse;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( toupper( *filter ) != toupper( *name ) ) {
|
|
|
|
return qfalse;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
filter++;
|
|
|
|
name++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
Com_HashString
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
int Com_HashString( const char *fname ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
int i;
|
|
|
|
long hash;
|
|
|
|
char letter;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
hash = 0;
|
|
|
|
i = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( fname[i] != '\0' ) {
|
|
|
|
letter = tolower( fname[i] );
|
|
|
|
if ( letter == '.' ) {
|
|
|
|
break; // don't include extension
|
|
|
|
}
|
|
|
|
if ( letter == '\\' ) {
|
|
|
|
letter = '/'; // damn path names
|
|
|
|
}
|
|
|
|
hash += (long)( letter ) * ( i + 119 );
|
2007-11-04 03:51:54 +00:00
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
hash &= ( FILE_HASH_SIZE - 1 );
|
2007-11-04 03:51:54 +00:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
Com_SkipPath
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
char *Com_SkipPath( char *pathname ){
|
|
|
|
char *last;
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
last = pathname;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( *pathname )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( *pathname == '/' ) {
|
|
|
|
last = pathname + 1;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
pathname++;
|
|
|
|
}
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
Com_StripExtension
|
|
|
|
============
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
void Com_StripExtension( const char *in, char *out ) {
|
|
|
|
while ( *in && *in != '.' ) {
|
|
|
|
*out++ = *in++;
|
|
|
|
}
|
|
|
|
*out = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
Com_DefaultExtension
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
void Com_DefaultExtension( char *path, int maxSize, const char *extension ) {
|
|
|
|
char oldPath[MAX_QPATH];
|
2007-11-04 03:51:54 +00:00
|
|
|
char *src;
|
|
|
|
|
|
|
|
//
|
|
|
|
// if path doesn't have a .EXT, append extension
|
|
|
|
// (extension should include the .)
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
src = path + strlen( path ) - 1;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( *src != '/' && src != path ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( *src == '.' ) {
|
|
|
|
return; // it has an extension
|
|
|
|
}
|
|
|
|
src--;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_strncpyz( oldPath, path, sizeof( oldPath ) );
|
|
|
|
Com_sprintf( path, maxSize, "%s%s", oldPath, extension );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
BYTE ORDER FUNCTIONS
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
// can't just use function pointers, or dll linkage can
|
|
|
|
// mess up when qcommon is included in multiple places
|
2012-03-17 20:01:54 +00:00
|
|
|
static short ( *_BigShort )( short l );
|
|
|
|
static short ( *_LittleShort )( short l );
|
|
|
|
static int ( *_BigLong )( int l );
|
|
|
|
static int ( *_LittleLong )( int l );
|
|
|
|
static float ( *_BigFloat )( float l );
|
|
|
|
static float ( *_LittleFloat )( float l );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
short BigShort( short l ){return _BigShort( l ); }
|
|
|
|
short LittleShort( short l ) {return _LittleShort( l ); }
|
|
|
|
int BigLong( int l ) {return _BigLong( l ); }
|
|
|
|
int LittleLong( int l ) {return _LittleLong( l ); }
|
|
|
|
float BigFloat( float l ) {return _BigFloat( l ); }
|
|
|
|
float LittleFloat( float l ) {return _LittleFloat( l ); }
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
short ShortSwap( short l ){
|
|
|
|
byte b1,b2;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
b1 = l & 255;
|
|
|
|
b2 = ( l >> 8 ) & 255;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return ( b1 << 8 ) + b2;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
short ShortNoSwap( short l ){
|
2007-11-04 03:51:54 +00:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int LongSwap( int l ){
|
|
|
|
byte b1,b2,b3,b4;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
b1 = l & 255;
|
|
|
|
b2 = ( l >> 8 ) & 255;
|
|
|
|
b3 = ( l >> 16 ) & 255;
|
|
|
|
b4 = ( l >> 24 ) & 255;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return ( (int)b1 << 24 ) + ( (int)b2 << 16 ) + ( (int)b3 << 8 ) + b4;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int LongNoSwap( int l ){
|
2007-11-04 03:51:54 +00:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
float FloatSwap( float f ){
|
2007-11-04 03:51:54 +00:00
|
|
|
union
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
float f;
|
|
|
|
byte b[4];
|
2007-11-04 03:51:54 +00:00
|
|
|
} dat1, dat2;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
dat1.f = f;
|
|
|
|
dat2.b[0] = dat1.b[3];
|
|
|
|
dat2.b[1] = dat1.b[2];
|
|
|
|
dat2.b[2] = dat1.b[1];
|
|
|
|
dat2.b[3] = dat1.b[0];
|
|
|
|
return dat2.f;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
float FloatNoSwap( float f ){
|
2007-11-04 03:51:54 +00:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
Swap_Init
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void Swap_Init( void ){
|
|
|
|
byte swaptest[2] = {1,0};
|
|
|
|
|
|
|
|
// set the byte swapping variables in a portable manner
|
|
|
|
if ( *(short *)swaptest == 1 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
_BigShort = ShortSwap;
|
|
|
|
_LittleShort = ShortNoSwap;
|
|
|
|
_BigLong = LongSwap;
|
|
|
|
_LittleLong = LongNoSwap;
|
|
|
|
_BigFloat = FloatSwap;
|
|
|
|
_LittleFloat = FloatNoSwap;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_BigShort = ShortNoSwap;
|
|
|
|
_LittleShort = ShortSwap;
|
|
|
|
_BigLong = LongNoSwap;
|
|
|
|
_LittleLong = LongSwap;
|
|
|
|
_BigFloat = FloatNoSwap;
|
|
|
|
_LittleFloat = FloatSwap;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Com_ParseInfos
|
|
|
|
===============
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
int Com_ParseInfos( const char *buf, int max, char infos[][MAX_INFO_STRING] ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
const char *token;
|
|
|
|
int count;
|
|
|
|
char key[MAX_TOKEN_CHARS];
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
while ( 1 ) {
|
|
|
|
token = Com_Parse( &buf );
|
|
|
|
if ( !token[0] ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( strcmp( token, "{" ) ) {
|
|
|
|
Com_Printf( "Missing { in info file\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( count == max ) {
|
|
|
|
Com_Printf( "Max infos exceeded\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
infos[count][0] = 0;
|
|
|
|
while ( 1 ) {
|
|
|
|
token = Com_Parse( &buf );
|
|
|
|
if ( !token[0] ) {
|
|
|
|
Com_Printf( "Unexpected end of info file\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( !strcmp( token, "}" ) ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Q_strncpyz( key, token, sizeof( key ) );
|
|
|
|
|
|
|
|
token = Com_ParseOnLine( &buf );
|
|
|
|
if ( !token[0] ) {
|
|
|
|
token = "<NULL>";
|
|
|
|
}
|
|
|
|
Info_SetValueForKey( infos[count], key, token );
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LIBRARY REPLACEMENT FUNCTIONS
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int Q_isprint( int c ){
|
|
|
|
if ( c >= 0x20 && c <= 0x7E ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return ( 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
return ( 0 );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int Q_islower( int c ){
|
|
|
|
if ( c >= 'a' && c <= 'z' ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return ( 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
return ( 0 );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int Q_isupper( int c ){
|
|
|
|
if ( c >= 'A' && c <= 'Z' ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return ( 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
return ( 0 );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int Q_isalpha( int c ){
|
|
|
|
if ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return ( 1 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
return ( 0 );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
char* Q_strrchr( const char* string, int c ){
|
2007-11-04 03:51:54 +00:00
|
|
|
char cc = c;
|
|
|
|
char *s;
|
2012-03-17 20:01:54 +00:00
|
|
|
char *sp = (char *)0;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
s = (char*)string;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( *s )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( *s == cc ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
sp = s;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
s++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( cc == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
sp = s;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Q_strncpyz
|
|
|
|
|
|
|
|
Safe strncpy that ensures a trailing zero
|
|
|
|
=============
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
void Q_strncpyz( char *dest, const char *src, int destsize ) {
|
|
|
|
if ( !src ) {
|
|
|
|
Com_Error( ERR_FATAL, "Q_strncpyz: NULL src" );
|
|
|
|
}
|
|
|
|
if ( destsize < 1 ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
Com_Error( ERR_FATAL,"Q_strncpyz: destsize < 1" );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strncpy( dest, src, destsize - 1 );
|
|
|
|
dest[destsize - 1] = 0;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
int Q_stricmpn( const char *s1, const char *s2, int n ) {
|
|
|
|
int c1, c2;
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
do {
|
|
|
|
c1 = *s1++;
|
|
|
|
c2 = *s2++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !n-- ) {
|
|
|
|
return 0; // strings are equal until end point
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( c1 != c2 ) {
|
|
|
|
if ( c1 >= 'a' && c1 <= 'z' ) {
|
|
|
|
c1 -= ( 'a' - 'A' );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( c2 >= 'a' && c2 <= 'z' ) {
|
|
|
|
c2 -= ( 'a' - 'A' );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( c1 != c2 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return c1 < c2 ? -1 : 1;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( c1 );
|
|
|
|
|
|
|
|
return 0; // strings are equal
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int Q_strncmp( const char *s1, const char *s2, int n ) {
|
|
|
|
int c1, c2;
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
do {
|
|
|
|
c1 = *s1++;
|
|
|
|
c2 = *s2++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !n-- ) {
|
|
|
|
return 0; // strings are equal until end point
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( c1 != c2 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return c1 < c2 ? -1 : 1;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( c1 );
|
|
|
|
|
|
|
|
return 0; // strings are equal
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int Q_stricmp( const char *s1, const char *s2 ) {
|
|
|
|
return Q_stricmpn( s1, s2, 99999 );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *Q_strlwr( char *s1 ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
char *s;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
s = s1;
|
2007-11-04 03:51:54 +00:00
|
|
|
while ( *s ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
*s = tolower( *s );
|
2007-11-04 03:51:54 +00:00
|
|
|
s++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
return s1;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *Q_strupr( char *s1 ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
char *s;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
s = s1;
|
2007-11-04 03:51:54 +00:00
|
|
|
while ( *s ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
*s = toupper( *s );
|
2007-11-04 03:51:54 +00:00
|
|
|
s++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
return s1;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// never goes past bounds or leaves without a terminating 0
|
|
|
|
void Q_strcat( char *dest, int size, const char *src ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
int l1;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
l1 = strlen( dest );
|
|
|
|
if ( l1 >= size ) {
|
|
|
|
Com_Error( ERR_FATAL, "Q_strcat: already overflowed" );
|
|
|
|
}
|
|
|
|
Q_strncpyz( dest + l1, src, size - l1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Q_PrintStrlen( const char *string ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
int len;
|
|
|
|
const char *p;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !string ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
p = string;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( *p ) {
|
|
|
|
if ( Q_IsColorString( p ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
p += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *Q_CleanStr( char *string ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
char* d;
|
|
|
|
char* s;
|
|
|
|
int c;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
s = string;
|
|
|
|
d = string;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( ( c = *s ) != 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( Q_IsColorString( s ) ) {
|
|
|
|
s++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
else if ( c >= 0x20 && c <= 0x7E ) {
|
|
|
|
*d++ = c;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
*d = '\0';
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void QDECL Com_sprintf( char *dest, int size, const char *fmt, ... ) {
|
|
|
|
int len;
|
|
|
|
va_list argptr;
|
|
|
|
char bigbuffer[32000]; // big, but small enough to fit in PPC stack
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
va_start( argptr,fmt );
|
|
|
|
len = vsprintf( bigbuffer,fmt,argptr );
|
|
|
|
va_end( argptr );
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( len >= sizeof( bigbuffer ) ) {
|
|
|
|
Com_Error( ERR_FATAL, "Com_sprintf: overflowed bigbuffer" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( len >= size ) {
|
|
|
|
Com_Printf( "Com_sprintf: overflow of %i in %i\n", len, size );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
Q_strncpyz( dest, bigbuffer, size );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
va
|
|
|
|
|
|
|
|
does a varargs printf into a temp buffer, so I don't need to have
|
|
|
|
varargs versions of all text functions.
|
|
|
|
FIXME: make this buffer size safe someday
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
char * QDECL va( char *format, ... ) {
|
|
|
|
va_list argptr;
|
|
|
|
static char string[2][32000]; // in case va is called by nested functions
|
|
|
|
static int index = 0;
|
|
|
|
char *buf;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
buf = string[index & 1];
|
|
|
|
index++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
va_start( argptr, format );
|
|
|
|
vsprintf( buf, format,argptr );
|
|
|
|
va_end( argptr );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=====================================================================
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
INFO STRINGS
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
=====================================================================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Info_ValueForKey
|
|
|
|
|
|
|
|
Searches the string for the given
|
|
|
|
key and returns the associated value, or an empty string.
|
|
|
|
FIXME: overflow check?
|
|
|
|
===============
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
char *Info_ValueForKey( const char *s, const char *key ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
char pkey[MAX_INFO_KEY];
|
|
|
|
static char value[2][MAX_INFO_VALUE]; // use two buffers so compares
|
|
|
|
// work without stomping on each other
|
|
|
|
static int valueindex = 0;
|
|
|
|
char *o;
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( !s || !key ) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strlen( s ) >= MAX_INFO_STRING ) {
|
|
|
|
Com_Error( ERR_DROP, "Info_ValueForKey: oversize infostring" );
|
|
|
|
}
|
|
|
|
|
|
|
|
valueindex ^= 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( *s == '\\' ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
s++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
while ( 1 )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
o = pkey;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( *s != '\\' )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !*s ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return "";
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
s++;
|
|
|
|
|
|
|
|
o = value[valueindex];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( *s != '\\' && *s )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !Q_stricmp( key, pkey ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return value[valueindex];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !*s ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===================
|
|
|
|
Info_NextPair
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Used to itterate through all the key/value pairs in an info string
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
void Info_NextPair( const char *( *head ), char key[MAX_INFO_KEY], char value[MAX_INFO_VALUE] ) {
|
|
|
|
char *o;
|
|
|
|
const char *s;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
s = *head;
|
|
|
|
|
|
|
|
if ( *s == '\\' ) {
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
key[0] = 0;
|
|
|
|
value[0] = 0;
|
|
|
|
|
|
|
|
o = key;
|
|
|
|
while ( *s != '\\' ) {
|
|
|
|
if ( !*s ) {
|
|
|
|
*o = 0;
|
|
|
|
*head = s;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
s++;
|
|
|
|
|
|
|
|
o = value;
|
|
|
|
while ( *s != '\\' && *s ) {
|
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
|
|
|
|
*head = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===================
|
|
|
|
Info_RemoveKey
|
|
|
|
===================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
void Info_RemoveKey( char *s, const char *key ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
char *start;
|
|
|
|
char pkey[MAX_INFO_KEY];
|
|
|
|
char value[MAX_INFO_VALUE];
|
|
|
|
char *o;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
if ( strlen( s ) >= MAX_INFO_STRING ) {
|
|
|
|
Com_Error( ERR_DROP, "Info_RemoveKey: oversize infostring" );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strchr( key, '\\' ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( 1 )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
start = s;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( *s == '\\' ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
s++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
o = pkey;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( *s != '\\' )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !*s ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
s++;
|
|
|
|
|
|
|
|
o = value;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( *s != '\\' && *s )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !*s ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( key, pkey ) ) {
|
|
|
|
strcpy( start, s ); // remove this part
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !*s ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
Info_Validate
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Some characters are illegal in info strings because they
|
|
|
|
can mess up the server's parsing
|
|
|
|
==================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
qboolean Info_Validate( const char *s ) {
|
|
|
|
if ( strchr( s, '\"' ) ) {
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
if ( strchr( s, ';' ) ) {
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
Info_SetValueForKey
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Changes or adds a key/value pair
|
|
|
|
==================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
void Info_SetValueForKey( char *s, const char *key, const char *value ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
char newi[MAX_INFO_STRING];
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
if ( strlen( s ) >= MAX_INFO_STRING ) {
|
|
|
|
Com_Error( ERR_DROP, "Info_SetValueForKey: oversize infostring" );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strchr( key, '\\' ) || strchr( value, '\\' ) ) {
|
|
|
|
Com_Printf( "Can't use keys or values with a \\\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strchr( key, ';' ) || strchr( value, ';' ) ) {
|
|
|
|
Com_Printf( "Can't use keys or values with a semicolon\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strchr( key, '\"' ) || strchr( value, '\"' ) ) {
|
|
|
|
Com_Printf( "Can't use keys or values with a \"\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Info_RemoveKey( s, key );
|
|
|
|
if ( !value || !strlen( value ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Com_sprintf( newi, sizeof( newi ), "\\%s\\%s", key, value );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strlen( newi ) + strlen( s ) > MAX_INFO_STRING ) {
|
|
|
|
Com_Printf( "Info string length exceeded\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strcat( s, newi );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
ParseHex
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
int ParseHex( const char *text ) {
|
|
|
|
int value;
|
|
|
|
int c;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
value = 0;
|
|
|
|
while ( ( c = *text++ ) != 0 ) {
|
|
|
|
if ( c >= '0' && c <= '9' ) {
|
|
|
|
value = value * 16 + c - '0';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( c >= 'a' && c <= 'f' ) {
|
|
|
|
value = value * 16 + 10 + c - 'a';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( c >= 'A' && c <= 'F' ) {
|
|
|
|
value = value * 16 + 10 + c - 'A';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|