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);
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;
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;
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;
}
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;
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;
}
* 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;
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;
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;
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;
debug_printf("%d choices for this token\n", n);
for (i=0 ; i<n ; i++) {
- if (token_hdr.ops->complete_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++;
}
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;
}
}
}
(*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]");
/* several choices */
for (i=0 ; i<n ; i++) {
- if (token_hdr.ops->complete_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;
(*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;