diff options
| author | Albert Cervin <albert@acervin.com> | 2022-11-02 22:20:04 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2022-11-16 23:33:49 +0100 |
| commit | 2f4cb88d5c60f725323739300bb49dfa8923e7d5 (patch) | |
| tree | 6ec22c2be92eff05f18e5919e747faab56e555ad /src/command.h | |
| download | dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.tar.gz dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.tar.xz dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.zip | |
🎉 And so it begins
Diffstat (limited to 'src/command.h')
| -rw-r--r-- | src/command.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/command.h b/src/command.h new file mode 100644 index 0000000..9515282 --- /dev/null +++ b/src/command.h @@ -0,0 +1,34 @@ +#include <stdint.h> + +struct buffer; + +typedef void (*command_fn)(struct buffer *buffer); + +struct command { + const char *name; + command_fn fn; +}; + +struct hashed_command { + uint32_t hash; + struct command *command; +}; + +struct commands { + struct hashed_command *commands; + uint32_t ncommands; + uint32_t capacity; +}; + +struct commands command_list_create(uint32_t capacity); +void command_list_destroy(struct commands *commands); + +uint32_t register_command(struct commands *commands, struct command *command); +void register_commands(struct commands *command_list, struct command *commands, + uint32_t ncommands); + +uint32_t hash_command_name(const char *name); + +struct command *lookup_command(struct commands *commands, const char *name); +struct command *lookup_command_by_hash(struct commands *commands, + uint32_t hash); |
