> Date: Sat, 12 Oct 2019 18:54:19 +0200
> From: Klemens Nanni <k...@openbsd.org>
> 
> On Sat, Oct 12, 2019 at 09:53:44AM -0600, Theo de Raadt wrote:
> > I am suggesting you put the spaces after the cpu#.
> Is this better?
> 
> 4   CPUs:  0.0% user,  0.0% nice,  0.0% sys,  0.0% spin,  0.0% intr,  100% 
> idle
> 
> CPU  0  :  0.0% user,  0.0% nice,  0.0% sys,  0.0% spin,  0.0% intr,  100% 
> idle
> CPU  1  :  0.0% user,  0.0% nice,  0.0% sys,  0.0% spin,  0.0% intr,  100% 
> idle
> CPU  2  :  0.0% user,  0.0% nice,  0.0% sys,  0.0% spin,  0.0% intr,  100% 
> idle
> CPU  3  :  1.1% user,  0.0% nice,  0.0% sys,  0.0% spin,  0.0% intr, 98.9% 
> idle

This is horrible.  Please don't do this.


> Index: display.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/top/display.c,v
> retrieving revision 1.60
> diff -u -p -r1.60 display.c
> --- display.c 8 Oct 2019 07:26:59 -0000       1.60
> +++ display.c 12 Oct 2019 16:48:14 -0000
> @@ -72,7 +72,7 @@ FILE           *debug;
>  
>  static int      display_width = MAX_COLS;
>  
> -static char    *cpustates_tag(int);
> +static void     cpustates_tag(int);
>  static int      string_count(char **);
>  static void     summary_format(char *, size_t, int *, char **);
>  static int   readlinedumb(char *, int);
> @@ -335,44 +335,16 @@ i_procstates(int total, int *states, int
>  
>  /* cpustates_tag() calculates the correct tag to use to label the line */
>  
> -static char *
> +static void
>  cpustates_tag(int cpu)
>  {
>       if (screen_length > 3 || !smart_terminal) {
> -             static char *tag;
> -             static int cpulen, old_width;
> -             int i;
> -
> -             if (cpulen == 0 && ncpu > 1) {
> -                     /* compute length of the cpu string */
> -                     for (i = ncpu; i > 0; cpulen++, i /= 10)
> -                             continue;
> -             }
> -
> -             if (old_width == screen_width) {
> -                     if (ncpu > 1) {
> -                             /* just store the cpu number in the tag */
> -                             i = tag[3 + cpulen];
> -                             snprintf(tag + 3, cpulen + 1, "%.*d", cpulen, 
> cpu);
> -                             tag[3 + cpulen] = i;
> -                     }
> -             } else {
> -                     /*
> -                      * use a long tag if it will fit, otherwise use short 
> one.
> -                      */
> -                     free(tag);
> -                     if (cpustate_total_length + 10 + cpulen >= screen_width)
> -                             i = asprintf(&tag, "CPU%.*d: ", cpulen, cpu);
> -                     else
> -                             i = asprintf(&tag, "CPU%.*d states: ", cpulen, 
> cpu);
> -                     if (i == -1)
> -                             tag = NULL;
> -                     else
> -                             old_width = screen_width;
> -             }
> -             return (tag);
> +             if (ncpu > 1)
> +                     printwp("CPU%3d  : ", cpu);
> +             else
> +                     addstrp("CPU     : ");
>       } else
> -             return ("\0");
> +             addstrp("\0");
>  }
>  
>  void
> @@ -438,7 +410,7 @@ i_cpustates(int64_t *ostates, int *onlin
>               if (screen_length > 2 + cpu_line || !smart_terminal) {
>                       move(2 + cpu_line, 0);
>                       clrtoeol();
> -                     addstrp(cpustates_tag(cpu));
> +                     cpustates_tag(cpu);
>  
>                       while ((thisname = *names++) != NULL) {
>                               i
> 
> 

Reply via email to