Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 05 Jul 1997 21:34:04 +1000
From:      David Nugent <davidn@labs.usn.blaze.net.au>
To:        Wolfram Schneider <wosch@apfel.de>
Cc:        current@FreeBSD.ORG
Subject:   Re: long usernames in top 
Message-ID:  <199707051134.VAA01367@labs.usn.blaze.net.au>
In-Reply-To: Your message of "Sat, 05 Jul 1997 12:01:32 %2B0200." <199707051001.MAA00736@panke.panke.de> 

next in thread | previous in thread | raw e-mail | index | archive | help
>  The long usernames in top(1) looks not well. In most cases
>  the usernames are less than 8 chars. Top reserves 16 chars
>  for the username in the output string.

Yes, unnecessarily wasted space.

>  Here is a workaround. Top should print only the first 10
>  characters. If the username is longer than 10 characters, the
>  10th character will be replaces with an asterisk ('*').

Yuck, yuck, yuck.

int getmaxnamelen(void)
{
  int maxnamelen = 8;
  struct passwd *pw;

  setpwent();
  while ((pw=getpwent()) != NULL) {
    if (pw->pw_name) {
      int nlen = strlen(pw->pw_name;
      if (nlen > maxnamelen)
        maxnamelen = nlen;
    }
  }
  endpwent();
  return maxnamelen > SOME_MAX_VALUE ? SOME_MAX_VALUE : maxnamelen;
}

Use this to determine the maximum name. 8 is an obvious minimum, and
do this at startup. If larger names are added while top is running,
well, tough, they get truncated which is no big deal.

I've had this on my todo list for a while since this was last
discussed here, but haven't had much time of late to do much.
Note that this will also work with 2.2 systems, or in fact any
system, so the patch could (and should) be sent to the author.

Sitting the length at some arbitrary small value is silly.

Regards,
David

-- 
David Nugent - Unique Computing Pty Ltd - Melbourne, Australia
Voice +61-3-9791-9547  Data/BBS +61-3-9792-3507  3:632/348@fidonet
davidn@freebsd.org davidn@blaze.net.au http://www.blaze.net.au/~davidn/




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199707051134.VAA01367>