parser.h

Go to the documentation of this file.
00001 
00045 #ifndef MWARE_PARSER_H
00046 #define MWARE_PARSER_H
00047 
00048 #include <cpu/types.h>
00049 
00051 #define PARSER_MAX_ARGS       8
00052 
00056 typedef enum
00057 {
00058     RC_ERROR  = -1, 
00059     RC_OK     = 0,  
00060     RC_REPLY  = 1,  
00061     RC_SKIP   = 2   
00062 } ResultCode;
00063 
00065 typedef union { long l; const char *s; } parms;
00067 typedef ResultCode (*CmdFuncPtr)(parms args_results[]);
00068 
00081 struct CmdTemplate
00082 {
00083     const char *name;          
00084     const char *arg_fmt;       
00085     const char *result_fmt;    
00086     CmdFuncPtr func;           
00087     uint16_t   flags;          
00088 };
00089 
00095 void parser_init(void);
00096 
00097 
00104 void parser_register_cmd(const struct CmdTemplate* cmd);
00105 
00106 
00114 const char* parser_rl_match(void* dummy, const char* word, int word_len);
00115 
00116 
00128 bool parser_process_line(const char* line);
00129 
00130 
00139 INLINE bool parser_execute_cmd(const struct CmdTemplate* templ, parms args[PARSER_MAX_ARGS])
00140 {
00141     return (templ->func(args) == 0);
00142 }
00143 
00144 
00159 const struct CmdTemplate* parser_get_cmd_template(const char* line);
00160 
00161 
00171 bool parser_get_cmd_arguments(const char* line, const struct CmdTemplate* templ, parms args[PARSER_MAX_ARGS]);
00172 
00173 
00183 bool parser_get_cmd_id(const char* line, unsigned long* ID);
00184 
00185 
00186 #endif /* MWARE_PARSER_H */
00187