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. --- cmd-load-buffer.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'cmd-load-buffer.c') 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 -- cgit v1.2.3