summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-06-28 03:00:19 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-06-28 03:00:19 +0200
commit02ab0f743bed7607daef5b4992d4b2fc1e28203f (patch)
tree25bb98a6a5d8121a2d4b196e41703bc5cb1df034
parent335aeb599aa35872eb85eb266610baf5525aa250 (diff)
downloadxK-02ab0f743bed7607daef5b4992d4b2fc1e28203f.tar.gz
xK-02ab0f743bed7607daef5b4992d4b2fc1e28203f.tar.xz
xK-02ab0f743bed7607daef5b4992d4b2fc1e28203f.zip
degesch: remove "ctx" from command handler args
-rw-r--r--degesch.c119
1 files changed, 43 insertions, 76 deletions
diff --git a/degesch.c b/degesch.c
index 98c9df2..d951e60 100644
--- a/degesch.c
+++ b/degesch.c
@@ -5918,6 +5918,7 @@ enum handler_flags
struct handler_args
{
+ struct app_context *ctx; ///< Application context
struct buffer *buffer; ///< Current buffer
struct server *s; ///< Related server
const char *channel_name; ///< Related channel name
@@ -6095,8 +6096,9 @@ handle_buffer_move (struct app_context *ctx, struct handler_args *a)
}
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);
if (try_handle_buffer_goto (ctx, action))
return true;
@@ -6259,8 +6261,9 @@ handle_command_set_assign
}
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 = "*";
if (*a->arguments)
option = cut_word (&a->arguments);
@@ -6286,8 +6289,9 @@ handle_command_set (struct app_context *ctx, struct handler_args *a)
}
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)
return false;
@@ -6312,10 +6316,8 @@ handle_command_save (struct app_context *ctx, struct handler_args *a)
}
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)
return false;
@@ -6328,7 +6330,7 @@ handle_command_msg (struct app_context *ctx, struct handler_args *a)
}
static bool
-handle_command_query (struct app_context *ctx, struct handler_args *a)
+handle_command_query (struct handler_args *a)
{
if (!*a->arguments)
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");
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);
}
return true;
}
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)
return false;
@@ -6363,10 +6363,8 @@ handle_command_notice (struct app_context *ctx, struct handler_args *a)
}
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)
return false;
@@ -6388,10 +6386,8 @@ handle_command_ctcp (struct app_context *ctx, struct handler_args *a)
}
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)
SEND_AUTOSPLIT_ACTION (a->s,
a->buffer->channel->name, a->arguments);
@@ -6406,10 +6402,10 @@ handle_command_me (struct app_context *ctx, struct handler_args *a)
}
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;
- str_map_iter_init (&iter, &ctx->servers);
+ str_map_iter_init (&iter, &a->ctx->servers);
struct server *s;
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);
}
- initiate_quit (ctx);
+ initiate_quit (a->ctx);
return true;
}
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?
if (irc_is_channel (a->s, a->arguments))
// 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
-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))
{
struct str_vector v;
@@ -6501,10 +6493,8 @@ cycle_channel (struct server *s, const char *channel_name, const char *reason)
}
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))
{
struct str_vector v;
@@ -6527,10 +6517,8 @@ handle_command_cycle (struct app_context *ctx, struct handler_args *a)
}
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,
// so we just disallow specifying these channels
char *target = NULL;
@@ -6560,10 +6548,8 @@ handle_command_mode (struct app_context *ctx, struct handler_args *a)
}
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)
// FIXME: there's no way to unset the topic
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
-handle_command_kick (struct app_context *ctx, struct handler_args *a)
+handle_command_kick (struct handler_args *a)
{
- (void) ctx;
-
if (!*a->arguments)
return false;
@@ -6590,10 +6574,8 @@ handle_command_kick (struct app_context *ctx, struct handler_args *a)
}
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)
return false;
@@ -6661,10 +6643,8 @@ mass_channel_mode_mask_list
}
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)
mass_channel_mode_mask_list (a, true, 'b');
else
@@ -6673,10 +6653,8 @@ handle_command_ban (struct app_context *ctx, struct handler_args *a)
}
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)
mass_channel_mode_mask_list (a, false, 'b');
else
@@ -6685,10 +6663,8 @@ handle_command_unban (struct app_context *ctx, struct handler_args *a)
}
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;
str_vector_init (&v);
split_str_ignore_empty (a->arguments, ' ', &v);
@@ -6722,10 +6698,10 @@ resolve_server (struct app_context *ctx, struct handler_args *a,
}
static bool
-handle_command_connect (struct app_context *ctx, struct handler_args *a)
+handle_command_connect (struct handler_args *a)
{
struct server *s = NULL;
- if (!(s = resolve_server (ctx, a, "connect")))
+ if (!(s = resolve_server (a->ctx, a, "connect")))
return true;
if (irc_is_connected (s))
@@ -6742,10 +6718,10 @@ handle_command_connect (struct app_context *ctx, struct handler_args *a)
}
static bool
-handle_command_disconnect (struct app_context *ctx, struct handler_args *a)
+handle_command_disconnect (struct handler_args *a)
{
struct server *s = NULL;
- if (!(s = resolve_server (ctx, a, "disconnect")))
+ if (!(s = resolve_server (a->ctx, a, "disconnect")))
return true;
if (s->state == IRC_CONNECTING)
@@ -6761,10 +6737,8 @@ handle_command_disconnect (struct app_context *ctx, struct handler_args *a)
}
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);
if (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
-handle_command_whois (struct app_context *ctx, struct handler_args *a)
+handle_command_whois (struct handler_args *a)
{
- (void) ctx;
-
if (*a->arguments)
irc_send (a->s, "WHOIS %s", a->arguments);
else if (a->buffer->type == BUFFER_PM)
@@ -6791,10 +6763,8 @@ handle_command_whois (struct app_context *ctx, struct handler_args *a)
}
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)
irc_send (a->s, "WHOWAS %s", a->arguments);
else if (a->buffer->type == BUFFER_PM)
@@ -6806,10 +6776,8 @@ handle_command_whowas (struct app_context *ctx, struct handler_args *a)
}
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)
return false;
@@ -6818,9 +6786,8 @@ handle_command_nick (struct app_context *ctx, struct handler_args *a)
}
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);
return true;
}
@@ -6844,9 +6811,8 @@ handle_command_channel_mode
#define CHANMODE_HANDLER(name, adding, mode_char) \
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)); \
}
@@ -6855,9 +6821,8 @@ CHANMODE_HANDLER (voice, true, 'v') CHANMODE_HANDLER (devoice, false, 'v')
#define TRIVIAL_HANDLER(name, command) \
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) \
irc_send (a->s, command " %s", a->arguments); \
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
{
const char *name;
const char *description;
const char *usage;
- bool (*handler) (struct app_context *ctx, struct handler_args *a);
+ bool (*handler) (struct handler_args *a);
enum handler_flags flags;
}
g_command_handlers[] =
@@ -7032,8 +6997,9 @@ try_handle_command_help_option (struct app_context *ctx, const char *name)
}
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)
{
log_global_status (ctx, "");
@@ -7126,6 +7092,7 @@ process_user_command (struct app_context *ctx, char *input)
struct handler_args args =
{
+ .ctx = ctx,
.buffer = ctx->current_buffer,
.arguments = input,
};
@@ -7151,7 +7118,7 @@ process_user_command (struct app_context *ctx, char *input)
try_get_channel (&args, maybe_cut_word_from_end))))
log_server_error (args.s, args.buffer, "/#s: #s", command_name,
"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,
"#s: /#s #s", "Usage", handler->name, handler->usage);
}