Bill Allombert on Wed, 19 Apr 2017 13:43:00 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: PARI/GP for Windows doesn't support umlauts and diacritical signs but it's possible


On Wed, Apr 19, 2017 at 07:42:41AM +0200, Jens Schmidt wrote:
> PARI/GP for Windows only supports ASCII chars in input and output. The
> programm should set the both codepages for input and output to the
> default value given by Windows registry (called ACP: ANSI codepage).
> That is easily done by some C code at startup:
> 
>   SetConsoleCP( GetACP() );
>   SetConsoleOutputCP( GetACP() );
> 
> By default the codepage of a Windows console is set to ancient DOS 437
> or 850,... called OEMCP. These old OEM codepages aren't recommend.
> 
> ACP is CP 1252 by default (aka Western) which is nearly identical to
> ISO-8859-1 and UTF-8 (Latin1 block). Windows uses some of the characters
> 0x80 .. 0x9f which are non-printable chars in ISO-8859-1 and UTF-8.
> 
> Windows has very limited support for UTF-8 console (codepage 65001).
> UTF-8 file/console redirect isn't possible because Windows doesn't
> support multibyte file IO - only single byte and wide chars.
> 
> I've tested this with Windows 7 and Wine in Linux. Setting codepages
> functions too through a PARI/GP plugin which could be installed at any
> time and would make older versions working.

Hello Jens,
Thanks for your suggestion.
I tried to write a patch following your suggestion but it did not seem
to change anything on wine. See below.

Cheers,
Bill.
diff --git a/src/gp/gp.c b/src/gp/gp.c
index dd542ec..9227fdd 100644
--- a/src/gp/gp.c
+++ b/src/gp/gp.c
@@ -16,6 +16,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
 /**                        PARI CALCULATOR                        **/
 /**                                                               **/
 /*******************************************************************/
+#ifdef _WIN32
+#  include "../systems/mingw/pwinver.h"
+#  include <windows.h>
+#  include "../systems/mingw/mingw.h"
+#endif
 #include "pari.h"
 #include "paripriv.h"
 #include "gp.h"
@@ -571,7 +576,9 @@ main(int argc, char **argv)
   cb_pari_ask_confirm = gp_ask_confirm;
   pari_init_paths();
   pari_mt_init(); /* MPI: will not return on slaves (pari_MPI_rank = 0) */
-
+#ifdef _WIN32
+  if (stdin_isatty) win32_set_codepage();
+#endif
 #ifdef READLINE
   init_readline();
 #endif
diff --git a/src/systems/mingw/mingw.c b/src/systems/mingw/mingw.c
index 5469276..3727571 100644
--- a/src/systems/mingw/mingw.c
+++ b/src/systems/mingw/mingw.c
@@ -136,6 +136,13 @@ win32_terminal_height(void)
 }
 
 void
+win32_set_codepage(void)
+{
+  SetConsoleCP( GetACP() );
+  SetConsoleOutputCP( GetACP() );
+}
+
+void
 win32_set_pdf_viewer(void)
 {
   char *s = getenv("GP_PDF_VIEWER");
diff --git a/src/systems/mingw/mingw.h b/src/systems/mingw/mingw.h
index 3f42d7f..da7201f 100644
--- a/src/systems/mingw/mingw.h
+++ b/src/systems/mingw/mingw.h
@@ -16,6 +16,7 @@ char* win32_datadir(void);
 void win32_ansi_fputs(const char* s, void* f);
 int win32_terminal_width(void);
 int win32_terminal_height(void);
+void win32_set_codepage(void);
 void win32_set_pdf_viewer(void);
 void win32_alarm(unsigned int s);
 long win32_timer(void);