BeRTOS
|
Channel protocol parser and commands. More...
#include "parser.h"
#include "cfg/cfg_parser.h"
#include <io/kfile.h>
#include <struct/hashtable.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Functions | |
static const void * | get_key_from_command (const void *cmd, uint8_t *length) |
Hashtable hook to extract the key from a command. | |
DECLARE_HASHTABLE_STATIC (commands, CONFIG_MAX_COMMANDS_NUMBER, get_key_from_command) | |
Hashtable that handles the commands that can be executed. | |
static bool | get_word (const char **begin, const char **end) |
Tokenize one word at a time from a text. | |
static bool | parseArgs (const char *fmt, const char *input, parms argv[]) |
Command arguments parser. | |
const char * | parser_rl_match (UNUSED_ARG(void *, dummy), const char *word, int word_len) |
Hook provided by the parser for matching of command names (TAB completion) for readline. | |
struct CmdTemplate * | parser_get_cmd_template (const char *input) |
Find the template for the command contained in the text line. | |
bool | parser_get_cmd_arguments (const char *input, const struct CmdTemplate *cmdp, parms args[CONFIG_PARSER_MAX_ARGS]) |
Extract the arguments for the command contained in the text line. | |
bool | parser_process_line (const char *input) |
Command input handler. | |
void | parser_register_cmd (const struct CmdTemplate *cmd) |
Register a new command into the parser. | |
void | parser_init (void) |
Initialize the parser module. |
Channel protocol parser and commands.
This file contains the channel protocol parser and the definition of the protocol commands. Commands are defined in a "CmdTemplate" type array, containing:
The arguments and results are passed to command function using an union: the element of the union to use for each argument is determined by format strings present in the CmdTemplate table.
Definition in file parser.c.
static bool get_word | ( | const char ** | begin, |
const char ** | end | ||
) | [static] |
Tokenize one word at a time from a text.
This function is similar to strtok, but does not use any implicit context, nor it does modify the input buffer in any form. The word is returned as a STL-like [begin,end) range.
To extract the first word, make both begin and end point at the start of the text, and call the function. Then, subsequent calls will return the following words (assuming the begin/end variable are not modified between calls).
begin | Will contain the index of the first character of the word |
end | Will contain the index of the character after the last character of the word |
static bool parseArgs | ( | const char * | fmt, |
const char * | input, | ||
parms | argv[] | ||
) | [static] |
Command arguments parser.
Using the format pointed by the argument fmt parses the input string filling the array argv with input parameters of the correct type.
fmt | Parameters format string. |
input | Input string. |
argv | Array filled with parameters. |