![]() |
C-chat
|
Defines macros to aim to handle commands. More...
Go to the source code of this file.
Macros | |
#define | COMMAND_HANDLER(NAME, commands) |
Defines a command handler. More... | |
#define | COMMAND(NAME, usage, next) |
Defines a command. More... | |
Defines macros to aim to handle commands.
#define COMMAND | ( | NAME, | |
usage, | |||
next | |||
) |
Defines a command.
This macro must be called as a parameter of COMMAND_HANDLER macro (see COMMAND_HANDLER macro documentation). Multiple COMMAND call can be nested and once a command is handled, a return call must be made to avoid error message display.
Example of COMMAND macro call :
COMMAND(users, "users <create | delete | list>", COMMAND(delete, "users delete <user>", if (strlen(command) > 0) { // Delete user return; } ) COMMAND(create, "users create <user>", if (strlen(command) > 0) { // Create user return; } ) COMMAND(list, "users list", // List users return; ) )
NAME | The command name (raw identifier) |
usage | The command usage (string) |
next | The code to execute on command match |
#define COMMAND_HANDLER | ( | NAME, | |
commands | |||
) |
Defines a command handler.
Defines a function named NAMEHandler where NAME if the given name. The produced function signature is: void NAMEHandler(const char* command); Example:
COMMAND_HANDLER(commands, COMMAND(...) COMMAND(...) COMMAND(...) )
Will create the function : void commandsHandler(const char* command)
The body of the function MUST be generated by COMMAND macros.
NAME | The prefix for the produced command handle |
commands | Successive calls to COMMAND macro |