BeRTOS
|
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 00125 typedef enum 00126 { 00127 RC_ERROR = -1, 00128 RC_OK = 0, 00129 RC_REPLY = 1, 00130 RC_SKIP = 2 00131 } ResultCode; 00132 00134 typedef union { long l; const char *s; } parms; 00136 typedef ResultCode (*CmdFuncPtr)(parms args_results[]); 00137 00150 struct CmdTemplate 00151 { 00152 const char *name; 00153 const char *arg_fmt; 00154 const char *result_fmt; 00155 CmdFuncPtr func; 00156 uint16_t flags; 00157 }; 00158 00159 #define REGISTER_FUNCTION parser_register_cmd 00160 00166 #define REGISTER_CMD(NAME) REGISTER_FUNCTION(&cmd_ ## NAME ## _template) 00167 00178 #define MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) \ 00179 const struct CmdTemplate cmd_ ## NAME ## _template = \ 00180 { \ 00181 #NAME, ARGS, RES, cmd_ ## NAME, FLAGS \ 00182 }; 00183 00208 #define MAKE_CMD(NAME, ARGS, RES, BODY, FLAGS) \ 00209 static ResultCode cmd_ ## NAME (parms *args) \ 00210 { \ 00211 return (ResultCode)BODY; \ 00212 } \ 00213 MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) 00214 00220 void parser_init(void); 00221 00222 void parser_register_cmd(const struct CmdTemplate* cmd); 00223 00224 00232 const char* parser_rl_match(void* dummy, const char* word, int word_len); 00233 00234 bool parser_process_line(const char* line); 00235 00247 INLINE bool parser_execute_cmd(const struct CmdTemplate* templ, parms args[CONFIG_PARSER_MAX_ARGS]) 00248 { 00249 return (templ->func(args) == 0); 00250 } 00251 00252 const struct CmdTemplate* parser_get_cmd_template(const char* line); 00253 00254 bool parser_get_cmd_arguments(const char* line, const struct CmdTemplate* templ, parms args[CONFIG_PARSER_MAX_ARGS]); 00255 00256 #if CONFIG_ENABLE_COMPAT_BEHAVIOUR 00257 00266 bool parser_get_cmd_id(const char* line, unsigned long* ID); 00267 #endif 00268 00269 // defgroup parser 00271 #endif /* MWARE_PARSER_H */ 00272