Pass full argument list to mood parsers.
[paraslash.git] / gui.c
diff --git a/gui.c b/gui.c
index 6806cc8fcc662435cf53a3c01a7b1f6b4607386f..e734b10c8e9e57438075a14a2cc1941f0c28a7b1 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -294,20 +294,23 @@ static void add_spaces(WINDOW* win, unsigned int num)
  * print aligned string to curses window. This function always prints
  * exactly len chars.
  */
-static int align_str(WINDOW* win, const char *string, unsigned int len,
+static int align_str(WINDOW* win, char *str, unsigned int len,
                unsigned int align)
 {
-       int num; /* of spaces */
-       char *str;
+       int i, num; /* of spaces */
 
-       if (!win || !string)
+       if (!win || !str)
                return -1;
-       num = len - strlen(string);
-       str = para_strdup(string);
+       num = len - strlen(str);
        if (num < 0) {
                str[len] = '\0';
                num = 0;
        }
+       /* replace newlines by spaces */
+       for (i = 0; i < len; i++) {
+               if (str[i] == '\n')
+                       str[i] = ' ';
+       }
        if (align == LEFT) {
                waddstr(win, str);
                add_spaces(win, num);
@@ -319,7 +322,6 @@ static int align_str(WINDOW* win, const char *string, unsigned int len,
                waddstr(win, str[0]? str: "");
                add_spaces(win, num - num / 2);
        }
-       free(str);
        return 1;
 }
 
@@ -342,10 +344,14 @@ __printf_2_3 static void print_in_bar(int color, const char *fmt,...)
  */
 static void print_status_bar(void)
 {
+       char *tmp;
+
        if (!curses_active)
                return;
+       tmp = para_strdup(STANDARD_STATUS_BAR);
        wmove(sb.win, 0, 0);
-       align_str(sb.win, STANDARD_STATUS_BAR, sb.cols, CENTER);
+       align_str(sb.win, tmp, sb.cols, CENTER);
+       free(tmp);
        wrefresh(sb.win);
 }
 
@@ -669,9 +675,6 @@ static void print_stat_item(int i)
        wrefresh(top.win);
 }
 
-/*
- * print status line if line starts with known command.
- */
 static int update_item(int item_num, char *buf)
 {
        free(stat_content[item_num]);
@@ -682,13 +685,20 @@ static int update_item(int item_num, char *buf)
 
 static int read_audiod_pipe(int fd)
 {
-       static char buf[8192];
-       static int loaded;
+       static char *buf;
+       static int bufsize, loaded;
        int ret;
 
-       if (loaded >= sizeof(buf)) /* overflow */
-               return 0;
-       ret = read(fd, buf + loaded, sizeof(buf) - loaded);
+       if (loaded >= bufsize) {
+               if (bufsize > 1000 * 1000) {
+                       loaded = 0;
+                       return 0;
+               }
+               bufsize += bufsize + 1000;
+               buf = para_realloc(buf, bufsize);
+       }
+       assert(loaded < bufsize);
+       ret = read(fd, buf + loaded, bufsize - loaded);
        if (ret <= 0)
                return ret;
        loaded += ret;