diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-18 08:48:13 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-18 08:48:13 +0200 |
| commit | 8b94d135429a9f3253cc7f25a1453b412065c4a0 (patch) | |
| tree | 4a31d6def5421e95fb98505a2bc2653c18fca330 /src/solvers/h48/utils.h | |
| parent | 30b43f08955158d4f2066f4b50fe8d1241b3177b (diff) | |
| download | nissy-core-8b94d135429a9f3253cc7f25a1453b412065c4a0.tar.gz nissy-core-8b94d135429a9f3253cc7f25a1453b412065c4a0.zip | |
Refactor solver dispatch and checkdata
Diffstat (limited to 'src/solvers/h48/utils.h')
| -rw-r--r-- | src/solvers/h48/utils.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/solvers/h48/utils.h b/src/solvers/h48/utils.h new file mode 100644 index 0000000..b266c66 --- /dev/null +++ b/src/solvers/h48/utils.h | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | long long parse_h48_hk( | ||
| 2 | const char *, uint8_t [static 1], uint8_t [static 1]); | ||
| 3 | STATIC long long dataid_h48(const char *, char [static NISSY_SIZE_DATAID]); | ||
| 4 | |||
| 5 | long long | ||
| 6 | parse_h48_hk(const char *buf, uint8_t h[static 1], uint8_t k[static 1]) | ||
| 7 | { | ||
| 8 | char format_error_msg[100]; | ||
| 9 | sprintf(format_error_msg, "[H48] Error parsing H48 solver: must be in " | ||
| 10 | "'h48h*k*' format, but got '%s'\n", buf); | ||
| 11 | |||
| 12 | buf += 3; | ||
| 13 | |||
| 14 | if (*buf != 'h') { | ||
| 15 | LOG(format_error_msg); | ||
| 16 | goto parse_h48_hk_error; | ||
| 17 | } | ||
| 18 | buf++; | ||
| 19 | |||
| 20 | *h = atoi(buf); | ||
| 21 | if (*h > 11) { | ||
| 22 | LOG("[H48] Invalid value %" PRIu8 " for parameter h\n", *h); | ||
| 23 | goto parse_h48_hk_error; | ||
| 24 | } | ||
| 25 | |||
| 26 | for ( ; *buf >= 0 + '0' && *buf <= 9 + '0'; buf++) { | ||
| 27 | if (*buf == 0) { | ||
| 28 | LOG(format_error_msg); | ||
| 29 | goto parse_h48_hk_error; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | if (*buf != 'k') { | ||
| 34 | LOG(format_error_msg); | ||
| 35 | goto parse_h48_hk_error; | ||
| 36 | } | ||
| 37 | buf++; | ||
| 38 | |||
| 39 | *k = atoi(buf); | ||
| 40 | if (!(*k == 2 || (*k == 4 && *h == 0))) { | ||
| 41 | LOG("[H48] Invalid combinations of values h=%" PRIu8 " and k=%" | ||
| 42 | PRIu8 " for parameters h and k\n", *h, *k); | ||
| 43 | goto parse_h48_hk_error; | ||
| 44 | } | ||
| 45 | |||
| 46 | return NISSY_OK; | ||
| 47 | |||
| 48 | parse_h48_hk_error: | ||
| 49 | *h = 0; | ||
| 50 | *k = 0; | ||
| 51 | return NISSY_ERROR_INVALID_SOLVER; | ||
| 52 | } | ||
| 53 | |||
| 54 | STATIC long long | ||
| 55 | dataid_h48(const char *hk, char buf[static NISSY_SIZE_DATAID]) | ||
| 56 | { | ||
| 57 | uint8_t h, k; | ||
| 58 | long long err; | ||
| 59 | |||
| 60 | err = parse_h48_hk(hk, &h, &k); | ||
| 61 | if (err < 0) | ||
| 62 | return err; | ||
| 63 | |||
| 64 | sprintf(buf, "h48h%" PRIu8 "k%" PRIu8, h, k); | ||
| 65 | return NISSY_OK; | ||
| 66 | } | ||
