Mercurial > hg
changeset 1352:61a54e172010
Add internal hooks support
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 10 Nov 2007 22:29:31 +0100 |
parents | 43e777a5ff06 |
children | 7caedca15e50 |
files | mcabber/src/commands.c mcabber/src/commands.h mcabber/src/hooks.c mcabber/src/hooks.h |
diffstat | 4 files changed, 37 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mcabber/src/commands.c Sat Nov 10 22:28:16 2007 +0100 +++ b/mcabber/src/commands.c Sat Nov 10 22:29:31 2007 +0100 @@ -292,12 +292,12 @@ // If no alias is found, returns line // Note : if the returned pointer is different from line, the caller should // g_free() the pointer after use -char *expandalias(char *line) +char *expandalias(const char *line) { const char *p1, *p2; char *word; const gchar *value; - char *newline = line; + char *newline = (char*)line; // Ignore leading COMMAND_CHAR for (p1 = line ; *p1 == COMMAND_CHAR ; p1++) @@ -357,7 +357,7 @@ // If iscmd is TRUE, process the command even if verbatim mmode is set; // it is intended to be used for key bindings. // Return 255 if this is the /quit command, and 0 for the other commands. -int process_command(char *line, guint iscmd) +int process_command(const char *line, guint iscmd) { char *p; char *xpline; @@ -367,9 +367,9 @@ if (iscmd || scr_get_multimode() != 2) xpline = expandalias(line); else - xpline = line; // No expansion in verbatim multi-line mode - - // We want to have a copy + xpline = (char*)line; // No expansion in verbatim multi-line mode + + // We want to use a copy if (xpline == line) xpline = g_strdup(line); @@ -430,7 +430,7 @@ // If this isn't a command, this is a message and it is sent to the // currently selected buddy. // Return 255 if the line is the /quit command, or 0. -int process_line(char *line) +int process_line(const char *line) { if (!*line) { // User only pressed enter if (scr_get_multimode()) { @@ -450,7 +450,7 @@ if (scr_get_multimode()) scr_append_multiline(line); else - do_say_internal(line, 0); + do_say_internal((char*)line, 0); return 0; }
--- a/mcabber/src/commands.h Sat Nov 10 22:28:16 2007 +0100 +++ b/mcabber/src/commands.h Sat Nov 10 22:29:31 2007 +0100 @@ -13,9 +13,9 @@ void cmd_init(void); cmd *cmd_get(const char *command); -int process_line(char *line); -int process_command(char *line, guint iscmd); -char *expandalias(char *line); +int process_line(const char *line); +int process_command(const char *line, guint iscmd); +char *expandalias(const char *line); extern char *mcabber_version(void); extern void mcabber_connect(void);
--- a/mcabber/src/hooks.c Sat Nov 10 22:28:16 2007 +0100 +++ b/mcabber/src/hooks.c Sat Nov 10 22:29:31 2007 +0100 @@ -31,6 +31,7 @@ #include "settings.h" #include "utils.h" #include "utf8.h" +#include "commands.h" static char *extcmd; @@ -332,6 +333,29 @@ } +/* Internal commands */ + +void hook_execute_internal(const char *hookname) +{ + const char *hook_command; + char *buf; + char *cmdline; + + hook_command = settings_opt_get(hookname); + if (!hook_command) + return; + + buf = g_strdup_printf("Running %s...", hookname); + scr_LogPrint(LPRINT_LOGNORM, "%s", buf); + + cmdline = g_strdup_printf(mkcmdstr("%s"), hook_command); + process_command(hook_command, TRUE); // XXX Note: /quit won't work. + + g_free(cmdline); + g_free(buf); +} + + /* External commands */ // hk_ext_cmd_init()
--- a/mcabber/src/hooks.h Sat Nov 10 22:28:16 2007 +0100 +++ b/mcabber/src/hooks.h Sat Nov 10 22:29:31 2007 +0100 @@ -17,6 +17,8 @@ enum imstatus old_status, enum imstatus new_status, const char *msg); +void hook_execute_internal(const char *hookname); + void hk_ext_cmd_init(const char *command); void hk_ext_cmd(const char *bjid, guchar type, guchar info, const char *data);