parser.h

Go to the documentation of this file.
00001 
00043 #ifndef MWARE_PARSER_H
00044 #define MWARE_PARSER_H
00045 
00046 #include <cpu/types.h>
00047 
00049 #define PARSER_MAX_ARGS       8
00050 
00054 typedef enum
00055 {
00056     RC_ERROR  = -1, 
00057     RC_OK     = 0,  
00058     RC_REPLY  = 1,  
00059     RC_SKIP   = 2   
00060 } ResultCode;
00061 
00063 typedef union { long l; const char *s; } parms;
00065 typedef ResultCode (*CmdFuncPtr)(parms args_results[]);
00066 
00079 struct CmdTemplate
00080 {
00081     const char *name;          
00082     const char *arg_fmt;       
00083     const char *result_fmt;    
00084     CmdFuncPtr func;           
00085     uint16_t   flags;          
00086 };
00087 
00093 void parser_init(void);
00094 
00095 
00102 void parser_register_cmd(const struct CmdTemplate* cmd);
00103 
00104 
00112 const char* parser_rl_match(void* dummy, const char* word, int word_len);
00113 
00114 
00126 bool parser_process_line(const char* line);
00127 
00128 
00137 INLINE bool parser_execute_cmd(const struct CmdTemplate* templ, parms args[PARSER_MAX_ARGS])
00138 {
00139     return (templ->func(args) == 0);
00140 }
00141 
00142 
00157 const struct CmdTemplate* parser_get_cmd_template(const char* line);
00158 
00159 
00169 bool parser_get_cmd_arguments(const char* line, const struct CmdTemplate* templ, parms args[PARSER_MAX_ARGS]);
00170 
00171 
00181 bool parser_get_cmd_id(const char* line, unsigned long* ID);
00182 
00183 
00184 #endif /* MWARE_PARSER_H */
00185