degesch: remove "ctx" from command handler args

This commit is contained in:
Přemysl Eric Janouch 2015-06-28 03:00:19 +02:00
parent 335aeb599a
commit 02ab0f743b
1 changed files with 43 additions and 76 deletions

119
degesch.c
View File

@ -5918,6 +5918,7 @@ enum handler_flags
struct handler_args struct handler_args
{ {
struct app_context *ctx; ///< Application context
struct buffer *buffer; ///< Current buffer struct buffer *buffer; ///< Current buffer
struct server *s; ///< Related server struct server *s; ///< Related server
const char *channel_name; ///< Related channel name const char *channel_name; ///< Related channel name
@ -6095,8 +6096,9 @@ handle_buffer_move (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_buffer (struct app_context *ctx, struct handler_args *a) handle_command_buffer (struct handler_args *a)
{ {
struct app_context *ctx = a->ctx;
char *action = cut_word (&a->arguments); char *action = cut_word (&a->arguments);
if (try_handle_buffer_goto (ctx, action)) if (try_handle_buffer_goto (ctx, action))
return true; return true;
@ -6259,8 +6261,9 @@ handle_command_set_assign
} }
static bool static bool
handle_command_set (struct app_context *ctx, struct handler_args *a) handle_command_set (struct handler_args *a)
{ {
struct app_context *ctx = a->ctx;
char *option = "*"; char *option = "*";
if (*a->arguments) if (*a->arguments)
option = cut_word (&a->arguments); option = cut_word (&a->arguments);
@ -6286,8 +6289,9 @@ handle_command_set (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_save (struct app_context *ctx, struct handler_args *a) handle_command_save (struct handler_args *a)
{ {
struct app_context *ctx = a->ctx;
if (*a->arguments) if (*a->arguments)
return false; return false;
@ -6312,10 +6316,8 @@ handle_command_save (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_msg (struct app_context *ctx, struct handler_args *a) handle_command_msg (struct handler_args *a)
{ {
(void) ctx;
if (!*a->arguments) if (!*a->arguments)
return false; return false;
@ -6328,7 +6330,7 @@ handle_command_msg (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_query (struct app_context *ctx, struct handler_args *a) handle_command_query (struct handler_args *a)
{ {
if (!*a->arguments) if (!*a->arguments)
return false; return false;
@ -6340,17 +6342,15 @@ handle_command_query (struct app_context *ctx, struct handler_args *a)
log_server_error (a->s, a->s->buffer, "No text to send"); log_server_error (a->s, a->s->buffer, "No text to send");
else else
{ {
buffer_activate (ctx, irc_get_or_make_user_buffer (a->s, target)); buffer_activate (a->ctx, irc_get_or_make_user_buffer (a->s, target));
SEND_AUTOSPLIT_PRIVMSG (a->s, target, a->arguments); SEND_AUTOSPLIT_PRIVMSG (a->s, target, a->arguments);
} }
return true; return true;
} }
static bool static bool
handle_command_notice (struct app_context *ctx, struct handler_args *a) handle_command_notice (struct handler_args *a)
{ {
(void) ctx;
if (!*a->arguments) if (!*a->arguments)
return false; return false;
@ -6363,10 +6363,8 @@ handle_command_notice (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_ctcp (struct app_context *ctx, struct handler_args *a) handle_command_ctcp (struct handler_args *a)
{ {
(void) ctx;
if (!*a->arguments) if (!*a->arguments)
return false; return false;
@ -6388,10 +6386,8 @@ handle_command_ctcp (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_me (struct app_context *ctx, struct handler_args *a) handle_command_me (struct handler_args *a)
{ {
(void) ctx;
if (a->buffer->type == BUFFER_CHANNEL) if (a->buffer->type == BUFFER_CHANNEL)
SEND_AUTOSPLIT_ACTION (a->s, SEND_AUTOSPLIT_ACTION (a->s,
a->buffer->channel->name, a->arguments); a->buffer->channel->name, a->arguments);
@ -6406,10 +6402,10 @@ handle_command_me (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_quit (struct app_context *ctx, struct handler_args *a) handle_command_quit (struct handler_args *a)
{ {
struct str_map_iter iter; struct str_map_iter iter;
str_map_iter_init (&iter, &ctx->servers); str_map_iter_init (&iter, &a->ctx->servers);
struct server *s; struct server *s;
while ((s = str_map_iter_next (&iter))) while ((s = str_map_iter_next (&iter)))
@ -6418,15 +6414,13 @@ handle_command_quit (struct app_context *ctx, struct handler_args *a)
irc_initiate_disconnect (s, *a->arguments ? a->arguments : NULL); irc_initiate_disconnect (s, *a->arguments ? a->arguments : NULL);
} }
initiate_quit (ctx); initiate_quit (a->ctx);
return true; return true;
} }
static bool static bool
handle_command_join (struct app_context *ctx, struct handler_args *a) handle_command_join (struct handler_args *a)
{ {
(void) ctx;
// XXX: send the last known channel key? // XXX: send the last known channel key?
if (irc_is_channel (a->s, a->arguments)) if (irc_is_channel (a->s, a->arguments))
// XXX: we may want to split the list of channels // XXX: we may want to split the list of channels
@ -6455,10 +6449,8 @@ part_channel (struct server *s, const char *channel_name, const char *reason)
} }
static bool static bool
handle_command_part (struct app_context *ctx, struct handler_args *a) handle_command_part (struct handler_args *a)
{ {
(void) ctx;
if (irc_is_channel (a->s, a->arguments)) if (irc_is_channel (a->s, a->arguments))
{ {
struct str_vector v; struct str_vector v;
@ -6501,10 +6493,8 @@ cycle_channel (struct server *s, const char *channel_name, const char *reason)
} }
static bool static bool
handle_command_cycle (struct app_context *ctx, struct handler_args *a) handle_command_cycle (struct handler_args *a)
{ {
(void) ctx;
if (irc_is_channel (a->s, a->arguments)) if (irc_is_channel (a->s, a->arguments))
{ {
struct str_vector v; struct str_vector v;
@ -6527,10 +6517,8 @@ handle_command_cycle (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_mode (struct app_context *ctx, struct handler_args *a) handle_command_mode (struct handler_args *a)
{ {
(void) ctx;
// Channel names prefixed by "+" collide with mode strings, // Channel names prefixed by "+" collide with mode strings,
// so we just disallow specifying these channels // so we just disallow specifying these channels
char *target = NULL; char *target = NULL;
@ -6560,10 +6548,8 @@ handle_command_mode (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_topic (struct app_context *ctx, struct handler_args *a) handle_command_topic (struct handler_args *a)
{ {
(void) ctx;
if (*a->arguments) if (*a->arguments)
// FIXME: there's no way to unset the topic // FIXME: there's no way to unset the topic
irc_send (a->s, "TOPIC %s :%s", a->channel_name, a->arguments); irc_send (a->s, "TOPIC %s :%s", a->channel_name, a->arguments);
@ -6573,10 +6559,8 @@ handle_command_topic (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_kick (struct app_context *ctx, struct handler_args *a) handle_command_kick (struct handler_args *a)
{ {
(void) ctx;
if (!*a->arguments) if (!*a->arguments)
return false; return false;
@ -6590,10 +6574,8 @@ handle_command_kick (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_kickban (struct app_context *ctx, struct handler_args *a) handle_command_kickban (struct handler_args *a)
{ {
(void) ctx;
if (!*a->arguments) if (!*a->arguments)
return false; return false;
@ -6661,10 +6643,8 @@ mass_channel_mode_mask_list
} }
static bool static bool
handle_command_ban (struct app_context *ctx, struct handler_args *a) handle_command_ban (struct handler_args *a)
{ {
(void) ctx;
if (*a->arguments) if (*a->arguments)
mass_channel_mode_mask_list (a, true, 'b'); mass_channel_mode_mask_list (a, true, 'b');
else else
@ -6673,10 +6653,8 @@ handle_command_ban (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_unban (struct app_context *ctx, struct handler_args *a) handle_command_unban (struct handler_args *a)
{ {
(void) ctx;
if (*a->arguments) if (*a->arguments)
mass_channel_mode_mask_list (a, false, 'b'); mass_channel_mode_mask_list (a, false, 'b');
else else
@ -6685,10 +6663,8 @@ handle_command_unban (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_invite (struct app_context *ctx, struct handler_args *a) handle_command_invite (struct handler_args *a)
{ {
(void) ctx;
struct str_vector v; struct str_vector v;
str_vector_init (&v); str_vector_init (&v);
split_str_ignore_empty (a->arguments, ' ', &v); split_str_ignore_empty (a->arguments, ' ', &v);
@ -6722,10 +6698,10 @@ resolve_server (struct app_context *ctx, struct handler_args *a,
} }
static bool static bool
handle_command_connect (struct app_context *ctx, struct handler_args *a) handle_command_connect (struct handler_args *a)
{ {
struct server *s = NULL; struct server *s = NULL;
if (!(s = resolve_server (ctx, a, "connect"))) if (!(s = resolve_server (a->ctx, a, "connect")))
return true; return true;
if (irc_is_connected (s)) if (irc_is_connected (s))
@ -6742,10 +6718,10 @@ handle_command_connect (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_disconnect (struct app_context *ctx, struct handler_args *a) handle_command_disconnect (struct handler_args *a)
{ {
struct server *s = NULL; struct server *s = NULL;
if (!(s = resolve_server (ctx, a, "disconnect"))) if (!(s = resolve_server (a->ctx, a, "disconnect")))
return true; return true;
if (s->state == IRC_CONNECTING) if (s->state == IRC_CONNECTING)
@ -6761,10 +6737,8 @@ handle_command_disconnect (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_names (struct app_context *ctx, struct handler_args *a) handle_command_names (struct handler_args *a)
{ {
(void) ctx;
char *channel_name = try_get_channel (a, maybe_cut_word); char *channel_name = try_get_channel (a, maybe_cut_word);
if (channel_name) if (channel_name)
irc_send (a->s, "NAMES %s", channel_name); irc_send (a->s, "NAMES %s", channel_name);
@ -6774,10 +6748,8 @@ handle_command_names (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_whois (struct app_context *ctx, struct handler_args *a) handle_command_whois (struct handler_args *a)
{ {
(void) ctx;
if (*a->arguments) if (*a->arguments)
irc_send (a->s, "WHOIS %s", a->arguments); irc_send (a->s, "WHOIS %s", a->arguments);
else if (a->buffer->type == BUFFER_PM) else if (a->buffer->type == BUFFER_PM)
@ -6791,10 +6763,8 @@ handle_command_whois (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_whowas (struct app_context *ctx, struct handler_args *a) handle_command_whowas (struct handler_args *a)
{ {
(void) ctx;
if (*a->arguments) if (*a->arguments)
irc_send (a->s, "WHOWAS %s", a->arguments); irc_send (a->s, "WHOWAS %s", a->arguments);
else if (a->buffer->type == BUFFER_PM) else if (a->buffer->type == BUFFER_PM)
@ -6806,10 +6776,8 @@ handle_command_whowas (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_nick (struct app_context *ctx, struct handler_args *a) handle_command_nick (struct handler_args *a)
{ {
(void) ctx;
if (!*a->arguments) if (!*a->arguments)
return false; return false;
@ -6818,9 +6786,8 @@ handle_command_nick (struct app_context *ctx, struct handler_args *a)
} }
static bool static bool
handle_command_quote (struct app_context *ctx, struct handler_args *a) handle_command_quote (struct handler_args *a)
{ {
(void) ctx;
irc_send (a->s, "%s", a->arguments); irc_send (a->s, "%s", a->arguments);
return true; return true;
} }
@ -6844,9 +6811,8 @@ handle_command_channel_mode
#define CHANMODE_HANDLER(name, adding, mode_char) \ #define CHANMODE_HANDLER(name, adding, mode_char) \
static bool \ static bool \
handle_command_ ## name (struct app_context *ctx, struct handler_args *a) \ handle_command_ ## name (struct handler_args *a) \
{ \ { \
(void) ctx; \
return handle_command_channel_mode (a, (adding), (mode_char)); \ return handle_command_channel_mode (a, (adding), (mode_char)); \
} }
@ -6855,9 +6821,8 @@ CHANMODE_HANDLER (voice, true, 'v') CHANMODE_HANDLER (devoice, false, 'v')
#define TRIVIAL_HANDLER(name, command) \ #define TRIVIAL_HANDLER(name, command) \
static bool \ static bool \
handle_command_ ## name (struct app_context *ctx, struct handler_args *a) \ handle_command_ ## name (struct handler_args *a) \
{ \ { \
(void) ctx; \
if (*a->arguments) \ if (*a->arguments) \
irc_send (a->s, command " %s", a->arguments); \ irc_send (a->s, command " %s", a->arguments); \
else \ else \
@ -6873,14 +6838,14 @@ TRIVIAL_HANDLER (away, "AWAY")
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static bool handle_command_help (struct app_context *, struct handler_args *); static bool handle_command_help (struct handler_args *);
static struct command_handler static struct command_handler
{ {
const char *name; const char *name;
const char *description; const char *description;
const char *usage; const char *usage;
bool (*handler) (struct app_context *ctx, struct handler_args *a); bool (*handler) (struct handler_args *a);
enum handler_flags flags; enum handler_flags flags;
} }
g_command_handlers[] = g_command_handlers[] =
@ -7032,8 +6997,9 @@ try_handle_command_help_option (struct app_context *ctx, const char *name)
} }
static bool static bool
handle_command_help (struct app_context *ctx, struct handler_args *a) handle_command_help (struct handler_args *a)
{ {
struct app_context *ctx = a->ctx;
if (!*a->arguments) if (!*a->arguments)
{ {
log_global_status (ctx, ""); log_global_status (ctx, "");
@ -7126,6 +7092,7 @@ process_user_command (struct app_context *ctx, char *input)
struct handler_args args = struct handler_args args =
{ {
.ctx = ctx,
.buffer = ctx->current_buffer, .buffer = ctx->current_buffer,
.arguments = input, .arguments = input,
}; };
@ -7151,7 +7118,7 @@ process_user_command (struct app_context *ctx, char *input)
try_get_channel (&args, maybe_cut_word_from_end)))) try_get_channel (&args, maybe_cut_word_from_end))))
log_server_error (args.s, args.buffer, "/#s: #s", command_name, log_server_error (args.s, args.buffer, "/#s: #s", command_name,
"no channel name given and this buffer is not a channel"); "no channel name given and this buffer is not a channel");
else if (!handler->handler (ctx, &args)) else if (!handler->handler (&args))
log_global_error (ctx, log_global_error (ctx,
"#s: /#s #s", "Usage", handler->name, handler->usage); "#s: /#s #s", "Usage", handler->name, handler->usage);
} }