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 ! } } }