* Complete the word at or before point, * 'what_to_do' says what to do with the completion. * \t means do standard completion. * `?' means list the possible completions. * `*' means insert all of the possible completions. * `!' means to do standard completion, and list all possible completions if * there is more than one. * * Note: '*' support is not implemented * '!' could never
| 406 | * '!' could never be invoked |
| 407 | */ |
| 408 | int |
| 409 | fn_complete(EditLine *el, |
| 410 | char *(*complet_func)(const char *, int), |
| 411 | char **(*attempted_completion_function)(const char *, int, int), |
| 412 | const Char *word_break, const Char *special_prefixes, |
| 413 | const char *(*app_func)(const char *), size_t query_items, |
| 414 | int *completion_type, int *over, int *point, int *end) |
| 415 | { |
| 416 | const TYPE(LineInfo) *li; |
| 417 | Char *temp; |
| 418 | char **matches; |
| 419 | const Char *ctemp; |
| 420 | size_t len; |
| 421 | int what_to_do = '\t'; |
| 422 | int retval = CC_NORM; |
| 423 | |
| 424 | if (el->el_state.lastcmd == el->el_state.thiscmd) |
| 425 | what_to_do = '?'; |
| 426 | |
| 427 | /* readline's rl_complete() has to be told what we did... */ |
| 428 | if (completion_type != NULL) |
| 429 | *completion_type = what_to_do; |
| 430 | |
| 431 | if (!complet_func) |
| 432 | complet_func = fn_filename_completion_function; |
| 433 | if (!app_func) |
| 434 | app_func = append_char_function; |
| 435 | |
| 436 | /* We now look backwards for the start of a filename/variable word */ |
| 437 | li = FUN(el,line)(el); |
| 438 | ctemp = li->cursor; |
| 439 | while (ctemp > li->buffer |
| 440 | && !Strchr(word_break, ctemp[-1]) |
| 441 | && (!special_prefixes || !Strchr(special_prefixes, ctemp[-1]) ) ) |
| 442 | ctemp--; |
| 443 | |
| 444 | len = (size_t)(li->cursor - ctemp); |
| 445 | temp = el_malloc((len + 1) * sizeof(*temp)); |
| 446 | (void)Strncpy(temp, ctemp, len); |
| 447 | temp[len] = '\0'; |
| 448 | |
| 449 | /* these can be used by function called in completion_matches() */ |
| 450 | /* or (*attempted_completion_function)() */ |
| 451 | if (point != 0) |
| 452 | *point = (int)(li->cursor - li->buffer); |
| 453 | if (end != NULL) |
| 454 | *end = (int)(li->lastchar - li->buffer); |
| 455 | |
| 456 | if (attempted_completion_function) { |
| 457 | int cur_off = (int)(li->cursor - li->buffer); |
| 458 | matches = (*attempted_completion_function)( |
| 459 | ct_encode_string(temp, &el->el_scratch), |
| 460 | cur_off - (int)len, cur_off); |
| 461 | } else |
| 462 | matches = 0; |
| 463 | if (!attempted_completion_function || |
| 464 | (over != NULL && !*over && !matches)) |
| 465 | matches = completion_matches( |
no test coverage detected