miscellaneous top and library cleanup

top changes
 . refined column header width calculations
 . added error messages for:
     invalid signal ('k')
     invalad max tasks ('n')
 . corrected narrative for summary_show

library changes
 . corrected some comments (only)
This commit is contained in:
Craig Small 2011-09-25 00:27:37 +10:00
parent e4c45d6984
commit f7fb8bddf4
3 changed files with 14 additions and 12 deletions

View File

@ -105,7 +105,7 @@ typedef struct status_table_struct {
// "Threads:\n", etc. would be lines, but no quote, no escape, etc.
//
// After a pipe through gperf, insert the resulting 'asso_values'
// into our 'assoc' array. Then convert the gperf 'wordlist' array
// into our 'asso' array. Then convert the gperf 'wordlist' array
// into our 'table' array by wrapping the string literals within
// the F macro and replacing empty strings with the NUL define.
//

View File

@ -255,8 +255,8 @@ extern proc_t * get_proc_stats(pid_t pid, proc_t *p);
#define PROC_FILLENV 0x0004 // alloc and fill in `environ'
#define PROC_FILLUSR 0x0008 // resolve user id number -> user name
#define PROC_FILLGRP 0x0010 // resolve group id number -> group name
#define PROC_FILLSTATUS 0x0020 // read status -- currently unconditional
#define PROC_FILLSTAT 0x0040 // read stat -- currently unconditional
#define PROC_FILLSTATUS 0x0020 // read status
#define PROC_FILLSTAT 0x0040 // read stat
#define PROC_FILLWCHAN 0x0080 // look up WCHAN name
#define PROC_FILLARG 0x0100 // alloc and fill in `cmdline'
#define PROC_FILLCGROUP 0x0200 // alloc and fill in `cgroup`

20
top.c
View File

@ -1416,7 +1416,7 @@ static void calibrate_fields (void) {
#endif
h = Fieldstab[f].head;
// oops, won't fit -- we're outta here...
if (Screen_cols <= ((int)(s - w->columnhdr) + (int)strlen(h))) break;
if (Screen_cols < ((int)(s - w->columnhdr) + (int)strlen(h))) break;
if (!Fieldstab[f].fmts) { ++varcolcnt; w->varcolsz += strlen(h) - 1; }
s = scat(s, h);
}
@ -1441,7 +1441,7 @@ static void calibrate_fields (void) {
if (P_MAXPFLGS < f) { w->endpflg = i; continue; }
#endif
h = Fieldstab[f].head;
if (Screen_cols <= ((int)(s - w->columnhdr) + (int)strlen(h))) break;
if (Screen_cols < ((int)(s - w->columnhdr) + (int)strlen(h))) break;
s = scat(s, h);
w->endpflg = i;
}
@ -2777,6 +2777,7 @@ static void keys_global (int ch) {
if (0 < sig && kill(pid, sig))
show_msg(fmtmk("\aFailed signal pid '%d' with '%d': %s"
, pid, sig, strerror(errno)));
else if (0 > sig) show_msg("Invalid signal");
}
}
break;
@ -2834,7 +2835,10 @@ static void keys_task (int ch) {
case 'n':
if (VIZCHKw(w)) {
int num = get_int(fmtmk("Maximum tasks = %d, change to (0 is unlimited)", w->rc.maxtasks));
if (INT_MIN < num) w->rc.maxtasks = num;
if (INT_MIN < num) {
if (-1 < num ) w->rc.maxtasks = num;
else show_msg("Invalid maximum");
}
}
break;
case '<':
@ -3275,12 +3279,10 @@ static void summaryhlp (CPU_t *cpu, const char *pfx) {
/*
* Begin a new frame by:
* 1) Refreshing the all important proc table
* 2) Displaying uptime and load average (maybe)
* 3) Displaying task/cpu states (maybe)
* 4) Displaying memory & swap usage (maybe)
* and then, returning a pointer to the pointers to the proc_t's! */
* In support of a new frame:
* 1) Display uptime and load average (maybe)
* 2) Display task/cpu states (maybe)
* 3) Display memory & swap usage (maybe) */
static void summary_show (void) {
#define isROOM(f,n) (CHKw(w, f) && Msg_row + (n) < Screen_rows - 1)
#define anyFLG 0xffffff