summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authormdodd <mdodd@FreeBSD.org>2006-02-22 04:10:20 +0000
committermdodd <mdodd@FreeBSD.org>2006-02-22 04:10:20 +0000
commitc21de88b4e33909a63b502fb63c0540a215b8125 (patch)
tree821f035ef1c990f091d1e3c47e883aca94ccd83d /tools
parent0cce18db1a245e6ffab6d49e75be2d39580226a8 (diff)
downloadFreeBSD-src-c21de88b4e33909a63b502fb63c0540a215b8125.zip
FreeBSD-src-c21de88b4e33909a63b502fb63c0540a215b8125.tar.gz
Add option -w to specify graph width.
Use COLUMNS, terminal width for default graph width. Reviewed by: rwatson
Diffstat (limited to 'tools')
-rw-r--r--tools/tools/ministat/ministat.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/tools/tools/ministat/ministat.c b/tools/tools/ministat/ministat.c
index cbada01..038ef6b 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
@@ -503,7 +505,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 +515,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 +529,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 +560,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 +591,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++)
OpenPOWER on IntegriCloud