summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2011-12-13 20:59:40 +0400
committerAndrey Nazarov <skuller@skuller.net>2011-12-13 20:59:40 +0400
commitf075099b69eca47036f42c09ac7a0773a8848f7f (patch)
tree8b7769f6a68847c29db0fb328f115f09f083700b
parent9743ac9f799b6f7eaf9370ae65978999a08c0f75 (diff)
Filter duplicates when completing command args.
-rw-r--r--src/common.c3
-rw-r--r--src/common.h1
-rw-r--r--src/prompt.c36
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;
}