Added input parsing for now
This commit is contained in:
+39
-3
@@ -1,14 +1,50 @@
|
||||
#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;
|
||||
|
||||
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 }
|
||||
};
|
||||
|
||||
while (( option = getopt_long(argc, argv, ""
|
||||
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;
|
||||
}
|
||||
|
||||
return {max_range, num_entries, seed};
|
||||
switch (option)
|
||||
{
|
||||
case 'm':
|
||||
max_range = atoi(optarg);
|
||||
break;
|
||||
|
||||
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<int>(seed): std::nullopt};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user