13static inline void read_option(
const char* option,
int argc,
char** argv,
bool* out) {
14 for (
int i = 0; i < argc; ++i) {
15 if (strcmp(argv[i], option) == 0) {
23static inline void read_int_option(
const char* option,
int argc,
char** argv,
int* out,
int default_val) {
24 for (
int i = 0; i < argc - 1; ++i) {
25 if (strcmp(argv[i], option) == 0 && (*out = atoi(argv[i + 1])) > 0) {
32static inline char parse_nibble(
char hex) {
34 return (hex & 0x40) ? hex - (
'A' - 10) : hex & 0xf;
37static inline void hex2bin(
const char* in,
int length,
char* out) {
38 for (
int i = 0; i < length; i += 2) {
39 char nibble1 = parse_nibble(*in++);
40 char nibble2 = parse_nibble(*in++);
41 *out++ = nibble1 << 4 | nibble2;
45static inline void output_hex(
const char* data,
int length) {
46 for (
unsigned i = 0; i < length; ++i)
47 printf(
"%02x", data[i] & 0xff);
50static inline bool hashes_equal(
char* a,
char* b) {
51 return memcmp(a, b, HASHX_SIZE) == 0;
54static inline bool equals_hex(
const void* hash,
const char* hex) {
55 char reference[HASHX_SIZE];
56 hex2bin(hex, 2 * HASHX_SIZE, reference);
57 return memcmp(hash, reference,
sizeof(reference)) == 0;