From: Olivier Matz Date: Fri, 24 Dec 2010 12:53:16 +0000 (+0100) Subject: cmdline (merge-intel): cmdline: disable float parsing X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e963f1233ab27f2568fa34714b834deb836f724a;p=libcmdline.git cmdline (merge-intel): cmdline: disable float parsing Signed-off-by: Olivier Matz --- diff --git a/Makefile b/Makefile index 29d4861..450ab25 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,8 @@ SUBDIRS += genconf # really small devices, because it changes the API. # CFLAGS += -DNO_RDLINE_HISTORY # CFLAGS += -DNO_RDLINE_KILL_BUF -# CFLAGS += -DNO_PARSE_FLOAT +# CFLAGS += -DCMDLINE_HAVE_FLOAT +CFLAGS += -DCMDLINE_HAVE_SOCKET CFLAGS += -Wall -Werror CFLAGS += -O0 -g diff --git a/src/lib/cmdline_parse_num.c b/src/lib/cmdline_parse_num.c index 71075b4..90c9402 100644 --- a/src/lib/cmdline_parse_num.c +++ b/src/lib/cmdline_parse_num.c @@ -84,7 +84,7 @@ enum num_parse_state_t { static const char * num_help[] = { "UINT8", "UINT16", "UINT32", "INT8", "INT16", "INT32", -#ifndef NO_PARSE_FLOAT +#ifndef CMDLINE_NO_FLOAT "FLOAT", #endif }; @@ -110,7 +110,10 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) enum num_parse_state_t st = START; const char * buf = srcbuf; char c = *buf; - uint32_t res1=0, res2=0, res3=1; + uint32_t res1 = 0; +#ifndef CMDLINE_NO_FLOAT + uint32_t res2 = 0, res3 = 1; +#endif memcpy(&nd, &((struct cmdline_token_num *)tk)->num_data, sizeof(nd)); @@ -124,7 +127,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) else if (c == '0') { st = ZERO_OK; } -#ifndef NO_PARSE_FLOAT +#ifndef CMDLINE_NO_FLOAT else if (c == '.') { st = FLOAT_POS; res1 = 0; @@ -148,7 +151,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) else if (c == 'b') { st = BIN; } -#ifndef NO_PARSE_FLOAT +#ifndef CMDLINE_NO_FLOAT else if (c == '.') { st = FLOAT_POS; res1 = 0; @@ -172,7 +175,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) else st = DEC_NEG_OK; } -#ifndef NO_PARSE_FLOAT +#ifndef CMDLINE_NO_FLOAT else if (c == '.') { res1 = 0; st = FLOAT_NEG; @@ -188,7 +191,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) if (add_to_res(c - '0', &res1, 10) < 0) st = ERROR; } -#ifndef NO_PARSE_FLOAT +#ifndef CMDLINE_NO_FLOAT else if (c == '.') { st = FLOAT_NEG; } @@ -203,7 +206,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) if (add_to_res(c - '0', &res1, 10) < 0) st = ERROR; } -#ifndef NO_PARSE_FLOAT +#ifndef CMDLINE_NO_FLOAT else if (c == '.') { st = FLOAT_POS; } @@ -258,7 +261,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) } break; -#ifndef NO_PARSE_FLOAT +#ifndef CMDLINE_NO_FLOAT case FLOAT_POS: if (c >= '0' && c <= '9') { if (add_to_res(c - '0', &res2, 10) < 0) @@ -315,8 +318,12 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) } - /* XXX uint32_t et %d */ - debug_printf("(%d) (%d) (%d)\n", res1, res2, res3); +#ifdef CMDLINE_NO_FLOAT + debug_printf("(%"PRIu32")\n", res1); +#else + debug_printf("(%"PRIu32") (%"PRIu32") (%"PRIu32")\n", + res1, res2, res3); +#endif buf ++; c = *buf; @@ -362,7 +369,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) *(uint32_t *)res = (uint32_t) res1; return (buf-srcbuf); } -#ifndef NO_PARSE_FLOAT +#ifndef CMDLINE_NO_FLOAT else if ( nd.type == FLOAT ) { if (res) *(float *)res = (float)res1; @@ -390,7 +397,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) *(int32_t *)res = - (int32_t) res1; return (buf-srcbuf); } -#ifndef NO_PARSE_FLOAT +#ifndef CMDLINE_NO_FLOAT else if ( nd.type == FLOAT ) { if (res) *(float *)res = - (float)res1; @@ -402,7 +409,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) } break; -#ifndef NO_PARSE_FLOAT +#ifndef CMDLINE_NO_FLOAT case FLOAT_POS: case FLOAT_POS_OK: if ( nd.type == FLOAT ) { @@ -446,8 +453,8 @@ cmdline_get_help_num(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int s memcpy(&nd, &((struct cmdline_token_num *)tk)->num_data, sizeof(nd)); /* should not happen.... don't so this test */ -/* if (nd.type >= (sizeof(num_help)/sizeof(const char *))) */ -/* return -1; */ + /* if (nd.type >= (sizeof(num_help)/sizeof(const char *))) */ + /* return -1; */ strncpy(dstbuf, num_help[nd.type], size); dstbuf[size-1] = '\0';