* helpSQL -- help with SQL commands * * Note: we assume caller removed any trailing spaces in "topic". */
| 527 | * Note: we assume caller removed any trailing spaces in "topic". |
| 528 | */ |
| 529 | void |
| 530 | helpSQL(const char *topic, unsigned short int pager) |
| 531 | { |
| 532 | #define VALUE_OR_NULL(a) ((a) ? (a) : "") |
| 533 | |
| 534 | if (!topic || strlen(topic) == 0) |
| 535 | { |
| 536 | /* Print all the available command names */ |
| 537 | int screen_width; |
| 538 | int ncolumns; |
| 539 | int nrows; |
| 540 | FILE *output; |
| 541 | int i; |
| 542 | int j; |
| 543 | |
| 544 | /* Find screen width to determine how many columns will fit */ |
| 545 | #ifdef TIOCGWINSZ |
| 546 | struct winsize screen_size; |
| 547 | |
| 548 | if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1) |
| 549 | screen_width = 80; /* ioctl failed, assume 80 */ |
| 550 | else |
| 551 | screen_width = screen_size.ws_col; |
| 552 | #else |
| 553 | screen_width = 80; /* default assumption */ |
| 554 | #endif |
| 555 | |
| 556 | ncolumns = (screen_width - 3) / (QL_MAX_CMD_LEN + 1); |
| 557 | ncolumns = Max(ncolumns, 1); |
| 558 | nrows = (QL_HELP_COUNT + (ncolumns - 1)) / ncolumns; |
| 559 | |
| 560 | output = PageOutput(nrows + 1, pager ? &(pset.popt.topt) : NULL); |
| 561 | |
| 562 | fputs(_("Available help:\n"), output); |
| 563 | |
| 564 | for (i = 0; i < nrows; i++) |
| 565 | { |
| 566 | fprintf(output, " "); |
| 567 | for (j = 0; j < ncolumns - 1; j++) |
| 568 | fprintf(output, "%-*s", |
| 569 | QL_MAX_CMD_LEN + 1, |
| 570 | VALUE_OR_NULL(QL_HELP[i + j * nrows].cmd)); |
| 571 | if (i + j * nrows < QL_HELP_COUNT) |
| 572 | fprintf(output, "%s", |
| 573 | VALUE_OR_NULL(QL_HELP[i + j * nrows].cmd)); |
| 574 | fputc('\n', output); |
| 575 | } |
| 576 | |
| 577 | ClosePager(output); |
| 578 | } |
| 579 | else |
| 580 | { |
| 581 | int i, |
| 582 | pass; |
| 583 | FILE *output = NULL; |
| 584 | size_t len, |
| 585 | wordlen, |
| 586 | j; |
no test coverage detected