3
3
*
4
4
* Copyright 2000 by PostgreSQL Global Development Group
5
5
*
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 $
7
7
*/
8
8
#include "postgres_fe.h"
9
+ #include "common.h"
9
10
#include "print.h"
10
11
#include "help.h"
11
12
@@ -161,48 +162,11 @@ struct winsize
161
162
void
162
163
slashUsage (bool pager )
163
164
{
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 ;
177
166
178
- #ifdef TIOCGWINSZ
179
- int result ;
180
- struct winsize screen_size ;
167
+ output = PageOutput (50 ,pager );
181
168
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 */
206
170
207
171
/*
208
172
* if this " is the start of the string then it ought to end there to
@@ -262,9 +226,9 @@ slashUsage(bool pager)
262
226
fprintf (output ,_ (" \\z [PATTERN] list table access privileges (same as \\dp)\n" ));
263
227
fprintf (output ,_ (" \\! [COMMAND] execute command in shell or start interactive shell\n" ));
264
228
265
- if (pagerfd )
229
+ if (output != stdout )
266
230
{
267
- pclose (pagerfd );
231
+ pclose (output );
268
232
#ifndef WIN32
269
233
pqsignal (SIGPIPE ,SIG_DFL );
270
234
#endif
@@ -278,29 +242,39 @@ slashUsage(bool pager)
278
242
*
279
243
*/
280
244
void
281
- helpSQL (const char * topic )
245
+ helpSQL (const char * topic , bool pager )
282
246
{
283
247
#define VALUE_OR_NULL (a ) ((a) ? (a) : "")
284
248
285
249
if (!topic || strlen (topic )== 0 )
286
250
{
287
251
int i ;
288
252
int items_per_column = (QL_HELP_COUNT + 2 ) /3 ;
253
+ FILE * output ;
254
+
255
+ output = PageOutput (items_per_column ,pager );
289
256
290
- puts (_ ("Available help:" ) );
257
+ fputs (_ ("Available help:\n" ), output );
291
258
292
259
for (i = 0 ;i < items_per_column ;i ++ )
293
260
{
294
- printf ( " %-26s%-26s" ,
261
+ fprintf ( output , " %-26s%-26s" ,
295
262
VALUE_OR_NULL (QL_HELP [i ].cmd ),
296
263
VALUE_OR_NULL (QL_HELP [i + items_per_column ].cmd ));
297
264
if (i + 2 * items_per_column < QL_HELP_COUNT )
298
- printf ( "%-26s" ,
265
+ fprintf ( output , "%-26s" ,
299
266
VALUE_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
301
276
}
302
277
}
303
-
304
278
else
305
279
{
306
280
int i ;