X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fmware%2Fparser.h;h=281db3964c05e51c8a85fe110daf8a670fb3947b;hb=751e0228258e4c9e738fdcbfd43e45cdf873a553;hp=382027c6384da9520a84c3b49fd7410e417e63c7;hpb=1112768b03f449f5b8f94d47bea51014710ac70b;p=bertos.git diff --git a/bertos/mware/parser.h b/bertos/mware/parser.h index 382027c6..281db396 100644 --- a/bertos/mware/parser.h +++ b/bertos/mware/parser.h @@ -70,8 +70,8 @@ * // Declare a buzzer command * MAKE_CMD(beep, "d", "", * ({ - * buz_beep(args[1].l); - * RC_OK; + * buz_beep(args[1].l); + * RC_OK; * }), 0) * * // initialize the parser @@ -92,7 +92,7 @@ * //Execute command * if(!parser_execute_cmd(templ, args)) * { - * // error + * // error * } * // Now args contain the outputs of the function, you can send it * // back to the caller @@ -100,6 +100,8 @@ * * \endcode * + * Configuration file: cfg_parser.h + * * \author Bernie Innocenti * \author Stefano Fedrigo * \author Giovanni Bajo @@ -116,6 +118,7 @@ #include "cfg/cfg_parser.h" #include +#include /** * Error generated by the commands through the return code. @@ -161,7 +164,11 @@ struct CmdTemplate * * \param NAME Command name to register */ -#define REGISTER_CMD(NAME) REGISTER_FUNCTION(&cmd_ ## NAME ## _template) +#define REGISTER_CMD(NAME) \ + do { \ + if (!REGISTER_FUNCTION(&cmd_ ## NAME ## _template)) \ + ASSERT2(0, "Error in registering command, no space left"); \ + } while (0) /** * Utility macro to create a command template. @@ -217,14 +224,7 @@ MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) */ void parser_init(void); - -/** - * Register a new command into the parser - * - * \param cmd Command template describing the command - * - */ -void parser_register_cmd(const struct CmdTemplate* cmd); +bool parser_register_cmd(const struct CmdTemplate* cmd); /** @@ -236,21 +236,8 @@ void parser_register_cmd(const struct CmdTemplate* cmd); */ const char* parser_rl_match(void* dummy, const char* word, int word_len); - -/** - * \brief Command input handler. - * - * Process the input, calling the requested command - * (if found) and calling printResult() to give out - * the result (on device specified with parameter fd). - * - * \param line Text line to be processed (ASCIIZ) - * - * \return true if everything is OK, false in case of errors - */ bool parser_process_line(const char* line); - /** * Execute a command with its arguments, and fetch its results. * @@ -267,39 +254,10 @@ INLINE bool parser_execute_cmd(const struct CmdTemplate* templ, parms args[CONFI return (templ->func(args) == 0); } - -/** - * 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 line 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* line); - -/** - * 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 line Text line to be processed (ASCIIZ) - * \param templ 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* line, const struct CmdTemplate* templ, parms args[CONFIG_PARSER_MAX_ARGS]); - #if CONFIG_ENABLE_COMPAT_BEHAVIOUR /** * Extract the ID from the command text line.