annotate src/cmds.c @ 9444:a88c8ca91518

[gaim-migrate @ 10265] More stock button changes. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 02 Jul 2004 19:16:33 +0000
parents 796f510a6e19
children d6f398e80b32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /**
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * @file cmds.c Commands API
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 * @ingroup core
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 *
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 * Copyright (C) 2003-2004 Timothy Ringenbach <omarvo@hotmail.com
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 *
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 * (at your option) any later version.
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 *
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 * GNU General Public License for more details.
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 *
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 *
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 */
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #include <string.h>
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 #include "account.h"
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
26 #include "util.h"
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 #include "cmds.h"
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 static GList *cmds = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 static guint next_id = 1;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 typedef struct _GaimCmd {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 GaimCmdId id;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34 gchar *cmd;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 gchar *args;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 GaimCmdPriority priority;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 GaimCmdFlag flags;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 gchar *prpl_id;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 GaimCmdFunc func;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 gchar *help;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 } GaimCmd;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44 static gint cmds_compare_func(const GaimCmd *a, const GaimCmd *b)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46 if (a->id > b->id)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
47 return -1;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48 else if (a->id < b->id)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
49 return 1;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 else return 0;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
53 GaimCmdId gaim_cmd_register(const gchar *cmd, const gchar *args, GaimCmdPriority p, GaimCmdFlag f,
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54 const gchar *prpl_id, GaimCmdFunc func, const gchar *helpstr)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 {
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
56 GaimCmdId id;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
59 g_return_val_if_fail(cmd != NULL && *cmd != '\0', 0);
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
60 g_return_val_if_fail(args != NULL, 0);
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
61 g_return_val_if_fail(func != NULL, 0);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
63 id = next_id++;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65 c = g_new0(GaimCmd, 1);
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
66 c->id = id;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67 c->cmd = g_strdup(cmd);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68 c->args = g_strdup(args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69 c->priority = p;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 c->flags = f;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 c->prpl_id = prpl_id ? g_strdup(prpl_id) : NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72 c->func = func;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73 c->help = helpstr ? g_strdup(helpstr) : NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75 cmds = g_list_insert_sorted(cmds, c, (GCompareFunc)cmds_compare_func);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77 return id;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
79
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80 static void gaim_cmd_free(GaimCmd *c)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
82 g_free(c->cmd);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83 g_free(c->args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84 if (c->prpl_id)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85 g_free(c->prpl_id);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 if (c->help)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 g_free(c->help);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 g_free(c);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
92 void gaim_cmd_unregister(GaimCmdId id)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
94 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95 GList *l;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98 c = l->data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99
9343
5f6ba17ef9f5 [gaim-migrate @ 10151]
Tim Ringenbach <marv@pidgin.im>
parents: 9175
diff changeset
100 if (c->id == id) {
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 cmds = g_list_remove(cmds, c);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102 gaim_cmd_free(c);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103 return;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
108 static gboolean gaim_cmd_parse_args(GaimCmd *cmd, const gchar *s, const gchar *m, gchar ***args)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
109 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
110 int i;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
111 const char *end, *cur;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
112
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
113 *args = g_new0(char *, strlen(cmd->args) + 1);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
114
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
115 cur = s;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
117 for (i = 0; cmd->args[i]; i++) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
118 if (!*cur)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
119 return (cmd->flags & GAIM_CMD_FLAG_ALLOW_WRONG_ARGS);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121 switch (cmd->args[i]) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 case 'w':
9428
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
123 if (!(end = strchr(cur, ' '))) {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
124 end = cur + strlen(cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
125 (*args)[i] = g_strndup(cur, end - cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
126 cur = end;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
127 } else {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
128 (*args)[i] = g_strndup(cur, end - cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
129 cur = end + 1;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
130 }
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
132 case 'W':
9428
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
133 if (!(end = strchr(cur, ' '))) {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
134 end = cur + strlen(cur);
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
135 (*args)[i] = gaim_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_pointer_to_offset(s, end));
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
136 cur = end;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
137 } else {
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
138 (*args)[i] = gaim_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_pointer_to_offset(s, end));
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
139 cur = end +1;
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
140 }
796f510a6e19 [gaim-migrate @ 10247]
Tim Ringenbach <marv@pidgin.im>
parents: 9343
diff changeset
141 break;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
142 case 's':
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
143 (*args)[i] = g_strdup(cur);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144 cur = cur + strlen(cur);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
145 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
146 case 'S':
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
147 (*args)[i] = gaim_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_strlen(cur, -1) + 1);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148 cur = cur + strlen(cur);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
152
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 if (*cur)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154 return (cmd->flags & GAIM_CMD_FLAG_ALLOW_WRONG_ARGS);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156 return TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159 static void gaim_cmd_free_args(gchar **args)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161 int i;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163 for (i = 0; args[i]; i++)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 g_free(args[i]);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165 g_free(args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
168 static void gaim_cmd_strip_current_char(gunichar c, char *s, guint len)
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
169 {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
170 int bytes;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
171
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
172 bytes = g_unichar_to_utf8(c, NULL);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
173 memmove(s, s + bytes, len + 1 - bytes);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
174 }
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
176 static void gaim_cmd_strip_cmd_from_markup(char *markup)
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
177 {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
178 guint len = strlen(markup);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
179 char *s = markup;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
180
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
181 while (*s) {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
182 gunichar c = g_utf8_get_char(s);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
183
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
184 if (c == '<') {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
185 s = strchr(s, '>');
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
186 if (!s)
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
187 return;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
188 } else if (g_unichar_isspace(c)) {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
189 gaim_cmd_strip_current_char(c, s, len - (s - markup));
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
190 return;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
191 } else {
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
192 gaim_cmd_strip_current_char(c, s, len - (s - markup));
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
193 continue;
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
194 }
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
195 s = g_utf8_next_char(s);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
196 }
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
197 }
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
198 GaimCmdStatus gaim_cmd_do_command(GaimConversation *conv, const gchar *cmdline,
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
199 const gchar *markup, gchar **error)
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
200 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
201 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
202 GList *l;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
203 gchar *err = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
204 gboolean is_im;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
205 gboolean found = FALSE, tried_cmd = FALSE, right_type = FALSE, right_prpl = FALSE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
206 const gchar *prpl_id;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207 gchar **args = NULL;
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
208 gchar *cmd, *rest, *mrest;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209 GaimCmdRet ret = GAIM_CMD_RET_CONTINUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210
9149
108a0300135d [gaim-migrate @ 9933]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
211 *error = NULL;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 prpl_id = gaim_account_get_protocol_id(gaim_conversation_get_account(conv));
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215 is_im = TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217 is_im = FALSE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218 else
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219 return GAIM_CMD_STATUS_FAILED;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221 rest = strchr(cmdline, ' ');
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222 if (rest) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223 cmd = g_strndup(cmdline, rest - cmdline);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
224 rest++;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
225 } else {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
226 cmd = g_strdup(cmdline);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
227 rest = "";
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
228 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
229
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
230 mrest = g_strdup(markup);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
231 gaim_cmd_strip_cmd_from_markup(mrest);
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
232
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234 c = l->data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
235
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
236 if (strcmp(c->cmd, cmd) != 0)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
237 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 found = TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241 if (is_im)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242 if (!(c->flags & GAIM_CMD_FLAG_IM))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244 if (!is_im)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245 if (!(c->flags & GAIM_CMD_FLAG_CHAT))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248 right_type = TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250 if ((c->flags & GAIM_CMD_FLAG_PRPL_ONLY) && c->prpl_id &&
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 (strcmp(c->prpl_id, prpl_id) != 0))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
252 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254 right_prpl = TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 /* this checks the allow bad args flag for us */
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
257 if (!gaim_cmd_parse_args(c, rest, mrest, &args)) {
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258 gaim_cmd_free_args(args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259 args = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
261 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263 tried_cmd = TRUE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264 ret = c->func(conv, cmd, args, &err);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
265 if (ret == GAIM_CMD_RET_CONTINUE) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266 if (err)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267 g_free(err);
9149
108a0300135d [gaim-migrate @ 9933]
Nathan Walp <nwalp@pidgin.im>
parents: 9130
diff changeset
268 err = NULL;
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269 gaim_cmd_free_args(args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270 args = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
271 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272 } else {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273 break;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
274 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278 if (args)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279 gaim_cmd_free_args(args);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280 g_free(cmd);
9175
3e2ea5b69605 [gaim-migrate @ 9970]
Tim Ringenbach <marv@pidgin.im>
parents: 9149
diff changeset
281 g_free(mrest);
9130
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
282
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
283 if (!found)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
284 return GAIM_CMD_STATUS_NOT_FOUND;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
285
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286 if (!right_type)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
287 return GAIM_CMD_STATUS_WRONG_TYPE;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288 if (!right_prpl)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
289 return GAIM_CMD_STATUS_WRONG_PRPL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
290 if (!tried_cmd)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
291 return GAIM_CMD_STATUS_WRONG_ARGS;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
292
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
293 if (ret == GAIM_CMD_RET_OK) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294 return GAIM_CMD_STATUS_OK;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
295 } else {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
296 *error = err;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
297 if (ret == GAIM_CMD_RET_CONTINUE)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
298 return GAIM_CMD_STATUS_NOT_FOUND;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
299 else
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300 return GAIM_CMD_STATUS_FAILED;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
301 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
302
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
303 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
304
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
306 GList *gaim_cmd_list(GaimConversation *conv)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
307 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
308 GList *ret = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
309 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
310 GList *l;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
311
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
312 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
313 c = l->data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
314
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
315 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_IM))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
316 if (!(c->flags & GAIM_CMD_FLAG_IM))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
317 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
318 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
319 if (!(c->flags & GAIM_CMD_FLAG_CHAT))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
320 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
321
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
322 if (conv && (c->flags & GAIM_CMD_FLAG_PRPL_ONLY) && c->prpl_id &&
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
323 (strcmp(c->prpl_id, gaim_account_get_protocol_id(gaim_conversation_get_account(conv))) != 0))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
324 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
325
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
326 ret = g_list_append(ret, c->cmd);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
328
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
329 return ret;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
330 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
331
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
332
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
333 GList *gaim_cmd_help(GaimConversation *conv, const gchar *cmd)
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
334 {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
335 GList *ret = NULL;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
336 GaimCmd *c;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
337 GList *l;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
338
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
339 for (l = cmds; l; l = l->next) {
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
340 c = l->data;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
341
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
342 if (cmd && (strcmp(cmd, c->cmd) != 0))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
343 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
344
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
345 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_IM))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
346 if (!(c->flags & GAIM_CMD_FLAG_IM))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
347 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
348 if (conv && (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
349 if (!(c->flags & GAIM_CMD_FLAG_CHAT))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
350 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
351
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
352 if (conv && (c->flags & GAIM_CMD_FLAG_PRPL_ONLY) && c->prpl_id &&
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
353 (strcmp(c->prpl_id, gaim_account_get_protocol_id(gaim_conversation_get_account(conv))) != 0))
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
354 continue;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
355
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
356 ret = g_list_append(ret, c->help);
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
357 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
358
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
359 return ret;
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
360 }
933a19e3a6b3 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
361