summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorWojciech A. Koszek <wkoszek@FreeBSD.org>2006-02-27 22:34:36 +0000
committerWojciech A. Koszek <wkoszek@FreeBSD.org>2006-02-27 22:34:36 +0000
commitfd8d4a60c83e50e0b2cda48a6a8fd039983adf78 (patch)
treebd31491656200ddf0805899350f28740ec6aa0b4 /tools
parentebd76269e4150d48490a19e803b2b57011ca199a (diff)
Notes
Diffstat (limited to 'tools')
-rw-r--r--tools/tools/ministat/ministat.c52
1 files changed, 42 insertions, 10 deletions
diff --git a/tools/tools/ministat/ministat.c b/tools/tools/ministat/ministat.c
index cbada0152ac0..af3f803b88d6 100644
--- a/tools/tools/ministat/ministat.c
+++ b/tools/tools/ministat/ministat.c
@@ -17,7 +17,9 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/ioctl.h>
#include <sys/queue.h>
+#include <sys/ttycom.h>
#define NSTUDENT 100
#define NCONF 6
@@ -200,15 +202,26 @@ Avg(struct dataset *ds)
static double
Median(struct dataset *ds)
{
- int i;
- struct point *pp;
+ int even, i;
+ struct point *p1, *p2;
- i = ds->n / 2;
- TAILQ_FOREACH(pp, &ds->list, list) {
- if (i--)
- continue;
- return (pp->val);
+ if ((ds->n % 2) == 1) {
+ i = (ds->n / 2) + 1;
+ even = 0;
+ } else {
+ i = ds->n / 2;
+ even = 1;
+ }
+ TAILQ_FOREACH(p1, &ds->list, list) {
+ --i;
+ if (i == 0)
+ break;
}
+ if (even) {
+ p2 = TAILQ_NEXT(p1, list);
+ return ((p2->val + p1->val) / 2);
+ }
+ return (p1->val);
}
static double
@@ -503,7 +516,7 @@ usage(char const *whine)
fprintf(stderr, "%s\n", whine);
fprintf(stderr,
- "Usage: ministat [ -c confidence ] [-ns] [file [file ...]]\n");
+ "Usage: ministat [ -c confidence ] [-ns] [-w width] [file [file ...]]\n");
fprintf(stderr, "\tconfidence = {");
for (i = 0; i < NCONF; i++) {
fprintf(stderr, "%s%g%%",
@@ -513,6 +526,7 @@ usage(char const *whine)
fprintf(stderr, "}\n");
fprintf(stderr, "\t-n : print summary statistics only, no graph/test\n");
fprintf(stderr, "\t-s : print avg/median/stddev bars on separate lines\n");
+ fprintf(stderr, "\t-w : width of graph/test output (default 74 or terminal width)\n");
exit (2);
}
@@ -526,9 +540,20 @@ main(int argc, char **argv)
int c, i, ci;
int flag_s = 0;
int flag_n = 0;
+ int termwidth = 74;
+
+ if (isatty(STDOUT_FILENO)) {
+ struct winsize wsz;
+
+ if ((p = getenv("COLUMNS")) != NULL && *p != '\0')
+ termwidth = atoi(p);
+ else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &wsz) != -1 &&
+ wsz.ws_col > 0)
+ termwidth = wsz.ws_col - 2;
+ }
ci = -1;
- while ((c = getopt(argc, argv, "c:sn")) != -1)
+ while ((c = getopt(argc, argv, "c:snw:")) != -1)
switch (c) {
case 'c':
a = strtod(optarg, &p);
@@ -546,6 +571,13 @@ main(int argc, char **argv)
case 's':
flag_s = 1;
break;
+ case 'w':
+ termwidth = strtol(optarg, &p, 10);
+ if (p != NULL && *p != '\0')
+ usage("Invalid width, not a number.");
+ if (termwidth < 0)
+ usage("Unable to move beyond left margin.");
+ break;
default:
usage("Unknown option");
break;
@@ -570,7 +602,7 @@ main(int argc, char **argv)
}
if (!flag_n) {
- SetupPlot(74, flag_s, nds);
+ SetupPlot(termwidth, flag_s, nds);
for (i = 0; i < nds; i++)
DimPlot(ds[i]);
for (i = 0; i < nds; i++)