summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-11-15 01:23:32 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2015-11-15 01:23:32 +0100
commitd14bc2df53b8f61811b21a7b4a2ec8ec9e414a07 (patch)
tree714e8835a5f13dd3db5e8d254cd01ce2fe4d5cdc
parentd8299a1231110908986159b6f0ea65484fb17c84 (diff)
downloadxK-d14bc2df53b8f61811b21a7b4a2ec8ec9e414a07.tar.gz
xK-d14bc2df53b8f61811b21a7b4a2ec8ec9e414a07.tar.xz
xK-d14bc2df53b8f61811b21a7b4a2ec8ec9e414a07.zip
degesch: have just one input buffer
-rw-r--r--degesch.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/degesch.c b/degesch.c
index 4c27283..d0aca74 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1367,12 +1367,8 @@ struct app_context
size_t nick_palette_len; ///< Number of entries in nick_palette
bool awaiting_mirc_escape; ///< Awaiting a mIRC attribute escape
- // TODO: try to get rid of this in favor of "paste_buffer" -> "input_buffer"
- char char_buf[MB_LEN_MAX + 1]; ///< Buffered multibyte char
- size_t char_buf_len; ///< How much of an MB char is buffered
-
bool in_bracketed_paste; ///< User is pasting some content
- struct str paste_buffer; ///< Buffered pasted content
+ struct str input_buffer; ///< Buffered pasted content
bool running_backlog_helper; ///< Running a backlog helper
}
@@ -1437,7 +1433,7 @@ app_context_init (struct app_context *self)
free (encoding);
input_init (&self->input);
- str_init (&self->paste_buffer);
+ str_init (&self->input_buffer);
self->nick_palette =
filter_color_cube_for_acceptable_nick_colors (&self->nick_palette_len);
@@ -1471,7 +1467,7 @@ app_context_free (struct app_context *self)
iconv_close (self->term_to_utf8);
input_free (&self->input);
- str_free (&self->paste_buffer);
+ str_free (&self->input_buffer);
}
static void refresh_prompt (struct app_context *ctx);
@@ -9060,7 +9056,6 @@ static void
await_mirc_escape (struct app_context *ctx)
{
ctx->awaiting_mirc_escape = true;
- ctx->char_buf_len = 0;
}
static void
@@ -9887,13 +9882,16 @@ process_mirc_escape (const struct pollfd *fd, struct app_context *ctx)
{
// There's no other way with libedit, as both el_getc() in a function
// handler and CC_ARGHACK would block execution
- if (read (fd->fd, ctx->char_buf + ctx->char_buf_len, 1) != 1)
+ struct str *buf = &ctx->input_buffer;
+ str_ensure_space (buf, 1);
+ if (read (fd->fd, buf->str + buf->len, 1) != 1)
goto error;
+ buf->str[++buf->len] = '\0';
mbstate_t state;
memset (&state, 0, sizeof state);
- size_t len = mbrlen (ctx->char_buf, ++ctx->char_buf_len, &state);
+ size_t len = mbrlen (buf->str, buf->len, &state);
// Illegal sequence
if (len == (size_t) -1)
@@ -9903,9 +9901,9 @@ process_mirc_escape (const struct pollfd *fd, struct app_context *ctx)
if (len == (size_t) -2)
return;
- if (ctx->char_buf_len != 1)
+ if (buf->len != 1)
goto error;
- switch (ctx->char_buf[0])
+ switch (buf->str[0])
{
case 'b': input_insert (&ctx->input, "\x02"); break;
case 'c': input_insert (&ctx->input, "\x03"); break;
@@ -9924,6 +9922,7 @@ process_mirc_escape (const struct pollfd *fd, struct app_context *ctx)
error:
input_ding (&ctx->input);
done:
+ str_reset (buf);
ctx->awaiting_mirc_escape = false;
}
@@ -9932,7 +9931,7 @@ done:
static void
process_bracketed_paste (const struct pollfd *fd, struct app_context *ctx)
{
- struct str *buf = &ctx->paste_buffer;
+ struct str *buf = &ctx->input_buffer;
str_ensure_space (buf, 1);
if (read (fd->fd, buf->str + buf->len, 1) != 1)
goto error;