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

Commitcf1cf89

Browse files
committed
Make the printing code somewhat more independent by not relying on
functions and global variables from the rest of psql. Also clean up somedata type mismatches created by the last pager patch.
1 parent9384dc6 commitcf1cf89

File tree

10 files changed

+88
-89
lines changed

10 files changed

+88
-89
lines changed

‎src/bin/psql/command.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.91 2003/03/1015:46:01 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.92 2003/03/18 22:15:43 petere Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -471,6 +471,7 @@ exec_command(const char *cmd,
471471
{
472472
/* save encoding info into psql internal data */
473473
pset.encoding=PQclientEncoding(pset.db);
474+
pset.popt.topt.encoding=PQclientEncoding(pset.db);
474475
SetVariable(pset.vars,"ENCODING",pg_encoding_to_char(pset.encoding));
475476
}
476477
free(encoding);
@@ -1445,6 +1446,7 @@ do_connect(const char *new_dbname, const char *new_user)
14451446

14461447
PQsetNoticeProcessor(pset.db,NoticeProcessor,NULL);
14471448
pset.encoding=PQclientEncoding(pset.db);
1449+
pset.popt.topt.encoding=PQclientEncoding(pset.db);
14481450

14491451
/* Update variables */
14501452
SetVariable(pset.vars,"DBNAME",PQdb(pset.db));

‎src/bin/psql/common.c

Lines changed: 1 addition & 52 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/common.c,v 1.56 2003/03/10 22:28:19 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.57 2003/03/18 22:15:44 petere Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -24,14 +24,6 @@
2424
#include<sys/timeb.h>/* for _ftime() */
2525
#endif
2626

27-
#ifndefWIN32
28-
#include<sys/ioctl.h>/* for ioctl() */
29-
#endif
30-
31-
#ifdefHAVE_TERMIOS_H
32-
#include<termios.h>
33-
#endif
34-
3527
#include"libpq-fe.h"
3628
#include"pqsignal.h"
3729

@@ -522,46 +514,3 @@ SendQuery(const char *query)
522514

523515
returnsuccess;
524516
}
525-
526-
527-
/*
528-
* PageOutput
529-
*
530-
* Tests if pager is needed and returns appropriate FILE pointer.
531-
*/
532-
FILE*
533-
PageOutput(intlines,boolpager)
534-
{
535-
/* check whether we need / can / are supposed to use pager */
536-
if (pager
537-
#ifndefWIN32
538-
&&
539-
isatty(fileno(stdin))&&
540-
isatty(fileno(stdout))
541-
#endif
542-
)
543-
{
544-
constchar*pagerprog;
545-
546-
#ifdefTIOCGWINSZ
547-
intresult;
548-
structwinsizescreen_size;
549-
550-
result=ioctl(fileno(stdout),TIOCGWINSZ,&screen_size);
551-
if (result==-1||lines>screen_size.ws_row||pager>1)
552-
{
553-
#endif
554-
pagerprog=getenv("PAGER");
555-
if (!pagerprog)
556-
pagerprog=DEFAULT_PAGER;
557-
#ifndefWIN32
558-
pqsignal(SIGPIPE,SIG_IGN);
559-
#endif
560-
returnpopen(pagerprog,"w");
561-
#ifdefTIOCGWINSZ
562-
}
563-
#endif
564-
}
565-
566-
returnstdout;
567-
}

‎src/bin/psql/common.h

Lines changed: 1 addition & 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/common.h,v 1.21 2002/10/29 19:35:33 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.22 2003/03/18 22:15:44 petere Exp $
77
*/
88
#ifndefCOMMON_H
99
#defineCOMMON_H
@@ -37,8 +37,6 @@ extern PGresult *PSQLexec(const char *query, bool ignore_command_ok);
3737

3838
externboolSendQuery(constchar*query);
3939

40-
externFILE*PageOutput(intlines,boolpager);
41-
4240
/* sprompt.h */
4341
externchar*simple_prompt(constchar*prompt,intmaxlen,boolecho);
4442

‎src/bin/psql/help.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/help.c,v 1.70 2003/03/1015:46:03 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.71 2003/03/18 22:15:44 petere Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -262,7 +262,7 @@ slashUsage(unsigned short int pager)
262262
*
263263
*/
264264
void
265-
helpSQL(constchar*topic,boolpager)
265+
helpSQL(constchar*topic,unsigned shortintpager)
266266
{
267267
#defineVALUE_OR_NULL(a) ((a) ? (a) : "")
268268

‎src/bin/psql/help.h

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/help.h,v 1.11 2002/11/08 19:12:21 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/help.h,v 1.12 2003/03/18 22:15:44 petere Exp $
77
*/
88
#ifndefHELP_H
99
#defineHELP_H
@@ -12,7 +12,7 @@ voidusage(void);
1212

1313
voidslashUsage(unsigned shortintpager);
1414

15-
voidhelpSQL(constchar*topic,boolpager);
15+
voidhelpSQL(constchar*topic,unsigned shortintpager);
1616

1717
voidprint_copyright(void);
1818

‎src/bin/psql/mbprint.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.5 2002/10/03 17:09:42 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.6 2003/03/18 22:15:44 petere Exp $
77
*/
88

99
#include"postgres_fe.h"
1010
#include"mbprint.h"
1111

1212
#include"mb/pg_wchar.h"
13-
#include"settings.h"
1413

1514
/*
1615
* This is an implementation of wcwidth() and wcswidth() as defined in
@@ -310,9 +309,9 @@ mb_utf_validate(unsigned char *pwcs)
310309
*/
311310

312311
int
313-
pg_wcswidth(unsignedchar*pwcs,size_tlen)
312+
pg_wcswidth(unsignedchar*pwcs,size_tlen,intencoding)
314313
{
315-
if (pset.encoding==PG_UTF8)
314+
if (encoding==PG_UTF8)
316315
returnmb_utf_wcswidth(pwcs,len);
317316
else
318317
{
@@ -325,9 +324,9 @@ pg_wcswidth(unsigned char *pwcs, size_t len)
325324
}
326325

327326
unsignedchar*
328-
mbvalidate(unsignedchar*pwcs)
327+
mbvalidate(unsignedchar*pwcs,intencoding)
329328
{
330-
if (pset.encoding==PG_UTF8)
329+
if (encoding==PG_UTF8)
331330
returnmb_utf_validate(pwcs);
332331
else
333332
{

‎src/bin/psql/mbprint.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/* $Id: mbprint.h,v 1.5 2002/08/27 20:16:48 petere Exp $ */
1+
/* $Id: mbprint.h,v 1.6 2003/03/18 22:15:44 petere Exp $ */
22
#ifndefMBPRINT_H
33
#defineMBPRINT_H
44

55
#include"mb/pg_wchar.h"
66

77
pg_wcharutf2ucs(constunsignedchar*c);
88

9-
unsignedchar*mbvalidate(unsignedchar*pwcs);
9+
unsignedchar*mbvalidate(unsignedchar*pwcs,intencoding);
1010

11-
intpg_wcswidth(unsignedchar*pwcs,size_tlen);
11+
intpg_wcswidth(unsignedchar*pwcs,size_tlen,intencoding);
1212

1313
#endif/* MBPRINT_H */

‎src/bin/psql/print.c

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.35 2002/11/0115:12:19 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.36 2003/03/18 22:15:44 petere Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
1010
#include"print.h"
1111

1212
#include<math.h>
1313
#include<signal.h>
14+
#include<unistd.h>
15+
16+
#ifndefWIN32
17+
#include<sys/ioctl.h>/* for ioctl() */
18+
#endif
1419

1520
#include"pqsignal.h"
1621
#include"libpq-fe.h"
1722

18-
#include"settings.h"
19-
2023
#include"mbprint.h"
2124

2225
/*************************/
@@ -195,7 +198,7 @@ static void
195198
print_aligned_text(constchar*title,constchar*const*headers,
196199
constchar*const*cells,constchar*const*footers,
197200
constchar*opt_align,boolopt_barebones,
198-
unsigned shortintopt_border,
201+
unsigned shortintopt_border,intencoding,
199202
FILE*fout)
200203
{
201204
unsignedintcol_count=0;
@@ -253,15 +256,15 @@ print_aligned_text(const char *title, const char *const * headers,
253256
/* calc column widths */
254257
for (i=0;i<col_count;i++)
255258
{
256-
tmp=pg_wcswidth((unsignedchar*)headers[i],strlen(headers[i]));
259+
tmp=pg_wcswidth((unsignedchar*)headers[i],strlen(headers[i]),encoding);
257260
if (tmp>widths[i])
258261
widths[i]=tmp;
259262
head_w[i]=tmp;
260263
}
261264

262265
for (i=0,ptr=cells;*ptr;ptr++,i++)
263266
{
264-
tmp=pg_wcswidth((unsignedchar*)*ptr,strlen(*ptr));
267+
tmp=pg_wcswidth((unsignedchar*)*ptr,strlen(*ptr),encoding);
265268
if (tmp>widths[i %col_count])
266269
widths[i %col_count]=tmp;
267270
cell_w[i]=tmp;
@@ -282,7 +285,7 @@ print_aligned_text(const char *title, const char *const * headers,
282285
{
283286
inttlen;
284287

285-
tlen=pg_wcswidth((unsignedchar*)title,strlen(title));
288+
tlen=pg_wcswidth((unsignedchar*)title,strlen(title),encoding);
286289
if (tlen >= (int)total_w)
287290
fprintf(fout,"%s\n",title);
288291
else
@@ -392,9 +395,9 @@ print_aligned_text(const char *title, const char *const * headers,
392395

393396
staticvoid
394397
print_aligned_vertical(constchar*title,constchar*const*headers,
395-
constchar*const*cells,constchar*const*footers,
398+
constchar*const*cells,constchar*const*footers,
396399
boolopt_barebones,unsigned shortintopt_border,
397-
FILE*fout)
400+
intencoding,FILE*fout)
398401
{
399402
unsignedintcol_count=0;
400403
unsignedintrecord=1;
@@ -425,7 +428,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
425428
}
426429
for (i=0;i<col_count;i++)
427430
{
428-
if ((tmp=pg_wcswidth((unsignedchar*)headers[i],strlen(headers[i])))>hwidth)
431+
if ((tmp=pg_wcswidth((unsignedchar*)headers[i],strlen(headers[i]),encoding))>hwidth)
429432
hwidth=tmp;
430433
head_w[i]=tmp;
431434
}
@@ -447,7 +450,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
447450
/* find longest data cell */
448451
for (i=0,ptr=cells;*ptr;ptr++,i++)
449452
{
450-
if ((tmp=pg_wcswidth((unsignedchar*)*ptr,strlen(*ptr)))>dwidth)
453+
if ((tmp=pg_wcswidth((unsignedchar*)*ptr,strlen(*ptr),encoding))>dwidth)
451454
dwidth=tmp;
452455
cell_w[i]=tmp;
453456
}
@@ -953,14 +956,55 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
953956

954957

955958

956-
957-
958-
959959
/********************************/
960960
/* Public functions*/
961961
/********************************/
962962

963963

964+
/*
965+
* PageOutput
966+
*
967+
* Tests if pager is needed and returns appropriate FILE pointer.
968+
*/
969+
FILE*
970+
PageOutput(intlines,unsigned shortintpager)
971+
{
972+
/* check whether we need / can / are supposed to use pager */
973+
if (pager
974+
#ifndefWIN32
975+
&&
976+
isatty(fileno(stdin))&&
977+
isatty(fileno(stdout))
978+
#endif
979+
)
980+
{
981+
constchar*pagerprog;
982+
983+
#ifdefTIOCGWINSZ
984+
intresult;
985+
structwinsizescreen_size;
986+
987+
result=ioctl(fileno(stdout),TIOCGWINSZ,&screen_size);
988+
if (result==-1||lines>screen_size.ws_row||pager>1)
989+
{
990+
#endif
991+
pagerprog=getenv("PAGER");
992+
if (!pagerprog)
993+
pagerprog=DEFAULT_PAGER;
994+
#ifndefWIN32
995+
pqsignal(SIGPIPE,SIG_IGN);
996+
#endif
997+
returnpopen(pagerprog,"w");
998+
#ifdefTIOCGWINSZ
999+
}
1000+
#endif
1001+
}
1002+
1003+
returnstdout;
1004+
}
1005+
1006+
1007+
9641008
void
9651009
printTable(constchar*title,
9661010
constchar*const*headers,
@@ -1023,9 +1067,9 @@ printTable(const char *title,
10231067
break;
10241068
casePRINT_ALIGNED:
10251069
if (opt->expanded)
1026-
print_aligned_vertical(title,headers,cells,footers,opt->tuples_only,border,output);
1070+
print_aligned_vertical(title,headers,cells,footers,opt->tuples_only,border,opt->encoding,output);
10271071
else
1028-
print_aligned_text(title,headers,cells,footers,align,opt->tuples_only,border,output);
1072+
print_aligned_text(title,headers,cells,footers,align,opt->tuples_only,border,opt->encoding,output);
10291073
break;
10301074
casePRINT_HTML:
10311075
if (opt->expanded)
@@ -1077,7 +1121,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
10771121
}
10781122

10791123
for (i=0;i<nfields;i++)
1080-
headers[i]=mbvalidate(PQfname(result,i));
1124+
headers[i]=mbvalidate(PQfname(result,i),opt->topt.encoding);
10811125

10821126
/* set cells */
10831127

@@ -1093,7 +1137,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
10931137
if (PQgetisnull(result,i /nfields,i %nfields))
10941138
cells[i]=opt->nullPrint ?opt->nullPrint :"";
10951139
else
1096-
cells[i]=mbvalidate(PQgetvalue(result,i /nfields,i %nfields));
1140+
cells[i]=mbvalidate(PQgetvalue(result,i /nfields,i %nfields),opt->topt.encoding);
10971141
}
10981142

10991143
/* set footers */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp