summaryrefslogtreecommitdiffstats
path: root/input/keycodes.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-30 22:44:56 +0100
committerwm4 <wm4@nowhere>2013-12-30 22:49:51 +0100
commitb0efd3f36a3d2c72a8682d6a2b97925716ff9ba5 (patch)
tree969b3bc0a191126c7d1e883b205041e00f706fef /input/keycodes.c
parent963a3d2c6407f1ec92185406ebf933f8999d7406 (diff)
downloadmpv-b0efd3f36a3d2c72a8682d6a2b97925716ff9ba5.tar.bz2
mpv-b0efd3f36a3d2c72a8682d6a2b97925716ff9ba5.tar.xz
input: use bstr_xappend()
To get rid of mp_append_utf8_buffer().
Diffstat (limited to 'input/keycodes.c')
-rw-r--r--input/keycodes.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/input/keycodes.c b/input/keycodes.c
index a1e466ed09..66cb403c23 100644
--- a/input/keycodes.c
+++ b/input/keycodes.c
@@ -251,39 +251,49 @@ found:
return -1;
}
-char *mp_input_get_key_name(int key, char *ret)
+static void mp_input_append_key_name(bstr *buf, int key)
{
for (int i = 0; modifier_names[i].name; i++) {
if (modifier_names[i].key & key) {
- ret = talloc_asprintf_append_buffer(ret, "%s+",
- modifier_names[i].name);
+ bstr_xappend_asprintf(NULL, buf, "%s+", modifier_names[i].name);
key -= modifier_names[i].key;
}
}
for (int i = 0; key_names[i].name != NULL; i++) {
- if (key_names[i].key == key)
- return talloc_asprintf_append_buffer(ret, "%s", key_names[i].name);
+ if (key_names[i].key == key) {
+ bstr_xappend_asprintf(NULL, buf, "%s", key_names[i].name);
+ return;
+ }
}
// printable, and valid unicode range
- if (key >= 32 && key <= 0x10FFFF)
- return mp_append_utf8_buffer(ret, key);
+ if (key >= 32 && key <= 0x10FFFF) {
+ mp_append_utf8_bstr(NULL, buf, key);
+ return;
+ }
// Print the hex key code
- return talloc_asprintf_append_buffer(ret, "%#-8x", key);
+ bstr_xappend_asprintf(NULL, buf, "%#-8x", key);
+}
+
+char *mp_input_get_key_name(int key)
+{
+ bstr dst = {0};
+ mp_input_append_key_name(&dst, key);
+ return dst.start;
}
char *mp_input_get_key_combo_name(int *keys, int max)
{
- char *ret = talloc_strdup(NULL, "");
+ bstr dst = {0};
while (max > 0) {
- ret = mp_input_get_key_name(*keys, ret);
+ mp_input_append_key_name(&dst, *keys);
if (--max && *++keys)
- ret = talloc_asprintf_append_buffer(ret, "-");
+ bstr_xappend(NULL, &dst, bstr0("-"));
else
break;
}
- return ret;
+ return dst.start;
}
int mp_input_get_keys_from_string(char *name, int max_num_keys,