X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fmware%2Fparser.c;h=71aec30dc980f58d1c4b1ada8060224c96878e7c;hb=ad030f478d3e17130f6d9a36f90e843cf2e781d9;hp=2d47a5372cc67b24e67f33f042ba1c9bec4d70b5;hpb=d6aafcb0363974688e68f2325cf18f8087e07448;p=bertos.git diff --git a/bertos/mware/parser.c b/bertos/mware/parser.c index 2d47a537..71aec30d 100644 --- a/bertos/mware/parser.c +++ b/bertos/mware/parser.c @@ -55,6 +55,8 @@ #include "parser.h" +#include "cfg/cfg_parser.h" + #include #include @@ -197,6 +199,20 @@ bool parser_get_cmd_id(const char* line, unsigned long* ID) } #endif +/** + * Find the template for the command contained in the text line. + * The template can be used to tokenize the command and interpret + * it. + * + * This function can be used to find out which command is contained + * in a given text line without parsing all the parameters and + * executing it. + * + * \param input Text line to be processed (ASCIIZ) + * + * \return The command template associated with the command contained + * in the line, or NULL if the command is invalid. + */ const struct CmdTemplate* parser_get_cmd_template(const char *input) { const char *begin = input, *end = input; @@ -230,6 +246,18 @@ static const char *skip_to_params(const char *input, const struct CmdTemplate *c return end; } +/** + * Extract the arguments for the command contained in the text line. + * + * The first argument will always be the command name, so the actual arguments + * will start at index 1. + * + * \param input Text line to be processed (ASCIIZ) + * \param cmdp Command template for this line + * \param args Will contain the extracted parameters + * + * \return True if everything OK, false in case of parsing error. + */ bool parser_get_cmd_arguments(const char* input, const struct CmdTemplate* cmdp, parms args[CONFIG_PARSER_MAX_ARGS]) { input = skip_to_params(input, cmdp); @@ -250,6 +278,15 @@ static const void* get_key_from_command(const void* cmd, uint8_t* length) return c->name; } +/** + * \brief Command input handler. + * + * Process the input, calling the requested command (if found). + * + * \param input Text line to be processed (ASCIIZ) + * + * \return true if everything is OK, false in case of errors + */ bool parser_process_line(const char* input) { const struct CmdTemplate *cmdp; @@ -268,9 +305,15 @@ bool parser_process_line(const char* input) return true; } -void parser_register_cmd(const struct CmdTemplate* cmd) +/** + * Register a new command into the parser + * + * \param cmd Command template describing the command + * \return true if registration was successful, false otherwise + */ +bool parser_register_cmd(const struct CmdTemplate* cmd) { - ht_insert(&commands, cmd); + return ht_insert(&commands, cmd); } void parser_init(void)