675 {
676 int iArg, patternSpecified = 0;
677
678 for (iArg = 1; iArg < argc; iArg++) {
679 const char *arg = argv[iArg];
680 const char *value;
681
682 if (option_name_matches(arg, "help", NULL) || option_name_matches(arg, "h", NULL)) {
683 fputs(USAGE, stdout);
684 exit(EXIT_SUCCESS);
685 } else if ((value = option_value(&iArg, argc, argv, arg, "pattern"))) {
686 if (!patternSpecified) {
687 string_list_clear(&opts->pattern);
688 patternSpecified = 1;
689 }
690 string_list_append(&opts->pattern, value);
691 } else if ((value = option_value(&iArg, argc, argv, arg, "inputDir"))) {
692 if (!strlen(value)) {
693 fprintf(stderr, "error: -inputDir value may not be blank\n");
694 exit(EXIT_FAILURE);
695 }
696 free(opts->inputDir);
697 opts->inputDir = xstrdup(value);
698 } else if ((value = option_value(&iArg, argc, argv, arg, "groupBy"))) {
699 if (!strlen(value)) {
700 fprintf(stderr, "error: -groupBy value may not be blank\n");
701 exit(EXIT_FAILURE);
702 }
703 free(opts->groupBy);
704 opts->groupBy = xstrdup(value);
705 } else if ((value = option_value(&iArg, argc, argv, arg, "groupValue"))) {
706 string_list_append(&opts->groupValue, value);
707 } else if ((value = option_value(&iArg, argc, argv, arg, "output"))) {
708 free(opts->output);
709 opts->output = xstrdup(value);
710 } else if ((value = option_value(&iArg, argc, argv, arg, "majorOrder"))) {
711 if (strcasecmp(value, "column") == 0)
712 opts->columnMajorOrder = 1;
713 else if (strcasecmp(value, "row") == 0)
714 opts->columnMajorOrder = 0;
715 else {
716 fprintf(stderr, "error: -majorOrder must be row or column\n");
717 exit(EXIT_FAILURE);
718 }
719 } else if ((value = option_value(&iArg, argc, argv, arg, "threads"))) {
720 long threads = parse_long_option("threads", value);
721 if (threads < 1) {
722 fprintf(stderr, "error: -threads must be >= 1\n");
723 exit(EXIT_FAILURE);
724 }
725 if (threads > INT_MAX) {
726 fprintf(stderr, "error: -threads value is too large\n");
727 exit(EXIT_FAILURE);
728 }
729 opts->threads = (int)threads;
730 } else if ((value = option_value(&iArg, argc, argv, arg, "copy"))) {
731 add_simple_stat_request(opts, STAT_COPY, value);
732 } else if ((value = option_value(&iArg, argc, argv, arg, "maximum"))) {
733 add_simple_stat_request(opts, STAT_MAXIMUM, value);
734 } else if ((value = option_value(&iArg, argc, argv, arg, "minimum"))) {
735 add_simple_stat_request(opts, STAT_MINIMUM, value);
736 } else if ((value = option_value(&iArg, argc, argv, arg, "mean"))) {
737 add_simple_stat_request(opts, STAT_MEAN, value);
738 } else if ((value = option_value(&iArg, argc, argv, arg, "largest"))) {
739 add_simple_stat_request(opts, STAT_LARGEST, value);
740 } else if ((value = option_value(&iArg, argc, argv, arg, "signedLargest"))) {
741 add_simple_stat_request(opts, STAT_SIGNED_LARGEST, value);
742 } else if ((value = option_value(&iArg, argc, argv, arg, "sum"))) {
743 add_sum_request(opts, value);
744 } else if ((value = option_value(&iArg, argc, argv, arg, "rms"))) {
745 add_simple_stat_request(opts, STAT_RMS, value);
746 } else if ((value = option_value(&iArg, argc, argv, arg, "standarddeviations")) ||
747 (value = option_value(&iArg, argc, argv, arg, "standarddeviation"))) {
748 add_simple_stat_request(opts, STAT_STANDARD_DEVIATION, value);
749 } else if ((value = option_value(&iArg, argc, argv, arg, "sigmas")) ||
750 (value = option_value(&iArg, argc, argv, arg, "sigma"))) {
751 add_simple_stat_request(opts, STAT_SIGMA, value);
752 } else if ((value = option_value(&iArg, argc, argv, arg, "wmean"))) {
753 add_weighted_request(opts, STAT_WMEAN, value, "wmean");
754 } else if ((value = option_value(&iArg, argc, argv, arg, "wstandarddeviations")) ||
755 (value = option_value(&iArg, argc, argv, arg, "wstandarddeviation"))) {
756 add_weighted_request(opts, STAT_WSTANDARD_DEVIATION, value, "wstandarddeviations");
757 } else if ((value = option_value(&iArg, argc, argv, arg, "wrms"))) {
758 add_weighted_request(opts, STAT_WRMS, value, "wrms");
759 } else if ((value = option_value(&iArg, argc, argv, arg, "wsigma")) ||
760 (value = option_value(&iArg, argc, argv, arg, "wsigmas"))) {
761 add_weighted_request(opts, STAT_WSIGMA, value, "wsigma");
762 } else if ((value = option_value(&iArg, argc, argv, arg, "cmaximum"))) {
763 add_function_request(opts, STAT_CMAXIMUM, value, "cmaximum");
764 } else if ((value = option_value(&iArg, argc, argv, arg, "cminimum"))) {
765 add_function_request(opts, STAT_CMINIMUM, value, "cminimum");
766 } else if ((value = option_value(&iArg, argc, argv, arg, "pmaximum"))) {
767 add_function_request(opts, STAT_PMAXIMUM, value, "pmaximum");
768 } else if ((value = option_value(&iArg, argc, argv, arg, "pminimum"))) {
769 add_function_request(opts, STAT_PMINIMUM, value, "pminimum");
770 } else if ((value = option_value(&iArg, argc, argv, arg, "slope"))) {
771 add_function_request(opts, STAT_SLOPE, value, "slope");
772 } else if ((value = option_value(&iArg, argc, argv, arg, "intercept"))) {
773 add_function_request(opts, STAT_INTERCEPT, value, "intercept");
774 } else if ((value = option_value(&iArg, argc, argv, arg, "exmmMean"))) {
775 add_simple_stat_request(opts, STAT_EXMM_MEAN, value);
776 } else if (option_name_matches(arg, "noOverwrite", NULL)) {
777 opts->overwrite = 0;
778 } else if (option_name_matches(arg, "overwrite", NULL)) {
779 opts->overwrite = 1;
780 } else if (option_name_matches(arg, "verbose", NULL)) {
781 opts->verbose = 1;
782 } else if (option_name_matches(arg, "nowarnings", NULL)) {
783 opts->noWarnings = 1;
784 } else if (option_name_matches(arg, "median", NULL) ||
785 option_name_matches(arg, "percentile", NULL) ||
786 option_name_matches(arg, "decilerange", NULL)) {
787 fprintf(stderr, "error: %s is not supported because it requires retaining page histories\n", arg);
788 exit(EXIT_FAILURE);
789 } else {
790 fprintf(stderr, "error: unknown option: %s\n", arg);
791 exit(EXIT_FAILURE);
792 }
793 }
794
795 if (opts->requests == 0) {
796 fprintf(stderr, "error: at least one statistic option is required\n");
797 exit(EXIT_FAILURE);
798 }
799 if (!is_directory(opts->inputDir)) {
800 fprintf(stderr, "error: -inputDir is not a directory: %s\n", opts->inputDir);
801 exit(EXIT_FAILURE);
802 }
803}