From 73acb3a0f4ea7204f149c964adcd8938e09cb9f4 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 3 Oct 2015 12:15:39 -0500 Subject: Back to chipping away at ps... --- toys/pending/ps.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'toys/pending') diff --git a/toys/pending/ps.c b/toys/pending/ps.c index 29111d57..def59b6e 100644 --- a/toys/pending/ps.c +++ b/toys/pending/ps.c @@ -11,6 +11,10 @@ * the same field should be called "TT" which is _INSANE_ and I'm not doing it. * It also says that -o "args" and "comm" should behave differently but use * the same title, which is not the same title as the default output. No. + * + * ps aux + * TODO: -o maj_flt, min_flt + * TODO: --sort USE_PS(NEWTOY(ps, "aAdeflo*[!ol][+Ae]", TOYFLAG_USR|TOYFLAG_BIN)) @@ -97,7 +101,7 @@ static int do_ps(struct dirtree *new) char *name, *s, state; int nlen, i, fd, len, width = TT.width; - if (!new->parent) return DIRTREE_RECURSE; + if (!new->parent) return DIRTREE_RECURSE|DIRTREE_SHUTUP; if (!(*slot = atol(new->name))) return 0; // name field limited to 256 bytes by VFS, plus 40 fields * max 20 chars: @@ -267,9 +271,9 @@ void ps_main(void) // Set title, length of title, type, end of type, and display width while ((type = comma_iterate(&arg, &length))) { - if ((end = strchr(type, '=')) && length<(end-type)) { + if ((end = strchr(type, '=')) && length>(end-type)) { title = end+1; - length = (end-type)-1; + length -= (end-type)+1; } else { end = type+length; title = 0; @@ -282,11 +286,8 @@ void ps_main(void) // Allocate structure, copy title field = xmalloc(sizeof(struct strawberry)+length+1); - if (title) { - memcpy(field->title, title, length); - field->title[length] = 0; - } - field->len = length; + memcpy(field->title, title ? title : type, length); + field->title[field->len = length] = 0; if (width) { field->len = strtol(++width, &title, 10); @@ -296,7 +297,7 @@ void ps_main(void) } // Find type (reuse width as temp because we're done with it) - for (i = 0; iwhich; i++) { + for (i = 0; i