]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - gui.c
gui: Move signal handling code out of do_select().
[paraslash.git] / gui.c
diff --git a/gui.c b/gui.c
index 5f51cfceec026bbafeb36f7eb1bd24d2ddecb4c7..70981e898ba7de929d56a8ee448cbbeff10040c3 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -916,9 +916,12 @@ static void reread_conf(void)
 /*
  * React to various signal-related events
  */
-static void handle_signal(int sig)
+static void signal_post_select(fd_set *rfds)
 {
-       switch (sig) {
+       int ret = para_next_signal(rfds);
+       if (ret <= 0)
+               return;
+       switch (ret) {
        case SIGTERM:
                die(EXIT_FAILURE, "only the good die young (caught SIGTERM)\n");
                return;
@@ -1030,6 +1033,44 @@ 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 */
+       }
+}
+
+static void signal_pre_select(fd_set *rfds, int *max_fileno)
+{
+       para_fd_set(signal_pipe, rfds, max_fileno);
+}
+
 /*
  * This is the core select loop. Besides the (internal) signal
  * pipe, the following other fds are checked according to the mode:
@@ -1056,42 +1097,22 @@ repeat:
        FD_ZERO(&rfds);
        max_fileno = 0;
        status_pre_select(&rfds, &max_fileno, &tv);
-       /* signal pipe */
-       para_fd_set(signal_pipe, &rfds, &max_fileno);
+       signal_pre_select(&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 */
-       /* signals */
-       ret = para_next_signal(&rfds);
-       if (ret > 0)
-               handle_signal(ret);
+       signal_post_select(&rfds);
        /* read command pipe if ready */
        ret = command_post_select(mode, &rfds);
        if (ret < 0)
                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;
 }