From ede8312d59c5d08990f83f38682c26434823525b Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 11 Jul 2012 07:10:15 +0000 Subject: Make command exec functions return an enum rather than -1/0/1 values and add a new value to mean "leave client running but don't attach" to fix problems with using some commands in a command sequence. Most of the work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531. --- cfg.c | 18 ++++++++++++++---- cmd-attach-session.c | 14 +++++++------- cmd-bind-key.c | 32 ++++++++++++++++---------------- cmd-break-pane.c | 10 +++++----- cmd-capture-pane.c | 14 +++++++------- cmd-choose-buffer.c | 14 +++++++------- cmd-choose-client.c | 12 ++++++------ cmd-choose-tree.c | 11 +++++------ cmd-clear-history.c | 8 ++++---- cmd-clock-mode.c | 8 ++++---- cmd-command-prompt.c | 10 +++++----- cmd-confirm-before.c | 16 ++++++++-------- cmd-copy-mode.c | 12 ++++++------ cmd-delete-buffer.c | 12 ++++++------ cmd-detach-client.c | 10 +++++----- cmd-display-message.c | 14 +++++++------- cmd-display-panes.c | 8 ++++---- cmd-find-window.c | 12 ++++++------ cmd-has-session.c | 8 ++++---- cmd-if-shell.c | 6 +++--- cmd-join-pane.c | 26 +++++++++++++------------- cmd-kill-pane.c | 10 +++++----- cmd-kill-server.c | 6 +++--- cmd-kill-session.c | 8 ++++---- cmd-kill-window.c | 8 ++++---- cmd-link-window.c | 12 ++++++------ cmd-list-buffers.c | 6 +++--- cmd-list-clients.c | 6 +++--- cmd-list-commands.c | 6 +++--- cmd-list-keys.c | 13 ++++++------- cmd-list-panes.c | 10 +++++----- cmd-list-sessions.c | 6 +++--- cmd-list-windows.c | 8 ++++---- cmd-list.c | 34 +++++++++++++++++++--------------- cmd-load-buffer.c | 22 +++++++++++----------- cmd-lock-server.c | 10 +++++----- cmd-move-window.c | 16 ++++++++-------- cmd-new-session.c | 28 ++++++++++++++-------------- cmd-new-window.c | 12 ++++++------ cmd-paste-buffer.c | 12 ++++++------ cmd-pipe-pane.c | 16 ++++++++-------- cmd-refresh-client.c | 8 ++++---- cmd-rename-session.c | 12 ++++++------ cmd-rename-window.c | 8 ++++---- cmd-resize-pane.c | 12 ++++++------ cmd-respawn-pane.c | 12 ++++++------ cmd-respawn-window.c | 12 ++++++------ cmd-rotate-window.c | 10 +++++----- cmd-run-shell.c | 11 +++++------ cmd-save-buffer.c | 18 +++++++++--------- cmd-select-layout.c | 22 +++++++++++----------- cmd-select-pane.c | 20 ++++++++++---------- cmd-select-window.c | 18 +++++++++--------- cmd-send-keys.c | 8 ++++---- cmd-send-prefix.c | 8 ++++---- cmd-server-info.c | 6 +++--- cmd-set-buffer.c | 12 ++++++------ cmd-set-environment.c | 18 +++++++++--------- cmd-set-option.c | 22 +++++++++++----------- cmd-show-buffer.c | 14 +++++++------- cmd-show-environment.c | 12 ++++++------ cmd-show-messages.c | 8 ++++---- cmd-show-options.c | 16 ++++++++-------- cmd-source-file.c | 4 ++-- cmd-split-window.c | 12 ++++++------ cmd-start-server.c | 6 +++--- cmd-suspend-client.c | 8 ++++---- cmd-swap-pane.c | 16 ++++++++-------- cmd-swap-window.c | 12 ++++++------ cmd-switch-client.c | 18 +++++++++--------- cmd-unbind-key.c | 31 +++++++++++++++---------------- cmd-unlink-window.c | 10 +++++----- cmd.c | 2 +- server-client.c | 10 +++++++++- tmux.h | 13 ++++++++++--- 75 files changed, 489 insertions(+), 464 deletions(-) diff --git a/cfg.c b/cfg.c index 733238f3..ead99818 100644 --- a/cfg.c +++ b/cfg.c @@ -81,7 +81,7 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) size_t len; struct cmd_list *cmdlist; struct cmd_ctx ctx; - int retval; + enum cmd_retval retval; if ((f = fopen(path, "rb")) == NULL) { cfg_add_cause(causes, "%s: %s", path, strerror(errno)); @@ -90,7 +90,7 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) n = 0; line = NULL; - retval = 0; + retval = CMD_RETURN_NORMAL; while ((buf = fgetln(f, &len))) { if (buf[len - 1] == '\n') len--; @@ -145,8 +145,18 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) ctx.info = cfg_print; cfg_cause = NULL; - if (cmd_list_exec(cmdlist, &ctx) == 1) - retval = 1; + switch (cmd_list_exec(cmdlist, &ctx)) { + case CMD_RETURN_YIELD: + if (retval != CMD_RETURN_ATTACH) + retval = CMD_RETURN_YIELD; + break; + case CMD_RETURN_ATTACH: + retval = CMD_RETURN_ATTACH; + break; + case CMD_RETURN_ERROR: + case CMD_RETURN_NORMAL: + break; + } cmd_list_free(cmdlist); if (cfg_cause != NULL) { cfg_add_cause( diff --git a/cmd-attach-session.c b/cmd-attach-session.c index 42ef89ce..30451389 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -26,7 +26,7 @@ * Attach existing session to the current terminal. */ -int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_attach_session_entry = { "attach-session", "attach", @@ -38,7 +38,7 @@ const struct cmd_entry cmd_attach_session_entry = { cmd_attach_session_exec }; -int +enum cmd_retval cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -50,14 +50,14 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) if (RB_EMPTY(&sessions)) { ctx->error(ctx, "no sessions"); - return (-1); + return (CMD_RETURN_ERROR); } if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (ctx->cmdclient == NULL && ctx->curclient == NULL) - return (0); + return (CMD_RETURN_NORMAL); if (ctx->cmdclient == NULL) { if (args_has(self->args, 'd')) { @@ -84,7 +84,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) if (server_client_open(ctx->cmdclient, s, &cause) != 0) { ctx->error(ctx, "open terminal failed: %s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } if (args_has(self->args, 'r')) @@ -107,5 +107,5 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) recalculate_sizes(); server_update_socket(); - return (1); /* 1 means don't tell command client to exit */ + return (CMD_RETURN_ATTACH); } diff --git a/cmd-bind-key.c b/cmd-bind-key.c index 980e7ec9..909f4839 100644 --- a/cmd-bind-key.c +++ b/cmd-bind-key.c @@ -27,10 +27,10 @@ * Bind a key to a command, this recurses through cmd_*. */ -int cmd_bind_key_check(struct args *); -int cmd_bind_key_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_bind_key_check(struct args *); +enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_ctx *); -int cmd_bind_key_table(struct cmd *, struct cmd_ctx *, int); +enum cmd_retval cmd_bind_key_table(struct cmd *, struct cmd_ctx *, int); const struct cmd_entry cmd_bind_key_entry = { "bind-key", "bind", @@ -42,20 +42,20 @@ const struct cmd_entry cmd_bind_key_entry = { cmd_bind_key_exec }; -int +enum cmd_retval cmd_bind_key_check(struct args *args) { if (args_has(args, 't')) { if (args->argc != 2) - return (-1); + return (CMD_RETURN_ERROR); } else { if (args->argc < 2) - return (-1); + return (CMD_RETURN_ERROR); } - return (0); + return (CMD_RETURN_NORMAL); } -int +enum cmd_retval cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -66,7 +66,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx) key = key_string_lookup_string(args->argv[0]); if (key == KEYC_NONE) { ctx->error(ctx, "unknown key: %s", args->argv[0]); - return (-1); + return (CMD_RETURN_ERROR); } if (args_has(args, 't')) @@ -76,16 +76,16 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx) if (cmdlist == NULL) { ctx->error(ctx, "%s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } if (!args_has(args, 'n')) key |= KEYC_PREFIX; key_bindings_add(key, args_has(args, 'r'), cmdlist); - return (0); + return (CMD_RETURN_NORMAL); } -int +enum cmd_retval cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key) { struct args *args = self->args; @@ -97,25 +97,25 @@ cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key) tablename = args_get(args, 't'); if ((mtab = mode_key_findtable(tablename)) == NULL) { ctx->error(ctx, "unknown key table: %s", tablename); - return (-1); + return (CMD_RETURN_ERROR); } cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]); if (cmd == MODEKEY_NONE) { ctx->error(ctx, "unknown command: %s", args->argv[1]); - return (-1); + return (CMD_RETURN_ERROR); } mtmp.key = key; mtmp.mode = !!args_has(args, 'c'); if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) { mbind->cmd = cmd; - return (0); + return (CMD_RETURN_NORMAL); } mbind = xmalloc(sizeof *mbind); mbind->key = mtmp.key; mbind->mode = mtmp.mode; mbind->cmd = cmd; RB_INSERT(mode_key_tree, mtab->tree, mbind); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-break-pane.c b/cmd-break-pane.c index bcb6e6b9..5ddb8362 100644 --- a/cmd-break-pane.c +++ b/cmd-break-pane.c @@ -26,7 +26,7 @@ * Break pane off into a window. */ -int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_break_pane_entry = { "break-pane", "breakp", @@ -38,7 +38,7 @@ const struct cmd_entry cmd_break_pane_entry = { cmd_break_pane_exec }; -int +enum cmd_retval cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -55,11 +55,11 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx) char *cp; if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (window_count_panes(wl->window) == 1) { ctx->error(ctx, "can't break with only one pane"); - return (-1); + return (CMD_RETURN_ERROR); } w = wl->window; @@ -110,5 +110,5 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx) format_free(ft); } - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c index 236a51ca..f38fcb76 100644 --- a/cmd-capture-pane.c +++ b/cmd-capture-pane.c @@ -27,7 +27,7 @@ * Write the entire contents of a pane to a buffer. */ -int cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_capture_pane_entry = { "capture-pane", "capturep", @@ -39,7 +39,7 @@ const struct cmd_entry cmd_capture_pane_entry = { cmd_capture_pane_exec }; -int +enum cmd_retval cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -52,7 +52,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx) size_t len, linelen; if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) - return (-1); + return (CMD_RETURN_ERROR); s = &wp->base; gd = s->grid; @@ -103,7 +103,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx) if (!args_has(args, 'b')) { paste_add(&global_buffers, buf, len, limit); - return (0); + return (CMD_RETURN_NORMAL); } buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); @@ -111,14 +111,14 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx) ctx->error(ctx, "buffer %s", cause); free(buf); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } if (paste_replace(&global_buffers, buffer, buf, len) != 0) { ctx->error(ctx, "no buffer %d", buffer); free(buf); - return (-1); + return (CMD_RETURN_ERROR); } - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-choose-buffer.c b/cmd-choose-buffer.c index 6c62cfa3..3deedfa9 100644 --- a/cmd-choose-buffer.c +++ b/cmd-choose-buffer.c @@ -27,7 +27,7 @@ * Enter choice mode to choose a buffer. */ -int cmd_choose_buffer_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_ctx *); void cmd_choose_buffer_callback(struct window_choose_data *); void cmd_choose_buffer_free(struct window_choose_data *); @@ -42,7 +42,7 @@ const struct cmd_entry cmd_choose_buffer_entry = { cmd_choose_buffer_exec }; -int +enum cmd_retval cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -55,20 +55,20 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); - return (-1); + return (CMD_RETURN_ERROR); } if ((template = args_get(args, 'F')) == NULL) template = DEFAULT_BUFFER_LIST_TEMPLATE; if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (paste_get_top(&global_buffers) == NULL) - return (0); + return (CMD_RETURN_NORMAL); if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0) - return (0); + return (CMD_RETURN_NORMAL); if (args->argc != 0) action = xstrdup(args->argv[0]); @@ -96,7 +96,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) window_choose_ready(wl->window->active, 0, cmd_choose_buffer_callback, cmd_choose_buffer_free); - return (0); + return (CMD_RETURN_NORMAL); } void diff --git a/cmd-choose-client.c b/cmd-choose-client.c index a20fec42..4059cbba 100644 --- a/cmd-choose-client.c +++ b/cmd-choose-client.c @@ -27,7 +27,7 @@ * Enter choice mode to choose a client. */ -int cmd_choose_client_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_ctx *); void cmd_choose_client_callback(struct window_choose_data *); void cmd_choose_client_free(struct window_choose_data *); @@ -47,7 +47,7 @@ struct cmd_choose_client_data { char *template; }; -int +enum cmd_retval cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -60,14 +60,14 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx) if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); - return (-1); + return (CMD_RETURN_ERROR); } if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0) - return (0); + return (CMD_RETURN_NORMAL); if ((template = args_get(args, 'F')) == NULL) template = DEFAULT_CLIENT_TEMPLATE; @@ -104,7 +104,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx) window_choose_ready(wl->window->active, cur, cmd_choose_client_callback, cmd_choose_client_free); - return (0); + return (CMD_RETURN_NORMAL); } void diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c index 0389bea3..166684f8 100644 --- a/cmd-choose-tree.c +++ b/cmd-choose-tree.c @@ -70,7 +70,7 @@ const struct cmd_entry cmd_choose_window_entry = { cmd_choose_tree_exec }; -int +enum cmd_retval cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -89,17 +89,17 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); - return (-1); + return (CMD_RETURN_ERROR); } s = ctx->curclient->session; tty = &ctx->curclient->tty; if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0) - return (0); + return (CMD_RETURN_NORMAL); /* Sort out which command this is. */ wflag = sflag = 0; @@ -221,7 +221,7 @@ windows_only: window_choose_ready(wl->window->active, cur_win, cmd_choose_tree_callback, cmd_choose_tree_free); - return (0); + return (CMD_RETURN_NORMAL); } void @@ -248,4 +248,3 @@ cmd_choose_tree_free(struct window_choose_data *cdata) free(cdata); } - diff --git a/cmd-clear-history.c b/cmd-clear-history.c index cf3da229..8a88e46c 100644 --- a/cmd-clear-history.c +++ b/cmd-clear-history.c @@ -24,7 +24,7 @@ * Clear pane history. */ -int cmd_clear_history_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_clear_history_entry = { "clear-history", "clearhist", @@ -36,7 +36,7 @@ const struct cmd_entry cmd_clear_history_entry = { cmd_clear_history_exec }; -int +enum cmd_retval cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -44,11 +44,11 @@ cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx) struct grid *gd; if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) - return (-1); + return (CMD_RETURN_ERROR); gd = wp->base.grid; grid_move_lines(gd, 0, gd->hsize, gd->sy); gd->hsize = 0; - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-clock-mode.c b/cmd-clock-mode.c index 0dc151d1..f1d9eceb 100644 --- a/cmd-clock-mode.c +++ b/cmd-clock-mode.c @@ -24,7 +24,7 @@ * Enter clock mode. */ -int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_clock_mode_entry = { "clock-mode", NULL, @@ -36,16 +36,16 @@ const struct cmd_entry cmd_clock_mode_entry = { cmd_clock_mode_exec }; -int +enum cmd_retval cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct window_pane *wp; if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) - return (-1); + return (CMD_RETURN_ERROR); window_pane_set_mode(wp, &window_clock_mode); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index 3105744f..6c3df4ef 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -31,7 +31,7 @@ void cmd_command_prompt_key_binding(struct cmd *, int); int cmd_command_prompt_check(struct args *); -int cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *); int cmd_command_prompt_callback(void *, const char *); void cmd_command_prompt_free(void *); @@ -84,7 +84,7 @@ cmd_command_prompt_key_binding(struct cmd *self, int key) } } -int +enum cmd_retval cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -95,10 +95,10 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx) size_t n; if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (c->prompt_string != NULL) - return (0); + return (CMD_RETURN_NORMAL); cdata = xmalloc(sizeof *cdata); cdata->c = c; @@ -141,7 +141,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_command_prompt_free, cdata, 0); free(prompt); - return (0); + return (CMD_RETURN_NORMAL); } int diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index 78c6bac4..16607d0e 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -26,11 +26,11 @@ * Asks for confirmation before executing a command. */ -void cmd_confirm_before_key_binding(struct cmd *, int); -int cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *); +void cmd_confirm_before_key_binding(struct cmd *, int); +enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *); -int cmd_confirm_before_callback(void *, const char *); -void cmd_confirm_before_free(void *); +int cmd_confirm_before_callback(void *, const char *); +void cmd_confirm_before_free(void *); const struct cmd_entry cmd_confirm_before_entry = { "confirm-before", "confirm", @@ -65,7 +65,7 @@ cmd_confirm_before_key_binding(struct cmd *self, int key) } } -int +enum cmd_retval cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -76,11 +76,11 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx) if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); - return (-1); + return (CMD_RETURN_ERROR); } if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if ((prompt = args_get(args, 'p')) != NULL) xasprintf(&new_prompt, "%s ", prompt); @@ -99,7 +99,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx) PROMPT_SINGLE); free(new_prompt); - return (1); + return (CMD_RETURN_YIELD); } int diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c index b9290593..3f80cd8c 100644 --- a/cmd-copy-mode.c +++ b/cmd-copy-mode.c @@ -24,8 +24,8 @@ * Enter copy mode. */ -void cmd_copy_mode_key_binding(struct cmd *, int); -int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *); +void cmd_copy_mode_key_binding(struct cmd *, int); +enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_copy_mode_entry = { "copy-mode", NULL, @@ -45,20 +45,20 @@ cmd_copy_mode_key_binding(struct cmd *self, int key) args_set(self->args, 'u', NULL); } -int +enum cmd_retval cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct window_pane *wp; if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (window_pane_set_mode(wp, &window_copy_mode) != 0) - return (0); + return (CMD_RETURN_NORMAL); window_copy_init_from_pane(wp); if (wp->mode == &window_copy_mode && args_has(self->args, 'u')) window_copy_pageup(wp); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-delete-buffer.c b/cmd-delete-buffer.c index f087b9a7..c3f8776a 100644 --- a/cmd-delete-buffer.c +++ b/cmd-delete-buffer.c @@ -26,7 +26,7 @@ * Delete a paste buffer. */ -int cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_delete_buffer_entry = { "delete-buffer", "deleteb", @@ -38,7 +38,7 @@ const struct cmd_entry cmd_delete_buffer_entry = { cmd_delete_buffer_exec }; -int +enum cmd_retval cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -47,20 +47,20 @@ cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) if (!args_has(args, 'b')) { paste_free_top(&global_buffers); - return (0); + return (CMD_RETURN_NORMAL); } buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); if (cause != NULL) { ctx->error(ctx, "buffer %s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } if (paste_free_index(&global_buffers, buffer) != 0) { ctx->error(ctx, "no buffer %d", buffer); - return (-1); + return (CMD_RETURN_ERROR); } - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-detach-client.c b/cmd-detach-client.c index 6477e062..b437ddd3 100644 --- a/cmd-detach-client.c +++ b/cmd-detach-client.c @@ -24,7 +24,7 @@ * Detach a client. */ -int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_detach_client_entry = { "detach-client", "detach", @@ -36,7 +36,7 @@ const struct cmd_entry cmd_detach_client_entry = { cmd_detach_client_exec }; -int +enum cmd_retval cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -53,7 +53,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(args, 's')) { s = cmd_find_session(ctx, args_get(args, 's'), 0); if (s == NULL) - return (-1); + return (CMD_RETURN_ERROR); for (i = 0; i < ARRAY_LENGTH(&clients); i++) { c = ARRAY_ITEM(&clients, i); @@ -63,7 +63,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx) } else { c = cmd_find_client(ctx, args_get(args, 't')); if (c == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (args_has(args, 'a')) { for (i = 0; i < ARRAY_LENGTH(&clients); i++) { @@ -76,5 +76,5 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx) server_write_client(c, msgtype, NULL, 0); } - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-display-message.c b/cmd-display-message.c index 3bc3a38c..1aed4f1d 100644 --- a/cmd-display-message.c +++ b/cmd-display-message.c @@ -27,7 +27,7 @@ * Displays a message in the status line. */ -int cmd_display_message_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_display_message_entry = { "display-message", "display", @@ -39,7 +39,7 @@ const struct cmd_entry cmd_display_message_entry = { cmd_display_message_exec }; -int +enum cmd_retval cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -55,21 +55,21 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx) size_t len; if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (args_has(args, 't')) { wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp); if (wl == NULL) - return (-1); + return (CMD_RETURN_ERROR); } else { wl = cmd_find_pane(ctx, NULL, &s, &wp); if (wl == NULL) - return (-1); + return (CMD_RETURN_ERROR); } if (args_has(args, 'F') && args->argc != 0) { ctx->error(ctx, "only one of -F or argument must be given"); - return (-1); + return (CMD_RETURN_ERROR); } template = args_get(args, 'F'); @@ -96,5 +96,5 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx) free(msg); format_free(ft); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-display-panes.c b/cmd-display-panes.c index bc64b4b5..5f0893d4 100644 --- a/cmd-display-panes.c +++ b/cmd-display-panes.c @@ -24,7 +24,7 @@ * Display panes on a client. */ -int cmd_display_panes_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_display_panes_entry = { "display-panes", "displayp", @@ -36,16 +36,16 @@ const struct cmd_entry cmd_display_panes_entry = { cmd_display_panes_exec }; -int +enum cmd_retval cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct client *c; if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) - return (-1); + return (CMD_RETURN_ERROR); server_set_identify(c); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-find-window.c b/cmd-find-window.c index 864f1821..e73effbf 100644 --- a/cmd-find-window.c +++ b/cmd-find-window.c @@ -28,7 +28,7 @@ * Find window containing text. */ -int cmd_find_window_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_ctx *); u_int cmd_find_window_match_flags(struct args *); void cmd_find_window_callback(struct window_choose_data *); @@ -74,7 +74,7 @@ cmd_find_window_match_flags(struct args *args) return (match_flags); } -int +enum cmd_retval cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -90,12 +90,12 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); - return (-1); + return (CMD_RETURN_ERROR); } s = ctx->curclient->session; if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if ((template = args_get(args, 'F')) == NULL) template = DEFAULT_FIND_WINDOW_TEMPLATE; @@ -150,7 +150,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) ctx->error(ctx, "no windows matching: %s", str); ARRAY_FREE(&list_idx); ARRAY_FREE(&list_ctx); - return (-1); + return (CMD_RETURN_ERROR); } if (ARRAY_LENGTH(&list_idx) == 1) { @@ -189,7 +189,7 @@ out: ARRAY_FREE(&list_idx); ARRAY_FREE(&list_ctx); - return (0); + return (CMD_RETURN_NORMAL); } void diff --git a/cmd-has-session.c b/cmd-has-session.c index cfaf032b..8e77942a 100644 --- a/cmd-has-session.c +++ b/cmd-has-session.c @@ -24,7 +24,7 @@ * Cause client to report an error and exit with 1 if session doesn't exist. */ -int cmd_has_session_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_has_session_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_has_session_entry = { "has-session", "has", @@ -36,13 +36,13 @@ const struct cmd_entry cmd_has_session_entry = { cmd_has_session_exec }; -int +enum cmd_retval cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; if (cmd_find_session(ctx, args_get(args, 't'), 0) == NULL) - return (-1); + return (CMD_RETURN_ERROR); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-if-shell.c b/cmd-if-shell.c index bdd26e70..5e23fb10 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -29,7 +29,7 @@ * Executes a tmux command if a shell command returns true or false. */ -int cmd_if_shell_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmd_ctx *); void cmd_if_shell_callback(struct job *); void cmd_if_shell_free(void *); @@ -50,7 +50,7 @@ struct cmd_if_shell_data { struct cmd_ctx ctx; }; -int +enum cmd_retval cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -72,7 +72,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx) job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata); - return (1); /* don't let client exit */ + return (CMD_RETURN_YIELD); /* don't let client exit */ } void diff --git a/cmd-join-pane.c b/cmd-join-pane.c index 602dcf66..c792948c 100644 --- a/cmd-join-pane.c +++ b/cmd-join-pane.c @@ -29,10 +29,10 @@ * Join or move a pane into another (like split/swap/kill). */ -void cmd_join_pane_key_binding(struct cmd *, int); -int cmd_join_pane_exec(struct cmd *, struct cmd_ctx *); +void cmd_join_pane_key_binding(struct cmd *, int); +enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_ctx *); -int join_pane(struct cmd *, struct cmd_ctx *, int); +enum cmd_retval join_pane(struct cmd *, struct cmd_ctx *, int); const struct cmd_entry cmd_join_pane_entry = { "join-pane", "joinp", @@ -68,13 +68,13 @@ cmd_join_pane_key_binding(struct cmd *self, int key) } } -int +enum cmd_retval cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx) { return (join_pane(self, ctx, self->entry == &cmd_join_pane_entry)); } -int +enum cmd_retval join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window) { struct args *args = self->args; @@ -89,22 +89,22 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window) dst_wl = cmd_find_pane(ctx, args_get(args, 't'), &dst_s, &dst_wp); if (dst_wl == NULL) - return (-1); + return (CMD_RETURN_ERROR); dst_w = dst_wl->window; dst_idx = dst_wl->idx; src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp); if (src_wl == NULL) - return (-1); + return (CMD_RETURN_ERROR); src_w = src_wl->window; if (not_same_window && src_w == dst_w) { ctx->error(ctx, "can't join a pane to its own window"); - return (-1); + return (CMD_RETURN_ERROR); } if (!not_same_window && src_wp == dst_wp) { ctx->error(ctx, "source and target panes must be different"); - return (-1); + return (CMD_RETURN_ERROR); } type = LAYOUT_TOPBOTTOM; @@ -117,14 +117,14 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window) if (cause != NULL) { ctx->error(ctx, "size %s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } } else if (args_has(args, 'p')) { percentage = args_strtonum(args, 'p', 0, 100, &cause); if (cause != NULL) { ctx->error(ctx, "percentage %s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } if (type == LAYOUT_TOPBOTTOM) size = (dst_wp->sy * percentage) / 100; @@ -134,7 +134,7 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window) lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b')); if (lc == NULL) { ctx->error(ctx, "create pane failed: pane too small"); - return (-1); + return (CMD_RETURN_ERROR); } layout_close_pane(src_wp); @@ -168,5 +168,5 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window) server_status_session(dst_s); notify_window_layout_changed(dst_w); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-kill-pane.c b/cmd-kill-pane.c index 215c8ed7..ff8c425f 100644 --- a/cmd-kill-pane.c +++ b/cmd-kill-pane.c @@ -26,7 +26,7 @@ * Kill pane. */ -int cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_kill_pane_entry = { "kill-pane", "killp", @@ -38,7 +38,7 @@ const struct cmd_entry cmd_kill_pane_entry = { cmd_kill_pane_exec }; -int +enum cmd_retval cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -46,13 +46,13 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx) struct window_pane *loopwp, *nextwp, *wp; if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (window_count_panes(wl->window) == 1) { /* Only one pane, kill the window. */ server_kill_window(wl->window); recalculate_sizes(); - return (0); + return (CMD_RETURN_NORMAL); } if (args_has(self->args, 'a')) { @@ -71,5 +71,5 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx) } server_redraw_window(wl->window); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-kill-server.c b/cmd-kill-server.c index 800563a4..6761dac4 100644 --- a/cmd-kill-server.c +++ b/cmd-kill-server.c @@ -27,7 +27,7 @@ * Kill the server and do nothing else. */ -int cmd_kill_server_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_kill_server_entry = { "kill-server", NULL, @@ -40,10 +40,10 @@ const struct cmd_entry cmd_kill_server_entry = { }; /* ARGSUSED */ -int +enum cmd_retval cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx) { kill(getpid(), SIGTERM); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-kill-session.c b/cmd-kill-session.c index bdc4a71c..9ee6a928 100644 --- a/cmd-kill-session.c +++ b/cmd-kill-session.c @@ -27,7 +27,7 @@ * Note this deliberately has no alias to make it hard to hit by accident. */ -int cmd_kill_session_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_kill_session_entry = { "kill-session", NULL, @@ -39,14 +39,14 @@ const struct cmd_entry cmd_kill_session_entry = { cmd_kill_session_exec }; -int +enum cmd_retval cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct session *s, *s2, *s3; if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (args_has(args, 'a')) { RB_FOREACH_SAFE(s2, sessions, &sessions, s3) { @@ -59,5 +59,5 @@ cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx) server_destroy_session(s); session_destroy(s); } - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-kill-window.c b/cmd-kill-window.c index 255026cd..01587fc8 100644 --- a/cmd-kill-window.c +++ b/cmd-kill-window.c @@ -24,7 +24,7 @@ * Destroy window. */ -int cmd_kill_window_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_kill_window_entry = { "kill-window", "killw", @@ -36,7 +36,7 @@ const struct cmd_entry cmd_kill_window_entry = { cmd_kill_window_exec }; -int +enum cmd_retval cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -44,7 +44,7 @@ cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx) struct session *s; if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (args_has(args, 'a')) { RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) { @@ -55,5 +55,5 @@ cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx) server_kill_window(wl->window); recalculate_sizes(); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-link-window.c b/cmd-link-window.c index a9dcf621..5c050904 100644 --- a/cmd-link-window.c +++ b/cmd-link-window.c @@ -26,7 +26,7 @@ * Link a window into another session. */ -int cmd_link_window_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_link_window_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_link_window_entry = { "link-window", "linkw", @@ -38,7 +38,7 @@ const struct cmd_entry cmd_link_window_entry = { cmd_link_window_exec }; -int +enum cmd_retval cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -48,18 +48,18 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx) int idx, kflag, dflag; if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2) - return (-1); + return (CMD_RETURN_ERROR); kflag = args_has(self->args, 'k'); dflag = args_has(self->args, 'd'); if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) { ctx->error(ctx, "can't link window: %s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } recalculate_sizes(); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-list-buffers.c b/cmd-list-buffers.c index 64fbd3f2..f22a35bc 100644 --- a/cmd-list-buffers.c +++ b/cmd-list-buffers.c @@ -27,7 +27,7 @@ * List paste buffers. */ -int cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_list_buffers_entry = { "list-buffers", "lsb", @@ -40,7 +40,7 @@ const struct cmd_entry cmd_list_buffers_entry = { }; /* ARGSUSED */ -int +enum cmd_retval cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -66,5 +66,5 @@ cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx) format_free(ft); } - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-list-clients.c b/cmd-list-clients.c index 2286ff98..af6ebde2 100644 --- a/cmd-list-clients.c +++ b/cmd-list-clients.c @@ -41,7 +41,7 @@ const struct cmd_entry cmd_list_clients_entry = { }; /* ARGSUSED */ -int +enum cmd_retval cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -55,7 +55,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(args, 't')) { s = cmd_find_session(ctx, args_get(args, 't'), 0); if (s == NULL) - return (-1); + return (CMD_RETURN_ERROR); } else s = NULL; @@ -82,5 +82,5 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx) format_free(ft); } - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-list-commands.c b/cmd-list-commands.c index 87901210..2ebc206e 100644 --- a/cmd-list-commands.c +++ b/cmd-list-commands.c @@ -24,7 +24,7 @@ * List all commands with usages. */ -int cmd_list_commands_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_list_commands_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_list_commands_entry = { "list-commands", "lscm", @@ -37,7 +37,7 @@ const struct cmd_entry cmd_list_commands_entry = { }; /* ARGSUSED */ -int +enum cmd_retval cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx) { const struct cmd_entry **entryp; @@ -45,5 +45,5 @@ cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx) for (entryp = cmd_table; *entryp != NULL; entryp++) ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-list-keys.c b/cmd-list-keys.c index 95f33023..d93f368b 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -26,9 +26,8 @@ * List key bindings. */ -int cmd_list_keys_exec(struct cmd *, struct cmd_ctx *); - -int cmd_list_keys_table(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_list_keys_entry = { "list-keys", "lsk", @@ -40,7 +39,7 @@ const struct cmd_entry cmd_list_keys_entry = { cmd_list_keys_exec }; -int +enum cmd_retval cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -95,7 +94,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx) ctx->print(ctx, "bind-key %s", tmp); } - return (0); + return (CMD_RETURN_NORMAL); } int @@ -111,7 +110,7 @@ cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx) tablename = args_get(args, 't'); if ((mtab = mode_key_findtable(tablename)) == NULL) { ctx->error(ctx, "unknown key table: %s", tablename); - return (-1); + return (CMD_RETURN_ERROR); } width = 0; @@ -145,5 +144,5 @@ cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx) } } - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-list-panes.c b/cmd-list-panes.c index 3f9e672c..7a8d81d2 100644 --- a/cmd-list-panes.c +++ b/cmd-list-panes.c @@ -27,7 +27,7 @@ * List panes on given window. */ -int cmd_list_panes_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_ctx *); void cmd_list_panes_server(struct cmd *, struct cmd_ctx *); void cmd_list_panes_session( @@ -45,7 +45,7 @@ const struct cmd_entry cmd_list_panes_entry = { cmd_list_panes_exec }; -int +enum cmd_retval cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -57,16 +57,16 @@ cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx) else if (args_has(args, 's')) { s = cmd_find_session(ctx, args_get(args, 't'), 0); if (s == NULL) - return (-1); + return (CMD_RETURN_ERROR); cmd_list_panes_session(self, s, ctx, 1); } else { wl = cmd_find_window(ctx, args_get(args, 't'), &s); if (wl == NULL) - return (-1); + return (CMD_RETURN_ERROR); cmd_list_panes_window(self, s, wl, ctx, 0); } - return (0); + return (CMD_RETURN_NORMAL); } void diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c index 1aa6dbaa..6db1e11c 100644 --- a/cmd-list-sessions.c +++ b/cmd-list-sessions.c @@ -28,7 +28,7 @@ * List all sessions. */ -int cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_list_sessions_entry = { "list-sessions", "ls", @@ -40,7 +40,7 @@ const struct cmd_entry cmd_list_sessions_entry = { cmd_list_sessions_exec }; -int +enum cmd_retval cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -67,5 +67,5 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx) n++; } - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-list-windows.c b/cmd-list-windows.c index 241e64de..62ae6b11 100644 --- a/cmd-list-windows.c +++ b/cmd-list-windows.c @@ -27,7 +27,7 @@ * List windows on given session. */ -int cmd_list_windows_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_ctx *); void cmd_list_windows_server(struct cmd *, struct cmd_ctx *); void cmd_list_windows_session( @@ -43,7 +43,7 @@ const struct cmd_entry cmd_list_windows_entry = { cmd_list_windows_exec }; -int +enum cmd_retval cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -54,11 +54,11 @@ cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx) else { s = cmd_find_session(ctx, args_get(args, 't'), 0); if (s == NULL) - return (-1); + return (CMD_RETURN_ERROR); cmd_list_windows_session(self, s, ctx, 0); } - return (0); + return (CMD_RETURN_NORMAL); } void diff --git a/cmd-list.c b/cmd-list.c index 08d5716f..80d1ade3 100644 --- a/cmd-list.c +++ b/cmd-list.c @@ -79,12 +79,13 @@ bad: return (NULL); } -int +enum cmd_retval cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx) { struct client *c = ctx->curclient; struct cmd *cmd; - int n, retval, guards; + enum cmd_retval retval; + int guards, n; guards = 0; if (c != NULL && c->session != NULL) @@ -98,21 +99,17 @@ cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx) if (guards) ctx->print(ctx, "%%end"); - /* Return of -1 is an error. */ - if (n == -1) - return (-1); - - /* - * A 1 return value means the command client is being attached - * (sent MSG_READY). - */ - if (n == 1) { - retval = 1; + switch (n) + { + case CMD_RETURN_ERROR: + return (CMD_RETURN_ERROR); + case CMD_RETURN_ATTACH: + /* Client is being attached (send MSG_READY). */ + retval = CMD_RETURN_ATTACH; /* - * The command client has been attached, so mangle the - * context to treat any following commands as if they - * were called from inside. + * Mangle the context to treat any following commands + * as if they were called from inside. */ if (ctx->curclient == NULL) { ctx->curclient = ctx->cmdclient; @@ -122,6 +119,13 @@ cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx) ctx->print = key_bindings_print; ctx->info = key_bindings_info; } + break; + case CMD_RETURN_YIELD: + if (retval == CMD_RETURN_NORMAL) + retval = CMD_RETURN_YIELD; + break; + case CMD_RETURN_NORMAL: + break; } } return (retval); diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c index 83ab6078..bfb06842 100644 --- a/cmd-load-buffer.c +++ b/cmd-load-buffer.c @@ -30,8 +30,8 @@ * Loads a paste buffer from a file. */ -int cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *); -void cmd_load_buffer_callback(struct client *, int, void *); +enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *); +void cmd_load_buffer_callback(struct client *, int, void *); const struct cmd_entry cmd_load_buffer_entry = { "load-buffer", "loadb", @@ -43,7 +43,7 @@ const struct cmd_entry cmd_load_buffer_entry = { cmd_load_buffer_exec }; -int +enum cmd_retval cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -63,7 +63,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) if (cause != NULL) { ctx->error(ctx, "buffer %s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } } @@ -77,9 +77,9 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) if (error != 0) { ctx->error(ctx, "%s: %s", path, cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } - return (1); + return (CMD_RETURN_YIELD); } if (c != NULL) @@ -97,7 +97,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) } if ((f = fopen(path, "rb")) == NULL) { ctx->error(ctx, "%s: %s", path, strerror(errno)); - return (-1); + return (CMD_RETURN_ERROR); } pdata = NULL; @@ -123,21 +123,21 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) limit = options_get_number(&global_options, "buffer-limit"); if (buffer == -1) { paste_add(&global_buffers, pdata, psize, limit); - return (0); + return (CMD_RETURN_NORMAL); } if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) { ctx->error(ctx, "no buffer %d", buffer); free(pdata); - return (-1); + return (CMD_RETURN_ERROR); } - return (0); + return (CMD_RETURN_NORMAL); error: free(pdata); if (f != NULL) fclose(f); - return (-1); + return (CMD_RETURN_ERROR); } void diff --git a/cmd-lock-server.c b/cmd-lock-server.c index ecbcee9b..7a9ced33 100644 --- a/cmd-lock-server.c +++ b/cmd-lock-server.c @@ -28,7 +28,7 @@ * Lock commands. */ -int cmd_lock_server_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_lock_server_entry = { "lock-server", "lock", @@ -61,7 +61,7 @@ const struct cmd_entry cmd_lock_client_entry = { }; /* ARGSUSED */ -int +enum cmd_retval cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx) { struct args *args = self->args; @@ -72,14 +72,14 @@ cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx) server_lock(); else if (self->entry == &cmd_lock_session_entry) { if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); server_lock_session(s); } else { if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) - return (-1); + return (CMD_RETURN_ERROR); server_lock_client(c); } recalculate_sizes(); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-move-window.c b/cmd-move-window.c index 4adad410..03d42a8d 100644 --- a/cmd-move-window.c +++ b/cmd-move-window.c @@ -26,7 +26,7 @@ * Move a window. */ -int cmd_move_window_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_move_window_entry = { "move-window", "movew", @@ -38,7 +38,7 @@ const struct cmd_entry cmd_move_window_entry = { cmd_move_window_exec }; -int +enum cmd_retval cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -49,28 +49,28 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(args, 'r')) { if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); session_renumber_windows(s); recalculate_sizes(); - return (0); + return (CMD_RETURN_NORMAL); } if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2) - return (-1); + return (CMD_RETURN_ERROR); kflag = args_has(self->args, 'k'); dflag = args_has(self->args, 'd'); if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) { ctx->error(ctx, "can't move window: %s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } server_unlink_window(src, wl); recalculate_sizes(); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-new-session.c b/cmd-new-session.c index 22ec16fb..cd1bc2b1 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -30,8 +30,8 @@ * Create a new session and attach to the current terminal unless -d is given. */ -int cmd_new_session_check(struct args *); -int cmd_new_session_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_new_session_check(struct args *); +enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_new_session_entry = { "new-session", "new", @@ -44,15 +44,15 @@ const struct cmd_entry cmd_new_session_entry = { cmd_new_session_exec }; -int +enum cmd_retval cmd_new_session_check(struct args *args) { if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) - return (-1); - return (0); + return (CMD_RETURN_ERROR); + return (CMD_RETURN_NORMAL); } -int +enum cmd_retval cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -71,11 +71,11 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) if (newname != NULL) { if (!session_check_name(newname)) { ctx->error(ctx, "bad session name: %s", newname); - return (-1); + return (CMD_RETURN_ERROR); } if (session_find(newname) != NULL) { ctx->error(ctx, "duplicate session: %s", newname); - return (-1); + return (CMD_RETURN_ERROR); } } @@ -83,7 +83,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) if (target != NULL) { groupwith = cmd_find_session(ctx, target, 0); if (groupwith == NULL) - return (-1); + return (CMD_RETURN_ERROR); } else groupwith = NULL; @@ -131,7 +131,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) if (server_client_open(ctx->cmdclient, NULL, &cause) != 0) { ctx->error(ctx, "open terminal failed: %s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } } @@ -163,7 +163,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) args_get(args, 'x'), 1, USHRT_MAX, &errstr); if (errstr != NULL) { ctx->error(ctx, "width %s", errstr); - return (-1); + return (CMD_RETURN_ERROR); } } if (args_has(args, 'y')) { @@ -171,7 +171,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) args_get(args, 'y'), 1, USHRT_MAX, &errstr); if (errstr != NULL) { ctx->error(ctx, "height %s", errstr); - return (-1); + return (CMD_RETURN_ERROR); } } } @@ -202,7 +202,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) if (s == NULL) { ctx->error(ctx, "create session failed: %s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } environ_free(&env); @@ -269,5 +269,5 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) ARRAY_FREE(&cfg_causes); } - return (!detached); /* 1 means don't tell command client to exit */ + return (detached ? CMD_RETURN_NORMAL : CMD_RETURN_ATTACH); } diff --git a/cmd-new-window.c b/cmd-new-window.c index 3d9e9320..28dd2358 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -39,7 +39,7 @@ const struct cmd_entry cmd_new_window_entry = { cmd_new_window_exec }; -int +enum cmd_retval cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -56,7 +56,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(args, 'a')) { wl = cmd_find_window(ctx, args_get(args, 't'), &s); if (wl == NULL) - return (-1); + return (CMD_RETURN_ERROR); idx = wl->idx + 1; /* Find the next free index. */ @@ -66,7 +66,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) } if (last == INT_MAX) { ctx->error(ctx, "no free window indexes"); - return (-1); + return (CMD_RETURN_ERROR); } /* Move everything from last - 1 to idx up a bit. */ @@ -77,7 +77,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) } } else { if ((idx = cmd_find_index(ctx, args_get(args, 't'), &s)) == -2) - return (-1); + return (CMD_RETURN_ERROR); } detached = args_has(args, 'd'); @@ -113,7 +113,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) if (wl == NULL) { ctx->error(ctx, "create window failed: %s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } if (!detached) { session_select(s, wl->idx); @@ -139,5 +139,5 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) format_free(ft); } - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c index 2c367259..9bf27fcd 100644 --- a/cmd-paste-buffer.c +++ b/cmd-paste-buffer.c @@ -28,7 +28,7 @@ * Paste paste buffer if present. */ -int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *); void cmd_paste_buffer_filter(struct window_pane *, const char *, size_t, const char *, int bracket); @@ -43,7 +43,7 @@ const struct cmd_entry cmd_paste_buffer_entry = { cmd_paste_buffer_exec }; -int +enum cmd_retval cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -56,7 +56,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) int pflag; if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (!args_has(args, 'b')) buffer = -1; @@ -65,7 +65,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) if (cause != NULL) { ctx->error(ctx, "buffer %s", cause); free(cause); - return (-1); + return (CMD_RETURN_ERROR); } } @@ -75,7 +75,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) pb = paste_get_index(&global_buffers, buffer); if (pb == NULL) { ctx->error(ctx, "no buffer %d", buffer); - return (-1); + return (CMD_RETURN_ERROR); } } @@ -100,7 +100,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) paste_free_index(&global_buffers, buffer); } - return (0); + return (CMD_RETURN_NORMAL); } /* Add bytes to a buffer and filter '\n' according to separator. */ diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c index 0a52ae5d..bf89e51a 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -32,7 +32,7 @@ * Open pipe to redirect pane output. If already open, close first. */ -int cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *); void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *); @@ -46,7 +46,7 @@ const struct cmd_entry cmd_pipe_pane_entry = { cmd_pipe_pane_exec }; -int +enum cmd_retval cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -56,7 +56,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) int old_fd, pipe_fd[2], null_fd; if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) - return (-1); + return (CMD_RETURN_ERROR); c = cmd_find_client(ctx, NULL); /* Destroy the old pipe. */ @@ -69,7 +69,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) /* If no pipe command, that is enough. */ if (args->argc == 0 || *args->argv[0] == '\0') - return (0); + return (CMD_RETURN_NORMAL); /* * With -o, only open the new pipe if there was no previous one. This @@ -78,19 +78,19 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) * bind ^p pipep -o 'cat >>~/output' */ if (args_has(self->args, 'o') && old_fd != -1) - return (0); + return (CMD_RETURN_NORMAL); /* Open the new pipe. */ if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) { ctx->error(ctx, "socketpair error: %s", strerror(errno)); - return (-1); + return (CMD_RETURN_ERROR); } /* Fork the child. */ switch (fork()) { case -1: ctx->error(ctx, "fork error: %s", strerror(errno)); - return (-1); + return (CMD_RETURN_ERROR); case 0: /* Child process. */ close(pipe_fd[0]); @@ -127,7 +127,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) bufferevent_enable(wp->pipe_event, EV_WRITE); setblocking(wp->pipe_fd, 0); - return (0); + return (CMD_RETURN_NORMAL); } } diff --git a/cmd-refresh-client.c b/cmd-refresh-client.c index e7e10696..0ce7be9d 100644 --- a/cmd-refresh-client.c +++ b/cmd-refresh-client.c @@ -24,7 +24,7 @@ * Refresh client. */ -int cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_refresh_client_entry = { "refresh-client", "refresh", @@ -36,14 +36,14 @@ const struct cmd_entry cmd_refresh_client_entry = { cmd_refresh_client_exec }; -int +enum cmd_retval cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct client *c; if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (args_has(args, 'S')) { status_update_jobs(c); @@ -51,5 +51,5 @@ cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx) } else server_redraw_client(c); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-rename-session.c b/cmd-rename-session.c index bbae1872..fb8dd4ed 100644 --- a/cmd-rename-session.c +++ b/cmd-rename-session.c @@ -26,7 +26,7 @@ * Change session name. */ -int cmd_rename_session_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_rename_session_entry = { "rename-session", "rename", @@ -38,7 +38,7 @@ const struct cmd_entry cmd_rename_session_entry = { cmd_rename_session_exec }; -int +enum cmd_retval cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -48,15 +48,15 @@ cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx) newname = args->argv[0]; if (!session_check_name(newname)) { ctx->error(ctx, "bad session name: %s", newname); - return (-1); + return (CMD_RETURN_ERROR); } if (session_find(newname) != NULL) { ctx->error(ctx, "duplicate session: %s", newname); - return (-1); + return (CMD_RETURN_ERROR); } if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); RB_REMOVE(sessions, &sessions, s); free(s->name); @@ -66,5 +66,5 @@ cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx) server_status_session(s); notify_session_renamed(s); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-rename-window.c b/cmd-rename-window.c index dc7fec5c..099ab3b7 100644 --- a/cmd-rename-window.c +++ b/cmd-rename-window.c @@ -26,7 +26,7 @@ * Rename a window. */ -int cmd_rename_window_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_rename_window_entry = { "rename-window", "renamew", @@ -38,7 +38,7 @@ const struct cmd_entry cmd_rename_window_entry = { cmd_rename_window_exec }; -int +enum cmd_retval cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -46,12 +46,12 @@ cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx) struct winlink *wl; if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); window_set_name(wl->window, args->argv[0]); options_set_number(&wl->window->options, "automatic-rename", 0); server_status_window(wl->window); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index cabf1da4..4842d411 100644 --- a/cmd-resize-pane.c +++ b/cmd-resize-pane.c @@ -26,8 +26,8 @@ * Increase or decrease pane size. */ -void cmd_resize_pane_key_binding(struct cmd *, int); -int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *); +void cmd_resize_pane_key_binding(struct cmd *, int); +enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_resize_pane_entry = { "resize-pane", "resizep", @@ -81,7 +81,7 @@ cmd_resize_pane_key_binding(struct cmd *self, int key) } } -int +enum cmd_retval cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; @@ -91,7 +91,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx) u_int adjust; if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL) - return (-1); + return (CMD_RETURN_ERROR); if (args->argc == 0) adjust = 1; @@ -99,7 +99,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx) adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr); if (errstr != NULL) { ctx->error(ctx, "adjustment %s", errstr); - return (-1); + return (CMD_RETURN_ERROR); } } @@ -114,5 +114,5 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx) layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust); server_redraw_window(wl->window); - return (0); + return (CMD_RETURN_NORMAL); } diff --git a/cmd-respawn-pane.c b/cmd-respawn-pane.c index 71e07831..3860dc93 100644 --- a/cmd-respawn-pane.c +++ b/cmd-respawn-pane.c @@ -28,7 +28,7 @@ * Respawn a pane (restart the command). Kill existing if -k given. */ -int cmd_respawn_pane_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_respawn_pane_entry = { "respawn-pane", "respawnp", @@ -40,7 +40,7 @@ const st