summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-03-19 19:25:59 +0100
committerSebastien Helleu <flashcode@flashtux.org>2010-03-19 19:25:59 +0100
commit568d913c5895e356672320a4a6694570ed0b87c2 (patch)
tree30a30a47dfffa02bc4ed5aabc63f5fb23c6ce553 /src/core
parent645d38d4032f6ba7222ca841769004e175b3335f (diff)
downloadweechat-568d913c5895e356672320a4a6694570ed0b87c2.zip
Fix bugs with function hook_command_run
A '/' is always sent at beginning of command to callback, even if user used another command char. Now it is possible to catch a command, with or without arguments, with hook_command_run("/command").
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-hook.c57
1 files changed, 47 insertions, 10 deletions
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c
index 8286e72b1..275213a0b 100644
--- a/src/core/wee-hook.c
+++ b/src/core/wee-hook.c
@@ -714,7 +714,23 @@ int
hook_command_run_exec (struct t_gui_buffer *buffer, const char *command)
{
struct t_hook *ptr_hook, *next_hook;
- int rc;
+ int rc, hook_matching, length;
+ char *command2;
+ const char *ptr_command;
+
+ ptr_command = command;
+ command2 = NULL;
+
+ if (command[0] != '/')
+ {
+ length = strlen (command) + 1;
+ command2 = malloc (length);
+ if (command2)
+ {
+ snprintf (command2, length, "/%s", command + 1);
+ ptr_command = command2;
+ }
+ }
ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND_RUN];
while (ptr_hook)
@@ -723,21 +739,42 @@ hook_command_run_exec (struct t_gui_buffer *buffer, const char *command)
if (!ptr_hook->deleted
&& !ptr_hook->running
- && HOOK_COMMAND_RUN(ptr_hook, command)
- && (string_match (command, HOOK_COMMAND_RUN(ptr_hook, command), 0)))
+ && HOOK_COMMAND_RUN(ptr_hook, command))
{
- ptr_hook->running = 1;
- rc = (HOOK_COMMAND_RUN(ptr_hook, callback)) (ptr_hook->callback_data,
- buffer,
- command);
- ptr_hook->running = 0;
- if (rc == WEECHAT_RC_OK_EAT)
- return rc;
+ hook_matching = string_match (ptr_command,
+ HOOK_COMMAND_RUN(ptr_hook, command),
+ 0);
+
+ if (!hook_matching
+ && !strchr (HOOK_COMMAND_RUN(ptr_hook, command), ' '))
+ {
+ hook_matching = (string_strncasecmp (ptr_command,
+ HOOK_COMMAND_RUN(ptr_hook, command),
+ utf8_strlen (HOOK_COMMAND_RUN(ptr_hook, command))) == 0);
+ }
+
+ if (hook_matching)
+ {
+ ptr_hook->running = 1;
+ rc = (HOOK_COMMAND_RUN(ptr_hook, callback)) (ptr_hook->callback_data,
+ buffer,
+ ptr_command);
+ ptr_hook->running = 0;
+ if (rc == WEECHAT_RC_OK_EAT)
+ {
+ if (command2)
+ free (command2);
+ return rc;
+ }
+ }
}
ptr_hook = next_hook;
}
+ if (command2)
+ free (command2);
+
return WEECHAT_RC_OK;
}