From 1373211465c34015ee900e097aa87fbffb401187 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sun, 29 Jan 2017 19:54:26 +0100 Subject: Trying out ACSL, continuing implementation. --- src/parameters/CMakeLists.txt | 6 +++ src/parameters/parameters.c | 84 +++++++++++++++++++++++++++++++++++++++ src/parameters/parameters.h | 18 +++++++++ src/parameters/parameters_types.h | 18 +++++++++ 4 files changed, 126 insertions(+) create mode 100644 src/parameters/CMakeLists.txt create mode 100644 src/parameters/parameters.c create mode 100644 src/parameters/parameters.h create mode 100644 src/parameters/parameters_types.h (limited to 'src/parameters') 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 +#include +#include + +#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 -- cgit v1.2.3-70-g09d2