Index: usr.bin/top/display.c =================================================================== --- usr.bin/top/display.c +++ usr.bin/top/display.c @@ -57,9 +57,8 @@ static int lmpid = 0; static int last_hi = 0; /* used in u_process and u_endscreen */ static int lastline = 0; -static int display_width = MAX_COLS; -#define lineindex(l) ((l)*display_width) +#define lineindex(l) ((l)*screen_width) /* things initialized by display_init and used thruout */ @@ -138,17 +137,9 @@ if (lines < 0) lines = 0; - /* we don't want more than MAX_COLS columns, since the machine-dependent - modules make static allocations based on MAX_COLS and we don't want - to run off the end of their buffers */ - display_width = screen_width; - if (display_width >= MAX_COLS) - { - display_width = MAX_COLS - 1; - } /* now, allocate space for the screen buffer */ - screenbuf = calloc(lines, display_width); + screenbuf = calloc(lines, screen_width); if (screenbuf == NULL) { /* oops! */ @@ -336,8 +327,23 @@ } static int ltotal = 0; -static char procstates_buffer[MAX_COLS]; +static char *procstates_buffer = NULL; +static int any_buffer_size = 0; +#define SETUP_BUFFER(BUFNAME, ADDLEN) \ + if (NULL == BUFNAME) { \ + any_buffer_size = screen_width; \ + BUFNAME = calloc(sizeof(char) * \ + (any_buffer_size + ADDLEN), 1); \ + } else { \ + if (screen_width > any_buffer_size) { \ + any_buffer_size = screen_width; \ + free(BUFNAME); \ + BUFNAME = calloc(sizeof(char) * \ + (any_buffer_size + ADDLEN), 1); \ + } \ + } + /* * *_procstates(total, brkdn, names) - print the process summary line * @@ -350,6 +356,8 @@ { int i; + SETUP_BUFFER(procstates_buffer, 0) + /* write current number of processes and remember the value */ printf("%d %s:", total, (ps.thread) ? "threads" :"processes"); ltotal = total; @@ -372,9 +380,11 @@ void u_procstates(int total, int *brkdn) { - static char new[MAX_COLS]; + static char *new = NULL; int i; + SETUP_BUFFER(new, 0) + /* update number of processes only if it has changed */ if (ltotal != total) { @@ -551,11 +561,13 @@ * for i_memory ONLY: cursor is on the previous line */ -static char memory_buffer[MAX_COLS]; +static char *memory_buffer = NULL; void i_memory(int *stats) { + SETUP_BUFFER(memory_buffer, 0) + fputs("\nMem: ", stdout); lastline++; @@ -567,8 +579,10 @@ void u_memory(int *stats) { - static char new[MAX_COLS]; + static char *new = NULL; + SETUP_BUFFER(new, 0) + /* format the new line */ summary_format(new, stats, memory_names); line_update(memory_buffer, new, x_mem, y_mem); @@ -580,11 +594,13 @@ * Assumptions: cursor is on "lastline" * for i_arc ONLY: cursor is on the previous line */ -static char arc_buffer[MAX_COLS]; +static char *arc_buffer = NULL; void i_arc(int *stats) { + SETUP_BUFFER(arc_buffer, 0) + if (arc_names == NULL) return; @@ -599,8 +615,10 @@ void u_arc(int *stats) { - static char new[MAX_COLS]; + static char *new = NULL; + SETUP_BUFFER(new, 0) + if (arc_names == NULL) return; @@ -616,11 +634,13 @@ * Assumptions: cursor is on "lastline" * for i_carc ONLY: cursor is on the previous line */ -static char carc_buffer[MAX_COLS]; +static char *carc_buffer = NULL; void i_carc(int *stats) { + SETUP_BUFFER(carc_buffer, 0) + if (carc_names == NULL) return; @@ -635,8 +655,10 @@ void u_carc(int *stats) { - static char new[MAX_COLS]; + static char *new = NULL; + SETUP_BUFFER(new, 0) + if (carc_names == NULL) return; @@ -652,11 +674,13 @@ * for i_swap ONLY: cursor is on the previous line */ -static char swap_buffer[MAX_COLS]; +static char *swap_buffer = NULL; void i_swap(int *stats) { + SETUP_BUFFER(swap_buffer, 0) + fputs("\nSwap: ", stdout); lastline++; @@ -668,8 +692,10 @@ void u_swap(int *stats) { - static char new[MAX_COLS]; + static char *new = NULL; + SETUP_BUFFER(new, 0) + /* format the new line */ summary_format(new, stats, swap_names); line_update(swap_buffer, new, x_swap, y_swap); @@ -689,7 +715,7 @@ * respect to screen updates). */ -static char next_msg[MAX_COLS + 5]; +static char *next_msg = NULL; static int msglen = 0; /* Invariant: msglen is always the length of the message currently displayed on the screen (even when next_msg doesn't contain that message). */ @@ -697,6 +723,7 @@ void i_message(void) { + SETUP_BUFFER(next_msg, 5) while (lastline < y_message) { @@ -736,7 +763,7 @@ int width; s = NULL; - width = display_width; + width = screen_width; header_length = strlen(text); if (header_length >= width) { s = strndup(text, width); @@ -807,7 +834,7 @@ } /* truncate the line to conform to our current screen width */ - thisline[display_width] = '\0'; + thisline[screen_width] = '\0'; /* write the line out */ fputs(thisline, stdout); @@ -817,7 +844,7 @@ p = stpcpy(base, thisline); /* zero fill the rest of it */ - memset(p, 0, display_width - (p - base)); + memset(p, 0, screen_width - (p - base)); } void @@ -831,7 +858,7 @@ bufferline = &screenbuf[lineindex(line)]; /* truncate the line to conform to our current screen width */ - newline[display_width] = '\0'; + newline[screen_width] = '\0'; /* is line higher than we went on the last display? */ if (line >= last_hi) @@ -856,7 +883,7 @@ optr = stpcpy(bufferline, newline); /* zero fill the rest of it */ - memset(optr, 0, display_width - (optr - bufferline)); + memset(optr, 0, screen_width - (optr - bufferline)); } else { @@ -1235,7 +1262,7 @@ } while (ch != '\0'); /* zero out the rest of the line buffer -- MUST BE DONE! */ - diff = display_width - newcol; + diff = screen_width - newcol; if (diff > 0) { memset(old, 0, diff); Index: usr.bin/top/machine.c =================================================================== --- usr.bin/top/machine.c +++ usr.bin/top/machine.c @@ -870,7 +870,7 @@ long p_tot, s_tot; char *cmdbuf = NULL; char **args; - const int cmdlen = 256; + const int cmdlen = screen_width; static struct sbuf* procbuf = NULL; /* clean up from last time. */ Index: usr.bin/top/screen.c =================================================================== --- usr.bin/top/screen.c +++ usr.bin/top/screen.c @@ -62,8 +62,7 @@ char *term_name; int status; - /* set defaults in case we aren't smart */ - screen_width = MAX_COLS; + screen_width = 0; screen_length = 0; if (!interactive) Index: usr.bin/top/top.h =================================================================== --- usr.bin/top/top.h +++ usr.bin/top/top.h @@ -13,9 +13,6 @@ /* Number of lines of header information on the standard screen */ extern int Header_lines; -/* Maximum number of columns allowed for display */ -#define MAX_COLS 512 - /* Special atoi routine returns either a non-negative number or one of: */ #define Infinity -1 #define Invalid -2