diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common.c | 3 | ||||
-rw-r--r-- | src/common.h | 1 | ||||
-rw-r--r-- | src/prompt.c | 36 |
3 files changed, 32 insertions, 8 deletions
diff --git a/src/common.c b/src/common.c index ae91863..71a5abd 100644 --- a/src/common.c +++ b/src/common.c @@ -1788,6 +1788,9 @@ void Com_Generic_c( genctx_t *ctx, int argnum ) { return; } + // protect against possible duplicates + ctx->ignoredups = qtrue; + s = Cmd_Argv( ctx->argnum - argnum ); // complete command argument or cvar value diff --git a/src/common.h b/src/common.h index 28c8354..d894075 100644 --- a/src/common.h +++ b/src/common.h @@ -122,6 +122,7 @@ typedef struct genctx_s { int count, size; void *data; qboolean ignorecase; + qboolean ignoredups; } genctx_t; typedef void ( *xcommand_t )( void ); diff --git a/src/prompt.c b/src/prompt.c index 1e928b8..2bb7a7e 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -129,20 +129,40 @@ static void Prompt_ShowIndividualMatches( } } +static qboolean find_dup( genctx_t *ctx, const char *s ) { + int i, r; + + for( i = 0; i < ctx->count; i++ ) { + if( ctx->ignorecase ) + r = Q_strcasecmp( ctx->matches[i], s ); + else + r = strcmp( ctx->matches[i], s ); + + if( !r ) + return qtrue; + } + + return qfalse; +} + qboolean Prompt_AddMatch( genctx_t *ctx, const char *s ) { int r; - if( ctx->count >= ctx->size ) { + if( ctx->count >= ctx->size ) return qfalse; - } - if( ctx->ignorecase ) { + + if( ctx->ignorecase ) r = Q_strncasecmp( ctx->partial, s, ctx->length ); - } else { + else r = strncmp( ctx->partial, s, ctx->length ); - } - if( !r ) { - ctx->matches[ctx->count++] = Z_CopyString( s ); - } + + if( r ) + return qtrue; + + if( ctx->ignoredups && find_dup( ctx, s ) ) + return qtrue; + + ctx->matches[ctx->count++] = Z_CopyString( s ); return qtrue; } |