Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 8345C143B1AC for ; Tue, 20 Mar 2012 16:50:42 -0300 (ADT) Received: from mail-bk0-f46.google.com ([209.85.214.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SA54q-0005Lp-Vh for pgsql-bugs@postgresql.org; Tue, 20 Mar 2012 19:50:41 +0000 Received: by bkcik5 with SMTP id ik5so350571bkc.19 for ; Tue, 20 Mar 2012 12:50:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; bh=V4v/h2N2IH828is238r5eGJj53qR8918uN0VYbjO2vI=; b=bk4ruXB3dWuX4CY9wBLxHy8IUMANkEbvqxKO/apBEEOHjpgXy3nTIIlr1seMCjwPZO OBQ0mNyABaEpaaJ7PKPs7I7h3cP4T0ZkTljwKpktSI83MpyoHa3T4Hm6H0vqogTzMJwc yUJ9FP7WXL/iOevpH0tQqrdfSxIc6vt57dUdEf9kIUQBe3FeBbqePnh5KZVbyZfJv9xA fJqSm/G/vjmbp5BUppX8kktdhYDPLtQD9XzZFC6t081U5b37WBdsK7ipB3Szq91bjycu vgK7CEQsOVcnsyY++hKrs/stUde1Ugj8KoYPSHMIcjca0esFSIsNiX2nJa9AUDrwjr/6 8okg== Received: by 10.204.131.84 with SMTP id w20mr429654bks.65.1332273027575; Tue, 20 Mar 2012 12:50:27 -0700 (PDT) Received: from [1.0.0.7] ([94.138.26.200]) by mx.google.com with ESMTPS id u14sm5286393bkp.2.2012.03.20.12.50.25 (version=SSLv3 cipher=OTHER); Tue, 20 Mar 2012 12:50:26 -0700 (PDT) Message-ID: <4F68DF76.1030609@gmail.com> Date: Tue, 20 Mar 2012 23:50:14 +0400 From: Alexander LAW User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: Alvaro Herrera CC: Pg Bugs Subject: Re: BUG #6510: A simple prompt is displayed using wrong charset References: <1331925178-sup-9261@alvh.no-ip.org> <4F65A533.7090208@gmail.com> <1332187409-sup-4631@alvh.no-ip.org> In-Reply-To: <1332187409-sup-4631@alvh.no-ip.org> Content-Type: multipart/mixed; boundary="------------040505050406020606070609" X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201203/153 X-Sequence-Number: 32714 This is a multi-part message in MIME format. --------------040505050406020606070609 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Thanks, I've understood your point. Please look at the patch. It implements the first way and it makes psql work too. Regards, Alexander 20.03.2012 00:05, Alvaro Herrera пишет: > Excerpts from Alexander LAW's message of dom mar 18 06:04:51 -0300 2012: >> I see two ways to resolve the issue. >> First is to use CharToOemBuff when writing a string to the "con" and >> OemToCharBuff when reading an input from it. >> The other is to always use stderr/stdin for Win32 as it was done for >> msys before. I think it's more straightforward. > Using console directly instead of stdin/out/err is more appropriate when > asking for passwords and reading them back, because you can redirect the > rest of the output to/from files or pipes, without the prompt > interfering with that. This also explains why stderr is used instead of > stdout. > --------------040505050406020606070609 Content-Type: text/x-patch; name="sprompt.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="sprompt.diff" --- a/src/port/sprompt.c 2012-02-24 02:53:36.000000000 +0400 +++ b/src/port/sprompt.c 2012-03-20 23:34:22.181979200 +0400 @@ -41,6 +41,7 @@ char *destination; FILE *termin, *termout; + char *_prompt; #ifdef HAVE_TERMIOS_H struct termios t_orig, @@ -49,6 +50,7 @@ #ifdef WIN32 HANDLE t = NULL; LPDWORD t_orig = NULL; + char *oem_prompt = NULL; #endif #endif @@ -104,7 +106,20 @@ if (prompt) { - fputs(_(prompt), termout); + _prompt = _(prompt); +#ifdef WIN32 + if ((termout != stderr) && (termout != stdout)) + { + oem_prompt = (char*) malloc(strlen(_prompt) + 1); + CharToOemBuff(_prompt, oem_prompt, strlen(_prompt) + 1); + _prompt = oem_prompt; + } +#endif + fputs(_prompt, termout); +#ifdef WIN32 + if (oem_prompt) + free(oem_prompt); +#endif fflush(termout); } @@ -130,6 +145,13 @@ /* remove trailing newline */ destination[length - 1] = '\0'; +#ifdef WIN32 + if (termin != stdin) + { + OemToCharBuff(destination, destination, strlen(destination) + 1); + } +#endif + #ifdef HAVE_TERMIOS_H if (!echo) { --------------040505050406020606070609--