Tom Lane wrote:
> Robert Treat <xzilla@users.sourceforge.net> writes:
> > On Thu, 2003-09-04 at 21:14, Bruce Momjian wrote:
> >> Should we be using the pager for \h output?
>
> > in 7.3.4 we do, let me check 7.4...seems to work, though I am on beta1
> > on this box.
>
> Hmm. I do not see the pager used for \h in either version, though it
> does get used for \? ...
OK, turns out the '\h alter' code does a simple printf(), not a
PageOutput() and fprintf() to that pipe. Various \h outputs are long,
including CREATE TABLE, GRANT, and ALTER TABLE. ALTER itself is really
larger because it prints all the ALTER commands help.
The attached patch counts the number of newlines output by \h command,
and invokes the pager where appropriate.
This isn't a bug fix, so it will be kept for 7.5.
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
Index: src/bin/psql/help.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/help.c,v
retrieving revision 1.78
diff -c -c -r1.78 help.c
*** src/bin/psql/help.c 10 Sep 2003 21:35:55 -0000 1.78
--- src/bin/psql/help.c 10 Sep 2003 22:12:39 -0000
***************
*** 303,322 ****
{
int i;
bool help_found = false;
size_t len;
!
/* don't care about trailing spaces */
len = strlen(topic);
while (topic[len - 1] == ' ')
len--;
for (i = 0; QL_HELP[i].cmd; i++)
{
if (strncasecmp(topic, QL_HELP[i].cmd, len) == 0 ||
strcmp(topic, "*") == 0)
{
help_found = true;
! printf(_("Command: %s\n"
"Description: %s\n"
"Syntax:\n%s\n\n"),
QL_HELP[i].cmd, QL_HELP[i].help, QL_HELP[i].syntax);
--- 303,343 ----
{
int i;
bool help_found = false;
+ FILE *output;
size_t len;
! int nl_count = 0;
! char *ch;
!
/* don't care about trailing spaces */
len = strlen(topic);
while (topic[len - 1] == ' ')
len--;
+ /* Count newlines for pager */
+ for (i = 0; QL_HELP[i].cmd; i++)
+ {
+ if (strncasecmp(topic, QL_HELP[i].cmd, len) == 0 ||
+ strcmp(topic, "*") == 0)
+ {
+ nl_count += 5;
+ for (ch = QL_HELP[i].syntax; *ch != '\0'; ch++)
+ if (*ch == '\n')
+ nl_count++;
+ /* If we have an exact match, exit. Fixes \h SELECT */
+ if (strcasecmp(topic, QL_HELP[i].cmd) == 0)
+ break;
+ }
+ }
+
+ output = PageOutput(nl_count, pager);
+
for (i = 0; QL_HELP[i].cmd; i++)
{
if (strncasecmp(topic, QL_HELP[i].cmd, len) == 0 ||
strcmp(topic, "*") == 0)
{
help_found = true;
! fprintf(output, _("Command: %s\n"
"Description: %s\n"
"Syntax:\n%s\n\n"),
QL_HELP[i].cmd, QL_HELP[i].help, QL_HELP[i].syntax);
***************
*** 327,333 ****
}
if (!help_found)
! printf(_("No help available for \"%-.*s\".\nTry \\h with no arguments to see available help.\n"), (int)
len,topic);
}
}
--- 348,363 ----
}
if (!help_found)
! fprintf(output, _("No help available for \"%-.*s\".\nTry \\h with no arguments to see available
help.\n"),(int) len, topic);
!
! /* Only close if we used the pager */
! if (output != stdout)
! {
! pclose(output);
! #ifndef WIN32
! pqsignal(SIGPIPE, SIG_DFL);
! #endif
! }
}
}