From 5d0431891a7147840aa0b255c48cc62278154a45 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Fri, 15 Apr 2016 00:00:00 -0500 Subject: [PATCH] top: extend 'zero suppression' to out-of-memory fields Now that the conditional OOMEM_ENABLE has been removed and more attention recently paid to the 2 oomem fields it was revealed that Rc.zero_suppress didn't extend to them. So this commit will just correct that oversight. And while we're at it, we'll also extend zero suppress to that NI (nice value) field, which already should've had it. Plus we trade those namespaces custom suppress logic for our now slightly enhanced make_num function. Reference(s): . removal of misguided OOMEM_ENABLE commit 64238730fa45e92bc40b2aa28d107c2469ac29e9 . zero suppression only recently added to namespaces commit b2853ed1170ff900100fa69fee5a8dfd728bd120 Signed-off-by: Jim Warner --- top/top.c | 47 ++++++++++++++++++++++++++--------------------- top/top.h | 2 +- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/top/top.c b/top/top.c index 29202e40..0165fc0d 100644 --- a/top/top.c +++ b/top/top.c @@ -1314,13 +1314,18 @@ static inline const char *make_chr (const char ch, int width, int justr) { /* * Make and then justify an integer NOT subject to scaling, * and include a visual clue should tuncation be necessary. */ -static inline const char *make_num (long num, int width, int justr, int col) { +static inline const char *make_num (long num, int width, int justr, int col, int noz) { static char buf[SMLBUFSIZ]; + buf[0] = '\0'; + if (noz && Rc.zero_suppress && 0 == num) + goto end_justifies; + if (width < snprintf(buf, sizeof(buf), "%ld", num)) { buf[width-1] = COLPLUSCH; AUTOX_COL(col); } +end_justifies: return justify_pad(buf, width, justr); } // end: make_num @@ -4981,8 +4986,6 @@ static const char *task_show (const WIN_t *q, struct pids_stack *p) { cp = make_chr(rSv(EU_STA, s_ch), W, Js); break; /* s_int, make_num without auto width */ - case EU_OOA: - case EU_OOM: case EU_PGD: case EU_PID: case EU_PPD: @@ -4990,25 +4993,30 @@ static const char *task_show (const WIN_t *q, struct pids_stack *p) { case EU_TGD: case EU_THD: case EU_TPG: - cp = make_num(rSv(i, s_int), W, Jn, AUTOX_NO); + cp = make_num(rSv(i, s_int), W, Jn, AUTOX_NO, 0); + break; + /* s_int, make_num without auto width, but with zero supression */ + case EU_OOA: + case EU_OOM: + cp = make_num(rSv(i, s_int), W, Jn, AUTOX_NO, 1); break; /* s_int, make_num or make_str */ case EU_PRI: if (-99 > rSv(EU_PRI, s_int) || 999 < rSv(EU_PRI, s_int)) { cp = make_str("rt", W, Jn, AUTOX_NO); } else - cp = make_num(rSv(EU_PRI, s_int), W, Jn, AUTOX_NO); + cp = make_num(rSv(EU_PRI, s_int), W, Jn, AUTOX_NO, 0); break; /* u_int, make_num without auto width */ case EU_CPN: - cp = make_num(rSv(i, u_int), W, Jn, AUTOX_NO); + cp = make_num(rSv(i, u_int), W, Jn, AUTOX_NO, 0); break; /* u_int, make_num with auto width */ case EU_GID: case EU_UED: case EU_URD: case EU_USD: - cp = make_num(rSv(i, u_int), W, Jn, i); + cp = make_num(rSv(i, u_int), W, Jn, i, 0); break; /* u_int, scale_pcnt with special handling */ case EU_CPU: @@ -5021,9 +5029,18 @@ static const char *task_show (const WIN_t *q, struct pids_stack *p) { cp = scale_pcnt(u, W, Jn); } break; - /* sl_int, make_num */ + /* sl_int, make_num without auto width, but with zero supression */ case EU_NCE: - cp = make_num(rSv(EU_NCE, sl_int), W, Jn, AUTOX_NO); + cp = make_num(rSv(EU_NCE, sl_int), W, Jn, AUTOX_NO, 1); + break; + /* ul_int, make_num with auto width and zero supression */ + case EU_NS1: + case EU_NS2: + case EU_NS3: + case EU_NS4: + case EU_NS5: + case EU_NS6: + cp = make_num(rSv(i, ul_int), W, Jn, i, 1); break; /* ul_int, scale_mem */ case EU_COD: @@ -5055,18 +5072,6 @@ static const char *task_show (const WIN_t *q, struct pids_stack *p) { case EU_FLG: cp = make_str(hex_make(rSv(EU_FLG, ul_int), 1), W, Js, AUTOX_NO); break; - /* ul_int, make_num or make_str */ - case EU_NS1: - case EU_NS2: - case EU_NS3: - case EU_NS4: - case EU_NS5: - case EU_NS6: - { long ino = rSv(i, ul_int); - if (Rc.zero_suppress && 0 >= ino) cp = make_str("", W, Js, i); - else cp = make_num(ino, W, Jn, i); - } - break; /* ull_int, scale_tics */ case EU_TM2: case EU_TME: diff --git a/top/top.h b/top/top.h index fed717e7..f16e7b8c 100644 --- a/top/top.h +++ b/top/top.h @@ -582,7 +582,7 @@ typedef struct WIN_t { /*------ Basic Formatting support --------------------------------------*/ //atic inline const char *justify_pad (const char *str, int width, int justr); //atic inline const char *make_chr (const char ch, int width, int justr); -//atic inline const char *make_num (long num, int width, int justr, int col); +//atic inline const char *make_num (long num, int width, int justr, int col, int noz); //atic inline const char *make_str (const char *str, int width, int justr, int col); //atic const char *scale_mem (int target, unsigned long num, int width, int justr); //atic const char *scale_num (unsigned long num, int width, int justr);