aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48/utils.h
blob: b266c662f0f550de051117ab8179855167a61755 (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
long long parse_h48_hk(
    const char *, uint8_t [static 1], uint8_t [static 1]);
STATIC long long dataid_h48(const char *, char [static NISSY_SIZE_DATAID]);

long long
parse_h48_hk(const char *buf, uint8_t h[static 1], uint8_t k[static 1])
{
	char format_error_msg[100];
	sprintf(format_error_msg, "[H48] Error parsing H48 solver: must be in "
	    "'h48h*k*' format, but got '%s'\n", buf);

	buf += 3;

	if (*buf != 'h') {
		LOG(format_error_msg);
		goto parse_h48_hk_error;
	}
	buf++;

	*h = atoi(buf);
	if (*h > 11) {
		LOG("[H48] Invalid value %" PRIu8 " for parameter h\n", *h);
		goto parse_h48_hk_error;
	}

	for ( ; *buf >= 0 + '0' && *buf <= 9 + '0'; buf++) {
		if (*buf == 0) {
			LOG(format_error_msg);
			goto parse_h48_hk_error;
		}
	}

	if (*buf != 'k') {
		LOG(format_error_msg);
		goto parse_h48_hk_error;
	}
	buf++;

	*k = atoi(buf);
	if (!(*k == 2 || (*k == 4 && *h == 0))) {
		LOG("[H48] Invalid combinations of values h=%" PRIu8 " and k=%"
		    PRIu8 " for parameters h and k\n", *h, *k);
		goto parse_h48_hk_error;
	}

	return NISSY_OK;

parse_h48_hk_error:
	*h = 0;
	*k = 0;
	return NISSY_ERROR_INVALID_SOLVER;
}

STATIC long long
dataid_h48(const char *hk, char buf[static NISSY_SIZE_DATAID])
{
	uint8_t h, k;
	long long err;

	err = parse_h48_hk(hk, &h, &k);
	if (err < 0)
		return err;

	sprintf(buf, "h48h%" PRIu8 "k%" PRIu8, h, k);
	return NISSY_OK;
}

Generated with cgit - Back to sebastiano.tronto.net