projects
/
paraslash.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
gui: Avoid unnecessary strdup's and replace newlines by spaces in curses output.
[paraslash.git]
/
gui.c
diff --git
a/gui.c
b/gui.c
index
21770ca
..
e734b10
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.
*/
* print aligned string to curses window. This function always prints
* exactly len chars.
*/
-static int align_str(WINDOW* win, c
onst char *string
, unsigned int len,
+static int align_str(WINDOW* win, c
har *str
, unsigned int len,
unsigned int align)
{
unsigned int align)
{
- int num; /* of spaces */
- char *str;
+ int i, num; /* of spaces */
- if (!win || !str
ing
)
+ if (!win || !str)
return -1;
return -1;
- 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);
@@
-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);
}
waddstr(win, str[0]? str: "");
add_spaces(win, num - num / 2);
}
- free(str);
return 1;
}
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)
{
*/
static void print_status_bar(void)
{
+ char *tmp;
+
if (!curses_active)
return;
if (!curses_active)
return;
+ tmp = para_strdup(STANDARD_STATUS_BAR);
wmove(sb.win, 0, 0);
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);
}
wrefresh(sb.win);
}
@@
-669,9
+675,6
@@
static void print_stat_item(int i)
wrefresh(top.win);
}
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]);
static int update_item(int item_num, char *buf)
{
free(stat_content[item_num]);