version 1.15, 2003/06/18 08:36:31 |
version 1.16, 2003/06/19 22:40:45 |
|
|
|
|
static char *cpustates_tag(void); |
static char *cpustates_tag(void); |
static int string_count(char **); |
static int string_count(char **); |
static void summary_format(char *, int *, char **); |
static void summary_format(char *, size_t, int *, char **); |
static void line_update(char *, char *, int, int); |
static void line_update(char *, char *, int, int); |
|
|
#define lineindex(l) ((l)*display_width) |
#define lineindex(l) ((l)*display_width) |
|
|
} |
} |
|
|
/* 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, sizeof(procstates_buffer), brkdn, |
|
procstate_names); |
if (fputs(procstates_buffer, stdout) == EOF) |
if (fputs(procstates_buffer, stdout) == EOF) |
exit(1); |
exit(1); |
|
|
|
|
/* see if any of the state numbers has changed */ |
/* see if any of the state numbers has changed */ |
if (memcmp(lprocstates, brkdn, num_procstates * sizeof(int)) != 0) { |
if (memcmp(lprocstates, brkdn, num_procstates * sizeof(int)) != 0) { |
/* format and update the line */ |
/* format and update the line */ |
summary_format(new, brkdn, procstate_names); |
summary_format(new, sizeof(new), brkdn, procstate_names); |
line_update(procstates_buffer, new, x_brkdn, y_brkdn); |
line_update(procstates_buffer, new, x_brkdn, y_brkdn); |
memcpy(lprocstates, brkdn, num_procstates * sizeof(int)); |
memcpy(lprocstates, brkdn, num_procstates * sizeof(int)); |
} |
} |
|
|
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, sizeof(memory_buffer), stats, |
|
memory_names); |
if (fputs(memory_buffer, stdout) == EOF) |
if (fputs(memory_buffer, stdout) == EOF) |
exit(1); |
exit(1); |
} |
} |
|
|
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, sizeof(new), stats, memory_names); |
line_update(memory_buffer, new, x_mem, y_mem); |
line_update(memory_buffer, new, x_mem, y_mem); |
} |
} |
|
|
|
|
void |
void |
i_process(int line, char *thisline) |
i_process(int line, char *thisline) |
{ |
{ |
char *p, *base; |
char *base; |
|
size_t len; |
|
|
/* make sure we are on the correct line */ |
/* make sure we are on the correct line */ |
while (lastline < y_procs + line) { |
while (lastline < y_procs + line) { |
|
|
|
|
/* 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); |
len = strlcpy(base, thisline, display_width); |
|
if (len < (size_t)display_width) { |
/* zero fill the rest of it */ |
/* zero fill the rest of it */ |
memset(p, 0, display_width - (p - base)); |
memset(base + len, 0, display_width - len); |
|
} |
} |
} |
|
|
void |
void |
u_process(int linenum, char *linebuf) |
u_process(int linenum, char *linebuf) |
{ |
{ |
int screen_line = linenum + Header_lines; |
int screen_line = linenum + Header_lines; |
char *optr, *bufferline; |
char *bufferline; |
|
size_t len; |
|
|
/* remember a pointer to the current line in the screen buffer */ |
/* remember a pointer to the current line in the screen buffer */ |
bufferline = &screenbuf[lineindex(linenum)]; |
bufferline = &screenbuf[lineindex(linenum)]; |
|
|
exit(1); |
exit(1); |
|
|
/* copy it in to the buffer */ |
/* copy it in to the buffer */ |
optr = strecpy(bufferline, linebuf); |
len = strlcpy(bufferline, linebuf, display_width); |
|
if (len < (size_t)display_width) { |
/* zero fill the rest of it */ |
/* zero fill the rest of it */ |
memset(optr, 0, display_width - (optr - bufferline)); |
memset(bufferline + len, 0, display_width - len); |
|
} |
} else { |
} else { |
line_update(bufferline, linebuf, 0, linenum + Header_lines); |
line_update(bufferline, linebuf, 0, linenum + Header_lines); |
} |
} |
|
|
return (cnt); |
return (cnt); |
} |
} |
|
|
|
#define COPYLEFT(to, from) \ |
|
do { \ |
|
len = strlcpy((to), (from), left); \ |
|
if (len >= left) \ |
|
return; \ |
|
p += len; \ |
|
left -= len; \ |
|
} while (0) |
|
|
static void |
static void |
summary_format(char *str, int *numbers, char **names) |
summary_format(char *buf, size_t left, int *numbers, char **names) |
{ |
{ |
char *p, *thisname; |
char *p, *thisname; |
|
size_t len; |
int num; |
int num; |
|
|
/* format each number followed by its string */ |
/* format each number followed by its string */ |
p = str; |
p = buf; |
while ((thisname = *names++) != NULL) { |
while ((thisname = *names++) != NULL) { |
/* get the number to format */ |
/* get the number to format */ |
num = *numbers++; |
num = *numbers++; |
|
|
/* is this number in kilobytes? */ |
/* is this number in kilobytes? */ |
if (thisname[0] == 'K') { |
if (thisname[0] == 'K') { |
/* yes: format it as a memory value */ |
/* yes: format it as a memory value */ |
p = strecpy(p, format_k(num)); |
COPYLEFT(p, format_k(num)); |
|
|
/* |
/* |
* skip over the K, since it was included by |
* skip over the K, since it was included by |
* format_k |
* format_k |
*/ |
*/ |
p = strecpy(p, thisname + 1); |
COPYLEFT(p, thisname + 1); |
} else if (num > 0) { |
} else if (num > 0) { |
p = strecpy(p, itoa(num)); |
len = snprintf(p, left, "%d%s", num, thisname); |
p = strecpy(p, thisname); |
if (len == (size_t)-1 || len >= left) |
|
return; |
|
p += len; |
|
left -= len; |
} |
} |
|
} else { |
|
/* |
|
* Ignore negative numbers, but display corresponding |
|
* string. |
|
*/ |
|
COPYLEFT(p, thisname); |
} |
} |
/* ignore negative numbers, but display corresponding string */ |
|
else |
|
p = strecpy(p, thisname); |
|
} |
} |
|
|
/* if the last two characters in the string are ", ", delete them */ |
/* if the last two characters in the string are ", ", delete them */ |
p -= 2; |
p -= 2; |
if (p >= str && p[0] == ',' && p[1] == ' ') |
if (p >= buf && p[0] == ',' && p[1] == ' ') |
*p = '\0'; |
*p = '\0'; |
} |
} |
|
|