cvarlist, buf_cvarlist: support wildcards if present (if not present, it's treated...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 23 Jan 2009 19:29:16 +0000 (19:29 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 23 Jan 2009 19:29:16 +0000 (19:29 +0000)
fix two places where cvar names were treated case insensitively, while they usually are case sensitive (e.g. when hashed with crc32)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8667 d7cf8633-e32d-0410-b094-e92efae38249

cvar.c
prvm_cmds.c

diff --git a/cvar.c b/cvar.c
index 3de5a88..47a5735 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -40,7 +40,7 @@ cvar_t *Cvar_FindVar (const char *var_name)
        // use hash lookup to minimize search time
        hashindex = CRC_Block((const unsigned char *)var_name, strlen(var_name));
        for (var = cvar_hashtable[hashindex];var;var = var->nextonhashchain)
-               if (!strcasecmp (var_name, var->name))
+               if (!strcmp (var_name, var->name))
                        return var;
 
        return NULL;
@@ -663,6 +663,7 @@ void Cvar_List_f (void)
        const char *partial;
        size_t len;
        int count;
+       qboolean ispattern;
 
        if (Cmd_Argc() > 1)
        {
@@ -675,18 +676,25 @@ void Cvar_List_f (void)
                len = 0;
        }
 
+       ispattern = partial && (strchr(partial, '*') || strchr(partial, '?'));
+
        count = 0;
        for (cvar = cvar_vars; cvar; cvar = cvar->next)
        {
-               if (partial && strncasecmp (partial,cvar->name,len))
+               if (len && (ispattern ? !matchpattern_with_separator(cvar->name, partial, false, "", false) : strncmp (partial,cvar->name,len)))
                        continue;
 
                Con_Printf("%s is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description);
                count++;
        }
 
-       if (partial)
-               Con_Printf("%i cvar(s) beginning with \"%s\"\n", count, partial);
+       if (len)
+       {
+               if(ispattern)
+                       Con_Printf("%i cvar(s) matching \"%s\"\n", count, partial);
+               else
+                       Con_Printf("%i cvar(s) beginning with \"%s\"\n", count, partial);
+       }
        else
                Con_Printf("%i cvar(s)\n", count);
 }
index 2887b0f..cb3107c 100644 (file)
@@ -4397,6 +4397,7 @@ void VM_buf_cvarlist(void)
        const char *partial, *antipartial;
        size_t len, antilen;
        size_t alloclen;
+       qboolean ispattern, antiispattern;
        int n;
        prvm_stringbuffer_t     *stringbuffer;
        VM_SAFEPARMCOUNTRANGE(2, 3, VM_buf_cvarlist);
@@ -4430,13 +4431,16 @@ void VM_buf_cvarlist(void)
                Mem_Free(stringbuffer->strings);
        stringbuffer->strings = NULL;
 
+       ispattern = partial && (strchr(partial, '*') || strchr(partial, '?'));
+       antiispattern = antipartial && (strchr(antipartial, '*') || strchr(antipartial, '?'));
+
        n = 0;
        for(cvar = cvar_vars; cvar; cvar = cvar->next)
        {
-               if(partial && strncasecmp(partial, cvar->name, len))
+               if(len && (ispattern ? !matchpattern_with_separator(cvar->name, partial, false, "", false) : strncmp(partial, cvar->name, len)))
                        continue;
 
-               if(antilen && !strncasecmp(antipartial, cvar->name, antilen))
+               if(antilen && (antiispattern ? matchpattern_with_separator(cvar->name, antipartial, false, "", false) : !strncmp(antipartial, cvar->name, antilen)))
                        continue;
 
                ++n;
@@ -4449,10 +4453,10 @@ void VM_buf_cvarlist(void)
        n = 0;
        for(cvar = cvar_vars; cvar; cvar = cvar->next)
        {
-               if(len && strncasecmp(partial, cvar->name, len))
+               if(len && (ispattern ? !matchpattern_with_separator(cvar->name, partial, false, "", false) : strncmp(partial, cvar->name, len)))
                        continue;
 
-               if(antilen && !strncasecmp(antipartial, cvar->name, antilen))
+               if(antilen && (antiispattern ? matchpattern_with_separator(cvar->name, antipartial, false, "", false) : !strncmp(antipartial, cvar->name, antilen)))
                        continue;
 
                alloclen = strlen(cvar->name) + 1;