MCPcopy Create free account
hub / github.com/apache/cloudberry / helpSQL

Function helpSQL

src/bin/psql/help.c:529–687  ·  view source on GitHub ↗

* helpSQL -- help with SQL commands * * Note: we assume caller removed any trailing spaces in "topic". */

Source from the content-addressed store, hash-verified

527 * Note: we assume caller removed any trailing spaces in "topic".
528 */
529void
530helpSQL(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;

Callers 1

exec_command_helpFunction · 0.85

Calls 7

PageOutputFunction · 0.85
ClosePagerFunction · 0.85
pg_strncasecmpFunction · 0.85
pg_strcasecmpFunction · 0.85
initPQExpBufferFunction · 0.85
psprintfFunction · 0.85
termPQExpBufferFunction · 0.85

Tested by

no test coverage detected