Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/systat - implement layered help.



details:   https://anonhg.NetBSD.org/src/rev/742560cb915a
branches:  trunk
changeset: 480288:742560cb915a
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sat Jan 08 23:12:36 2000 +0000

description:
- implement layered help.
  Suggested by: Andy Doran <ad%mr-magoo.sports.gov.uk@localhost>
- inet6.ip6 and ipsec menu
- u_quad_t printing fix
- #ifdefs to allow compilation on 1.4.x

diffstat:

 usr.bin/systat/Makefile     |    5 +-
 usr.bin/systat/cmdtab.c     |   14 ++-
 usr.bin/systat/extern.h     |   18 +++-
 usr.bin/systat/globalcmds.c |   52 ++++++++++-
 usr.bin/systat/icmp.c       |    7 +-
 usr.bin/systat/ip.c         |    7 +-
 usr.bin/systat/ip6.c        |  215 ++++++++++++++++++++++++++++++++++++++++++++
 usr.bin/systat/ipsec.c      |  205 +++++++++++++++++++++++++++++++++++++++++
 usr.bin/systat/pigs.c       |    8 +-
 usr.bin/systat/ps.c         |   10 +-
 usr.bin/systat/systat.1     |   20 +++-
 11 files changed, 540 insertions(+), 21 deletions(-)

diffs (truncated from 770 to 300 lines):

diff -r 99199a553f09 -r 742560cb915a usr.bin/systat/Makefile
--- a/usr.bin/systat/Makefile   Sat Jan 08 23:02:16 2000 +0000
+++ b/usr.bin/systat/Makefile   Sat Jan 08 23:12:36 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.21 2000/01/05 11:59:12 itojun Exp $
+#      $NetBSD: Makefile,v 1.22 2000/01/08 23:12:36 itojun Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 
 PROG=  systat
@@ -17,6 +17,7 @@
 LINKS= ${BINDIR}/systat ${BINDIR}/sysstat
 MLINKS+=systat.1 sysstat.1
 
-CPPFLAGS+=-DINET6
+CPPFLAGS+=-DINET6 -DIPSEC
+SRCS+= ip6.c ipsec.c
 
 .include <bsd.prog.mk>
diff -r 99199a553f09 -r 742560cb915a usr.bin/systat/cmdtab.c
--- a/usr.bin/systat/cmdtab.c   Sat Jan 08 23:02:16 2000 +0000
+++ b/usr.bin/systat/cmdtab.c   Sat Jan 08 23:12:36 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmdtab.c,v 1.12 1999/12/22 14:46:14 kleink Exp $       */
+/*     $NetBSD: cmdtab.c,v 1.13 2000/01/08 23:12:37 itojun Exp $       */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)cmdtab.c   8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: cmdtab.c,v 1.12 1999/12/22 14:46:14 kleink Exp $");
+__RCSID("$NetBSD: cmdtab.c,v 1.13 2000/01/08 23:12:37 itojun Exp $");
 #endif /* not lint */
 
 #include "systat.h"
@@ -121,6 +121,16 @@
        { "inet.tcpsyn",showtcpsyn,     fetchtcp,       labeltcpsyn,
          inittcp,      opentcp,        closetcp,       0,
          CF_LOADAV },
+#ifdef INET6
+       { "inet6.ip6",  showip6,        fetchip6,       labelip6,
+         initip6,      openip6,        closeip6,       0,
+         CF_LOADAV },
+#endif
+#ifdef IPSEC
+       { "ipsec",      showipsec,      fetchipsec,     labelipsec,
+         initipsec,    openipsec,      closeipsec,     0,
+         CF_LOADAV },
+#endif
        { "iostat",     showiostat,     fetchiostat,    labeliostat,
          initiostat,   openiostat,     closeiostat,    iostat_commands,
          CF_LOADAV },
diff -r 99199a553f09 -r 742560cb915a usr.bin/systat/extern.h
--- a/usr.bin/systat/extern.h   Sat Jan 08 23:02:16 2000 +0000
+++ b/usr.bin/systat/extern.h   Sat Jan 08 23:12:36 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.20 2000/01/07 04:47:23 itojun Exp $       */
+/*     $NetBSD: extern.h,v 1.21 2000/01/08 23:12:37 itojun Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -172,3 +172,19 @@
 void    vmstat_run __P((char *args));
 void    vmstat_time __P((char *args));
 void    vmstat_zero __P((char *args));
+#ifdef INET6
+void    closeip6 __P ((WINDOW *));
+void    fetchip6 __P((void));
+int     initip6 __P((void));
+void    labelip6 __P((void));
+WINDOW *openip6 __P((void));
+void    showip6 __P((void));
+#endif
+#ifdef IPSEC
+void    closeipsec __P ((WINDOW *));
+void    fetchipsec __P((void));
+int     initipsec __P((void));
+void    labelipsec __P((void));
+WINDOW *openipsec __P((void));
+void    showipsec __P((void));
+#endif
diff -r 99199a553f09 -r 742560cb915a usr.bin/systat/globalcmds.c
--- a/usr.bin/systat/globalcmds.c       Sat Jan 08 23:02:16 2000 +0000
+++ b/usr.bin/systat/globalcmds.c       Sat Jan 08 23:12:36 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: globalcmds.c,v 1.5 1999/12/20 21:49:11 lukem Exp $ */
+/*     $NetBSD: globalcmds.c,v 1.6 2000/01/08 23:12:37 itojun Exp $ */
 
 /*-
  * Copyright (c) 1999
@@ -40,23 +40,69 @@
 #include "extern.h"
 
 
+static char *shortname __P((const char *, const char *));
+
+static char *
+shortname(key, s)
+       const char *key;
+       const char *s;
+{
+       char *p, *q;
+       size_t l;
+
+       if (key == NULL) {
+               if ((p = strdup(s)) == NULL)
+                       return NULL;
+               q = strchr(p, '.');
+               if (q && strlen(q) > 1) {
+                       q[1] = '*';
+                       q[2] = '\0';
+               }
+               return p;
+       } else if (strncmp(key, s, l = strlen(key)) == 0 && s[l] == '.') {
+               p = strdup(s + l + 1);
+               return p;
+       } else
+               return NULL;
+}
+
 void
 global_help(args)
        char *args;
 {
        int col, len;
        struct mode *p;
+       char *cur, *prev;
 
        move(CMDLINE, col = 0);
+       cur = prev = NULL;
        for (p = modes; p->c_name; p++) {
-               len = strlen(p->c_name);
+               if ((cur = shortname(args, p->c_name)) == NULL)
+                       continue;
+               if (cur && prev && strcmp(cur, prev) == 0) {
+                       free(cur);
+                       continue;
+               }
+               len = strlen(cur);
                if (col + len > COLS)
                        break;
-               addstr(p->c_name); col += len;
+               addstr(cur); col += len;
                if (col + 1 < COLS)
                        addch(' ');
+               if (prev)
+                       free(prev);
+               prev = cur;
+       }
+       if (col == 0 && args) {
+               standout();
+               addstr("help: no matches");
+               standend();
        }
        clrtoeol();
+       if (cur)
+               free(cur);
+       if (prev)
+               free(prev);
 }
 
 void
diff -r 99199a553f09 -r 742560cb915a usr.bin/systat/icmp.c
--- a/usr.bin/systat/icmp.c     Sat Jan 08 23:02:16 2000 +0000
+++ b/usr.bin/systat/icmp.c     Sat Jan 08 23:12:36 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: icmp.c,v 1.1 1999/05/30 20:26:21 ad Exp $ */
+/*     $NetBSD: icmp.c,v 1.2 2000/01/08 23:12:37 itojun Exp $ */
 
 /*
  * Copyright (c) 1999 Andy Doran <ad%NetBSD.org@localhost>
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: icmp.c,v 1.1 1999/05/30 20:26:21 ad Exp $");
+__RCSID("$NetBSD: icmp.c,v 1.2 2000/01/08 23:12:37 itojun Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -54,7 +54,8 @@
 #define LHD(row, str) mvwprintw(wnd, row, 10, str)
 #define RHD(row, str) mvwprintw(wnd, row, 45, str);
 #define BD(row, str) LHD(row, str); RHD(row, str)
-#define SHOW(stat, row, col) mvwprintw(wnd, row, col, "%9lu", stats.stat)
+#define SHOW(stat, row, col) \
+    mvwprintw(wnd, row, col, "%9llu", (unsigned long long)stats.stat)
 #define SHOW2(type, row) SHOW(icps_inhist[type], row, 0); \
     SHOW(icps_outhist[type], row, 35)
 
diff -r 99199a553f09 -r 742560cb915a usr.bin/systat/ip.c
--- a/usr.bin/systat/ip.c       Sat Jan 08 23:02:16 2000 +0000
+++ b/usr.bin/systat/ip.c       Sat Jan 08 23:12:36 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip.c,v 1.3 2000/01/04 15:17:00 msaitoh Exp $ */
+/*     $NetBSD: ip.c,v 1.4 2000/01/08 23:12:37 itojun Exp $ */
 
 /*
  * Copyright (c) 1999 Andy Doran <ad%NetBSD.org@localhost>
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ip.c,v 1.3 2000/01/04 15:17:00 msaitoh Exp $");
+__RCSID("$NetBSD: ip.c,v 1.4 2000/01/08 23:12:37 itojun Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -54,7 +54,8 @@
 
 #define LHD(row, str)          mvwprintw(wnd, row, 10, str)
 #define RHD(row, str)          mvwprintw(wnd, row, 45, str);
-#define SHOW(stat, row, col)   mvwprintw(wnd, row, col, "%9llu", curstat.stat)
+#define SHOW(stat, row, col) \
+    mvwprintw(wnd, row, col, "%9llu", (unsigned long long)curstat.stat)
 
 struct mystat {
        struct ipstat i;
diff -r 99199a553f09 -r 742560cb915a usr.bin/systat/ip6.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/systat/ip6.c      Sat Jan 08 23:12:36 2000 +0000
@@ -0,0 +1,215 @@
+/*     $NetBSD: ip6.c,v 1.1 2000/01/08 23:12:37 itojun Exp $ */
+
+/*
+ * Copyright (c) 1999 Andy Doran <ad%NetBSD.org@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: ip6.c,v 1.1 2000/01/08 23:12:37 itojun Exp $");
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip6.h>
+#include <netinet6/ip6_var.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <paths.h>
+#include <nlist.h>
+#include <kvm.h>
+#include "systat.h"
+#include "extern.h"
+
+#define LHD(row, str)          mvwprintw(wnd, row, 10, str)
+#define RHD(row, str)          mvwprintw(wnd, row, 45, str);
+#define SHOW(stat, row, col) \
+    mvwprintw(wnd, row, col, "%9llu", (unsigned long long)curstat.stat)
+
+struct mystat {
+       struct ip6stat i;
+};
+
+static struct mystat curstat;
+
+static struct nlist namelist[] = {
+       { "_ip6stat" },
+       { "" }
+};
+
+WINDOW *
+openip6(void)
+{
+
+       return (subwin(stdscr, LINES-5-1, 0, 5, 0));
+}
+
+void
+closeip6(w)



Home | Main Index | Thread Index | Old Index