puzzlebox
Loading...
Searching...
No Matches
cmd.h
1#pragma once
2
11#include <stddef.h>
12
19typedef void cmd_handle_t(char * line);
31typedef char ** cmd_complete_t(const char * text, int start, int end);
32
37typedef struct {
39 const char * name;
40 const char *
43} cmd_t;
44
199
201
204
206static const cmd_t cmds[] = {
207 {
208 .handle = cmd_exit,
209 .name = "exit",
210 .info = "exit pbc",
211 },
212 {
213 .handle = cmd_help,
214 .name = "help",
215 .info = "show this help",
216 },
217 {
218 .handle = cmd_reset,
219 .name = "reset",
220 .info = "set a puzzle module's game state to 'idle'",
221 },
222 {
223 .handle = cmd_skip,
224 .name = "skip",
225 .info = "set a puzzle module's game state to 'solved'",
226 },
227#ifdef DEBUG
228 {
229 .handle = cmd_send,
230 .name = "send",
231 .info = "[debug] send raw message",
232 },
233 {
234 .handle = cmd_test,
235 .name = "test",
236 .info = "[debug] send a test puzbus message",
237 },
238 {
239 .handle = cmd_dump,
240 .name = "dump",
241 .info = "[debug] dump sent or received messages",
242 .complete = cmd_dump_complete,
243 },
244#endif
245};
246
248static const size_t cmds_length = sizeof(cmds) / sizeof(cmds[0]);
249
cmd_handle_t cmd_send
send command
Definition cmd.h:172
cmd_handle_t cmd_exit
exit command
Definition cmd.h:61
cmd_handle_t cmd_dump
dump command
Definition cmd.h:198
void cmd_handle_t(char *line)
Command handler function.
Definition cmd.h:19
cmd_handle_t cmd_reset
reset command
Definition cmd.h:99
static const size_t cmds_length
Number of commands defined in cmds.
Definition cmd.h:248
cmd_handle_t cmd_skip
skip command
Definition cmd.h:185
cmd_complete_t cmd_dump_complete
dump completion function
Definition cmd.h:203
cmd_handle_t cmd_test
test command
Definition cmd.h:75
char ** cmd_complete_t(const char *text, int start, int end)
Command completion function.
Definition cmd.h:31
cmd_handle_t cmd_help
help command
Definition cmd.h:86
static const cmd_t cmds[]
Commands.
Definition cmd.h:206
Command definition struct.
Definition cmd.h:37
const char * name
Command name (required)
Definition cmd.h:39
cmd_handle_t * handle
Handler function (required)
Definition cmd.h:38
cmd_complete_t * complete
Completion function (optional = NULL)
Definition cmd.h:42
const char * info
Command info (shown in help command) (optional = NULL)
Definition cmd.h:41