if (!strcmp (var_name, hash->cvar->name) && (hash->cvar->flags & neededflags))
return hash->cvar;
else
- for (int i = 0; i < hash->cvar->aliasindex; i++)
- if (!strcmp (var_name, hash->cvar->aliases[i]) && (hash->cvar->flags & neededflags))
+ for (char **alias = hash->cvar->aliases; alias && *alias; alias++)
+ if (!strcmp (var_name, *alias) && (hash->cvar->flags & neededflags))
return hash->cvar;
return NULL;
}
if (!strcmp (var_name, hash->cvar->name) && (hash->cvar->flags & neededflags))
goto match;
else
- for (int i = 0; i < hash->cvar->aliasindex; i++)
- if (!strcmp (var_name, hash->cvar->aliases[i]) && (hash->cvar->flags & neededflags))
+ for (char **alias = hash->cvar->aliases; alias && *alias; alias++)
+ if (!strcmp (var_name, *alias) && (hash->cvar->flags & neededflags))
goto match;
if(parent) *parent = hash->cvar;
}
if (!strncasecmp(partial, cvar->name, len) && (cvar->flags & neededflags))
h++;
else
- for(int i = 0; i < cvar->aliasindex; i++)
- if (!strncasecmp(partial, cvar->aliases[i], len) && (cvar->flags & neededflags))
+ for (char **alias = cvar->aliases; alias && *alias; alias++)
+ if (!strncasecmp(partial, *alias, len) && (cvar->flags & neededflags))
h++;
return h;
if (!strncasecmp(partial, cvar->name, len) && (cvar->flags & neededflags))
buf[bpos++] = cvar->name;
else
- for(int i = 0; i < cvar->aliasindex; i++)
- if (!strncasecmp(partial, cvar->aliases[i], len) && (cvar->flags & neededflags))
- buf[bpos++] = cvar->aliases[i];
+ for (char **alias = cvar->aliases; alias && *alias; alias++)
+ if (!strncasecmp(partial, *alias, len) && (cvar->flags & neededflags))
+ buf[bpos++] = *alias;
buf[bpos] = NULL;
if (!strncasecmp(partial, cvar->name, len) && (cvar->flags & neededflags))
Cvar_PrintHelp(cvar, cvar->name, true);
else
- for (int i = 0; i < cvar->aliasindex; i++)
- if (!strncasecmp (partial, cvar->aliases[i], len) && (cvar->flags & neededflags))
- Cvar_PrintHelp(cvar, cvar->aliases[i], true);
+ for (char **alias = cvar->aliases; alias && *alias; alias++)
+ if (!strncasecmp (partial, *alias, len) && (cvar->flags & neededflags))
+ Cvar_PrintHelp(cvar, *alias, true);
}
cvar_hash_t *hash;
int hashindex;
- variable->aliases = (char **)Mem_Realloc(zonemempool, variable->aliases, sizeof(char *) * (variable->aliasindex + 1));
+ if(!*alias)
+ {
+ Con_Printf("Cvar_RegisterAlias: invalid alias name\n");
+ return;
+ }
+
+ // check for overlap with a command
+ if (Cmd_Exists(cmd_local, alias))
+ {
+ Con_Printf("Cvar_RegisterAlias: %s is a command\n", alias);
+ return;
+ }
+
+ if(Cvar_FindVar(&cvars_all, alias, 0))
+ {
+ Con_Printf("Cvar_RegisterAlias: %s is a cvar\n", alias);
+ return;
+ }
+
+ if(!variable->aliases)
+ variable->aliases = (char **)Z_Malloc(sizeof(char *) * 2); // For NULL terminator
+ else
+ variable->aliases = (char **)Mem_Realloc(zonemempool, variable->aliases, sizeof(char *) * (variable->aliases_size + 1));
+
+ variable->aliases[variable->aliases_size + 1] = NULL;
+
// Add to it
- variable->aliases[variable->aliasindex] = (char *)Z_Malloc(strlen(alias) + 1);
- memcpy(variable->aliases[variable->aliasindex], alias, strlen(alias) + 1);
- variable->aliasindex++;
+ variable->aliases[variable->aliases_size] = (char *)Z_Malloc(strlen(alias) + 1);
+ memcpy(variable->aliases[variable->aliases_size], alias, strlen(alias) + 1);
+ variable->aliases_size++;
// link to head of list in this hash table index
hash = (cvar_hash_t *)Z_Malloc(sizeof(cvar_hash_t));
variable->defstring = (char *)Mem_strdup(zonemempool, variable->string);
variable->value = atof (variable->string);
variable->integer = (int) variable->value;
- variable->aliasindex = 0;
+ variable->aliases = NULL;
+ variable->aliases_size = 0;
variable->initstate = NULL;
// Mark it as not an autocvar.
cvar->defstring = (char *)Mem_strdup(zonemempool, value);
cvar->value = atof (cvar->string);
cvar->integer = (int) cvar->value;
- cvar->aliases = (char **)Z_Malloc(sizeof(char **));
+ cvar->aliases = NULL;
+ cvar->aliases_size = 0;
cvar->initstate = NULL;
memset(cvar->aliases, 0, sizeof(char *));
Cvar_PrintHelp(cvar, cvar->name, true);
count++;
}
- for (int i = 0; i < cvar->aliasindex; i++)
+ for (char **alias = cvar->aliases; alias && *alias; alias++)
{
- if (matchpattern_with_separator(cvar->aliases[i], partial, false, "", false))
+ if (matchpattern_with_separator(*alias, partial, false, "", false))
{
- Cvar_PrintHelp(cvar, cvar->aliases[i], true);
+ Cvar_PrintHelp(cvar, *alias, true);
count++;
}
}