summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-16 15:18:21 +0000
committerrubidium <rubidium@openttd.org>2010-08-16 15:18:21 +0000
commitd98ff7c4c4c49aa1748ef94fe17eed171c51780d (patch)
tree5f514b6fb9a9b4fb58a063b1c34d655f4e5fec04 /src
parentca6aac6a5a125881ef1d65c3083344314ce81f61 (diff)
downloadopenttd-d98ff7c4c4c49aa1748ef94fe17eed171c51780d.tar.xz
(svn r20515) -Feature: ignore _ in console command names so there is no "inconsistent" behaviour w.r.t. underscores anymore without breaking backwards compatability greatly
Diffstat (limited to 'src')
-rw-r--r--src/console.cpp20
-rw-r--r--src/console_cmds.cpp2
2 files changed, 18 insertions, 4 deletions
diff --git a/src/console.cpp b/src/console.cpp
index 59c6c1a48..ab131b135 100644
--- a/src/console.cpp
+++ b/src/console.cpp
@@ -224,6 +224,21 @@ void IConsoleAddSorted(T **base, T *item_new)
}
/**
+ * Remove underscores from a string; the string will be modified!
+ * @param name The string to remove the underscores from.
+ * @return #name.
+ */
+char *RemoveUnderscores(char *name)
+{
+ char *q = name;
+ for (const char *p = name; *p != '\0'; p++) {
+ if (*p != '_') *q++ = *p;
+ }
+ *q = '\0';
+ return name;
+}
+
+/**
* Register a new command to be used in the console
* @param name name of the command that will be used
* @param proc function that will be called upon execution of command
@@ -231,7 +246,7 @@ void IConsoleAddSorted(T **base, T *item_new)
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc, IConsoleHook *hook)
{
IConsoleCmd *item_new = MallocT<IConsoleCmd>(1);
- item_new->name = strdup(name);
+ item_new->name = RemoveUnderscores(strdup(name));
item_new->next = NULL;
item_new->proc = proc;
item_new->hook = hook;
@@ -266,7 +281,7 @@ void IConsoleAliasRegister(const char *name, const char *cmd)
return;
}
- char *new_alias = strdup(name);
+ char *new_alias = RemoveUnderscores(strdup(name));
char *cmd_aliased = strdup(cmd);
IConsoleAlias *item_new = MallocT<IConsoleAlias>(1);
@@ -467,6 +482,7 @@ void IConsoleCmdExec(const char *cmdstr)
* First try commands, then aliases. Execute
* the found action taking into account its hooking code
*/
+ RemoveUnderscores(tokens[0]);
IConsoleCmd *cmd = IConsoleCmdGet(tokens[0]);
if (cmd != NULL) {
ConsoleHookResult chr = (cmd->hook == NULL ? CHR_ALLOW : cmd->hook(true));
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 49155919d..cd6546150 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -1767,8 +1767,6 @@ void IConsoleStdLibRegister()
IConsoleAliasRegister("dir", "ls");
IConsoleAliasRegister("del", "rm %+");
IConsoleAliasRegister("newmap", "newgame");
- IConsoleAliasRegister("new_map", "newgame");
- IConsoleAliasRegister("new_game", "newgame");
IConsoleAliasRegister("patch", "setting %+");
IConsoleAliasRegister("set", "setting %+");
IConsoleAliasRegister("set_newgame", "setting_newgame %+");