| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-01-29 19:54:26 +0100 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-01-29 19:54:26 +0100 |
| commit | 1373211465c34015ee900e097aa87fbffb401187 (patch) | |
| tree | 8ffa1f9296097c91627c05874fcf4559cac45de7 /src/parameters | |
| parent | df3657b2a99ef20da99ac3c6c02f43cc23e70fca (diff) | |
Trying out ACSL, continuing implementation.
Diffstat (limited to 'src/parameters')
| -rw-r--r-- | src/parameters/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/parameters/parameters.c | 84 | ||||
| -rw-r--r-- | src/parameters/parameters.h | 18 | ||||
| -rw-r--r-- | src/parameters/parameters_types.h | 18 |
4 files changed, 126 insertions, 0 deletions
diff --git a/src/parameters/CMakeLists.txt b/src/parameters/CMakeLists.txt new file mode 100644 index 0000000..94e6337 --- /dev/null +++ b/src/parameters/CMakeLists.txt @@ -0,0 +1,6 @@ +set( + SRC_FILES ${SRC_FILES} + ${CMAKE_CURRENT_SOURCE_DIR}/parameters.c +) +set(SRC_FILES ${SRC_FILES} PARENT_SCOPE) + diff --git a/src/parameters/parameters.c b/src/parameters/parameters.c new file mode 100644 index 0000000..82ac9d1 --- /dev/null +++ b/src/parameters/parameters.c @@ -0,0 +1,84 @@ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> + +#include "../core/index.h" + +#include "parameters.h" + +static int parse_markov_order +( + struct ZoO_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) ZoO_INDEX_MAX) + || (input < 1) + ) + { + fprintf + ( + stderr, + "[F] Invalid or value for parameter 'MARKOV_ORDER', accepted" + "range is " + "[1, %lli] (integer).", + (long long int) ZoO_INDEX_MAX + ); + + errno = old_errno; + + return -1; + } + + param->markov_order = (ZoO_index) input; + + errno = old_errno; + + return 0; +} + +enum ZoO_invocation_objective ZoO_parameters_initialize +( + struct ZoO_parameters param [const restrict static 1], + int const argc, + const char * argv [const static argc] +) +{ + param->session = (const char *) NULL; + param->markov_order = 1; + param->storage = (const char *) NULL; + + switch (argc) + { + case 4: + param->session = argv[1]; + param->storage = argv[3]; + + if (parse_markov_order(param, argv[2]) < 0) + { + return ZoO_PRINTS_HELP; + } + else + { + return ZoO_RUNS; + } + + case 3: + param->session = argv[1]; + + return ZoO_CLEANS_UP; + + default: + return ZoO_PRINTS_HELP; + } +} diff --git a/src/parameters/parameters.h b/src/parameters/parameters.h new file mode 100644 index 0000000..7927ef7 --- /dev/null +++ b/src/parameters/parameters.h @@ -0,0 +1,18 @@ +#ifndef _ZoO_CLI_PARAMETERS_H_ +#define _ZoO_CLI_PARAMETERS_H_ + +#include "parameters_types.h" + +char * ZoO_parameters_get_session_name +( + const struct ZoO_parameters param [const restrict static 1] +); + +enum ZoO_invocation_objective ZoO_parameters_initialize +( + struct ZoO_parameters param [const restrict static 1], + int const argc, + const char * argv [const static argc] +); + +#endif diff --git a/src/parameters/parameters_types.h b/src/parameters/parameters_types.h new file mode 100644 index 0000000..f9ca88b --- /dev/null +++ b/src/parameters/parameters_types.h @@ -0,0 +1,18 @@ +#ifndef _ZoO_CLI_PARAMETERS_TYPES_H_ +#define _ZoO_CLI_PARAMETERS_TYPES_H_ + +enum ZoO_invocation_objective +{ + ZoO_PRINTS_HELP, + ZoO_CLEANS_UP, + ZoO_RUNS +}; + +struct ZoO_parameters +{ + const char * restrict session; + ZoO_index markov_order; + const char * restrict storage; +}; + +#endif |


