version 1.124, 2019/04/23 20:36:55 |
version 1.125, 2019/04/26 11:38:51 |
|
|
.exec = cmd_set_option_exec |
.exec = cmd_set_option_exec |
}; |
}; |
|
|
|
const struct cmd_entry cmd_set_hook_entry = { |
|
.name = "set-hook", |
|
.alias = NULL, |
|
|
|
.args = { "agRt:u", 1, 2 }, |
|
.usage = "[-agRu] " CMD_TARGET_SESSION_USAGE " hook [command]", |
|
|
|
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, |
|
|
|
.flags = CMD_AFTERHOOK, |
|
.exec = cmd_set_option_exec |
|
}; |
|
|
static enum cmd_retval |
static enum cmd_retval |
cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) |
cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) |
{ |
{ |
|
|
c = cmd_find_client(item, NULL, 1); |
c = cmd_find_client(item, NULL, 1); |
argument = format_single(item, args->argv[0], c, s, wl, NULL); |
argument = format_single(item, args->argv[0], c, s, wl, NULL); |
|
|
|
if (self->entry == &cmd_set_hook_entry && args_has(args, 'R')) { |
|
notify_hook(item, argument); |
|
return (CMD_RETURN_NORMAL); |
|
} |
|
|
/* Parse option name and index. */ |
/* Parse option name and index. */ |
name = options_match(argument, &idx, &ambiguous); |
name = options_match(argument, &idx, &ambiguous); |
if (name == NULL) { |
if (name == NULL) { |
|
|
options_default(oo, options_table_entry(o)); |
options_default(oo, options_table_entry(o)); |
else |
else |
options_remove(o); |
options_remove(o); |
} else |
} else if (options_array_set(o, idx, NULL, 0, &cause) != 0) { |
options_array_set(o, idx, NULL, 0); |
cmdq_error(item, "%s", cause); |
|
free(cause); |
|
goto fail; |
|
} |
} else if (*name == '@') { |
} else if (*name == '@') { |
if (value == NULL) { |
if (value == NULL) { |
cmdq_error(item, "empty value"); |
cmdq_error(item, "empty value"); |
|
|
if (idx == -1) { |
if (idx == -1) { |
if (!append) |
if (!append) |
options_array_clear(o); |
options_array_clear(o); |
options_array_assign(o, value); |
if (options_array_assign(o, value, &cause) != 0) { |
} else if (options_array_set(o, idx, value, append) != 0) { |
cmdq_error(item, "%s", cause); |
cmdq_error(item, "invalid index: %s", argument); |
free(cause); |
|
goto fail; |
|
} |
|
} else if (options_array_set(o, idx, value, append, |
|
&cause) != 0) { |
|
cmdq_error(item, "%s", cause); |
|
free(cause); |
goto fail; |
goto fail; |
} |
} |
} |
} |
|
|
return (-1); |
return (-1); |
} |
} |
return (0); |
return (0); |
|
case OPTIONS_TABLE_COMMAND: |
|
break; |
} |
} |
return (-1); |
return (-1); |
} |
} |