Instead of combined flags for -c, -s, -t, split into different sets

using an enum and simplify the parsing code.
This commit is contained in:
nicm 2015-12-14 00:31:54 +00:00
parent ecfeee2e82
commit a3129fd4e8
53 changed files with 353 additions and 328 deletions

View File

@ -39,7 +39,9 @@ const struct cmd_entry cmd_attach_session_entry = {
.args = { "c:dErt:", 0, 0 },
.usage = "[-dEr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
.flags = CMD_STARTSERVER|CMD_SESSION_T|CMD_PANE_T|CMD_PREFERUNATTACHED,
.tflag = CMD_SESSION_WITHPANE,
.flags = CMD_STARTSERVER,
.exec = cmd_attach_session_exec
};

View File

@ -37,7 +37,10 @@ const struct cmd_entry cmd_break_pane_entry = {
.args = { "dPF:s:t:", 0, 0 },
.usage = "[-dP] [-F format] " CMD_SRCDST_PANE_USAGE,
.flags = CMD_PANE_S|CMD_INDEX_T,
.sflag = CMD_PANE,
.tflag = CMD_WINDOW_INDEX,
.flags = 0,
.exec = cmd_break_pane_exec
};

View File

@ -43,7 +43,9 @@ const struct cmd_entry cmd_capture_pane_entry = {
.usage = "[-aCeJpPq] " CMD_BUFFER_USAGE " [-E end-line] "
"[-S start-line]" CMD_TARGET_PANE_USAGE,
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_capture_pane_exec
};

View File

@ -39,7 +39,9 @@ const struct cmd_entry cmd_choose_buffer_entry = {
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_choose_buffer_exec
};

View File

@ -44,7 +44,9 @@ const struct cmd_entry cmd_choose_client_entry = {
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_choose_client_exec
};

View File

@ -51,7 +51,9 @@ const struct cmd_entry cmd_choose_tree_entry = {
.usage = "[-suw] [-b session-template] [-c window template] "
"[-S format] [-W format] " CMD_TARGET_WINDOW_USAGE,
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_choose_tree_exec
};
@ -60,10 +62,11 @@ const struct cmd_entry cmd_choose_session_entry = {
.alias = NULL,
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_choose_tree_exec
};
@ -74,7 +77,9 @@ const struct cmd_entry cmd_choose_window_entry = {
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE "[-F format] [template]",
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_choose_tree_exec
};

View File

@ -33,7 +33,9 @@ const struct cmd_entry cmd_clear_history_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_PANE_USAGE,
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_clear_history_exec
};

View File

@ -42,7 +42,9 @@ const struct cmd_entry cmd_command_prompt_entry = {
.usage = "[-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
"[template]",
.flags = CMD_CLIENT_T,
.tflag = CMD_CLIENT,
.flags = 0,
.exec = cmd_command_prompt_exec
};

View File

@ -40,7 +40,9 @@ const struct cmd_entry cmd_confirm_before_entry = {
.args = { "p:t:", 1, 1 },
.usage = "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
.flags = CMD_CLIENT_T,
.tflag = CMD_CLIENT,
.flags = 0,
.exec = cmd_confirm_before_exec
};

View File

@ -33,7 +33,9 @@ const struct cmd_entry cmd_copy_mode_entry = {
.args = { "Met:u", 0, 0 },
.usage = "[-Mu] " CMD_TARGET_PANE_USAGE,
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_copy_mode_exec
};

View File

@ -35,7 +35,10 @@ const struct cmd_entry cmd_detach_client_entry = {
.args = { "as:t:P", 0, 0 },
.usage = "[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
.flags = CMD_READONLY|CMD_CLIENT_T|CMD_SESSION_S,
.sflag = CMD_SESSION,
.tflag = CMD_CLIENT,
.flags = CMD_READONLY,
.exec = cmd_detach_client_exec
};
@ -46,7 +49,9 @@ const struct cmd_entry cmd_suspend_client_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_CLIENT_USAGE,
.flags = CMD_CLIENT_T,
.tflag = CMD_CLIENT,
.flags = 0,
.exec = cmd_detach_client_exec
};

View File

@ -42,7 +42,10 @@ const struct cmd_entry cmd_display_message_entry = {
.usage = "[-p] [-c target-client] [-F format] "
CMD_TARGET_PANE_USAGE " [message]",
.flags = CMD_CLIENT_C|CMD_PANE_T|CMD_CLIENT_CANFAIL,
.cflag = CMD_CLIENT_CANFAIL,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_display_message_exec
};

View File

@ -33,7 +33,9 @@ const struct cmd_entry cmd_display_panes_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_CLIENT_USAGE,
.flags = CMD_CLIENT_T,
.tflag = CMD_CLIENT,
.flags = 0,
.exec = cmd_display_panes_exec
};

View File

@ -54,7 +54,9 @@ const struct cmd_entry cmd_find_window_entry = {
.args = { "F:CNt:T", 1, 4 },
.usage = "[-CNT] [-F format] " CMD_TARGET_WINDOW_USAGE " match-string",
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_find_window_exec
};

View File

@ -43,7 +43,9 @@ const struct cmd_entry cmd_if_shell_entry = {
.usage = "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command "
"[command]",
.flags = CMD_PANE_T|CMD_CANFAIL,
.tflag = CMD_PANE_CANFAIL,
.flags = 0,
.exec = cmd_if_shell_exec
};

View File

@ -40,7 +40,10 @@ const struct cmd_entry cmd_join_pane_entry = {
.args = { "bdhvp:l:s:t:", 0, 0 },
.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
.flags = CMD_PANE_MARKED_S|CMD_PANE_T,
.sflag = CMD_PANE_MARKED,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_join_pane_exec
};
@ -51,7 +54,10 @@ const struct cmd_entry cmd_move_pane_entry = {
.args = { "bdhvp:l:s:t:", 0, 0 },
.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
.flags = CMD_PANE_S|CMD_PANE_T,
.sflag = CMD_PANE,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_join_pane_exec
};

View File

@ -35,7 +35,9 @@ const struct cmd_entry cmd_kill_pane_entry = {
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_PANE_USAGE,
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_kill_pane_exec
};

View File

@ -36,7 +36,9 @@ const struct cmd_entry cmd_kill_session_entry = {
.args = { "aCt:", 0, 0 },
.usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
.flags = CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = 0,
.exec = cmd_kill_session_exec
};

View File

@ -33,7 +33,9 @@ const struct cmd_entry cmd_kill_window_entry = {
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_WINDOW_USAGE,
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_kill_window_exec
};
@ -44,7 +46,9 @@ const struct cmd_entry cmd_unlink_window_entry = {
.args = { "kt:", 0, 0 },
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE,
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_kill_window_exec
};

View File

@ -42,7 +42,9 @@ const struct cmd_entry cmd_list_clients_entry = {
.args = { "F:t:", 0, 0 },
.usage = "[-F format] " CMD_TARGET_SESSION_USAGE,
.flags = CMD_READONLY|CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = CMD_READONLY,
.exec = cmd_list_clients_exec
};

View File

@ -41,7 +41,9 @@ const struct cmd_entry cmd_list_panes_entry = {
.args = { "asF:t:", 0, 0 },
.usage = "[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_list_panes_exec
};

View File

@ -52,7 +52,9 @@ const struct cmd_entry cmd_list_windows_entry = {
.args = { "F:at:", 0, 0 },
.usage = "[-a] [-F format] " CMD_TARGET_SESSION_USAGE,
.flags = CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = 0,
.exec = cmd_list_windows_exec
};

View File

@ -44,7 +44,9 @@ const struct cmd_entry cmd_lock_session_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_SESSION_USAGE,
.flags = CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = 0,
.exec = cmd_lock_server_exec
};
@ -55,7 +57,9 @@ const struct cmd_entry cmd_lock_client_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_CLIENT_USAGE,
.flags = CMD_CLIENT_T,
.tflag = CMD_CLIENT,
.flags = 0,
.exec = cmd_lock_server_exec
};

View File

@ -35,7 +35,10 @@ const struct cmd_entry cmd_move_window_entry = {
.args = { "adkrs:t:", 0, 0 },
.usage = "[-dkr] " CMD_SRCDST_WINDOW_USAGE,
.flags = CMD_WINDOW_S|CMD_MOVEW_R|CMD_INDEX_T,
.sflag = CMD_WINDOW,
.tflag = CMD_MOVEW_R,
.flags = 0,
.exec = cmd_move_window_exec
};
@ -46,7 +49,10 @@ const struct cmd_entry cmd_link_window_entry = {
.args = { "adks:t:", 0, 0 },
.usage = "[-dk] " CMD_SRCDST_WINDOW_USAGE,
.flags = CMD_WINDOW_S|CMD_INDEX_T,
.sflag = CMD_WINDOW,
.tflag = CMD_WINDOW_INDEX,
.flags = 0,
.exec = cmd_move_window_exec
};

View File

@ -44,7 +44,9 @@ const struct cmd_entry cmd_new_session_entry = {
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
"[-y height] [command]",
.flags = CMD_STARTSERVER|CMD_CANFAIL|CMD_SESSION_T,
.tflag = CMD_SESSION_CANFAIL,
.flags = CMD_STARTSERVER,
.exec = cmd_new_session_exec
};
@ -55,7 +57,9 @@ const struct cmd_entry cmd_has_session_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_SESSION_USAGE,
.flags = CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = 0,
.exec = cmd_new_session_exec
};

View File

@ -42,7 +42,9 @@ const struct cmd_entry cmd_new_window_entry = {
.usage = "[-adkP] [-c start-directory] [-F format] [-n window-name] "
CMD_TARGET_WINDOW_USAGE " [command]",
.flags = CMD_INDEX_T,
.tflag = CMD_WINDOW_INDEX,
.flags = 0,
.exec = cmd_new_window_exec
};

View File

@ -41,7 +41,9 @@ const struct cmd_entry cmd_paste_buffer_entry = {
.usage = "[-dpr] [-s separator] " CMD_BUFFER_USAGE " "
CMD_TARGET_PANE_USAGE,
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_paste_buffer_exec
};

View File

@ -44,7 +44,9 @@ const struct cmd_entry cmd_pipe_pane_entry = {
.args = { "ot:", 0, 1 },
.usage = "[-o] " CMD_TARGET_PANE_USAGE " [command]",
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_pipe_pane_exec
};

View File

@ -33,7 +33,9 @@ const struct cmd_entry cmd_refresh_client_entry = {
.args = { "C:St:", 0, 0 },
.usage = "[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
.flags = CMD_CLIENT_T,
.tflag = CMD_CLIENT,
.flags = 0,
.exec = cmd_refresh_client_exec
};

View File

@ -35,7 +35,9 @@ const struct cmd_entry cmd_rename_session_entry = {
.args = { "t:", 1, 1 },
.usage = CMD_TARGET_SESSION_USAGE " new-name",
.flags = CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = 0,
.exec = cmd_rename_session_exec
};

View File

@ -35,7 +35,9 @@ const struct cmd_entry cmd_rename_window_entry = {
.args = { "t:", 1, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " new-name",
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_rename_window_exec
};

View File

@ -38,7 +38,9 @@ const struct cmd_entry cmd_resize_pane_entry = {
.usage = "[-DLMRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
"[adjustment]",
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_resize_pane_exec
};

View File

@ -37,7 +37,9 @@ const struct cmd_entry cmd_respawn_pane_entry = {
.args = { "kt:", 0, -1 },
.usage = "[-k] " CMD_TARGET_PANE_USAGE " [command]",
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_respawn_pane_exec
};

View File

@ -36,7 +36,9 @@ const struct cmd_entry cmd_respawn_window_entry = {
.args = { "kt:", 0, -1 },
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_respawn_window_exec
};

View File

@ -33,7 +33,9 @@ const struct cmd_entry cmd_rotate_window_entry = {
.args = { "Dt:U", 0, 0 },
.usage = "[-DU] " CMD_TARGET_WINDOW_USAGE,
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_rotate_window_exec
};

View File

@ -42,7 +42,9 @@ const struct cmd_entry cmd_run_shell_entry = {
.args = { "bt:", 1, 1 },
.usage = "[-b] " CMD_TARGET_PANE_USAGE " shell-command",
.flags = CMD_PANE_T|CMD_CANFAIL,
.tflag = CMD_PANE_CANFAIL,
.flags = 0,
.exec = cmd_run_shell_exec
};

View File

@ -35,7 +35,9 @@ const struct cmd_entry cmd_select_layout_entry = {
.args = { "nopt:", 0, 1 },
.usage = "[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_select_layout_exec
};
@ -46,7 +48,9 @@ const struct cmd_entry cmd_next_layout_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_WINDOW_USAGE,
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_select_layout_exec
};
@ -57,7 +61,9 @@ const struct cmd_entry cmd_previous_layout_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_WINDOW_USAGE,
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_select_layout_exec
};

View File

@ -33,7 +33,9 @@ const struct cmd_entry cmd_select_pane_entry = {
.args = { "DdegLlMmP:Rt:U", 0, 0 },
.usage = "[-DdegLlMmRU] [-P style] " CMD_TARGET_PANE_USAGE,
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_select_pane_exec
};
@ -44,7 +46,9 @@ const struct cmd_entry cmd_last_pane_entry = {
.args = { "det:", 0, 0 },
.usage = "[-de] " CMD_TARGET_WINDOW_USAGE,
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_select_pane_exec
};

View File

@ -35,7 +35,9 @@ const struct cmd_entry cmd_select_window_entry = {
.args = { "lnpTt:", 0, 0 },
.usage = "[-lnpT] " CMD_TARGET_WINDOW_USAGE,
.flags = CMD_WINDOW_T,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_select_window_exec
};
@ -46,7 +48,9 @@ const struct cmd_entry cmd_next_window_entry = {
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
.flags = CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = 0,
.exec = cmd_select_window_exec
};
@ -57,7 +61,9 @@ const struct cmd_entry cmd_previous_window_entry = {
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
.flags = CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = 0,
.exec = cmd_select_window_exec
};
@ -68,7 +74,9 @@ const struct cmd_entry cmd_last_window_entry = {
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_SESSION_USAGE,
.flags = CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = 0,
.exec = cmd_select_window_exec
};

View File

@ -36,7 +36,9 @@ const struct cmd_entry cmd_send_keys_entry = {
.args = { "lRMt:", 0, -1 },
.usage = "[-lRM] " CMD_TARGET_PANE_USAGE " key ...",
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_send_keys_exec
};
@ -47,7 +49,9 @@ const struct cmd_entry cmd_send_prefix_entry = {
.args = { "2t:", 0, 0 },
.usage = "[-2] " CMD_TARGET_PANE_USAGE,
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_send_keys_exec
};

View File

@ -36,7 +36,9 @@ const struct cmd_entry cmd_set_environment_entry = {
.args = { "grt:u", 1, 2 },
.usage = "[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
.flags = CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = 0,
.exec = cmd_set_environment_exec
};

View File

@ -36,7 +36,9 @@ const struct cmd_entry cmd_set_hook_entry = {
.args = { "gt:u", 1, 2 },
.usage = "[-gu] " CMD_TARGET_SESSION_USAGE " hook-name [command]",
.flags = CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = 0,
.exec = cmd_set_hook_exec
};
@ -47,7 +49,9 @@ const struct cmd_entry cmd_show_hooks_entry = {
.args = { "gt:", 0, 1 },
.usage = "[-g] " CMD_TARGET_SESSION_USAGE,
.flags = CMD_SESSION_T,
.tflag = CMD_SESSION,
.flags = 0,
.exec = cmd_set_hook_exec
};

View File

@ -71,7 +71,9 @@ const struct cmd_entry cmd_set_option_entry = {
.args = { "agoqst:uw", 1, 2 },
.usage = "[-agosquw] [-t target-window] option [value]",
.flags = CMD_WINDOW_T|CMD_CANFAIL,
.tflag = CMD_WINDOW_CANFAIL,
.flags = 0,
.exec = cmd_set_option_exec
};
@ -82,7 +84,9 @@ const struct cmd_entry cmd_set_window_option_entry = {
.args = { "agoqt:u", 1, 2 },
.usage = "[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
.flags = CMD_WINDOW_T|CMD_CANFAIL,
.tflag = CMD_WINDOW_CANFAIL,
.flags = 0,
.exec = cmd_set_option_exec
};

View File

@ -40,7 +40,9 @@ const struct cmd_entry cmd_show_environment_entry = {
.args = { "gst:", 0, 1 },
.usage = "[-gs] " CMD_TARGET_SESSION_USAGE " [name]",
.flags = CMD_SESSION_T|CMD_CANFAIL,
.tflag = CMD_SESSION_CANFAIL,
.flags = 0,
.exec = cmd_show_environment_exec
};

View File

@ -38,7 +38,9 @@ const struct cmd_entry cmd_show_messages_entry = {
.args = { "JTt:", 0, 0 },
.usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
.flags = CMD_CLIENT_T,
.tflag = CMD_CLIENT,
.flags = 0,
.exec = cmd_show_messages_exec
};

View File

@ -41,7 +41,9 @@ const struct cmd_entry cmd_show_options_entry = {
.args = { "gqst:vw", 0, 1 },
.usage = "[-gqsvw] [-t target-session|target-window] [option]",
.flags = CMD_WINDOW_T|CMD_CANFAIL,
.tflag = CMD_WINDOW_CANFAIL,
.flags = 0,
.exec = cmd_show_options_exec
};
@ -52,7 +54,9 @@ const struct cmd_entry cmd_show_window_options_entry = {
.args = { "gvt:", 0, 1 },
.usage = "[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
.flags = CMD_WINDOW_T|CMD_CANFAIL,
.tflag = CMD_WINDOW_CANFAIL,
.flags = 0,
.exec = cmd_show_options_exec
};

View File

@ -43,7 +43,9 @@ const struct cmd_entry cmd_split_window_entry = {
.usage = "[-bdhvP] [-c start-directory] [-F format] "
"[-p percentage|-l size] " CMD_TARGET_PANE_USAGE " [command]",
.flags = CMD_PANE_T,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_split_window_exec
};

View File

@ -35,14 +35,16 @@ const struct cmd_entry cmd_swap_pane_entry = {
.args = { "dDs:t:U", 0, 0 },
.usage = "[-dDU] " CMD_SRCDST_PANE_USAGE,
.flags = CMD_PANE_MARKED_S|CMD_PANE_T,
.sflag = CMD_PANE_MARKED,
.tflag = CMD_PANE,
.flags = 0,
.exec = cmd_swap_pane_exec
};
enum cmd_retval
cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *src_wl, *dst_wl;
struct window *src_w, *dst_w;
struct window_pane *tmp_wp, *src_wp, *dst_wp;
@ -52,22 +54,23 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
dst_wl = cmdq->state.tflag.wl;
dst_w = dst_wl->window;
dst_wp = cmdq->state.tflag.wp;
src_wp = cmdq->state.sflag.wp;
src_wl = cmdq->state.sflag.wl;
src_w = src_wl->window;
src_wp = cmdq->state.sflag.wp;
server_unzoom_window(dst_w);
if (!args_has(args, 's')) {
if (args_has(self->args, 'D')) {
src_wl = dst_wl;
src_w = dst_w;
if (args_has(self->args, 'D')) {
src_wp = TAILQ_NEXT(dst_wp, entry);
if (src_wp == NULL)
src_wp = TAILQ_FIRST(&dst_w->panes);
} else if (args_has(self->args, 'U')) {
src_wp = TAILQ_PREV(dst_wp, window_panes, entry);
if (src_wp == NULL)
src_wp = TAILQ_LAST(&dst_w->panes, window_panes);
}
src_wp = TAILQ_NEXT(dst_wp, entry);
if (src_wp == NULL)
src_wp = TAILQ_FIRST(&dst_w->panes);
} else if (args_has(self->args, 'U')) {
src_wl = dst_wl;
src_w = dst_w;
src_wp = TAILQ_PREV(dst_wp, window_panes, entry);
if (src_wp == NULL)
src_wp = TAILQ_LAST(&dst_w->panes, window_panes);
}
server_unzoom_window(src_w);

View File

@ -35,7 +35,10 @@ const struct cmd_entry cmd_swap_window_entry = {
.args = { "ds:t:", 0, 0 },
.usage = "[-d] " CMD_SRCDST_WINDOW_USAGE,
.flags = CMD_WINDOW_MARKED_S|CMD_WINDOW_MARKED_T,
.sflag = CMD_WINDOW_MARKED,
.tflag = CMD_WINDOW,
.flags = 0,
.exec = cmd_swap_window_exec
};

View File

@ -37,8 +37,10 @@ const struct cmd_entry cmd_switch_client_entry = {
.usage = "[-Elnpr] [-c target-client] [-t target-session] "
"[-T key-table]",
.flags = CMD_READONLY|CMD_CLIENT_C|CMD_PANE_T|CMD_SESSION_T|
CMD_PREFERUNATTACHED,
.cflag = CMD_CLIENT,
.tflag = CMD_SESSION_WITHPANE,
.flags = CMD_READONLY,
.exec = cmd_switch_client_exec
};

319
cmd.c
View File

@ -207,10 +207,6 @@ const struct cmd_entry *cmd_table[] = {
NULL
};
static void cmd_clear_state(struct cmd_state *);
static struct client *cmd_get_state_client(struct cmd_q *, int);
static int cmd_set_state_flag(struct cmd *, struct cmd_q *, char);
int
cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
{
@ -409,252 +405,131 @@ cmd_clear_state(struct cmd_state *state)
}
static int
cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
cmd_prepare_state_flag(struct cmd_find_state *fs, enum cmd_entry_flag flag,
const char *target, struct cmd_q *cmdq)
{
struct cmd_state *state = &cmdq->state;
struct cmd_find_state *fsf = NULL;
const char *flag;
int flags = cmd->entry->flags, everything = 0;
int allflags = 0, targetflags, error;
struct session *s;
struct window *w;
struct winlink *wl;
struct window_pane *wp;
int targetflags, error;
/* Set up state for either -t or -s. */
if (c == 't') {
fsf = &cmdq->state.tflag;
allflags = CMD_ALL_T;
} else if (c == 's') {
fsf = &cmdq->state.sflag;
allflags = CMD_ALL_S;
if (flag == CMD_SESSION_WITHPANE) {
if (target != NULL && target[strcspn(target, ":.")] != '\0')
flag = CMD_PANE;
else
flag = CMD_SESSION;
}
/*
* If the command wants something and no argument is present, use the
* base command instead.
*/
flag = args_get(cmd->args, c);
if (flag == NULL) {
if ((flags & allflags) == 0)
return (0); /* doesn't care about flag */
cmd = cmdq->cmd;
everything = 1;
flag = args_get(cmd->args, c);
}
/*
* If no flag and the current command is allowed to fail, just skip to
* fill in as much we can, otherwise continue and fail later if needed.
*/
if (flag == NULL && (flags & CMD_CANFAIL))
goto complete_everything;
/* Fill in state using command (current or base) flags. */
if (flags & CMD_PREFERUNATTACHED)
targetflags = CMD_FIND_PREFER_UNATTACHED;
else
targetflags = 0;
switch (cmd->entry->flags & allflags) {
case 0:
break;
case CMD_SESSION_T|CMD_PANE_T:
case CMD_SESSION_S|CMD_PANE_S:
if (flag != NULL && flag[strcspn(flag, ":.")] != '\0') {
error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_PANE,
targetflags);
if (error != 0)
return (-1);
} else {
error = cmd_find_target(fsf, cmdq, flag,
CMD_FIND_SESSION, targetflags);
if (error != 0)
return (-1);
if (flag == NULL) {
fsf->wl = fsf->s->curw;
fsf->wp = fsf->s->curw->window->active;
} else {
s = fsf->s;
if ((w = window_find_by_id_str(flag)) != NULL)
wp = w->active;
else {
wp = window_pane_find_by_id_str(flag);
if (wp != NULL)
w = wp->window;
}
wl = winlink_find_by_window(&s->windows, w);
if (wl != NULL) {
fsf->wl = wl;
fsf->wp = wp;
}
}
}
break;
case CMD_MOVEW_R|CMD_INDEX_T:
case CMD_MOVEW_R|CMD_INDEX_S:
error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_SESSION,
targetflags|CMD_FIND_QUIET);
if (error != 0) {
error = cmd_find_target(fsf, cmdq, flag,
CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX);
if (error != 0)
return (-1);
}
break;
case CMD_SESSION_T:
case CMD_SESSION_S:
error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_SESSION,
targetflags);
if (error != 0)
return (-1);
break;
case CMD_WINDOW_MARKED_T:
case CMD_WINDOW_MARKED_S:
targetflags |= CMD_FIND_DEFAULT_MARKED;
/* FALLTHROUGH */
case CMD_WINDOW_T:
case CMD_WINDOW_S:
error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_WINDOW,
targetflags);
if (error != 0)
return (-1);
break;
case CMD_PANE_MARKED_T:
case CMD_PANE_MARKED_S:
targetflags |= CMD_FIND_DEFAULT_MARKED;
/* FALLTHROUGH */
case CMD_PANE_T:
case CMD_PANE_S:
error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_PANE,
targetflags);
if (error != 0)
return (-1);
break;
case CMD_INDEX_T:
case CMD_INDEX_S:
error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_WINDOW,
CMD_FIND_WINDOW_INDEX);
if (error != 0)
return (-1);
break;
default:
fatalx("too many -%c for %s", c, cmd->entry->name);
}
/*
* If this is still the current command, it wants what it asked for and
* nothing more. If it's the base command, fill in as much as possible
* because the current command may have different flags.
*/
if (!everything)
switch (flag) {
case CMD_NONE:
case CMD_CLIENT:
case CMD_CLIENT_CANFAIL:
return (0);
case CMD_SESSION:
case CMD_SESSION_CANFAIL:
case CMD_SESSION_PREFERUNATTACHED:
case CMD_SESSION_WITHPANE:
targetflags = 0;
if (flag == CMD_SESSION_CANFAIL)
targetflags |= CMD_FIND_QUIET;
if (flag == CMD_SESSION_PREFERUNATTACHED)
targetflags |= CMD_FIND_PREFER_UNATTACHED;
complete_everything:
if (fsf->s == NULL) {
if (state->c != NULL)
fsf->s = state->c->session;
if (fsf->s == NULL) {
error = cmd_find_target(fsf, cmdq, NULL,
CMD_FIND_SESSION, CMD_FIND_QUIET);
if (error != 0)
fsf->s = NULL;
}
if (fsf->s == NULL) {
if (flags & CMD_CANFAIL)
return (0);
cmdq_error(cmdq, "no current session");
error = cmd_find_target(fs, cmdq, target, CMD_FIND_SESSION,
targetflags);
if (error != 0 && flag != CMD_SESSION_CANFAIL)
return (-1);
}
}
if (fsf->wl == NULL) {
error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_WINDOW, 0);
if (error != 0)
break;
case CMD_MOVEW_R:
error = cmd_find_target(fs, cmdq, target, CMD_FIND_SESSION,
CMD_FIND_QUIET);
if (error == 0)
break;
flag = CMD_WINDOW_INDEX;
/* FALLTHROUGH */
case CMD_WINDOW:
case CMD_WINDOW_CANFAIL:
case CMD_WINDOW_MARKED:
case CMD_WINDOW_INDEX:
targetflags = 0;
if (flag == CMD_WINDOW_CANFAIL)
targetflags |= CMD_FIND_QUIET;
if (flag == CMD_WINDOW_MARKED)
targetflags |= CMD_FIND_DEFAULT_MARKED;
if (flag == CMD_WINDOW_INDEX)
targetflags |= CMD_FIND_WINDOW_INDEX;
error = cmd_find_target(fs, cmdq, target, CMD_FIND_WINDOW,
targetflags);
if (error != 0 && flag != CMD_WINDOW_CANFAIL)
return (-1);
}
if (fsf->wp == NULL) {
error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_PANE, 0);
if (error != 0)
break;
case CMD_PANE:
case CMD_PANE_CANFAIL:
case CMD_PANE_MARKED:
targetflags = 0;
if (flag == CMD_PANE_CANFAIL)
targetflags |= CMD_FIND_QUIET;
if (flag == CMD_PANE_MARKED)
targetflags |= CMD_FIND_DEFAULT_MARKED;
error = cmd_find_target(fs, cmdq, target, CMD_FIND_PANE,
targetflags);
if (error != 0 && flag != CMD_PANE_CANFAIL)
return (-1);
break;
}
return (0);
}
static struct client *
cmd_get_state_client(struct cmd_q *cmdq, int quiet)
{
struct cmd *cmd = cmdq->cmd;
struct args *args = cmd->args;
switch (cmd->entry->flags & (CMD_CLIENT_C|CMD_CLIENT_T)) {
case 0:
return (cmd_find_client(cmdq, NULL, 1));
case CMD_CLIENT_C:
return (cmd_find_client(cmdq, args_get(args, 'c'), quiet));
case CMD_CLIENT_T:
return (cmd_find_client(cmdq, args_get(args, 't'), quiet));
default:
fatalx("both -t and -c for %s", cmd->entry->name);
}
}
int
cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq)
{
struct cmd_state *state = &cmdq->state;
struct args *args = cmd->args;
const char *cflag, *tflag;
char *tmp;
int error, quiet;
const struct cmd_entry *entry = cmd->entry;
struct cmd_state *state = &cmdq->state;
char *tmp;
enum cmd_entry_flag flag;
const char *s;
int error;
tmp = cmd_print(cmd);
log_debug("preparing state for: %s (client %p)", tmp, cmdq->client);
log_debug("preparing state for %s (client %p)", tmp, cmdq->client);
free(tmp);
/* Start with an empty state. */
cmd_clear_state(state);
/* No error messages if can fail. */
quiet = 0;
if (cmd->entry->flags & CMD_CLIENT_CANFAIL)
quiet = 1;
/*
* If the command wants a client and provides -c or -t, use it. If not,
* try the base command instead via cmd_get_state_client. No client is
* allowed if no flags, otherwise it must be available.
*/
switch (cmd->entry->flags & (CMD_CLIENT_C|CMD_CLIENT_T)) {
case 0:
state->c = cmd_get_state_client(cmdq, 1);
break;
case CMD_CLIENT_C:
cflag = args_get(args, 'c');
if (cflag == NULL)
state->c = cmd_get_state_client(cmdq, quiet);
flag = cmd->entry->cflag;
if (flag == CMD_NONE) {
flag = cmd->entry->tflag;
if (flag == CMD_CLIENT || flag == CMD_CLIENT_CANFAIL)
s = args_get(cmd->args, 't');
else
state->c = cmd_find_client(cmdq, cflag, quiet);
if (!quiet && state->c == NULL)
return (-1);
break;
case CMD_CLIENT_T:
tflag = args_get(args, 't');
if (tflag == NULL)
state->c = cmd_get_state_client(cmdq, 0);
else
state->c = cmd_find_client(cmdq, tflag, 0);
state->c = cmd_find_client(cmdq, args_get(args, 't'), quiet);
if (!quiet && state->c == NULL)
s = NULL;
} else
s = args_get(cmd->args, 'c');
switch (flag) {
case CMD_CLIENT:
state->c = cmd_find_client(cmdq, s, 0);
if (state->c == NULL)
return (-1);
break;
default:
fatalx("both -c and -t for %s", cmd->entry->name);
state->c = cmd_find_client(cmdq, s, 1);
break;
}
error = cmd_set_state_flag(cmd, cmdq, 't');
if (error == 0)
error = cmd_set_state_flag(cmd, cmdq, 's');
return (error);
s = args_get(cmd->args, 't');
log_debug("preparing -t state: target %s", s == NULL ? "none" : s);
error = cmd_prepare_state_flag(&state->tflag, entry->tflag, s, cmdq);
if (error != 0)
return (error);
s = args_get(cmd->args, 's');
log_debug("preparing -s state: target %s", s == NULL ? "none" : s);
error = cmd_prepare_state_flag(&state->sflag, entry->sflag, s, cmdq);
if (error != 0)
return (error);
return (0);
}
char *

1
log.c
View File

@ -144,6 +144,7 @@ fatalx(const char *msg, ...)
char *fmt;
va_list ap;
abort();
va_start(ap, msg);
if (asprintf(&fmt, "fatal: %s", msg) == -1)
exit(1);

53
tmux.h
View File

@ -1387,6 +1387,30 @@ struct cmd_q {
TAILQ_ENTRY(cmd_q) waitentry;
};
/* Command -c, -t or -s flags. */
enum cmd_entry_flag {
CMD_NONE,
CMD_CLIENT,
CMD_CLIENT_CANFAIL,
CMD_SESSION,
CMD_SESSION_CANFAIL,
CMD_SESSION_PREFERUNATTACHED,
CMD_SESSION_WITHPANE,
CMD_WINDOW,
CMD_WINDOW_CANFAIL,
CMD_WINDOW_MARKED,
CMD_WINDOW_INDEX,
CMD_PANE,
CMD_PANE_CANFAIL,
CMD_PANE_MARKED,
CMD_MOVEW_R,
};
/* Command definition. */
struct cmd_entry {
const char *name;
@ -1397,37 +1421,18 @@ struct cmd_entry {
int lower;
int upper;
} args;
const char *usage;
enum cmd_entry_flag tflag;
enum cmd_entry_flag sflag;
enum cmd_entry_flag cflag;
#define CMD_STARTSERVER 0x1
#define CMD_READONLY 0x2
#define CMD_SESSION_T 0x4
#define CMD_SESSION_S 0x8
#define CMD_WINDOW_T 0x10
#define CMD_WINDOW_S 0x20
#define CMD_PANE_T 0x40
#define CMD_PANE_S 0x80
#define CMD_CLIENT_T 0x100
#define CMD_CLIENT_C 0x200
#define CMD_INDEX_T 0x400
#define CMD_INDEX_S 0x800
#define CMD_CANFAIL 0x1000
#define CMD_PREFERUNATTACHED 0x2000
#define CMD_MOVEW_R 0x4000 /* for movew -r only */
#define CMD_PANE_MARKED_S 0x8000
#define CMD_PANE_MARKED_T 0x10000
#define CMD_WINDOW_MARKED_T 0x20000
#define CMD_WINDOW_MARKED_S 0x40000
#define CMD_CLIENT_CANFAIL 0x80000
int flags;
int flags;
enum cmd_retval (*exec)(struct cmd *, struct cmd_q *);
};
#define CMD_ALL_T (CMD_SESSION_T|CMD_WINDOW_T|CMD_PANE_T|CMD_INDEX_T| \
CMD_MOVEW_R|CMD_PANE_MARKED_T|CMD_WINDOW_MARKED_T)
#define CMD_ALL_S (CMD_SESSION_S|CMD_WINDOW_S|CMD_PANE_S|CMD_INDEX_S| \
CMD_PANE_MARKED_S|CMD_WINDOW_MARKED_S)
/* Key binding and key table. */
struct key_binding {