00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _PARSE_H_
00025 #define _PARSE_H_
00026
00027 #include <aversive/pgmspace.h>
00028 #include <aversive/types.h>
00029
00030 #ifndef offsetof
00031 #define offsetof(type, field) ((size_t) &( ((type *)0)->field) )
00032 #endif
00033
00034 #define PARSE_SUCCESS 0
00035 #define PARSE_AMBIGUOUS -1
00036 #define PARSE_NOMATCH -2
00037 #define PARSE_BAD_ARGS -3
00038
00043 struct token_hdr {
00044 struct token_ops *ops;
00045 uint8_t offset;
00046 };
00047 typedef struct token_hdr parse_token_hdr_t;
00048
00049 struct token_hdr_pgm {
00050 struct token_ops *ops;
00051 uint8_t offset;
00052 } PROGMEM;
00053 typedef struct token_hdr_pgm parse_pgm_token_hdr_t;
00054
00074 struct token_ops {
00076 int8_t (*parse)(parse_pgm_token_hdr_t *, const char *, void *);
00078 int8_t (*complete_get_nb)(parse_pgm_token_hdr_t *);
00080 int8_t (*complete_get_elt)(parse_pgm_token_hdr_t *, int8_t, char *, uint8_t);
00082 int8_t (*get_help)(parse_pgm_token_hdr_t *, char *, uint8_t);
00083 };
00084
00090 struct inst {
00091
00092 void (*f)(void *, void *);
00093 void * data;
00094 char * help_str;
00095 prog_void * tokens[];
00096 };
00097 typedef struct inst parse_inst_t;
00098 struct inst_pgm {
00099
00100 void (*f)(void *, void *);
00101 void * data;
00102 char * help_str;
00103 prog_void * tokens[];
00104 } PROGMEM;
00105 typedef struct inst_pgm parse_pgm_inst_t;
00106
00112 typedef parse_pgm_inst_t * parse_ctx_t;
00113 typedef PROGMEM parse_ctx_t parse_pgm_ctx_t;
00114
00122 int8_t parse(parse_pgm_ctx_t ctx[], const char * buf);
00123
00139 int8_t complete(parse_pgm_ctx_t ctx[], const char *buf, int16_t *state,
00140 char *dst, uint8_t size);
00141
00142
00143
00144 int isendoftoken(char c);
00145
00146 #endif