From c60ed50ac1449a2b2bccc33598d1f68458a36fb1 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Fri, 24 Dec 2010 13:52:24 +0100 Subject: [PATCH] cmdline (merge-intel): fix whitespaces Signed-off-by: Olivier Matz --- src/lib/cmdline.c | 12 ++--- src/lib/cmdline_cirbuf.c | 32 ++++++------- src/lib/cmdline_cirbuf.h | 34 +++++++------- src/lib/cmdline_parse.c | 72 ++++++++++++++-------------- src/lib/cmdline_parse.h | 8 ++-- src/lib/cmdline_parse_etheraddr.c | 4 +- src/lib/cmdline_parse_ipaddr.c | 8 ++-- src/lib/cmdline_parse_ipaddr.h | 24 +++++----- src/lib/cmdline_parse_num.c | 24 +++++----- src/lib/cmdline_parse_num.h | 4 +- src/lib/cmdline_parse_string.c | 78 +++++++++++++++---------------- src/lib/cmdline_parse_string.h | 4 +- src/lib/cmdline_rdline.c | 66 +++++++++++++------------- src/lib/cmdline_rdline.h | 16 +++---- src/lib/cmdline_socket.c | 2 +- src/lib/cmdline_vt100.c | 6 +-- src/lib/cmdline_vt100.h | 2 +- 17 files changed, 197 insertions(+), 199 deletions(-) diff --git a/src/lib/cmdline.c b/src/lib/cmdline.c index 621ce37..bf225e8 100644 --- a/src/lib/cmdline.c +++ b/src/lib/cmdline.c @@ -48,8 +48,8 @@ /**********************/ -void -cmdline_valid_buffer(struct rdline *rdl, const char *buf, unsigned int size) +void +cmdline_valid_buffer(struct rdline *rdl, const char *buf, unsigned int size) { struct cmdline *cl = rdl->opaque; int ret; @@ -62,7 +62,7 @@ cmdline_valid_buffer(struct rdline *rdl, const char *buf, unsigned int size) cmdline_printf(cl, "Bad arguments\n"); } -int +int cmdline_complete_buffer(struct rdline *rdl, const char *buf, char *dstbuf, unsigned int dstsize, int *state) @@ -84,7 +84,7 @@ cmdline_write_char(struct rdline *rdl, char c) void cmdline_set_prompt(struct cmdline *cl, const char *prompt) { - snprintf(cl->prompt, sizeof(cl->prompt), prompt); + snprintf(cl->prompt, sizeof(cl->prompt), prompt); } struct cmdline * @@ -99,7 +99,7 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out) cl->s_out = s_out; cl->ctx = ctx; - rdline_init(&cl->rdl, cmdline_write_char, + rdline_init(&cl->rdl, cmdline_write_char, cmdline_valid_buffer, cmdline_complete_buffer); cl->rdl.opaque = cl; cmdline_set_prompt(cl, prompt); @@ -124,7 +124,7 @@ cmdline_printf(const struct cmdline *cl, const char *fmt, ...) { va_list ap; char buffer[BUFSIZ]; - + va_start(ap, fmt); vsnprintf(buffer, 512, fmt, ap); va_end(ap); diff --git a/src/lib/cmdline_cirbuf.c b/src/lib/cmdline_cirbuf.c index 8cd5374..f8ef1f0 100644 --- a/src/lib/cmdline_cirbuf.c +++ b/src/lib/cmdline_cirbuf.c @@ -31,7 +31,7 @@ #include "cmdline_cirbuf.h" -void +void cirbuf_init(struct cirbuf *cbuf, char *buf, unsigned int start, unsigned int maxlen) { cbuf->maxlen = maxlen; @@ -52,7 +52,7 @@ cirbuf_add_buf_head(struct cirbuf *cbuf, const char *c, unsigned int n) return -EINVAL; e = CIRBUF_IS_EMPTY(cbuf) ? 1 : 0; - + if (n < cbuf->start + e) { dprintf("s[%d] -> d[%d] (%d)\n", 0, cbuf->start - n + e, n); memcpy(cbuf->buf + cbuf->start - n + e, c, n); @@ -80,7 +80,7 @@ cirbuf_add_buf_tail(struct cirbuf *cbuf, const char *c, unsigned int n) return -EINVAL; e = CIRBUF_IS_EMPTY(cbuf) ? 1 : 0; - + if (n < cbuf->maxlen - cbuf->end - 1 + e) { dprintf("s[%d] -> d[%d] (%d)\n", 0, cbuf->end + !e, n); memcpy(cbuf->buf + cbuf->end + !e, c, n); @@ -99,7 +99,7 @@ cirbuf_add_buf_tail(struct cirbuf *cbuf, const char *c, unsigned int n) /* add at head */ -static inline void +static inline void __cirbuf_add_head(struct cirbuf * cbuf, char c) { if (!CIRBUF_IS_EMPTY(cbuf)) { @@ -110,11 +110,11 @@ __cirbuf_add_head(struct cirbuf * cbuf, char c) cbuf->len ++; } -int +int cirbuf_add_head_safe(struct cirbuf * cbuf, char c) { if (cbuf && !CIRBUF_IS_FULL(cbuf)) { - __cirbuf_add_head(cbuf, c); + __cirbuf_add_head(cbuf, c); return 0; } return -EINVAL; @@ -123,12 +123,12 @@ cirbuf_add_head_safe(struct cirbuf * cbuf, char c) void cirbuf_add_head(struct cirbuf * cbuf, char c) { - __cirbuf_add_head(cbuf, c); + __cirbuf_add_head(cbuf, c); } /* add at tail */ -static inline void +static inline void __cirbuf_add_tail(struct cirbuf * cbuf, char c) { if (!CIRBUF_IS_EMPTY(cbuf)) { @@ -139,11 +139,11 @@ __cirbuf_add_tail(struct cirbuf * cbuf, char c) cbuf->len ++; } -int +int cirbuf_add_tail_safe(struct cirbuf * cbuf, char c) { if (cbuf && !CIRBUF_IS_FULL(cbuf)) { - __cirbuf_add_tail(cbuf, c); + __cirbuf_add_tail(cbuf, c); return 0; } return -EINVAL; @@ -152,7 +152,7 @@ cirbuf_add_tail_safe(struct cirbuf * cbuf, char c) void cirbuf_add_tail(struct cirbuf * cbuf, char c) { - __cirbuf_add_tail(cbuf, c); + __cirbuf_add_tail(cbuf, c); } @@ -163,7 +163,7 @@ __cirbuf_shift_left(struct cirbuf *cbuf) char tmp = cbuf->buf[cbuf->start]; for (i=0 ; ilen ; i++) { - cbuf->buf[(cbuf->start+i)%cbuf->maxlen] = + cbuf->buf[(cbuf->start+i)%cbuf->maxlen] = cbuf->buf[(cbuf->start+i+1)%cbuf->maxlen]; } cbuf->buf[(cbuf->start-1+cbuf->maxlen)%cbuf->maxlen] = tmp; @@ -180,7 +180,7 @@ __cirbuf_shift_right(struct cirbuf *cbuf) char tmp = cbuf->buf[cbuf->end]; for (i=0 ; ilen ; i++) { - cbuf->buf[(cbuf->end+cbuf->maxlen-i)%cbuf->maxlen] = + cbuf->buf[(cbuf->end+cbuf->maxlen-i)%cbuf->maxlen] = cbuf->buf[(cbuf->end+cbuf->maxlen-i-1)%cbuf->maxlen]; } cbuf->buf[(cbuf->end+1)%cbuf->maxlen] = tmp; @@ -322,7 +322,7 @@ int cirbuf_get_buf_head(struct cirbuf *cbuf, char *c, unsigned int size) { unsigned int n = (size < CIRBUF_GET_LEN(cbuf)) ? size : CIRBUF_GET_LEN(cbuf); - + if (!n) return 0; @@ -365,7 +365,7 @@ cirbuf_get_buf_tail(struct cirbuf *cbuf, char *c, unsigned int size) /* get head or get tail */ -char +char cirbuf_get_head(struct cirbuf * cbuf) { return cbuf->buf[cbuf->start]; @@ -373,7 +373,7 @@ cirbuf_get_head(struct cirbuf * cbuf) /* get head or get tail */ -char +char cirbuf_get_tail(struct cirbuf * cbuf) { return cbuf->buf[cbuf->end]; diff --git a/src/lib/cmdline_cirbuf.h b/src/lib/cmdline_cirbuf.h index c68e248..1f976dd 100644 --- a/src/lib/cmdline_cirbuf.h +++ b/src/lib/cmdline_cirbuf.h @@ -77,7 +77,7 @@ void cirbuf_init(struct cirbuf *cbuf, char *buf, unsigned int start, unsigned in #define CIRBUF_GET_MAXLEN(cirbuf) ((cirbuf)->maxlen) /** - * return the number of free elts + * return the number of free elts */ #define CIRBUF_GET_FREELEN(cirbuf) ((cirbuf)->maxlen - (cirbuf)->len) @@ -93,49 +93,49 @@ void cirbuf_init(struct cirbuf *cbuf, char *buf, unsigned int start, unsigned in i ++, e=(c)->buf[((c)->start+i)%((c)->maxlen)]) -/** +/** * Add a character at head of the circular buffer. Return 0 on success, or * a negative value on error. */ int cirbuf_add_head_safe(struct cirbuf *cbuf, char c); -/** +/** * Add a character at head of the circular buffer. You _must_ check that you * have enough free space in the buffer before calling this func. */ void cirbuf_add_head(struct cirbuf *cbuf, char c); -/** +/** * Add a character at tail of the circular buffer. Return 0 on success, or * a negative value on error. */ int cirbuf_add_tail_safe(struct cirbuf *cbuf, char c); -/** +/** * Add a character at tail of the circular buffer. You _must_ check that you * have enough free space in the buffer before calling this func. */ void cirbuf_add_tail(struct cirbuf *cbuf, char c); -/** +/** * Remove a char at the head of the circular buffer. Return 0 on * success, or a negative value on error. */ int cirbuf_del_head_safe(struct cirbuf *cbuf); -/** +/** * Remove a char at the head of the circular buffer. You _must_ check * that buffer is not empty before calling the function. */ void cirbuf_del_head(struct cirbuf *cbuf); -/** +/** * Remove a char at the tail of the circular buffer. Return 0 on * success, or a negative value on error. */ int cirbuf_del_tail_safe(struct cirbuf *cbuf); -/** +/** * Remove a char at the tail of the circular buffer. You _must_ check * that buffer is not empty before calling the function. */ @@ -153,40 +153,40 @@ char cirbuf_get_head(struct cirbuf *cbuf); */ char cirbuf_get_tail(struct cirbuf *cbuf); -/** +/** * Add a buffer at head of the circular buffer. 'c' is a pointer to a * buffer, and n is the number of char to add. Return the number of * copied bytes on success, or a negative value on error. */ int cirbuf_add_buf_head(struct cirbuf *cbuf, const char *c, unsigned int n); -/** +/** * Add a buffer at tail of the circular buffer. 'c' is a pointer to a * buffer, and n is the number of char to add. Return the number of * copied bytes on success, or a negative value on error. */ int cirbuf_add_buf_tail(struct cirbuf *cbuf, const char *c, unsigned int n); -/** +/** * Remove chars at the head of the circular buffer. Return 0 on * success, or a negative value on error. */ int cirbuf_del_buf_head(struct cirbuf *cbuf, unsigned int size); -/** +/** * Remove chars at the tail of the circular buffer. Return 0 on * success, or a negative value on error. */ int cirbuf_del_buf_tail(struct cirbuf *cbuf, unsigned int size); -/** +/** * Copy a maximum of 'size' characters from the head of the circular * buffer to a flat one pointed by 'c'. Return the number of copied * chars. */ int cirbuf_get_buf_head(struct cirbuf *cbuf, char *c, unsigned int size); -/** +/** * Copy a maximum of 'size' characters from the tail of the circular * buffer to a flat one pointed by 'c'. Return the number of copied * chars. @@ -194,12 +194,12 @@ int cirbuf_get_buf_head(struct cirbuf *cbuf, char *c, unsigned int size); int cirbuf_get_buf_tail(struct cirbuf *cbuf, char *c, unsigned int size); -/** +/** * Set the start of the data to the index 0 of the internal buffer. */ void cirbuf_align_left(struct cirbuf *cbuf); -/** +/** * Set the end of the data to the last index of the internal buffer. */ void cirbuf_align_right(struct cirbuf *cbuf); diff --git a/src/lib/cmdline_parse.c b/src/lib/cmdline_parse.c index 85958d0..aec9e80 100644 --- a/src/lib/cmdline_parse.c +++ b/src/lib/cmdline_parse.c @@ -44,7 +44,7 @@ static int isblank2(char c) { - if (c == ' ' || + if (c == ' ' || c == '\t' ) return 1; return 0; @@ -53,7 +53,7 @@ isblank2(char c) static int isendofline(char c) { - if (c == '\n' || + if (c == '\n' || c == '\r' ) return 1; return 0; @@ -88,13 +88,13 @@ nb_common_chars(const char * s1, const char * s2) return i; } -/** +/** * try to match the buffer with an instruction (only the first * nb_match_token tokens if != 0). Return 0 if we match all the * tokens, else the number of matched tokens, else -1. */ static int -match_inst(cmdline_parse_inst_t *inst, const char *buf, unsigned int nb_match_token, +match_inst(cmdline_parse_inst_t *inst, const char *buf, unsigned int nb_match_token, void * result_buf) { unsigned int token_num=0; @@ -106,7 +106,7 @@ match_inst(cmdline_parse_inst_t *inst, const char *buf, unsigned int nb_match_to token_p = inst->tokens[token_num]; if (token_p) memcpy(&token_hdr, token_p, sizeof(token_hdr)); - + /* check if we match all tokens of inst */ while (token_p && (!nb_match_token || iparse(token_p, buf, (result_buf ? result_buf+token_hdr.offset : NULL)); if ( n < 0 ) break; debug_printf("TK parsed (len=%d)\n", n); i++; buf += n; - + token_num ++; token_p = inst->tokens[token_num]; if (token_p) memcpy(&token_hdr, token_p, sizeof(token_hdr)); } - + /* 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) { @@ -153,7 +153,7 @@ match_inst(cmdline_parse_inst_t *inst, const char *buf, unsigned int nb_match_to while (isblank2(*buf)) { buf++; } - + /* end of buf */ if ( isendofline(*buf) || iscomment(*buf) ) return 0; @@ -182,9 +182,9 @@ cmdline_parse(struct cmdline *cl, const char * buf) char debug_buf[BUFSIZ]; #endif - /* + /* * - look if the buffer contains at least one line - * - look if line contains only spaces or comments + * - look if line contains only spaces or comments * - count line length */ curbuf = buf; @@ -236,7 +236,7 @@ cmdline_parse(struct cmdline *cl, const char * buf) while (isblank2(*curbuf)) { curbuf++; } - + /* if end of buf -> there is no garbage after inst */ if (isendofline(*curbuf) || iscomment(*curbuf)) { if (!f) { @@ -252,11 +252,11 @@ cmdline_parse(struct cmdline *cl, const char * buf) } } } - + inst_num ++; inst = ctx[inst_num]; } - + /* call func */ if (f) { f(result_buf, cl, data); @@ -267,12 +267,12 @@ cmdline_parse(struct cmdline *cl, const char * buf) debug_printf("No match err=%d\n", err); return err; } - + return linelen; } -int -cmdline_complete(struct cmdline *cl, const char *buf, int *state, +int +cmdline_complete(struct cmdline *cl, const char *buf, int *state, char *dst, unsigned int size) { const char *incomplete_token = buf; @@ -309,22 +309,22 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, nb_completable = 0; nb_non_completable = 0; - + inst = ctx[inst_num]; 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 = inst->tokens[nb_token]; if (token_p) memcpy(&token_hdr, token_p, sizeof(token_hdr)); /* non completable */ - if (!token_p || - !token_hdr.ops->complete_get_nb || - !token_hdr.ops->complete_get_elt || + if (!token_p || + !token_hdr.ops->complete_get_nb || + !token_hdr.ops->complete_get_elt || (n = token_hdr.ops->complete_get_nb(token_p)) == 0) { nb_non_completable++; goto next; @@ -341,16 +341,16 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, if (completion_len == -1) { strcpy(completion_buf, tmpbuf+incomplete_token_len); completion_len = strlen(tmpbuf+incomplete_token_len); - + } else { - completion_len = nb_common_chars(completion_buf, + completion_len = nb_common_chars(completion_buf, tmpbuf+incomplete_token_len); completion_buf[completion_len] = 0; } nb_completable++; } - } + } next: inst_num ++; inst = ctx[inst_num]; @@ -361,15 +361,15 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, /* no possible completion */ if (nb_completable == 0 && nb_non_completable == 0) return 0; - + /* if multichoice is not required */ if (*state == 0 && incomplete_token_len > 0) { /* one or several choices starting with the same chars */ - if (completion_len > 0) { + if (completion_len > 0) { if (completion_len + 1 > size) return 0; - + strcpy(dst, completion_buf); return 2; } @@ -387,18 +387,18 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, while (inst) { /* we need to redo it */ inst = ctx[inst_num]; - + if (nb_token && match_inst(inst, buf, nb_token, NULL)) goto next2; - + token_p = inst->tokens[nb_token]; if (token_p) memcpy(&token_hdr, token_p, sizeof(token_hdr)); /* one choice for this token */ - if (!token_p || - !token_hdr.ops->complete_get_nb || - !token_hdr.ops->complete_get_elt || + if (!token_p || + !token_hdr.ops->complete_get_nb || + !token_hdr.ops->complete_get_elt || (n = token_hdr.ops->complete_get_nb(token_p)) == 0) { if (local_state < *state) { local_state++; @@ -441,7 +441,7 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, else snprintf(dst+l, size-l, "[%s]: No help", tmpbuf); } - + return 1; } } diff --git a/src/lib/cmdline_parse.h b/src/lib/cmdline_parse.h index 6b7fca9..8f79364 100644 --- a/src/lib/cmdline_parse.h +++ b/src/lib/cmdline_parse.h @@ -64,7 +64,7 @@ typedef struct cmdline_token_hdr cmdline_parse_token_hdr_t; * parsed chars on success and a negative value on error. * * complete_get_nb() returns the number of possible values for this - * token if completion is possible. If it is NULL or if it returns 0, + * token if completion is possible. If it is NULL or if it returns 0, * no completion is possible. * * complete_get_elt() copy in dstbuf (the size is specified in the @@ -83,7 +83,7 @@ struct cmdline_token_ops { int (*complete_get_elt)(cmdline_parse_token_hdr_t *, int, char *, unsigned int); /** get help for this token (token, dstbuf, size) */ int (*get_help)(cmdline_parse_token_hdr_t *, char *, unsigned int); -}; +}; struct cmdline; /** @@ -102,7 +102,7 @@ typedef struct cmdline_inst cmdline_parse_inst_t; /** * A context is identified by its name, and contains a list of - * instruction + * instruction * */ typedef cmdline_parse_inst_t *cmdline_parse_ctx_t; @@ -123,7 +123,7 @@ int cmdline_parse(struct cmdline *cl, const char *buf); * modifying *state until it returns CMDLINE_PARSE_COMPLETED_BUFFER or * CMDLINE_PARSE_COMPLETED_BUFFER. * - * It returns < 0 on error. + * It returns < 0 on error. * * Else it returns: * - CMDLINE_PARSE_COMPLETED_BUFFER on completion (one possible diff --git a/src/lib/cmdline_parse_etheraddr.c b/src/lib/cmdline_parse_etheraddr.c index 69df142..94ee7cc 100644 --- a/src/lib/cmdline_parse_etheraddr.c +++ b/src/lib/cmdline_parse_etheraddr.c @@ -50,7 +50,7 @@ struct cmdline_token_ops cmdline_token_etheraddr_ops = { #define ETHER_ADDRSTRLEN 18 -int +int cmdline_parse_etheraddr(cmdline_parse_token_hdr_t *tk, const char *buf, void *res) { unsigned int token_len = 0; @@ -63,7 +63,7 @@ cmdline_parse_etheraddr(cmdline_parse_token_hdr_t *tk, const char *buf, void *re while (!cmdline_isendoftoken(buf[token_len])) token_len++; - + /* if token is too big... */ if (token_len >= ETHER_ADDRSTRLEN) return -1; diff --git a/src/lib/cmdline_parse_ipaddr.c b/src/lib/cmdline_parse_ipaddr.c index 96b384d..24ed350 100644 --- a/src/lib/cmdline_parse_ipaddr.c +++ b/src/lib/cmdline_parse_ipaddr.c @@ -45,7 +45,7 @@ struct cmdline_token_ops cmdline_token_ipaddr_ops = { }; -int +int cmdline_parse_ipaddr(cmdline_parse_token_hdr_t *tk, const char *buf, void *res) { struct cmdline_token_ipaddr *tk2 = (struct cmdline_token_ipaddr *)tk; @@ -60,7 +60,7 @@ cmdline_parse_ipaddr(cmdline_parse_token_hdr_t *tk, const char *buf, void *res) while (!cmdline_isendoftoken(buf[token_len])) token_len++; - + /* if token is too big... */ if (token_len >= INET6_ADDRSTRLEN+4) return -1; @@ -81,7 +81,7 @@ cmdline_parse_ipaddr(cmdline_parse_token_hdr_t *tk, const char *buf, void *res) ipaddr->prefixlen = prefixlen; } else { - ipaddr->prefixlen = 0; + ipaddr->prefixlen = 0; } /* convert the IP addr */ @@ -96,7 +96,7 @@ cmdline_parse_ipaddr(cmdline_parse_token_hdr_t *tk, const char *buf, void *res) return token_len; } return -1; - + } int cmdline_get_help_ipaddr(cmdline_parse_token_hdr_t *tk, char *dstbuf, diff --git a/src/lib/cmdline_parse_ipaddr.h b/src/lib/cmdline_parse_ipaddr.h index 68576ab..937a818 100644 --- a/src/lib/cmdline_parse_ipaddr.h +++ b/src/lib/cmdline_parse_ipaddr.h @@ -68,8 +68,8 @@ int cmdline_get_help_ipaddr(cmdline_parse_token_hdr_t *tk, char *dstbuf, .offset = offsetof(structure, field), \ }, \ .ipaddr_data = { \ - .flags = CMDLINE_IPADDR_V4 | \ - CMDLINE_IPADDR_V6, \ + .flags = CMDLINE_IPADDR_V4 | \ + CMDLINE_IPADDR_V6, \ }, \ } @@ -80,7 +80,7 @@ int cmdline_get_help_ipaddr(cmdline_parse_token_hdr_t *tk, char *dstbuf, .offset = offsetof(structure, field), \ }, \ .ipaddr_data = { \ - .flags = CMDLINE_IPADDR_V4, \ + .flags = CMDLINE_IPADDR_V4, \ }, \ } @@ -91,7 +91,7 @@ int cmdline_get_help_ipaddr(cmdline_parse_token_hdr_t *tk, char *dstbuf, .offset = offsetof(structure, field), \ }, \ .ipaddr_data = { \ - .flags = CMDLINE_IPADDR_V6, \ + .flags = CMDLINE_IPADDR_V6, \ }, \ } @@ -102,9 +102,9 @@ int cmdline_get_help_ipaddr(cmdline_parse_token_hdr_t *tk, char *dstbuf, .offset = offsetof(structure, field), \ }, \ .ipaddr_data = { \ - .flags = CMDLINE_IPADDR_V4 | \ - CMDLINE_IPADDR_V6 | \ - CMDLINE_IPADDR_NETWORK, \ + .flags = CMDLINE_IPADDR_V4 | \ + CMDLINE_IPADDR_V6 | \ + CMDLINE_IPADDR_NETWORK, \ }, \ } @@ -115,8 +115,8 @@ int cmdline_get_help_ipaddr(cmdline_parse_token_hdr_t *tk, char *dstbuf, .offset = offsetof(structure, field), \ }, \ .ipaddr_data = { \ - .flags = CMDLINE_IPADDR_V4 | \ - CMDLINE_IPADDR_NETWORK, \ + .flags = CMDLINE_IPADDR_V4 | \ + CMDLINE_IPADDR_NETWORK, \ }, \ } @@ -127,11 +127,9 @@ int cmdline_get_help_ipaddr(cmdline_parse_token_hdr_t *tk, char *dstbuf, .offset = offsetof(structure, field), \ }, \ .ipaddr_data = { \ - .flags = CMDLINE_IPADDR_V4 | \ - CMDLINE_IPADDR_NETWORK, \ + .flags = CMDLINE_IPADDR_V4 | \ + CMDLINE_IPADDR_NETWORK, \ }, \ } - - #endif /* _PARSE_IPADDR_H_ */ diff --git a/src/lib/cmdline_parse_num.c b/src/lib/cmdline_parse_num.c index 6a37a76..71075b4 100644 --- a/src/lib/cmdline_parse_num.c +++ b/src/lib/cmdline_parse_num.c @@ -89,7 +89,7 @@ static const char * num_help[] = { #endif }; -static inline int +static inline int add_to_res(unsigned int c, unsigned int *res, unsigned int base) { /* overflow */ @@ -103,7 +103,7 @@ add_to_res(unsigned int c, unsigned int *res, unsigned int base) /* parse an int or a float */ -int +int cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) { struct cmdline_token_num_data nd; @@ -159,7 +159,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) st = ERROR; else st = OCTAL_OK; - } + } else { st = ERROR; } @@ -246,7 +246,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) break; case BIN: - st = BIN_OK; + st = BIN_OK; /* no break */ case BIN_OK: if (c >= '0' && c <= '1') { @@ -263,7 +263,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) if (c >= '0' && c <= '9') { if (add_to_res(c - '0', &res2, 10) < 0) st = ERROR; - else + else st = FLOAT_POS_OK; res3 = 10; } @@ -276,7 +276,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) if (c >= '0' && c <= '9') { if (add_to_res(c - '0', &res2, 10) < 0) st = ERROR; - else + else st = FLOAT_NEG_OK; res3 = 10; } @@ -312,7 +312,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) default: debug_printf("not impl "); - + } /* XXX uint32_t et %d */ @@ -325,7 +325,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) if (buf-srcbuf > 127) return -1; } - + switch (st) { case ZERO_OK: case DEC_POS_OK: @@ -409,7 +409,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) if (res) *(float *)res = (float)res1 + ((float)res2 / (float)res3); return (buf-srcbuf); - + } else { return -1; @@ -422,7 +422,7 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) if (res) *(float *)res = - ((float)res1 + ((float)res2 / (float)res3)); return (buf-srcbuf); - + } else { return -1; @@ -438,13 +438,13 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) /* parse an int or a float */ -int +int cmdline_get_help_num(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size) { struct cmdline_token_num_data nd; 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; */ diff --git a/src/lib/cmdline_parse_num.h b/src/lib/cmdline_parse_num.h index b149c92..cf4b4a5 100644 --- a/src/lib/cmdline_parse_num.h +++ b/src/lib/cmdline_parse_num.h @@ -54,9 +54,9 @@ typedef struct cmdline_token_num cmdline_parse_token_num_t; extern struct cmdline_token_ops cmdline_token_num_ops; -int cmdline_parse_num(cmdline_parse_token_hdr_t *tk, +int cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res); -int cmdline_get_help_num(cmdline_parse_token_hdr_t *tk, +int cmdline_get_help_num(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size); #define TOKEN_NUM_INITIALIZER(structure, field, numtype) \ diff --git a/src/lib/cmdline_parse_string.c b/src/lib/cmdline_parse_string.c index eb4553b..7ac2892 100644 --- a/src/lib/cmdline_parse_string.c +++ b/src/lib/cmdline_parse_string.c @@ -47,15 +47,15 @@ struct cmdline_token_ops cmdline_token_string_ops = { static unsigned int get_token_len(const char *s) { - char c; + char c; unsigned int i=0; c = s[i]; - while (c!='#' && c!='\0') { - i++; + while (c!='#' && c!='\0') { + i++; c = s[i]; } - return i; + return i; } static const char * @@ -68,7 +68,7 @@ get_next_token(const char *s) return NULL; } -int +int cmdline_parse_string(cmdline_parse_token_hdr_t *tk, const char *buf, void *res) { struct cmdline_token_string *tk2 = (struct cmdline_token_string *)tk; @@ -79,51 +79,51 @@ cmdline_parse_string(cmdline_parse_token_hdr_t *tk, const char *buf, void *res) if (! *buf) return -1; - /* fixed string */ - if (sd->str) { + /* fixed string */ + if (sd->str) { str = sd->str; - do { - token_len = get_token_len(str); - - /* if token is too big... */ - if (token_len >= STR_TOKEN_SIZE - 1) { + do { + token_len = get_token_len(str); + + /* if token is too big... */ + if (token_len >= STR_TOKEN_SIZE - 1) { continue; - } - - if ( strncmp(buf, str, token_len) ) { + } + + if ( strncmp(buf, str, token_len) ) { continue; - } - - if ( !cmdline_isendoftoken(*(buf+token_len)) ) { + } + + if ( !cmdline_isendoftoken(*(buf+token_len)) ) { continue; - } + } - break; - } while ( (str = get_next_token(str)) != NULL ); + break; + } while ( (str = get_next_token(str)) != NULL ); if (!str) return -1; - } - /* unspecified string */ - else { - token_len=0; - while(!cmdline_isendoftoken(buf[token_len]) && - token_len < (STR_TOKEN_SIZE-1)) - token_len++; - - /* return if token too long */ - if (token_len >= STR_TOKEN_SIZE - 1) { - return -1; - } - } - + } + /* unspecified string */ + else { + token_len=0; + while(!cmdline_isendoftoken(buf[token_len]) && + token_len < (STR_TOKEN_SIZE-1)) + token_len++; + + /* return if token too long */ + if (token_len >= STR_TOKEN_SIZE - 1) { + return -1; + } + } + if (res) { /* we are sure that token_len is < STR_TOKEN_SIZE-1 */ strncpy(res, buf, token_len); *((char *)res + token_len) = 0; } - return token_len; + return token_len; } int cmdline_complete_get_nb_string(cmdline_parse_token_hdr_t *tk) @@ -143,7 +143,7 @@ int cmdline_complete_get_nb_string(cmdline_parse_token_hdr_t *tk) return ret; } -int cmdline_complete_get_elt_string(cmdline_parse_token_hdr_t *tk, int idx, +int cmdline_complete_get_elt_string(cmdline_parse_token_hdr_t *tk, int idx, char *dstbuf, unsigned int size) { struct cmdline_token_string *tk2 = (struct cmdline_token_string *)tk; @@ -175,7 +175,7 @@ int cmdline_get_help_string(cmdline_parse_token_hdr_t *tk, char *dstbuf, struct cmdline_token_string *tk2 = (struct cmdline_token_string *)tk; struct cmdline_token_string_data *sd = &tk2->string_data;; const char *s; - + s = sd->str; if (s) { @@ -189,7 +189,7 @@ int cmdline_get_help_string(cmdline_parse_token_hdr_t *tk, char *dstbuf, else { strncpy(dstbuf, ANYSTRING_HELP, size); } - + dstbuf[size-1] = '\0'; return 0; diff --git a/src/lib/cmdline_parse_string.h b/src/lib/cmdline_parse_string.h index de34ba6..a512e51 100644 --- a/src/lib/cmdline_parse_string.h +++ b/src/lib/cmdline_parse_string.h @@ -50,7 +50,7 @@ extern struct cmdline_token_ops cmdline_token_string_ops; int cmdline_parse_string(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res); int cmdline_complete_get_nb_string(cmdline_parse_token_hdr_t *tk); -int cmdline_complete_get_elt_string(cmdline_parse_token_hdr_t *tk, int idx, +int cmdline_complete_get_elt_string(cmdline_parse_token_hdr_t *tk, int idx, char *dstbuf, unsigned int size); int cmdline_get_help_string(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size); @@ -62,7 +62,7 @@ int cmdline_get_help_string(cmdline_parse_token_hdr_t *tk, char *dstbuf, .offset = offsetof(structure, field), \ }, \ .string_data = { \ - .str = string, \ + .str = string, \ }, \ } diff --git a/src/lib/cmdline_rdline.c b/src/lib/cmdline_rdline.c index 287c7d8..8e4b2a5 100644 --- a/src/lib/cmdline_rdline.c +++ b/src/lib/cmdline_rdline.c @@ -36,7 +36,7 @@ #include "cmdline_rdline.h" static void rdline_puts(struct rdline *rdl, const char *buf); -static void rdline_miniprintf(struct rdline *rdl, +static void rdline_miniprintf(struct rdline *rdl, const char *buf, unsigned int val); #ifndef NO_RDLINE_HISTORY @@ -51,13 +51,13 @@ static unsigned int rdline_get_history_size(struct rdline *rdl); static int isblank2(char c) { - if (c == ' ' || + if (c == ' ' || c == '\t' ) return 1; return 0; } -void rdline_init(struct rdline *rdl, +void rdline_init(struct rdline *rdl, rdline_write_char_t *write_char, rdline_validate_t *validate, rdline_complete_t *complete) @@ -89,12 +89,12 @@ rdline_newline(struct rdline *rdl, const char *prompt) rdl->write_char(rdl, rdl->prompt[i]); rdl->status = RDLINE_RUNNING; -#ifndef NO_RDLINE_HISTORY +#ifndef NO_RDLINE_HISTORY rdl->history_cur_line = -1; #endif /* !NO_RDLINE_HISTORY */ } -void +void rdline_stop(struct rdline *rdl) { rdl->status = RDLINE_INIT; @@ -133,7 +133,7 @@ display_right_buffer(struct rdline *rdl) CIRBUF_FOREACH(&rdl->right, i, tmp) { rdl->write_char(rdl, tmp); } - rdline_miniprintf(rdl, vt100_multi_left, + rdline_miniprintf(rdl, vt100_multi_left, CIRBUF_GET_LEN(&rdl->right)); } } @@ -161,7 +161,7 @@ rdline_char_in(struct rdline *rdl, char c) #ifndef NO_RDLINE_HISTORY char *buf; #endif - + if (rdl->status != RDLINE_RUNNING) return -1; @@ -192,37 +192,37 @@ rdline_char_in(struct rdline *rdl, char c) break; case CMDLINE_KEY_WLEFT: - while (! CIRBUF_IS_EMPTY(&rdl->left) && - (tmp = cirbuf_get_tail(&rdl->left)) && + while (! CIRBUF_IS_EMPTY(&rdl->left) && + (tmp = cirbuf_get_tail(&rdl->left)) && isblank2(tmp)) { rdline_puts(rdl, vt100_left_arr); cirbuf_del_tail(&rdl->left); cirbuf_add_head(&rdl->right, tmp); } - while (! CIRBUF_IS_EMPTY(&rdl->left) && - (tmp = cirbuf_get_tail(&rdl->left)) && + while (! CIRBUF_IS_EMPTY(&rdl->left) && + (tmp = cirbuf_get_tail(&rdl->left)) && !isblank2(tmp)) { rdline_puts(rdl, vt100_left_arr); cirbuf_del_tail(&rdl->left); cirbuf_add_head(&rdl->right, tmp); - } + } break; case CMDLINE_KEY_WRIGHT: - while (! CIRBUF_IS_EMPTY(&rdl->right) && - (tmp = cirbuf_get_head(&rdl->right)) && + while (! CIRBUF_IS_EMPTY(&rdl->right) && + (tmp = cirbuf_get_head(&rdl->right)) && isblank2(tmp)) { rdline_puts(rdl, vt100_right_arr); cirbuf_del_head(&rdl->right); cirbuf_add_tail(&rdl->left, tmp); } - while (! CIRBUF_IS_EMPTY(&rdl->right) && - (tmp = cirbuf_get_head(&rdl->right)) && + while (! CIRBUF_IS_EMPTY(&rdl->right) && + (tmp = cirbuf_get_head(&rdl->right)) && !isblank2(tmp)) { rdline_puts(rdl, vt100_right_arr); cirbuf_del_head(&rdl->right); cirbuf_add_tail(&rdl->left, tmp); - } + } break; case CMDLINE_KEY_BKSPACE: @@ -246,7 +246,7 @@ rdline_char_in(struct rdline *rdl, char c) case CMDLINE_KEY_SUPPR: case CMDLINE_KEY_CTRL_D: - if (cmd == CMDLINE_KEY_CTRL_D && + if (cmd == CMDLINE_KEY_CTRL_D && CIRBUF_IS_EMPTY(&rdl->left) && CIRBUF_IS_EMPTY(&rdl->right)) { return -2; @@ -259,7 +259,7 @@ rdline_char_in(struct rdline *rdl, char c) case CMDLINE_KEY_CTRL_A: if (CIRBUF_IS_EMPTY(&rdl->left)) break; - rdline_miniprintf(rdl, vt100_multi_left, + rdline_miniprintf(rdl, vt100_multi_left, CIRBUF_GET_LEN(&rdl->left)); while (! CIRBUF_IS_EMPTY(&rdl->left)) { tmp = cirbuf_get_tail(&rdl->left); @@ -271,7 +271,7 @@ rdline_char_in(struct rdline *rdl, char c) case CMDLINE_KEY_CTRL_E: if (CIRBUF_IS_EMPTY(&rdl->right)) break; - rdline_miniprintf(rdl, vt100_multi_right, + rdline_miniprintf(rdl, vt100_multi_right, CIRBUF_GET_LEN(&rdl->right)); while (! CIRBUF_IS_EMPTY(&rdl->right)) { tmp = cirbuf_get_head(&rdl->right); @@ -291,7 +291,7 @@ rdline_char_in(struct rdline *rdl, char c) case CMDLINE_KEY_CTRL_Y: i=0; while(CIRBUF_GET_LEN(&rdl->right) + CIRBUF_GET_LEN(&rdl->left) < - RDLINE_BUF_SIZE && + RDLINE_BUF_SIZE && i < rdl->kill_size) { cirbuf_add_tail(&rdl->left, rdl->kill_buf[i]); rdl->write_char(rdl, rdl->kill_buf[i]); @@ -313,7 +313,7 @@ rdline_char_in(struct rdline *rdl, char c) case CMDLINE_KEY_TAB: case CMDLINE_KEY_HELP: cirbuf_align_left(&rdl->left); - rdl->left_buf[CIRBUF_GET_LEN(&rdl->left)] = '\0'; + rdl->left_buf[CIRBUF_GET_LEN(&rdl->left)] = '\0'; if (rdl->complete) { char tmp_buf[BUFSIZ]; int complete_state; @@ -339,7 +339,7 @@ rdline_char_in(struct rdline *rdl, char c) if (ret == 2) { i=0; while(CIRBUF_GET_LEN(&rdl->right) + CIRBUF_GET_LEN(&rdl->left) < - RDLINE_BUF_SIZE && + RDLINE_BUF_SIZE && i < tmp_size) { cirbuf_add_tail(&rdl->left, tmp_buf[i]); rdl->write_char(rdl, tmp_buf[i]); @@ -378,7 +378,7 @@ rdline_char_in(struct rdline *rdl, char c) if (rdl->validate) rdl->validate(rdl, rdl->left_buf, CIRBUF_GET_LEN(&rdl->left)+2); return 1; - + #ifndef NO_RDLINE_HISTORY case CMDLINE_KEY_UP_ARR: if (rdl->history_cur_line == 0) { @@ -388,11 +388,11 @@ rdline_char_in(struct rdline *rdl, char c) rdline_add_history(rdl, rdline_get_buffer(rdl)); rdl->history_cur_line = 0; } - + buf = rdline_get_history_item(rdl, rdl->history_cur_line + 1); if (!buf) break; - + rdl->history_cur_line ++; vt100_init(&rdl->vt100); cirbuf_init(&rdl->left, rdl->left_buf, 0, RDLINE_BUF_SIZE); @@ -404,7 +404,7 @@ rdline_char_in(struct rdline *rdl, char c) case CMDLINE_KEY_DOWN_ARR: if (rdl->history_cur_line - 1 < 0) break; - + rdl->history_cur_line --; buf = rdline_get_history_item(rdl, rdl->history_cur_line); if (!buf) @@ -425,14 +425,14 @@ rdline_char_in(struct rdline *rdl, char c) return 0; } - + if (! isprint(c)) return 0; /* standard chars */ if (CIRBUF_GET_LEN(&rdl->left) + CIRBUF_GET_LEN(&rdl->right) >= RDLINE_BUF_SIZE) return 0; - + if (cirbuf_add_tail_safe(&rdl->left, c)) return 0; @@ -515,7 +515,7 @@ rdline_get_history_item(struct rdline * rdl, unsigned int idx) return NULL; } -int +int rdline_add_history(struct rdline * rdl, const char * buf) { unsigned int len, i; @@ -537,7 +537,7 @@ rdline_add_history(struct rdline * rdl, const char * buf) cirbuf_add_buf_tail(&rdl->history, buf, len); cirbuf_add_tail(&rdl->history, 0); - + return 0; } @@ -559,7 +559,7 @@ char * rdline_get_history_item(struct rdline * rdl, unsigned int i) {return NULL /* STATIC USEFUL FUNCS */ -static void +static void rdline_puts(struct rdline * rdl, const char * buf) { char c; @@ -569,7 +569,7 @@ rdline_puts(struct rdline * rdl, const char * buf) } /* a very very basic printf with one arg and one format 'u' */ -static void +static void rdline_miniprintf(struct rdline *rdl, const char * buf, unsigned int val) { char c, started=0, div=100; diff --git a/src/lib/cmdline_rdline.h b/src/lib/cmdline_rdline.h index f8437a5..20f7652 100644 --- a/src/lib/cmdline_rdline.h +++ b/src/lib/cmdline_rdline.h @@ -34,7 +34,7 @@ * microcontrollers (8 bits). Indeed, we don't use any malloc that is * sometimes not implemented (or just not recommended) on such * systems. - * + * * Obviously, it does not support as many things as the GNU readline, * but at least it supports some interresting features like a kill * buffer and a command history. @@ -44,11 +44,11 @@ * time, even on a monothread program, since it works with callbacks. * * The lib is designed for a client-side or a server-side use: - * - server-side: the server receives all data from a socket, including - * control chars, like arrows, tabulations, ... The client is + * - server-side: the server receives all data from a socket, including + * control chars, like arrows, tabulations, ... The client is * very simple, it can be a telnet or a minicom through a serial line. * - client-side: the client receives its data through its stdin for - * instance. + * instance. */ #include @@ -137,12 +137,12 @@ struct rdline { * of your program. * \param rdl A pointer to an uninitialized struct rdline * \param write_char The function used by the function to write a character - * \param validate A pointer to the function to execute when the + * \param validate A pointer to the function to execute when the * user validates the buffer. - * \param complete A pointer to the function to execute when the + * \param complete A pointer to the function to execute when the * user completes the buffer. */ -void rdline_init(struct rdline *rdl, +void rdline_init(struct rdline *rdl, rdline_write_char_t *write_char, rdline_validate_t *validate, rdline_complete_t *complete); @@ -175,7 +175,7 @@ void rdline_redisplay(struct rdline *rdl); /** - * append a char to the readline buffer. + * append a char to the readline buffer. * Return 1 when the line has been validated. * Return 2 when the user asked to complete the buffer. * Return -1 if it is not running. diff --git a/src/lib/cmdline_socket.c b/src/lib/cmdline_socket.c index 78a8b31..a017874 100644 --- a/src/lib/cmdline_socket.c +++ b/src/lib/cmdline_socket.c @@ -136,7 +136,7 @@ cmdline_unix_listen(char *filename) bzero(&servAddr, sizeof(servAddr)); servAddr.sun_family = AF_UNIX; memcpy(servAddr.sun_path, filename , strlen(filename)); - + unlink(filename); if(bind(s, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) { dprintf("bind() failed\n"); diff --git a/src/lib/cmdline_vt100.c b/src/lib/cmdline_vt100.c index 1245cd0..59ab1f4 100644 --- a/src/lib/cmdline_vt100.c +++ b/src/lib/cmdline_vt100.c @@ -71,7 +71,7 @@ match_command(char *buf, unsigned int size) { const char *cmd; unsigned int i = 0; - + for (i=0 ; ibufpos = 0; break; } return -2; - + match_command: return match_command(vt->buf, size); } diff --git a/src/lib/cmdline_vt100.h b/src/lib/cmdline_vt100.h index 968d70e..0faab26 100644 --- a/src/lib/cmdline_vt100.h +++ b/src/lib/cmdline_vt100.h @@ -97,7 +97,7 @@ struct cmdline_vt100 { void vt100_init(struct cmdline_vt100 *vt); /** - * Input a new character. + * Input a new character. * Return -1 if the character is not part of a control sequence * Return -2 if c is not the last char of a control sequence * Else return the index in vt100_commands[] -- 2.20.1