options (currently '%s')\n", ps->opt.tableOpt ? ps->opt.tableOpt : "");
+ fprintf(fout, " \\x -- toggle expanded output (currently %s)\n", on(ps->opt.expanded));
+ fprintf(fout, " \\z -- list current grant/revoke permissions\n");
+ fprintf(fout, " \\! [] -- shell escape or command\n");
+
+ if (usePipe)
+ {
+ pclose(fout);
+ pqsignal(SIGPIPE, SIG_DFL);
+ }
}
static PGresult *
switch (info_type) {
case 't': fprintf(stderr, "Couldn't find any tables!\n");
break;
- case 'i': fprintf(stderr, "Couldn't find any indicies!\n");
+ case 'i': fprintf(stderr, "Couldn't find any indices!\n");
break;
case 'S': fprintf(stderr, "Couldn't find any sequences!\n");
break;
case 'b':
- default: fprintf(stderr, "Couldn't find any tables, sequences or indicies!\n");
+ default: fprintf(stderr, "Couldn't find any tables, sequences or indices!\n");
break;
}
return (-1);
int i; /* Index into QL_HELP[] */
bool help_found; /* We found the help he asked for */
+ int usePipe = 0;
+ char *pagerenv;
+ FILE *fout;
+
+ if ((pagerenv = getenv("PAGER")) && (pagerenv[0] != '\0') && \
+ (fout = popen(pagerenv, "w")))
+ {
+ usePipe = 1;
+ pqsignal(SIGPIPE, SIG_IGN);
+ }
+ else
+ fout = stderr;
+
help_found = false; /* Haven't found it yet */
for (i = 0; QL_HELP[i].cmd; i++) {
if (strcmp(QL_HELP[i].cmd, topic) == 0 ||
strcmp(topic, "*") == 0) {
help_found = true;
- printf("Command: %s\n", QL_HELP[i].cmd);
- printf("Description: %s\n", QL_HELP[i].help);
- printf("Syntax:\n");
- printf("%s\n", QL_HELP[i].syntax);
- printf("\n");
+ fprintf(fout, "Command: %s\n", QL_HELP[i].cmd);
+ fprintf(fout, "Description: %s\n", QL_HELP[i].help);
+ fprintf(fout, "Syntax:\n");
+ fprintf(fout, "%s\n", QL_HELP[i].syntax);
+ fprintf(fout, "\n");
}
}
+
+ if (usePipe)
+ {
+ pclose(fout);
+ pqsignal(SIGPIPE, SIG_DFL);
+ }
+
if (!help_found)
printf("command not found, "
"try \\h with no arguments to see available help\n");
break;
case 'C': /* define new caption */
if (settings->opt.caption)
- free(settings->opt.caption);
- if (!optarg)
{
- if (settings->opt.caption)
- free(settings->opt.caption);
+ free(settings->opt.caption);
settings->opt.caption = NULL;
}
- else if (!(settings->opt.caption = strdup(optarg))) {
+ if (optarg && !(settings->opt.caption = strdup(optarg))) {
perror("malloc");
exit(1);
}
case 'd': /* \d describe tables or columns in a table */
if (strncmp(cmd, "dt", 2) == 0) { /* only tables */
tableList(settings, 0, 't');
- } else if (strncmp(cmd, "di", 2) == 0) { /* only indicies */
+ } else if (strncmp(cmd, "di", 2) == 0) { /* only indices */
tableList(settings, 0, 'i');
} else if (strncmp(cmd, "ds", 2) == 0) { /* only sequences */
tableList(settings, 0, 'S');
- } else if (!optarg) { /* show tables, sequences and indicies */
+ } else if (!optarg) { /* show tables, sequences and indices */
tableList(settings, 0, 'b');
} else if (strcmp(optarg, "*") == 0) { /* show everything */
tableList(settings, 0, 'b');