diff options
author | M. Kristall <mkpdev@gmail.com> | 2009-10-03 12:41:40 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:16:09 +0000 |
commit | 19433e1c2790ebab99bdff1f18f16e8ab86d249f (patch) | |
tree | 804fbd10d47ce2622119ed5089463a4ca0b01a52 /src/game/bg_lib.c | |
parent | 47fd44d7bb4acd32854e4f6fdbdef04692ff728f (diff) |
* (bug 4037) cgame forgets to close buildstat.cfg
* Admin searches now list all matches
* !listadmins now properly handles negative numbers
* "!ban: too many bans" errors were sometimes wrong
* A bit of refactoring
* Add %s support to sscanf
Diffstat (limited to 'src/game/bg_lib.c')
-rw-r--r-- | src/game/bg_lib.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/game/bg_lib.c b/src/game/bg_lib.c index fa184228..1ed9c6b3 100644 --- a/src/game/bg_lib.c +++ b/src/game/bg_lib.c @@ -2391,10 +2391,11 @@ int Q_snprintf(char *str, size_t length, const char *fmt, ...) int sscanf( const char *buffer, const char *fmt, ... ) { int cmd; - int **arg; + va_list ap; int count; + size_t len; - arg = (int **)&fmt + 1; + va_start( ap, fmt ); count = 0; while( *fmt ) @@ -2405,27 +2406,47 @@ int sscanf( const char *buffer, const char *fmt, ... ) continue; } - cmd = fmt[ 1 ]; - fmt += 2; + fmt++; + cmd = *fmt; + + if( isdigit( cmd ) ) + { + len = (size_t)_atoi( &fmt ); + cmd = *( fmt - 1 ); + } + else + { + len = MAX_STRING_CHARS - 1; + fmt++; + } switch( cmd ) { case 'i': case 'd': case 'u': - **arg = _atoi( &buffer ); + *( va_arg( ap, int * ) ) = _atoi( &buffer ); break; case 'f': - *(float *)*arg = _atof( &buffer ); + *( va_arg( ap, float * ) ) = _atof( &buffer ); break; case 'x': - **arg = _hextoi( &buffer ); + *( va_arg( ap, unsigned int * ) ) = _hextoi( &buffer ); + break; + case 's': + { + char *s = va_arg( ap, char * ); + while( isspace( *buffer ) ) + buffer++; + while( *buffer && !isspace( *buffer) && len-- > 0 ) + *s++ = *buffer++; + *s++ = '\0'; break; + } } - - arg++; } + va_end( ap ); return count; } |