Apply the FreeBSD-local patches.

Obtained from:	The ports collection.
This commit is contained in:
Joerg Wunsch 1997-03-23 18:53:01 +00:00
parent 583a088157
commit 6ab598d69b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=24142
7 changed files with 107 additions and 17 deletions

View File

@ -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 */
@ -531,6 +538,40 @@ int *stats;
line_update(memory_buffer, new, x_mem, y_mem);
}
/*
* *_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;
}

View File

@ -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

View File

@ -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,

View File

@ -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;

View File

@ -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

View File

@ -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);
}

View File

@ -21,3 +21,4 @@ long percentages();
char *errmsg();
char *format_time();
char *format_k();
char *format_k2();