utils.h (1382B)
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 }