top: to prepare for collapse, move forest view support
In anticipation of a new collapsible child feature, we will have to make some forest view variables available to that 'keys_task()' function. This commit just moves the forest view logic ahead of tertiary input support. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
79a92c3478
commit
c88ff1782c
192
top/top.c
192
top/top.c
@ -4226,6 +4226,102 @@ static inline int wins_usrselect (const WIN_t *q, struct pids_stack *p) {
|
|||||||
#undef rSv
|
#undef rSv
|
||||||
} // end: wins_usrselect
|
} // end: wins_usrselect
|
||||||
|
|
||||||
|
/*###### Forest View support ###########################################*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We try to keep most existing code unaware of our activities
|
||||||
|
* ( plus, maintain alphabetical order with carefully chosen )
|
||||||
|
* ( function names like such: forest_a, forest_b & forest_c )
|
||||||
|
* ( each with exactly one letter more than its predecessor! ) */
|
||||||
|
static struct pids_stack **Seed_ppt; // temporary win ppt pointer
|
||||||
|
static struct pids_stack **Tree_ppt; // forest_begin resizes this
|
||||||
|
static int Tree_idx; // frame_make resets to zero
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This little recursive guy is the real forest view workhorse.
|
||||||
|
* He fills in the Tree_ppt array and also sets the child indent
|
||||||
|
* level which is stored in an 'extra' result struct as a u_int. */
|
||||||
|
static void forest_adds (const int self, unsigned level) {
|
||||||
|
// tailored 'results stack value' extractor macros
|
||||||
|
#define rSv(E,X) PID_VAL(E, s_int, Seed_ppt[X])
|
||||||
|
// if xtra-procps-debug.h active, can't use PID_VAL as base due to assignment
|
||||||
|
#define rLevel Tree_ppt[Tree_idx]->head[Fieldstab[eu_XTRA].erel].result.u_int
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (Tree_idx < PIDSmaxt) { // immunize against insanity
|
||||||
|
if (level > 100) level = 101; // our arbitrary nests limit
|
||||||
|
Tree_ppt[Tree_idx] = Seed_ppt[self]; // add this as root or child
|
||||||
|
rLevel = level; // while recording its level
|
||||||
|
++Tree_idx;
|
||||||
|
#ifdef TREE_SCANALL
|
||||||
|
for (i = 0; i < PIDSmaxt; i++) {
|
||||||
|
if (i == self) continue;
|
||||||
|
#else
|
||||||
|
for (i = self + 1; i < PIDSmaxt; i++) {
|
||||||
|
#endif
|
||||||
|
if (rSv(EU_PID, self) == rSv(EU_TGD, i)
|
||||||
|
|| (rSv(EU_PID, self) == rSv(EU_PPD, i) && rSv(EU_PID, i) == rSv(EU_TGD, i)))
|
||||||
|
forest_adds(i, level + 1); // got one child any others?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#undef rSv
|
||||||
|
#undef rLevel
|
||||||
|
} // end: forest_adds
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This routine is responsible for preparing the stacks ptr array
|
||||||
|
* for forest display in the designated window. Upon completion,
|
||||||
|
* he'll replace the original window ppt with our specially
|
||||||
|
* ordered forest version. */
|
||||||
|
static void forest_begin (WIN_t *q) {
|
||||||
|
// tailored 'results stack value' extractor macro
|
||||||
|
#define rLevel PID_VAL(eu_XTRA, u_int, Seed_ppt[i])
|
||||||
|
static int hwmsav;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
Seed_ppt = q->ppt; // avoid passing pointers
|
||||||
|
if (!Tree_idx) { // do just once per frame
|
||||||
|
if (hwmsav < PIDSmaxt) { // grow, but never shrink
|
||||||
|
hwmsav = PIDSmaxt;
|
||||||
|
Tree_ppt = alloc_r(Tree_ppt, sizeof(void*) * hwmsav);
|
||||||
|
}
|
||||||
|
#ifndef TREE_SCANALL
|
||||||
|
if (!(procps_pids_sort(Pids_ctx, Seed_ppt, PIDSmaxt
|
||||||
|
, PIDS_TIME_START, PIDS_SORT_ASCEND)))
|
||||||
|
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__, strerror(errno)));
|
||||||
|
#endif
|
||||||
|
for (i = 0; i < PIDSmaxt; i++) // avoid any hidepid distortions
|
||||||
|
if (!rLevel) // identify real or pretend trees
|
||||||
|
forest_adds(i, 0); // add as parent plus its children
|
||||||
|
}
|
||||||
|
memcpy(Seed_ppt, Tree_ppt, sizeof(void*) * PIDSmaxt);
|
||||||
|
#undef rLevel
|
||||||
|
} // end: forest_begin
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This guy adds the artwork to either a 'cmd' or 'cmdline'
|
||||||
|
* when in forest view mode, otherwise he just returns 'em. */
|
||||||
|
static inline const char *forest_colour (const WIN_t *q, struct pids_stack *p) {
|
||||||
|
// tailored 'results stack value' extractor macros
|
||||||
|
#define rSv(E) PID_VAL(E, str, p)
|
||||||
|
#define rLevel PID_VAL(eu_XTRA, u_int, p)
|
||||||
|
#ifndef SCROLLVAR_NO
|
||||||
|
static char buf[1024*64*2]; // the same as libray's max buffer size
|
||||||
|
#else
|
||||||
|
static char buf[ROWMINSIZ];
|
||||||
|
#endif
|
||||||
|
const char *which = (CHKw(q, Show_CMDLIN)) ? rSv(eu_CMDLINE) : rSv(EU_CMD);
|
||||||
|
|
||||||
|
if (!CHKw(q, Show_FOREST) || !rLevel) return which;
|
||||||
|
if (rLevel > 100) snprintf(buf, sizeof(buf), "%400s%s", " + ", which);
|
||||||
|
else snprintf(buf, sizeof(buf), "%*s%s", (4 * rLevel), " `- ", which);
|
||||||
|
return buf;
|
||||||
|
#undef rSv
|
||||||
|
#undef rLevel
|
||||||
|
} // end: forest_colour
|
||||||
|
|
||||||
/*###### Interactive Input Tertiary support ############################*/
|
/*###### Interactive Input Tertiary support ############################*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -4980,102 +5076,6 @@ static void keys_xtra (int ch) {
|
|||||||
// show_msg(fmtmk("%s sort compatibility key honored", xmsg));
|
// show_msg(fmtmk("%s sort compatibility key honored", xmsg));
|
||||||
} // end: keys_xtra
|
} // end: keys_xtra
|
||||||
|
|
||||||
/*###### Forest View support ###########################################*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We try to keep most existing code unaware of our activities
|
|
||||||
* ( plus, maintain alphabetical order with carefully chosen )
|
|
||||||
* ( function names like such: forest_a, forest_b & forest_c )
|
|
||||||
* ( each with exactly one letter more than its predecessor! ) */
|
|
||||||
static struct pids_stack **Seed_ppt; // temporary win ppt pointer
|
|
||||||
static struct pids_stack **Tree_ppt; // forest_begin resizes this
|
|
||||||
static int Tree_idx; // frame_make resets to zero
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This little recursive guy is the real forest view workhorse.
|
|
||||||
* He fills in the Tree_ppt array and also sets the child indent
|
|
||||||
* level which is stored in an 'extra' result struct as a u_int. */
|
|
||||||
static void forest_adds (const int self, unsigned level) {
|
|
||||||
// tailored 'results stack value' extractor macros
|
|
||||||
#define rSv(E,X) PID_VAL(E, s_int, Seed_ppt[X])
|
|
||||||
// if xtra-procps-debug.h active, can't use PID_VAL as base due to assignment
|
|
||||||
#define rLevel Tree_ppt[Tree_idx]->head[Fieldstab[eu_XTRA].erel].result.u_int
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (Tree_idx < PIDSmaxt) { // immunize against insanity
|
|
||||||
if (level > 100) level = 101; // our arbitrary nests limit
|
|
||||||
Tree_ppt[Tree_idx] = Seed_ppt[self]; // add this as root or child
|
|
||||||
rLevel = level; // while recording its level
|
|
||||||
++Tree_idx;
|
|
||||||
#ifdef TREE_SCANALL
|
|
||||||
for (i = 0; i < PIDSmaxt; i++) {
|
|
||||||
if (i == self) continue;
|
|
||||||
#else
|
|
||||||
for (i = self + 1; i < PIDSmaxt; i++) {
|
|
||||||
#endif
|
|
||||||
if (rSv(EU_PID, self) == rSv(EU_TGD, i)
|
|
||||||
|| (rSv(EU_PID, self) == rSv(EU_PPD, i) && rSv(EU_PID, i) == rSv(EU_TGD, i)))
|
|
||||||
forest_adds(i, level + 1); // got one child any others?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#undef rSv
|
|
||||||
#undef rLevel
|
|
||||||
} // end: forest_adds
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This routine is responsible for preparing the stacks ptr array
|
|
||||||
* for forest display in the designated window. Upon completion,
|
|
||||||
* he'll replace the original window ppt with our specially
|
|
||||||
* ordered forest version. */
|
|
||||||
static void forest_begin (WIN_t *q) {
|
|
||||||
// tailored 'results stack value' extractor macro
|
|
||||||
#define rLevel PID_VAL(eu_XTRA, u_int, Seed_ppt[i])
|
|
||||||
static int hwmsav;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
Seed_ppt = q->ppt; // avoid passing pointers
|
|
||||||
if (!Tree_idx) { // do just once per frame
|
|
||||||
if (hwmsav < PIDSmaxt) { // grow, but never shrink
|
|
||||||
hwmsav = PIDSmaxt;
|
|
||||||
Tree_ppt = alloc_r(Tree_ppt, sizeof(void*) * hwmsav);
|
|
||||||
}
|
|
||||||
#ifndef TREE_SCANALL
|
|
||||||
if (!(procps_pids_sort(Pids_ctx, Seed_ppt, PIDSmaxt
|
|
||||||
, PIDS_TIME_START, PIDS_SORT_ASCEND)))
|
|
||||||
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__, strerror(errno)));
|
|
||||||
#endif
|
|
||||||
for (i = 0; i < PIDSmaxt; i++) // avoid any hidepid distortions
|
|
||||||
if (!rLevel) // identify real or pretend trees
|
|
||||||
forest_adds(i, 0); // add as parent plus its children
|
|
||||||
}
|
|
||||||
memcpy(Seed_ppt, Tree_ppt, sizeof(void*) * PIDSmaxt);
|
|
||||||
#undef rLevel
|
|
||||||
} // end: forest_begin
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This guy adds the artwork to either a 'cmd' or 'cmdline'
|
|
||||||
* when in forest view mode, otherwise he just returns 'em. */
|
|
||||||
static inline const char *forest_colour (const WIN_t *q, struct pids_stack *p) {
|
|
||||||
// tailored 'results stack value' extractor macros
|
|
||||||
#define rSv(E) PID_VAL(E, str, p)
|
|
||||||
#define rLevel PID_VAL(eu_XTRA, u_int, p)
|
|
||||||
#ifndef SCROLLVAR_NO
|
|
||||||
static char buf[1024*64*2]; // the same as libray's max buffer size
|
|
||||||
#else
|
|
||||||
static char buf[ROWMINSIZ];
|
|
||||||
#endif
|
|
||||||
const char *which = (CHKw(q, Show_CMDLIN)) ? rSv(eu_CMDLINE) : rSv(EU_CMD);
|
|
||||||
|
|
||||||
if (!CHKw(q, Show_FOREST) || !rLevel) return which;
|
|
||||||
if (rLevel > 100) snprintf(buf, sizeof(buf), "%400s%s", " + ", which);
|
|
||||||
else snprintf(buf, sizeof(buf), "%*s%s", (4 * rLevel), " `- ", which);
|
|
||||||
return buf;
|
|
||||||
#undef rSv
|
|
||||||
#undef rLevel
|
|
||||||
} // end: forest_colour
|
|
||||||
|
|
||||||
/*###### Main Screen routines ##########################################*/
|
/*###### Main Screen routines ##########################################*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -641,6 +641,10 @@ typedef struct WIN_t {
|
|||||||
//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, struct pids_stack *p);
|
//atic inline int wins_usrselect (const WIN_t *q, struct pids_stack *p);
|
||||||
|
/*------ Forest View support -------------------------------------------*/
|
||||||
|
//atic void forest_adds (const int self, unsigned level);
|
||||||
|
//atic void forest_begin (WIN_t *q);
|
||||||
|
//atic inline const char *forest_colour (const WIN_t *q, struct pids_stack *p);
|
||||||
/*------ Interactive Input Tertiary support ----------------------------*/
|
/*------ Interactive Input Tertiary support ----------------------------*/
|
||||||
//atic inline int find_ofs (const WIN_t *q, const char *buf);
|
//atic inline int find_ofs (const WIN_t *q, const char *buf);
|
||||||
//atic void find_string (int ch);
|
//atic void find_string (int ch);
|
||||||
@ -653,10 +657,6 @@ typedef struct WIN_t {
|
|||||||
//atic void keys_task (int ch);
|
//atic void keys_task (int ch);
|
||||||
//atic void keys_window (int ch);
|
//atic void keys_window (int ch);
|
||||||
//atic void keys_xtra (int ch);
|
//atic void keys_xtra (int ch);
|
||||||
/*------ Forest View support -------------------------------------------*/
|
|
||||||
//atic void forest_adds (const int self, unsigned level);
|
|
||||||
//atic void forest_begin (WIN_t *q);
|
|
||||||
//atic inline const char *forest_colour (const WIN_t *q, struct pids_stack *p);
|
|
||||||
/*------ Main Screen routines ------------------------------------------*/
|
/*------ Main Screen routines ------------------------------------------*/
|
||||||
//atic void do_key (int ch);
|
//atic void do_key (int ch);
|
||||||
//atic void summary_hlp (struct stat_stack *this, const char *pfx);
|
//atic void summary_hlp (struct stat_stack *this, const char *pfx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user