From owner-svn-src-all@FreeBSD.ORG Fri Feb 17 08:24:58 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D3CD91065670; Fri, 17 Feb 2012 08:24:58 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BE0AE8FC0A; Fri, 17 Feb 2012 08:24:58 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q1H8OwUj057536; Fri, 17 Feb 2012 08:24:58 GMT (envelope-from adrian@svn.freebsd.org) Received: (from adrian@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q1H8OwX0057533; Fri, 17 Feb 2012 08:24:58 GMT (envelope-from adrian@svn.freebsd.org) Message-Id: <201202170824.q1H8OwX0057533@svn.freebsd.org> From: Adrian Chadd Date: Fri, 17 Feb 2012 08:24:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r231863 - head/tools/tools/ath/athstats X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Feb 2012 08:24:59 -0000 Author: adrian Date: Fri Feb 17 08:24:58 2012 New Revision: 231863 URL: http://svn.freebsd.org/changeset/base/231863 Log: Fix up this local copy of statfoo to support > 128 statistics. This allows all of the athstats statistics to work again. Specifics: * The previous code used chars < 0x80 as printable, and chars >= 0x80 as "statistics" * .. which meant any statistic above 127 would wrap around to 0; * .. so once I added the 802.11n TX/RX statistics to athstats, the tail end of the statistics list weren't accessible. This patch: * adds a define which represents the magic character, rather than a hard coded one * the statistic in question is little endian encoded after the magic character. Notes: * statfoo is useful enough to possibly warrant turning into a library API. Modified: head/tools/tools/ath/athstats/statfoo.c head/tools/tools/ath/athstats/statfoo.h Modified: head/tools/tools/ath/athstats/statfoo.c ============================================================================== --- head/tools/tools/ath/athstats/statfoo.c Fri Feb 17 07:59:37 2012 (r231862) +++ head/tools/tools/ath/athstats/statfoo.c Fri Feb 17 08:24:58 2012 (r231863) @@ -60,7 +60,9 @@ statfoo_setfmt(struct statfoo *sf, const } if (j != 0) sf->fmts[j++] = ' '; - sf->fmts[j++] = 0x80 | i; + sf->fmts[j++] = FMTS_IS_STAT; + sf->fmts[j++] = i & 0xff; + sf->fmts[j++] = (i >> 8) & 0xff; } sf->fmts[j] = '\0'; #undef N @@ -89,10 +91,14 @@ static void statfoo_print_header(struct statfoo *sf, FILE *fd) { const unsigned char *cp; + int i; + const struct fmt *f; for (cp = sf->fmts; *cp != '\0'; cp++) { - if (*cp & 0x80) { - const struct fmt *f = &sf->stats[*cp &~ 0x80]; + if (*cp == FMTS_IS_STAT) { + i = *(++cp); + i |= ((int) *(++cp)) << 8; + f = &sf->stats[i]; fprintf(fd, "%*s", f->width, f->label); } else putc(*cp, fd); @@ -105,11 +111,15 @@ statfoo_print_current(struct statfoo *sf { char buf[32]; const unsigned char *cp; + int i; + const struct fmt *f; for (cp = sf->fmts; *cp != '\0'; cp++) { - if (*cp & 0x80) { - const struct fmt *f = &sf->stats[*cp &~ 0x80]; - if (sf->get_curstat(sf, *cp &~ 0x80, buf, sizeof(buf))) + if (*cp == FMTS_IS_STAT) { + i = *(++cp); + i |= ((int) *(++cp)) << 8; + f = &sf->stats[i]; + if (sf->get_curstat(sf, i, buf, sizeof(buf))) fprintf(fd, "%*s", f->width, buf); } else putc(*cp, fd); @@ -122,11 +132,15 @@ statfoo_print_total(struct statfoo *sf, { char buf[32]; const unsigned char *cp; + const struct fmt *f; + int i; for (cp = sf->fmts; *cp != '\0'; cp++) { - if (*cp & 0x80) { - const struct fmt *f = &sf->stats[*cp &~ 0x80]; - if (sf->get_totstat(sf, *cp &~ 0x80, buf, sizeof(buf))) + if (*cp == FMTS_IS_STAT) { + i = *(++cp); + i |= ((int) *(++cp)) << 8; + f = &sf->stats[i]; + if (sf->get_totstat(sf, i, buf, sizeof(buf))) fprintf(fd, "%*s", f->width, buf); } else putc(*cp, fd); Modified: head/tools/tools/ath/athstats/statfoo.h ============================================================================== --- head/tools/tools/ath/athstats/statfoo.h Fri Feb 17 07:59:37 2012 (r231862) +++ head/tools/tools/ath/athstats/statfoo.h Fri Feb 17 08:24:58 2012 (r231863) @@ -79,6 +79,7 @@ struct statfoo { const char *name; /* statistics name, e.g. wlanstats */ const struct fmt *stats; /* statistics in class */ int nstats; /* number of stats */ +#define FMTS_IS_STAT 0x80 /* the following two bytes are the stat id */ unsigned char fmts[4096]; /* private: compiled stats to display */ STATFOO_DECL_METHODS(struct statfoo *);