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
|
coord_t *all_coordinates[] = {
&coordinate_eo,
NULL
};
STATIC void append_coord_name(const coord_t *, char *);
STATIC coord_t *parse_coord(const char *, int);
STATIC uint8_t parse_axis(const char *, int);
STATIC void parse_coord_and_axis(const char *, int, coord_t **, uint8_t *);
STATIC int64_t dataid_coord(const char *, char [static NISSY_DATAID_SIZE]);
STATIC void
append_coord_name(const coord_t *coord, char *str)
{
int i, j;
i = 0;
j = strlen(str);
while (coord->name[i]) str[j++] = coord->name[i++];
str[j] = '\0';
}
STATIC coord_t *
parse_coord(const char *coord, int n)
{
int i;
for (i = 0; all_coordinates[i] != NULL; i++)
if (!strncmp(all_coordinates[i]->name, coord, n))
return all_coordinates[i];
return NULL;
}
STATIC uint8_t
parse_axis(const char *axis, int n)
{
if (!strncmp(axis, "UD", n) || !strncmp(axis, "DU", n)) {
return AXIS_UD;
} else if (!strncmp(axis, "RL", n) || !strncmp(axis, "LR", n)) {
return AXIS_RL;
} else if (!strncmp(axis, "FB", n) || !strncmp(axis, "BF", n)) {
return AXIS_FB;
}
return UINT8_ERROR;
}
STATIC void
parse_coord_and_axis(const char *str, int n, coord_t **coord, uint8_t *axis)
{
int i;
for (i = 0; i < n; i++)
if (str[i] == '_')
break;
if (coord != NULL)
*coord = parse_coord(str, i);
if (axis != NULL)
*axis = i == n ? UINT8_ERROR : parse_axis(str+i+1, n-i-1);
}
STATIC int64_t
dataid_coord(const char *ca, char dataid[static NISSY_DATAID_SIZE])
{
coord_t *c;
parse_coord_and_axis(ca, strlen(ca), &c, NULL);
if (c == NULL) {
LOG("dataid_coord: cannot parse coordinate from '%s'\n", ca);
return NISSY_ERROR_INVALID_SOLVER;
}
strcpy(dataid, c->name);
return NISSY_OK;
}
|