use a table to hook commands in
authorChristian Thaeter <ct@pipapo.org>
Sun, 4 Nov 2007 02:14:01 +0000 (03:14 +0100)
committerChristian Thaeter <ct@pipapo.org>
Sun, 4 Nov 2007 02:14:01 +0000 (03:14 +0100)
contrib/irc/xchat/rx.c

index fe46207..7c0ebab 100644 (file)
@@ -268,7 +268,6 @@ rxhook_cb (char *word[], char *word_eol[], void *userdata)
 
       if (PREFIXCMP(line, "ignore:"))
         return XCHAT_EAT_XCHAT;
-
       //else if (PREFIXCMP(line, "kick:"))
       //else if (PREFIXCMP(line, "kickban:"))
       //else if (PREFIXCMP(line, "ban:"))
@@ -279,12 +278,31 @@ rxhook_cb (char *word[], char *word_eol[], void *userdata)
   return XCHAT_EAT_NONE;
 }
 
+static struct commands
+{
+  const char* command;
+  const char* help;
+  int (*callback) (char *[], char *[], void *);
+} command_table[] =
+  {
+    {"RXSTART", "Usage: RXSTART server port list; enables and connects to rxpd", rxstart_cb},
+    {"RXSTOP", "Usage: RXSTOP; disconnects and stops rxpd plugin", rxstop_cb},
+    {"RXADD", "Usage: RXADD listname rule; adds rule to list", rxadd_cb},
+    {"RXDEL", "Usage: RXDEL list rule; removes rule from list", rxdel_cb},
+    {"RXLIST", "Usage: RXLIST [list]; shows list", rxlist_cb},
+    //{"RXRAW", "Usage: RXRAW ...; sends a raw command to the rxpd", rxraw_cb},
+    {"RXDEBUG", "Usage: RXDEBUG; toggle rxpd plugin debugging", rxdebug_cb},
+    {"RXINFO", "Usage: RXINFO; show some information about the rxpd plugin", rxinfo_cb},
+    {NULL, NULL}
+  };
+
+
 int
-xchat_plugin_init(xchat_plugin *plugin_handle,
-                  char **plugin_name,
-                  char **plugin_desc,
-                  char **plugin_version,
-                  char *arg)
+xchat_plugin_init (xchat_plugin *plugin_handle,
+                   char **plugin_name,
+                   char **plugin_desc,
+                   char **plugin_version,
+                   char *arg)
 {
   /* we need to save this for use with any xchat_* functions */
   ph = plugin_handle;
@@ -302,29 +320,10 @@ xchat_plugin_init(xchat_plugin *plugin_handle,
   rx_private.eol = rx_private.eob = rx_private.buffer;
   rx_private.buffer [4095] = '\0';
 
-  xchat_hook_command (ph, "RXSTART", XCHAT_PRI_NORM, rxstart_cb,
-                      "Usage: RXSTART server port list; enables and connects to rxpd", &rx_private);
-
-  xchat_hook_command (ph, "RXSTOP", XCHAT_PRI_NORM, rxstop_cb,
-                      "Usage: RXSTOP; disconnects and stops rxpd plugin", &rx_private);
-
-  xchat_hook_command (ph, "RXADD", XCHAT_PRI_NORM, rxadd_cb,
-                      "Usage: RXADD listname rule; adds rule to list", &rx_private);
-
-  xchat_hook_command (ph, "RXDEL", XCHAT_PRI_NORM, rxdel_cb,
-                      "Usage: RXDEL list rule; removes rule from list", &rx_private);
-
-  xchat_hook_command (ph, "RXLIST", XCHAT_PRI_NORM, rxlist_cb,
-                      "Usage: RXLIST [list]; shows list", &rx_private);
-
-  xchat_hook_command (ph, "RXRAW", XCHAT_PRI_NORM, rxraw_cb,
-                      "Usage: RXRAW ...; sends a raw command to the rxpd", &rx_private);
-
-  xchat_hook_command (ph, "RXDEBUG", XCHAT_PRI_NORM, rxdebug_cb,
-                      "Usage: RXDEBUG; toggle rxpd plugin debugging", &rx_private);
-
-  xchat_hook_command (ph, "RXINFO", XCHAT_PRI_NORM, rxinfo_cb,
-                      "Usage: RXINFO; show some information about the rxpd plugin", &rx_private);
+  struct commands* itr;
+  for (itr = command_table; itr->command; ++itr)
+    xchat_hook_command (ph, itr->command, XCHAT_PRI_NORM, itr->callback,
+                        itr->help, &rx_private);
 
   xchat_hook_server (ph, "RAW LINE", XCHAT_PRI_NORM, rxhook_cb, &rx_private);