diff options
81 files changed, 185 insertions, 185 deletions
diff --git a/cmd-attach-session.c b/cmd-attach-session.c index 59c2b479..be7adb3f 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -29,7 +29,7 @@ int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_attach_session_entry = { "attach-session", "attach", "[-d] " CMD_TARGET_SESSION_USAGE, - CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, CMD_CHFLAG('d'), + CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, "d", cmd_target_init, cmd_target_parse, cmd_attach_session_exec, @@ -58,7 +58,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) return (0); if (ctx->cmdclient == NULL) { - if (data->chflags & CMD_CHFLAG('d')) { + if (cmd_check_flag(data->chflags, 'd')) { /* * Can't use server_write_session in case attaching to * the same session as currently attached to. @@ -89,7 +89,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) return (-1); } - if (data->chflags & CMD_CHFLAG('d')) + if (cmd_check_flag(data->chflags, 'd')) server_write_session(s, MSG_DETACH, NULL, 0); ctx->cmdclient->session = s; diff --git a/cmd-bind-key.c b/cmd-bind-key.c index 041f558d..eba5125b 100644 --- a/cmd-bind-key.c +++ b/cmd-bind-key.c @@ -46,7 +46,7 @@ struct cmd_bind_key_data { const struct cmd_entry cmd_bind_key_entry = { "bind-key", "bind", "[-cnr] [-t key-table] key command [arguments]", - 0, 0, + 0, "", NULL, cmd_bind_key_parse, cmd_bind_key_exec, diff --git a/cmd-break-pane.c b/cmd-break-pane.c index 58a93de2..d465f602 100644 --- a/cmd-break-pane.c +++ b/cmd-break-pane.c @@ -31,7 +31,7 @@ int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_break_pane_entry = { "break-pane", "breakp", CMD_TARGET_PANE_USAGE " [-d]", - 0, CMD_CHFLAG('d'), + 0, "d", cmd_target_init, cmd_target_parse, cmd_break_pane_exec, @@ -74,7 +74,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx) base_idx = options_get_number(&s->options, "base-index"); wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */ - if (!(data->chflags & CMD_CHFLAG('d'))) + if (!cmd_check_flag(data->chflags, 'd')) session_select(s, wl->idx); server_redraw_session(s); diff --git a/cmd-choose-client.c b/cmd-choose-client.c index 0aa66622..cd5ab9ea 100644 --- a/cmd-choose-client.c +++ b/cmd-choose-client.c @@ -34,7 +34,7 @@ void cmd_choose_client_free(void *); const struct cmd_entry cmd_choose_client_entry = { "choose-client", NULL, CMD_TARGET_WINDOW_USAGE " [template]", - CMD_ARG01, 0, + CMD_ARG01, "", cmd_target_init, cmd_target_parse, cmd_choose_client_exec, diff --git a/cmd-choose-session.c b/cmd-choose-session.c index b9c7c258..23228105 100644 --- a/cmd-choose-session.c +++ b/cmd-choose-session.c @@ -34,7 +34,7 @@ void cmd_choose_session_free(void *); const struct cmd_entry cmd_choose_session_entry = { "choose-session", NULL, CMD_TARGET_WINDOW_USAGE " [template]", - CMD_ARG01, 0, + CMD_ARG01, "", cmd_target_init, cmd_target_parse, cmd_choose_session_exec, diff --git a/cmd-choose-window.c b/cmd-choose-window.c index 9d6cd932..a1540f1d 100644 --- a/cmd-choose-window.c +++ b/cmd-choose-window.c @@ -34,7 +34,7 @@ void cmd_choose_window_free(void *); const struct cmd_entry cmd_choose_window_entry = { "choose-window", NULL, CMD_TARGET_WINDOW_USAGE " [template]", - CMD_ARG01, 0, + CMD_ARG01, "", cmd_target_init, cmd_target_parse, cmd_choose_window_exec, diff --git a/cmd-clear-history.c b/cmd-clear-history.c index a9271346..9241485a 100644 --- a/cmd-clear-history.c +++ b/cmd-clear-history.c @@ -29,7 +29,7 @@ int cmd_clear_history_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_clear_history_entry = { "clear-history", "clearhist", CMD_TARGET_PANE_USAGE, - 0, 0, + 0, "", cmd_target_init, cmd_target_parse, cmd_clear_history_exec, diff --git a/cmd-clock-mode.c b/cmd-clock-mode.c index b1f135a6..4df934f7 100644 --- a/cmd-clock-mode.c +++ b/cmd-clock-mode.c @@ -29,7 +29,7 @@ int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_clock_mode_entry = { "clock-mode", NULL, CMD_TARGET_PANE_USAGE, - 0, 0, + 0, "", cmd_target_init, cmd_target_parse, cmd_clock_mode_exec, diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index bcbde064..e3774256 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -39,7 +39,7 @@ void cmd_command_prompt_cfree(void *); const struct cmd_entry cmd_command_prompt_entry = { "command-prompt", NULL, CMD_TARGET_CLIENT_USAGE " [-p prompts] [template]", - 0, 0, + 0, "", cmd_command_prompt_init, cmd_command_prompt_parse, cmd_command_prompt_exec, diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index d0a2196a..cdde81ac 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -34,7 +34,7 @@ void cmd_confirm_before_free(void *); const struct cmd_entry cmd_confirm_before_entry = { "confirm-before", "confirm", CMD_TARGET_CLIENT_USAGE " command", - CMD_ARG1, 0, + CMD_ARG1, "", cmd_confirm_before_init, cmd_target_parse, cmd_confirm_before_exec, diff --git a/cmd-copy-buffer.c b/cmd-copy-buffer.c index 98166c4b..3a6a441e 100644 --- a/cmd-copy-buffer.c +++ b/cmd-copy-buffer.c @@ -43,7 +43,7 @@ struct cmd_copy_buffer_data { const struct cmd_entry cmd_copy_buffer_entry = { "copy-buffer", "copyb", "[-a src-index] [-b dst-index] [-s src-session] [-t dst-session]", - 0, 0, + 0, "", cmd_copy_buffer_init, cmd_copy_buffer_parse, cmd_copy_buffer_exec, diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c index fda19efb..48cdd656 100644 --- a/cmd-copy-mode.c +++ b/cmd-copy-mode.c @@ -30,7 +30,7 @@ int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_copy_mode_entry = { "copy-mode", NULL, "[-u] " CMD_TARGET_PANE_USAGE, - 0, CMD_CHFLAG('u'), + 0, "u", cmd_copy_mode_init, cmd_target_parse, cmd_copy_mode_exec, @@ -48,7 +48,7 @@ cmd_copy_mode_init(struct cmd *self, int key) switch (key) { case KEYC_PPAGE: - data->chflags |= CMD_CHFLAG('u'); + cmd_set_flag(&data->chflags, 'u'); break; } } @@ -63,7 +63,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx) return (-1); window_pane_set_mode(wp, &window_copy_mode); - if (wp->mode == &window_copy_mode && data->chflags & CMD_CHFLAG('u')) + if (wp->mode == &window_copy_mode && cmd_check_flag(data->chflags, 'u')) window_copy_pageup(wp); return (0); diff --git a/cmd-delete-buffer.c b/cmd-delete-buffer.c index b193438c..1a5b6d82 100644 --- a/cmd-delete-buffer.c +++ b/cmd-delete-buffer.c @@ -31,7 +31,7 @@ int cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_delete_buffer_entry = { "delete-buffer", "deleteb", CMD_BUFFER_SESSION_USAGE, - 0, 0, + 0, "", cmd_buffer_init, cmd_buffer_parse, cmd_delete_buffer_exec, diff --git a/cmd-detach-client.c b/cmd-detach-client.c index dd480226..4903281f 100644 --- a/cmd-detach-client.c +++ b/cmd-detach-client.c @@ -29,7 +29,7 @@ int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_detach_client_entry = { "detach-client", "detach", CMD_TARGET_CLIENT_USAGE, - 0, 0, + 0, "", cmd_target_init, cmd_target_parse, cmd_detach_client_exec, diff --git a/cmd-display-message.c b/cmd-display-message.c index 71421ea2..1ff5718b 100644 --- a/cmd-display-message.c +++ b/cmd-display-message.c @@ -31,7 +31,7 @@ int cmd_display_message_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_display_message_entry = { "display-message", "display", CMD_TARGET_CLIENT_USAGE " [message]", - CMD_ARG01, 0, + CMD_ARG01, "", cmd_target_init, cmd_target_parse, cmd_display_message_exec, diff --git a/cmd-display-panes.c b/cmd-display-panes.c index 141e3436..42ecbb9b 100644 --- a/cmd-display-panes.c +++ b/cmd-display-panes.c @@ -29,7 +29,7 @@ int cmd_display_panes_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_display_panes_entry = { "display-panes", "displayp", CMD_TARGET_CLIENT_USAGE, - 0, 0, + 0, "", cmd_target_init, cmd_target_parse, cmd_display_panes_exec, diff --git a/cmd-down-pane.c b/cmd-down-pane.c index 242c6ac3..a0f771eb 100644 --- a/cmd-down-pane.c +++ b/cmd-down-pane.c @@ -29,7 +29,7 @@ int cmd_down_pane_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_down_pane_entry = { "down-pane", "downp", CMD_TARGET_WINDOW_USAGE, - 0, 0, + 0, "", cmd_target_init, cmd_target_parse, cmd_down_pane_exec, diff --git a/cmd-find-window.c b/cmd-find-window.c index 0a1c38da..49e29337 100644 --- a/cmd-find-window.c +++ b/cmd-find-window.c @@ -34,7 +34,7 @@ void cmd_find_window_callback(void *, int); const struct cmd_entry cmd_find_window_entry = { "find-window", "findw", CMD_TARGET_WINDOW_USAGE " match-string", - CMD_ARG1, 0, + CMD_ARG1, "", cmd_target_init, cmd_target_parse, cmd_find_window_exec, diff --git a/cmd-generic.c b/cmd-generic.c index 89dc2e25..59d9bbb7 100644 --- a/cmd-generic.c +++ b/cmd-generic.c @@ -23,8 +23,8 @@ #include "tmux.h" -int cmd_getopt(int, char **, const char *, uint64_t); -int cmd_flags(int, uint64_t, uint64_t *); +int cmd_getopt(int, char **, const char *, const char *); +int cmd_parse_flags(int, const char *, uint64_t *); size_t cmd_print_flags(char *, size_t, size_t, uint64_t); int cmd_fill_argument(int, char **, char **, int, char **); @@ -36,51 +36,53 @@ cmd_prarg(char *buf, size_t len, const char *prefix, char *arg) return (xsnprintf(buf, len, "%s%s", prefix, arg)); } -/* Prepend flags from chflags onto flagstr and call getopt. */ +/* Append two flag strings together and call getopt. */ int -cmd_getopt(int argc, char **argv, const char *flagstr, uint64_t chflags) +cmd_getopt(int argc, char **argv, const char *flagstr, const char *chflagstr) { - u_char ch; - char buf[128]; - size_t len, off; - - *buf = '\0'; + char tmp[BUFSIZ]; - len = sizeof buf; - off = 0; + if (strlcpy(tmp, flagstr, sizeof tmp) >= sizeof tmp) + fatalx("strlcpy overflow"); + if (strlcat(tmp, chflagstr, sizeof tmp) >= sizeof tmp) + fatalx("strlcat overflow"); + return (getopt(argc, argv, tmp)); +} - for (ch = 0; ch < 26; ch++) { - if (chflags & CMD_CHFLAG('a' + ch)) - off += xsnprintf(buf + off, len - off, "%c", 'a' + ch); - if (chflags & CMD_CHFLAG('A' + ch)) - off += xsnprintf(buf + off, len - off, "%c", 'A' + ch); - } - - strlcat(buf, flagstr, sizeof buf); +/* Return if flag character is set. */ +int +cmd_check_flag(uint64_t chflags, int flag) +{ + if (flag >= 'A' && flag <= 'Z') + flag = 26 + flag - 'A'; + else if (flag >= 'a' && flag <= 'z') + flag = flag - 'a'; + else + return (0); + return ((chflags & (1ULL << flag)) != 0); +} - return (getopt(argc, argv, buf)); +/* Set flag character. */ +void +cmd_set_flag(uint64_t *chflags, int flag) +{ + if (flag >= 'A' && flag <= 'Z') + flag = 26 + flag - 'A'; + else if (flag >= 'a' && flag <= 'z') + flag = flag - 'a'; + else + return; + (*chflags) |= (1ULL << flag); } -/* - * If this option is expected (in ichflags), set it in ochflags, otherwise - * return -1. - */ +/* If this option is expected, set it in chflags, otherwise return -1. */ int -cmd_flags(int opt, uint64_t ichflags, uint64_t *ochflags) +cmd_parse_flags(int opt, const char *chflagstr, uint64_t *chflags) { - u_char ch; - - for (ch = 0; ch < 26; ch++) { - if (opt == 'a' + ch && ichflags & CMD_CHFLAG(opt)) { - (*ochflags) |= CMD_CHFLAG(opt); - return (0); - } - if (opt == 'A' + ch && ichflags & CMD_CHFLAG(opt)) { - (*ochflags) |= CMD_CHFLAG(opt); - return (0); - } - } - return (-1); + if (strchr(chflagstr, opt) == NULL) + return (-1); + cmd_set_flag(chflags, opt); + return (0); } /* Print the flags supported in chflags. */ @@ -95,9 +97,9 @@ cmd_print_flags(char *buf, size_t len, size_t off, uint64_t chflags) off += xsnprintf(buf + off, len - off, " -"); for (ch = 0; ch < 26; ch++) { - if (chflags & CMD_CHFLAG('a' + ch)) + if (cmd_check_flag(chflags, 'a' + ch)) off += xsnprintf(buf + off, len - off, "%c", 'a' + ch); - if (chflags & CMD_CHFLAG('A' + ch)) + if (cmd_check_flag(chflags, 'A' + ch)) off += xsnprintf(buf + off, len - off, "%c", 'A' + ch); } return (off - boff); @@ -170,7 +172,7 @@ cmd_target_parse(struct cmd *self, int argc, char **argv, char **cause) data = self->data; while ((opt = cmd_getopt(argc, argv, "t:", entry->chflags)) != -1) { - if (cmd_flag |