changeset 1986:ad77110343d6

Use a command ID with cmd_add/cmd_del (Myhailo Danylenko) Patch merged from isbear's mcabber-experimental repository.
author Mikael Berthe <mikael@lilotux.net>
date Sun, 27 Mar 2011 18:28:45 +0200
parents 0870005f7efc
children 212c9589b25c
files mcabber/mcabber/api.h mcabber/mcabber/commands.c mcabber/mcabber/commands.h mcabber/modules/beep/beep.c
diffstat 4 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/api.h	Sun Mar 27 13:35:08 2011 +0200
+++ b/mcabber/mcabber/api.h	Sun Mar 27 18:28:45 2011 +0200
@@ -3,8 +3,8 @@
 
 #include <mcabber/config.h> // For MCABBER_BRANCH
 
-#define MCABBER_API_VERSION 18
-#define MCABBER_API_MIN     18
+#define MCABBER_API_VERSION 19
+#define MCABBER_API_MIN     19
 
 extern const gchar *mcabber_branch;
 extern const guint mcabber_api_version;
--- a/mcabber/mcabber/commands.c	Sun Mar 27 13:35:08 2011 +0200
+++ b/mcabber/mcabber/commands.c	Sun Mar 27 18:28:45 2011 +0200
@@ -103,27 +103,26 @@
 #ifdef MODULES_ENABLE
 #include "modules.h"
 
-gpointer cmd_del(const char *name)
+gpointer cmd_del(gpointer id)
 {
   GSList *sl_cmd;
-  for (sl_cmd = Commands; sl_cmd; sl_cmd = sl_cmd->next) {
-    cmd *command = (cmd *) sl_cmd->data;
-    if (!strcmp (command->name, name)) {
+  for (sl_cmd = Commands; sl_cmd; sl_cmd = sl_cmd->next)
+    if (sl_cmd -> data == id) {
+      cmd *command = (cmd *) sl_cmd->data;
       gpointer userdata = command->userdata;
       Commands = g_slist_delete_link(Commands, sl_cmd);
       compl_del_category_word(COMPL_CMD, command->name);
       g_free(command);
       return userdata;
     }
-  }
   return NULL;
 }
 #endif
 
 //  cmd_add()
 // Adds a command to the commands list and to the CMD completion list
-void cmd_add(const char *name, const char *help, guint flags_row1,
-             guint flags_row2, void (*f)(char*), gpointer userdata)
+gpointer cmd_add(const char *name, const char *help, guint flags_row1,
+                 guint flags_row2, void (*f)(char*), gpointer userdata)
 {
   cmd *n_cmd = g_new0(cmd, 1);
   strncpy(n_cmd->name, name, 32-1);
@@ -135,6 +134,7 @@
   Commands = g_slist_prepend(Commands, n_cmd);
   // Add to completion CMD category
   compl_add_category_word(COMPL_CMD, name);
+  return n_cmd;
 }
 
 //  cmd_init()
--- a/mcabber/mcabber/commands.h	Sun Mar 27 13:35:08 2011 +0200
+++ b/mcabber/mcabber/commands.h	Sun Mar 27 18:28:45 2011 +0200
@@ -20,8 +20,9 @@
 int  process_command(const char *line, guint iscmd);
 char *expandalias(const char *line);
 #ifdef MODULES_ENABLE
-gpointer cmd_del(const char *name);
-void cmd_add(const char *name, const char *help, guint flags1, guint flags2, void (*f)(char*), gpointer userdata);
+gpointer cmd_del(gpointer id);
+gpointer cmd_add(const char *name, const char *help, guint flags1, guint flags2,
+                 void (*f)(char*), gpointer userdata);
 #endif
 
 void cmd_room_whois(gpointer bud, const char *nick, guint interactive);
--- a/mcabber/modules/beep/beep.c	Sun Mar 27 13:35:08 2011 +0200
+++ b/mcabber/modules/beep/beep.c	Sun Mar 27 18:28:45 2011 +0200
@@ -46,8 +46,9 @@
         .next            = NULL,
 };
 
-static guint beep_cid = 0;  /* Command completion category id */
-static guint beep_hid = 0;  /* Hook handler id */
+static guint    beep_cid  = 0;  /* Command completion category id */
+static gpointer beep_cmid = 0;  /* Command id */
+static guint    beep_hid  = 0;  /* Hook handler id */
 
 /* Event handler */
 static guint beep_hh(const gchar *hookname, hk_arg_t *args, gpointer userdata)
@@ -94,7 +95,7 @@
     compl_add_category_word(beep_cid, "disable");
   }
   /* Add command */
-  cmd_add("beep", "", beep_cid, 0, do_beep, NULL);
+  beep_cmid = cmd_add("beep", "", beep_cid, 0, do_beep, NULL);
   /* Add handler
    * We are only interested in incoming message events
    */
@@ -108,7 +109,7 @@
   /* Unregister event handler */
   hk_del_handler(HOOK_POST_MESSAGE_IN, beep_hid);
   /* Unregister command */
-  cmd_del("beep");
+  cmd_del(beep_cmid);
   /* Give back completion handle */
   if (beep_cid)
     compl_del_category(beep_cid);