33 *
44 * Copyright (c) 2000-2010, PostgreSQL Global Development Group
55 *
6- * $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.161 2010/08/12 00:40:59 tgl Exp $
6+ * $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.162 2010/08/13 20:56:18 tgl Exp $
77 */
88#include "postgres_fe.h"
99
10- #include <signal.h>
11-
1210#ifndef WIN32
1311#ifdef HAVE_PWD_H
1412#include <pwd.h> /* for getpwuid() */
2725#include <termios.h>
2826#endif
2927
30- #include "pqsignal.h"
31-
3228#include "common.h"
3329#include "help.h"
3430#include "input.h"
@@ -271,13 +267,7 @@ slashUsage(unsigned short int pager)
271267" \\lo_list\n"
272268" \\lo_unlink LOBOID large object operations\n" ));
273269
274- if (output != stdout )
275- {
276- pclose (output );
277- #ifndef WIN32
278- pqsignal (SIGPIPE ,SIG_DFL );
279- #endif
280- }
270+ ClosePager (output );
281271}
282272
283273
@@ -334,22 +324,15 @@ helpSQL(const char *topic, unsigned short int pager)
334324fputc ('\n' ,output );
335325}
336326
337- /* Only close if we used the pager */
338- if (output != stdout )
339- {
340- pclose (output );
341- #ifndef WIN32
342- pqsignal (SIGPIPE ,SIG_DFL );
343- #endif
344- }
327+ ClosePager (output );
345328}
346329else
347330{
348331int i ,
349332j ,
350333x = 0 ;
351334bool help_found = false;
352- FILE * output ;
335+ FILE * output = NULL ;
353336size_t len ,
354337wordlen ;
355338int nl_count = 0 ;
@@ -376,7 +359,8 @@ helpSQL(const char *topic, unsigned short int pager)
376359}
377360if (wordlen >=len )/* Don't try again if the same word */
378361{
379- output = PageOutput (nl_count ,pager );
362+ if (!output )
363+ output = PageOutput (nl_count ,pager );
380364break ;
381365}
382366len = wordlen ;
@@ -396,7 +380,8 @@ helpSQL(const char *topic, unsigned short int pager)
396380}
397381}
398382
399- output = PageOutput (nl_count ,pager );
383+ if (!output )
384+ output = PageOutput (nl_count ,pager );
400385
401386for (i = 0 ;QL_HELP [i ].cmd ;i ++ )
402387{
@@ -426,14 +411,7 @@ helpSQL(const char *topic, unsigned short int pager)
426411if (!help_found )
427412fprintf (output ,_ ("No help available for \"%s\".\nTry \\h with no arguments to see available help.\n" ),topic );
428413
429- /* Only close if we used the pager */
430- if (output != stdout )
431- {
432- pclose (output );
433- #ifndef WIN32
434- pqsignal (SIGPIPE ,SIG_DFL );
435- #endif
436- }
414+ ClosePager (output );
437415}
438416}
439417