From: Andre Noll Date: Fri, 3 Jan 2014 18:49:19 +0000 (+0000) Subject: gui: Move input related code out of do_select(). X-Git-Tag: v0.5.3~12^2~16 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=f127354753a643a070958f577f31251a3f58115f;hp=2436fd444428d2549575fe40484ffae9dc11e58e gui: Move input related code out of do_select(). This moves the relevant part of do_select() into the new functions input_pre_select() and input_post_select(). --- diff --git a/gui.c b/gui.c index 5f51cfce..ae585b8b 100644 --- a/gui.c +++ b/gui.c @@ -1030,6 +1030,39 @@ static int command_post_select(int mode, fd_set *rfds) return 1; } +static void input_pre_select(int mode, fd_set *rfds, int *max_fileno) +{ + if (mode == GETCH_MODE || mode == COMMAND_MODE) + para_fd_set(STDIN_FILENO, rfds, max_fileno); +} + +static int input_post_select(int mode) +{ + int ret; + + switch (mode) { + case COMMAND_MODE: + ret = wgetch(top.win); + if (ret != ERR && ret != KEY_RESIZE) { + if (cmd_pid) + kill(cmd_pid, SIGTERM); + return -1; + } + return 0; + case GETCH_MODE: + ret = wgetch(top.win); + if (ret != ERR && ret != KEY_RESIZE) + return ret; + return 0; + case EXTERNAL_MODE: + if (cmd_pid == 0) + return -1; + return 0; + default: + assert(false); /* bug */ + } +} + /* * This is the core select loop. Besides the (internal) signal * pipe, the following other fds are checked according to the mode: @@ -1059,8 +1092,7 @@ repeat: /* signal pipe */ para_fd_set(signal_pipe, &rfds, &max_fileno); command_pre_select(mode, &rfds, &max_fileno); - if (mode == GETCH_MODE || mode == COMMAND_MODE) - para_fd_set(STDIN_FILENO, &rfds, &max_fileno); + input_pre_select(mode, &rfds, &max_fileno); ret = para_select(max_fileno + 1, &rfds, NULL, &tv); if (ret <= 0) goto check_return; /* skip fd checks */ @@ -1074,24 +1106,9 @@ repeat: return 0; status_post_select(&rfds); check_return: - switch (mode) { - case COMMAND_MODE: - ret = wgetch(top.win); - if (ret != ERR && ret != KEY_RESIZE) { - if (cmd_pid) - kill(cmd_pid, SIGTERM); - return -1; - } - break; - case GETCH_MODE: - ret = wgetch(top.win); - if (ret != ERR && ret != KEY_RESIZE) - return ret; - break; - case EXTERNAL_MODE: - if (cmd_pid == 0) - return 0; - } + ret = input_post_select(mode); + if (ret != 0) + return ret; goto repeat; }