X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=gui.c;h=933729a26c9e530570a8bf01418f6e839fcf535d;hp=f2115832ec3a0773105c152b88e25048873c1a8b;hb=5b8e525dfb2f18a4e0d67b9da264259159ad2184;hpb=c8862b9e246b4ef6ff1fe103946e18cf2537ecde diff --git a/gui.c b/gui.c index f2115832..933729a2 100644 --- a/gui.c +++ b/gui.c @@ -4,7 +4,7 @@ * Licensed under the GPL v2. For licencing details see COPYING. */ -/** \file gui.c ncurses-based interface for paraslash */ +/** \file gui.c Curses-based interface for paraslash. */ #include #include @@ -12,9 +12,9 @@ #include "gui.cmdline.h" #include "para.h" #include "gui.h" +#include "string.h" #include #include "ringbuffer.h" -#include "gui_common.h" #include "fd.h" #include "error.h" #include "list.h" @@ -29,8 +29,6 @@ static char *stat_content[NUM_STAT_ITEMS]; static int signal_pipe; -static void finish(int sig); - static struct win_data { WINDOW *win; NCURSES_SIZE_T begx; @@ -45,7 +43,7 @@ struct rb_entry { size_t len; int color; }; -void *bot_win_rb; +struct ringbuffer *bot_win_rb; #define NUM_LINES(len) (1 + (len) / bot.cols) static unsigned scroll_position; @@ -191,6 +189,38 @@ struct gui_command command_list[] = { } }; +static int para_open_audiod_pipe(char *cmd) +{ + int fds[3] = {0, 1, 0}; + pid_t pid; + int ret = para_exec_cmdline_pid(&pid, cmd, fds); + if (ret < 0) + return ret; + ret = mark_fd_nonblocking(fds[1]); + if (ret > 0) + return fds[1]; + close(fds[1]); + return ret; +} + +static int read_audiod_pipe(int fd, line_handler_t *line_handler) +{ + static char buf[4096]; + const ssize_t bufsize = sizeof(buf) - 1; + static ssize_t loaded; + ssize_t ret; + + if (loaded >= bufsize) + loaded = 0; + ret = read(fd, buf + loaded, bufsize - loaded); + if (ret > 0) { + loaded += ret; + buf[loaded] = '\0'; + loaded = for_each_line(buf, loaded, line_handler, NULL); + } + return ret; +} + static int find_cmd_byname(char *name) { int i; @@ -966,8 +996,15 @@ check_return: */ static int send_output(void) { + int ret; + if (command_pipe < 0) return 0; + ret = mark_fd_nonblocking(command_pipe); + if (ret < 0) { + close(command_pipe); + return ret; + } if (do_select(COMMAND_MODE) >= 0) PARA_INFO_LOG("%s", "command complete"); else @@ -988,7 +1025,6 @@ static int client_cmd_cmdline(char *cmd) if (ret < 0) return -1; command_pipe = fds[1]; - mark_fd_nonblocking(command_pipe); return send_output(); } @@ -1004,7 +1040,6 @@ static int display_cmd(char *cmd) if (para_exec_cmdline_pid(&cmd_pid, cmd, fds) < 0) return -1; command_pipe = fds[1]; - mark_fd_nonblocking(command_pipe); return send_output(); }