ali@11
|
1 |
#ifdef WIN32
|
ali@11
|
2 |
#include <windows.h>
|
ali@11
|
3 |
#endif
|
ali@11
|
4 |
#include <stdlib.h>
|
ali@11
|
5 |
#include <stdio.h>
|
ali@11
|
6 |
#include <glib.h>
|
ali@11
|
7 |
|
ali@11
|
8 |
/*
|
ali@11
|
9 |
* Handlers for g_print() and g_printerr() which will output via
|
ali@11
|
10 |
* WriteConsoleW when run under MS-Windows and the corresponding
|
ali@11
|
11 |
* stream has not been re-directed. In all other cases, output
|
ali@11
|
12 |
* via stdout and stderr respectively.
|
ali@11
|
13 |
*/
|
ali@11
|
14 |
|
ali@11
|
15 |
#ifdef WIN32
|
ali@11
|
16 |
static HANDLE bl_console=0;
|
ali@11
|
17 |
|
ali@11
|
18 |
static void bl_print_handler_console(const char *string)
|
ali@11
|
19 |
{
|
ali@11
|
20 |
long len;
|
ali@11
|
21 |
DWORD dummy;
|
ali@11
|
22 |
gunichar2 *string2;
|
ali@11
|
23 |
string2=g_utf8_to_utf16(string,-1,NULL,&len,NULL);
|
ali@11
|
24 |
if (string2)
|
ali@11
|
25 |
{
|
ali@11
|
26 |
WriteConsoleW(bl_console,string2,len,&dummy,NULL);
|
ali@11
|
27 |
g_free(string2);
|
ali@11
|
28 |
}
|
ali@11
|
29 |
}
|
ali@11
|
30 |
#endif
|
ali@11
|
31 |
|
ali@11
|
32 |
static void bl_print_handler_stdout(const char *string)
|
ali@11
|
33 |
{
|
ali@11
|
34 |
fputs(string,stdout);
|
ali@11
|
35 |
}
|
ali@11
|
36 |
|
ali@11
|
37 |
static void bl_print_handler_stderr(const char *string)
|
ali@11
|
38 |
{
|
ali@11
|
39 |
fputs(string,stderr);
|
ali@11
|
40 |
}
|
ali@11
|
41 |
|
ali@11
|
42 |
void bl_set_print_handlers(void)
|
ali@11
|
43 |
{
|
ali@11
|
44 |
#ifdef WIN32
|
ali@11
|
45 |
DWORD dummy;
|
ali@11
|
46 |
if (GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE),&dummy))
|
ali@11
|
47 |
{
|
ali@11
|
48 |
bl_console=GetStdHandle(STD_OUTPUT_HANDLE);
|
ali@11
|
49 |
g_set_print_handler(bl_print_handler_console);
|
ali@11
|
50 |
}
|
ali@11
|
51 |
else
|
ali@11
|
52 |
#endif
|
ali@11
|
53 |
g_set_print_handler(bl_print_handler_stdout);
|
ali@11
|
54 |
#ifdef WIN32
|
ali@11
|
55 |
if (GetConsoleMode(GetStdHandle(STD_ERROR_HANDLE),&dummy))
|
ali@11
|
56 |
{
|
ali@11
|
57 |
if (!bl_console)
|
ali@11
|
58 |
bl_console=GetStdHandle(STD_ERROR_HANDLE);
|
ali@11
|
59 |
g_set_printerr_handler(bl_print_handler_console);
|
ali@11
|
60 |
}
|
ali@11
|
61 |
else
|
ali@11
|
62 |
#endif
|
ali@11
|
63 |
g_set_printerr_handler(bl_print_handler_stderr);
|
ali@11
|
64 |
}
|