comparison src/cmds.c @ 9597:d6f398e80b32

[gaim-migrate @ 10440] denyri added a void *data argument to most of the command related functions. This makes it easier for language binding and such. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Mon, 26 Jul 2004 03:27:03 +0000
parents 796f510a6e19
children 1a97d5e88d12
comparison
equal deleted inserted replaced
9596:7b3212aa698c 9597:d6f398e80b32
36 GaimCmdPriority priority; 36 GaimCmdPriority priority;
37 GaimCmdFlag flags; 37 GaimCmdFlag flags;
38 gchar *prpl_id; 38 gchar *prpl_id;
39 GaimCmdFunc func; 39 GaimCmdFunc func;
40 gchar *help; 40 gchar *help;
41 void *data;
41 } GaimCmd; 42 } GaimCmd;
42 43
43 44
44 static gint cmds_compare_func(const GaimCmd *a, const GaimCmd *b) 45 static gint cmds_compare_func(const GaimCmd *a, const GaimCmd *b)
45 { 46 {
48 else if (a->id < b->id) 49 else if (a->id < b->id)
49 return 1; 50 return 1;
50 else return 0; 51 else return 0;
51 } 52 }
52 53
53 GaimCmdId gaim_cmd_register(const gchar *cmd, const gchar *args, GaimCmdPriority p, GaimCmdFlag f, 54 GaimCmdId gaim_cmd_register(const gchar *cmd, const gchar *args,
54 const gchar *prpl_id, GaimCmdFunc func, const gchar *helpstr) 55 GaimCmdPriority p, GaimCmdFlag f,
56 const gchar *prpl_id, GaimCmdFunc func,
57 const gchar *helpstr, void *data)
55 { 58 {
56 GaimCmdId id; 59 GaimCmdId id;
57 GaimCmd *c; 60 GaimCmd *c;
58 61
59 g_return_val_if_fail(cmd != NULL && *cmd != '\0', 0); 62 g_return_val_if_fail(cmd != NULL && *cmd != '\0', 0);
69 c->priority = p; 72 c->priority = p;
70 c->flags = f; 73 c->flags = f;
71 c->prpl_id = prpl_id ? g_strdup(prpl_id) : NULL; 74 c->prpl_id = prpl_id ? g_strdup(prpl_id) : NULL;
72 c->func = func; 75 c->func = func;
73 c->help = helpstr ? g_strdup(helpstr) : NULL; 76 c->help = helpstr ? g_strdup(helpstr) : NULL;
77 c->data = data;
74 78
75 cmds = g_list_insert_sorted(cmds, c, (GCompareFunc)cmds_compare_func); 79 cmds = g_list_insert_sorted(cmds, c, (GCompareFunc)cmds_compare_func);
76 80
77 return id; 81 return id;
78 } 82 }
193 continue; 197 continue;
194 } 198 }
195 s = g_utf8_next_char(s); 199 s = g_utf8_next_char(s);
196 } 200 }
197 } 201 }
202
198 GaimCmdStatus gaim_cmd_do_command(GaimConversation *conv, const gchar *cmdline, 203 GaimCmdStatus gaim_cmd_do_command(GaimConversation *conv, const gchar *cmdline,
199 const gchar *markup, gchar **error) 204 const gchar *markup, gchar **error)
200 { 205 {
201 GaimCmd *c; 206 GaimCmd *c;
202 GList *l; 207 GList *l;
259 args = NULL; 264 args = NULL;
260 continue; 265 continue;
261 } 266 }
262 267
263 tried_cmd = TRUE; 268 tried_cmd = TRUE;
264 ret = c->func(conv, cmd, args, &err); 269 ret = c->func(conv, cmd, args, &err, c->data);
265 if (ret == GAIM_CMD_RET_CONTINUE) { 270 if (ret == GAIM_CMD_RET_CONTINUE) {
266 if (err) 271 if (err)
267 g_free(err); 272 g_free(err);
268 err = NULL; 273 err = NULL;
269 gaim_cmd_free_args(args); 274 gaim_cmd_free_args(args);