aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql/help.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-10-23 19:23:57 +0000
committerBruce Momjian <bruce@momjian.us>2002-10-23 19:23:57 +0000
commit641b658c26f927bf59d38ecba9c8ab45544a2816 (patch)
tree0567c4c9acb11ee82a3d29ae52010d2afcb2f624 /src/bin/psql/help.c
parent30963fc20009b98a7a2b2dcd1f2ec559d58ac6d5 (diff)
downloadpostgresql-641b658c26f927bf59d38ecba9c8ab45544a2816.tar.gz
postgresql-641b658c26f927bf59d38ecba9c8ab45544a2816.zip
Page \h output and centralize psql paging code in PageOutput().
Diffstat (limited to 'src/bin/psql/help.c')
-rw-r--r--src/bin/psql/help.c72
1 files changed, 23 insertions, 49 deletions
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index af60be1bca9..7dfb594b435 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -3,9 +3,10 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.58 2002/10/18 22:05:36 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.59 2002/10/23 19:23:56 momjian Exp $
*/
#include "postgres_fe.h"
+#include "common.h"
#include "print.h"
#include "help.h"
@@ -161,48 +162,11 @@ struct winsize
void
slashUsage(bool pager)
{
- FILE *output,
- *pagerfd = NULL;
-
- /* check whether we need / can / are supposed to use pager */
- if (pager
-#ifndef WIN32
- &&
- isatty(fileno(stdin)) &&
- isatty(fileno(stdout))
-#endif
- )
- {
- const char *pagerprog;
+ FILE *output;
-#ifdef TIOCGWINSZ
- int result;
- struct winsize screen_size;
+ output = PageOutput(50, pager);
- result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
- if (result == -1 || 50 > screen_size.ws_row)
- {
-#endif
- pagerprog = getenv("PAGER");
- if (!pagerprog)
- pagerprog = DEFAULT_PAGER;
- pagerfd = popen(pagerprog, "w");
-#ifdef TIOCGWINSZ
- }
-#endif
- }
-
- if (pagerfd)
- {
- output = pagerfd;
-#ifndef WIN32
- pqsignal(SIGPIPE, SIG_IGN);
-#endif
- }
- else
- output = stdout;
-
- /* if you add/remove a line here, change the row test above */
+ /* if you add/remove a line here, change the row count above */
/*
* if this " is the start of the string then it ought to end there to
@@ -262,9 +226,9 @@ slashUsage(bool pager)
fprintf(output, _(" \\z [PATTERN] list table access privileges (same as \\dp)\n"));
fprintf(output, _(" \\! [COMMAND] execute command in shell or start interactive shell\n"));
- if (pagerfd)
+ if (output != stdout)
{
- pclose(pagerfd);
+ pclose(output);
#ifndef WIN32
pqsignal(SIGPIPE, SIG_DFL);
#endif
@@ -278,7 +242,7 @@ slashUsage(bool pager)
*
*/
void
-helpSQL(const char *topic)
+helpSQL(const char *topic, bool pager)
{
#define VALUE_OR_NULL(a) ((a) ? (a) : "")
@@ -286,21 +250,31 @@ helpSQL(const char *topic)
{
int i;
int items_per_column = (QL_HELP_COUNT + 2) / 3;
+ FILE *output;
+
+ output = PageOutput(items_per_column, pager);
- puts(_("Available help:"));
+ fputs(_("Available help:\n"), output);
for (i = 0; i < items_per_column; i++)
{
- printf(" %-26s%-26s",
+ fprintf(output, " %-26s%-26s",
VALUE_OR_NULL(QL_HELP[i].cmd),
VALUE_OR_NULL(QL_HELP[i + items_per_column].cmd));
if (i + 2 * items_per_column < QL_HELP_COUNT)
- printf("%-26s",
+ fprintf(output, "%-26s",
VALUE_OR_NULL(QL_HELP[i + 2 * items_per_column].cmd));
- fputc('\n', stdout);
+ fputc('\n', output);
+ }
+ /* Only close if we used the pager */
+ if (output != stdout)
+ {
+ pclose(output);
+#ifndef WIN32
+ pqsignal(SIGPIPE, SIG_DFL);
+#endif
}
}
-
else
{
int i;