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

Commit3620051

Browse files
committed
Applied patch for UTF8 windows psql
1 parentfd9fc27 commit3620051

File tree

10 files changed

+150
-9
lines changed

10 files changed

+150
-9
lines changed

‎src/bin/psql/command.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,13 @@ do_connect(enum trivalue reuse_previous_specification,
19231923
keywords[++paramnum]="fallback_application_name";
19241924
values[paramnum]=pset.progname;
19251925
keywords[++paramnum]="client_encoding";
1926-
values[paramnum]= (pset.notty||getenv("PGCLIENTENCODING")) ?NULL :"auto";
1926+
values[paramnum]= (pset.notty||getenv("PGCLIENTENCODING")) ?NULL :
1927+
#ifdefHAVE_WIN32_LIBEDIT
1928+
"UTF8"
1929+
#else
1930+
"auto"
1931+
#endif
1932+
;
19271933

19281934
/* add array terminator */
19291935
keywords[++paramnum]=NULL;
@@ -2105,6 +2111,11 @@ printSSLInfo(void)
21052111
staticvoid
21062112
checkWin32Codepage(void)
21072113
{
2114+
#ifdefHAVE_WIN32_LIBEDIT
2115+
if (isatty(fileno(stdout)))
2116+
printf(_("WARNING: Unicode mode enabled. "
2117+
"You need TTF font in your console window\n"));
2118+
#else
21082119
unsignedintwincp,
21092120
concp;
21102121

@@ -2117,6 +2128,7 @@ checkWin32Codepage(void)
21172128
" page \"Notes for Windows users\" for details.\n"),
21182129
concp,wincp);
21192130
}
2131+
#endif
21202132
}
21212133
#endif
21222134

‎src/bin/psql/input.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ gets_fromFile(FILE *source)
287287
for (VARNAME = current_history(); VARNAME != NULL; \
288288
VARNAME = use_prev_ ? previous_history() : next_history()) \
289289
{ \
290+
if (VARNAME -> line == NULL) \
291+
continue; \
290292
(void) 0
291293

292294
#defineEND_ITERATE_HISTORY() \
@@ -355,7 +357,9 @@ initializeInput(int flags)
355357

356358
/* these two things must be done in this order: */
357359
initialize_readline();
360+
#ifndefHAVE_WIN32_LIBEDIT
358361
rl_initialize();
362+
#endif
359363

360364
useHistory= true;
361365
using_history();
@@ -459,8 +463,10 @@ saveHistory(char *fname, int max_lines)
459463
#else/* don't have append support */
460464
{
461465
/* truncate what we have ... */
466+
#ifndefHAVE_WIN32_LIBEDIT
462467
if (max_lines >=0)
463468
stifle_history(max_lines);
469+
#endif
464470
/* ... and overwrite file. Tough luck for concurrent sessions. */
465471
errnum=write_history(fname);
466472
if (errnum==0)

‎src/bin/psql/startup.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include"mainloop.h"
2929
#include"fe_utils/print.h"
3030
#include"settings.h"
31+
#include"mb/pg_wchar.h"
3132

3233

3334

@@ -158,7 +159,11 @@ main(int argc, char *argv[])
158159
pset.popt.topt.env_columns=getenv("COLUMNS") ?atoi(getenv("COLUMNS")) :0;
159160

160161
pset.notty= (!isatty(fileno(stdin))|| !isatty(fileno(stdout)));
161-
162+
#ifdefHAVE_WIN32_LIBEDIT
163+
if (!pset.notty&&pset.encoding==PG_SQL_ASCII) {
164+
pset.encoding=PG_UTF8;
165+
}
166+
#endif
162167
pset.getPassword=TRI_DEFAULT;
163168

164169
EstablishVariableSpace();
@@ -233,7 +238,13 @@ main(int argc, char *argv[])
233238
keywords[5]="fallback_application_name";
234239
values[5]=pset.progname;
235240
keywords[6]="client_encoding";
236-
values[6]= (pset.notty||getenv("PGCLIENTENCODING")) ?NULL :"auto";
241+
values[6]= (pset.notty||getenv("PGCLIENTENCODING")) ?NULL :
242+
#ifdefHAVE_WIN32_LIBEDIT
243+
"UTF8"
244+
#else
245+
"auto"
246+
#endif
247+
;
237248
keywords[7]=NULL;
238249
values[7]=NULL;
239250

@@ -992,3 +1003,4 @@ EstablishVariableSpace(void)
9921003
SetVariableAssignHook(pset.vars,"VERBOSITY",verbosity_hook);
9931004
SetVariableAssignHook(pset.vars,"SHOW_CONTEXT",show_context_hook);
9941005
}
1006+

‎src/bin/psql/tab-complete.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,13 @@ initialize_readline(void)
967967
{
968968
rl_readline_name= (char*)pset.progname;
969969
rl_attempted_completion_function=psql_completion;
970-
970+
#ifndefHAVE_WIN32_LIBEDIT
971971
rl_basic_word_break_characters=WORD_BREAKS;
972972

973+
/* In WinLibEdit rl_basic_word_break_characters is constant */
974+
975+
#endif
976+
973977
completion_max_records=1000;
974978

975979
/*

‎src/common/exec.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ pipe_read_line(char *cmd, char *line, int maxsize)
443443
break;/* Timeout, but perhaps we got a line already */
444444

445445
if (!ReadFile(childstdoutrddup,lineptr,maxsize- (lineptr-line),
446-
&bytesread,NULL))
446+
&bytesread,NULL))
447447
break;/* Error, but perhaps we got a line already */
448448

449449
lineptr+=strlen(lineptr);
@@ -578,6 +578,11 @@ set_pglocale_pgservice(const char *argv0, const char *app)
578578
bindtextdomain(app,path);
579579
textdomain(app);
580580

581+
#if defined(HAVE_WIN32_LIBEDIT)&& defined(ENABLE_NLS)
582+
bind_textdomain_codeset(app,"UTF-8");
583+
bind_textdomain_codeset(PG_TEXTDOMAIN("libpq"),"UTF-8");
584+
#endif
585+
581586
if (getenv("PGLOCALEDIR")==NULL)
582587
{
583588
/* set for libpq to use */

‎src/fe_utils/print.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,19 @@ format_numeric_locale(const char *my_str)
318318
staticvoid
319319
fputnbytes(FILE*f,constchar*str,size_tn)
320320
{
321+
322+
#ifdefHAVE_WIN32_LIBEDIT
323+
charbuffer[1024];
324+
char*buf=buffer;
325+
if (n>1023)buf=malloc(n+1);
326+
strncpy(buf,str,n);
327+
buf[n]=0;
328+
fputs(buf,f);
329+
if (n>1023)free(buf);
330+
#else
321331
while (n-->0)
322332
fputc(*str++,f);
333+
#endif
323334
}
324335

325336

‎src/include/fe_utils/print.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818

1919
/* This is not a particularly great place for this ... */
20+
/* Let build system to redefine default pager */
21+
#ifndefDEFAULT_PAGER
2022
#ifndef__CYGWIN__
2123
#defineDEFAULT_PAGER "more"
2224
#else
2325
#defineDEFAULT_PAGER "less"
2426
#endif
25-
27+
#endif
2628
enumprintFormat
2729
{
2830
PRINT_NOTHING=0,/* to make sure someone initializes this */

‎src/include/port.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ extern unsigned char pg_ascii_tolower(unsigned char ch);
152152
#ifdefprintf
153153
#undef printf
154154
#endif
155+
#ifdeffputs
156+
#undef fputs
157+
#endif
155158

156159
externintpg_vsnprintf(char*str,size_tcount,constchar*fmt,va_listargs);
157160
externintpg_snprintf(char*str,size_tcount,constchar*fmt,...)pg_attribute_printf(3,4);
@@ -160,6 +163,10 @@ extern intpg_vfprintf(FILE *stream, const char *fmt, va_list args);
160163
externintpg_fprintf(FILE*stream,constchar*fmt,...)pg_attribute_printf(2,3);
161164
externintpg_printf(constchar*fmt,...)pg_attribute_printf(1,2);
162165

166+
#ifdefHAVE_WIN32_LIBEDIT
167+
externintpg_fputs(constchar*s,FILE*stream);
168+
externintpg_puts(constchar*s);
169+
#endif
163170
/*
164171
*The GCC-specific code below prevents the pg_attribute_printf above from
165172
*being replaced, and this is required because gcc doesn't know anything
@@ -180,6 +187,11 @@ extern intpg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
180187
#definefprintfpg_fprintf
181188
#defineprintfpg_printf
182189
#endif
190+
#ifdefHAVE_WIN32_LIBEDIT
191+
/* Catch fputs as well so we can use WriteConsole for table output */
192+
#definefputs(s,f)pg_fputs(s,f)
193+
#defineputs(s)pg_puts(s)
194+
#endif
183195
#endif/* USE_REPL_SNPRINTF */
184196

185197
#if defined(WIN32)

‎src/port/snprintf.c

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 1983, 1995, 1996 Eric P. Allman
33
* Copyright (c) 1988, 1993
44
*The Regents of the University of California. All rights reserved.
@@ -103,7 +103,9 @@
103103
#undefvfprintf
104104
#undeffprintf
105105
#undefprintf
106-
106+
#ifdefHAVE_WIN32_LIBEDIT
107+
#undef fputs
108+
#endif
107109
/* Info about where the formatted output is going */
108110
typedefstruct
109111
{
@@ -262,13 +264,35 @@ flushbuffer(PrintfTarget *target)
262264
if (!target->failed&&nc>0)
263265
{
264266
size_twritten;
265-
267+
#ifdefHAVE_WIN32_LIBEDIT
268+
/*With Win32 libedit we use WriteW API to write to
269+
* console instead of fwrite*/
270+
if (isatty(fileno(target->stream)))
271+
{
272+
/* Convert message from buffer (expected as utf8)
273+
to widechar */
274+
HANDLEconsoleHandle=_get_osfhandle(_fileno(target->stream));
275+
DWORDactuallyWritten;
276+
wchar_t*widebuf= (wchar_t*)malloc(nc*sizeof(wchar_t));
277+
written=MultiByteToWideChar(CP_UTF8,0,target->bufstart,nc,widebuf,nc);
278+
WriteConsoleW(consoleHandle,widebuf,written,&actuallyWritten,NULL);
279+
if (actuallyWritten==written)
280+
target->nchars+=nc;
281+
else
282+
target->failed= true;
283+
free(widebuf);
284+
}else {
285+
#endif
266286
written=fwrite(target->bufstart,1,nc,target->stream);
267287
target->nchars+=written;
268288
if (written!=nc)
269289
target->failed= true;
290+
#ifdefHAVE_WIN32_LIBEDIT
291+
}
292+
#endif
270293
}
271294
target->bufptr=target->bufstart;
295+
fflush(target->stream);
272296
}
273297

274298

@@ -1139,3 +1163,42 @@ trailing_pad(int *padlen, PrintfTarget *target)
11391163
++(*padlen);
11401164
}
11411165
}
1166+
1167+
#ifdefHAVE_WIN32_LIBEDIT
1168+
/* replacement to fputs function which uses flushBuffer */
1169+
intpg_fputs(constchar*s,FILE*stream)
1170+
{
1171+
PrintfTargettarget;
1172+
if (stream==NULL)
1173+
{
1174+
errno=EINVAL;
1175+
return-1;
1176+
}
1177+
target.bufstart=s;
1178+
target.nchars=0;
1179+
target.bufptr=s+strlen(s);
1180+
target.bufend=NULL;
1181+
target.failed=false;
1182+
target.stream=stream;
1183+
flushbuffer(&target);
1184+
returntarget.failed ?-1 :target.nchars;
1185+
}
1186+
1187+
/* replacement to puts function which uses flushBuffer */
1188+
intpg_puts(constchar*tmps)
1189+
{
1190+
char*s=NULL;
1191+
1192+
s= (char*)malloc(strlen(tmps)+1);
1193+
sprintf(s,"%s\n",tmps);
1194+
PrintfTargettarget;
1195+
target.bufstart=s;
1196+
target.nchars=0;
1197+
target.bufptr=s+strlen(s);
1198+
target.bufend=NULL;
1199+
target.failed= false;
1200+
target.stream=stdout;
1201+
flushbuffer(&target);
1202+
returntarget.failed ?-1 :target.nchars;
1203+
}
1204+
#endif

‎src/tools/msvc/Solution.pm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ sub GenerateFiles
247247
{
248248
print O"#define USE_ICU\n";
249249
}
250+
if ($self->{options}->{libedit})
251+
{
252+
print O"#define HAVE_EDITLINE_READLINE_H\n";
253+
print O"#define HAVE_LIBREADLINE\n";
254+
print O"#define HAVE_WIN32_LIBEDIT\n";
255+
print O"#define HAVE_RL_FILENAME_COMPLETION_FUNCTION\n";
256+
print O"#define HAVE_RL_COMPLETION_MATCHES\n";
257+
}
250258
print O"#define VAL_CONFIGURE\""
251259
.$self->GetFakeConfigure() ."\"\n";
252260
print O"#endif /* IGNORE_CONFIGURED_SETTINGS */\n";
@@ -576,6 +584,12 @@ sub AddProject
576584
$proj->AddLibrary($libdir.'\icuin.lib');
577585
$proj->AddLibrary($libdir.'\icuuc.lib');
578586
}
587+
if ($self->{options}->{libedit})
588+
{
589+
$proj->AddIncludeDir($self->{options}->{libedit} .'\include');
590+
$proj->AddLibrary($self->{options}->{libedit} ."\\" .
591+
($self->{platform}eq'x64'?'lib64':'lib32').'\edit.lib');
592+
}
579593
return$proj;
580594
}
581595

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp