Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/commands.c @ 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 | dd65a18dc480 |
comparison
equal
deleted
inserted
replaced
1985:0870005f7efc | 1986:ad77110343d6 |
---|---|
101 static GSList *Commands; | 101 static GSList *Commands; |
102 | 102 |
103 #ifdef MODULES_ENABLE | 103 #ifdef MODULES_ENABLE |
104 #include "modules.h" | 104 #include "modules.h" |
105 | 105 |
106 gpointer cmd_del(const char *name) | 106 gpointer cmd_del(gpointer id) |
107 { | 107 { |
108 GSList *sl_cmd; | 108 GSList *sl_cmd; |
109 for (sl_cmd = Commands; sl_cmd; sl_cmd = sl_cmd->next) { | 109 for (sl_cmd = Commands; sl_cmd; sl_cmd = sl_cmd->next) |
110 cmd *command = (cmd *) sl_cmd->data; | 110 if (sl_cmd -> data == id) { |
111 if (!strcmp (command->name, name)) { | 111 cmd *command = (cmd *) sl_cmd->data; |
112 gpointer userdata = command->userdata; | 112 gpointer userdata = command->userdata; |
113 Commands = g_slist_delete_link(Commands, sl_cmd); | 113 Commands = g_slist_delete_link(Commands, sl_cmd); |
114 compl_del_category_word(COMPL_CMD, command->name); | 114 compl_del_category_word(COMPL_CMD, command->name); |
115 g_free(command); | 115 g_free(command); |
116 return userdata; | 116 return userdata; |
117 } | 117 } |
118 } | |
119 return NULL; | 118 return NULL; |
120 } | 119 } |
121 #endif | 120 #endif |
122 | 121 |
123 // cmd_add() | 122 // cmd_add() |
124 // Adds a command to the commands list and to the CMD completion list | 123 // Adds a command to the commands list and to the CMD completion list |
125 void cmd_add(const char *name, const char *help, guint flags_row1, | 124 gpointer cmd_add(const char *name, const char *help, guint flags_row1, |
126 guint flags_row2, void (*f)(char*), gpointer userdata) | 125 guint flags_row2, void (*f)(char*), gpointer userdata) |
127 { | 126 { |
128 cmd *n_cmd = g_new0(cmd, 1); | 127 cmd *n_cmd = g_new0(cmd, 1); |
129 strncpy(n_cmd->name, name, 32-1); | 128 strncpy(n_cmd->name, name, 32-1); |
130 n_cmd->help = help; | 129 n_cmd->help = help; |
131 n_cmd->completion_flags[0] = flags_row1; | 130 n_cmd->completion_flags[0] = flags_row1; |
133 n_cmd->func = f; | 132 n_cmd->func = f; |
134 n_cmd->userdata = userdata; | 133 n_cmd->userdata = userdata; |
135 Commands = g_slist_prepend(Commands, n_cmd); | 134 Commands = g_slist_prepend(Commands, n_cmd); |
136 // Add to completion CMD category | 135 // Add to completion CMD category |
137 compl_add_category_word(COMPL_CMD, name); | 136 compl_add_category_word(COMPL_CMD, name); |
137 return n_cmd; | |
138 } | 138 } |
139 | 139 |
140 // cmd_init() | 140 // cmd_init() |
141 // Commands table initialization | 141 // Commands table initialization |
142 // !!! | 142 // !!! |