align_str() made a copy of the given buffer because one of its callers, print_in_bar(),
passes a string literal and align_str() needs to truncate large strings.However, all other
callers pass a writable string anyway, so do the strdup() in print_in_bar(). This avoids the
unnecessary copies for each status item.
The areas for the status items was designed to hold only a part of a single line, so status
item text should not contain newlines. The patch replaces newlines by spaces.
Also get rid of a stale comment.
* print aligned string to curses window. This function always prints
* exactly len chars.
*/
* 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,
- int num; /* of spaces */
- char *str;
+ int i, num; /* of spaces */
- num = len - strlen(string);
- str = para_strdup(string);
+ num = len - strlen(str);
if (num < 0) {
str[len] = '\0';
num = 0;
}
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);
if (align == LEFT) {
waddstr(win, str);
add_spaces(win, num);
waddstr(win, str[0]? str: "");
add_spaces(win, num - num / 2);
}
waddstr(win, str[0]? str: "");
add_spaces(win, num - num / 2);
}
*/
static void print_status_bar(void)
{
*/
static void print_status_bar(void)
{
if (!curses_active)
return;
if (!curses_active)
return;
+ tmp = para_strdup(STANDARD_STATUS_BAR);
- align_str(sb.win, STANDARD_STATUS_BAR, sb.cols, CENTER);
+ align_str(sb.win, tmp, sb.cols, CENTER);
+ free(tmp);
-/*
- * print status line if line starts with known command.
- */
static int update_item(int item_num, char *buf)
{
free(stat_content[item_num]);
static int update_item(int item_num, char *buf)
{
free(stat_content[item_num]);