summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-10 18:29:24 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-10 18:51:27 +0200
commite7d0f2380eb00610d335d87dd0656e50840aa8c0 (patch)
treecfbeb45dbd3b028355d394fbe2929598426020dd
parent36529a46fd52d8924923027c79afe44cd810861e (diff)
downloadxK-e7d0f2380eb00610d335d87dd0656e50840aa8c0.tar.gz
xK-e7d0f2380eb00610d335d87dd0656e50840aa8c0.tar.xz
xK-e7d0f2380eb00610d335d87dd0656e50840aa8c0.zip
xC: split Command.BUFFER_INPUT on newlines
-rw-r--r--xC.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/xC.c b/xC.c
index 13cd57d..eedb769 100644
--- a/xC.c
+++ b/xC.c
@@ -8180,7 +8180,7 @@ irc_try_parse_welcome_for_userhost (struct server *s, const char *m)
strv_free (&v);
}
-static bool process_input_utf8
+static bool process_input_line
(struct app_context *, struct buffer *, const char *, int);
static void on_autoaway_timer (struct app_context *ctx);
@@ -8209,7 +8209,7 @@ irc_on_registered (struct server *s, const char *nickname)
if (command)
{
log_server_debug (s, "Executing \"#s\"", command);
- (void) process_input_utf8 (s->ctx, s->buffer, command, 0);
+ (void) process_input_line (s->ctx, s->buffer, command, 0);
}
int64_t command_delay = get_config_integer (s->config, "command_delay");
@@ -9840,7 +9840,7 @@ lua_buffer_execute (lua_State *L)
struct lua_weak *wrapper = lua_weak_deref (L, &lua_buffer_info);
struct buffer *buffer = wrapper->object;
const char *line = lua_plugin_check_utf8 (L, 2);
- (void) process_input_utf8 (wrapper->plugin->ctx, buffer, line, 0);
+ (void) process_input_line (wrapper->plugin->ctx, buffer, line, 0);
return 0;
}
@@ -13270,13 +13270,13 @@ process_alias (struct app_context *ctx, struct buffer *buffer,
log_global_debug (ctx, "Alias expanded to: ###d: \"#s\"",
(int) i, commands->vector[i]);
for (size_t i = 0; i < commands->len; i++)
- if (!process_input_utf8 (ctx, buffer, commands->vector[i], ++level))
+ if (!process_input_line (ctx, buffer, commands->vector[i], ++level))
return false;
return true;
}
static bool
-process_input_utf8_posthook (struct app_context *ctx, struct buffer *buffer,
+process_input_line_posthook (struct app_context *ctx, struct buffer *buffer,
char *input, int alias_level)
{
if (*input != '/' || *++input == '/')
@@ -13325,35 +13325,27 @@ process_input_hooks (struct app_context *ctx, struct buffer *buffer,
}
static bool
-process_input_utf8 (struct app_context *ctx, struct buffer *buffer,
+process_input_line (struct app_context *ctx, struct buffer *buffer,
const char *input, int alias_level)
{
// Note that this also gets called on expanded aliases,
// which might or might not be desirable (we can forward "alias_level")
char *processed = process_input_hooks (ctx, buffer, xstrdup (input));
bool result = !processed
- || process_input_utf8_posthook (ctx, buffer, processed, alias_level);
+ || process_input_line_posthook (ctx, buffer, processed, alias_level);
free (processed);
return result;
}
static void
-process_input (struct app_context *ctx, char *user_input)
+process_input (struct app_context *ctx, struct buffer *buffer,
+ const char *input)
{
- char *input;
- if (!(input = iconv_xstrdup (ctx->term_to_utf8, user_input, -1, NULL)))
- print_error ("character conversion failed for: %s", "user input");
- else
- {
- struct strv lines = strv_make ();
- cstr_split (input, "\r\n", false, &lines);
- for (size_t i = 0; i < lines.len; i++)
- (void) process_input_utf8 (ctx,
- ctx->current_buffer, lines.vector[i], 0);
-
- strv_free (&lines);
- }
- free (input);
+ struct strv lines = strv_make ();
+ cstr_split (input, "\r\n", false, &lines);
+ for (size_t i = 0; i < lines.len; i++)
+ (void) process_input_line (ctx, buffer, lines.vector[i], 0);
+ strv_free (&lines);
}
// --- Word completion ---------------------------------------------------------
@@ -14589,7 +14581,7 @@ on_editline_return (EditLine *editline, int key)
}
free (line);
- // process_input() expects a multibyte string
+ // on_pending_input() expects a multibyte string
const LineInfo *info_mb = el_line (editline);
strv_append_owned (&ctx->pending_input,
xstrndup (info_mb->buffer, info_mb->lastchar - info_mb->buffer));
@@ -15179,7 +15171,15 @@ on_pending_input (struct app_context *ctx)
{
poller_idle_reset (&ctx->input_event);
for (size_t i = 0; i < ctx->pending_input.len; i++)
- process_input (ctx, ctx->pending_input.vector[i]);
+ {
+ char *input = iconv_xstrdup
+ (ctx->term_to_utf8, ctx->pending_input.vector[i], -1, NULL);
+ if (input)
+ process_input (ctx, ctx->current_buffer, input);
+ else
+ print_error ("character conversion failed for: %s", "user input");
+ free (input);
+ }
strv_reset (&ctx->pending_input);
}
@@ -15383,8 +15383,7 @@ client_process_message (struct client *c,
&m->data.buffer_complete);
break;
case RELAY_COMMAND_BUFFER_INPUT:
- (void) process_input_utf8 (c->ctx,
- buffer, m->data.buffer_input.text.str, 0);
+ process_input (c->ctx, buffer, m->data.buffer_input.text.str);
break;
case RELAY_COMMAND_BUFFER_ACTIVATE:
buffer_activate (c->ctx, buffer);