string: Add discard feature for for_each_line().
[paraslash.git] / gui.c
diff --git a/gui.c b/gui.c
index 7bb74e6f484a2ab0731f77a121b95d06af1b2c93..85d77c9e581d060c5a97c543361aaf95a499ee21 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -982,6 +982,7 @@ static int do_select(int mode)
        char command_buf[2][COMMAND_BUF_SIZE] = {"", ""};
        int cbo[2] = {0, 0}; /* command buf offsets */
        struct timeval tv;
+       unsigned flags[2] = {0, 0}; /* for for_each_line() */
 
 repeat:
        tv.tv_sec = conf.timeout_arg  / 1000;
@@ -1019,21 +1020,25 @@ repeat:
                                COMMAND_BUF_SIZE - 1 - cbo[i], &rfds, &sz);
                        cbo[i] += sz;
                        sz = cbo[i];
-                       cbo[i] = for_each_line(0, command_buf[i], cbo[i],
+                       cbo[i] = for_each_line(flags[i], command_buf[i], cbo[i],
                                add_output_line, &i);
-                       if (sz != cbo[i])
+                       if (sz != cbo[i]) { /* at least one line found */
                                wrefresh(bot.win);
+                               flags[i] = 0;
+                       }
                        if (ret < 0) {
                                PARA_NOTICE_LOG("closing command fd %d: %s",
                                        i, para_strerror(-ret));
                                close(command_fds[i]);
                                command_fds[i] = -1;
+                               flags[i] = 0;
                                if (command_fds[!i] < 0) /* both fds closed */
                                        return 0;
                        }
                        if (cbo[i] == COMMAND_BUF_SIZE - 1) {
                                PARA_NOTICE_LOG("discarding overlong line");
                                cbo[i] = 0;
+                               flags[i] = FELF_DISCARD_FIRST;
                        }
                }
        }