From owner-freebsd-current Sat Jul 5 04:34:23 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id EAA03497 for current-outgoing; Sat, 5 Jul 1997 04:34:23 -0700 (PDT) Received: from labs.usn.blaze.net.au (labs.usn.blaze.net.au [203.17.53.30]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id EAA03488 for ; Sat, 5 Jul 1997 04:34:17 -0700 (PDT) Received: from labs.usn.blaze.net.au (local [127.0.0.1]) by labs.usn.blaze.net.au (8.8.5/8.8.5) with ESMTP id VAA01367; Sat, 5 Jul 1997 21:34:06 +1000 (EST) Message-Id: <199707051134.VAA01367@labs.usn.blaze.net.au> X-Mailer: exmh version 2.0gamma 1/27/96 To: Wolfram Schneider cc: current@FreeBSD.ORG Subject: Re: long usernames in top In-reply-to: Your message of "Sat, 05 Jul 1997 12:01:32 +0200." <199707051001.MAA00736@panke.panke.de> X-Face: (W@z~5kg?"+5?!2kHP)+l369.~a@oTl^8l87|/s8"EH?Uk~P#N+Ec~Z&@;'LL!;3?y Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 05 Jul 1997 21:34:04 +1000 From: David Nugent Sender: owner-current@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk > 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/