]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - gui.c
gui: Speed up add_spaces().
[paraslash.git] / gui.c
diff --git a/gui.c b/gui.c
index 65b2ac05d748ab1bb7d24e3b752d906d2ffca5c5..6e44b09d37cc574846f1de0a4d325e586c69dad0 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (C) 1998-2012 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1998-2013 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -50,7 +50,7 @@ static struct ringbuffer *bot_win_rb;
 
 static unsigned scroll_position;
 
 
 static unsigned scroll_position;
 
-static int cmd_died, curses_active;
+static int curses_active;
 static pid_t cmd_pid;
 
 static int command_fds[2];
 static pid_t cmd_pid;
 
 static int command_fds[2];
@@ -287,14 +287,20 @@ static char *configfile_exists(void)
        return file_exists(tmp)? tmp: NULL;
 }
 
        return file_exists(tmp)? tmp: NULL;
 }
 
-/*
- * print num spaces to curses window
- */
+/* Print given number of spaces to curses window. */
 static void add_spaces(WINDOW* win, unsigned int num)
 {
 static void add_spaces(WINDOW* win, unsigned int num)
 {
-       while (num > 0) {
-               num--;
-               waddstr(win, " ");
+       char space[] = "                                ";
+       unsigned sz = sizeof(space);
+
+       while (num >= sz)  {
+               waddstr(win, space);
+               num -= sz;
+       }
+       if (num > 0) {
+               assert(num < sz);
+               space[num] = '\0';
+               waddstr(win, space);
        }
 }
 
        }
 }
 
@@ -533,7 +539,8 @@ static void setup_signal_handling(void)
        para_sigaction(SIGHUP, SIG_IGN);
 }
 
        para_sigaction(SIGHUP, SIG_IGN);
 }
 
-__noreturn static void do_exit(int ret)
+/* kill every process in the process group and exit */
+__noreturn static void kill_pg_and_die(int ret)
 {
        para_sigaction(SIGTERM, SIG_IGN);
        kill(0, SIGTERM);
 {
        para_sigaction(SIGTERM, SIG_IGN);
        kill(0, SIGTERM);
@@ -552,7 +559,7 @@ static void shutdown_curses(void)
 __noreturn static void finish(int ret)
 {
        shutdown_curses();
 __noreturn static void finish(int ret)
 {
        shutdown_curses();
-       do_exit(ret);
+       kill_pg_and_die(ret);
 }
 
 /*
 }
 
 /*
@@ -567,7 +574,7 @@ __noreturn __printf_2_3 static void msg_n_exit(int ret, const char* fmt, ...)
        va_start(argp, fmt);
        vfprintf(outfd, fmt, argp);
        va_end(argp);
        va_start(argp, fmt);
        vfprintf(outfd, fmt, argp);
        va_end(argp);
-       do_exit(ret);
+       kill_pg_and_die(ret);
 }
 
 static void print_welcome(void)
 }
 
 static void print_welcome(void)
@@ -834,10 +841,8 @@ reap_next_child:
        ret = para_reap_child(&pid);
        if (ret <= 0)
                return;
        ret = para_reap_child(&pid);
        if (ret <= 0)
                return;
-       if (pid == cmd_pid) {
+       if (pid == cmd_pid)
                cmd_pid = 0;
                cmd_pid = 0;
-               cmd_died = 1;
-       }
        goto reap_next_child;
 }
 
        goto reap_next_child;
 }
 
@@ -951,7 +956,7 @@ static int open_stat_pipe(void)
        return ret;
 }
 
        return ret;
 }
 
-#define COMMAND_BUF_SIZE 4096
+#define COMMAND_BUF_SIZE 32768
 
 /*
  * This is the core select loop. Besides the (internal) signal
 
 /*
  * This is the core select loop. Besides the (internal) signal
@@ -993,6 +998,8 @@ repeat:
                if (command_fds[1] >= 0)
                        para_fd_set(command_fds[1], &rfds, &max_fileno);
        }
                if (command_fds[1] >= 0)
                        para_fd_set(command_fds[1], &rfds, &max_fileno);
        }
+       if (mode == GETCH_MODE || mode == COMMAND_MODE)
+               para_fd_set(STDIN_FILENO, &rfds, &max_fileno);
        ret = para_select(max_fileno + 1, &rfds, NULL, &tv);
        if (ret <= 0)
                goto check_return; /* skip fd checks */
        ret = para_select(max_fileno + 1, &rfds, NULL, &tv);
        if (ret <= 0)
                goto check_return; /* skip fd checks */
@@ -1023,6 +1030,10 @@ repeat:
                                if (command_fds[!i] < 0) /* both fds closed */
                                        return 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;
+                       }
                }
        }
        ret = read_stat_pipe(&rfds);
                }
        }
        ret = read_stat_pipe(&rfds);
@@ -1060,10 +1071,8 @@ check_return:
                        return ret;
                break;
        case EXTERNAL_MODE:
                        return ret;
                break;
        case EXTERNAL_MODE:
-               if (cmd_died) {
-                       cmd_died = 0;
+               if (cmd_pid == 0)
                        return 0;
                        return 0;
-               }
        }
        goto repeat;
 }
        }
        goto repeat;
 }
@@ -1137,7 +1146,6 @@ static void external_cmd(char *cmd)
        shutdown_curses();
        if (para_exec_cmdline_pid(&cmd_pid, cmd, fds) < 0)
                return;
        shutdown_curses();
        if (para_exec_cmdline_pid(&cmd_pid, cmd, fds) < 0)
                return;
-       cmd_died = 0;
        do_select(EXTERNAL_MODE);
        init_curses();
 }
        do_select(EXTERNAL_MODE);
        init_curses();
 }
@@ -1486,8 +1494,7 @@ int main(int argc, char *argv[])
        _argc = argc;
        _argv = argv;
 
        _argc = argc;
        _argv = argv;
 
-       if (gui_cmdline_parser(argc, argv, &conf) != 0)
-               exit(EXIT_FAILURE);
+       gui_cmdline_parser(argc, argv, &conf); /* exits on errors */
        HANDLE_VERSION_FLAG("gui", conf);
        cf = configfile_exists();
        if (!cf && conf.config_file_given) {
        HANDLE_VERSION_FLAG("gui", conf);
        cf = configfile_exists();
        if (!cf && conf.config_file_given) {