From e8ca7526ddebc98f3023736f77fa13b65034767b Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 3 Jan 2014 20:58:24 +0000 Subject: [PATCH] gui: Simplify display command execution. para_cmd() and display_cmd() are almost identical. Move the command part into send_output() and rename this function to exec_and_display_cmd(). --- gui.c | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/gui.c b/gui.c index 6928e0b3..e03fb287 100644 --- a/gui.c +++ b/gui.c @@ -1096,19 +1096,23 @@ check_return: goto repeat; } -/* - * read from command pipe and print data to bot window - */ -static void send_output(void) +/* read from command pipe and print data to bot window */ +static void exec_and_display_cmd(const char *cmd) { - int ret; + int ret, fds[3] = {0, 1, 1}; - ret = mark_fd_nonblocking(command_fds[0]); + outputf(COLOR_COMMAND, "%s", cmd); + ret = para_exec_cmdline_pid(&cmd_pid, cmd, fds); + if (ret < 0) + return; + ret = mark_fd_nonblocking(fds[1]); if (ret < 0) goto fail; - ret = mark_fd_nonblocking(command_fds[1]); + ret = mark_fd_nonblocking(fds[2]); if (ret < 0) goto fail; + command_fds[0] = fds[1]; + command_fds[1] = fds[2]; if (do_select(COMMAND_MODE) >= 0) PARA_INFO_LOG("command complete\n"); else @@ -1123,34 +1127,18 @@ fail: static void para_cmd(char *cmd) { - int ret, fds[3] = {0, 1, 1}; - char *c = make_message(BINDIR "/para_client -- %s", cmd); + char *c; - outputf(COLOR_COMMAND, "%s", c); print_in_bar(COLOR_MSG, "executing client command, hit any key to abort\n"); - ret = para_exec_cmdline_pid(&cmd_pid, c, fds); + c = make_message(BINDIR "/para_client -- %s", cmd); + exec_and_display_cmd(c); free(c); - if (ret < 0) - return; - command_fds[0] = fds[1]; - command_fds[1] = fds[2]; - send_output(); } -/* - * exec command and print output to bot win - */ static void display_cmd(char *cmd) { - int fds[3] = {0, 1, 1}; - print_in_bar(COLOR_MSG, "executing display command, hit any key to abort"); - outputf(COLOR_COMMAND, "%s", cmd); - if (para_exec_cmdline_pid(&cmd_pid, cmd, fds) < 0) - return; - command_fds[0] = fds[1]; - command_fds[1] = fds[2]; - send_output(); + exec_and_display_cmd(cmd); } /* -- 2.39.5