summaryrefslogtreecommitdiff
blob: 0e38e5e411532b8b60b9b98da0c2119af58de28b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#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).\n",
         (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;
   }
}

const char * ZoO_parameters_get_session_name
(
   const struct ZoO_parameters param [const restrict static 1]
)
{
   return param->session;
}

ZoO_index ZoO_parameters_get_markov_order
(
   const struct ZoO_parameters param [const restrict static 1]
)
{
   return param->markov_order;
}

const char * ZoO_parameters_get_storage_filename
(
   const struct ZoO_parameters param [const restrict static 1]
)
{
   return param->storage;
}