#include // size_t #include // strcmp() #include "km.h" static const struct { const km_init_type_t type; const char * const name; } TYPES[] = {{ .name = "rand", .type = KM_INIT_TYPE_RAND, }, { .name = "forgy", .type = KM_INIT_TYPE_FORGY, }}; #define NUM_TYPES (sizeof(TYPES) / sizeof(TYPES[0])) km_init_type_t km_get_init_type( const char * const s ) { // find init method for (size_t i = 0; i < NUM_TYPES; i++) { if (!strcmp(s, TYPES[i].name)) { // return type return TYPES[i].type; } } // return failure return KM_INIT_TYPE_LAST; }