| summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/parameters/parameters.c')
| -rw-r--r-- | src/parameters/parameters.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/parameters/parameters.c b/src/parameters/parameters.c new file mode 100644 index 0000000..24cbd68 --- /dev/null +++ b/src/parameters/parameters.c @@ -0,0 +1,100 @@ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> + +#include "../core/index.h" + +#include "../error/error.h" + +#include "parameters.h" + +static int parse_markov_order +( + struct JH_parameters param [const restrict static 1], + const char argv [const restrict] +) +{ + long long int input; + const int old_errno = errno; + + errno = 0; + + input = strtoll(argv, (char **) NULL, 10); + + if + ( + (errno != 0) + || (input > (long long int) JH_INDEX_MAX) + || (input < 1) + ) + { + JH_FATAL + ( + stderr, + "Invalid or value for parameter 'MARKOV_ORDER', accepted " + "range is " + "[2, %lli] (integer).", + (long long int) JH_INDEX_MAX + ); + + errno = old_errno; + + return -1; + } + + param->markov_order = (JH_index) input; + + errno = old_errno; + + return 0; +} + +enum JH_invocation_objective JH_parameters_initialize +( + struct JH_parameters param [const restrict static 1], + int const argc, + const char * argv [const static argc] +) +{ + param->session = (const char *) NULL; + param->markov_order = 2; + + switch (argc) + { + case 3: + param->session = argv[1]; + + if (parse_markov_order(param, argv[2]) < 0) + { + return JH_PRINTS_HELP; + } + else + { + return JH_RUNS; + } + + case 2: + param->session = argv[1]; + + return JH_CLEANS_UP; + + default: + return JH_PRINTS_HELP; + } +} + +const char * JH_parameters_get_session_name +( + const struct JH_parameters param [const restrict static 1] +) +{ + return param->session; +} + +JH_index JH_parameters_get_markov_order +( + const struct JH_parameters param [const restrict static 1] +) +{ + return param->markov_order; +} |


