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

Commitde82ece

Browse files
committed
Fix PAGER bug in createuser/etc scripts
submitted by: Bruce Momjian (root@candle.pha.pa.us)
1 parent6562fa8 commitde82ece

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

‎src/interfaces/libpq/fe-exec.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.3 1996/07/18 05:48:56 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.4 1996/07/19 06:36:38 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include<stdlib.h>
1515
#include<stdio.h>
1616
#include<string.h>
17+
#include<signal.h>
1718
#include<errno.h>
1819
#include"postgres.h"
1920
#include"libpq/pqcomm.h"
@@ -727,6 +728,10 @@ PQprint(FILE *fout,
727728
char*border=NULL;
728729
intnumFieldName;
729730
intfs_len=strlen(po->fieldSep);
731+
inttotal_line_length=0;
732+
intusePipe=0;
733+
char*pager;
734+
730735
nTups=PQntuples(res);
731736
if (!(fieldNames=(char**)calloc(nFields,sizeof (char*))))
732737
{
@@ -758,7 +763,37 @@ PQprint(FILE *fout,
758763
len+=fs_len;
759764
if (len>fieldMaxLen)
760765
fieldMaxLen=len;
766+
total_line_length+=len;
761767
}
768+
769+
total_line_length+=nFields*strlen(po->fieldSep)+1;
770+
771+
if (fout==NULL)
772+
fout=stdout;
773+
if (fout==stdout) {
774+
/* try to pipe to the pager program if possible */
775+
pager=getenv("PAGER");
776+
if (pager!=NULL&&
777+
isatty(fileno(stdout))&&
778+
!po->html3&&
779+
((po->expanded&&nTups* (nFields+1) >=24)||
780+
(!po->expanded&&nTups* (total_line_length /80+1)*
781+
(1+ (po->standard!=0)) >=
782+
24-
783+
(po->header!=0)* (total_line_length /80+1)*2
784+
/*- 1 *//* newline at end of tuple list */
785+
/*- (quiet == 0)
786+
*/)))
787+
{
788+
fout=popen(pager,"w");
789+
if (fout) {
790+
usePipe=1;
791+
signal(SIGPIPE,SIG_IGN);
792+
}else
793+
fout=stdout;
794+
}
795+
}
796+
762797
if (!po->expanded&& (po->align||po->html3))
763798
{
764799
if (!(fields=(char**)calloc(nFields*(nTups+1),sizeof(char*))))
@@ -977,6 +1012,10 @@ PQprint(FILE *fout,
9771012
fputc('\n',fout);
9781013
}
9791014
free(fields);
1015+
if (usePipe) {
1016+
pclose(fout);
1017+
signal(SIGPIPE,SIG_DFL);
1018+
}
9801019
}
9811020
free(fieldMax);
9821021
free(fieldNotNum);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp