From: Olivier Matz Date: Fri, 24 Dec 2010 12:54:37 +0000 (+0100) Subject: cmdline (merge-intel): cosmetic fixes, conform to coding rules X-Git-Url: http://git.droids-corp.org/?p=libcmdline.git;a=commitdiff_plain;h=62115fff94ec9f1d023a3b713f178980f6bb5691 cmdline (merge-intel): cosmetic fixes, conform to coding rules Signed-off-by: Olivier Matz --- diff --git a/src/lib/cmdline_cirbuf.c b/src/lib/cmdline_cirbuf.c index 133b32e..4046947 100644 --- a/src/lib/cmdline_cirbuf.c +++ b/src/lib/cmdline_cirbuf.c @@ -92,10 +92,13 @@ cirbuf_add_buf_head(struct cirbuf *cbuf, const char *c, unsigned int n) memcpy(cbuf->buf + cbuf->start - n + e, c, n); } else { - dprintf("s[%d] -> d[%d] (%d)\n", + n - (cbuf->start + e), 0, cbuf->start + e); - dprintf("s[%d] -> d[%d] (%d)\n", cbuf->maxlen - n + (cbuf->start + e), 0, n - (cbuf->start + e)); + dprintf("s[%d] -> d[%d] (%d)\n", + n - (cbuf->start + e), 0, + cbuf->start + e); + dprintf("s[%d] -> d[%d] (%d)\n", cbuf->maxlen - n + + (cbuf->start + e), 0, n - (cbuf->start + e)); memcpy(cbuf->buf, c + n - (cbuf->start + e) , cbuf->start + e); - memcpy(cbuf->buf + cbuf->maxlen - n + (cbuf->start + e), c, n - (cbuf->start + e)); + memcpy(cbuf->buf + cbuf->maxlen - n + (cbuf->start + e), c, + n - (cbuf->start + e)); } cbuf->len += n; cbuf->start += (cbuf->maxlen - n + e); @@ -120,10 +123,14 @@ cirbuf_add_buf_tail(struct cirbuf *cbuf, const char *c, unsigned int n) memcpy(cbuf->buf + cbuf->end + !e, c, n); } else { - dprintf("s[%d] -> d[%d] (%d)\n", cbuf->end + !e, 0, cbuf->maxlen - cbuf->end - 1 + e); - dprintf("s[%d] -> d[%d] (%d)\n", cbuf->maxlen - cbuf->end - 1 + e, 0, n - cbuf->maxlen + cbuf->end + 1 - e); - memcpy(cbuf->buf + cbuf->end + !e, c, cbuf->maxlen - cbuf->end - 1 + e); - memcpy(cbuf->buf, c + cbuf->maxlen - cbuf->end - 1 + e, n - cbuf->maxlen + cbuf->end + 1 - e); + dprintf("s[%d] -> d[%d] (%d)\n", cbuf->end + !e, 0, + cbuf->maxlen - cbuf->end - 1 + e); + dprintf("s[%d] -> d[%d] (%d)\n", cbuf->maxlen - cbuf->end - 1 + + e, 0, n - cbuf->maxlen + cbuf->end + 1 - e); + memcpy(cbuf->buf + cbuf->end + !e, c, cbuf->maxlen - + cbuf->end - 1 + e); + memcpy(cbuf->buf, c + cbuf->maxlen - cbuf->end - 1 + e, + n - cbuf->maxlen + cbuf->end + 1 - e); } cbuf->len += n; cbuf->end += n - e; @@ -355,7 +362,9 @@ cirbuf_del_tail(struct cirbuf * cbuf) 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); + unsigned int n; + + n = (size < CIRBUF_GET_LEN(cbuf)) ? size : CIRBUF_GET_LEN(cbuf); if (!n) return 0; @@ -365,10 +374,13 @@ cirbuf_get_buf_head(struct cirbuf *cbuf, char *c, unsigned int size) memcpy(c, cbuf->buf + cbuf->start , n); } else { - dprintf("s[%d] -> d[%d] (%d)\n", cbuf->start, 0, cbuf->maxlen - cbuf->start); - dprintf("s[%d] -> d[%d] (%d)\n", 0, cbuf->maxlen - cbuf->start, n - cbuf->maxlen + cbuf->start); + dprintf("s[%d] -> d[%d] (%d)\n", cbuf->start, 0, + cbuf->maxlen - cbuf->start); + dprintf("s[%d] -> d[%d] (%d)\n", 0,cbuf->maxlen - cbuf->start, + n - cbuf->maxlen + cbuf->start); memcpy(c, cbuf->buf + cbuf->start , cbuf->maxlen - cbuf->start); - memcpy(c + cbuf->maxlen - cbuf->start, cbuf->buf, n - cbuf->maxlen + cbuf->start); + memcpy(c + cbuf->maxlen - cbuf->start, cbuf->buf, + n - cbuf->maxlen + cbuf->start); } return n; } @@ -378,7 +390,9 @@ 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) { - unsigned int n = (size < CIRBUF_GET_LEN(cbuf)) ? size : CIRBUF_GET_LEN(cbuf); + unsigned int n; + + n = (size < CIRBUF_GET_LEN(cbuf)) ? size : CIRBUF_GET_LEN(cbuf); if (!n) return 0; @@ -388,11 +402,15 @@ cirbuf_get_buf_tail(struct cirbuf *cbuf, char *c, unsigned int size) memcpy(c, cbuf->buf + cbuf->end - n + 1, n); } else { - dprintf("s[%d] -> d[%d] (%d)\n", 0, cbuf->maxlen - cbuf->start, cbuf->end + 1); - dprintf("s[%d] -> d[%d] (%d)\n", cbuf->maxlen - n + cbuf->end + 1, 0, n - cbuf->end - 1); - - memcpy(c + cbuf->maxlen - cbuf->start, cbuf->buf, cbuf->end + 1); - memcpy(c, cbuf->buf + cbuf->maxlen - n + cbuf->end +1, n - cbuf->end - 1); + dprintf("s[%d] -> d[%d] (%d)\n", 0, + cbuf->maxlen - cbuf->start, cbuf->end + 1); + dprintf("s[%d] -> d[%d] (%d)\n", + cbuf->maxlen - n + cbuf->end + 1, 0, n - cbuf->end - 1); + + memcpy(c + cbuf->maxlen - cbuf->start, + cbuf->buf, cbuf->end + 1); + memcpy(c, cbuf->buf + cbuf->maxlen - n + cbuf->end +1, + n - cbuf->end - 1); } return n; } diff --git a/src/lib/cmdline_parse.c b/src/lib/cmdline_parse.c index 053e14c..215077e 100644 --- a/src/lib/cmdline_parse.c +++ b/src/lib/cmdline_parse.c @@ -129,8 +129,8 @@ nb_common_chars(const char * s1, const char * s2) * 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, - void * result_buf) +match_inst(cmdline_parse_inst_t *inst, const char *buf, + unsigned int nb_match_token, void * result_buf) { unsigned int token_num=0; cmdline_parse_token_hdr_t * token_p; @@ -211,7 +211,7 @@ cmdline_parse(struct cmdline *cl, const char * buf) unsigned int inst_num=0; cmdline_parse_inst_t *inst; const char *curbuf; - char result_buf[BUFSIZ]; /* XXX align, size zé in broblém */ + char result_buf[BUFSIZ]; void (*f)(void *, struct cmdline *, void *) = NULL; void *data = NULL; int comment = 0; @@ -317,14 +317,14 @@ int cmdline_complete(struct cmdline *cl, const char *buf, int *state, char *dst, unsigned int size) { - const char *incomplete_token = buf; + const char *partial_tok = buf; unsigned int inst_num = 0; cmdline_parse_inst_t *inst; cmdline_parse_token_hdr_t *token_p; struct cmdline_token_hdr token_hdr; - char tmpbuf[64], completion_buf[64]; - unsigned int incomplete_token_len; - int completion_len = -1; + char tmpbuf[64], comp_buf[64]; + unsigned int partial_tok_len; + int comp_len = -1; int nb_token = 0; unsigned int i, n; int l; @@ -342,14 +342,15 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, if (!isblank2(buf[i]) && isblank2(buf[i+1])) nb_token++; if (isblank2(buf[i]) && !isblank2(buf[i+1])) - incomplete_token = buf+i+1; + partial_tok = buf+i+1; } - incomplete_token_len = strlen(incomplete_token); + partial_tok_len = strlen(partial_tok); /* first call -> do a first pass */ if (*state <= 0) { debug_printf("try complete <%s>\n", buf); - debug_printf("there is %d complete tokens, <%s> is incomplete\n", nb_token, incomplete_token); + debug_printf("there is %d complete tokens, <%s> is incomplete\n", + nb_token, partial_tok); nb_completable = 0; nb_non_completable = 0; @@ -376,21 +377,33 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, debug_printf("%d choices for this token\n", n); for (i=0 ; icomplete_get_elt(token_p, i, tmpbuf, sizeof(tmpbuf)) < 0) + if (token_hdr.ops->complete_get_elt(token_p, i, + tmpbuf, + sizeof(tmpbuf)) < 0) continue; - strcat(tmpbuf, " "); /* we have at least room for one char */ + + /* we have at least room for one char */ + strcat(tmpbuf, " "); + debug_printf(" choice <%s>\n", tmpbuf); - /* does the completion match the beginning of the word ? */ - if (!strncmp(incomplete_token, tmpbuf, incomplete_token_len)) { - if (completion_len == -1) { - strcpy(completion_buf, tmpbuf+incomplete_token_len); - completion_len = strlen(tmpbuf+incomplete_token_len); + + /* does the completion match the + * beginning of the word ? */ + if (!strncmp(partial_tok, tmpbuf, + partial_tok_len)) { + if (comp_len == -1) { + strcpy(comp_buf, + tmpbuf + partial_tok_len); + comp_len = + strlen(tmpbuf + + partial_tok_len); } else { - completion_len = nb_common_chars(completion_buf, - tmpbuf+incomplete_token_len); - completion_buf[completion_len] = 0; + comp_len = + nb_common_chars(comp_buf, + tmpbuf+partial_tok_len); + comp_buf[comp_len] = 0; } nb_completable++; } @@ -400,21 +413,22 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, inst = ctx[inst_num]; } - debug_printf("total choices %d for this completion\n", nb_completable); + debug_printf("total choices %d for this completion\n", + nb_completable); /* 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) { + if (*state == 0 && partial_tok_len > 0) { /* one or several choices starting with the same chars */ - if (completion_len > 0) { - if ((unsigned)(completion_len + 1) > size) + if (comp_len > 0) { + if ((unsigned)(comp_len + 1) > size) return 0; - strcpy(dst, completion_buf); + strcpy(dst, comp_buf); return 2; } } @@ -450,12 +464,15 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, } (*state)++; if (token_p && token_hdr.ops->get_help) { - token_hdr.ops->get_help(token_p, tmpbuf, sizeof(tmpbuf)); + token_hdr.ops->get_help(token_p, tmpbuf, + sizeof(tmpbuf)); help_str = inst->help_str; if (help_str) - snprintf(dst, size, "[%s]: %s", tmpbuf, help_str); + snprintf(dst, size, "[%s]: %s", tmpbuf, + help_str); else - snprintf(dst, size, "[%s]: No help", tmpbuf); + snprintf(dst, size, "[%s]: No help", + tmpbuf); } else { snprintf(dst, size, "[RETURN]"); @@ -465,12 +482,18 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, /* several choices */ for (i=0 ; icomplete_get_elt(token_p, i, tmpbuf, sizeof(tmpbuf)) < 0) + if (token_hdr.ops->complete_get_elt(token_p, i, tmpbuf, + sizeof(tmpbuf)) < 0) continue; - strcat(tmpbuf, " "); /* we have at least room for one char */ + /* we have at least room for one char */ + strcat(tmpbuf, " "); + debug_printf(" choice <%s>\n", tmpbuf); - /* does the completion match the beginning of the word ? */ - if (!strncmp(incomplete_token, tmpbuf, incomplete_token_len)) { + + /* does the completion match the beginning of + * the word ? */ + if (!strncmp(partial_tok, tmpbuf, + partial_tok_len)) { if (local_state < *state) { local_state++; continue; @@ -478,12 +501,15 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, (*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)); + token_hdr.ops->get_help(token_p, tmpbuf, + sizeof(tmpbuf)); help_str = inst->help_str; if (help_str) - snprintf(dst+l, size-l, "[%s]: %s", tmpbuf, help_str); + snprintf(dst+l, size-l, "[%s]: %s", + tmpbuf, help_str); else - snprintf(dst+l, size-l, "[%s]: No help", tmpbuf); + snprintf(dst+l, size-l, + "[%s]: No help", tmpbuf); } return 1; diff --git a/src/lib/cmdline_rdline.c b/src/lib/cmdline_rdline.c index 44ad5ed..15f096d 100644 --- a/src/lib/cmdline_rdline.c +++ b/src/lib/cmdline_rdline.c @@ -91,7 +91,8 @@ isblank2(char c) 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) @@ -172,7 +173,8 @@ display_right_buffer(struct rdline *rdl) } } -void rdline_redisplay(struct rdline *rdl) +void +rdline_redisplay(struct rdline *rdl) { unsigned int i; char tmp;