diff --git a/input_parsing.cpp b/input_parsing.cpp index 64d1015..2c2af02 100644 --- a/input_parsing.cpp +++ b/input_parsing.cpp @@ -1,14 +1,50 @@ #include "input_parsing.h" #include "constants.h" +#include +#include +#include + ProgramOptions get_params(int argc, char *argv[]) { int max_range = MAX_VALUES, num_entries = DEFAULT_NR_ENTRIES; bool is_seed_specified = false; - int option; + static struct option long_options[] = { + {"max-range", required_argument, 0, 'm' }, + {"num-entries", required_argument, 0, 'n' }, + {"seed", required_argument, 0, 's' }, + {0, 0, 0, 0 } + }; + + bool seed_found = false; + int option, option_index, seed = 0; + while (( option = getopt_long(argc, argv, "m:n:s:", long_options, &option_index))) + { + if (option == -1) + { + break; + } - while (( option = getopt_long(argc, argv, "" + switch (option) + { + case 'm': + max_range = atoi(optarg); + break; - return {max_range, num_entries, seed}; + case 'n': + num_entries = atoi(optarg); + break; + + case 's': + seed_found = true; + seed = atoi(optarg); + break; + + default: + std::cerr << "Incorrect character code returned: %d" << option; + } + } + + return {max_range, num_entries, seed_found ? std::optional(seed): std::nullopt}; }