# HG changeset patch # User ali # Date 1369938384 -3600 # Node ID cffa80824f8cf7fe977a5e290564c8d4650de3bd # Parent 52d4a7f926b4e5fb787fef05decfd4a88457a2c5 Use SetConsoleOutputCP() under MS-Windows diff -r 52d4a7f926b4 -r cffa80824f8c bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Thu May 30 18:33:44 2013 +0100 +++ b/bookloupe/bookloupe.c Thu May 30 19:26:24 2013 +0100 @@ -22,6 +22,9 @@ #include #include #include +#ifdef __WIN32__ +#include +#endif #include #include #include "HTMLentities.h" @@ -235,6 +238,10 @@ GTree *qword,*qperiod; +#ifdef __WIN32__ +UINT saved_cp; +#endif + struct first_pass_results { long firstline,astline; long footerline,totlen,binlen,alphalen,endquote_count,shortline,dotcomma; @@ -405,18 +412,35 @@ { utf8=g_utf8_normalize(contents,len,G_NORMALIZE_DEFAULT_COMPOSE); g_set_print_handler(print_as_utf_8); +#ifdef __WIN32__ + SetConsoleOutputCP(CP_UTF8); +#endif } else { utf8=g_convert(contents,len,"UTF-8","WINDOWS-1252",NULL,&nb,NULL); g_set_print_handler(print_as_windows_1252); +#ifdef __WIN32__ + SetConsoleOutputCP(1252); +#endif } g_free(contents); return utf8; } +void cleanup_on_exit(void) +{ +#ifdef __WIN32__ + SetConsoleOutputCP(saved_cp); +#endif +} + int main(int argc,char **argv) { +#ifdef __WIN32__ + atexit(cleanup_on_exit); + saved_cp=GetConsoleOutputCP(); +#endif running_from=g_path_get_dirname(argv[0]); parse_options(&argc,&argv); if (pswit[USERTYPO_SWITCH])