From ad17ffe60d3bfc0f0b7c2df49a605a780b483e6f Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Thu, 12 May 2022 00:00:00 -0500 Subject: [PATCH] top: rename 'Ctrl' bottom window routines and relocate This patch will just set the stage for the next commit where we'll be adding the capability to display things that sometimes may necessitate multiple library items. In that effort we will be adding several new routines. Signed-off-by: Jim Warner --- top/top.c | 155 +++++++++++++++++++++++++++++------------------------- top/top.h | 8 +-- 2 files changed, 87 insertions(+), 76 deletions(-) diff --git a/top/top.c b/top/top.c index 7c58cad3..1ba5e3dd 100644 --- a/top/top.c +++ b/top/top.c @@ -102,18 +102,18 @@ static int Monpidsidx = 0; /* Current terminal screen size. */ static int Screen_cols, Screen_rows, Max_lines; - // these are used to potentially set aside a bottom 'window' -#define SCREEN_ROWS ( Screen_rows - Tagged_rsvd ) + // these are for the special separate bottom 'window' +#define SCREEN_ROWS ( Screen_rows - Bot_rsvd ) // 1 for horizontal separator -#define TAGGED_RSVD ( 1 ) -#define TAGGED_KEEP Tagged_show = 0 -#define TAGGED_TOSS do { Tagged_show = 0; \ - Tagged_task = Tagged_rsvd = Tagged_enum = 0; } while(0) -static int Tagged_show, - Tagged_rsvd, - Tagged_task; -enum pflag Tagged_enum; -static char *Tagged_name; +#define BOT_RSVD 1 +#define BOT_KEEP Bot_show = 0 +#define BOT_TOSS do { Bot_show = 0; \ + Bot_task = Bot_rsvd = Bot_item = 0; } while(0) +static int Bot_show, + Bot_rsvd, + Bot_task; +enum pflag Bot_item; +static char *Bot_name; /* This is really the number of lines needed to display the summary information (0 - nn), but is used as the relative row where we @@ -2095,7 +2095,7 @@ static void build_headers (void) { else ckITEM(f); // lastly, accommodate any special non-display 'tagged' needs... - if (Tagged_enum) ckITEM(Tagged_enum); + ckITEM(Bot_item); } // end: VIZISw(w) if (Rc.mode_altscr) w = w->next; @@ -4362,7 +4362,7 @@ static void win_reset (WIN_t *q) { // these next guys are global, not really windows based Monpidsidx = 0; Rc.tics_scaled = 0; - TAGGED_TOSS; + BOT_TOSS; } // end: win_reset @@ -4634,59 +4634,6 @@ static void wins_stage_2 (void) { } // end: wins_stage_2 - /* - * This guy manages the bottom margin window, - * showing miscellaneous variable width data. */ -static void wins_tag_show (void) { - #define maxRSVD ( Screen_rows - 1 ) - char buf[SMLBUFSIZ]; - const char *p; - int i; - - for (i = 0; i < PIDSmaxt; i++) { - if (Tagged_task == PID_VAL(EU_PID, s_int, Curwin->ppt[i])) - break; - } - if (i < PIDSmaxt) { - snprintf(buf, sizeof(buf), " %s for pid %d, %s" - , Tagged_name, Tagged_task, PID_VAL(EU_CMD, str, Curwin->ppt[i])); - p = PID_VAL(Tagged_enum, str, Curwin->ppt[i]); - if (!p || !*p || !strcmp(p, "-")) p = "n/a"; - Tagged_rsvd = 1 + TAGGED_RSVD + (strlen(p) / Screen_cols); - if (Tagged_rsvd > maxRSVD) Tagged_rsvd = maxRSVD; - putp(fmtmk("%s%s%-*s", tg2(0, SCREEN_ROWS), Curwin->capclr_hdr, Screen_cols, buf)); - putp(fmtmk("%s%s", tg2(0, SCREEN_ROWS + 1), Cap_clr_eos)); - putp(fmtmk("%s%s", tg2(0, SCREEN_ROWS + 1), Cap_norm)); - fputs(p, stdout); -#ifdef TAGGED_BRIEF - } else - TAGGED_TOSS; -#else - } - TAGGED_KEEP; -#endif - #undef maxRSVD -} // end: wins_tag_show - - - /* - * This guy toggles between displaying a Ctrl - * bottom window or arranging to turn it off. */ -static void wins_tag_toggle (enum pflag enu, const char *str) { - int pid = PID_VAL(EU_PID, s_int, Curwin->ppt[Curwin->begtask]); - - // if already targeted, assume user wants to turn it off ... - if (Tagged_enum == enu) { - TAGGED_TOSS; - } else { - Tagged_task = pid; - Tagged_enum = enu; - Tagged_name = (char*)str; - Tagged_show = 1; - } -} // end: wins_tag_toggle - - /* * Determine if this task matches the 'u/U' selection * criteria for a given window */ @@ -4695,7 +4642,7 @@ static inline int wins_usrselect (const WIN_t *q, int idx) { #define rSv(E) PID_VAL(E, u_int, p) struct pids_stack *p = q->ppt[idx]; - switch(q->usrseltyp) { + switch (q->usrseltyp) { case 0: // uid selection inactive return 1; case 'U': // match any uid @@ -4938,6 +4885,68 @@ static inline const char *forest_display (const WIN_t *q, int idx) { #undef rSv_Hid } // end: forest_display +/*###### Special Separate Bottom Window support ########################*/ + + /* + * This guy actually draws the bottom window, | + * including the contents passed as a string. | */ +static void bot_do_see (const char *str, const char *pgm) { + #define maxRSVD ( Screen_rows - 1 ) + char buf[SMLBUFSIZ]; + + snprintf(buf, sizeof(buf), "%s for pid %d, %s" + , Bot_name, Bot_task, pgm); + if (!str || !*str || !strcmp(str, "-")) str = "n/a"; + Bot_rsvd = 1 + BOT_RSVD + (strlen(str) / Screen_cols); + if (Bot_rsvd > maxRSVD) Bot_rsvd = maxRSVD; + putp(fmtmk("%s%s%-*s", tg2(0, SCREEN_ROWS), Curwin->capclr_hdr, Screen_cols, buf)); + putp(fmtmk("%s%s", tg2(0, SCREEN_ROWS + 1), Cap_clr_eos)); + putp(fmtmk("%s%s", tg2(0, SCREEN_ROWS + 1), Cap_norm)); + fputs(str, stdout); + #undef maxRSVD +} // end: bot_do_see + + + + /* + * This guy manages the bottom margin window, | + * showing misc stuff based on a single item. | */ +static void bot_item_show (void) { + struct pids_stack *p; + int i; + + for (i = 0; i < PIDSmaxt; i++) { + p = Curwin->ppt[i]; + if (Bot_task == PID_VAL(EU_PID, s_int, p)) + break; + } + if (i < PIDSmaxt) { + bot_do_see(PID_VAL(Bot_item, str, p), PID_VAL(EU_CMD, str, p)); + } +#ifdef BOT_DEAD_ZAP + else + BOT_TOSS; +#else + BOT_KEEP; +#endif +} // end: bot_item_show + + + /* + * This guy toggles between displaying a Ctrl | + * bottom window or arranging to turn it off. | */ +static void bot_item_toggle (enum pflag item, const char *name) { + // if already targeted, assume user wants to turn it off ... + if (Bot_item == item) { + BOT_TOSS; + } else { + Bot_item = item; + Bot_name = (char*)name; + Bot_show = 1; + Bot_task = PID_VAL(EU_PID, s_int, Curwin->ppt[Curwin->begtask]); + } +} // end: bot_item_toggle + /*###### Interactive Input Tertiary support ############################*/ /* @@ -5313,13 +5322,13 @@ static void keys_global (int ch) { #endif break; case kbd_CtrlG: - wins_tag_toggle(EU_CGR, "control groups"); + bot_item_toggle(EU_CGR, "control groups"); break; case kbd_CtrlK: - wins_tag_toggle(eu_CMDLINE, "command line"); + bot_item_toggle(eu_CMDLINE, "command line"); break; case kbd_CtrlN: - wins_tag_toggle(EU_ENV, "environment"); + bot_item_toggle(EU_ENV, "environment"); break; case kbd_CtrlR: if (Secure_mode) @@ -5348,7 +5357,7 @@ static void keys_global (int ch) { } break; case kbd_CtrlU: - wins_tag_toggle(EU_SGN, "supplementary groups"); + bot_item_toggle(EU_SGN, "supplementary groups"); break; case kbd_ENTER: // these two have the effect of waking us case kbd_SPACE: // from 'pselect', refreshing the display @@ -6785,7 +6794,7 @@ static void frame_make (void) { if (Frames_signal) { if (Frames_signal == BREAK_sig || (Frames_signal == BREAK_screen)) - TAGGED_TOSS; + BOT_TOSS; zap_fieldstab(); } @@ -6854,7 +6863,7 @@ static void frame_make (void) { } if (CHKw(w, View_SCROLL) && VIZISw(Curwin)) show_scroll(); - if (Tagged_show) wins_tag_show(); + if (Bot_show) bot_item_show(); fflush(stdout); /* we'll deem any terminal not supporting tgoto as dumb and disable diff --git a/top/top.h b/top/top.h index 4c350bba..ccb63753 100644 --- a/top/top.h +++ b/top/top.h @@ -26,6 +26,7 @@ /* Development/Debugging defines ----------------------------------- */ //#define ATEOJ_RPTSTD /* report on some miscellany at end-of-job */ +//#define BOT_DEAD_ZAP /* zap Ctrl bottom window when target dies */ //#define CASEUP_HEXES /* show all those hex values in upper case */ //#define CASEUP_SUFIX /* show time/mem/cnts suffix in upper case */ //#define EQUCOLHDRYES /* yes, equalize the column header lengths */ @@ -54,7 +55,6 @@ //#define SCROLLVAR_NO /* disable intra-column horizontal scrolls */ //#define SCROLLV_BY_1 /* when scrolling left/right do not move 8 */ //#define STRINGCASENO /* case insenstive compare/locate versions */ -//#define TAGGED_BRIEF /* zap Ctrl bottom window when target dies */ //#define TERMIOS_ONLY /* use native input only (just limp along) */ //#define THREADED_CPU /* separate background thread for cpu updt */ //#define THREADED_MEM /* separate background thread for mem updt */ @@ -727,14 +727,16 @@ typedef struct WIN_t { //atic void wins_reflag (int what, int flg); //atic void wins_stage_1 (void); //atic void wins_stage_2 (void); -//atic void wins_tag_show (void); -//atic void wins_tag_toggle (enum pflag enu, const char *str); //atic inline int wins_usrselect (const WIN_t *q, int idx); /*------ Forest View support -------------------------------------------*/ //atic void forest_adds (const int self, int level); //atic void forest_begin (WIN_t *q); //atic void forest_config (WIN_t *q); //atic inline const char *forest_display (const WIN_t *q, int idx); +/*------ Special Separate Bottom Window support ------------------------*/ +//atic void bot_do_see (const char *str, const char *pgm); +//atic void bot_item_show (void); +//atic void bot_item_toggle (enum pflag item, const char *name); /*------ Interactive Input Tertiary support ----------------------------*/ //atic inline int find_ofs (const WIN_t *q, const char *buf); //atic void find_string (int ch);