summaryrefslogtreecommitdiff
path: root/source/q_shared.c
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2008-04-23 15:02:41 +0000
committerAndrey Nazarov <skuller@skuller.net>2008-04-23 15:02:41 +0000
commit49e6170b49fbb933eddec6d0e3f946320c68832f (patch)
tree88d228d6f89103710074fdba041ce80584d5caa6 /source/q_shared.c
parent8c795585fb0c6c9178d9981f6943da04b7279205 (diff)
Added `dumpents' server command.
Added support for `cl_noskins' value of 2 (default all female skins to `female/athena', all male skins to `male/grunt'). Renamed `scoreshot' command to `aashot', added `aadump' command. Fixed several alignment issues on ARM architecture. Server browser menu now indicates full and password protected servers with color codes. Implemented history search in console with Ctrl+R, Ctrl+S. Removed `cl_railtrail_alpha' variable, all `cl_rail*_color' variables now accept colors in #RRGGBBAA format. Added `map_override' cvar (enables loading map entity lump from external maps/*.ent file). Made `quit' command accept extra arguments. Made `draw' command accept arbitrary colors in #RRGGBBAA format. Fixed debian packages.
Diffstat (limited to 'source/q_shared.c')
-rw-r--r--source/q_shared.c198
1 files changed, 139 insertions, 59 deletions
diff --git a/source/q_shared.c b/source/q_shared.c
index 4d830f7..2e6b523 100644
--- a/source/q_shared.c
+++ b/source/q_shared.c
@@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include "config.h"
+#include <config.h>
#include "q_shared.h"
static const char hexchars[] = "0123456789ABCDEF";
@@ -846,51 +846,61 @@ void COM_AppendExtension( char *path, const char *extension, int pathSize ) {
/*
==================
-COM_IsNumeric
+COM_IsFloat
Returns true if the given string is valid representation
-of floating point or integer number.
+of floating point number.
==================
*/
-qboolean COM_IsNumeric( const char *string ) {
- int c;
+qboolean COM_IsFloat( const char *s ) {
+ int c, dot = '.';
- if( !string ) {
+ if( *s == '-' ) {
+ s++;
+ }
+ if( !*s ) {
return qfalse;
}
- if( !*string ) {
+ do {
+ c = *s++;
+ if( c == dot ) {
+ dot = 0;
+ } else if( !Q_isdigit( c ) ) {
+ return qfalse;
+ }
+ } while( *s );
+
+ return qtrue;
+}
+
+qboolean COM_IsUint( const char *s ) {
+ int c;
+
+ if( !*s ) {
return qfalse;
}
do {
- c = *string++;
- if( Q_isdigit( c ) ) {
- continue;
- }
- if( c != '-' && c != '.' && c != ' ' ) {
+ c = *s++;
+ if( !Q_isdigit( c ) ) {
return qfalse;
}
- } while( *string );
+ } while( *s );
return qtrue;
-
}
-qboolean COM_HasSpaces( const char *string ) {
- while( *string ) {
- if( *string <= 32 ) {
+qboolean COM_HasSpaces( const char *s ) {
+ while( *s ) {
+ if( *s <= 32 ) {
return qtrue;
}
- string++;
+ s++;
}
return qfalse;
}
-/* Parses hexadecimal number until it encounters
- * illegible symbol or end of string.
- * Does not check for overflow.
- */
unsigned COM_ParseHex( const char *s ) {
int c;
unsigned result;
@@ -899,24 +909,80 @@ unsigned COM_ParseHex( const char *s ) {
if( ( c = Q_charhex( *s ) ) == -1 ) {
break;
}
+ if( result & ~( UINT_MAX >> 4 ) ) {
+ return UINT_MAX;
+ }
result = c | ( result << 4 );
}
return result;
}
+qboolean COM_ParseColor( const char *s, color_t color ) {
+ int i;
+ int c[8];
+
+ if( *s == '#' ) {
+ s++;
+ for( i = 0; s[i]; i++ ) {
+ c[i] = Q_charhex( s[i] );
+ if( c[i] == -1 ) {
+ return qfalse;
+ }
+ }
+ switch( i ) {
+ case 3:
+ color[0] = c[0] | ( c[0] << 4 );
+ color[1] = c[1] | ( c[1] << 4 );
+ color[2] = c[2] | ( c[2] << 4 );
+ color[3] = 255;
+ break;
+ case 6:
+ color[0] = c[1] | ( c[0] << 4 );
+ color[1] = c[3] | ( c[2] << 4 );
+ color[2] = c[5] | ( c[4] << 4 );
+ color[3] = 255;
+ break;
+ case 8:
+ color[0] = c[1] | ( c[0] << 4 );
+ color[1] = c[3] | ( c[2] << 4 );
+ color[2] = c[5] | ( c[4] << 4 );
+ color[3] = c[7] | ( c[6] << 4 );
+ break;
+ default:
+ return qfalse;
+ }
+ return qtrue;
+ } else {
+ for( i = 0; i < 8; i++ ) {
+ if( !strcmp( colorNames[i], s ) ) {
+ *( uint32_t * )color = *( uint32_t * )colorTable[i];
+ return qtrue;
+ }
+ }
+ return qfalse;
+ }
+}
+
/*
=================
SortStrcmp
=================
*/
int QDECL SortStrcmp( const void *p1, const void *p2 ) {
- const char *s1 = *(const char **)p1;
- const char *s2 = *(const char **)p2;
+ const char *s1 = *( const char ** )p1;
+ const char *s2 = *( const char ** )p2;
return strcmp( s1, s2 );
}
+int QDECL SortStricmp( const void *p1, const void *p2 ) {
+ const char *s1 = *( const char ** )p1;
+ const char *s2 = *( const char ** )p2;
+
+ return Q_stricmp( s1, s2 );
+}
+
/*
=================
Com_WildCmp
@@ -1194,51 +1260,64 @@ char *Q_FormatString( const char *string ) {
return buffer;
}
+#if 0
+
+typedef enum {
+ ESC_CHR = ( 1 << 0 ),
+ ESC_CLR = ( 1 << 1 )
+} escape_t;
+
/*
================
Q_UnescapeString
================
*/
-char *Q_UnescapeString( const char *string ) {
- static char buffer[MAX_STRING_CHARS];
+size_t Q_UnescapeString( char *out, const char *in, size_t bufsize, escape_t flags ) {
char *dst, *last;
int c;
- dst = buffer;
- last = buffer + MAX_STRING_CHARS - 1;
- while( *string && dst != last ) {
- c = *string++;
-
- if( c != '\\' ) {
- *dst++ = c;
- continue;
- }
+ if( bufsize < 1 ) {
+ Com_Error( ERR_FATAL, "%s: bad bufsize: %d", __func__, bufsize );
+ }
- c = *string++;
- if( c == 0 ) {
- break;
- }
- switch( c ) {
- case 't':
- c = '\t';
- break;
- case 'b':
- c = '\b';
- break;
- case 'r':
- c = '\r';
- break;
- case 'n':
- c = '\n';
- break;
- case '\\':
- c = '\\';
- break;
- default:
- break;
- }
+ p = out;
+ m = out + bufsize - 1;
+ while( *in && p < m ) {
+ c = *in++;
+
+ if( ( flags & ESC_CHR ) && c == '\\' ) {
+ c = *in++;
+ switch( c ) {
+ case 0:
+ goto breakOut;
+ case 't':
+ c = '\t';
+ break;
+ case 'b':
+ c = '\b';
+ break;
+ case 'r':
+ c = '\r';
+ break;
+ case 'n':
+ c = '\n';
+ break;
+ case '\\':
+ c = '\\';
+ break;
+ case 'x':
+ if( ( c = Q_charhex( in[0] ) ) == -1 ) {
+ goto breakOut;
+ }
+ result = c | ( r << 4 );
+ }
+ break;
+ default:
+ break;
+ }
- *dst++ = c;
+ *p++ = c;
+ }
}
*dst = 0;
@@ -1246,6 +1325,7 @@ char *Q_UnescapeString( const char *string ) {
return buffer;
}
+#endif
int Q_EscapeMarkup( char *out, const char *in, int bufsize ) {
char *p, *m, *s;