Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/ps Calculate field widths on the fly so that all columns...
details: https://anonhg.NetBSD.org/src/rev/2257d3c1308d
branches: trunk
changeset: 487396:2257d3c1308d
user: simonb <simonb%NetBSD.org@localhost>
date: Wed Jun 07 04:57:59 2000 +0000
description:
Calculate field widths on the fly so that all columns line up nicely
and make more effective use of screen real estate when some columns
(eg USER and VSZ) didn't need the full default width.
diffstat:
bin/ps/extern.h | 54 ++--
bin/ps/keyword.c | 134 ++++++-------
bin/ps/print.c | 537 ++++++++++++++++++++++++++++++++++++++++++------------
bin/ps/ps.c | 53 +++--
bin/ps/ps.h | 20 +-
5 files changed, 548 insertions(+), 250 deletions(-)
diffs (truncated from 1379 to 300 lines):
diff -r b19259fe262c -r 2257d3c1308d bin/ps/extern.h
--- a/bin/ps/extern.h Wed Jun 07 04:40:46 2000 +0000
+++ b/bin/ps/extern.h Wed Jun 07 04:57:59 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.18 2000/06/02 03:39:02 simonb Exp $ */
+/* $NetBSD: extern.h,v 1.19 2000/06/07 04:57:59 simonb Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -50,42 +50,42 @@
extern VARENT *vhead;
__BEGIN_DECLS
-void command __P((struct kinfo_proc2 *, VARENT *));
-void cputime __P((struct kinfo_proc2 *, VARENT *));
+void command __P((struct kinfo_proc2 *, VARENT *, int));
+void cputime __P((struct kinfo_proc2 *, VARENT *, int));
int donlist __P((void));
int donlist_sysctl __P((void));
void fmt_puts __P((char *, int *));
void fmt_putc __P((int, int *));
double getpcpu __P((struct kinfo_proc2 *));
double getpmem __P((struct kinfo_proc2 *));
-void logname __P((struct kinfo_proc2 *, VARENT *));
-void longtname __P((struct kinfo_proc2 *, VARENT *));
-void lstarted __P((struct kinfo_proc2 *, VARENT *));
-void maxrss __P((struct kinfo_proc2 *, VARENT *));
+void logname __P((struct kinfo_proc2 *, VARENT *, int));
+void longtname __P((struct kinfo_proc2 *, VARENT *, int));
+void lstarted __P((struct kinfo_proc2 *, VARENT *, int));
+void maxrss __P((struct kinfo_proc2 *, VARENT *, int));
void nlisterr __P((struct nlist *));
-void p_rssize __P((struct kinfo_proc2 *, VARENT *));
-void pagein __P((struct kinfo_proc2 *, VARENT *));
+void p_rssize __P((struct kinfo_proc2 *, VARENT *, int));
+void pagein __P((struct kinfo_proc2 *, VARENT *, int));
void parsefmt __P((char *));
-void pcpu __P((struct kinfo_proc2 *, VARENT *));
-void pmem __P((struct kinfo_proc2 *, VARENT *));
-void pnice __P((struct kinfo_proc2 *, VARENT *));
-void pri __P((struct kinfo_proc2 *, VARENT *));
+void pcpu __P((struct kinfo_proc2 *, VARENT *, int));
+void pmem __P((struct kinfo_proc2 *, VARENT *, int));
+void pnice __P((struct kinfo_proc2 *, VARENT *, int));
+void pri __P((struct kinfo_proc2 *, VARENT *, int));
void printheader __P((void));
struct kinfo_proc2
- *getkinfo_procfs __P((int, int, int*));
+ *getkinfo_procfs __P((int, int, int *));
char **procfs_getargv __P((const struct kinfo_proc2 *, int));
-void pvar __P((struct kinfo_proc2 *, VARENT *));
-void rssize __P((struct kinfo_proc2 *, VARENT *));
-void runame __P((struct kinfo_proc2 *, VARENT *));
+void pvar __P((struct kinfo_proc2 *, VARENT *, int));
+void rssize __P((struct kinfo_proc2 *, VARENT *, int));
+void runame __P((struct kinfo_proc2 *, VARENT *, int));
void showkey __P((void));
-void started __P((struct kinfo_proc2 *, VARENT *));
-void state __P((struct kinfo_proc2 *, VARENT *));
-void tdev __P((struct kinfo_proc2 *, VARENT *));
-void tname __P((struct kinfo_proc2 *, VARENT *));
-void tsize __P((struct kinfo_proc2 *, VARENT *));
-void ucomm __P((struct kinfo_proc2 *, VARENT *));
-void uname __P((struct kinfo_proc2 *, VARENT *));
-void uvar __P((struct kinfo_proc2 *, VARENT *));
-void vsize __P((struct kinfo_proc2 *, VARENT *));
-void wchan __P((struct kinfo_proc2 *, VARENT *));
+void started __P((struct kinfo_proc2 *, VARENT *, int));
+void state __P((struct kinfo_proc2 *, VARENT *, int));
+void tdev __P((struct kinfo_proc2 *, VARENT *, int));
+void tname __P((struct kinfo_proc2 *, VARENT *, int));
+void tsize __P((struct kinfo_proc2 *, VARENT *, int));
+void ucomm __P((struct kinfo_proc2 *, VARENT *, int));
+void uname __P((struct kinfo_proc2 *, VARENT *, int));
+void uvar __P((struct kinfo_proc2 *, VARENT *, int));
+void vsize __P((struct kinfo_proc2 *, VARENT *, int));
+void wchan __P((struct kinfo_proc2 *, VARENT *, int));
__END_DECLS
diff -r b19259fe262c -r 2257d3c1308d bin/ps/keyword.c
--- a/bin/ps/keyword.c Wed Jun 07 04:40:46 2000 +0000
+++ b/bin/ps/keyword.c Wed Jun 07 04:57:59 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: keyword.c,v 1.24 2000/06/02 03:39:02 simonb Exp $ */
+/* $NetBSD: keyword.c,v 1.25 2000/06/07 04:57:59 simonb Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)keyword.c 8.5 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: keyword.c,v 1.24 2000/06/02 03:39:02 simonb Exp $");
+__RCSID("$NetBSD: keyword.c,v 1.25 2000/06/07 04:57:59 simonb Exp $");
#endif
#endif /* not lint */
@@ -63,126 +63,118 @@
static VAR *findvar __P((char *));
static int vcmp __P((const void *, const void *));
-
-#define SIGWIDTH (((_NSIG / 32) + 1) * 8)
-
#ifdef NOTINUSE
-int utime(), stime(), ixrss(), idrss(), isrss();
- {{"utime"}, "UTIME", USER, utime, 4},
- {{"stime"}, "STIME", USER, stime, 4},
- {{"ixrss"}, "IXRSS", USER, ixrss, 4},
- {{"idrss"}, "IDRSS", USER, idrss, 4},
- {{"isrss"}, "ISRSS", USER, isrss, 4},
+ {"stime", "STIME", NULL, 0, cputime}, /* XXX add stime, utime ... */
+ {"utime", "UTIME", NULL, 0, cputime}, /* ... display to cputime() */
+ {"idrss", "IDRSS", NULL, 0, pvar, 0, POFF(p_uru_idrss), ULONG, "d"},
+ {"isrss", "ISRSS", NULL, 0, pvar, 0, POFF(p_uru_isrss), ULONG, "d"},
+ {"ixrss", "IXRSS", NULL, 0, pvar, 0, POFF(p_uru_ixrss), ULONG, "d"},
#endif
/* Compute offset in common structures. */
#define POFF(x) offsetof(struct kinfo_proc2, x)
#define UIDFMT "u"
-#define UIDLEN 5
#define UID(n1, n2, fn, off) \
- { n1, n2, NULL, 0, fn, UIDLEN, off, UINT32, UIDFMT }
+ { n1, n2, NULL, 0, fn, 0, off, UINT32, UIDFMT }
#define GID(n1, n2, fn, off) UID(n1, n2, fn, off)
#define PIDFMT "d"
-#define PIDLEN 5
#define PID(n1, n2, fn, off) \
- { n1, n2, NULL, 0, fn, PIDLEN, off, INT32, PIDFMT }
-
-#define USERLEN 8
+ { n1, n2, NULL, 0, fn, 0, off, INT32, PIDFMT }
VAR var[] = {
- {"%cpu", "%CPU", NULL, 0, pcpu, 4},
- {"%mem", "%MEM", NULL, 0, pmem, 4},
- {"acflag", "ACFLG", NULL, 0, pvar, 3, POFF(p_acflag), USHORT, "x"},
+ {"%cpu", "%CPU", NULL, 0, pcpu},
+ {"%mem", "%MEM", NULL, 0, pmem},
+ {"acflag", "ACFLG", NULL, 0, pvar, 0, POFF(p_acflag), USHORT, "x"},
{"acflg", "", "acflag"},
{"blocked", "", "sigmask"},
{"caught", "", "sigcatch"},
- {"command", "COMMAND", NULL, COMM|LJUST|USER, command, 16},
- {"cpu", "CPU", NULL, 0, pvar, 3, POFF(p_estcpu), UINT, "d"},
+ {"command", "COMMAND", NULL, COMM|LJUST, command},
+ {"cpu", "CPU", NULL, 0, pvar, 0, POFF(p_estcpu), UINT, "d"},
{"cputime", "", "time"},
- {"f", "F", NULL, 0, pvar, 7, POFF(p_flag), INT, "x"},
+ {"f", "F", NULL, 0, pvar, 0, POFF(p_flag), INT, "x"},
{"flags", "", "f"},
- {"holdcnt", "HOLDCNT", NULL, 0, pvar, 8, POFF(p_holdcnt), INT, "d"},
+ {"holdcnt", "HOLDCNT", NULL, 0, pvar, 0, POFF(p_holdcnt), INT, "d"},
{"ignored", "", "sigignore"},
- {"inblk", "INBLK", NULL, USER, pvar, 4, POFF(p_uru_inblock), LONG, "d"},
+ {"inblk", "INBLK", NULL, 0, pvar, 0, POFF(p_uru_inblock), ULONG, "d"},
{"inblock", "", "inblk"},
- {"jobc", "JOBC", NULL, 0, pvar, 4, POFF(p_jobc), SHORT, "d"},
- {"ktrace", "KTRACE", NULL, 0, pvar, 8, POFF(p_traceflag), INT, "x"},
+ {"jobc", "JOBC", NULL, 0, pvar, 0, POFF(p_jobc), SHORT, "d"},
+ {"ktrace", "KTRACE", NULL, 0, pvar, 0, POFF(p_traceflag), INT, "x"},
/* XXX */
- {"ktracep", "KTRACEP", NULL, 0, pvar, 8, POFF(p_tracep), KPTR, "x"},
- {"lim", "LIM", NULL, 0, maxrss, 5},
- {"login", "LOGIN", NULL, LJUST, logname, MAXLOGNAME},
+ {"ktracep", "KTRACEP", NULL, 0, pvar, 0, POFF(p_tracep), KPTR, "x"},
+ {"lim", "LIM", NULL, 0, maxrss},
+ {"login", "LOGIN", NULL, LJUST, logname},
{"logname", "", "login"},
- {"lstart", "STARTED", NULL, LJUST|USER, lstarted, 28},
- {"majflt", "MAJFLT", NULL, USER, pvar, 4, POFF(p_uru_majflt), LONG, "d"},
- {"minflt", "MINFLT", NULL, USER, pvar, 4, POFF(p_uru_minflt), LONG, "d"},
- {"msgrcv", "MSGRCV", NULL, USER, pvar, 4, POFF(p_uru_msgrcv), LONG, "d"},
- {"msgsnd", "MSGSND", NULL, USER, pvar, 4, POFF(p_uru_msgsnd), LONG, "d"},
+ {"lstart", "STARTED", NULL, LJUST, lstarted},
+ {"majflt", "MAJFLT", NULL, 0, pvar, 0, POFF(p_uru_majflt), ULONG, "d"},
+ {"minflt", "MINFLT", NULL, 0, pvar, 0, POFF(p_uru_minflt), ULONG, "d"},
+ {"msgrcv", "MSGRCV", NULL, 0, pvar, 0, POFF(p_uru_msgrcv), ULONG, "d"},
+ {"msgsnd", "MSGSND", NULL, 0, pvar, 0, POFF(p_uru_msgsnd), ULONG, "d"},
{"ni", "", "nice"},
- {"nice", "NI", NULL, 0, pnice, 3},
- {"nivcsw", "NIVCSW", NULL, USER, pvar, 5, POFF(p_uru_nivcsw), LONG, "d"},
+ {"nice", "NI", NULL, 0, pnice},
+ {"nivcsw", "NIVCSW", NULL, 0, pvar, 0, POFF(p_uru_nivcsw), ULONG, "d"},
{"nsignals", "", "nsigs"},
- {"nsigs", "NSIGS", NULL, USER, pvar, 4, POFF(p_uru_nsignals), LONG, "d"},
- {"nswap", "NSWAP", NULL, USER, pvar, 4, POFF(p_uru_nswap), LONG, "d"},
- {"nvcsw", "NVCSW", NULL, USER, pvar, 5, POFF(p_uru_nvcsw), LONG, "d"},
+ {"nsigs", "NSIGS", NULL, 0, pvar, 0, POFF(p_uru_nsignals), ULONG, "d"},
+ {"nswap", "NSWAP", NULL, 0, pvar, 0, POFF(p_uru_nswap), ULONG, "d"},
+ {"nvcsw", "NVCSW", NULL, 0, pvar, 0, POFF(p_uru_nvcsw), ULONG, "d"},
/* XXX */
- {"nwchan", "WCHAN", NULL, 0, pvar, 6, POFF(p_wchan), KPTR, "x"},
- {"oublk", "OUBLK", NULL, USER, pvar, 4, POFF(p_uru_oublock), LONG, "d"},
+ {"nwchan", "WCHAN", NULL, 0, pvar, 0, POFF(p_wchan), KPTR, "x"},
+ {"oublk", "OUBLK", NULL, 0, pvar, 0, POFF(p_uru_oublock), ULONG, "d"},
{"oublock", "", "oublk"},
/* XXX */
- {"p_ru", "P_RU", NULL, 0, pvar, 6, POFF(p_ru), KPTR, "x"},
+ {"p_ru", "P_RU", NULL, 0, pvar, 0, POFF(p_ru), KPTR, "x"},
/* XXX */
- {"paddr", "PADDR", NULL, 0, pvar, 6, POFF(p_paddr), KPTR, "x"},
- {"pagein", "PAGEIN", NULL, USER, pagein, 6},
+ {"paddr", "PADDR", NULL, 0, pvar, 0, POFF(p_paddr), KPTR, "x"},
+ {"pagein", "PAGEIN", NULL, 0, pagein},
{"pcpu", "", "%cpu"},
{"pending", "", "sig"},
PID("pgid", "PGID", pvar, POFF(p__pgid)),
PID("pid", "PID", pvar, POFF(p_pid)),
{"pmem", "", "%mem"},
PID("ppid", "PPID", pvar, POFF(p_ppid)),
- {"pri", "PRI", NULL, 0, pri, 3},
- {"re", "RE", NULL, INF127, pvar, 3, POFF(p_swtime), UINT, "d"},
+ {"pri", "PRI", NULL, 0, pri},
+ {"re", "RE", NULL, INF127, pvar, 0, POFF(p_swtime), UINT, "d"},
GID("rgid", "RGID", pvar, POFF(p_rgid)),
/* XXX */
- {"rlink", "RLINK", NULL, 0, pvar, 8, POFF(p_back), KPTR, "x"},
- {"rss", "RSS", NULL, 0, p_rssize, 4},
+ {"rlink", "RLINK", NULL, 0, pvar, 0, POFF(p_back), KPTR, "x"},
+ {"rss", "RSS", NULL, 0, p_rssize},
{"rssize", "", "rsz"},
- {"rsz", "RSZ", NULL, 0, rssize, 4},
+ {"rsz", "RSZ", NULL, 0, rssize},
UID("ruid", "RUID", pvar, POFF(p_ruid)),
- {"ruser", "RUSER", NULL, LJUST, runame, USERLEN},
- {"sess", "SESS", NULL, 0, pvar, 6, POFF(p_sess), KPTR24, "x"},
+ {"ruser", "RUSER", NULL, LJUST, runame},
+ {"sess", "SESS", NULL, 0, pvar, 0, POFF(p_sess), KPTR24, "x"},
PID("sid", "SID", pvar, POFF(p_sid)),
{"sig", "PENDING",
- NULL, 0, pvar, SIGWIDTH, POFF(p_siglist), SIGLIST, "s"},
+ NULL, 0, pvar, 0, POFF(p_siglist), SIGLIST, "s"},
{"sigcatch", "CAUGHT",
- NULL, 0, pvar, SIGWIDTH, POFF(p_sigcatch), SIGLIST, "s"},
+ NULL, 0, pvar, 0, POFF(p_sigcatch), SIGLIST, "s"},
{"sigignore", "IGNORED",
- NULL, 0, pvar, SIGWIDTH, POFF(p_sigignore), SIGLIST, "s"},
+ NULL, 0, pvar, 0, POFF(p_sigignore), SIGLIST, "s"},
{"sigmask", "BLOCKED",
- NULL, 0, pvar, SIGWIDTH, POFF(p_sigmask), SIGLIST, "s"},
- {"sl", "SL", NULL, INF127, pvar, 3, POFF(p_slptime), UINT, "d"},
- {"start", "STARTED", NULL, LJUST|USER, started, 8},
+ NULL, 0, pvar, 0, POFF(p_sigmask), SIGLIST, "s"},
+ {"sl", "SL", NULL, INF127, pvar, 0, POFF(p_slptime), UINT, "d"},
+ {"start", "STARTED", NULL, 0, started},
{"stat", "", "state"},
- {"state", "STAT", NULL, 0, state, 4},
+ {"state", "STAT", NULL, LJUST, state},
GID("svgid", "SVGID", pvar, POFF(p_gid)),
UID("svuid", "SVUID", pvar, POFF(p_uid)),
- {"tdev", "TDEV", NULL, 0, tdev, 4},
- {"time", "TIME", NULL, USER, cputime, 9},
+ {"tdev", "TDEV", NULL, 0, tdev},
+ {"time", "TIME", NULL, 0, cputime},
PID("tpgid", "TGPID", pvar, POFF(p_tpgid)),
- {"tsess", "TSESS", NULL, 0, pvar, 6, POFF(p_tsess), KPTR, "x"},
- {"tsiz", "TSIZ", NULL, 0, tsize, 4},
- {"tt", "TT", NULL, LJUST, tname, 3},
- {"tty", "TTY", NULL, LJUST, longtname, 8},
- {"ucomm", "UCOMM", NULL, LJUST, ucomm, MAXCOMLEN},
+ {"tsess", "TSESS", NULL, 0, pvar, 0, POFF(p_tsess), KPTR, "x"},
+ {"tsiz", "TSIZ", NULL, 0, tsize},
+ {"tt", "TT", NULL, LJUST, tname},
+ {"tty", "TTY", NULL, LJUST, longtname},
+ {"ucomm", "UCOMM", NULL, LJUST, ucomm},
UID("uid", "UID", pvar, POFF(p_uid)),
- {"upr", "UPR", NULL, 0, pvar, 3, POFF(p_usrpri), UCHAR, "d"},
- {"user", "USER", NULL, LJUST, uname, USERLEN},
+ {"upr", "UPR", NULL, 0, pvar, 0, POFF(p_usrpri), UCHAR, "d"},
+ {"user", "USER", NULL, LJUST, uname},
{"usrpri", "", "upr"},
{"vsize", "", "vsz"},
- {"vsz", "VSZ", NULL, 0, vsize, 5},
- {"wchan", "WCHAN", NULL, LJUST, wchan, 6},
- {"xstat", "XSTAT", NULL, 0, pvar, 4, POFF(p_xstat), USHORT, "x"},
+ {"vsz", "VSZ", NULL, 0, vsize},
+ {"wchan", "WCHAN", NULL, LJUST, wchan},
+ {"xstat", "XSTAT", NULL, 0, pvar, 0, POFF(p_xstat), USHORT, "x"},
{""},
};
diff -r b19259fe262c -r 2257d3c1308d bin/ps/print.c
--- a/bin/ps/print.c Wed Jun 07 04:40:46 2000 +0000
+++ b/bin/ps/print.c Wed Jun 07 04:57:59 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: print.c,v 1.52 2000/06/02 03:39:02 simonb Exp $ */
+/* $NetBSD: print.c,v 1.53 2000/06/07 04:58:00 simonb Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
#else
-__RCSID("$NetBSD: print.c,v 1.52 2000/06/02 03:39:02 simonb Exp $");
+__RCSID("$NetBSD: print.c,v 1.53 2000/06/07 04:58:00 simonb Exp $");
#endif
Home |
Main Index |
Thread Index |
Old Index