summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2003-01-19 00:31:16 +0000
committerjmallett <jmallett@FreeBSD.org>2003-01-19 00:31:16 +0000
commit73809496b45d21085a6db24febd200f02c70f935 (patch)
tree1cc7b9065ac7aabd4420de7b517bd239be8106b6
parentd52835b4ab057c3bfdf416502c82c4c0f7a22546 (diff)
downloadFreeBSD-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.
-rw-r--r--bin/ps/keyword.c19
-rw-r--r--bin/ps/print.c8
-rw-r--r--bin/ps/ps.c2
-rw-r--r--bin/ps/ps.h1
4 files changed, 19 insertions, 11 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);
}
diff --git a/bin/ps/print.c b/bin/ps/print.c
index 8760484..6b3489b 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -76,7 +76,7 @@ printheader(void)
allempty = 1;
for (vent = vhead; vent; vent = vent->next)
- if (*vent->var->header != '\0') {
+ if (*vent->header != '\0') {
allempty = 0;
break;
}
@@ -86,11 +86,11 @@ printheader(void)
v = vent->var;
if (v->flag & LJUST) {
if (vent->next == NULL) /* last one */
- (void)printf("%s", v->header);
+ (void)printf("%s", vent->header);
else
- (void)printf("%-*s", v->width, v->header);
+ (void)printf("%-*s", v->width, vent->header);
} else
- (void)printf("%*s", v->width, v->header);
+ (void)printf("%*s", v->width, vent->header);
if (vent->next != NULL)
(void)putchar(' ');
}
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 24e47eb..c62d1dc 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -515,7 +515,7 @@ sizevars(void)
for (vent = vhead; vent; vent = vent->next) {
v = vent->var;
- i = strlen(v->header);
+ i = strlen(vent->header);
if (v->width < i)
v->width = i;
totwidth += v->width + 1; /* +1 for space */
diff --git a/bin/ps/ps.h b/bin/ps/ps.h
index 917c025..2fd10de 100644
--- a/bin/ps/ps.h
+++ b/bin/ps/ps.h
@@ -46,6 +46,7 @@ typedef struct kinfo {
/* Variables. */
typedef struct varent {
+ const char *header;
struct varent *next;
struct var *var;
} VARENT;
OpenPOWER on IntegriCloud