47
|
1 /*
|
|
2 * commands.c -- user commands handling
|
|
3 *
|
|
4 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net>
|
|
5 *
|
|
6 * This program is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or (at
|
|
9 * your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful, but
|
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 * General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
19 * USA
|
|
20 */
|
|
21
|
|
22 #include "commands.h"
|
|
23 #include "jabglue.h"
|
81
|
24 #include "roster.h"
|
47
|
25 #include "screen.h"
|
81
|
26 #include "utf8.h"
|
47
|
27 #include "utils.h"
|
|
28
|
|
29
|
94
|
30 // Command structure
|
|
31 typedef struct {
|
|
32 char name[32];
|
|
33 char *help; // ?
|
|
34 guint completion_flags;
|
|
35 void *(*func)();
|
|
36 } cmd;
|
|
37
|
|
38
|
47
|
39 // send_message(msg)
|
|
40 // Write the message in the buddy's window and send the message on
|
|
41 // the network.
|
|
42 void send_message(char *msg)
|
|
43 {
|
|
44 char *buffer;
|
81
|
45 const char *jid;
|
|
46
|
|
47 if (!current_buddy) {
|
|
48 scr_LogPrint("No buddy currently selected.");
|
|
49 return;
|
|
50 }
|
|
51
|
|
52 jid = CURRENT_JID;
|
|
53 if (!jid) {
|
|
54 scr_LogPrint("No buddy currently selected.");
|
|
55 return;
|
|
56 }
|
47
|
57
|
|
58 // UI part
|
81
|
59 scr_WriteOutgoingMessage(jid, msg);
|
47
|
60
|
|
61 // Network part
|
|
62 buffer = utf8_encode(msg);
|
81
|
63 jb_send_msg(jid, buffer);
|
47
|
64 free(buffer);
|
|
65 }
|
|
66
|
|
67 // process_line(line)
|
|
68 // Process a command/message line.
|
|
69 // If this isn't a command, this is a message and it is sent to the
|
|
70 // currently selected buddy.
|
|
71 int process_line(char *line)
|
|
72 {
|
|
73 if (*line != '/') {
|
|
74 send_message(line);
|
|
75 return 0;
|
|
76 }
|
|
77 if (!strcasecmp(line, "/quit")) {
|
|
78 return 255;
|
|
79 }
|
|
80 // Commands handling
|
|
81 // TODO
|
|
82 // say, send_raw...
|
|
83
|
|
84 scr_LogPrint("Unrecognised command, sorry.");
|
|
85 return 0;
|
|
86 }
|
|
87
|