X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=bertos%2Fmware%2Fparser.h;h=ca7a7a2891f9fe627776fce6b6b85962587f54e7;hb=73263eca4f0a41d35deb3256c8cc894cfc907ff2;hp=0e2b0b9d9aa5804335830fe55a49733eba2001eb;hpb=f87390bf71f44a3ed9dc65c66128c5c6979655a9;p=bertos.git
diff --git a/bertos/mware/parser.h b/bertos/mware/parser.h
index 0e2b0b9d..ca7a7a28 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.
@@ -125,11 +128,18 @@ typedef enum
RC_ERROR = -1, ///< Reply with error.
RC_OK = 0, ///< No reply (ignore reply arguments).
RC_REPLY = 1, ///< Reply command arguments.
- RC_SKIP = 2 ///< Skip following commands
+ RC_SKIP = 2, ///< Skip following commands
+ RC_CLAMPED = 3, ///< argument values have been clamped.
} 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[]);
@@ -161,7 +171,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,7 +231,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);
/**
@@ -250,6 +264,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
/**