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.
This commit is contained in:
Juli Mallett
2003-01-19 00:31:16 +00:00
parent a712d94e68
commit 78b1878a16
4 changed files with 19 additions and 11 deletions
+13 -6
View File
@@ -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);
}
+4 -4
View File
@@ -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(' ');
}
+1 -1
View File
@@ -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 */
+1
View File
@@ -46,6 +46,7 @@ typedef struct kinfo {
/* Variables. */
typedef struct varent {
const char *header;
struct varent *next;
struct var *var;
} VARENT;