Files
2026-09-13 21:29:48 +03:00

52 lines
1.1 KiB
C++

#include "input_parsing.h"
#include "constants.h"
#include <getopt.h>
#include <stdlib.h>
#include <iostream>
ProgramOptions get_params(int argc, char *argv[])
{
int max_range = MAX_VALUES, num_entries = DEFAULT_NR_ENTRIES;
bool is_seed_specified = false;
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 }
};
int option, option_index, seed = 0;
while (( option = getopt_long(argc, argv, "m:n:s:", long_options, &option_index)))
{
if (option == -1)
{
break;
}
switch (option)
{
case 'm':
max_range = atoi(optarg);
break;
case 'n':
num_entries = atoi(optarg);
break;
case 's':
is_seed_specified = true;
seed = atoi(optarg);
break;
default:
std::cerr << "Incorrect character code returned: %d\n" << option;
}
}
using return_type = std::optional<int>;
return {max_range, num_entries, is_seed_specified ? return_type(seed): std::nullopt};
}