aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-07-15 15:28:09 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-07-15 15:28:09 +0000
commit65a46be822fe290ae721d1dd668f54dcc7a7ec49 (patch)
tree0bc3ded63e67f2ba8dbb0727c2ee8a318a72a9d2
parentinput: comments (diff)
config: change syntax for pipe-command in key binding
The pipe command can contain almost all printable characters. In particular, we can expect it to contain '='. Having the pipe command as part of the key breaks the key/value splitting. Change it so that it is instead an optional initial part of the value, enclosed in '[]'. I.e. instead of pipe-visible:cmd=binding we now need to write pipe-visible=[cmd] binding
-rw-r--r--config.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/config.c b/config.c
index 044266f1..4ed3e2f4 100644
--- a/config.c
+++ b/config.c
@@ -528,11 +528,21 @@ parse_section_key_bindings(
const char *key, const char *value, struct config *conf,
const char *path, unsigned lineno)
{
- const char *pipe_cmd = strchr(key, ':');
- if (pipe_cmd != NULL)
- pipe_cmd++;
+ const char *pipe_cmd = NULL;
+ size_t pipe_len = 0;
- const size_t key_len = pipe_cmd != NULL ? pipe_cmd - key - 1: strlen(key);
+ if (value[0] == '[') {
+ const char *pipe_cmd_end = strrchr(value, ']');
+ if (pipe_cmd_end == NULL) {
+ LOG_ERR("%s:%d: unclosed '['", path, lineno);
+ return false;
+ }
+
+ pipe_cmd = &value[1];
+ pipe_len = pipe_cmd_end - pipe_cmd;
+
+ value = pipe_cmd_end + 1;
+ }
for (enum bind_action_normal action = 0;
action < BIND_ACTION_COUNT;
@@ -541,7 +551,7 @@ parse_section_key_bindings(
if (binding_action_map[action] == NULL)
continue;
- if (strncmp(key, binding_action_map[action], key_len) != 0)
+ if (strcmp(key, binding_action_map[action]) != 0)
continue;
if (strcasecmp(value, "none") == 0) {
@@ -564,14 +574,15 @@ parse_section_key_bindings(
if (it->item.action == action &&
((it->item.pipe_cmd == NULL && pipe_cmd == NULL) ||
(it->item.pipe_cmd != NULL && pipe_cmd != NULL &&
- strcmp(it->item.pipe_cmd, pipe_cmd) == 0)))
+ strncmp(it->item.pipe_cmd, pipe_cmd, pipe_len) == 0)))
{
free(it->item.key);
free(it->item.pipe_cmd);
it->item.key = strdup(value);
- it->item.pipe_cmd = pipe_cmd != NULL ? strdup(pipe_cmd) : NULL;
+ it->item.pipe_cmd = pipe_cmd != NULL
+ ? strndup(pipe_cmd, pipe_len) : NULL;
already_added = true;
break;
}