Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/top/dist/machine - Bump field width for state t...
details: https://anonhg.NetBSD.org/src/rev/7bd49d0d5316
branches: trunk
changeset: 954275:7bd49d0d5316
user: christos <christos%NetBSD.org@localhost>
date: Sat Apr 03 19:25:38 2021 +0000
description:
- Bump field width for state to accommodate > 9 CPUs
- When star formatting to adjust the width, count the trailing number of
digits starting backwards instead of using strcspn because the lwp name
might contain other digits like wm0TxRx/10.
diffstat:
external/bsd/top/dist/machine/m_netbsd.c | 39 ++++++++++++++++++-------------
1 files changed, 23 insertions(+), 16 deletions(-)
diffs (90 lines):
diff -r 04ec5ac621be -r 7bd49d0d5316 external/bsd/top/dist/machine/m_netbsd.c
--- a/external/bsd/top/dist/machine/m_netbsd.c Sat Apr 03 17:46:07 2021 +0000
+++ b/external/bsd/top/dist/machine/m_netbsd.c Sat Apr 03 19:25:38 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: m_netbsd.c,v 1.23 2019/04/27 14:10:01 christos Exp $ */
+/* $NetBSD: m_netbsd.c,v 1.24 2021/04/03 19:25:38 christos Exp $ */
/*
* top - a top users display for Unix
@@ -37,12 +37,12 @@
* Andrew Doran <ad%NetBSD.org@localhost>
*
*
- * $Id: m_netbsd.c,v 1.23 2019/04/27 14:10:01 christos Exp $
+ * $Id: m_netbsd.c,v 1.24 2021/04/03 19:25:38 christos Exp $
*/
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: m_netbsd.c,v 1.23 2019/04/27 14:10:01 christos Exp $");
+__RCSID("$NetBSD: m_netbsd.c,v 1.24 2021/04/03 19:25:38 christos Exp $");
#endif
#include <sys/param.h>
@@ -57,6 +57,7 @@
#include <errno.h>
#include <kvm.h>
#include <math.h>
+#include <ctype.h>
#include <nlist.h>
#include <stdio.h>
#include <stdlib.h>
@@ -102,18 +103,18 @@
*/
static char Proc_header[] =
- " PID X PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND";
+ " PID X PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND";
/* 0123456 -- field to fill in starts at header+6 */
#define PROC_UNAME_START 6
#define Proc_format \
- "%5d %-8.8s %3d %4d%7s %5s %-8.8s%7s %5.*f%% %5.*f%% %s"
+ "%5d %-8.8s %3d %4d%7s %5s %-9.9s%7s %5.*f%% %5.*f%% %s"
static char Thread_header[] =
- " PID LID X PRI STATE TIME WCPU CPU NAME COMMAND";
+ " PID LID X PRI STATE TIME WCPU CPU NAME COMMAND";
/* 0123456 -- field to fill in starts at header+6 */
#define THREAD_UNAME_START 12
#define Thread_format \
- "%5d %5d %-8.8s %3d %-8.8s%7s %5.2f%% %5.2f%% %-9.9s %s"
+ "%5d %5d %-8.8s %3d %-9.9s%7s %5.2f%% %5.2f%% %-9.9s %s"
/*
* Process state names for the "STATE" column of the display.
@@ -879,19 +880,25 @@
}
static char *
-countable(char *p, size_t l)
+countable(char *p, size_t width)
{
- static const char digits[] = "0123456789";
- size_t first = strcspn(p, digits); // non digits
- size_t last = strspn(p + first, digits); // trailing digits
- size_t len = first + last;
- if (p[len] || last == 0) // should be total and must have digits
+ size_t len = strlen(p);
+ if (len < width) { // shorter than width, ok
return p;
- if (len < l) // if shorter, done
+ }
+ size_t first, last = len - 1;
+ for (first = len - 1; isdigit((unsigned char)p[first]); first--) {
+ continue;
+ }
+ if (first == len - 1) { // no digits, ok
return p;
- if (l < last + 1) // if not enough for digits, done
+ }
+ first++;
+ last = len - first;
+ if (width < last + 1) { // if not enough for digits, done
return p;
- size_t start = l - last - 1; // compute starting point
+ }
+ size_t start = width - last - 1; // compute starting point
p[start] = '*'; // put a star
memmove(p + start + 1, p + first, last + 1); // move digits and NUL
return p;
Home |
Main Index |
Thread Index |
Old Index