Deleted Added
full compact
ministat.c (148224) ministat.c (155894)
1/*
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 *
9 */
10
11#include <sys/cdefs.h>
1/*
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 *
9 */
10
11#include <sys/cdefs.h>
12__FBSDID("$FreeBSD: head/usr.bin/ministat/ministat.c 148224 2005-07-21 08:32:56Z phk $");
12__FBSDID("$FreeBSD: head/usr.bin/ministat/ministat.c 155894 2006-02-22 04:10:20Z mdodd $");
13
14#include <stdio.h>
15#include <math.h>
16#include <err.h>
17#include <string.h>
18#include <stdlib.h>
19#include <unistd.h>
13
14#include <stdio.h>
15#include <math.h>
16#include <err.h>
17#include <string.h>
18#include <stdlib.h>
19#include <unistd.h>
20#include <sys/ioctl.h>
20#include <sys/queue.h>
21#include <sys/queue.h>
22#include <sys/ttycom.h>
21
22#define NSTUDENT 100
23#define NCONF 6
24double const studentpct[] = { 80, 90, 95, 98, 99, 99.5 };
25double student [NSTUDENT + 1][NCONF] = {
26/* inf */ { 1.282, 1.645, 1.960, 2.326, 2.576, 3.090 },
27/* 1. */ { 3.078, 6.314, 12.706, 31.821, 63.657, 318.313 },
28/* 2. */ { 1.886, 2.920, 4.303, 6.965, 9.925, 22.327 },

--- 469 unchanged lines hidden (view full) ---

498
499static void
500usage(char const *whine)
501{
502 int i;
503
504 fprintf(stderr, "%s\n", whine);
505 fprintf(stderr,
23
24#define NSTUDENT 100
25#define NCONF 6
26double const studentpct[] = { 80, 90, 95, 98, 99, 99.5 };
27double student [NSTUDENT + 1][NCONF] = {
28/* inf */ { 1.282, 1.645, 1.960, 2.326, 2.576, 3.090 },
29/* 1. */ { 3.078, 6.314, 12.706, 31.821, 63.657, 318.313 },
30/* 2. */ { 1.886, 2.920, 4.303, 6.965, 9.925, 22.327 },

--- 469 unchanged lines hidden (view full) ---

500
501static void
502usage(char const *whine)
503{
504 int i;
505
506 fprintf(stderr, "%s\n", whine);
507 fprintf(stderr,
506 "Usage: ministat [ -c confidence ] [-ns] [file [file ...]]\n");
508 "Usage: ministat [ -c confidence ] [-ns] [-w width] [file [file ...]]\n");
507 fprintf(stderr, "\tconfidence = {");
508 for (i = 0; i < NCONF; i++) {
509 fprintf(stderr, "%s%g%%",
510 i ? ", " : "",
511 studentpct[i]);
512 }
513 fprintf(stderr, "}\n");
514 fprintf(stderr, "\t-n : print summary statistics only, no graph/test\n");
515 fprintf(stderr, "\t-s : print avg/median/stddev bars on separate lines\n");
509 fprintf(stderr, "\tconfidence = {");
510 for (i = 0; i < NCONF; i++) {
511 fprintf(stderr, "%s%g%%",
512 i ? ", " : "",
513 studentpct[i]);
514 }
515 fprintf(stderr, "}\n");
516 fprintf(stderr, "\t-n : print summary statistics only, no graph/test\n");
517 fprintf(stderr, "\t-s : print avg/median/stddev bars on separate lines\n");
518 fprintf(stderr, "\t-w : width of graph/test output (default 74 or terminal width)\n");
516 exit (2);
517}
518
519int
520main(int argc, char **argv)
521{
522 struct dataset *ds[7];
523 int nds;
524 double a;
525 char *p;
526 int c, i, ci;
527 int flag_s = 0;
528 int flag_n = 0;
519 exit (2);
520}
521
522int
523main(int argc, char **argv)
524{
525 struct dataset *ds[7];
526 int nds;
527 double a;
528 char *p;
529 int c, i, ci;
530 int flag_s = 0;
531 int flag_n = 0;
532 int termwidth = 74;
529
533
534 if (isatty(STDOUT_FILENO)) {
535 struct winsize wsz;
536
537 if ((p = getenv("COLUMNS")) != NULL && *p != '\0')
538 termwidth = atoi(p);
539 else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &wsz) != -1 &&
540 wsz.ws_col > 0)
541 termwidth = wsz.ws_col - 2;
542 }
543
530 ci = -1;
544 ci = -1;
531 while ((c = getopt(argc, argv, "c:sn")) != -1)
545 while ((c = getopt(argc, argv, "c:snw:")) != -1)
532 switch (c) {
533 case 'c':
534 a = strtod(optarg, &p);
535 if (p != NULL && *p != '\0')
536 usage("Not a floating point number");
537 for (i = 0; i < NCONF; i++)
538 if (a == studentpct[i])
539 ci = i;
540 if (ci == -1)
541 usage("No support for confidence level");
542 break;
543 case 'n':
544 flag_n = 1;
545 break;
546 case 's':
547 flag_s = 1;
548 break;
546 switch (c) {
547 case 'c':
548 a = strtod(optarg, &p);
549 if (p != NULL && *p != '\0')
550 usage("Not a floating point number");
551 for (i = 0; i < NCONF; i++)
552 if (a == studentpct[i])
553 ci = i;
554 if (ci == -1)
555 usage("No support for confidence level");
556 break;
557 case 'n':
558 flag_n = 1;
559 break;
560 case 's':
561 flag_s = 1;
562 break;
563 case 'w':
564 termwidth = strtol(optarg, &p, 10);
565 if (p != NULL && *p != '\0')
566 usage("Invalid width, not a number.");
567 if (termwidth < 0)
568 usage("Unable to move beyond left margin.");
569 break;
549 default:
550 usage("Unknown option");
551 break;
552 }
553 if (ci == -1)
554 ci = 2;
555 argc -= optind;
556 argv += optind;

--- 8 unchanged lines hidden (view full) ---

565 nds = argc;
566 for (i = 0; i < nds; i++) {
567 ds[i] = ReadSet(argv[i]);
568 printf("%c %s\n", symbol[i+1], argv[i]);
569 }
570 }
571
572 if (!flag_n) {
570 default:
571 usage("Unknown option");
572 break;
573 }
574 if (ci == -1)
575 ci = 2;
576 argc -= optind;
577 argv += optind;

--- 8 unchanged lines hidden (view full) ---

586 nds = argc;
587 for (i = 0; i < nds; i++) {
588 ds[i] = ReadSet(argv[i]);
589 printf("%c %s\n", symbol[i+1], argv[i]);
590 }
591 }
592
593 if (!flag_n) {
573 SetupPlot(74, flag_s, nds);
594 SetupPlot(termwidth, flag_s, nds);
574 for (i = 0; i < nds; i++)
575 DimPlot(ds[i]);
576 for (i = 0; i < nds; i++)
577 PlotSet(ds[i], i + 1);
578 DumpPlot();
579 }
580 VitalsHead();
581 Vitals(ds[0], 1);
582 for (i = 1; i < nds; i++) {
583 Vitals(ds[i], i + 1);
584 if (!flag_n)
585 Relative(ds[i], ds[0], ci);
586 }
587 exit(0);
588}
595 for (i = 0; i < nds; i++)
596 DimPlot(ds[i]);
597 for (i = 0; i < nds; i++)
598 PlotSet(ds[i], i + 1);
599 DumpPlot();
600 }
601 VitalsHead();
602 Vitals(ds[0], 1);
603 for (i = 1; i < nds; i++) {
604 Vitals(ds[i], i + 1);
605 if (!flag_n)
606 Relative(ds[i], ds[0], ci);
607 }
608 exit(0);
609}