From 871d20f6944e3f8fbb1fa40aeb2801c9a85badf6 Mon Sep 17 00:00:00 2001 From: Xin Li Date: Fri, 16 Dec 2011 13:25:28 -0800 Subject: [PATCH 09/65] Better output look and feel for top(1) on multiprocessor systems. --- contrib/top/display.c | 12 ++++++++++-- contrib/top/top.h | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/contrib/top/display.c b/contrib/top/display.c index 89795c0..926a803 100644 --- a/contrib/top/display.c +++ b/contrib/top/display.c @@ -723,7 +723,7 @@ char *text; int width; s = NULL; - width = display_width; + width = screen_width; header_length = strlen(text); if (header_length >= width) { s = malloc((width + 1) * sizeof(char)); @@ -731,6 +731,14 @@ char *text; return (NULL); strncpy(s, text, width); s[width] = '\0'; + } else { + s = malloc((width + 1) * sizeof(char)); + if (s == NULL) + return (NULL); + strncpy(s, text, width); + while (screen_width > header_length) + s[header_length++] = ' '; + s[width] = '\0'; } return (s); } @@ -755,7 +763,7 @@ char *text; if (header_status == ON) { putchar('\n'); - fputs(text, stdout); + standout(text, stdout); lastline++; } else if (header_status == ERASE) diff --git a/contrib/top/top.h b/contrib/top/top.h index a281957..c51485a 100644 --- a/contrib/top/top.h +++ b/contrib/top/top.h @@ -14,7 +14,7 @@ extern int Header_lines; /* 7 */ /* Maximum number of columns allowed for display */ -#define MAX_COLS 128 +#define MAX_COLS 512 /* Log base 2 of 1024 is 10 (2^10 == 1024) */ #define LOG1024 10 -- 1.7.8.3