aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJuli Mallett <jmallett@FreeBSD.org>2003-01-19 00:31:16 +0000
committerJuli Mallett <jmallett@FreeBSD.org>2003-01-19 00:31:16 +0000
commit78b1878a16bbcf6382a99566c2efe3bb0bd014b1 (patch)
tree1cc7b9065ac7aabd4420de7b517bd239be8106b6 /bin
parenta712d94e681ddbb4f7e777aa3af432a79cc50fdb (diff)
Notes
Diffstat (limited to 'bin')
-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 045a7b0df6fc..bb79d638395f 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 876048414a82..6b3489b78590 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 24e47eb052d9..c62d1dc5fab7 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 917c025896fb..2fd10de7c0bb 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;