From: Jan-Simon Pendry Date: Sun, 3 Apr 1994 00:59:57 +0000 (-0800) Subject: prettyness police X-Git-Tag: BSD-4_4_Lite2-Snapshot-Development~2867 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/1a6fd003b66648e0d3449e593d9ff27b3341473e prettyness police SCCS-vsn: bin/ps/nlist.c 8.3 SCCS-vsn: bin/ps/ps.c 8.3 SCCS-vsn: bin/ps/keyword.c 8.4 SCCS-vsn: bin/ps/print.c 8.4 SCCS-vsn: bin/ps/fmt.c 8.2 SCCS-vsn: bin/ps/extern.h 8.2 SCCS-vsn: bin/ps/ps.c 8.3 --- diff --git a/usr/src/bin/ps/extern.h b/usr/src/bin/ps/extern.h index 99746bacb4..aa2981dadc 100644 --- a/usr/src/bin/ps/extern.h +++ b/usr/src/bin/ps/extern.h @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)extern.h 8.1 (Berkeley) %G% + * @(#)extern.h 8.2 (Berkeley) %G% */ struct kinfo; @@ -12,6 +12,9 @@ struct nlist; struct var; struct varent; +extern fixpt_t ccpu; +extern int eval, fscale, mempages, nlistread, rawcpu; +extern int sumrusage, termwidth, totwidth; extern VAR var[]; extern VARENT *vhead; diff --git a/usr/src/bin/ps/fmt.c b/usr/src/bin/ps/fmt.c index 4eb8b77df1..d2b2d404c5 100644 --- a/usr/src/bin/ps/fmt.c +++ b/usr/src/bin/ps/fmt.c @@ -6,7 +6,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)fmt.c 8.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)fmt.c 8.2 (Berkeley) %G%"; #endif /* not lint */ #include @@ -27,9 +27,9 @@ static char *shquote __P((char **)); */ static char * shquote(argv) - register char **argv; + char **argv; { - register char **p, *dst, *src; + char **p, *dst, *src; static char buf[1024]; /* XXX */ if (*argv == 0) { @@ -52,19 +52,19 @@ static char * cmdpart(arg0) char *arg0; { - register char *cp; + char *cp; return ((cp = strrchr(arg0, '/')) != NULL ? cp + 1 : arg0); } char * fmt_argv(argv, cmd, maxlen) - register char **argv; - register char *cmd; + char **argv; + char *cmd; int maxlen; { - register int len; - register char *ap, *cp; + int len; + char *ap, *cp; if (argv == 0 || argv[0] == 0) { if (cmd == NULL) diff --git a/usr/src/bin/ps/keyword.c b/usr/src/bin/ps/keyword.c index 6e36a950f7..95330e582b 100644 --- a/usr/src/bin/ps/keyword.c +++ b/usr/src/bin/ps/keyword.c @@ -6,7 +6,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)keyword.c 8.3 (Berkeley) %G%"; +static char sccsid[] = "@(#)keyword.c 8.4 (Berkeley) %G%"; #endif /* not lint */ #include @@ -237,15 +237,14 @@ VAR var[] = { void showkey() { - extern int termwidth; - register VAR *v; - register int i, len; - register char *p, *sep; + VAR *v; + int i; + char *p, *sep; i = 0; sep = ""; for (v = var; *(p = v->name); ++v) { - len = strlen(p); + int len = strlen(p); if (termwidth && (i += len + 1) > termwidth) { i = len; sep = "\n"; @@ -261,12 +260,13 @@ parsefmt(p) char *p; { static struct varent *vtail; - register VAR *v; - register char *cp; - register struct varent *vent; #define FMTSEP " \t,\n" while (p && *p) { + char *cp; + VAR *v; + struct varent *vent; + while ((cp = strsep(&p, FMTSEP)) != NULL && *cp == '\0') /* void */; if (!(v = findvar(cp))) @@ -290,7 +290,6 @@ static VAR * findvar(p) char *p; { - extern int eval; VAR *v, key; char *hp; int vcmp(); @@ -310,7 +309,7 @@ findvar(p) eval = 1; } parsefmt(v->alias); - return((VAR *)NULL); + return ((VAR *)NULL); } if (!v) { warnx("%s: keyword not found", p); @@ -318,12 +317,12 @@ findvar(p) } if (hp) v->header = hp; - return(v); + return (v); } static int vcmp(a, b) const void *a, *b; { - return(strcmp(((VAR *)a)->name, ((VAR *)b)->name)); + return (strcmp(((VAR *)a)->name, ((VAR *)b)->name)); } diff --git a/usr/src/bin/ps/nlist.c b/usr/src/bin/ps/nlist.c index ef5d348c73..4e66e25612 100644 --- a/usr/src/bin/ps/nlist.c +++ b/usr/src/bin/ps/nlist.c @@ -6,7 +6,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)nlist.c 8.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)nlist.c 8.3 (Berkeley) %G%"; #endif /* not lint */ #include @@ -57,7 +57,6 @@ extern kvm_t *kd; int donlist() { - extern int eval; int rval; #ifdef NEWVM int tmp; diff --git a/usr/src/bin/ps/print.c b/usr/src/bin/ps/print.c index d0e28b09af..006c626449 100644 --- a/usr/src/bin/ps/print.c +++ b/usr/src/bin/ps/print.c @@ -6,7 +6,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)print.c 8.3 (Berkeley) %G%"; +static char sccsid[] = "@(#)print.c 8.4 (Berkeley) %G%"; #endif /* not lint */ #include @@ -40,13 +40,11 @@ static char sccsid[] = "@(#)print.c 8.3 (Berkeley) %G%"; #include "ps.h" -static void printval __P((char*, struct var *)); - void printheader() { - register VAR *v; - register struct varent *vent; + VAR *v; + struct varent *vent; for (vent = vhead; vent; vent = vent->next) { v = vent->var; @@ -68,7 +66,6 @@ command(k, ve) KINFO *k; VARENT *ve; { - extern int termwidth, totwidth; VAR *v; v = ve->var; @@ -79,8 +76,8 @@ command(k, ve) (void)printf("%s ", k->ki_env); (void)printf("%s", k->ki_args); } else { - register int left = termwidth - (totwidth - v->width); - register char *cp; + int left = termwidth - (totwidth - v->width); + char *cp; if (left < 1) /* already wrapped, just use std width */ left = v->width; @@ -131,9 +128,9 @@ state(k, ve) KINFO *k; VARENT *ve; { - register struct proc *p; - register int flag; - register char *cp; + struct proc *p; + int flag; + char *cp; VAR *v; char buf[16]; @@ -332,12 +329,12 @@ started(k, ve) if (!now) (void)time(&now); if (now - k->ki_u.u_start.tv_sec < 24 * SECSPERHOUR) { - static char fmt[] = "%l:@M%p"; - fmt[3] = '%'; /* I *hate* SCCS... */ + /* I *hate* SCCS... */ + static char fmt[] = __CONCAT("%l:%", "M%p"); (void)strftime(buf, sizeof(buf) - 1, fmt, tp); } else if (now - k->ki_u.u_start.tv_sec < 7 * SECSPERDAY) { - static char fmt[] = "%a@I%p"; - fmt[2] = '%'; /* I *hate* SCCS... */ + /* I *hate* SCCS... */ + static char fmt[] = __CONCAT("%a%", "I%p"); (void)strftime(buf, sizeof(buf) - 1, fmt, tp); } else (void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp); @@ -439,7 +436,6 @@ cputime(k, ve) KINFO *k; VARENT *ve; { - extern int sumrusage; VAR *v; long secs; long psecs; /* "parts" of a second. first micro, then centi */ @@ -479,8 +475,6 @@ double getpcpu(k) KINFO *k; { - extern fixpt_t ccpu; - extern int fscale, nlistread, rawcpu; struct proc *p; static int failure; @@ -516,7 +510,6 @@ double getpmem(k) KINFO *k; { - extern int mempages, nlistread; static int failure; struct proc *p; struct eproc *e; @@ -617,6 +610,48 @@ trss(k, ve) * Generic output routines. Print fields from various prototype * structures. */ +static void +printval(bp, v) + char *bp; + VAR *v; +{ + static char ofmt[32] = "%"; + char *fcp, *cp; + + cp = ofmt + 1; + fcp = v->fmt; + if (v->flag & LJUST) + *cp++ = '-'; + *cp++ = '*'; + while (*cp++ = *fcp++); + + switch (v->type) { + case CHAR: + (void)printf(ofmt, v->width, *(char *)bp); + break; + case UCHAR: + (void)printf(ofmt, v->width, *(u_char *)bp); + break; + case SHORT: + (void)printf(ofmt, v->width, *(short *)bp); + break; + case USHORT: + (void)printf(ofmt, v->width, *(u_short *)bp); + break; + case LONG: + (void)printf(ofmt, v->width, *(long *)bp); + break; + case ULONG: + (void)printf(ofmt, v->width, *(u_long *)bp); + break; + case KPTR: + (void)printf(ofmt, v->width, *(u_long *)bp &~ KERNBASE); + break; + default: + errx(1, "unknown type %d", v->type); + } +} + void pvar(k, ve) KINFO *k; @@ -666,45 +701,3 @@ rvar(k, ve) else (void)printf("%*s", v->width, "-"); } - -static void -printval(bp, v) - char *bp; - VAR *v; -{ - static char ofmt[32] = "%"; - register char *fcp, *cp; - - cp = ofmt + 1; - fcp = v->fmt; - if (v->flag & LJUST) - *cp++ = '-'; - *cp++ = '*'; - while (*cp++ = *fcp++); - - switch (v->type) { - case CHAR: - (void)printf(ofmt, v->width, *(char *)bp); - break; - case UCHAR: - (void)printf(ofmt, v->width, *(u_char *)bp); - break; - case SHORT: - (void)printf(ofmt, v->width, *(short *)bp); - break; - case USHORT: - (void)printf(ofmt, v->width, *(u_short *)bp); - break; - case LONG: - (void)printf(ofmt, v->width, *(long *)bp); - break; - case ULONG: - (void)printf(ofmt, v->width, *(u_long *)bp); - break; - case KPTR: - (void)printf(ofmt, v->width, *(u_long *)bp &~ KERNBASE); - break; - default: - errx(1, "unknown type %d", v->type); - } -} diff --git a/usr/src/bin/ps/ps.c b/usr/src/bin/ps/ps.c index 700a84e873..d12d26124c 100644 --- a/usr/src/bin/ps/ps.c +++ b/usr/src/bin/ps/ps.c @@ -12,7 +12,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)ps.c 8.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)ps.c 8.3 (Berkeley) %G%"; #endif /* not lint */ #include @@ -78,13 +78,14 @@ main(argc, argv) int argc; char *argv[]; { - register struct kinfo_proc *kp; - register struct varent *vent; - int nentries; - register int i; + struct kinfo_proc *kp; + struct varent *vent; struct winsize ws; dev_t ttydev; - int all, ch, flag, fmt, lineno, pid, prtheader, uid, wflag, what, xflg; + pid_t pid; + uid_t uid; + int all, ch, flag, i, fmt, lineno, nentries; + int prtheader, wflag, what, xflg; char *nlistf, *memf, *swapf, errbuf[256]; if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 && @@ -99,7 +100,8 @@ main(argc, argv) argv[1] = kludge_oldps_options(argv[1]); all = fmt = prtheader = wflag = xflg = 0; - pid = uid = -1; + pid = -1; + uid = (uid_t) -1; ttydev = NODEV; memf = nlistf = swapf = NULL; while ((ch = getopt(argc, argv, @@ -153,7 +155,7 @@ main(argc, argv) fmt = 1; break; case 'p': - pid = atoi(optarg); + pid = atol(optarg); xflg = 1; break; case 'r': @@ -252,7 +254,7 @@ main(argc, argv) /* * get proc list */ - if (uid != -1) { + if (uid != (uid_t) -1) { what = KERN_PROC_UID; flag = uid; } else if (ttydev != NODEV) { @@ -308,9 +310,9 @@ main(argc, argv) static void scanvars() { - register struct varent *vent; - register VAR *v; - register int i; + struct varent *vent; + VAR *v; + int i; for (vent = vhead; vent; vent = vent->next) { v = vent->var; @@ -333,7 +335,7 @@ fmt(fn, ki, comm, maxlen) char *comm; int maxlen; { - register char *s; + char *s; if ((s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen)) == NULL) @@ -345,12 +347,12 @@ static void saveuser(ki) KINFO *ki; { - register struct usave *usp = &ki->ki_u; struct pstats pstats; - extern char *fmt_argv(); + struct usave *usp; + usp = &ki->ki_u; if (kvm_read(kd, (u_long)&KI_PROC(ki)->p_addr->u_stats, - (char *)&pstats, sizeof(pstats)) == sizeof(pstats)) { + (char *)&pstats, sizeof(pstats)) == sizeof(pstats)) { /* * The u-area might be swapped out, and we can't get * at it because we have a crashdump and no swap. @@ -462,7 +464,11 @@ kludge_oldps_options(s) static void usage() { + (void)fprintf(stderr, -"usage: ps [-aChjlmrSTuvwx] [-O|o fmt] [-p pid] [-t tty]\n\t [-M core] [-N system] [-W swap]\n ps [-L]\n"); + "usage:\t%s\n\t %s\n\t%s\n", + "ps [-aChjlmrSTuvwx] [-O|o fmt] [-p pid] [-t tty]", + "[-M core] [-N system] [-W swap]", + "ps [-L]"); exit(1); }