* tokens, else the number of matched tokens, else -1.
*/
static int8_t
-match_inst(parse_pgm_inst_t *inst, const char * buf, uint8_t nb_match_token,
+match_inst(PGM_P inst, const char * buf, uint8_t nb_match_token,
void * result_buf)
{
uint8_t token_num=0;
- parse_pgm_token_hdr_t * token_p;
+ PGM_P token_p;
uint8_t i=0;
int8_t n = 0;
struct token_hdr token_hdr;
- token_p = (parse_pgm_token_hdr_t *)pgm_read_pgmptr(&inst->tokens[token_num]);
+ token_p = pgm_read_pgmptr(inst + sizeof(struct inst));
if (token_p)
memcpy_P(&token_hdr, token_p, sizeof(token_hdr));
buf += n;
token_num ++;
- token_p = (parse_pgm_token_hdr_t *)pgm_read_pgmptr(&inst->tokens[token_num]);
+ token_p = pgm_read_pgmptr(inst + sizeof(struct inst) +
+ token_num * sizeof(PGM_P));
if (token_p)
memcpy_P(&token_hdr, token_p, sizeof(token_hdr));
}
int8_t
-parse(parse_pgm_ctx_t ctx[], const char * buf)
+parse(PGM_P ctx, const char * buf)
{
uint8_t inst_num=0;
- parse_pgm_inst_t * inst;
+ PGM_P inst;
const char * curbuf;
char result_buf[256]; /* XXX align, size zé in broblém */
void (*f)(void *, void *) = NULL;
#endif
/* parse it !! */
- inst = (parse_pgm_inst_t *)pgm_read_pgmptr(ctx+inst_num);
+ inst = pgm_read_pgmptr(ctx + inst_num * sizeof(PGM_P));
while (inst) {
debug_printf("INST\n");
/* if end of buf -> there is no garbage after inst */
if (isendofline(*curbuf) || iscomment(*curbuf)) {
if (!f) {
- memcpy_P(&f, &inst->f, sizeof(f));
- memcpy_P(&data, &inst->data, sizeof(data));
+ memcpy_P(&f, inst + offsetof(parse_inst_t, f), sizeof(f));
+ memcpy_P(&data, inst + offsetof(parse_inst_t, data), sizeof(data));
}
else {
/* more than 1 inst matches */
}
inst_num ++;
- inst = (parse_pgm_inst_t *)pgm_read_pgmptr(ctx+inst_num);
+ inst = pgm_read_pgmptr(ctx + inst_num * sizeof(PGM_P));
}
/* call func */
}
int8_t
-complete(parse_pgm_ctx_t ctx[], const char *buf, int16_t *state,
+complete(PGM_P ctx, const char *buf, int16_t *state,
char *dst, uint8_t size)
{
const char * incomplete_token = buf;
uint8_t inst_num = 0;
- parse_pgm_inst_t *inst;
- parse_pgm_token_hdr_t *token_p;
+ PGM_P inst;
+ PGM_P token_p;
struct token_hdr token_hdr;
char tmpbuf[64], completion_buf[64];
uint8_t incomplete_token_len;
uint8_t nb_completable;
uint8_t nb_non_completable;
int16_t local_state=0;
- prog_char *help_str;
+ PGM_P help_str;
debug_printf("%s called\n", __FUNCTION__);
/* count the number of complete token to parse */
nb_completable = 0;
nb_non_completable = 0;
- inst = (parse_pgm_inst_t *)pgm_read_pgmptr(ctx+inst_num);
+ inst = pgm_read_pgmptr(ctx + inst_num * sizeof(PGM_P));
while (inst) {
/* parse the first tokens of the inst */
if (nb_token && match_inst(inst, buf, nb_token, NULL))
goto next;
debug_printf("instruction match \n");
- token_p = (parse_pgm_token_hdr_t *) pgm_read_pgmptr(&inst->tokens[nb_token]);
+ token_p = pgm_read_pgmptr(inst + sizeof(struct inst) +
+ sizeof(PGM_P) * nb_token);
if (token_p)
memcpy_P(&token_hdr, token_p, sizeof(token_hdr));
}
next:
inst_num ++;
- inst = (parse_pgm_inst_t *)pgm_read_pgmptr(ctx+inst_num);
+ inst = pgm_read_pgmptr(ctx + inst_num * sizeof(PGM_P));
}
debug_printf("total choices %d for this completion\n", nb_completable);
debug_printf("Multiple choice STATE=%d\n", *state);
inst_num = 0;
- inst = (parse_pgm_inst_t *)pgm_read_pgmptr(ctx+inst_num);
+ inst = pgm_read_pgmptr(ctx + inst_num * sizeof(PGM_P));
while (inst) {
/* we need to redo it */
- inst = (parse_pgm_inst_t *)pgm_read_pgmptr(ctx+inst_num);
+ inst = pgm_read_pgmptr(ctx + inst_num * sizeof(PGM_P));
if (nb_token && match_inst(inst, buf, nb_token, NULL))
goto next2;
- token_p = (parse_pgm_token_hdr_t *)pgm_read_pgmptr(&inst->tokens[nb_token]);
+ token_p = pgm_read_pgmptr(inst + sizeof(struct inst) +
+ sizeof(PGM_P) * nb_token);
if (token_p)
memcpy_P(&token_hdr, token_p, sizeof(token_hdr));
(*state)++;
if (token_p && token_hdr.ops->get_help) {
token_hdr.ops->get_help(token_p, tmpbuf, sizeof(tmpbuf));
- help_str = (prog_char *) pgm_read_pgmptr(&inst->help_str);
+ help_str = pgm_read_pgmptr(inst + offsetof(struct inst, help_str));
if (help_str)
snprintf_P(dst, size, PSTR("[%s]: "PGMS_FMT""), tmpbuf, help_str);
else
l=snprintf(dst, size, "%s", tmpbuf);
if (l>=0 && token_hdr.ops->get_help) {
token_hdr.ops->get_help(token_p, tmpbuf, sizeof(tmpbuf));
- help_str = (prog_char *) pgm_read_pgmptr(&inst->help_str);
+ help_str = pgm_read_pgmptr(inst + offsetof(struct inst, help_str));
if (help_str)
snprintf_P(dst+l, size-l, PSTR("[%s]: "PGMS_FMT), tmpbuf, help_str);
else
}
next2:
inst_num ++;
- inst = (parse_pgm_inst_t *)pgm_read_pgmptr(ctx+inst_num);
+ inst = pgm_read_pgmptr(ctx + inst_num * sizeof(PGM_P));
}
return 0;
}
};
typedef struct token_hdr parse_token_hdr_t;
-struct token_hdr_pgm {
- struct token_ops *ops;
- uint8_t offset;
-} PROGMEM;
-typedef struct token_hdr_pgm parse_pgm_token_hdr_t;
-
/**
* A token is defined by this structure.
*
*/
struct token_ops {
/** parse(token ptr, buf, res pts) */
- int8_t (*parse)(parse_pgm_token_hdr_t *, const char *, void *);
+ int8_t (*parse)(PGM_P, const char *, void *);
/** return the num of possible choices for this token */
- int8_t (*complete_get_nb)(parse_pgm_token_hdr_t *);
+ int8_t (*complete_get_nb)(PGM_P);
/** return the elt x for this token (token, idx, dstbuf, size) */
- int8_t (*complete_get_elt)(parse_pgm_token_hdr_t *, int8_t, char *, uint8_t);
+ int8_t (*complete_get_elt)(PGM_P, int8_t, char *, uint8_t);
/** get help for this token (token, dstbuf, size) */
- int8_t (*get_help)(parse_pgm_token_hdr_t *, char *, uint8_t);
+ int8_t (*get_help)(PGM_P, char *, uint8_t);
};
/**
/* f(parsed_struct, data) */
void (*f)(void *, void *);
void * data;
- char * help_str;
- prog_void * tokens[];
+ const char * help_str;
+ PGM_P tokens[];
};
typedef struct inst parse_inst_t;
-struct inst_pgm {
- /* f(parsed_struct, data) */
- void (*f)(void *, void *);
- void * data;
- char * help_str;
- prog_void * tokens[];
-} PROGMEM;
-typedef struct inst_pgm parse_pgm_inst_t;
/**
* A context is identified by its name, and contains a list of
* instruction
*
*/
-typedef parse_pgm_inst_t * parse_ctx_t;
-typedef PROGMEM parse_ctx_t parse_pgm_ctx_t;
+typedef const parse_inst_t * parse_ctx_t;
/**
* Try to parse a buffer according to the specified context. The
* calls the associated function (defined in the context) and returns
* 0 (PARSE_SUCCESS).
*/
-int8_t parse(parse_pgm_ctx_t ctx[], const char * buf);
+int8_t parse(PGM_P ctx, const char * buf);
/**
* complete() must be called with *state==0.
* The returned dst buf ends with \0.
*
*/
-int8_t complete(parse_pgm_ctx_t ctx[], const char *buf, int16_t *state,
+int8_t complete(PGM_P ctx, const char *buf, int16_t *state,
char *dst, uint8_t size);
};
/* Keep it sync with enum in .h */
-static const prog_char help1[] = "UINT8";
-static const prog_char help2[] = "UINT16";
-static const prog_char help3[] = "UINT32";
-static const prog_char help4[] = "INT8";
-static const prog_char help5[] = "INT16";
-static const prog_char help6[] = "INT32";
+static const char PROGMEM help1[] = "UINT8";
+static const char PROGMEM help2[] = "UINT16";
+static const char PROGMEM help3[] = "UINT32";
+static const char PROGMEM help4[] = "INT8";
+static const char PROGMEM help5[] = "INT16";
+static const char PROGMEM help6[] = "INT32";
#ifndef CONFIG_MODULE_PARSE_NO_FLOAT
-static const prog_char help7[] = "FLOAT";
+static const char PROGMEM help7[] = "FLOAT";
#endif
-static const prog_char * num_help[] = {
+static PGM_P num_help[] = {
help1, help2, help3, help4,
help5, help6,
#ifndef CONFIG_MODULE_PARSE_NO_FLOAT
/* parse an int or a float */
-int8_t
-parse_num(parse_pgm_token_hdr_t * tk, const char * srcbuf, void * res)
+int8_t
+parse_num(PGM_P tk, const char * srcbuf, void * res)
{
struct token_num_data nd;
enum num_parse_state_t st = START;
/* parse an int or a float */
-int8_t
-get_help_num(parse_pgm_token_hdr_t * tk, char * dstbuf, uint8_t size)
+int8_t
+get_help_num(PGM_P tk, char * dstbuf, uint8_t size)
{
struct token_num_data nd;
struct token_num_data num_data;
};
typedef struct token_num parse_token_num_t;
-struct token_num_pgm {
- struct token_hdr hdr;
- struct token_num_data num_data;
-} PROGMEM;
-typedef struct token_num_pgm parse_pgm_token_num_t;
extern struct token_ops token_num_ops;
-int8_t parse_num(parse_pgm_token_hdr_t * tk,
- const char * srcbuf, void * res);
-int8_t get_help_num(parse_pgm_token_hdr_t * tk,
- char * dstbuf, uint8_t size);
+int8_t parse_num(PGM_P tk, const char * srcbuf, void * res);
+int8_t get_help_num(PGM_P tk, char * dstbuf, uint8_t size);
#define TOKEN_NUM_INITIALIZER(structure, field, numtype) \
{ \
#define FIXEDSTRING_HELP PSTR("Fixed STRING")
static uint8_t
-get_token_len(const prog_char * s)
+get_token_len(const char * s)
{
- prog_char c;
+ char c;
uint8_t i=0;
c = pgm_read_byte(s+i);
return i;
}
-static const prog_char *
-get_next_token(const prog_char * s)
+static const char *
+get_next_token(PGM_P s)
{
uint8_t i;
i = get_token_len(s);
}
int8_t
-parse_string(parse_pgm_token_hdr_t * tk, const char * buf, void * res)
+parse_string(PGM_P tk, const char * buf, void * res)
{
struct token_string_data sd;
uint8_t token_len;
- const prog_char * str;
+ PGM_P str;
if (! *buf)
return -1;
return token_len;
}
-int8_t complete_get_nb_string(parse_pgm_token_hdr_t * tk)
+int8_t complete_get_nb_string(PGM_P tk)
{
struct token_string_data sd;
int8_t ret=1;
return ret;
}
-int8_t complete_get_elt_string(parse_pgm_token_hdr_t * tk, int8_t idx,
+int8_t complete_get_elt_string(PGM_P tk, int8_t idx,
char * dstbuf, uint8_t size)
{
struct token_string_data sd;
- const prog_char * s;
+ PGM_P s;
uint8_t len;
memcpy_P(&sd, &((struct token_string *)tk)->string_data, sizeof(sd));
}
-int8_t get_help_string(parse_pgm_token_hdr_t * tk, char * dstbuf, uint8_t size)
+int8_t get_help_string(PGM_P tk, char * dstbuf, uint8_t size)
{
struct token_string_data sd;
- const prog_char * s;
+ PGM_P s;
memcpy_P(&sd, &((struct token_string *)tk)->string_data, sizeof(sd));
s = sd.str;
typedef char fixed_string_t[STR_TOKEN_SIZE];
struct token_string_data {
- const prog_char * str;
+ PGM_P str;
};
struct token_string {
struct token_string_data string_data;
};
typedef struct token_string parse_token_string_t;
-struct token_string_pgm {
- struct token_hdr hdr;
- struct token_string_data string_data;
-} PROGMEM;
-typedef struct token_string_pgm parse_pgm_token_string_t;
extern struct token_ops token_string_ops;
-int8_t parse_string(parse_pgm_token_hdr_t * tk, const char * srcbuf, void * res);
-int8_t complete_get_nb_string(parse_pgm_token_hdr_t * tk);
-int8_t complete_get_elt_string(parse_pgm_token_hdr_t * tk, int8_t idx,
+int8_t parse_string(PGM_P tk, const char * srcbuf, void * res);
+int8_t complete_get_nb_string(PGM_P tk);
+int8_t complete_get_elt_string(PGM_P tk, int8_t idx,
char * dstbuf, uint8_t size);
-int8_t get_help_string(parse_pgm_token_hdr_t * tk, char * dstbuf, uint8_t size);
+int8_t get_help_string(PGM_P tk, char * dstbuf, uint8_t size);
#define TOKEN_STRING_INITIALIZER(structure, field, string) \
{ \
#include <cirbuf.h>
#include "rdline.h"
-static void rdline_puts_P(struct rdline * rdl, const prog_char * buf);
+static void rdline_puts_P(struct rdline * rdl, const char * buf);
static void rdline_miniprintf_P(struct rdline * rdl,
- const prog_char * buf, uint8_t val);
+ const char * buf, uint8_t val);
#ifdef CONFIG_MODULE_RDLINE_HISTORY
static void rdline_remove_old_history_item(struct rdline * rdl);
/* STATIC USEFUL FUNCS */
static void
-rdline_puts_P(struct rdline * rdl, const prog_char * buf)
+rdline_puts_P(struct rdline * rdl, const char * buf)
{
char c;
while ( (c=pgm_read_byte(buf++)) != '\0' ) {
/* a very very basic printf with one arg and one format 'u' */
static void
-rdline_miniprintf_P(struct rdline * rdl, const prog_char * buf, uint8_t val)
+rdline_miniprintf_P(struct rdline * rdl, const char * buf, uint8_t val)
{
char c, started=0, div=100;
#include "vt100.h"
-static const prog_char cmd0[] = vt100_up_arr;
-static const prog_char cmd1[] = vt100_down_arr;
-static const prog_char cmd2[] = vt100_right_arr;
-static const prog_char cmd3[] = vt100_left_arr;
-static const prog_char cmd4[] = "\177";
-static const prog_char cmd5[] = "\n";
-static const prog_char cmd6[] = "\001";
-static const prog_char cmd7[] = "\005";
-static const prog_char cmd8[] = "\013";
-static const prog_char cmd9[] = "\031";
-static const prog_char cmd10[] = "\003";
-static const prog_char cmd11[] = "\006";
-static const prog_char cmd12[] = "\002";
-static const prog_char cmd13[] = vt100_suppr;
-static const prog_char cmd14[] = vt100_tab;
-static const prog_char cmd15[] = "\004";
-static const prog_char cmd16[] = "\014";
-static const prog_char cmd17[] = "\r";
-static const prog_char cmd18[] = "\033\177";
-static const prog_char cmd19[] = vt100_word_left;
-static const prog_char cmd20[] = vt100_word_right;
-static const prog_char cmd21[] = "?";
-
-const prog_char * vt100_commands[] PROGMEM = {
+static const char PROGMEM cmd0[] = vt100_up_arr;
+static const char PROGMEM cmd1[] = vt100_down_arr;
+static const char PROGMEM cmd2[] = vt100_right_arr;
+static const char PROGMEM cmd3[] = vt100_left_arr;
+static const char PROGMEM cmd4[] = "\177";
+static const char PROGMEM cmd5[] = "\n";
+static const char PROGMEM cmd6[] = "\001";
+static const char PROGMEM cmd7[] = "\005";
+static const char PROGMEM cmd8[] = "\013";
+static const char PROGMEM cmd9[] = "\031";
+static const char PROGMEM cmd10[] = "\003";
+static const char PROGMEM cmd11[] = "\006";
+static const char PROGMEM cmd12[] = "\002";
+static const char PROGMEM cmd13[] = vt100_suppr;
+static const char PROGMEM cmd14[] = vt100_tab;
+static const char PROGMEM cmd15[] = "\004";
+static const char PROGMEM cmd16[] = "\014";
+static const char PROGMEM cmd17[] = "\r";
+static const char PROGMEM cmd18[] = "\033\177";
+static const char PROGMEM cmd19[] = vt100_word_left;
+static const char PROGMEM cmd20[] = vt100_word_right;
+static const char PROGMEM cmd21[] = "?";
+
+const char * const PROGMEM vt100_commands[] = {
cmd0, cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7,
cmd8, cmd9, cmd10, cmd11, cmd12, cmd13, cmd14,
cmd15, cmd16, cmd17, cmd18, cmd19, cmd20,
static int8_t
match_command(char * buf, uint8_t size)
{
- const prog_char * cmd;
+ const char *cmd;
uint8_t i = 0;
- for (i=0 ; i<sizeof(vt100_commands)/sizeof(const prog_char *) ; i++) {
+ for (i=0 ; i<sizeof(vt100_commands)/sizeof(const char *) ; i++) {
#ifdef HOST_VERSION
cmd = *(vt100_commands + i);
#else
- cmd = (const prog_char *) pgm_read_word (vt100_commands + i);
+ cmd = (const char *) pgm_read_word (vt100_commands + i);
#endif
if (size == strlen_P(cmd) &&
#define KEY_WRIGHT 20
#define KEY_HELP 21
-extern const prog_char * vt100_commands[] PROGMEM;
+extern const char * const PROGMEM vt100_commands[];
enum vt100_parser_state {
VT100_INIT,