| 309 | } |
| 310 | |
| 311 | int |
| 312 | cmdline_complete(struct cmdline *cl, const char *buf, int *state, |
| 313 | char *dst, unsigned int size) |
| 314 | { |
| 315 | const char *partial_tok = buf; |
| 316 | unsigned int inst_num = 0; |
| 317 | cmdline_parse_inst_t *inst; |
| 318 | cmdline_parse_token_hdr_t *token_p; |
| 319 | struct cmdline_token_hdr token_hdr; |
| 320 | char tmpbuf[CMDLINE_BUFFER_SIZE], comp_buf[CMDLINE_BUFFER_SIZE]; |
| 321 | unsigned int partial_tok_len; |
| 322 | int comp_len = -1; |
| 323 | int tmp_len = -1; |
| 324 | int nb_token = 0; |
| 325 | unsigned int i, n; |
| 326 | int l; |
| 327 | unsigned int nb_completable; |
| 328 | unsigned int nb_non_completable; |
| 329 | int local_state = 0; |
| 330 | const char *help_str; |
| 331 | cmdline_parse_ctx_t *ctx; |
| 332 | |
| 333 | if (!cl || !buf || !state || !dst) |
| 334 | return -1; |
| 335 | |
| 336 | ctx = cl->ctx; |
| 337 | |
| 338 | debug_printf("%s called\n", __func__); |
| 339 | memset(&token_hdr, 0, sizeof(token_hdr)); |
| 340 | |
| 341 | /* count the number of complete token to parse */ |
| 342 | for (i=0 ; buf[i] ; i++) { |
| 343 | if (!isblank2(buf[i]) && isblank2(buf[i+1])) |
| 344 | nb_token++; |
| 345 | if (isblank2(buf[i]) && !isblank2(buf[i+1])) |
| 346 | partial_tok = buf+i+1; |
| 347 | } |
| 348 | partial_tok_len = strnlen(partial_tok, RDLINE_BUF_SIZE); |
| 349 | |
| 350 | /* first call -> do a first pass */ |
| 351 | if (*state <= 0) { |
| 352 | debug_printf("try complete <%s>\n", buf); |
| 353 | debug_printf("there is %d complete tokens, <%s> is incomplete\n", |
| 354 | nb_token, partial_tok); |
| 355 | |
| 356 | nb_completable = 0; |
| 357 | nb_non_completable = 0; |
| 358 | |
| 359 | inst = ctx[inst_num]; |
| 360 | while (inst) { |
| 361 | /* parse the first tokens of the inst */ |
| 362 | if (nb_token && |
| 363 | match_inst(inst, buf, nb_token, NULL, 0)) |
| 364 | goto next; |
| 365 | |
| 366 | debug_printf("instruction match\n"); |
| 367 | token_p = get_token(inst, nb_token); |
| 368 | if (token_p) |