Commit from zer0 on branch b_zer0 (2007-11-16 15:03 CET) =================================
fix bug in parse_num for negative integers aversive modules/ihm/parse/parse_num.c 1.1.2.5 ====================================== aversive/modules/ihm/parse/parse_num.c (1.1.2.4 -> 1.1.2.5) ====================================== @@ -306,6 +306,7 @@ else if ( type == INT32 && res1 <= S32_MAX ) { if (res) *(int32_t *)res = (int32_t) res1; + return (buf-srcbuf); } else if ( type == UINT8 && res1 <= U08_MAX ) { if (res) @@ -335,17 +336,17 @@ case DEC_NEG_OK: if ( type == INT8 && res1 <= S08_MAX + 1 ) { if (res) - *(int8_t *)res = (int8_t) res1; + *(int8_t *)res = - (int8_t) res1; return (buf-srcbuf); } else if ( type == INT16 && res1 <= (uint16_t)S16_MAX + 1 ) { if (res) - *(int16_t *)res = (int16_t) res1; + *(int16_t *)res = - (int16_t) res1; return (buf-srcbuf); } else if ( type == INT32 && res1 <= (uint32_t)S32_MAX + 1 ) { if (res) - *(int32_t *)res = (int32_t) res1; + *(int32_t *)res = - (int32_t) res1; return (buf-srcbuf); } else if ( type == FLOAT ) { Commit from zer0 on branch b_zer0 (2007-11-16 18:12 CET) ================================= update parse lib. Different kind of errors, some bug fixes. aversive modules/ihm/parse/parse.c 1.1.2.5 aversive modules/ihm/parse/parse.h 1.1.2.5 ================================== aversive/modules/ihm/parse/parse.c (1.1.2.4 -> 1.1.2.5) ================================== @@ -55,7 +55,8 @@ /** * try to match the buffer with an instruction (only the first - * nb_match_token if != 0). Return 0 on success or -1. + * nb_match_token tokens if != 0). Return 0 if we match all the + * tokens, else the number of matched tokens, else -1. */ static int8_t match_inst(struct inst * inst, const char * buf, uint8_t nb_match_token, @@ -92,18 +93,23 @@ token = *token_list; } - /* match the first token */ + /* does not match */ + if (i==0) + return -1; + + /* in case we want to match a specific num of token */ if (nb_match_token) { if (i == nb_match_token) { return 0; } - return -1; + return i; + } + + /* we don't match all the tokens */ + if (token) { + return i; } - /* does not match */ - if (token) - return -1; - /* are there are some tokens more */ while (isblank(*buf)) { buf++; @@ -113,9 +119,11 @@ if ( isendofline(*buf) || iscomment(*buf) ) return 0; - return -1; + /* garbage after inst */ + return i; } + int8_t parse(struct ctx * ctx, const char * buf) { @@ -128,6 +136,8 @@ int comment = 0; int linelen = 0; int parse_it = 0; + int8_t err = PARSE_NOMATCH; + int8_t tok; #ifdef CMDLINE_DEBUG char debug_buf[64]; #endif @@ -175,7 +185,12 @@ debug_printf("INST\n"); /* fully parsed */ - if (! match_inst(inst, buf, 0, result_buf)) { + tok = match_inst(inst, buf, 0, result_buf); + + if (tok > 0) /* we matched at least one token */ + err = PARSE_BAD_ARGS; + + else if (!tok) { debug_printf("INST fully parsed\n"); /* skip spaces */ while (isblank(*curbuf)) { @@ -190,16 +205,12 @@ } else { /* more than 1 inst matches */ - /* return -1; */ - /* XXX */ + err = PARSE_AMBIGUOUS; f=NULL; debug_printf("Ambiguous cmd\n"); break; } } - else { - debug_printf("Garbage after inst %x\n", *curbuf & 0xff); - } } inst_list ++; @@ -213,10 +224,8 @@ /* no match */ else { - /* XXX */ - /* return mes couilles */ - debug_printf("No match\n"); - return -1; /* pas bien ça... */ + debug_printf("No match err=%d\n", err); + return err; } return linelen; @@ -260,8 +269,10 @@ } } - if (nb_token == -1) + if (nb_token == -1) { nb_token = 0; + incomplete_token++; + } incomplete_token_len = strlen(incomplete_token); @@ -293,8 +304,9 @@ debug_printf("%d choices for this token\n", n); for (i=0 ; i<n ; i++) { - if (token->ops->complete_get_elt(token, i, tmpbuf, sizeof(tmpbuf)) < 0) + if (token->ops->complete_get_elt(token, i, tmpbuf, sizeof(tmpbuf)-1) < 0) continue; + strcat(tmpbuf, " "); /* we have at least room for one char */ debug_printf(" choice <%s>\n", tmpbuf); /* does the completion match the beginning of the word ? */ if (!strncmp(incomplete_token, tmpbuf, incomplete_token_len)) { @@ -324,19 +336,10 @@ /* if multichoice is not required */ if (*state == 0 && incomplete_token_len > 0) { - /* one possible choice */ - if (nb_completable == 1) { - if (completion_len + 1 > size) //strlen(completion_buf)+1 > size) - return 0; - - strcpy(dst, completion_buf); - strcat(dst, " "); - return 2; - } - - /* several choices starting with the same chars */ - if (completion_len > 0) { // strlen(completion_buf) > 0) { - if (completion_len + 1 > size) //strlen(completion_buf) > size) + /* one or several choices starting with the + same chars */ + if (completion_len > 0) { + if (completion_len + 1 > size) return 0; strcpy(dst, completion_buf); @@ -380,8 +383,9 @@ } for (i=0 ; i<n ; i++) { - if (token->ops->complete_get_elt(token, i, tmpbuf, sizeof(tmpbuf)) < 0) + if (token->ops->complete_get_elt(token, i, tmpbuf, sizeof(tmpbuf)-1) < 0) continue; + strcat(tmpbuf, " "); /* we have at least room for one char */ debug_printf(" choice <%s>\n", tmpbuf); /* does the completion match the beginning of the word ? */ if (!strncmp(incomplete_token, tmpbuf, incomplete_token_len)) { @@ -393,7 +397,7 @@ l=snprintf(dst, size, "%s", tmpbuf); if (l>=0 && token->ops->get_help) { token->ops->get_help(token, tmpbuf, sizeof(tmpbuf)); - snprintf(dst+l, size-l, " [%s]: %s", tmpbuf, inst->help_str?:"No help"); + snprintf(dst+l, size-l, "[%s]: %s", tmpbuf, inst->help_str?:"No help"); } return 1; ================================== aversive/modules/ihm/parse/parse.h (1.1.2.4 -> 1.1.2.5) ================================== @@ -7,6 +7,10 @@ #define offsetof(type, field) ((size_t) &( ((type *)0)->field) ) #endif +#define PARSE_AMBIGUOUS -1 +#define PARSE_NOMATCH -2 +#define PARSE_BAD_ARGS -3 + /** * A token is defined by this structure. *
_______________________________________________ Avr-list mailing list Avr-list@droids-corp.org CVSWEB : http://cvsweb.droids-corp.org/cgi-bin/viewcvs.cgi/aversive WIKI : http://wiki.droids-corp.org/index.php/Aversive DOXYGEN : http://zer0.droids-corp.org/doxygen_aversive/html/ BUGZILLA : http://bugzilla.droids-corp.org COMMIT LOGS : http://zer0.droids-corp.org/aversive_commitlog