summaryrefslogtreecommitdiff
blob: 8e52fe112ff3cb67cafd96461114d4806c011284 (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
/**** POSIX *******************************************************************/
#include <string.h>

/**** RELABSD *****************************************************************/
#include <relabsd/debug.h>

#include <relabsd/util/string.h>

#include <relabsd/device/axis.h>

/******************************************************************************/
/**** LOCAL FUNCTIONS *********************************************************/
/******************************************************************************/

/******************************************************************************/
/**** EXPORTED FUNCTIONS ******************************************************/
/******************************************************************************/
/*
 * Returns -1 if the option was discarded (an error has been reported),
 *         0 if the option was successfully parsed.
 */
int relabsd_axis_enable_option_from_name
(
   const char option_name [const restrict static 1],
   const char axis_name [const restrict static 1],
   struct relabsd_axis axis [const restrict static 1]
)
{

   if (RELABSD_IS_PREFIX("direct", option_name))
   {
      axis->flags[RELABSD_DIRECT] = 1;

      if (axis->flags[RELABSD_FRAMED])
      {
         RELABSD_WARNING
         (
            "Option 'direct' on axis '%s' supersedes its 'framed' option.",
            axis_name
         );
      }
   }
   else if (RELABSD_IS_PREFIX("real_fuzz", option_name))
   {
      axis->flags[RELABSD_REAL_FUZZ] = 1;
   }
   else if (RELABSD_IS_PREFIX("framed", option_name))
   {
      axis->flags[RELABSD_FRAMED] = 1;

      if (axis->flags[RELABSD_DIRECT])
      {
         RELABSD_WARNING
         (
            "Option 'direct' on axis '%s' supersedes its 'framed' option.",
            axis_name
         );
      }
   }
   else if (RELABSD_IS_PREFIX("convert_to=", option_name))
   {
      axis->convert_to =
         relabsd_axis_parse_name_from_prefix
         (
            option_name + strlen("convert_to=")
         );

      if (axis->convert_to == RELABSD_UNKNOWN)
      {
         RELABSD_ERROR
         (
            "Unknown target axis to convert to in config for axis '%s'.",
            axis_name
         );

         return -1;
      }
   }
   else
   {
      RELABSD_ERROR
      (
         "Unknown option '%s' for axis '%s'.",
         option_name,
         axis_name
      );

      return -1;
   }

   return 0;
}