diff options
author | jmallett <jmallett@FreeBSD.org> | 2003-01-19 00:31:16 +0000 |
---|---|---|
committer | jmallett <jmallett@FreeBSD.org> | 2003-01-19 00:31:16 +0000 |
commit | 73809496b45d21085a6db24febd200f02c70f935 (patch) | |
tree | 1cc7b9065ac7aabd4420de7b517bd239be8106b6 /bin/ps/keyword.c | |
parent | d52835b4ab057c3bfdf416502c82c4c0f7a22546 (diff) | |
download | FreeBSD-src-73809496b45d21085a6db24febd200f02c70f935.zip FreeBSD-src-73809496b45d21085a6db24febd200f02c70f935.tar.gz |
Per-variable\ entry headers, to allow the 'ps -otime -otime=FOO' or similar
case to do the right thing and affect exactly one column. This is consistent
with GNU ps(1) in BSD mode, and POLA.
Diffstat (limited to 'bin/ps/keyword.c')
-rw-r--r-- | bin/ps/keyword.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index 045a7b0..bb79d63 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -54,7 +54,7 @@ __FBSDID("$FreeBSD$"); #include "ps.h" -static VAR *findvar(char *, int); +static VAR *findvar(char *, int, char **header); static int vcmp(const void *, const void *); /* Compute offset in common structures. */ @@ -231,7 +231,7 @@ parsefmt(const char *p, int user) #define FMTSEP " \t,\n" tempstr1 = tempstr = strdup(p); while (tempstr && *tempstr) { - char *cp; + char *cp, *hp; VAR *v; struct varent *vent; @@ -248,7 +248,7 @@ parsefmt(const char *p, int user) cp = tempstr; tempstr = NULL; } - if (cp == NULL || !(v = findvar(cp, user))) + if (cp == NULL || !(v = findvar(cp, user, &hp))) continue; if (!user) { /* @@ -262,6 +262,12 @@ parsefmt(const char *p, int user) } if ((vent = malloc(sizeof(struct varent))) == NULL) errx(1, "malloc failed"); + vent->header = v->header; + if (hp) { + hp = strdup(hp); + if (hp) + vent->header = hp; + } vent->var = malloc(sizeof(*vent->var)); if (vent->var == NULL) errx(1, "malloc failed"); @@ -283,7 +289,7 @@ parsefmt(const char *p, int user) } static VAR * -findvar(char *p, int user) +findvar(char *p, int user, char **header) { VAR *v, key; char *hp; @@ -306,8 +312,9 @@ findvar(char *p, int user) if (!v) { warnx("%s: keyword not found", p); eval = 1; - } else if (hp) - v->header = strdup(hp); + } + if (header) + *header = hp; return (v); } |