* // 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
* //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
*
* \endcode
*
+ * <b>Configuration file</b>: cfg_parser.h
+ *
* \author Bernie Innocenti <bernie@codewiz.org>
* \author Stefano Fedrigo <aleph@develer.com>
* \author Giovanni Bajo <rasky@develer.com>
#include "cfg/cfg_parser.h"
#include <cpu/types.h>
+#include <cfg/debug.h>
/**
* Error generated by the commands through the return code.
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[]);
*
* \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.
*/
void parser_init(void);
-void parser_register_cmd(const struct CmdTemplate* cmd);
+bool parser_register_cmd(const struct CmdTemplate* cmd);
/**
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
/**