summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-08-01 23:41:21 +0200
committerwm4 <wm4@nowhere>2012-08-01 23:43:17 +0200
commit9dbe8e1b84febe00563cf28d8983ae6bc28872a5 (patch)
tree61a3841b17f343933ff4d7228dc7c193debb6110 /input
parenta87084c841a2bf35a7cb87a38533fefb070d7f9b (diff)
downloadmpv-9dbe8e1b84febe00563cf28d8983ae6bc28872a5.tar.bz2
mpv-9dbe8e1b84febe00563cf28d8983ae6bc28872a5.tar.xz
input: change bind_keys() to use bstr
This seems rather pointless considering there are still stupid bstrdup0()s left, but maybe this is the right direction.
Diffstat (limited to 'input')
-rw-r--r--input/input.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/input/input.c b/input/input.c
index 6f2e9822cd..b1c7f1264e 100644
--- a/input/input.c
+++ b/input/input.c
@@ -1438,24 +1438,24 @@ static int get_input_from_name(char *name, int *keys)
return 1;
}
-#define SPACE_CHAR " \n\r\t"
-
static void bind_keys(struct input_ctx *ictx, bool builtin,
- const int keys[MP_MAX_KEY_DOWN + 1], char *cmd)
+ const int keys[MP_MAX_KEY_DOWN + 1], bstr command)
{
int i = 0, j;
struct cmd_bind *bind = NULL;
struct cmd_bind_section *bind_section = NULL;
- char *section = NULL, *p;
-
- if (*cmd == '{' && (p = strchr(cmd, '}'))) {
- *p = 0;
- section = ++cmd;
- cmd = ++p;
- // Jump beginning space
- cmd += strspn(cmd, SPACE_CHAR);
+ char *section = NULL;
+
+ if (bstr_startswith0(command, "{")) {
+ int p = bstrchr(command, '}');
+ if (p != -1) {
+ bstr bsection = bstr_strip(bstr_splice(command, 1, p));
+ section = bstrdup0(NULL, bsection);
+ command = bstr_lstrip(bstr_cut(command, p + 1));
+ }
}
bind_section = get_bind_section(ictx, builtin, section);
+ talloc_free(section);
if (bind_section->cmd_binds) {
for (i = 0; bind_section->cmd_binds[i].cmd != NULL; i++) {
@@ -1476,7 +1476,7 @@ static void bind_keys(struct input_ctx *ictx, bool builtin,
bind = &bind_section->cmd_binds[i];
}
talloc_free(bind->cmd);
- bind->cmd = talloc_strdup(bind_section->cmd_binds, cmd);
+ bind->cmd = bstrdup0(bind_section->cmd_binds, command);
memcpy(bind->input, keys, (MP_MAX_KEY_DOWN + 1) * sizeof(int));
}
@@ -1491,7 +1491,7 @@ static int parse_config(struct input_ctx *ictx, bool builtin, bstr data)
continue;
struct bstr command;
// Find the key name starting a line
- struct bstr keyname = bstr_split(line, SPACE_CHAR, &command);
+ struct bstr keyname = bstr_split(line, WHITESPACE, &command);
command = bstr_strip(command);
if (command.len == 0) {
mp_tmsg(MSGT_INPUT, MSGL_ERR,
@@ -1506,10 +1506,8 @@ static int parse_config(struct input_ctx *ictx, bool builtin, bstr data)
continue;
}
talloc_free(name);
- char *cmd = bstrdup0(NULL, command);
- bind_keys(ictx, builtin, keys, cmd);
+ bind_keys(ictx, builtin, keys, command);
n_binds++;
- talloc_free(cmd);
}
return n_binds;