utils.h (1535B)
1 #if SIZE_MAX == UINT64_MAX 2 #define H48_HMAX UINT8_C(11) 3 #else 4 #define H48_HMAX UINT8_C(7) 5 #endif 6 7 long long parse_h48_hk( 8 const char *, uint8_t [static 1], uint8_t [static 1]); 9 STATIC long long dataid_h48(const char *, char [static NISSY_SIZE_DATAID]); 10 11 long long 12 parse_h48_hk(const char *buf, uint8_t h[static 1], uint8_t k[static 1]) 13 { 14 char format_error_msg[100]; 15 sprintf(format_error_msg, "[H48] Error parsing H48 solver: must be in " 16 "'h48h*k*' format, but got '%s'\n", buf); 17 18 buf += 3; 19 20 if (*buf != 'h') { 21 LOG(format_error_msg); 22 goto parse_h48_hk_error; 23 } 24 buf++; 25 26 *h = atoi(buf); 27 if (*h > H48_HMAX) { 28 LOG("[H48] Invalid value %" PRIu8 " for parameter h (must be " 29 "at most %" PRIu8 ")\n", *h, H48_HMAX); 30 goto parse_h48_hk_error; 31 } 32 33 for ( ; *buf >= 0 + '0' && *buf <= 9 + '0'; buf++) { 34 if (*buf == 0) { 35 LOG(format_error_msg); 36 goto parse_h48_hk_error; 37 } 38 } 39 40 if (*buf != 'k') { 41 LOG(format_error_msg); 42 goto parse_h48_hk_error; 43 } 44 buf++; 45 46 *k = atoi(buf); 47 if (!(*k == 2 || (*k == 4 && *h == 0))) { 48 LOG("[H48] Invalid combinations of values h=%" PRIu8 " and k=%" 49 PRIu8 " for parameters h and k\n", *h, *k); 50 goto parse_h48_hk_error; 51 } 52 53 return NISSY_OK; 54 55 parse_h48_hk_error: 56 *h = 0; 57 *k = 0; 58 return NISSY_ERROR_INVALID_SOLVER; 59 } 60 61 STATIC long long 62 dataid_h48(const char *hk, char buf[static NISSY_SIZE_DATAID]) 63 { 64 uint8_t h, k; 65 long long err; 66 67 err = parse_h48_hk(hk, &h, &k); 68 if (err < 0) 69 return err; 70 71 sprintf(buf, "h48h%" PRIu8 "k%" PRIu8, h, k); 72 return NISSY_OK; 73 }