summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authoradrian <adrian@FreeBSD.org>2012-02-17 08:24:58 +0000
committeradrian <adrian@FreeBSD.org>2012-02-17 08:24:58 +0000
commit470ebe5c9e55a09183d8658c45c49da0d4a81e92 (patch)
treec925e4ad48d2dbdc6a6dd9e4d024960059674318 /tools
parentbe402d9b8f77902a8f942dcbf8ccfcdcc1ab8b69 (diff)
downloadFreeBSD-src-470ebe5c9e55a09183d8658c45c49da0d4a81e92.zip
FreeBSD-src-470ebe5c9e55a09183d8658c45c49da0d4a81e92.tar.gz
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.
Diffstat (limited to 'tools')
-rw-r--r--tools/tools/ath/athstats/statfoo.c32
-rw-r--r--tools/tools/ath/athstats/statfoo.h1
2 files changed, 24 insertions, 9 deletions
diff --git a/tools/tools/ath/athstats/statfoo.c b/tools/tools/ath/athstats/statfoo.c
index 9963ea0..eb39e25 100644
--- a/tools/tools/ath/athstats/statfoo.c
+++ b/tools/tools/ath/athstats/statfoo.c
@@ -60,7 +60,9 @@ statfoo_setfmt(struct statfoo *sf, const char *fmt0)
}
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, FILE *fd)
{
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, FILE *fd)
{
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);
diff --git a/tools/tools/ath/athstats/statfoo.h b/tools/tools/ath/athstats/statfoo.h
index df7eb7a..849a271 100644
--- a/tools/tools/ath/athstats/statfoo.h
+++ b/tools/tools/ath/athstats/statfoo.h
@@ -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 *);
OpenPOWER on IntegriCloud