irctk

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

commit d7fc9200e286b6e0c3e39977af48b6d422493918
parent bea07f7af5f9bd972832f23c4ce9cdd3160c5936
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Wed, 11 Jul 2012 22:13:00 +0200

cleanup

Diffstat:
irctk.c | 54++++++++++++++++++------------------------------------
1 file changed, 18 insertions(+), 36 deletions(-)

diff --git a/irctk.c b/irctk.c @@ -278,10 +278,8 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) struct arguments *arguments = state->input; int i; - if (key != ARGP_KEY_ARG && key != ARGP_KEY_END && (! arguments->channels)) - { - switch (key) - { + if (key != ARGP_KEY_ARG && key != ARGP_KEY_END && (! arguments->channels)) { + switch (key) { case 'v': arguments->verbosity = 1; break; @@ -374,11 +372,9 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) return ARGP_ERR_UNKNOWN; } } else { - switch(key) - { + switch(key) { case ARGP_KEY_ARG: - if (state->arg_num == 0) - { + if (state->arg_num == 0) { i = -1; arguments->raw_dest = arg; arguments->server = arg; @@ -386,14 +382,12 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) int saw_colon = 0; int saw_at = 0; - while (arguments->raw_dest[++i]) - { + while (arguments->raw_dest[++i]) { if (arguments->raw_dest[i] == ':' && !saw_colon) { arguments->raw_dest[i] = 0; saw_colon = i; } - if (arguments->raw_dest[i] == '@') - { + if (arguments->raw_dest[i] == '@') { arguments->raw_dest[i] = 0; saw_at = i; arguments->server = arguments->raw_dest + saw_at + 1; @@ -411,8 +405,7 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) } } else { - if (arguments->channels == NULL) - { + if (arguments->channels == NULL) { //debug("start with %s, at %d", arg, state->arg_num); arguments->channels = state->argv + (state->next - 1); } @@ -438,8 +431,7 @@ static struct argp argp = { options, parse_opt, args_doc, doc }; * Verbosity is >=1 for debug, 0 for info, -n for error n-1 */ void message(int verbosity, const char *err, va_list ap) { - if (args.verbosity >= verbosity) - { + if (args.verbosity >= verbosity) { fprintf(stderr, "%s: ", verbosity > 0 ? "debug" : verbosity >= 0 ? "info" : "error"); vfprintf(stderr, err, ap); @@ -836,10 +828,8 @@ void push_fifo_set(fifo_set *s, char *fl, char *dests, char *l) { reset_chan_marks(s); was_empty = empty_fifo_set(s); - while (cont) - { - if (dests[i] == ',' || !dests[i]) - { + while (cont) { + if (dests[i] == ',' || !dests[i]) { if (!dests[i]) cont = 0; if (i) @@ -880,8 +870,7 @@ void push_fifo_set_all(fifo_set *s, char *fl, char **dests, int ndests, char *l) assert(ndests > 0); reset_chan_marks(s); was_empty = empty_fifo_set(s); - for (i=0; i<ndests; i++) - { + for (i=0; i<ndests; i++) { push_one(s, i?NULL:fl, dests[i], l, fifoidx, lineidx, &nfifoidx, &nlineidx); fifoidx = nfifoidx; lineidx = nlineidx; @@ -1197,8 +1186,7 @@ int do_cmd_msg(irc_session_t *s, char* chan, char* line) if (rsl) return rsl; - if (args.own) - { + if (args.own) { printf("[%s] <%s> %s", is_local ? chan : "", output_nick(args.nick), line); fflush(stdout); @@ -1316,10 +1304,8 @@ void manage_event (irc_session_t *session, const char *event, const char *origin saw_user(origin); - if (atoi(event) == LIBIRC_RFC_ERR_ERRONEUSNICKNAME) - { - if (args.force_nick) - { + if (atoi(event) == LIBIRC_RFC_ERR_ERRONEUSNICKNAME) { + if (args.force_nick) { die(E_BADNAME, "Invalid nick"); } else { // TODO does not work @@ -1329,8 +1315,7 @@ void manage_event (irc_session_t *session, const char *event, const char *origin } } else if (atoi(event) == LIBIRC_RFC_ERR_NICKCOLLISION || atoi(event) == LIBIRC_RFC_ERR_NICKNAMEINUSE) { - if (args.force_nick) - { + if (args.force_nick) { die(E_BADNAME, "Nickname already in use"); } else { int len = strlen(args.nick); @@ -1468,8 +1453,7 @@ void event_connect (irc_session_t *session, const char *event, const char *origi ctx->ready = 1; debug("Connected!"); - for (i = 0; i < ctx->n_channels; i++) - { + for (i = 0; i < ctx->n_channels; i++) { debug("Attempt to join %s", ctx->channels[i]); join_channel (session, ctx->channels[i]); } @@ -1486,8 +1470,7 @@ void event_channel (irc_session_t *session, const char *event, if (count != 2) return; if (args.filter) - if (strcmp(params[0], args.nick)) - { + if (strcmp(params[0], args.nick)) { for (i=0; i<strlen(args.nick); i++) if (args.nick[i] != params[1][i] || !params[1][i]) { ok = 0; @@ -1635,8 +1618,7 @@ static void* fifo_in_thread (void *arg) { while ((res = getline(&line, (size_t*) &size, stdin)) != -1) { debug("[thread_in] READS %s", line); debug("someone will have to free %p", line); - if (line[0] == '[' && args.destination_prefix) - { + if (line[0] == '[' && args.destination_prefix) { int i=0; char *msg; char *target = line+1;