Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/ministat/ministat.c
Show First 20 Lines • Show All 527 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
usage(char const *whine) | usage(char const *whine) | ||||
{ | { | ||||
int i; | int i; | ||||
fprintf(stderr, "%s\n", whine); | fprintf(stderr, "%s\n", whine); | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"Usage: ministat [-C column] [-c confidence] [-d delimiter(s)] [-Ans] [-w width] [file [file ...]]\n"); | "Usage: ministat [-C column] [-c confidence] [-d delimiter(s)] [-Anqs] [-w width] [file [file ...]]\n"); | ||||
fprintf(stderr, "\tconfidence = {"); | fprintf(stderr, "\tconfidence = {"); | ||||
for (i = 0; i < NCONF; i++) { | for (i = 0; i < NCONF; i++) { | ||||
fprintf(stderr, "%s%g%%", | fprintf(stderr, "%s%g%%", | ||||
i ? ", " : "", | i ? ", " : "", | ||||
studentpct[i]); | studentpct[i]); | ||||
} | } | ||||
fprintf(stderr, "}\n"); | fprintf(stderr, "}\n"); | ||||
fprintf(stderr, "\t-A : print statistics only. suppress the graph.\n"); | fprintf(stderr, "\t-A : print statistics only. suppress the graph.\n"); | ||||
fprintf(stderr, "\t-C : column number to extract (starts and defaults to 1)\n"); | fprintf(stderr, "\t-C : column number to extract (starts and defaults to 1)\n"); | ||||
fprintf(stderr, "\t-d : delimiter(s) string, default to \" \\t\"\n"); | fprintf(stderr, "\t-d : delimiter(s) string, default to \" \\t\"\n"); | ||||
fprintf(stderr, "\t-n : print summary statistics only, no graph/test\n"); | fprintf(stderr, "\t-n : print summary statistics only, no graph/test\n"); | ||||
fprintf(stderr, "\t-q : suppress printing summary-statistics headers and data-set names\n"); | |||||
fprintf(stderr, "\t-s : print avg/median/stddev bars on separate lines\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"); | fprintf(stderr, "\t-w : width of graph/test output (default 74 or terminal width)\n"); | ||||
exit (2); | exit (2); | ||||
} | } | ||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
const char *setfilenames[MAX_DS - 1]; | const char *setfilenames[MAX_DS - 1]; | ||||
struct dataset *ds[MAX_DS - 1]; | struct dataset *ds[MAX_DS - 1]; | ||||
FILE *setfiles[MAX_DS - 1]; | FILE *setfiles[MAX_DS - 1]; | ||||
int nds; | int nds; | ||||
double a; | double a; | ||||
const char *delim = " \t"; | const char *delim = " \t"; | ||||
char *p; | char *p; | ||||
int c, i, ci; | int c, i, ci; | ||||
int column = 1; | int column = 1; | ||||
int flag_s = 0; | int flag_s = 0; | ||||
int flag_n = 0; | int flag_n = 0; | ||||
int flag_q = 0; | |||||
int termwidth = 74; | int termwidth = 74; | ||||
int suppress_plot = 0; | int suppress_plot = 0; | ||||
if (isatty(STDOUT_FILENO)) { | if (isatty(STDOUT_FILENO)) { | ||||
struct winsize wsz; | struct winsize wsz; | ||||
if ((p = getenv("COLUMNS")) != NULL && *p != '\0') | if ((p = getenv("COLUMNS")) != NULL && *p != '\0') | ||||
termwidth = atoi(p); | termwidth = atoi(p); | ||||
else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &wsz) != -1 && | else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &wsz) != -1 && | ||||
wsz.ws_col > 0) | wsz.ws_col > 0) | ||||
termwidth = wsz.ws_col - 2; | termwidth = wsz.ws_col - 2; | ||||
} | } | ||||
ci = -1; | ci = -1; | ||||
while ((c = getopt(argc, argv, "AC:c:d:snw:")) != -1) | while ((c = getopt(argc, argv, "AC:c:d:snqw:")) != -1) | ||||
switch (c) { | switch (c) { | ||||
case 'A': | case 'A': | ||||
suppress_plot = 1; | suppress_plot = 1; | ||||
break; | break; | ||||
case 'C': | case 'C': | ||||
column = strtol(optarg, &p, 10); | column = strtol(optarg, &p, 10); | ||||
if (p != NULL && *p != '\0') | if (p != NULL && *p != '\0') | ||||
usage("Invalid column number."); | usage("Invalid column number."); | ||||
Show All 13 Lines | while ((c = getopt(argc, argv, "AC:c:d:snqw:")) != -1) | ||||
case 'd': | case 'd': | ||||
if (*optarg == '\0') | if (*optarg == '\0') | ||||
usage("Can't use empty delimiter string"); | usage("Can't use empty delimiter string"); | ||||
delim = optarg; | delim = optarg; | ||||
break; | break; | ||||
case 'n': | case 'n': | ||||
flag_n = 1; | flag_n = 1; | ||||
break; | break; | ||||
case 'q': | |||||
flag_q = 1; | |||||
break; | |||||
case 's': | case 's': | ||||
flag_s = 1; | flag_s = 1; | ||||
break; | break; | ||||
case 'w': | case 'w': | ||||
termwidth = strtol(optarg, &p, 10); | termwidth = strtol(optarg, &p, 10); | ||||
if (p != NULL && *p != '\0') | if (p != NULL && *p != '\0') | ||||
usage("Invalid width, not a number."); | usage("Invalid width, not a number."); | ||||
if (termwidth < 0) | if (termwidth < 0) | ||||
Show All 40 Lines | if (caph_enter() < 0) | ||||
err(2, "unable to enter capability mode"); | err(2, "unable to enter capability mode"); | ||||
for (i = 0; i < nds; i++) { | for (i = 0; i < nds; i++) { | ||||
ds[i] = ReadSet(setfiles[i], setfilenames[i], column, delim); | ds[i] = ReadSet(setfiles[i], setfilenames[i], column, delim); | ||||
if (setfiles[i] != stdin) | if (setfiles[i] != stdin) | ||||
fclose(setfiles[i]); | fclose(setfiles[i]); | ||||
} | } | ||||
if (!flag_q) { | |||||
for (i = 0; i < nds; i++) | for (i = 0; i < nds; i++) | ||||
printf("%c %s\n", symbol[i+1], ds[i]->name); | printf("%c %s\n", symbol[i+1], ds[i]->name); | ||||
} | |||||
if (!flag_n && !suppress_plot) { | if (!flag_n && !suppress_plot) { | ||||
SetupPlot(termwidth, flag_s, nds); | SetupPlot(termwidth, flag_s, nds); | ||||
for (i = 0; i < nds; i++) | for (i = 0; i < nds; i++) | ||||
DimPlot(ds[i]); | DimPlot(ds[i]); | ||||
for (i = 0; i < nds; i++) | for (i = 0; i < nds; i++) | ||||
PlotSet(ds[i], i + 1); | PlotSet(ds[i], i + 1); | ||||
DumpPlot(); | DumpPlot(); | ||||
} | } | ||||
if (!flag_q) | |||||
VitalsHead(); | VitalsHead(); | ||||
Vitals(ds[0], 1); | Vitals(ds[0], 1); | ||||
for (i = 1; i < nds; i++) { | for (i = 1; i < nds; i++) { | ||||
Vitals(ds[i], i + 1); | Vitals(ds[i], i + 1); | ||||
if (!flag_n) | if (!flag_n) | ||||
Relative(ds[i], ds[0], ci); | Relative(ds[i], ds[0], ci); | ||||
} | } | ||||
exit(0); | exit(0); | ||||
} | } |