Changeset View
Changeset View
Standalone View
Standalone View
display.c
Show All 23 Lines | |||||
* have minimal (or nonexistant) terminal capabilities. | * have minimal (or nonexistant) terminal capabilities. | ||||
* | * | ||||
* The routines are called in this order: *_loadave, i_timeofday, | * The routines are called in this order: *_loadave, i_timeofday, | ||||
* *_procstates, *_cpustates, *_memory, *_message, *_header, | * *_procstates, *_cpustates, *_memory, *_message, *_header, | ||||
* *_process, u_endscreen. | * *_process, u_endscreen. | ||||
*/ | */ | ||||
#include "os.h" | #include "os.h" | ||||
#include <sys/time.h> | |||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include <sys/time.h> | #include <unistd.h> | ||||
#include "screen.h" /* interface to screen package */ | #include "screen.h" /* interface to screen package */ | ||||
#include "layout.h" /* defines for screen position layout */ | #include "layout.h" /* defines for screen position layout */ | ||||
#include "display.h" | #include "display.h" | ||||
#include "top.h" | #include "top.h" | ||||
#include "top.local.h" | #include "top.local.h" | ||||
#include "boolean.h" | #include "boolean.h" | ||||
#include "machine.h" /* we should eliminate this!!! */ | #include "machine.h" /* we should eliminate this!!! */ | ||||
#include "utils.h" | #include "utils.h" | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
FILE *debug; | FILE *debug; | ||||
#endif | #endif | ||||
/* imported from screen.c */ | /* imported from screen.c */ | ||||
extern int overstrike; | extern int overstrike; | ||||
static int lmpid = 0; | static int lmpid = 0; | ||||
static int last_hi = 0; /* used in u_process and u_endscreen */ | static int last_hi = 0; /* used in u_process and u_endscreen */ | ||||
static int lastline = 0; | static int lastline = 0; | ||||
static int display_width = MAX_COLS; | static int display_width = MAX_COLS; | ||||
#define lineindex(l) ((l)*display_width) | #define lineindex(l) ((l)*display_width) | ||||
char *printable(); | |||||
/* things initialized by display_init and used thruout */ | /* things initialized by display_init and used thruout */ | ||||
/* buffer of proc information lines for display updating */ | /* buffer of proc information lines for display updating */ | ||||
char *screenbuf = NULL; | char *screenbuf = NULL; | ||||
static char **procstate_names; | static char **procstate_names; | ||||
static char **cpustate_names; | static char **cpustate_names; | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | cpustate_total_length += i + 8; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/* return number of lines available */ | /* return number of lines available */ | ||||
return(lines); | return(lines); | ||||
} | } | ||||
void | |||||
i_loadave(mpid, avenrun) | i_loadave(mpid, avenrun) | ||||
int mpid; | int mpid; | ||||
double *avenrun; | double *avenrun; | ||||
{ | { | ||||
register int i; | register int i; | ||||
Show All 12 Lines | printf("last pid: %5d; ", mpid); | ||||
{ | { | ||||
printf("%c %5.2f", | printf("%c %5.2f", | ||||
i == 0 ? ':' : ',', | i == 0 ? ':' : ',', | ||||
avenrun[i]); | avenrun[i]); | ||||
} | } | ||||
lmpid = mpid; | lmpid = mpid; | ||||
} | } | ||||
void | |||||
u_loadave(mpid, avenrun) | u_loadave(mpid, avenrun) | ||||
int mpid; | int mpid; | ||||
double *avenrun; | double *avenrun; | ||||
{ | { | ||||
register int i; | register int i; | ||||
Show All 23 Lines | i = x_loadave_nompid; | ||||
for (i = 0; i < 3; i++) | for (i = 0; i < 3; i++) | ||||
{ | { | ||||
printf("%s%5.2f", | printf("%s%5.2f", | ||||
i == 0 ? "" : ", ", | i == 0 ? "" : ", ", | ||||
avenrun[i]); | avenrun[i]); | ||||
} | } | ||||
} | } | ||||
void | |||||
i_timeofday(tod) | i_timeofday(tod) | ||||
time_t *tod; | time_t *tod; | ||||
{ | { | ||||
/* | /* | ||||
* Display the current time. | * Display the current time. | ||||
* "ctime" always returns a string that looks like this: | * "ctime" always returns a string that looks like this: | ||||
Show All 29 Lines | |||||
/* | /* | ||||
* *_procstates(total, brkdn, names) - print the process summary line | * *_procstates(total, brkdn, names) - print the process summary line | ||||
* | * | ||||
* Assumptions: cursor is at the beginning of the line on entry | * Assumptions: cursor is at the beginning of the line on entry | ||||
* lastline is valid | * lastline is valid | ||||
*/ | */ | ||||
void | |||||
i_procstates(total, brkdn) | i_procstates(total, brkdn) | ||||
int total; | int total; | ||||
int *brkdn; | int *brkdn; | ||||
{ | { | ||||
register int i; | register int i; | ||||
Show All 11 Lines | putchar(' '); | ||||
/* format and print the process state summary */ | /* format and print the process state summary */ | ||||
summary_format(procstates_buffer, brkdn, procstate_names); | summary_format(procstates_buffer, brkdn, procstate_names); | ||||
fputs(procstates_buffer, stdout); | fputs(procstates_buffer, stdout); | ||||
/* save the numbers for next time */ | /* save the numbers for next time */ | ||||
memcpy(lprocstates, brkdn, num_procstates * sizeof(int)); | memcpy(lprocstates, brkdn, num_procstates * sizeof(int)); | ||||
} | } | ||||
void | |||||
u_procstates(total, brkdn) | u_procstates(total, brkdn) | ||||
int total; | int total; | ||||
int *brkdn; | int *brkdn; | ||||
{ | { | ||||
static char new[MAX_COLS]; | static char new[MAX_COLS]; | ||||
register int i; | register int i; | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | use = long_tag; | ||||
} | } | ||||
/* set cpustates_column accordingly then return result */ | /* set cpustates_column accordingly then return result */ | ||||
cpustates_column = strlen(use); | cpustates_column = strlen(use); | ||||
return(use); | return(use); | ||||
} | } | ||||
#endif | #endif | ||||
void | |||||
i_cpustates(states) | i_cpustates(states) | ||||
register int *states; | int *states; | ||||
{ | { | ||||
register int i = 0; | register int i = 0; | ||||
register int value; | register int value; | ||||
register char **names; | register char **names; | ||||
register char *thisname; | register char *thisname; | ||||
int cpu; | int cpu; | ||||
Show All 26 Lines | for (cpu = 0; cpu < num_cpus; cpu++) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/* copy over values into "last" array */ | /* copy over values into "last" array */ | ||||
memcpy(lcpustates, states, num_cpustates * sizeof(int) * num_cpus); | memcpy(lcpustates, states, num_cpustates * sizeof(int) * num_cpus); | ||||
} | } | ||||
void | |||||
u_cpustates(states) | u_cpustates(states) | ||||
register int *states; | int *states; | ||||
{ | { | ||||
register int value; | register int value; | ||||
register char **names; | register char **names; | ||||
register char *thisname; | register char *thisname; | ||||
register int *lp; | register int *lp; | ||||
register int *colp; | register int *colp; | ||||
int cpu; | int cpu; | ||||
Show All 33 Lines | for (cpu = 0; cpu < num_cpus; cpu++) { | ||||
/* increment and move on */ | /* increment and move on */ | ||||
lp++; | lp++; | ||||
states++; | states++; | ||||
colp++; | colp++; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void | |||||
z_cpustates() | z_cpustates() | ||||
{ | { | ||||
register int i = 0; | register int i = 0; | ||||
register char **names; | register char **names; | ||||
register char *thisname; | register char *thisname; | ||||
register int *lp; | register int *lp; | ||||
int cpu, value; | int cpu, value; | ||||
Show All 33 Lines | |||||
* *_memory(stats) - print "Memory: " followed by the memory summary string | * *_memory(stats) - print "Memory: " followed by the memory summary string | ||||
* | * | ||||
* Assumptions: cursor is on "lastline" | * Assumptions: cursor is on "lastline" | ||||
* for i_memory ONLY: cursor is on the previous line | * for i_memory ONLY: cursor is on the previous line | ||||
*/ | */ | ||||
char memory_buffer[MAX_COLS]; | char memory_buffer[MAX_COLS]; | ||||
void | |||||
i_memory(stats) | i_memory(stats) | ||||
int *stats; | int *stats; | ||||
{ | { | ||||
fputs("\nMem: ", stdout); | fputs("\nMem: ", stdout); | ||||
lastline++; | lastline++; | ||||
/* format and print the memory summary */ | /* format and print the memory summary */ | ||||
summary_format(memory_buffer, stats, memory_names); | summary_format(memory_buffer, stats, memory_names); | ||||
fputs(memory_buffer, stdout); | fputs(memory_buffer, stdout); | ||||
} | } | ||||
void | |||||
u_memory(stats) | u_memory(stats) | ||||
int *stats; | int *stats; | ||||
{ | { | ||||
static char new[MAX_COLS]; | static char new[MAX_COLS]; | ||||
/* format the new line */ | /* format the new line */ | ||||
summary_format(new, stats, memory_names); | summary_format(new, stats, memory_names); | ||||
line_update(memory_buffer, new, x_mem, y_mem); | line_update(memory_buffer, new, x_mem, y_mem); | ||||
} | } | ||||
/* | /* | ||||
* *_arc(stats) - print "ARC: " followed by the ARC summary string | * *_arc(stats) - print "ARC: " followed by the ARC summary string | ||||
* | * | ||||
* Assumptions: cursor is on "lastline" | * Assumptions: cursor is on "lastline" | ||||
* for i_arc ONLY: cursor is on the previous line | * for i_arc ONLY: cursor is on the previous line | ||||
*/ | */ | ||||
char arc_buffer[MAX_COLS]; | char arc_buffer[MAX_COLS]; | ||||
void | |||||
i_arc(stats) | i_arc(stats) | ||||
int *stats; | int *stats; | ||||
{ | { | ||||
if (arc_names == NULL) | if (arc_names == NULL) | ||||
return (0); | return; | ||||
fputs("\nARC: ", stdout); | fputs("\nARC: ", stdout); | ||||
lastline++; | lastline++; | ||||
/* format and print the memory summary */ | /* format and print the memory summary */ | ||||
summary_format(arc_buffer, stats, arc_names); | summary_format(arc_buffer, stats, arc_names); | ||||
fputs(arc_buffer, stdout); | fputs(arc_buffer, stdout); | ||||
} | } | ||||
void | |||||
u_arc(stats) | u_arc(stats) | ||||
int *stats; | int *stats; | ||||
{ | { | ||||
static char new[MAX_COLS]; | static char new[MAX_COLS]; | ||||
if (arc_names == NULL) | if (arc_names == NULL) | ||||
return (0); | return; | ||||
/* format the new line */ | /* format the new line */ | ||||
summary_format(new, stats, arc_names); | summary_format(new, stats, arc_names); | ||||
line_update(arc_buffer, new, x_arc, y_arc); | line_update(arc_buffer, new, x_arc, y_arc); | ||||
} | } | ||||
/* | /* | ||||
* *_swap(stats) - print "Swap: " followed by the swap summary string | * *_swap(stats) - print "Swap: " followed by the swap summary string | ||||
* | * | ||||
* Assumptions: cursor is on "lastline" | * Assumptions: cursor is on "lastline" | ||||
* for i_swap ONLY: cursor is on the previous line | * for i_swap ONLY: cursor is on the previous line | ||||
*/ | */ | ||||
char swap_buffer[MAX_COLS]; | char swap_buffer[MAX_COLS]; | ||||
void | |||||
i_swap(stats) | i_swap(stats) | ||||
int *stats; | int *stats; | ||||
{ | { | ||||
fputs("\nSwap: ", stdout); | fputs("\nSwap: ", stdout); | ||||
lastline++; | lastline++; | ||||
/* format and print the swap summary */ | /* format and print the swap summary */ | ||||
summary_format(swap_buffer, stats, swap_names); | summary_format(swap_buffer, stats, swap_names); | ||||
fputs(swap_buffer, stdout); | fputs(swap_buffer, stdout); | ||||
} | } | ||||
void | |||||
u_swap(stats) | u_swap(stats) | ||||
int *stats; | int *stats; | ||||
{ | { | ||||
static char new[MAX_COLS]; | static char new[MAX_COLS]; | ||||
/* format the new line */ | /* format the new line */ | ||||
Show All 15 Lines | |||||
* respect to screen updates). | * respect to screen updates). | ||||
*/ | */ | ||||
static char next_msg[MAX_COLS + 5]; | static char next_msg[MAX_COLS + 5]; | ||||
static int msglen = 0; | static int msglen = 0; | ||||
/* Invariant: msglen is always the length of the message currently displayed | /* Invariant: msglen is always the length of the message currently displayed | ||||
on the screen (even when next_msg doesn't contain that message). */ | on the screen (even when next_msg doesn't contain that message). */ | ||||
void | |||||
i_message() | i_message() | ||||
{ | { | ||||
while (lastline < y_message) | while (lastline < y_message) | ||||
{ | { | ||||
fputc('\n', stdout); | fputc('\n', stdout); | ||||
lastline++; | lastline++; | ||||
} | } | ||||
if (next_msg[0] != '\0') | if (next_msg[0] != '\0') | ||||
{ | { | ||||
standout(next_msg); | standout(next_msg); | ||||
msglen = strlen(next_msg); | msglen = strlen(next_msg); | ||||
next_msg[0] = '\0'; | next_msg[0] = '\0'; | ||||
} | } | ||||
else if (msglen > 0) | else if (msglen > 0) | ||||
{ | { | ||||
(void) clear_eol(msglen); | (void) clear_eol(msglen); | ||||
msglen = 0; | msglen = 0; | ||||
} | } | ||||
} | } | ||||
void | |||||
u_message() | u_message() | ||||
{ | { | ||||
i_message(); | i_message(); | ||||
} | } | ||||
static int header_length; | static int header_length; | ||||
Show All 25 Lines | |||||
} | } | ||||
/* | /* | ||||
* *_header(text) - print the header for the process area | * *_header(text) - print the header for the process area | ||||
* | * | ||||
* Assumptions: cursor is on the previous line and lastline is consistent | * Assumptions: cursor is on the previous line and lastline is consistent | ||||
*/ | */ | ||||
void | |||||
i_header(text) | i_header(text) | ||||
char *text; | char *text; | ||||
{ | { | ||||
char *s; | char *s; | ||||
s = trim_header(text); | s = trim_header(text); | ||||
Show All 9 Lines | lastline++; | ||||
else if (header_status == ERASE) | else if (header_status == ERASE) | ||||
{ | { | ||||
header_status = OFF; | header_status = OFF; | ||||
} | } | ||||
free(s); | free(s); | ||||
} | } | ||||
/*ARGSUSED*/ | /*ARGSUSED*/ | ||||
void | |||||
u_header(text) | u_header(text) | ||||
char *text; /* ignored */ | char *text __unused; /* ignored */ | ||||
{ | { | ||||
if (header_status == ERASE) | if (header_status == ERASE) | ||||
{ | { | ||||
putchar('\n'); | putchar('\n'); | ||||
lastline++; | lastline++; | ||||
clear_eol(header_length); | clear_eol(header_length); | ||||
header_status = OFF; | header_status = OFF; | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* *_process(line, thisline) - print one process line | * *_process(line, thisline) - print one process line | ||||
* | * | ||||
* Assumptions: lastline is consistent | * Assumptions: lastline is consistent | ||||
*/ | */ | ||||
void | |||||
i_process(line, thisline) | i_process(line, thisline) | ||||
int line; | int line; | ||||
char *thisline; | char *thisline; | ||||
{ | { | ||||
register char *p; | register char *p; | ||||
register char *base; | register char *base; | ||||
Show All 14 Lines | lastline++; | ||||
/* copy it in to our buffer */ | /* copy it in to our buffer */ | ||||
base = smart_terminal ? screenbuf + lineindex(line) : screenbuf; | base = smart_terminal ? screenbuf + lineindex(line) : screenbuf; | ||||
p = strecpy(base, thisline); | p = strecpy(base, thisline); | ||||
/* zero fill the rest of it */ | /* zero fill the rest of it */ | ||||
memzero(p, display_width - (p - base)); | memzero(p, display_width - (p - base)); | ||||
} | } | ||||
void | |||||
u_process(line, newline) | u_process(line, newline) | ||||
int line; | int line; | ||||
char *newline; | char *newline; | ||||
{ | { | ||||
register char *optr; | register char *optr; | ||||
register int screen_line = line + Header_lines; | register int screen_line = line + Header_lines; | ||||
Show All 31 Lines | char *newline; | ||||
memzero(optr, display_width - (optr - bufferline)); | memzero(optr, display_width - (optr - bufferline)); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
line_update(bufferline, newline, 0, line + Header_lines); | line_update(bufferline, newline, 0, line + Header_lines); | ||||
} | } | ||||
} | } | ||||
void | |||||
u_endscreen(hi) | u_endscreen(hi) | ||||
register int hi; | int hi; | ||||
{ | { | ||||
register int screen_line = hi + Header_lines; | register int screen_line = hi + Header_lines; | ||||
register int i; | register int i; | ||||
if (smart_terminal) | if (smart_terminal) | ||||
{ | { | ||||
if (hi < last_hi) | if (hi < last_hi) | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | lastline = y_idlecursor; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
/* separate this display from the next with some vertical room */ | /* separate this display from the next with some vertical room */ | ||||
fputs("\n\n", stdout); | fputs("\n\n", stdout); | ||||
} | } | ||||
} | } | ||||
void | |||||
display_header(t) | display_header(t) | ||||
int t; | int t; | ||||
{ | { | ||||
if (t) | if (t) | ||||
{ | { | ||||
header_status = ON; | header_status = ON; | ||||
} | } | ||||
else if (header_status == ON) | else if (header_status == ON) | ||||
{ | { | ||||
header_status = ERASE; | header_status = ERASE; | ||||
} | } | ||||
} | } | ||||
/*VARARGS2*/ | /*VARARGS2*/ | ||||
void | |||||
new_message(type, msgfmt, a1, a2, a3) | new_message(type, msgfmt, a1, a2, a3) | ||||
int type; | int type; | ||||
char *msgfmt; | char *msgfmt; | ||||
caddr_t a1, a2, a3; | caddr_t a1, a2, a3; | ||||
{ | { | ||||
register int i; | register int i; | ||||
Show All 24 Lines | caddr_t a1, a2, a3; | ||||
{ | { | ||||
type & MT_standout ? standout(next_msg) : fputs(next_msg, stdout); | type & MT_standout ? standout(next_msg) : fputs(next_msg, stdout); | ||||
msglen = strlen(next_msg); | msglen = strlen(next_msg); | ||||
next_msg[0] = '\0'; | next_msg[0] = '\0'; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void | |||||
clear_message() | clear_message() | ||||
{ | { | ||||
if (clear_eol(msglen) == 1) | if (clear_eol(msglen) == 1) | ||||
{ | { | ||||
putchar('\r'); | putchar('\r'); | ||||
} | } | ||||
} | } | ||||
int | |||||
readline(buffer, size, numeric) | readline(buffer, size, numeric) | ||||
char *buffer; | char *buffer; | ||||
int size; | int size; | ||||
int numeric; | int numeric; | ||||
{ | { | ||||
register char *ptr = buffer; | register char *ptr = buffer; | ||||
▲ Show 20 Lines • Show All 286 Lines • ▼ Show 20 Lines | char *str; | ||||
{ | { | ||||
*ptr = '?'; | *ptr = '?'; | ||||
} | } | ||||
ptr++; | ptr++; | ||||
} | } | ||||
return(str); | return(str); | ||||
} | } | ||||
void | |||||
i_uptime(bt, tod) | i_uptime(bt, tod) | ||||
struct timeval* bt; | struct timeval* bt; | ||||
time_t *tod; | time_t *tod; | ||||
{ | { | ||||
time_t uptime; | time_t uptime; | ||||
int days, hrs, mins, secs; | int days, hrs, mins, secs; | ||||
Show All 25 Lines |