rem: Frame_maxtask = 0;
context: static void frame_states (proc_t **ppt, int show){   static HIST_t   *hist_sav;   static HIST_t   *hist_new;   static unsigned  hist_siz; // number of structs   unsigned         total, running, sleeping, stopped, zombie;   HIST_t          *hist_tmp;   if (!hist_sav) {           // 1st time through      Frame_maxtask = 0;      hist_siz = 100;      hist_sav = alloc_c(sizeof(HIST_t)*hist_siz);      hist_new = alloc_c(sizeof(HIST_t)*hist_siz);   }   // reuse memory each time around   hist_tmp = hist_sav;   hist_sav = hist_new;   hist_new = hist_tmp;   total = running = sleeping = stopped = zombie = 0;   time_elapsed();      /* make a pass through the data to get stats */   while (-1 != ppt[total]->pid) {                      /* calculations //// */      TICS_t tics;      proc_t *this = ppt[total];      int i;      switch (this->state) {         case 'S':         case 'D':            sleeping++;            break;         case 'T':            stopped++;            break;         case 'Z':            zombie++;            break;         case 'R':            running++;            break;      }      if (total >= hist_siz) {         hist_siz = hist_siz * 5 / 4 + 1;  // grow by at least 25%         hist_sav = alloc_r(hist_sav, sizeof(HIST_t)*hist_siz);         hist_new = alloc_r(hist_new, sizeof(HIST_t)*hist_siz);      }         /* calculate time in this process; the sum of user time (utime)            + system time (stime) -- but PLEASE dont waste time and effort on            calcs and saves that go unused, like the old top! */      hist_new[total].pid  = this->pid;      hist_new[total].tics = tics = (this->utime + this->stime);         /* find matching entry from previous pass and make ticks elapsed */      for (i = 0; i < Frame_maxtask; i++) {         if (this->pid == hist_sav[i].pid) {            tics -= hist_sav[i].tics;            break;         }      }         /* we're just saving elapsed tics, to be converted into %cpu if            this task wins it's displayable screen row lottery... */      this->pcpu = tics;      total++;   } /* end: while 'pids' */      /* shout results to the world (and us too, the next time around) */   Frame_maxtask = total;   if (show) {                                          /* display ///////// */      static CPUS_t *smpcpu = NULL;         /* display Task states */      show_special(fmtmk(STATES_line1         , total, running, sleeping, stopped, zombie));      Msg_row += 1;         /* refresh our /proc/stat data... */      smpcpu = refreshcpus(smpcpu);      if (CHKw(Curwin, View_CPUSUM)) {            /* display just the 1st /proc/stat line */         cpudo(&smpcpu[Cpu_tot], "Cpu(s):");      } else {         int i;         char tmp[SMLBUFSIZ];            /* display each cpu's states separately */         for (i = 0; i < Cpu_tot; i++) {            sprintf(tmp, " Cpu%-2d:", Mode_irixps ? i : Cpu_map[i]);            cpudo(&smpcpu[i], tmp);         }      }   } /* end: if 'show' */}