commit 88c04eca19be963f2fa045e161a2f746014fb550
parent 64fa797900a188c066f438c6041eac8d939e8e57
Author: Antoine Amarilli <ant.amarilli@free.fr>
Date: Sun, 20 Feb 2011 03:56:46 +0100
wrote -l
Diffstat:
irctk.c | | | 79 | ++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- |
1 file changed, 46 insertions(+), 33 deletions(-)
diff --git a/irctk.c b/irctk.c
@@ -32,6 +32,7 @@
#define E_THREAD 3
#define E_BADNAME 4
+// TODO use an enum
#define DEFAULT_FIRST 0
#define DEFAULT_LAST_IN 1
#define DEFAULT_LAST_OUT 2
@@ -82,8 +83,8 @@ static struct argp_option options[] = {
/*{"no-auto-join", 0, 0, 0,
"Refuse to send any message to channels not specified on the command line (default is to join as needed)", MISC }, // TODO*/
- {"synchronous", 's', 0, 0,
- "Will wait for a multiline, blankline-terminated answer on stdin to all lines passed on stdout, and will bufferize activity before that", COM_MODE }, // TODO
+ /*{"synchronous", 's', 0, 0,
+ "Will wait for a multiline, blankline-terminated answer on stdin to all lines passed on stdout, and will bufferize activity before that", COM_MODE }, // TODO*/
/*{"exec", 'e', 0, 0,
"Pipe each message to this command", COM_MODE }, // TODO and support several of them
{"exec-argv", 'E', 0, 0,
@@ -470,7 +471,7 @@ int do_cmd_msg(irc_session_t *s, const char* chan, const char* line)
return 0;
}
-int cmd_msg(irc_session_t *s, char* target, const char* line)
+int cmd_msg_chan(irc_session_t *s, char *target, const char* line)
{
int i = 0;
int cont = 1;
@@ -479,18 +480,42 @@ int cmd_msg(irc_session_t *s, char* target, const char* line)
char *msg[MAX_LEN]; /* TODO TODO TODO !! */
int rsl;
+ one_target = target;
+
+ while (cont)
+ {
+ if (target[i] == ',' || !target[i])
+ {
+ if (!target[i])
+ cont = 0;
+ tmp = target[i];
+ target[i] = 0;
+ /* TODO manage errors correctly! */
+ rsl = do_cmd_msg(s, one_target, line);
+ target[i] = tmp;
+ one_target = target + i + 1;
+ }
+ i++;
+ }
+
+ return rsl;
+}
+
+int cmd_msg(irc_session_t *s, char* target, const char* line)
+{
+ int i = 0;
+ char *msg[MAX_LEN]; /* TODO TODO TODO !! */
+
/* Manage the fact that target may be "" */
if (!target[0])
{
switch(args.default_destination)
{
case DEFAULT_FIRST:
- target = first_chan();
- break;
+ return cmd_msg_chan(s, first_chan(), line);
case DEFAULT_LAST_IN:
- target = args.last_chan_in;
- if (args.show_nick_prefix && args.last_nick_in[0] && target[0] == '#')
+ if (args.show_nick_prefix && args.last_nick_in[0] && args.last_chan_in[0] == '#')
{
if (line[0] != '\n')
{
@@ -504,38 +529,26 @@ int cmd_msg(irc_session_t *s, char* target, const char* line)
args.last_nick_in[0] = 0;
}
}
- break;
+ return cmd_msg_chan(s, args.last_chan_in, line);
case DEFAULT_LAST_OUT:
- target = args.last_chans_out;
- break;
+ return cmd_msg_chan(s, args.last_chans_out, line);
case DEFAULT_ALL:
- /* TODO */
- target = args.last_chans_out;
- break;
- }
- }
-
- one_target = target;
-
- while (cont)
- {
- if (target[i] == ',' || !target[i])
- {
- if (!target[i])
- cont = 0;
- tmp = target[i];
- target[i] = 0;
- /* TODO manage errors correctly! */
- rsl = do_cmd_msg(s, one_target, line);
- target[i] = tmp;
- one_target = target + i + 1;
+ //TODO also for chans joined at runtime
+ //TODO2: ugly, could have generated the comma-separated string
+ //like for last_chans_out!
+ for (i = 0; i < args.n_channels; i++)
+ cmd_msg_chan(s, args.channels[i], line);
+ /* TODO return value */
+ return 0;
+
+ default:
+ return 42; // won't happen
}
- i++;
+ } else {
+ return cmd_msg_chan(s, target, line);
}
-
- return rsl;
}
THREAD_FUNCTION(irc_listen)