]> granicus.if.org Git - procps-ng/commitdiff
top: to prepare for collapse, move forest view support
authorJim Warner <james.warner@comcast.net>
Tue, 19 Jun 2018 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Sat, 23 Jun 2018 12:03:56 +0000 (22:03 +1000)
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>
top/top.c
top/top.h

index 9b1e51827e858ad7240ae0b08646f06ae0e87635..ebe7bb5b637677eb6b271e537ae63cc75a03967d 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -4679,6 +4679,98 @@ static void wins_stage_2 (void) {
 #endif
 } // end: wins_stage_2
 \f
+/*######  Forest View support  ###########################################*/
+
+        /*
+         * We try to keep most existing code unaware of our activities
+         * ( plus, maintain alphabetical order with carefully chosen )
+         * ( function names: forest_a, forest_b, forest_c & forest_d )
+         * ( each with exactly one letter more than its predecessor! ) */
+static proc_t **Seed_ppt;                   // temporary win ppt pointer
+static proc_t **Tree_ppt;                   // forest_create will resize
+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 unused proc_t padding byte. */
+static void forest_adds (const int self, int level) {
+   int i;
+
+   if (Tree_idx < Frame_maxtask) {          // 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
+      Tree_ppt[Tree_idx++]->pad_3 = level;  // borrow 1 byte, 127 levels
+#ifdef TREE_SCANALL
+      for (i = 0; i < Frame_maxtask; i++) {
+         if (i == self) continue;
+#else
+      for (i = self + 1; i < Frame_maxtask; i++) {
+#endif
+         if (Seed_ppt[self]->tid == Seed_ppt[i]->tgid
+         || (Seed_ppt[self]->tid == Seed_ppt[i]->ppid && Seed_ppt[i]->tid == Seed_ppt[i]->tgid))
+            forest_adds(i, level + 1);      // got one child any others?
+      }
+   }
+} // end: forest_adds
+
+
+#ifndef TREE_SCANALL
+        /*
+         * Our qsort callback to order a ppt by the non-display start_time
+         * which will make us immune from any pid, ppid or tgid anomalies
+         * if/when pid values are wrapped by the kernel! */
+static int forest_based (const proc_t **x, const proc_t **y) {
+   if ( (*x)->start_time > (*y)->start_time ) return  1;
+   if ( (*x)->start_time < (*y)->start_time ) return -1;
+   return 0;
+} // end: forest_based
+#endif
+
+
+        /*
+         * This routine is responsible for preparing the proc_t's for
+         * a forest display in the designated window.  Upon completion,
+         * he'll replace the original window ppt with our specially
+         * ordered forest version. */
+static void forest_create (WIN_t *q) {
+   static int hwmsav;
+   int i;
+
+   Seed_ppt = q->ppt;                       // avoid passing WIN_t ptrs
+   if (!Tree_idx) {                         // do just once per frame
+      if (hwmsav < Frame_maxtask) {         // grow, but never shrink
+         hwmsav = Frame_maxtask;
+         Tree_ppt = alloc_r(Tree_ppt, sizeof(proc_t*) * hwmsav);
+      }
+#ifndef TREE_SCANALL
+      qsort(Seed_ppt, Frame_maxtask, sizeof(proc_t*), (QFP_t)forest_based);
+#endif
+      for (i = 0; i < Frame_maxtask; i++)   // avoid any hidepid distortions
+         if (!Seed_ppt[i]->pad_3)           // identify real or pretend trees
+            forest_adds(i, 0);              // add as parent plus its children
+   }
+   memcpy(Seed_ppt, Tree_ppt, sizeof(proc_t*) * Frame_maxtask);
+} // end: forest_create
+
+
+        /*
+         * This guy adds the artwork to either p->cmd or p->cmdline
+         * when in forest view mode, otherwise he just returns 'em. */
+static inline const char *forest_display (const WIN_t *q, const proc_t *p) {
+#ifndef SCROLLVAR_NO
+   static char buf[1024*64*2]; // the same as readproc's MAX_BUFSZ
+#else
+   static char buf[ROWMINSIZ];
+#endif
+   const char *which = (CHKw(q, Show_CMDLIN)) ? *p->cmdline : p->cmd;
+
+   if (!CHKw(q, Show_FOREST) || !p->pad_3) return which;
+   if (p->pad_3 > 100) snprintf(buf, sizeof(buf), "%400s%s", " +  ", which);
+   else snprintf(buf, sizeof(buf), "%*s%s", (4 * p->pad_3), " `- ", which);
+   return buf;
+} // end: forest_display
+\f
 /*######  Interactive Input Tertiary support  ############################*/
 
   /*
@@ -5433,98 +5525,6 @@ static void keys_xtra (int ch) {
 // show_msg(fmtmk("%s sort compatibility key honored", xmsg));
 } // end: keys_xtra
 \f
-/*######  Forest View support  ###########################################*/
-
-        /*
-         * We try to keep most existing code unaware of our activities
-         * ( plus, maintain alphabetical order with carefully chosen )
-         * ( function names: forest_a, forest_b, forest_c & forest_d )
-         * ( each with exactly one letter more than its predecessor! ) */
-static proc_t **Seed_ppt;                   // temporary win ppt pointer
-static proc_t **Tree_ppt;                   // forest_create will resize
-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 unused proc_t padding byte. */
-static void forest_adds (const int self, int level) {
-   int i;
-
-   if (Tree_idx < Frame_maxtask) {          // 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
-      Tree_ppt[Tree_idx++]->pad_3 = level;  // borrow 1 byte, 127 levels
-#ifdef TREE_SCANALL
-      for (i = 0; i < Frame_maxtask; i++) {
-         if (i == self) continue;
-#else
-      for (i = self + 1; i < Frame_maxtask; i++) {
-#endif
-         if (Seed_ppt[self]->tid == Seed_ppt[i]->tgid
-         || (Seed_ppt[self]->tid == Seed_ppt[i]->ppid && Seed_ppt[i]->tid == Seed_ppt[i]->tgid))
-            forest_adds(i, level + 1);      // got one child any others?
-      }
-   }
-} // end: forest_adds
-
-
-#ifndef TREE_SCANALL
-        /*
-         * Our qsort callback to order a ppt by the non-display start_time
-         * which will make us immune from any pid, ppid or tgid anomalies
-         * if/when pid values are wrapped by the kernel! */
-static int forest_based (const proc_t **x, const proc_t **y) {
-   if ( (*x)->start_time > (*y)->start_time ) return  1;
-   if ( (*x)->start_time < (*y)->start_time ) return -1;
-   return 0;
-} // end: forest_based
-#endif
-
-
-        /*
-         * This routine is responsible for preparing the proc_t's for
-         * a forest display in the designated window.  Upon completion,
-         * he'll replace the original window ppt with our specially
-         * ordered forest version. */
-static void forest_create (WIN_t *q) {
-   static int hwmsav;
-   int i;
-
-   Seed_ppt = q->ppt;                       // avoid passing WIN_t ptrs
-   if (!Tree_idx) {                         // do just once per frame
-      if (hwmsav < Frame_maxtask) {         // grow, but never shrink
-         hwmsav = Frame_maxtask;
-         Tree_ppt = alloc_r(Tree_ppt, sizeof(proc_t*) * hwmsav);
-      }
-#ifndef TREE_SCANALL
-      qsort(Seed_ppt, Frame_maxtask, sizeof(proc_t*), (QFP_t)forest_based);
-#endif
-      for (i = 0; i < Frame_maxtask; i++)   // avoid any hidepid distortions
-         if (!Seed_ppt[i]->pad_3)           // identify real or pretend trees
-            forest_adds(i, 0);              // add as parent plus its children
-   }
-   memcpy(Seed_ppt, Tree_ppt, sizeof(proc_t*) * Frame_maxtask);
-} // end: forest_create
-
-
-        /*
-         * This guy adds the artwork to either p->cmd or p->cmdline
-         * when in forest view mode, otherwise he just returns 'em. */
-static inline const char *forest_display (const WIN_t *q, const proc_t *p) {
-#ifndef SCROLLVAR_NO
-   static char buf[1024*64*2]; // the same as readproc's MAX_BUFSZ
-#else
-   static char buf[ROWMINSIZ];
-#endif
-   const char *which = (CHKw(q, Show_CMDLIN)) ? *p->cmdline : p->cmd;
-
-   if (!CHKw(q, Show_FOREST) || !p->pad_3) return which;
-   if (p->pad_3 > 100) snprintf(buf, sizeof(buf), "%400s%s", " +  ", which);
-   else snprintf(buf, sizeof(buf), "%*s%s", (4 * p->pad_3), " `- ", which);
-   return buf;
-} // end: forest_display
-\f
 /*######  Main Screen routines  ##########################################*/
 
         /*
index 7742a8ef094cc1830a9c41773e184f5a6f582cf1..0f2b59cae2de9fbf26e42a1ae4d3ae44ac54709b 100644 (file)
--- a/top/top.h
+++ b/top/top.h
@@ -779,6 +779,13 @@ typedef struct WIN_t {
 //atic void          wins_reflag (int what, int flg);
 //atic void          wins_stage_1 (void);
 //atic void          wins_stage_2 (void);
+/*------  Forest View support  -------------------------------------------*/
+//atic void          forest_adds (const int self, int level);
+#ifndef TREE_SCANALL
+//atic int           forest_based (const proc_t **x, const proc_t **y);
+#endif
+//atic void          forest_create (WIN_t *q);
+//atic inline const char *forest_display (const WIN_t *q, const proc_t *p);
 /*------  Interactive Input Tertiary support  ----------------------------*/
 //atic inline int    find_ofs (const WIN_t *q, const char *buf);
 //atic void          find_string (int ch);
@@ -791,13 +798,6 @@ typedef struct WIN_t {
 //atic void          keys_task (int ch);
 //atic void          keys_window (int ch);
 //atic void          keys_xtra (int ch);
-/*------  Forest View support  -------------------------------------------*/
-//atic void          forest_adds (const int self, int level);
-#ifndef TREE_SCANALL
-//atic int           forest_based (const proc_t **x, const proc_t **y);
-#endif
-//atic void          forest_create (WIN_t *q);
-//atic inline const char *forest_display (const WIN_t *q, const proc_t *p);
 /*------  Main Screen routines  ------------------------------------------*/
 //atic void          do_key (int ch);
 //atic void          summary_hlp (CPU_t *cpu, const char *pfx);