From f7fb8bddf47a0bab6febc4119491fd9df512bc1a Mon Sep 17 00:00:00 2001 From: Craig Small Date: Sun, 25 Sep 2011 00:27:37 +1000 Subject: [PATCH] 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) --- proc/readproc.c | 2 +- proc/readproc.h | 4 ++-- top.c | 20 +++++++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/proc/readproc.c b/proc/readproc.c index bf4de18c..eef7919a 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -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. // diff --git a/proc/readproc.h b/proc/readproc.h index 98824958..b9d93d9c 100644 --- a/proc/readproc.h +++ b/proc/readproc.h @@ -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` diff --git a/top.c b/top.c index 88cf3297..b7beb4da 100644 --- a/top.c +++ b/top.c @@ -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