Date: Sun, 19 Oct 2008 06:24:32 GMT From: Sam Leffler <sam@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 151543 for review Message-ID: <200810190624.m9J6OWnV037984@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=151543 Change 151543 by sam@sam_ebb on 2008/10/19 06:24:00 Extend -o option: add predefined output formats selectable by name. For now there's just "default". In the future these might come from a dot file to simplify use. Affected files ... .. //depot/projects/vap/tools/tools/ath/athstats/main.c#4 edit Differences ... ==== //depot/projects/vap/tools/tools/ath/athstats/main.c#4 (text+ko) ==== @@ -49,8 +49,27 @@ #include "athstats.h" -#define S_DEFAULT \ - "input,output,altrate,short,long,xretry,crcerr,crypt,phyerr,rssi,rate" +static struct { + const char *tag; + const char *fmt; +} tags[] = { + { "default", + "input,output,altrate,short,long,xretry,crcerr,crypt,phyerr,rssi,rate" + }, +}; + +static const char * +getfmt(const char *tag) +{ +#define N(a) (sizeof(a)/sizeof(a[0])) + int i; + for (i = 0; i < N(tags); i++) + if (strcasecmp(tags[i].tag, tag) == 0) + return tags[i].fmt; + errx(-1, "unknown tag \%s\"", tag); + /*NOTREACHED*/ +#undef N +} static int signalled; @@ -70,7 +89,7 @@ ifname = getenv("ATH"); if (ifname == NULL) ifname = "ath0"; - wf = athstats_new(ifname, S_DEFAULT); + wf = athstats_new(ifname, getfmt("default")); while ((c = getopt(argc, argv, "i:lo:")) != -1) { switch (c) { case 'i': @@ -80,7 +99,7 @@ wf->print_fields(wf, stdout); return 0; case 'o': - wf->setfmt(wf, optarg); + wf->setfmt(wf, getfmt(optarg)); break; default: errx(-1, "usage: %s [-a] [-i ifname] [-l] [-o fmt] [interval]\n", argv[0]);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200810190624.m9J6OWnV037984>