33 *
44 * Copyright 2000 by PostgreSQL Global Development Group
55 *
6- * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.58 2002/10/18 22:05:36 petere Exp $
6+ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.59 2002/10/23 19:23:56 momjian Exp $
77 */
88#include "postgres_fe.h"
9+ #include "common.h"
910#include "print.h"
1011#include "help.h"
1112
@@ -161,48 +162,11 @@ struct winsize
161162void
162163slashUsage (bool pager )
163164{
164- FILE * output ,
165- * pagerfd = NULL ;
166-
167- /* check whether we need / can / are supposed to use pager */
168- if (pager
169- #ifndef WIN32
170- &&
171- isatty (fileno (stdin ))&&
172- isatty (fileno (stdout ))
173- #endif
174- )
175- {
176- const char * pagerprog ;
165+ FILE * output ;
177166
178- #ifdef TIOCGWINSZ
179- int result ;
180- struct winsize screen_size ;
167+ output = PageOutput (50 ,pager );
181168
182- result = ioctl (fileno (stdout ),TIOCGWINSZ ,& screen_size );
183- if (result == -1 || 50 > screen_size .ws_row )
184- {
185- #endif
186- pagerprog = getenv ("PAGER" );
187- if (!pagerprog )
188- pagerprog = DEFAULT_PAGER ;
189- pagerfd = popen (pagerprog ,"w" );
190- #ifdef TIOCGWINSZ
191- }
192- #endif
193- }
194-
195- if (pagerfd )
196- {
197- output = pagerfd ;
198- #ifndef WIN32
199- pqsignal (SIGPIPE ,SIG_IGN );
200- #endif
201- }
202- else
203- output = stdout ;
204-
205- /* if you add/remove a line here, change the row test above */
169+ /* if you add/remove a line here, change the row count above */
206170
207171/*
208172 * if this " is the start of the string then it ought to end there to
@@ -262,9 +226,9 @@ slashUsage(bool pager)
262226fprintf (output ,_ (" \\z [PATTERN] list table access privileges (same as \\dp)\n" ));
263227fprintf (output ,_ (" \\! [COMMAND] execute command in shell or start interactive shell\n" ));
264228
265- if (pagerfd )
229+ if (output != stdout )
266230{
267- pclose (pagerfd );
231+ pclose (output );
268232#ifndef WIN32
269233pqsignal (SIGPIPE ,SIG_DFL );
270234#endif
@@ -278,29 +242,39 @@ slashUsage(bool pager)
278242 *
279243 */
280244void
281- helpSQL (const char * topic )
245+ helpSQL (const char * topic , bool pager )
282246{
283247#define VALUE_OR_NULL (a ) ((a) ? (a) : "")
284248
285249if (!topic || strlen (topic )== 0 )
286250{
287251int i ;
288252int items_per_column = (QL_HELP_COUNT + 2 ) /3 ;
253+ FILE * output ;
254+
255+ output = PageOutput (items_per_column ,pager );
289256
290- puts (_ ("Available help:" ) );
257+ fputs (_ ("Available help:\n" ), output );
291258
292259for (i = 0 ;i < items_per_column ;i ++ )
293260{
294- printf ( " %-26s%-26s" ,
261+ fprintf ( output , " %-26s%-26s" ,
295262VALUE_OR_NULL (QL_HELP [i ].cmd ),
296263VALUE_OR_NULL (QL_HELP [i + items_per_column ].cmd ));
297264if (i + 2 * items_per_column < QL_HELP_COUNT )
298- printf ( "%-26s" ,
265+ fprintf ( output , "%-26s" ,
299266VALUE_OR_NULL (QL_HELP [i + 2 * items_per_column ].cmd ));
300- fputc ('\n' ,stdout );
267+ fputc ('\n' ,output );
268+ }
269+ /* Only close if we used the pager */
270+ if (output != stdout )
271+ {
272+ pclose (output );
273+ #ifndef WIN32
274+ pqsignal (SIGPIPE ,SIG_DFL );
275+ #endif
301276}
302277}
303-
304278else
305279{
306280int i ;