summaryrefslogtreecommitdiffstats
path: root/bin/ps/ps.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1997-04-29 05:26:05 +0000
committerjkh <jkh@FreeBSD.org>1997-04-29 05:26:05 +0000
commite2ef6a625f0f47896ca66ad15621eef18c956c3f (patch)
tree2afb09786a097e18b5da9bfdffbd76aa576a3d78 /bin/ps/ps.c
parente3a67334252e979065753f5b0a592767c576f09d (diff)
downloadFreeBSD-src-e2ef6a625f0f47896ca66ad15621eef18c956c3f.zip
FreeBSD-src-e2ef6a625f0f47896ca66ad15621eef18c956c3f.tar.gz
Dynamically adjust size of displayed username to the longest username which
appears, not the longest _maximum_ username (this should probably also go into 2.2, for the day when we bump up the username length there too). Submitted-By: Terry Lambert <terry@lambert.org>
Diffstat (limited to 'bin/ps/ps.c')
-rw-r--r--bin/ps/ps.c51
1 files changed, 46 insertions, 5 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index a26b981..a91877f 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ps.c,v 1.17 1997/02/22 14:05:08 peter Exp $
+ * $Id: ps.c,v 1.18 1997/03/28 15:24:29 imp Exp $
*/
#ifndef lint
@@ -92,6 +92,8 @@ static char *kludge_oldps_options __P((char *));
static int pscomp __P((const void *, const void *));
static void saveuser __P((KINFO *));
static void scanvars __P((void));
+static void dynsizevars __P((KINFO *));
+static void sizevars __P((void));
static void usage __P((void));
char dfmt[] = "pid tt state time command";
@@ -324,7 +326,11 @@ main(argc, argv)
kinfo[i].ki_p = kp;
if (needuser)
saveuser(&kinfo[i]);
+ dynsizevars(&kinfo[i]);
}
+
+ sizevars();
+
/*
* print header
*/
@@ -362,6 +368,45 @@ scanvars()
{
struct varent *vent;
VAR *v;
+
+ for (vent = vhead; vent; vent = vent->next) {
+ v = vent->var;
+ if (v->flag & DSIZ) {
+ v->dwidth = v->width;
+ v->width = 0;
+ }
+ if (v->flag & USER)
+ needuser = 1;
+ if (v->flag & COMM)
+ needcomm = 1;
+ }
+}
+
+static void
+dynsizevars(ki)
+ KINFO *ki;
+{
+ struct varent *vent;
+ VAR *v;
+ int i;
+
+ for (vent = vhead; vent; vent = vent->next) {
+ v = vent->var;
+ if (!(v->flag & DSIZ))
+ continue;
+ i = (v->sproc)( ki);
+ if (v->width < i)
+ v->width = i;
+ if (v->width > v->dwidth)
+ v->width = v->dwidth;
+ }
+}
+
+static void
+sizevars()
+{
+ struct varent *vent;
+ VAR *v;
int i;
for (vent = vhead; vent; vent = vent->next) {
@@ -370,10 +415,6 @@ scanvars()
if (v->width < i)
v->width = i;
totwidth += v->width + 1; /* +1 for space */
- if (v->flag & USER)
- needuser = 1;
- if (v->flag & COMM)
- needcomm = 1;
}
totwidth--;
}
OpenPOWER on IntegriCloud