irctk

libircclient binding for scripts
git clone https://a3nm.net/git/irctk/
Log | Files | Refs | README

commit 97c2a291efe961584c964d9f35ee2befa6d45c12
parent 6f6fef046a076c8bc7c9dae47b7a6eac6130243e
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sat, 21 Jul 2012 02:01:40 +0200

always flush stdout after printing

Diffstat:
irctk.c | 57+++++++++++++++++++++++++++++++++------------------------
1 file changed, 33 insertions(+), 24 deletions(-)

diff --git a/irctk.c b/irctk.c @@ -464,6 +464,16 @@ void die(int val, const char *err, ...) return message(-val - 1, err, ap); } +int mprintf(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int ret; + ret = vprintf(fmt, ap); + fflush(stdout); + return ret; +} + void debug_args() { @@ -1161,11 +1171,10 @@ int do_cmd_msg(irc_session_t *s, char *chan, char* line) return rsl; if (args.own) { - printf("[%s] <%s%s> %s", is_local ? chan : "", + mprintf("[%s] <%s%s> %s", is_local ? chan : "", output_nick(args.nick), args.with_host ? args.hostname : "", line); - fflush(stdout); } return 0; @@ -1349,10 +1358,11 @@ void event_nick (irc_session_t *session, const char *event, const char *origin, debug("[] <%s> /nick %s\n", origin, params[0]); saw_user(origin); rename_user(&fifos, origin, params[0]); + debug("EVENTS_TO events-to %d", args.event_to); if (args.event_to == COMMAND) - printf("[] <%s> /nick %s\n", output_nick(origin), params[0]); + mprintf("[] <%s> /nick %s\n", output_nick(origin), params[0]); if (args.event_to == MESSAGE) - printf("[] -!- %s is now known as %s\n", output_nick(origin), params[0]); + mprintf("[] -!- %s is now known as %s\n", output_nick(origin), params[0]); } // Handle a join event @@ -1364,9 +1374,9 @@ void event_join (irc_session_t * session, const char *event, const char *origin, saw_user(params[0]); if (args.event_to == COMMAND) - printf("[%s] <%s> /join %s\n", params[0], output_nick(origin), params[0]); + mprintf("[%s] <%s> /join %s\n", params[0], output_nick(origin), params[0]); if (args.event_to == MESSAGE) - printf("[%s] -!- %s has joined %s\n", params[0], output_nick(origin), params[0]); + mprintf("[%s] -!- %s has joined %s\n", params[0], output_nick(origin), params[0]); } // Handle a part event @@ -1375,9 +1385,9 @@ void event_part (irc_session_t *session, const char *event, const char *origin, { saw_user(origin); if (args.event_to == COMMAND) - printf("[%s] <%s> /part %s\n", params[0], output_nick(origin), params[0]); + mprintf("[%s] <%s> /part %s\n", params[0], output_nick(origin), params[0]); if (args.event_to == MESSAGE) - printf("[%s] -!- %s has left %s (%s)\n", params[0], output_nick(origin), params[0], + mprintf("[%s] -!- %s has left %s (%s)\n", params[0], output_nick(origin), params[0], params[1]); } @@ -1387,9 +1397,9 @@ void event_topic (irc_session_t *session, const char *event, const char *origin, { saw_user(origin); if (args.event_to == COMMAND) - printf("[%s] <%s> /topic %s\n", params[0], output_nick(origin), params[1]); + mprintf("[%s] <%s> /topic %s\n", params[0], output_nick(origin), params[1]); if (args.event_to == MESSAGE) - printf("[%s] -!- %s changed the topic of %s to %s\n", params[0], output_nick(origin), + mprintf("[%s] -!- %s changed the topic of %s to %s\n", params[0], output_nick(origin), params[0], params[1]); } @@ -1399,9 +1409,9 @@ void event_quit (irc_session_t *session, const char *event, const char *origin, { saw_user(origin); if (args.event_to == COMMAND) - printf("[] <%s> /quit %s\n", output_nick(origin), params[0]); + mprintf("[] <%s> /quit %s\n", output_nick(origin), params[0]); if (args.event_to == MESSAGE) - printf("[] -!- %s has quit (%s)\n", output_nick(origin), params[1]); + mprintf("[] -!- %s has quit (%s)\n", output_nick(origin), params[0]); } // Handle an action @@ -1411,9 +1421,9 @@ void event_ctcp_action (irc_session_t *session, const char *event, saw_user(origin); //TODO where is the channel?! if (args.event_to == COMMAND) - printf("[%s] <%s> /me %s\n", params[0], output_nick(origin), params[1]); + mprintf("[%s] <%s> /me %s\n", params[0], output_nick(origin), params[1]); if (args.event_to == MESSAGE) - printf("[%s] *** %s %s\n", params[0], output_nick(origin), params[1]); + mprintf("[%s] *** %s %s\n", params[0], output_nick(origin), params[1]); } // Handle a kick event @@ -1424,9 +1434,9 @@ void event_kick (irc_session_t *session, const char *event, const char *origin, saw_user(params[1]); // TODO check for optional params if (args.event_to == COMMAND) - printf("[%s] <%s> /kick %s %s\n", params[0], output_nick(origin), params[1], params[2]); + mprintf("[%s] <%s> /kick %s %s\n", params[0], output_nick(origin), params[1], params[2]); if (args.event_to == MESSAGE) - printf("[%s] -!- %s was kicked from %s by %s (%s)\n", params[0], output_nick(params[1]), + mprintf("[%s] -!- %s was kicked from %s by %s (%s)\n", params[0], output_nick(params[1]), params[0], output_nick(origin), params[2]); } @@ -1477,17 +1487,17 @@ void event_channel (irc_session_t *session, const char *event, if (ok) { if (!args.prune) { - printf ("[%s] <", params[0]); + mprintf ("[%s] <", params[0]); if (!origin) - printf("someone"); + mprintf("someone"); else /* not robust, and useless since we use STRIPNICKS */ //while(origin[i++] != '!') putchar(origin[i-1]); - printf("%s", output_nick(origin)); - printf("> "); + mprintf("%s", output_nick(origin)); + mprintf("> "); if (params[1][0] == '/' && args.event_to == COMMAND) - printf("/ "); // escape slashes - printf("%s\n", params[1] ); + mprintf("/ "); // escape slashes + mprintf("%s\n", params[1] ); } else { pruned = params[1]; while (pruned[0] == ' ') pruned++; @@ -1507,7 +1517,7 @@ void event_channel (irc_session_t *session, const char *event, } else pruned = params[1]; // no address - printf("%s\n", pruned); + mprintf("%s\n", pruned); } // if addressed in our private chan, reply on the sender's priv chan if (strcmp(params[0], args.nick)) @@ -1520,7 +1530,6 @@ void event_channel (irc_session_t *session, const char *event, } else { strncpy(args.last_nick_in, origin?origin:"someone", MAX_LEN-1); } - fflush(stdout); } }