comparison src/protocols/irc/parse.c @ 9130:933a19e3a6b3

[gaim-migrate @ 9908] This puts the core in charge of irc-style /commands, which is way cool. Tim did most of the work, I've just been keeping it in sync with CVS, and slowly adding more commands to jabber. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 30 May 2004 19:34:21 +0000
parents c60f82d78dea
children 6430b09ccc71
comparison
equal deleted inserted replaced
9129:3e94a77ee0c7 9130:933a19e3a6b3
24 24
25 #include "accountopt.h" 25 #include "accountopt.h"
26 #include "conversation.h" 26 #include "conversation.h"
27 #include "notify.h" 27 #include "notify.h"
28 #include "debug.h" 28 #include "debug.h"
29 #include "cmds.h"
29 #include "irc.h" 30 #include "irc.h"
30 31
31 #include <stdio.h> 32 #include <stdio.h>
32 #include <stdlib.h> 33 #include <stdlib.h>
33 #include <ctype.h> 34 #include <ctype.h>
133 { "wallops", ":", irc_cmd_wallops }, 134 { "wallops", ":", irc_cmd_wallops },
134 { "whois", "n", irc_cmd_whois }, 135 { "whois", "n", irc_cmd_whois },
135 { NULL, NULL, NULL } 136 { NULL, NULL, NULL }
136 }; 137 };
137 138
139 static GaimCmdRet irc_parse_gaim_cmd(GaimConversation *conv, const gchar *cmd,
140 gchar **args, gchar **error)
141 {
142 GaimConnection *gc;
143 struct irc_conn *irc;
144 struct _irc_user_cmd *cmdent;
145
146 gc = gaim_conversation_get_gc(conv);
147 if (!gc)
148 return GAIM_CMD_RET_FAILED;
149
150 irc = gc->proto_data;
151
152 if ((cmdent = g_hash_table_lookup(irc->cmds, cmd)) == NULL)
153 return GAIM_CMD_RET_FAILED;
154
155 (cmdent->cb)(irc, cmd, gaim_conversation_get_name(conv), (const char **)args);
156
157 return GAIM_CMD_RET_OK;
158 }
159
160 static void irc_register_command(struct _irc_user_cmd *c)
161 {
162 GaimCmdFlag f;
163 char args[10];
164 char *format;
165 int i;
166
167 f = GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_PRPL_ONLY
168 | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS;
169
170 format = c->format;
171
172 for (i = 0; (i < (sizeof(args) - 1)) && *format; i++, format++)
173 switch (*format) {
174 case 'v':
175 case 'n':
176 case 'c':
177 case 't':
178 args[i] = 'w';
179 break;
180 case ':':
181 case '*':
182 args[i] = 's';
183 break;
184 }
185
186 args[i] = '\0';
187
188 gaim_cmd_register(c->name, args, GAIM_CMD_P_PRPL, f, "prpl-irc", irc_parse_gaim_cmd,
189 _("No help is available at this time for this command."));
190 }
191
192 void irc_register_commands(void)
193 {
194 struct _irc_user_cmd *c;
195
196 for (c = _irc_cmds; c && c->name; c++)
197 irc_register_command(c);
198 }
199
138 static char *irc_send_convert(struct irc_conn *irc, const char *string) 200 static char *irc_send_convert(struct irc_conn *irc, const char *string)
139 { 201 {
140 char *utf8; 202 char *utf8;
141 GError *err = NULL; 203 GError *err = NULL;
142 204