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
|
STATIC coord_t *parse_coord(size_t, const char *);
STATIC void parse_coord_and_trans(const char *, coord_t **, uint8_t *);
STATIC long long dataid_coord(const char *, char [static NISSY_SIZE_DATAID]);
STATIC coord_t *
parse_coord(size_t n, const char *coord)
{
int i;
/*
TODO Some coordinates are parsed incorrectly, e.g. DRFINNOE
TODO is matched by DRFIN. Check that strncmp is used correctly.
*/
for (i = 0; all_coordinates[i] != NULL; i++)
if (!strncmp(all_coordinates[i]->name, coord, n))
return all_coordinates[i];
return NULL;
}
STATIC void
parse_coord_and_trans(
const char *str,
coord_t **coord,
uint8_t *trans
)
{
size_t i;
for (i = 6; i < strlen(str); i++)
if (str[i] == '_')
break;
if (coord != NULL)
*coord = parse_coord(i-6, str+6);
if (trans != NULL)
*trans = i == strlen(str) ?
UINT8_ERROR : readrotation(str+i+1);
}
STATIC long long
dataid_coord(const char *ca, char dataid[static NISSY_SIZE_DATAID])
{
coord_t *c;
parse_coord_and_trans(ca, &c, NULL);
if (c == NULL) {
LOG("Error: cannot parse coordinate from '%s'\n", ca);
return NISSY_ERROR_INVALID_SOLVER;
}
strcpy(dataid, c->name);
return NISSY_OK;
}
|