parser.h
Go to the documentation of this file.00001
00115 #ifndef MWARE_PARSER_H
00116 #define MWARE_PARSER_H
00117
00118 #include "cfg/cfg_parser.h"
00119
00120 #include <cpu/types.h>
00121 #include <cfg/debug.h>
00122
00126 typedef enum
00127 {
00128 RC_ERROR = -1,
00129 RC_OK = 0,
00130 RC_REPLY = 1,
00131 RC_SKIP = 2
00132 } ResultCode;
00133
00135 typedef union { long l; const char *s; } parms;
00137 typedef ResultCode (*CmdFuncPtr)(parms args_results[]);
00138
00151 struct CmdTemplate
00152 {
00153 const char *name;
00154 const char *arg_fmt;
00155 const char *result_fmt;
00156 CmdFuncPtr func;
00157 uint16_t flags;
00158 };
00159
00160 #define REGISTER_FUNCTION parser_register_cmd
00161
00167 #define REGISTER_CMD(NAME) \
00168 do { \
00169 if (!REGISTER_FUNCTION(&cmd_ ## NAME ## _template)) \
00170 ASSERT2(0, "Error in registering command, no space left"); \
00171 } while (0)
00172
00183 #define MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) \
00184 const struct CmdTemplate cmd_ ## NAME ## _template = \
00185 { \
00186 #NAME, ARGS, RES, cmd_ ## NAME, FLAGS \
00187 };
00188
00213 #define MAKE_CMD(NAME, ARGS, RES, BODY, FLAGS) \
00214 static ResultCode cmd_ ## NAME (parms *args) \
00215 { \
00216 return (ResultCode)BODY; \
00217 } \
00218 MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS)
00219
00225 void parser_init(void);
00226
00227 bool parser_register_cmd(const struct CmdTemplate* cmd);
00228
00229
00237 const char* parser_rl_match(void* dummy, const char* word, int word_len);
00238
00239 bool parser_process_line(const char* line);
00240
00252 INLINE bool parser_execute_cmd(const struct CmdTemplate* templ, parms args[CONFIG_PARSER_MAX_ARGS])
00253 {
00254 return (templ->func(args) == 0);
00255 }
00256
00257 const struct CmdTemplate* parser_get_cmd_template(const char* line);
00258
00259 bool parser_get_cmd_arguments(const char* line, const struct CmdTemplate* templ, parms args[CONFIG_PARSER_MAX_ARGS]);
00260
00261 #if CONFIG_ENABLE_COMPAT_BEHAVIOUR
00262
00271 bool parser_get_cmd_id(const char* line, unsigned long* ID);
00272 #endif
00273
00274
00276 #endif
00277