Change "struct varent" to use the standard queue(8) macros, instead of
using it's own version of the same basic algorithm. Submitted by: part by Cyrille Lefevre, part of it done by me
This commit is contained in:
parent
238b367c61
commit
bdf8ab4692
@ -40,7 +40,7 @@ extern int cflag, eval, fscale, nlistread, rawcpu;
|
|||||||
extern unsigned long mempages;
|
extern unsigned long mempages;
|
||||||
extern time_t now;
|
extern time_t now;
|
||||||
extern int sumrusage, termwidth, totwidth;
|
extern int sumrusage, termwidth, totwidth;
|
||||||
extern VARENT *vhead;
|
extern STAILQ_HEAD(velisthead, varent) varlist;
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
void arguments(KINFO *, VARENT *);
|
void arguments(KINFO *, VARENT *);
|
||||||
|
@ -235,7 +235,6 @@ showkey(void)
|
|||||||
void
|
void
|
||||||
parsefmt(const char *p, int user)
|
parsefmt(const char *p, int user)
|
||||||
{
|
{
|
||||||
static struct varent *vtail;
|
|
||||||
char *tempstr, *tempstr1;
|
char *tempstr, *tempstr1;
|
||||||
|
|
||||||
#define FMTSEP " \t,\n"
|
#define FMTSEP " \t,\n"
|
||||||
@ -282,16 +281,10 @@ parsefmt(const char *p, int user)
|
|||||||
if (vent->var == NULL)
|
if (vent->var == NULL)
|
||||||
errx(1, "malloc failed");
|
errx(1, "malloc failed");
|
||||||
memcpy(vent->var, v, sizeof(*vent->var));
|
memcpy(vent->var, v, sizeof(*vent->var));
|
||||||
vent->next = NULL;
|
STAILQ_INSERT_TAIL(&varlist, vent, next_ve);
|
||||||
if (vhead == NULL)
|
|
||||||
vhead = vtail = vent;
|
|
||||||
else {
|
|
||||||
vtail->next = vent;
|
|
||||||
vtail = vent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
free(tempstr1);
|
free(tempstr1);
|
||||||
if (!vhead) {
|
if (STAILQ_EMPTY(&varlist)) {
|
||||||
warnx("no valid keywords; valid keywords:");
|
warnx("no valid keywords; valid keywords:");
|
||||||
showkey();
|
showkey();
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -69,26 +69,23 @@ printheader(void)
|
|||||||
{
|
{
|
||||||
VAR *v;
|
VAR *v;
|
||||||
struct varent *vent;
|
struct varent *vent;
|
||||||
int allempty;
|
|
||||||
|
|
||||||
allempty = 1;
|
STAILQ_FOREACH(vent, &varlist, next_ve)
|
||||||
for (vent = vhead; vent; vent = vent->next)
|
if (*vent->header != '\0')
|
||||||
if (*vent->header != '\0') {
|
|
||||||
allempty = 0;
|
|
||||||
break;
|
break;
|
||||||
}
|
if (!vent)
|
||||||
if (allempty)
|
|
||||||
return;
|
return;
|
||||||
for (vent = vhead; vent; vent = vent->next) {
|
|
||||||
|
STAILQ_FOREACH(vent, &varlist, next_ve) {
|
||||||
v = vent->var;
|
v = vent->var;
|
||||||
if (v->flag & LJUST) {
|
if (v->flag & LJUST) {
|
||||||
if (vent->next == NULL) /* last one */
|
if (STAILQ_NEXT(vent, next_ve) == NULL) /* last one */
|
||||||
(void)printf("%s", vent->header);
|
(void)printf("%s", vent->header);
|
||||||
else
|
else
|
||||||
(void)printf("%-*s", v->width, vent->header);
|
(void)printf("%-*s", v->width, vent->header);
|
||||||
} else
|
} else
|
||||||
(void)printf("%*s", v->width, vent->header);
|
(void)printf("%*s", v->width, vent->header);
|
||||||
if (vent->next != NULL)
|
if (STAILQ_NEXT(vent, next_ve) != NULL)
|
||||||
(void)putchar(' ');
|
(void)putchar(' ');
|
||||||
}
|
}
|
||||||
(void)putchar('\n');
|
(void)putchar('\n');
|
||||||
@ -105,7 +102,7 @@ arguments(KINFO *k, VARENT *ve)
|
|||||||
if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
|
if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
|
||||||
errx(1, "malloc failed");
|
errx(1, "malloc failed");
|
||||||
strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
|
strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
|
||||||
if (ve->next == NULL) {
|
if (STAILQ_NEXT(ve, next_ve) == NULL) {
|
||||||
/* last field */
|
/* last field */
|
||||||
if (termwidth == UNLIMITED) {
|
if (termwidth == UNLIMITED) {
|
||||||
(void)printf("%s", vis_args);
|
(void)printf("%s", vis_args);
|
||||||
@ -131,7 +128,8 @@ command(KINFO *k, VARENT *ve)
|
|||||||
|
|
||||||
v = ve->var;
|
v = ve->var;
|
||||||
if (cflag) {
|
if (cflag) {
|
||||||
if (ve->next == NULL) /* last field, don't pad */
|
/* If it is the last field, then don't pad */
|
||||||
|
if (STAILQ_NEXT(ve, next_ve) == NULL)
|
||||||
(void)printf("%s", k->ki_p->ki_comm);
|
(void)printf("%s", k->ki_p->ki_comm);
|
||||||
else
|
else
|
||||||
(void)printf("%-*s", v->width, k->ki_p->ki_comm);
|
(void)printf("%-*s", v->width, k->ki_p->ki_comm);
|
||||||
@ -147,7 +145,7 @@ command(KINFO *k, VARENT *ve)
|
|||||||
} else
|
} else
|
||||||
vis_env = NULL;
|
vis_env = NULL;
|
||||||
|
|
||||||
if (ve->next == NULL) {
|
if (STAILQ_NEXT(ve, next_ve) == NULL) {
|
||||||
/* last field */
|
/* last field */
|
||||||
if (termwidth == UNLIMITED) {
|
if (termwidth == UNLIMITED) {
|
||||||
if (vis_env)
|
if (vis_env)
|
||||||
@ -180,7 +178,7 @@ ucomm(KINFO *k, VARENT *ve)
|
|||||||
VAR *v;
|
VAR *v;
|
||||||
|
|
||||||
v = ve->var;
|
v = ve->var;
|
||||||
if (ve->next == NULL) /* last field, don't pad */
|
if (STAILQ_NEXT(ve, next_ve) == NULL) /* last field, don't pad */
|
||||||
(void)printf("%s", k->ki_p->ki_comm);
|
(void)printf("%s", k->ki_p->ki_comm);
|
||||||
else
|
else
|
||||||
(void)printf("%-*s", v->width, k->ki_p->ki_comm);
|
(void)printf("%-*s", v->width, k->ki_p->ki_comm);
|
||||||
|
14
bin/ps/ps.c
14
bin/ps/ps.c
@ -98,7 +98,7 @@ int sumrusage; /* -S */
|
|||||||
int termwidth; /* Width of the screen (0 == infinity). */
|
int termwidth; /* Width of the screen (0 == infinity). */
|
||||||
int totwidth; /* Calculated-width of requested variables. */
|
int totwidth; /* Calculated-width of requested variables. */
|
||||||
|
|
||||||
struct varent *vhead;
|
struct velisthead varlist = STAILQ_HEAD_INITIALIZER(varlist);
|
||||||
|
|
||||||
static int forceuread = DEF_UREAD; /* Do extra work to get u-area. */
|
static int forceuread = DEF_UREAD; /* Do extra work to get u-area. */
|
||||||
static kvm_t *kd;
|
static kvm_t *kd;
|
||||||
@ -600,9 +600,9 @@ main(int argc, char *argv[])
|
|||||||
* For each process, call each variable output function.
|
* For each process, call each variable output function.
|
||||||
*/
|
*/
|
||||||
for (i = lineno = 0; i < nkept; i++) {
|
for (i = lineno = 0; i < nkept; i++) {
|
||||||
for (vent = vhead; vent; vent = vent->next) {
|
STAILQ_FOREACH(vent, &varlist, next_ve) {
|
||||||
(vent->var->oproc)(&kinfo[i], vent);
|
(vent->var->oproc)(&kinfo[i], vent);
|
||||||
if (vent->next != NULL)
|
if (STAILQ_NEXT(vent, next_ve) != NULL)
|
||||||
(void)putchar(' ');
|
(void)putchar(' ');
|
||||||
}
|
}
|
||||||
(void)putchar('\n');
|
(void)putchar('\n');
|
||||||
@ -886,7 +886,7 @@ find_varentry(VAR *v)
|
|||||||
{
|
{
|
||||||
struct varent *vent;
|
struct varent *vent;
|
||||||
|
|
||||||
for (vent = vhead; vent; vent = vent->next) {
|
STAILQ_FOREACH(vent, &varlist, next_ve) {
|
||||||
if (strcmp(vent->var->name, v->name) == 0)
|
if (strcmp(vent->var->name, v->name) == 0)
|
||||||
return vent;
|
return vent;
|
||||||
}
|
}
|
||||||
@ -899,7 +899,7 @@ scanvars(void)
|
|||||||
struct varent *vent;
|
struct varent *vent;
|
||||||
VAR *v;
|
VAR *v;
|
||||||
|
|
||||||
for (vent = vhead; vent; vent = vent->next) {
|
STAILQ_FOREACH(vent, &varlist, next_ve) {
|
||||||
v = vent->var;
|
v = vent->var;
|
||||||
if (v->flag & DSIZ) {
|
if (v->flag & DSIZ) {
|
||||||
v->dwidth = v->width;
|
v->dwidth = v->width;
|
||||||
@ -919,7 +919,7 @@ dynsizevars(KINFO *ki)
|
|||||||
VAR *v;
|
VAR *v;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (vent = vhead; vent; vent = vent->next) {
|
STAILQ_FOREACH(vent, &varlist, next_ve) {
|
||||||
v = vent->var;
|
v = vent->var;
|
||||||
if (!(v->flag & DSIZ))
|
if (!(v->flag & DSIZ))
|
||||||
continue;
|
continue;
|
||||||
@ -938,7 +938,7 @@ sizevars(void)
|
|||||||
VAR *v;
|
VAR *v;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (vent = vhead; vent; vent = vent->next) {
|
STAILQ_FOREACH(vent, &varlist, next_ve) {
|
||||||
v = vent->var;
|
v = vent->var;
|
||||||
i = strlen(vent->header);
|
i = strlen(vent->header);
|
||||||
if (v->width < i)
|
if (v->width < i)
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
* $FreeBSD$
|
* $FreeBSD$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/queue.h>
|
||||||
|
|
||||||
#define UNLIMITED 0 /* unlimited terminal width */
|
#define UNLIMITED 0 /* unlimited terminal width */
|
||||||
enum type { CHAR, UCHAR, SHORT, USHORT, INT, UINT, LONG, ULONG, KPTR, PGTOK };
|
enum type { CHAR, UCHAR, SHORT, USHORT, INT, UINT, LONG, ULONG, KPTR, PGTOK };
|
||||||
|
|
||||||
@ -44,8 +46,8 @@ typedef struct kinfo {
|
|||||||
|
|
||||||
/* Variables. */
|
/* Variables. */
|
||||||
typedef struct varent {
|
typedef struct varent {
|
||||||
|
STAILQ_ENTRY(varent) next_ve;
|
||||||
const char *header;
|
const char *header;
|
||||||
struct varent *next;
|
|
||||||
struct var *var;
|
struct var *var;
|
||||||
} VARENT;
|
} VARENT;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user