aboutsummaryrefslogtreecommitdiff
path: root/km-init-type.c
diff options
context:
space:
mode:
Diffstat (limited to 'km-init-type.c')
-rw-r--r--km-init-type.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/km-init-type.c b/km-init-type.c
new file mode 100644
index 0000000..27fc1ee
--- /dev/null
+++ b/km-init-type.c
@@ -0,0 +1,32 @@
+#include <stddef.h> // size_t
+#include <string.h> // 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;
+}