summaryrefslogtreecommitdiff
blob: 24cbd68d5f3353fc5f231feb12fe2d010d4b0622 (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
#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;
}