top: a refactor to prepare for including collapsed cpu

So that the impact (minimal) of the next commit can be
isolated, this commit just involves a little renaming,
reformat plus a refactor of some proc_t pointer logic.

[ renaming, relocation and changes to 'user_matched' ]
[ wasn't strictly necessary, but now mirrors newlib. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2018-06-24 00:00:00 -05:00 committed by Craig Small
parent c6e68e2fed
commit e66c36794a
2 changed files with 52 additions and 50 deletions

View File

@ -1527,29 +1527,6 @@ static const char *user_certify (WIN_t *q, const char *str, char typ) {
} }
return NULL; return NULL;
} // end: user_certify } // end: user_certify
/*
* Determine if this proc_t matches the 'u/U' selection criteria
* for a given window -- it's called from only one place, and
* likely inlined even without the directive */
static inline int user_matched (const WIN_t *q, const proc_t *p) {
switch(q->usrseltyp) {
case 0: // uid selection inactive
return 1;
case 'U': // match any uid
if (p->ruid == q->usrseluid) return q->usrselflg;
if (p->suid == q->usrseluid) return q->usrselflg;
if (p->fuid == q->usrseluid) return q->usrselflg;
// fall through...
case 'u': // match effective uid
if (p->euid == q->usrseluid) return q->usrselflg;
// fall through...
default: // no match...
;
}
return !q->usrselflg;
} // end: user_matched
/*###### Basic Formatting support ######################################*/ /*###### Basic Formatting support ######################################*/
@ -4673,6 +4650,29 @@ static void wins_stage_2 (void) {
sigaddset(&Sigwinch_set, SIGWINCH); sigaddset(&Sigwinch_set, SIGWINCH);
#endif #endif
} // end: wins_stage_2 } // end: wins_stage_2
/*
* Determine if this task matches the 'u/U' selection
* criteria for a given window */
static inline int wins_usrselect (const WIN_t *q, const int idx) {
proc_t *p = q->ppt[idx];
switch(q->usrseltyp) {
case 0: // uid selection inactive
return 1;
case 'U': // match any uid
if (p->ruid == q->usrseluid) return q->usrselflg;
if (p->suid == q->usrseluid) return q->usrselflg;
if (p->fuid == q->usrseluid) return q->usrselflg;
// fall through...
case 'u': // match effective uid
if (p->euid == q->usrseluid) return q->usrselflg;
// fall through...
default: // no match...
;
}
return !q->usrselflg;
} // end: wins_usrselect
/*###### Forest View support ###########################################*/ /*###### Forest View support ###########################################*/
@ -4689,8 +4689,8 @@ static int Tree_idx; // frame_make resets to zero
positive pid values represent parents with collapsed children positive pid values represent parents with collapsed children
while a negative pid value means children have been expanded. while a negative pid value means children have been expanded.
( both of these are managed under the 'keys_task()' routine ) */ ( both of these are managed under the 'keys_task()' routine ) */
static int *Hide_pid; // collapsible process array static int *Hide_pid; // collapsible process array
static int Hide_tot; // total used in above array static int Hide_tot; // total used in above array
/* /*
* This little recursive guy is the real forest view workhorse. * This little recursive guy is the real forest view workhorse.
@ -4750,10 +4750,10 @@ static void forest_create (WIN_t *q) {
#ifndef TREE_SCANALL #ifndef TREE_SCANALL
qsort(Seed_ppt, Frame_maxtask, sizeof(proc_t*), (QFP_t)forest_based); qsort(Seed_ppt, Frame_maxtask, sizeof(proc_t*), (QFP_t)forest_based);
#endif #endif
for (i = 0; i < Frame_maxtask; i++) // avoid any hidepid distortions for (i = 0; i < Frame_maxtask; i++) { // avoid any hidepid distortions
if (!Seed_ppt[i]->pad_3) // identify real or pretend trees if (!Seed_ppt[i]->pad_3) // real & pseudo parents == zero
forest_adds(i, 0); // add as parent plus its children forest_adds(i, 0); // add a parent and its children
}
/* we're borrowing some pad bytes in the proc_t, /* we're borrowing some pad bytes in the proc_t,
pad_2: 'x' means a collapsed thread, 'z' means an unseen child pad_2: 'x' means a collapsed thread, 'z' means an unseen child
pad_3: where level number is stored (0 - 100) */ pad_3: where level number is stored (0 - 100) */
@ -4761,16 +4761,17 @@ static void forest_create (WIN_t *q) {
if (Hide_pid[i] > 0) { if (Hide_pid[i] > 0) {
for (j = 0; j < Frame_maxtask; j++) { for (j = 0; j < Frame_maxtask; j++) {
if (Tree_ppt[j]->tid == Hide_pid[i]) { if (Tree_ppt[j]->tid == Hide_pid[i]) {
int idx = j; int parent = j;
char lvl = Tree_ppt[j]->pad_3; int children = 0;
Tree_ppt[j]->pad_2 = 'x'; char level = Tree_ppt[j]->pad_3;
while (j+1 < Frame_maxtask && Tree_ppt[j+1]->pad_3 > lvl) {
while (j+1 < Frame_maxtask && Tree_ppt[j+1]->pad_3 > level) {
Tree_ppt[j+1]->pad_2 = 'z'; Tree_ppt[j+1]->pad_2 = 'z';
idx = 0; children = 1;
++j; ++j;
} }
// no children found, so unmark this puppy // children found (and collapsed), so mark that puppy
if (idx) Tree_ppt[idx]->pad_2 = '\0'; if (children) Tree_ppt[parent]->pad_2 = 'x';
} }
} }
} }
@ -4830,7 +4831,7 @@ static inline int find_ofs (const WIN_t *q, const char *buf) {
/* This is currently the one true prototype require by top. /* This is currently the one true prototype require by top.
It is placed here, instead of top.h, so as to avoid a compiler It is placed here, instead of top.h, so as to avoid a compiler
warning when top_nls.c is compiled. */ warning when top_nls.c is compiled. */
static const char *task_show (const WIN_t *q, const proc_t *p); static const char *task_show (const WIN_t *q, const int idx);
static void find_string (int ch) { static void find_string (int ch) {
#define reDUX (found) ? N_txt(WORD_another_txt) : "" #define reDUX (found) ? N_txt(WORD_another_txt) : ""
@ -4855,7 +4856,7 @@ static void find_string (int ch) {
if (Curwin->findstr[0]) { if (Curwin->findstr[0]) {
SETw(Curwin, NOPRINT_xxx); SETw(Curwin, NOPRINT_xxx);
for (i = Curwin->begtask; i < Frame_maxtask; i++) { for (i = Curwin->begtask; i < Frame_maxtask; i++) {
const char *row = task_show(Curwin, Curwin->ppt[i]); const char *row = task_show(Curwin, i);
if (*row && -1 < find_ofs(Curwin, row)) { if (*row && -1 < find_ofs(Curwin, row)) {
found = 1; found = 1;
if (i == Curwin->begtask) continue; if (i == Curwin->begtask) continue;
@ -5916,7 +5917,7 @@ numa_nope:
/* /*
* Build the information for a single task row and * Build the information for a single task row and
* display the results or return them to the caller. */ * display the results or return them to the caller. */
static const char *task_show (const WIN_t *q, const proc_t *p) { static const char *task_show (const WIN_t *q, const int idx) {
#ifndef SCROLLVAR_NO #ifndef SCROLLVAR_NO
#define makeVAR(v) { const char *pv = v; \ #define makeVAR(v) { const char *pv = v; \
if (!q->varcolbeg) cp = make_str(pv, q->varcolsz, Js, AUTOX_NO); \ if (!q->varcolbeg) cp = make_str(pv, q->varcolsz, Js, AUTOX_NO); \
@ -5933,6 +5934,7 @@ static const char *task_show (const WIN_t *q, const proc_t *p) {
static char rbuf[ROWMINSIZ]; static char rbuf[ROWMINSIZ];
char *rp; char *rp;
int x; int x;
proc_t *p = q->ppt[idx];
/* we're borrowing some pad bytes in the proc_t, /* we're borrowing some pad bytes in the proc_t,
pad_2: 'x' means a collapsed thread, 'z' means an unseen child pad_2: 'x' means a collapsed thread, 'z' means an unseen child
@ -6217,8 +6219,8 @@ static void window_hlp (void) {
if (w->begnext > 0) { if (w->begnext > 0) {
fwd_redux: fwd_redux:
for (i = w->begtask; i < Frame_maxtask; i++) { for (i = w->begtask; i < Frame_maxtask; i++) {
if (user_matched(w, w->ppt[i]) if (wins_usrselect(w, i)
&& (*task_show(w, w->ppt[i]))) && (*task_show(w, i)))
break; break;
} }
if (i < Frame_maxtask) { if (i < Frame_maxtask) {
@ -6231,14 +6233,14 @@ fwd_redux:
// potentially scroll backward ... // potentially scroll backward ...
for (i = w->begtask; i > 0; i--) { for (i = w->begtask; i > 0; i--) {
if (user_matched(w, w->ppt[i]) if (wins_usrselect(w, i)
&& (*task_show(w, w->ppt[i]))) && (*task_show(w, i)))
break; break;
} }
// reached the top, but maybe this guy ain't visible // reached the top, but maybe this guy ain't visible
if (!(w->begtask = i) && !reversed) { if (!(w->begtask = i) && !reversed) {
if (!(user_matched(w, w->ppt[0])) if (!(wins_usrselect(w, 0))
|| (!(*task_show(w, w->ppt[0])))) { || (!(*task_show(w, 0)))) {
reversed = 1; reversed = 1;
goto fwd_redux; goto fwd_redux;
} }
@ -6285,14 +6287,14 @@ static int window_show (WIN_t *q, int wmax) {
checking some stuff with each iteration and check it just once... */ checking some stuff with each iteration and check it just once... */
if (CHKw(q, Show_IDLEPS) && !q->usrseltyp) if (CHKw(q, Show_IDLEPS) && !q->usrseltyp)
while (i < Frame_maxtask && lwin < wmax) { while (i < Frame_maxtask && lwin < wmax) {
if (*task_show(q, q->ppt[i++])) if (*task_show(q, i++))
++lwin; ++lwin;
} }
else else
while (i < Frame_maxtask && lwin < wmax) { while (i < Frame_maxtask && lwin < wmax) {
if ((CHKw(q, Show_IDLEPS) || isBUSY(q->ppt[i])) if ((CHKw(q, Show_IDLEPS) || isBUSY(q->ppt[i]))
&& user_matched(q, q->ppt[i]) && wins_usrselect(q, i)
&& *task_show(q, q->ppt[i])) && *task_show(q, i))
++lwin; ++lwin;
++i; ++i;
} }

View File

@ -718,7 +718,6 @@ typedef struct WIN_t {
//atic int get_int (const char *prompt); //atic int get_int (const char *prompt);
//atic inline const char *hex_make (KLONG num, int noz); //atic inline const char *hex_make (KLONG num, int noz);
//atic const char *user_certify (WIN_t *q, const char *str, char typ); //atic const char *user_certify (WIN_t *q, const char *str, char typ);
//atic inline int user_matched (const WIN_t *q, const proc_t *p);
/*------ Basic Formatting support --------------------------------------*/ /*------ Basic Formatting support --------------------------------------*/
//atic inline const char *justify_pad (const char *str, int width, int justr); //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_chr (const char ch, int width, int justr);
@ -787,6 +786,7 @@ typedef struct WIN_t {
//atic void wins_reflag (int what, int flg); //atic void wins_reflag (int what, int flg);
//atic void wins_stage_1 (void); //atic void wins_stage_1 (void);
//atic void wins_stage_2 (void); //atic void wins_stage_2 (void);
//atic inline int wins_usrselect (const WIN_t *q, const int idx);
/*------ Forest View support -------------------------------------------*/ /*------ Forest View support -------------------------------------------*/
//atic void forest_adds (const int self, int level); //atic void forest_adds (const int self, int level);
#ifndef TREE_SCANALL #ifndef TREE_SCANALL
@ -810,7 +810,7 @@ typedef struct WIN_t {
//atic void do_key (int ch); //atic void do_key (int ch);
//atic void summary_hlp (CPU_t *cpu, const char *pfx); //atic void summary_hlp (CPU_t *cpu, const char *pfx);
//atic void summary_show (void); //atic void summary_show (void);
//atic const char *task_show (const WIN_t *q, const proc_t *p); //atic const char *task_show (const WIN_t *q, const int idx);
//atic void window_hlp (void); //atic void window_hlp (void);
//atic int window_show (WIN_t *q, int wmax); //atic int window_show (WIN_t *q, int wmax);
/*------ Entry point plus two ------------------------------------------*/ /*------ Entry point plus two ------------------------------------------*/