summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2010-02-10 13:52:10 +0000
committersmatz <smatz@openttd.org>2010-02-10 13:52:10 +0000
commitb91b3ac836604ad364e5d8027a30e0c9bc7b4fcc (patch)
tree190ceb4d42e95ee8a107864c164dec2229ef91e8
parent4cd2ad0a5f17d3d2e8b8d0aec968a1969f481652 (diff)
downloadopenttd-b91b3ac836604ad364e5d8027a30e0c9bc7b4fcc.tar.xz
(svn r19074) -Change: when filtering list of settings and console commands, use strstr() instead of strncmp()
-rw-r--r--src/console_cmds.cpp23
-rw-r--r--src/settings.cpp4
2 files changed, 8 insertions, 19 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index c0a37d6dc..2237c956d 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -1394,17 +1394,14 @@ DEF_CONSOLE_CMD(ConHelp)
DEF_CONSOLE_CMD(ConListCommands)
{
const IConsoleCmd *cmd;
- size_t l = 0;
if (argc == 0) {
IConsoleHelp("List all registered commands. Usage: 'list_cmds [<pre-filter>]'");
return true;
}
- if (argv[1] != NULL) l = strlen(argv[1]);
-
for (cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) {
- if (argv[1] == NULL || strncmp(cmd->name, argv[1], l) == 0) {
+ if (argv[1] == NULL || strstr(cmd->name, argv[1]) != NULL) {
IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
}
}
@@ -1415,18 +1412,16 @@ DEF_CONSOLE_CMD(ConListCommands)
DEF_CONSOLE_CMD(ConListVariables)
{
const IConsoleVar *var;
- size_t l = 0;
if (argc == 0) {
IConsoleHelp("List all registered variables. Usage: 'list_vars [<pre-filter>]'");
return true;
}
- if (argv[1] != NULL) l = strlen(argv[1]);
-
for (var = _iconsole_vars; var != NULL; var = var->next) {
- if (argv[1] == NULL || strncmp(var->name, argv[1], l) == 0)
+ if (argv[1] == NULL || strstr(var->name, argv[1]) != NULL) {
IConsolePrintF(CC_DEFAULT, "%s", var->name);
+ }
}
return true;
@@ -1435,18 +1430,16 @@ DEF_CONSOLE_CMD(ConListVariables)
DEF_CONSOLE_CMD(ConListAliases)
{
const IConsoleAlias *alias;
- size_t l = 0;
if (argc == 0) {
IConsoleHelp("List all registered aliases. Usage: 'list_aliases [<pre-filter>]'");
return true;
}
- if (argv[1] != NULL) l = strlen(argv[1]);
-
for (alias = _iconsole_aliases; alias != NULL; alias = alias->next) {
- if (argv[1] == NULL || strncmp(alias->name, argv[1], l) == 0)
+ if (argv[1] == NULL || strstr(alias->name, argv[1]) != NULL) {
IConsolePrintF(CC_DEFAULT, "%s => %s", alias->name, alias->cmdline);
+ }
}
return true;
@@ -1748,18 +1741,16 @@ DEF_CONSOLE_CMD(ConListSettings)
DEF_CONSOLE_CMD(ConListDumpVariables)
{
const IConsoleVar *var;
- size_t l = 0;
if (argc == 0) {
IConsoleHelp("List all variables with their value. Usage: 'dump_vars [<pre-filter>]'");
return true;
}
- if (argv[1] != NULL) l = strlen(argv[1]);
-
for (var = _iconsole_vars; var != NULL; var = var->next) {
- if (argv[1] == NULL || strncmp(var->name, argv[1], l) == 0)
+ if (argv[1] == NULL || strstr(var->name, argv[1]) != NULL) {
IConsoleVarPrintGetValue(var);
+ }
}
return true;
diff --git a/src/settings.cpp b/src/settings.cpp
index 767bfbb1a..63d13470d 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1767,9 +1767,7 @@ void IConsoleListSettings(const char *prefilter)
for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
- if (prefilter != NULL) {
- if (strncmp(sd->desc.name, prefilter, min(strlen(sd->desc.name), strlen(prefilter))) != 0) continue;
- }
+ if (prefilter != NULL && strstr(sd->desc.name, prefilter) == NULL) continue;
char value[80];
const void *ptr = GetVariableAddress((_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game, &sd->save);