# HG changeset patch # User ali # Date 1327966367 0 # Node ID 4a80c6053a66b1a650d8250a368d2f872a67ff51 # Parent f28ad45778632e54c13951f763cc9b26ccca8179 Use Unicode output on MS-Windows consoles diff -r f28ad4577863 -r 4a80c6053a66 bl/Makefile.am --- a/bl/Makefile.am Mon Jan 30 09:11:07 2012 +0000 +++ b/bl/Makefile.am Mon Jan 30 23:32:47 2012 +0000 @@ -4,4 +4,4 @@ noinst_LTLIBRARIES=libbl.la libbl_la_SOURCES=bl.h textfileutils.c textfileutils.h spawn.c spawn.h \ - path.c path.h mkdtemp.c mkdtemp.h + path.c path.h mkdtemp.c mkdtemp.h print.c print.h diff -r f28ad4577863 -r 4a80c6053a66 bl/bl.h --- a/bl/bl.h Mon Jan 30 09:11:07 2012 +0000 +++ b/bl/bl.h Mon Jan 30 23:32:47 2012 +0000 @@ -2,3 +2,4 @@ #include #include #include +#include diff -r f28ad4577863 -r 4a80c6053a66 bl/print.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bl/print.c Mon Jan 30 23:32:47 2012 +0000 @@ -0,0 +1,64 @@ +#ifdef WIN32 +#include +#endif +#include +#include +#include + +/* + * Handlers for g_print() and g_printerr() which will output via + * WriteConsoleW when run under MS-Windows and the corresponding + * stream has not been re-directed. In all other cases, output + * via stdout and stderr respectively. + */ + +#ifdef WIN32 +static HANDLE bl_console=0; + +static void bl_print_handler_console(const char *string) +{ + long len; + DWORD dummy; + gunichar2 *string2; + string2=g_utf8_to_utf16(string,-1,NULL,&len,NULL); + if (string2) + { + WriteConsoleW(bl_console,string2,len,&dummy,NULL); + g_free(string2); + } +} +#endif + +static void bl_print_handler_stdout(const char *string) +{ + fputs(string,stdout); +} + +static void bl_print_handler_stderr(const char *string) +{ + fputs(string,stderr); +} + +void bl_set_print_handlers(void) +{ +#ifdef WIN32 + DWORD dummy; + if (GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE),&dummy)) + { + bl_console=GetStdHandle(STD_OUTPUT_HANDLE); + g_set_print_handler(bl_print_handler_console); + } + else +#endif + g_set_print_handler(bl_print_handler_stdout); +#ifdef WIN32 + if (GetConsoleMode(GetStdHandle(STD_ERROR_HANDLE),&dummy)) + { + if (!bl_console) + bl_console=GetStdHandle(STD_ERROR_HANDLE); + g_set_printerr_handler(bl_print_handler_console); + } + else +#endif + g_set_printerr_handler(bl_print_handler_stderr); +} diff -r f28ad4577863 -r 4a80c6053a66 bl/print.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bl/print.h Mon Jan 30 23:32:47 2012 +0000 @@ -0,0 +1,6 @@ +#ifndef BL_PRINT_H +#define BL_PRINT_H + +void bl_set_print_handlers(void); + +#endif /* BL_PRINT_H */ diff -r f28ad4577863 -r 4a80c6053a66 bl/spawn.c --- a/bl/spawn.c Mon Jan 30 09:11:07 2012 +0000 +++ b/bl/spawn.c Mon Jan 30 23:32:47 2012 +0000 @@ -20,7 +20,7 @@ retval=g_spawn_sync(working_directory,argv,NULL,flags,NULL,NULL, standard_output,&standard_error,exit_status,error); if (standard_error) - fputs(standard_error,stderr); + g_printerr("%s",standard_error); g_free(standard_error); if (retval && exit_status) *exit_status=WEXITSTATUS(*exit_status); diff -r f28ad4577863 -r 4a80c6053a66 test/harness/loupe-test.c --- a/test/harness/loupe-test.c Mon Jan 30 09:11:07 2012 +0000 +++ b/test/harness/loupe-test.c Mon Jan 30 23:32:47 2012 +0000 @@ -26,6 +26,7 @@ { int i; gboolean pass=TRUE; + bl_set_print_handlers(); for(i=1;istr,col,""); + g_print("%s\n%*s^\n",string->str,col,""); g_string_free(string,TRUE); } @@ -252,8 +252,8 @@ GError *error=NULL; if (!testcase_create_input_files(testcase,&error)) { - fprintf(stderr,"%s: FAIL\n",testcase->basename); - fprintf(stderr,"%s\n",error->message); + g_print("%s: FAIL\n",testcase->basename); + g_print("%s\n",error->message); g_error_free(error); return FALSE; } @@ -266,8 +266,8 @@ } if (!r) { - fprintf(stderr,"%s: FAIL\n",testcase->basename); - fprintf(stderr,"%s\n",error->message); + g_print("%s: FAIL\n",testcase->basename); + g_print("%s\n",error->message); g_error_free(error); (void)testcase_remove_input_files(testcase,NULL); return FALSE; @@ -275,8 +275,8 @@ filename=testcase_resolve_input_files(testcase,"TEST-XXXXXX"); if (!testcase_remove_input_files(testcase,&error)) { - fprintf(stderr,"%s: FAIL\n",testcase->basename); - fprintf(stderr,"%s\n",error->message); + g_print("%s: FAIL\n",testcase->basename); + g_print("%s\n",error->message); g_error_free(error); return FALSE; } @@ -288,9 +288,9 @@ expected=g_string_new(testcase->expected); if (!g_str_has_prefix(output,header->str)) { - fprintf(stderr,"%s: FAIL\n",testcase->basename); + g_print("%s: FAIL\n",testcase->basename); offset=common_prefix_length(output,header->str); - fprintf(stderr,"Unexpected header from bookloupe:\n"); + g_print("Unexpected header from bookloupe:\n"); print_unexpected(output,offset); r=FALSE; } @@ -303,22 +303,22 @@ pos=s-output+2; else { - fprintf(stderr,"%s: FAIL\n",testcase->basename); + g_print("%s: FAIL\n",testcase->basename); offset=common_prefix_length(output,header->str); - fprintf(stderr,"Unterminated summary from bookloupe:\n%s\n", + g_print("Unterminated summary from bookloupe:\n%s\n", output+pos); r=FALSE; } } if (r && strcmp(output+pos,expected->str)) { - fprintf(stderr,"%s: FAIL\n",testcase->basename); + g_print("%s: FAIL\n",testcase->basename); offset=common_prefix_length(output+pos,expected->str); if (!offset && !output[pos+offset]) - fprintf(stderr,"Unexpected zero warnings from bookloupe.\n"); + g_print("Unexpected zero warnings from bookloupe.\n"); else { - fprintf(stderr,"Unexpected output from bookloupe:\n"); + g_print("Unexpected output from bookloupe:\n"); print_unexpected(output+pos,offset); } r=FALSE; @@ -329,7 +329,7 @@ g_free(filename); g_free(output); if (r) - fprintf(stderr,"%s: PASS\n",testcase->basename); + g_print("%s: PASS\n",testcase->basename); return r; } diff -r f28ad4577863 -r 4a80c6053a66 test/harness/testcaseio.c --- a/test/harness/testcaseio.c Mon Jan 30 09:11:07 2012 +0000 +++ b/test/harness/testcaseio.c Mon Jan 30 23:32:47 2012 +0000 @@ -9,7 +9,7 @@ /* * Read a testcase in from a file. - * On error, print a suitable message on stderr and return NULL. + * On error, print a suitable message using g_printerr and return NULL. * The returned testcase should be freed with testcase_free(). */ Testcase *testcase_parse_file(const char *filename) @@ -25,7 +25,7 @@ return NULL; if (!*testcase_parser_get_flag(parser)) { - fprintf(stderr,"%s: Not a valid testcase (flag)\n",filename); + g_printerr("%s: Not a valid testcase (flag)\n",filename); testcase_parser_free(parser); return NULL; } @@ -49,7 +49,7 @@ * file on somebody's computer by getting them to run a * testcase! */ - fprintf(stderr, + g_printerr( "%s: Input files may not have a directory component\n",arg); g_free(s); g_free(arg); @@ -76,7 +76,7 @@ } else { - fprintf(stderr,"%s: Not a valid testcase (%s)\n",filename,tag); + g_printerr("%s: Not a valid testcase (%s)\n",filename,tag); testcase_free(testcase); testcase_parser_free(parser); return NULL; @@ -86,10 +86,10 @@ if (!testcase_parser_at_eof(parser)) { if (found_tag) - fprintf(stderr,"%s: Not a valid testcase (garbage at end)\n", + g_printerr("%s: Not a valid testcase (garbage at end)\n", filename); else - fprintf(stderr,"%s: Not a valid testcase (no valid tags)\n", + g_printerr("%s: Not a valid testcase (no valid tags)\n", filename); testcase_free(testcase); testcase_parser_free(parser); diff -r f28ad4577863 -r 4a80c6053a66 test/harness/testcaseparser.c --- a/test/harness/testcaseparser.c Mon Jan 30 09:11:07 2012 +0000 +++ b/test/harness/testcaseparser.c Mon Jan 30 23:32:47 2012 +0000 @@ -99,7 +99,7 @@ } if (!g_utf8_validate(parser->contents,len,NULL)) { - fprintf(stderr,"%s: Does not contain valid UTF-8\n",filename); + g_printerr("%s: Does not contain valid UTF-8\n",filename); g_free(parser->contents); g_free(parser); return NULL;