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 RC_CLAMPED = 3, 00133 } ResultCode; 00134 00135 typedef struct 00136 { 00137 const char *p; 00138 int sz; 00139 } str_parm; 00140 00142 typedef union { long l; str_parm s; } parms; 00144 typedef ResultCode (*CmdFuncPtr)(parms args_results[]); 00145 00158 struct CmdTemplate 00159 { 00160 const char *name; 00161 const char *arg_fmt; 00162 const char *result_fmt; 00163 CmdFuncPtr func; 00164 uint16_t flags; 00165 }; 00166 00167 #define REGISTER_FUNCTION parser_register_cmd 00168 00174 #define REGISTER_CMD(NAME) \ 00175 do { \ 00176 if (!REGISTER_FUNCTION(&cmd_ ## NAME ## _template)) \ 00177 ASSERT2(0, "Error in registering command, no space left"); \ 00178 } while (0) 00179 00190 #define MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) \ 00191 const struct CmdTemplate cmd_ ## NAME ## _template = \ 00192 { \ 00193 #NAME, ARGS, RES, cmd_ ## NAME, FLAGS \ 00194 }; 00195 00220 #define MAKE_CMD(NAME, ARGS, RES, BODY, FLAGS) \ 00221 static ResultCode cmd_ ## NAME (parms *args) \ 00222 { \ 00223 return (ResultCode)BODY; \ 00224 } \ 00225 MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) 00226 00232 void parser_init(void); 00233 00234 bool parser_register_cmd(const struct CmdTemplate* cmd); 00235 00236 00244 const char* parser_rl_match(void* dummy, const char* word, int word_len); 00245 00246 bool parser_process_line(const char* line); 00247 00259 INLINE bool parser_execute_cmd(const struct CmdTemplate* templ, parms args[CONFIG_PARSER_MAX_ARGS]) 00260 { 00261 return (templ->func(args) == 0); 00262 } 00263 00264 const struct CmdTemplate* parser_get_cmd_template(const char* line); 00265 00266 bool parser_get_cmd_arguments(const char* line, const struct CmdTemplate* templ, parms args[CONFIG_PARSER_MAX_ARGS]); 00267 bool get_word(const char **begin, const char **end); 00268 00269 #if CONFIG_ENABLE_COMPAT_BEHAVIOUR 00270 00279 bool parser_get_cmd_id(const char* line, unsigned long* ID); 00280 #endif 00281 00282 // defgroup parser 00284 #endif /* MWARE_PARSER_H */ 00285
![(please configure the [header_logo] section in trac.ini)](/chrome/site/bertos_logo.png)