X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=inline;f=bertos%2Fmware%2Fparser.h;h=d681f724d297daaf9ec89553840dd5563dff9d24;hb=6fffd0614f75137e8fed424c87835d4e7d478ef7;hp=7e837c60f32c48a71a3c86331f8d57a43b29254c;hpb=c0b2348ac2e28dd063bb5f5b571c3eac4d308203;p=bertos.git diff --git a/bertos/mware/parser.h b/bertos/mware/parser.h index 7e837c60..d681f724 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 @@ -118,6 +118,7 @@ #include "cfg/cfg_parser.h" #include +#include /** * Error generated by the commands through the return code. @@ -130,8 +131,14 @@ typedef enum RC_SKIP = 2 ///< Skip following commands } ResultCode; +typedef struct +{ + const char *p; + int sz; +} str_parm; + /** union that contains parameters passed to and from commands */ -typedef union { long l; const char *s; } parms; +typedef union { long l; str_parm s; } parms; /** pointer to commands */ typedef ResultCode (*CmdFuncPtr)(parms args_results[]); @@ -163,7 +170,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. @@ -219,7 +230,7 @@ MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) */ void parser_init(void); -void parser_register_cmd(const struct CmdTemplate* cmd); +bool parser_register_cmd(const struct CmdTemplate* cmd); /** @@ -252,6 +263,7 @@ INLINE bool parser_execute_cmd(const struct CmdTemplate* templ, parms args[CONFI const struct CmdTemplate* parser_get_cmd_template(const char* line); bool parser_get_cmd_arguments(const char* line, const struct CmdTemplate* templ, parms args[CONFIG_PARSER_MAX_ARGS]); +bool get_word(const char **begin, const char **end); #if CONFIG_ENABLE_COMPAT_BEHAVIOUR /**