aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-05-07 07:23:11 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-05-07 07:23:11 +0200
commit85baf5ecec9710d2a4410a38875575da88364aa2 (patch)
tree040d5951f5a7aba52e2dedf5fd8cd5654f1e890d
parent1d7903ae033eae21a5b2a6b13d247f0c56d25a18 (diff)
downloadxK-85baf5ecec9710d2a4410a38875575da88364aa2.tar.gz
xK-85baf5ecec9710d2a4410a38875575da88364aa2.tar.xz
xK-85baf5ecec9710d2a4410a38875575da88364aa2.zip
degesch: little libedit details
-rw-r--r--degesch.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/degesch.c b/degesch.c
index 54f523e..9f17678 100644
--- a/degesch.c
+++ b/degesch.c
@@ -5589,10 +5589,10 @@ on_editline_complete (EditLine *editline, int key)
unsigned char result = CC_REFRESH_BEEP;
// First prepare what Readline would have normally done for us...
- const LineInfo *info = el_line (editline);
- int len = info->lastchar - info->buffer;
- int point = info->cursor - info->buffer;
- char *copy = xstrndup (info->buffer, len);
+ const LineInfo *info_mb = el_line (editline);
+ int len = info_mb->lastchar - info_mb->buffer;
+ int point = info_mb->cursor - info_mb->buffer;
+ char *copy = xstrndup (info_mb->buffer, len);
// XXX: possibly incorrect wrt. shift state encodings
int el_start = point, el_end = point;
@@ -5652,17 +5652,15 @@ on_editline_return (EditLine *editline, int key)
history_w (self->current->history, &ev, H_ENTER, line);
print_debug ("history: %d %ls", ev.num, ev.str);
}
-
- // Convert it to multibyte to reflect the Readline interface
- size_t needed = wcstombs (NULL, line, 0) + 1;
- char converted[needed];
- if (!needed || wcstombs (converted, line, needed) == (size_t) -1)
- print_error ("encoding conversion failed");
- else
- process_input (g_ctx, converted);
-
free (line);
+ // process_input() expects a multibyte string
+ const LineInfo *info_mb = el_line (editline);
+ char copy[info_mb->lastchar - info_mb->buffer + 1];
+ memcpy (copy, info_mb->buffer, sizeof copy - 1);
+ copy[sizeof copy - 1] = '\0';
+ process_input (g_ctx, copy);
+
el_cursor (editline, len - point);
el_wdeletestr (editline, len);
return CC_REFRESH;