From 87a44fb8070da327e777c8dfbfdbd7fcaa34d416 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Thu, 18 Jun 2015 08:20:47 +0200 Subject: degesch: cleanup --- degesch.c | 52 ++++++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/degesch.c b/degesch.c index 989a95f..6dd1454 100644 --- a/degesch.c +++ b/degesch.c @@ -6320,48 +6320,28 @@ handle_command_mode (struct app_context *ctx, char *arguments) // Channel names prefixed by "+" collide with mode strings, // so we just disallow specifying these channels - char *channel_name = NULL; - char *nickname = NULL; - - if (*arguments != '+') - channel_name = maybe_cut_word (&arguments, validate_channel_name, s); - if (!channel_name - && !strchr ("+-\0", *arguments)) - nickname = cut_word (&arguments); - - if (!channel_name - && !nickname) + char *target = NULL; + if (strchr ("+-\0", *arguments) + || !(target = maybe_cut_word (&arguments, validate_channel_name, s)) + || !(target = cut_word (&arguments))) { if (ctx->current_buffer->type == BUFFER_CHANNEL) - channel_name = ctx->current_buffer->channel->name; + target = ctx->current_buffer->channel->name; if (ctx->current_buffer->type == BUFFER_PM) - nickname = ctx->current_buffer->user->nickname; + target = ctx->current_buffer->user->nickname; if (ctx->current_buffer->type == BUFFER_SERVER) - nickname = ctx->current_buffer->server->irc_user->nickname; - } - - if (channel_name) - { - if (*arguments) - // XXX: split as necessary using irc_max_modes? - irc_send (s, "MODE %s %s", channel_name, arguments); - else - irc_send (s, "MODE %s", channel_name); - return true; + target = ctx->current_buffer->server->irc_user->nickname; } - if (nickname) - { - if (*arguments) - irc_send (s, "MODE %s %s", nickname, arguments); - else - irc_send (s, "MODE %s", nickname); - return true; - } - - buffer_send_error (ctx, ctx->current_buffer, - "%s: %s", "Can't change mode", - "no target given and this buffer is neither a PM nor a channel"); + if (!target) + buffer_send_error (ctx, ctx->current_buffer, + "%s: %s", "Can't change mode", + "no target given and this buffer is neither a PM nor a channel"); + else if (*arguments) + // XXX: split channel mode params as necessary using irc_max_modes? + irc_send (s, "MODE %s %s", target, arguments); + else + irc_send (s, "MODE %s", target); return true; } -- cgit v1.2.3-70-g09d2