diff options
| author | Federico Angelilli <code@fedang.net> | 2024-11-18 17:02:20 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-11-18 17:02:20 +0100 |
| commit | aa19580474f96c9aacf5e85008013891ad2a7045 (patch) | |
| tree | a3323b6ca6ebed38799477ebba7df61ad1218240 /src/format.h | |
| parent | e07263e6f1c777241f9512fbbb266e89d1364f08 (diff) | |
Start working on advanced formatting
Diffstat (limited to 'src/format.h')
| -rw-r--r-- | src/format.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/format.h b/src/format.h new file mode 100644 index 0000000..bceff0c --- /dev/null +++ b/src/format.h @@ -0,0 +1,42 @@ +#ifndef COMET_FORMAT_H +#define COMET_FORMAT_H + +#include <stdint.h> +#include <stdbool.h> + +typedef struct { + char **parts; + size_t length; +} format_t; + +typedef enum { + FORMAT_SUCCESS, + FORMAT_NESTED, + FORMAT_UNKNOWN, + FORMAT_UNTERMINATED, +} format_status_t; + +typedef enum { + FORMAT_NONE, + FORMAT_STRING, + FORMAT_BYTE, + FORMAT_FUNCTION, +} format_action_t; + +typedef char *(*format_function_t)(const char *key); + +typedef struct { + format_action_t action; + const char *key; + union { + const char *value; + uint8_t byte; + format_function_t fn; + }; +} format_pair_t; + +format_status_t format_init(format_t *format, const char *string, char delim, const format_pair_t *pairs); + +void format_free(format_t *format); + +#endif |
