summaryrefslogtreecommitdiff
path: root/keyword.h
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-07-26 18:05:51 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-07-26 18:05:51 -0300
commitb0470f2db735f4dffda742fe38a7f9488a5ebc08 (patch)
treef6beff8370eb440d96074fd58ffdbdc0ec198699 /keyword.h
parent8c633723964993a2ce6fb1717823caf46514a167 (diff)
keyword: Added `keyword` type
This will allow for easy parsing of stuff like the PR `info`, PR `comments`, and config files.
Diffstat (limited to 'keyword.h')
-rw-r--r--keyword.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/keyword.h b/keyword.h
new file mode 100644
index 0000000..b4f4fa2
--- /dev/null
+++ b/keyword.h
@@ -0,0 +1,41 @@
+#ifndef KEYWORD_H
+#define KEYWORD_H
+#include <stddef.h>
+#include <time.h>
+
+typedef enum keyword_type keyword_type;
+typedef struct keyword keyword;
+typedef union keyword_val keyword_val;
+typedef void (keyword_cb)(void *ctx, void *ret, const keyword *key, keyword_val val);
+
+enum keyword_type {
+ TYPE_NONE,
+ TYPE_INT,
+ TYPE_STRING,
+ TYPE_FLOAT,
+ TYPE_BOOL,
+ TYPE_TIME,
+ TYPE_COUNT,
+};
+
+struct keyword {
+ const char *key; /* Keyword. */
+ const char *desc; /* Description of the keyword. */
+ const char *time_fmt; /* Format string used to parse a timestamp (if needed). */
+ keyword_type type; /* Datatype of the keyword. */
+ size_t *offsets; /* Offset(s) of member(s) in a struct (if needed). */
+ keyword_cb *callback; /* Callback to keyword specific parsing function (if needed). */
+};
+
+union keyword_val {
+ int i; /* Integer. */
+ time_t t; /* Time. */
+ char *str; /* String. */
+ float f; /* Float. */
+};
+
+extern keyword_val get_keyword_value(const keyword *key, char *value, int *error);
+extern void set_keyword(const keyword *key, keyword_val val, void *ret, void *ctx);
+extern keyword_val parse_keyword(const keyword *key, char *key_str, char *value, int *error);
+extern int parse_keywords(const keyword **keys, char *key, char *value, void *ret, void *ctx);
+#endif