* Display list of strings in columnar format on readline's output stream. * 'matches' is list of strings, 'num' is number of strings in 'matches', * 'width' is maximum length of string in 'matches'. * * matches[0] is not one of the match strings, but it is counted in * num, so the strings are matches[1] *through* matches[num-1]. */
| 355 | * num, so the strings are matches[1] *through* matches[num-1]. |
| 356 | */ |
| 357 | void |
| 358 | fn_display_match_list (EditLine *el, char **matches, size_t num, size_t width) |
| 359 | { |
| 360 | size_t line, lines, col, cols, thisguy; |
| 361 | int screenwidth = el->el_terminal.t_size.h; |
| 362 | |
| 363 | /* Ignore matches[0]. Avoid 1-based array logic below. */ |
| 364 | matches++; |
| 365 | num--; |
| 366 | |
| 367 | /* |
| 368 | * Find out how many entries can be put on one line; count |
| 369 | * with one space between strings the same way it's printed. |
| 370 | */ |
| 371 | cols = (size_t)screenwidth / (width + 1); |
| 372 | if (cols == 0) |
| 373 | cols = 1; |
| 374 | |
| 375 | /* how many lines of output, rounded up */ |
| 376 | lines = (num + cols - 1) / cols; |
| 377 | |
| 378 | /* Sort the items. */ |
| 379 | qsort(matches, num, sizeof(char *), _fn_qsort_string_compare); |
| 380 | |
| 381 | /* |
| 382 | * On the ith line print elements i, i+lines, i+lines*2, etc. |
| 383 | */ |
| 384 | for (line = 0; line < lines; line++) { |
| 385 | for (col = 0; col < cols; col++) { |
| 386 | thisguy = line + col * lines; |
| 387 | if (thisguy >= num) |
| 388 | break; |
| 389 | (void)fprintf(el->el_outfile, "%s%-*s", |
| 390 | col == 0 ? "" : " ", (int)width, matches[thisguy]); |
| 391 | } |
| 392 | (void)fprintf(el->el_outfile, "\n"); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /* |
| 397 | * Complete the word at or before point, |
no outgoing calls
no test coverage detected