From e571e75266c1a75ac309339c04879886cbd298cf Mon Sep 17 00:00:00 2001 From: joerg Date: Sun, 23 Mar 1997 18:53:01 +0000 Subject: Apply the FreeBSD-local patches. Obtained from: The ports collection. --- contrib/top/display.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- contrib/top/layout.h | 12 +++++++----- contrib/top/machine.h | 2 ++ contrib/top/top.c | 15 +++++++++++++-- contrib/top/top.h | 2 +- contrib/top/utils.c | 47 ++++++++++++++++++++++++++++++++++++++++------- contrib/top/utils.h | 1 + 7 files changed, 107 insertions(+), 17 deletions(-) (limited to 'contrib/top') diff --git a/contrib/top/display.c b/contrib/top/display.c index 0769e3f..6b3a5f4 100644 --- a/contrib/top/display.c +++ b/contrib/top/display.c @@ -63,14 +63,17 @@ char *screenbuf = NULL; static char **procstate_names; static char **cpustate_names; static char **memory_names; +static char **swap_names; static int num_procstates; static int num_cpustates; static int num_memory; +static int num_swap; static int *lprocstates; static int *lcpustates; static int *lmemory; +static int *lswap; static int *cpustate_columns; static int cpustate_total_length; @@ -140,6 +143,10 @@ struct statics *statics; lprocstates = (int *)malloc(num_procstates * sizeof(int)); cpustate_names = statics->cpustate_names; + + swap_names = statics->swap_names; + num_swap = string_count(swap_names); + lswap = (int *)malloc(num_swap * sizeof(int)); num_cpustates = string_count(cpustate_names); lcpustates = (int *)malloc(num_cpustates * sizeof(int)); cpustate_columns = (int *)malloc(num_cpustates * sizeof(int)); @@ -511,7 +518,7 @@ i_memory(stats) int *stats; { - fputs("\nMemory: ", stdout); + fputs("\nMem: ", stdout); lastline++; /* format and print the memory summary */ @@ -532,6 +539,40 @@ int *stats; } /* + * *_swap(stats) - print "Swap: " followed by the swap summary string + * + * Assumptions: cursor is on "lastline" + * for i_swap ONLY: cursor is on the previous line + */ + +char swap_buffer[MAX_COLS]; + +i_swap(stats) + +int *stats; + +{ + fputs("\nSwap: ", stdout); + lastline++; + + /* format and print the swap summary */ + summary_format(swap_buffer, stats, swap_names); + fputs(swap_buffer, stdout); +} + +u_swap(stats) + +int *stats; + +{ + static char new[MAX_COLS]; + + /* format the new line */ + summary_format(new, stats, swap_names); + line_update(swap_buffer, new, x_swap, y_swap); +} + +/* * *_message() - print the next pending message line, or erase the one * that is there. * @@ -845,7 +886,7 @@ int numeric; while ((fflush(stdout), read(0, ptr, 1) > 0)) { /* newline means we are done */ - if ((ch = *ptr) == '\n') + if ((ch = *ptr) == '\n' || ch == '\r') { break; } diff --git a/contrib/top/layout.h b/contrib/top/layout.h index 77ce102..5db383f 100644 --- a/contrib/top/layout.h +++ b/contrib/top/layout.h @@ -15,13 +15,15 @@ #define y_procstate 1 #define x_brkdn 15 #define y_brkdn 1 -#define x_mem 8 +#define x_mem 5 #define y_mem 3 -#define y_message 4 +#define x_swap 6 +#define y_swap 4 +#define y_message 5 #define x_header 0 -#define y_header 5 +#define y_header 6 #define x_idlecursor 0 -#define y_idlecursor 4 -#define y_procs 6 +#define y_idlecursor 5 +#define y_procs 7 #define y_cpustates 2 diff --git a/contrib/top/machine.h b/contrib/top/machine.h index 4f121a7..243ba27 100644 --- a/contrib/top/machine.h +++ b/contrib/top/machine.h @@ -12,6 +12,7 @@ struct statics char **procstate_names; char **cpustate_names; char **memory_names; + char **swap_names; #ifdef ORDER char **order_names; #endif @@ -30,6 +31,7 @@ struct system_info int *procstates; int *cpustates; int *memory; + int *swap; }; /* cpu_states is an array of percentages * 10. For example, diff --git a/contrib/top/top.c b/contrib/top/top.c index 55bee4e..1902abb 100644 --- a/contrib/top/top.c +++ b/contrib/top/top.c @@ -111,6 +111,8 @@ int i_cpustates(); int u_cpustates(); int i_memory(); int u_memory(); +int i_swap(); +int u_swap(); int i_message(); int u_message(); int i_header(); @@ -123,6 +125,7 @@ int (*d_loadave)() = i_loadave; int (*d_procstates)() = i_procstates; int (*d_cpustates)() = i_cpustates; int (*d_memory)() = i_memory; +int (*d_swap)() = i_swap; int (*d_message)() = i_message; int (*d_header)() = i_header; int (*d_process)() = i_process; @@ -568,6 +571,9 @@ Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n", /* display memory stats */ (*d_memory)(system_info.memory); + /* display swap stats */ + (*d_swap)(system_info.swap); + /* handle message area */ (*d_message)(); @@ -622,6 +628,7 @@ Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n", d_procstates = u_procstates; d_cpustates = u_cpustates; d_memory = u_memory; + d_swap = u_swap; d_message = u_message; d_header = u_header; d_process = u_process; @@ -663,8 +670,11 @@ Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n", (void) read(0, &ch, 1); if ((iptr = strchr(command_chars, ch)) == NULL) { - /* illegal command */ - new_message(MT_standout, " Command not understood"); + if (ch != '\r' && ch != '\n') + { + /* illegal command */ + new_message(MT_standout, " Command not understood"); + } putchar('\r'); no_command = Yes; } @@ -909,6 +919,7 @@ reset_display() d_procstates = i_procstates; d_cpustates = i_cpustates; d_memory = i_memory; + d_swap = i_swap; d_message = i_message; d_header = i_header; d_process = i_process; diff --git a/contrib/top/top.h b/contrib/top/top.h index 8f50922..aeed136 100644 --- a/contrib/top/top.h +++ b/contrib/top/top.h @@ -8,7 +8,7 @@ #define VERSION 3 /* Number of lines of header information on the standard screen */ -#define Header_lines 6 +#define Header_lines 7 /* Maximum number of columns allowed for display */ #define MAX_COLS 128 diff --git a/contrib/top/utils.c b/contrib/top/utils.c index 67b64e9..e136d2a 100644 --- a/contrib/top/utils.c +++ b/contrib/top/utils.c @@ -308,9 +308,13 @@ long *diffs; /* calculate percentages based on overall change, rounding up */ half_total = total_change / 2l; - for (i = 0; i < cnt; i++) - { - *out++ = (int)((*diffs++ * 1000 + half_total) / total_change); + + /* Do not divide by 0. Causes Floating point exception */ + if(total_change) { + for (i = 0; i < cnt; i++) + { + *out++ = (int)((*diffs++ * 1000 + half_total) / total_change); + } } /* return the total in case the caller wants to use it */ @@ -329,9 +333,6 @@ long *diffs; /* externs referenced by errmsg */ -extern char *sys_errlist[]; -extern int sys_nerr; - char *errmsg(errnum) int errnum; @@ -339,7 +340,7 @@ int errnum; { if (errnum > 0 && errnum < sys_nerr) { - return(sys_errlist[errnum]); + return((char *)sys_errlist[errnum]); } return("No error"); } @@ -451,3 +452,35 @@ int amt; return(ret); } + +char *format_k2(amt) + +int amt; + +{ + static char retarray[NUM_STRINGS][16]; + static int index = 0; + register char *p; + register char *ret; + register char tag = 'K'; + + p = ret = retarray[index]; + index = (index + 1) % NUM_STRINGS; + + if (amt >= 100000) + { + amt = (amt + 512) / 1024; + tag = 'M'; + if (amt >= 100000) + { + amt = (amt + 512) / 1024; + tag = 'G'; + } + } + + p = strecpy(p, itoa(amt)); + *p++ = tag; + *p = '\0'; + + return(ret); +} diff --git a/contrib/top/utils.h b/contrib/top/utils.h index 628a0be..6717092 100644 --- a/contrib/top/utils.h +++ b/contrib/top/utils.h @@ -21,3 +21,4 @@ long percentages(); char *errmsg(); char *format_time(); char *format_k(); +char *format_k2(); -- cgit v1.1