Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit91dfa1a

Browse files
committed
Fix \? and \pset pager handling. \? wasn't honoring pager before.
1 parentd5fa19c commit91dfa1a

File tree

6 files changed

+98
-92
lines changed

6 files changed

+98
-92
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.67 2002/06/20 16:00:43 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.68 2002/07/15 01:56:25 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -1036,7 +1036,7 @@ lo_import 152801
10361036
<term><literal>pager</literal></term>
10371037
<listitem>
10381038
<para>
1039-
Toggles thelist of a pagerto do table output. If the
1039+
Toggles theuse of a pagerfor query and psql help output. If the
10401040
environment variable <envar>PAGER</envar> is set, the output
10411041
is piped to the specified program. Otherwise
10421042
<filename>more</filename> is used.
@@ -1050,7 +1050,7 @@ lo_import 152801
10501050
of the printing routines it is not always possible to predict
10511051
the number of lines that will actually be printed. For that
10521052
reason <application>psql</application> might not appear very
1053-
discriminating about when to use the pager and when not to.
1053+
discriminating about when to use the pager.
10541054
</para>
10551055
</listitem>
10561056
</varlistentry>

‎src/bin/psql/command.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.72 2002/04/24 05:24:00 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.73 2002/07/15 01:56:25 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -846,7 +846,7 @@ exec_command(const char *cmd,
846846

847847
/* \? -- slash command help */
848848
elseif (strcmp(cmd,"?")==0)
849-
slashUsage();
849+
slashUsage(pset.popt.topt.pager);
850850

851851
#if0
852852

‎src/bin/psql/help.c

Lines changed: 76 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.51 2002/06/20 20:29:42 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.52 2002/07/15 01:56:25 momjian Exp $
77
*/
88
#include"postgres_fe.h"
9+
#include"print.h"
910
#include"help.h"
1011

1112
#include<signal.h>
@@ -138,7 +139,6 @@ usage(void)
138139
}
139140

140141

141-
142142
/*
143143
* slashUsage
144144
*
@@ -154,98 +154,106 @@ struct winsize
154154
#endif
155155

156156
void
157-
slashUsage(void)
157+
slashUsage(boolpager)
158158
{
159-
boolusePipe= false;
160-
constchar*pagerenv;
161-
FILE*fout;
162-
structwinsizescreen_size;
159+
FILE*output,*pagerfd=NULL;
163160

164-
#ifdefTIOCGWINSZ
165-
if (pset.notty==0&&
166-
(ioctl(fileno(stdout),TIOCGWINSZ,&screen_size)==-1||
167-
screen_size.ws_col==0||
168-
screen_size.ws_row==0))
161+
/* check whether we need / can / are supposed to use pager */
162+
if (pager
163+
#ifndefWIN32
164+
&&
165+
isatty(fileno(stdin))&&
166+
isatty(fileno(stdout))
167+
#endif
168+
)
169169
{
170+
constchar*pagerprog;
171+
172+
#ifdefTIOCGWINSZ
173+
intresult;
174+
structwinsizescreen_size;
175+
176+
result=ioctl(fileno(stdout),TIOCGWINSZ,&screen_size);
177+
if (result==-1||50>screen_size.ws_row)
178+
{
170179
#endif
171-
screen_size.ws_row=24;
172-
screen_size.ws_col=80;
180+
pagerprog=getenv("PAGER");
181+
if (!pagerprog)
182+
pagerprog=DEFAULT_PAGER;
183+
pagerfd=popen(pagerprog,"w");
173184
#ifdefTIOCGWINSZ
174-
}
185+
}
175186
#endif
187+
}
176188

177-
if (pset.notty==0&&
178-
(pagerenv=getenv("PAGER"))&&
179-
(pagerenv[0]!='\0')&&
180-
screen_size.ws_row <=46&&
181-
(fout=popen(pagerenv,"w")))
189+
if (pagerfd)
182190
{
183-
usePipe=true;
191+
output=pagerfd;
184192
#ifndefWIN32
185193
pqsignal(SIGPIPE,SIG_IGN);
186194
#endif
187195
}
188196
else
189-
fout=stdout;
197+
output=stdout;
190198

191199
/* if you add/remove a line here, change the row test above */
192200
/* if this " is the start of the string then it ought to end there to fit in 80 columns >> " */
193-
fprintf(fout,_(" \\a toggle between unaligned and aligned output mode\n"));
194-
fprintf(fout,_(" \\c[onnect] [DBNAME|- [USER]]\n"
201+
fprintf(output,_(" \\a toggle between unaligned and aligned output mode\n"));
202+
fprintf(output,_(" \\c[onnect] [DBNAME|- [USER]]\n"
195203
" connect to new database (currently \"%s\")\n"),
196204
PQdb(pset.db));
197-
fprintf(fout,_(" \\C [STRING] set table title, or unset if none\n"));
198-
fprintf(fout,_(" \\cd [DIR] change the current working directory\n"));
199-
fprintf(fout,_(" \\copy ... perform SQL COPY with data stream to the client host\n"));
200-
fprintf(fout,_(" \\copyright show PostgreSQL usage and distribution terms\n"));
201-
fprintf(fout,_(" \\d [NAME] describe table (or view, index, sequence)\n"));
202-
fprintf(fout,_(" \\d{t|i|s|v|S} [PATTERN]\n"));
203-
fprintf(fout,_(" list tables/indexes/sequences/views/system tables\n"));
204-
fprintf(fout,_(" \\da [PATTERN] list aggregate functions\n"));
205-
fprintf(fout,_(" \\dd [PATTERN] show comment for object\n"));
206-
fprintf(fout,_(" \\dD [PATTERN] list domains\n"));
207-
fprintf(fout,_(" \\df [PATTERN] list functions\n"));
208-
fprintf(fout,_(" \\do [NAME] list operators\n"));
209-
fprintf(fout,_(" \\dl list large objects, same as lo_list\n"));
210-
fprintf(fout,_(" \\dp [PATTERN] list table access privileges\n"));
211-
fprintf(fout,_(" \\dT [PATTERN] list data types\n"));
212-
fprintf(fout,_(" \\du [PATTERN] list users\n"));
213-
fprintf(fout,_(" \\e [FILE] edit the query buffer (or file) with external editor\n"));
214-
fprintf(fout,_(" \\echo [STRING] write string to standard output\n"));
215-
fprintf(fout,_(" \\encoding [ENCODING] show or set client encoding\n"));
216-
fprintf(fout,_(" \\f [STRING] show or set field separator for unaligned query output\n"));
217-
fprintf(fout,_(" \\g [FILE] send query buffer to server (and results to file or |pipe)\n"));
218-
fprintf(fout,_(" \\h [NAME] help on syntax of SQL commands, * for all commands\n"));
219-
fprintf(fout,_(" \\H toggle HTML output mode (currently %s)\n"),
205+
fprintf(output,_(" \\C [STRING] set table title, or unset if none\n"));
206+
fprintf(output,_(" \\cd [DIR] change the current working directory\n"));
207+
fprintf(output,_(" \\copy ... perform SQL COPY with data stream to the client host\n"));
208+
fprintf(output,_(" \\copyright show PostgreSQL usage and distribution terms\n"));
209+
fprintf(output,_(" \\d [NAME] describe table (or view, index, sequence)\n"));
210+
fprintf(output,_(" \\d{t|i|s|v|S} [PATTERN]\n"));
211+
fprintf(output,_(" list tables/indexes/sequences/views/system tables\n"));
212+
fprintf(output,_(" \\da [PATTERN] list aggregate functions\n"));
213+
fprintf(output,_(" \\dd [PATTERN] show comment for object\n"));
214+
fprintf(output,_(" \\dD [PATTERN] list domains\n"));
215+
fprintf(output,_(" \\df [PATTERN] list functions\n"));
216+
fprintf(output,_(" \\do [NAME] list operators\n"));
217+
fprintf(output,_(" \\dl list large objects, same as lo_list\n"));
218+
fprintf(output,_(" \\dp [PATTERN] list table access privileges\n"));
219+
fprintf(output,_(" \\dT [PATTERN] list data types\n"));
220+
fprintf(output,_(" \\du [PATTERN] list users\n"));
221+
fprintf(output,_(" \\e [FILE] edit the query buffer (or file) with external editor\n"));
222+
fprintf(output,_(" \\echo [STRING] write string to standard output\n"));
223+
fprintf(output,_(" \\encoding [ENCODING] show or set client encoding\n"));
224+
fprintf(output,_(" \\f [STRING] show or set field separator for unaligned query output\n"));
225+
fprintf(output,_(" \\g [FILE] send query buffer to server (and results to file or |pipe)\n"));
226+
fprintf(output,_(" \\h [NAME] help on syntax of SQL commands, * for all commands\n"));
227+
fprintf(output,_(" \\H toggle HTML output mode (currently %s)\n"),
220228
ON(pset.popt.topt.format==PRINT_HTML));
221-
fprintf(fout,_(" \\i FILE execute commands from file\n"));
222-
fprintf(fout,_(" \\l list all databases\n"));
223-
fprintf(fout,_(" \\lo_export, \\lo_import, \\lo_list, \\lo_unlink\n"
229+
fprintf(output,_(" \\i FILE execute commands from file\n"));
230+
fprintf(output,_(" \\l list all databases\n"));
231+
fprintf(output,_(" \\lo_export, \\lo_import, \\lo_list, \\lo_unlink\n"
224232
" large object operations\n"));
225-
fprintf(fout,_(" \\o FILE send all query results to file or |pipe\n"));
226-
fprintf(fout,_(" \\p show the contents of the query buffer\n"));
227-
fprintf(fout,_(" \\pset NAME [VALUE] set table output option (NAME := {format|border|expanded|\n"
233+
fprintf(output,_(" \\o FILE send all query results to file or |pipe\n"));
234+
fprintf(output,_(" \\p show the contents of the query buffer\n"));
235+
fprintf(output,_(" \\pset NAME [VALUE] set table output option (NAME := {format|border|expanded|\n"
228236
" fieldsep|null|recordsep|tuples_only|title|tableattr|pager})\n"));
229-
fprintf(fout,_(" \\q quit psql\n"));
230-
fprintf(fout,_(" \\qecho [STRING] write string to query output stream (see \\o)\n"));
231-
fprintf(fout,_(" \\r reset (clear) the query buffer\n"));
232-
fprintf(fout,_(" \\s [FILE] display history or save it to file\n"));
233-
fprintf(fout,_(" \\set [NAME [VALUE]] set internal variable, or list all if no parameters\n"));
234-
fprintf(fout,_(" \\t show only rows (currently %s)\n"),
237+
fprintf(output,_(" \\q quit psql\n"));
238+
fprintf(output,_(" \\qecho [STRING] write string to query output stream (see \\o)\n"));
239+
fprintf(output,_(" \\r reset (clear) the query buffer\n"));
240+
fprintf(output,_(" \\s [FILE] display history or save it to file\n"));
241+
fprintf(output,_(" \\set [NAME [VALUE]] set internal variable, or list all if no parameters\n"));
242+
fprintf(output,_(" \\t show only rows (currently %s)\n"),
235243
ON(pset.popt.topt.tuples_only));
236-
fprintf(fout,_(" \\T [STRING] set HTML <table>-tag attributes, or unset if none\n"));
237-
fprintf(fout,_(" \\timing toggle timing of queries (currently %s)\n"),
244+
fprintf(output,_(" \\T [STRING] set HTML <table>-tag attributes, or unset if none\n"));
245+
fprintf(output,_(" \\timing toggle timing of queries (currently %s)\n"),
238246
ON(pset.timing));
239-
fprintf(fout,_(" \\unset NAME unset (delete) internal variable\n"));
240-
fprintf(fout,_(" \\w [FILE] write query buffer to file\n"));
241-
fprintf(fout,_(" \\x toggle expanded output (currently %s)\n"),
247+
fprintf(output,_(" \\unset NAME unset (delete) internal variable\n"));
248+
fprintf(output,_(" \\w [FILE] write query buffer to file\n"));
249+
fprintf(output,_(" \\x toggle expanded output (currently %s)\n"),
242250
ON(pset.popt.topt.expanded));
243-
fprintf(fout,_(" \\z [PATTERN] list table access privileges (same as \\dp)\n"));
244-
fprintf(fout,_(" \\! [COMMAND] execute command in shell or start interactive shell\n"));
251+
fprintf(output,_(" \\z [PATTERN] list table access privileges (same as \\dp)\n"));
252+
fprintf(output,_(" \\! [COMMAND] execute command in shell or start interactive shell\n"));
245253

246-
if (usePipe)
254+
if (pagerfd)
247255
{
248-
pclose(fout);
256+
pclose(pagerfd);
249257
#ifndefWIN32
250258
pqsignal(SIGPIPE,SIG_DFL);
251259
#endif

‎src/bin/psql/help.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/help.h,v 1.8 2001/10/28 06:25:58 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/help.h,v 1.9 2002/07/15 01:56:25 momjian Exp $
77
*/
88
#ifndefHELP_H
99
#defineHELP_H
1010

1111
voidusage(void);
1212

13-
voidslashUsage(void);
13+
voidslashUsage(boolpager);
1414

1515
voidhelpSQL(constchar*topic);
1616

‎src/bin/psql/print.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.26 2002/04/24 15:56:38 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.27 2002/07/15 01:56:25 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"print.h"
@@ -23,12 +23,6 @@
2323

2424
#include"settings.h"
2525

26-
#ifndef__CYGWIN__
27-
#defineDEFAULT_PAGER "more"
28-
#else
29-
#defineDEFAULT_PAGER "less"
30-
#endif
31-
3226
#ifdefHAVE_TERMIOS_H
3327
#include<termios.h>
3428
#endif
@@ -1033,7 +1027,7 @@ printTable(const char *title,
10331027
{
10341028
constchar*default_footer[]= {NULL};
10351029
unsigned shortintborder=opt->border;
1036-
FILE*pager=NULL,
1030+
FILE*pagerfd=NULL,
10371031
*output;
10381032

10391033

@@ -1090,15 +1084,15 @@ printTable(const char *title,
10901084
pagerprog=getenv("PAGER");
10911085
if (!pagerprog)
10921086
pagerprog=DEFAULT_PAGER;
1093-
pager=popen(pagerprog,"w");
1087+
pagerfd=popen(pagerprog,"w");
10941088
#ifdefTIOCGWINSZ
10951089
}
10961090
#endif
10971091
}
10981092

1099-
if (pager)
1093+
if (pagerfd)
11001094
{
1101-
output=pager;
1095+
output=pagerfd;
11021096
#ifndefWIN32
11031097
pqsignal(SIGPIPE,SIG_IGN);
11041098
#endif
@@ -1139,13 +1133,12 @@ printTable(const char *title,
11391133
fprintf(stderr,"+ Oops, you shouldn't see this!\n");
11401134
}
11411135

1142-
if (pager)
1136+
if (pagerfd)
11431137
{
1144-
pclose(pager);
1138+
pclose(pagerfd);
11451139
#ifndefWIN32
11461140
pqsignal(SIGPIPE,SIG_DFL);
11471141
#endif
1148-
11491142
}
11501143
}
11511144

‎src/bin/psql/print.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.12 2001/11/05 17:46:31 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.13 2002/07/15 01:56:25 momjian Exp $
77
*/
88
#ifndefPRINT_H
99
#definePRINT_H
@@ -72,7 +72,12 @@ typedef struct _printQueryOpt
7272
*
7373
* It calls the printTable above with all the things set straight.
7474
*/
75-
void
76-
printQuery(constPGresult*result,constprintQueryOpt*opt,FILE*fout);
75+
voidprintQuery(constPGresult*result,constprintQueryOpt*opt,FILE*fout);
76+
77+
#ifndef__CYGWIN__
78+
#defineDEFAULT_PAGER "more"
79+
#else
80+
#defineDEFAULT_PAGER "less"
81+
#endif
7782

7883
#endif/* PRINT_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp