From: Olivier Matz Date: Tue, 6 Aug 2013 19:52:48 +0000 (+0200) Subject: some pgmspace types are deprecated X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e2732473f4de080bc937fbe9f1ee6a175bfbafb3;p=aversive.git some pgmspace types are deprecated --- diff --git a/modules/ihm/parse/parse.c b/modules/ihm/parse/parse.c index 73b78f4..171729d 100644 --- a/modules/ihm/parse/parse.c +++ b/modules/ihm/parse/parse.c @@ -85,16 +85,16 @@ nb_common_chars(const char * s1, const char * s2) * 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)); @@ -118,7 +118,8 @@ match_inst(parse_pgm_inst_t *inst, const char * buf, uint8_t nb_match_token, 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)); } @@ -155,10 +156,10 @@ match_inst(parse_pgm_inst_t *inst, const char * buf, uint8_t nb_match_token, 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; @@ -210,7 +211,7 @@ parse(parse_pgm_ctx_t ctx[], const char * buf) #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"); @@ -230,8 +231,8 @@ parse(parse_pgm_ctx_t ctx[], const char * buf) /* 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 */ @@ -244,7 +245,7 @@ parse(parse_pgm_ctx_t ctx[], const char * buf) } 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 */ @@ -262,13 +263,13 @@ parse(parse_pgm_ctx_t ctx[], const char * buf) } 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; @@ -279,7 +280,7 @@ complete(parse_pgm_ctx_t ctx[], const char *buf, int16_t *state, 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 */ @@ -299,14 +300,15 @@ complete(parse_pgm_ctx_t ctx[], const char *buf, int16_t *state, 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)); @@ -342,7 +344,7 @@ complete(parse_pgm_ctx_t ctx[], const char *buf, int16_t *state, } 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); @@ -372,15 +374,16 @@ complete(parse_pgm_ctx_t ctx[], const char *buf, int16_t *state, 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)); @@ -396,7 +399,7 @@ complete(parse_pgm_ctx_t ctx[], const char *buf, int16_t *state, (*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 @@ -424,7 +427,7 @@ complete(parse_pgm_ctx_t ctx[], const char *buf, int16_t *state, 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 @@ -436,7 +439,7 @@ complete(parse_pgm_ctx_t ctx[], const char *buf, int16_t *state, } 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; } diff --git a/modules/ihm/parse/parse.h b/modules/ihm/parse/parse.h index 2760ca6..e780b05 100644 --- a/modules/ihm/parse/parse.h +++ b/modules/ihm/parse/parse.h @@ -46,12 +46,6 @@ struct token_hdr { }; 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. * @@ -73,13 +67,13 @@ typedef struct token_hdr_pgm parse_pgm_token_hdr_t; */ 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); }; /** @@ -91,26 +85,17 @@ struct inst { /* 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 @@ -119,7 +104,7 @@ typedef PROGMEM parse_ctx_t parse_pgm_ctx_t; * 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. @@ -136,7 +121,7 @@ int8_t parse(parse_pgm_ctx_t ctx[], const char * buf); * 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); diff --git a/modules/ihm/parse/parse_num.c b/modules/ihm/parse/parse_num.c index 7bbc7ce..1651f88 100644 --- a/modules/ihm/parse/parse_num.c +++ b/modules/ihm/parse/parse_num.c @@ -53,16 +53,16 @@ enum num_parse_state_t { }; /* 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 @@ -84,8 +84,8 @@ add_to_res(uint8_t c, uint32_t * res, uint8_t base) /* 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; @@ -419,8 +419,8 @@ parse_num(parse_pgm_token_hdr_t * tk, const char * srcbuf, void * res) /* 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; diff --git a/modules/ihm/parse/parse_num.h b/modules/ihm/parse/parse_num.h index de10e7d..fd13ee4 100644 --- a/modules/ihm/parse/parse_num.h +++ b/modules/ihm/parse/parse_num.h @@ -24,18 +24,11 @@ struct token_num { 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) \ { \ diff --git a/modules/ihm/parse/parse_string.c b/modules/ihm/parse/parse_string.c index abfe8bb..8449ac3 100644 --- a/modules/ihm/parse/parse_string.c +++ b/modules/ihm/parse/parse_string.c @@ -18,9 +18,9 @@ struct token_ops token_string_ops = { #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); @@ -31,8 +31,8 @@ get_token_len(const prog_char * s) 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); @@ -42,11 +42,11 @@ get_next_token(const prog_char * 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; @@ -100,7 +100,7 @@ parse_string(parse_pgm_token_hdr_t * tk, const char * buf, void * res) 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; @@ -116,11 +116,11 @@ int8_t complete_get_nb_string(parse_pgm_token_hdr_t * tk) 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)); @@ -143,10 +143,10 @@ int8_t complete_get_elt_string(parse_pgm_token_hdr_t * tk, int8_t idx, } -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; diff --git a/modules/ihm/parse/parse_string.h b/modules/ihm/parse/parse_string.h index 0d09892..41ba3c7 100644 --- a/modules/ihm/parse/parse_string.h +++ b/modules/ihm/parse/parse_string.h @@ -9,7 +9,7 @@ typedef char fixed_string_t[STR_TOKEN_SIZE]; struct token_string_data { - const prog_char * str; + PGM_P str; }; struct token_string { @@ -17,19 +17,14 @@ 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) \ { \ diff --git a/modules/ihm/rdline/rdline.c b/modules/ihm/rdline/rdline.c index bb0169d..f71209a 100644 --- a/modules/ihm/rdline/rdline.c +++ b/modules/ihm/rdline/rdline.c @@ -32,9 +32,9 @@ #include #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); @@ -543,7 +543,7 @@ char * rdline_get_history_item(struct rdline * rdl, uint8_t i) {return NULL;} /* 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' ) { @@ -553,7 +553,7 @@ rdline_puts_P(struct rdline * rdl, const prog_char * buf) /* 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; diff --git a/modules/ihm/vt100/vt100.c b/modules/ihm/vt100/vt100.c index f006119..2bdc47a 100644 --- a/modules/ihm/vt100/vt100.c +++ b/modules/ihm/vt100/vt100.c @@ -31,30 +31,30 @@ #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, @@ -71,14 +71,14 @@ vt100_init(struct vt100 * vt) 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