Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFridrich Strba <fridrich.strba@bluewin.ch>2009-06-23 07:14:52 (GMT)
committer Fridrich Strba <fridrich.strba@bluewin.ch>2009-06-23 07:14:52 (GMT)
commit78ac55ced8691adfa03e4efbd139897599fca7b3 (patch)
treef36b12e1caba15f763f427e4c13adf92da9cc691
parentf575f06bfcb2e335f6b2089b3dba570e1da77198 (diff)
On Windows, when called from a console, get console output (works only
with Windows XP or higher. Windows 2000 will not have console output but it will just work fine.)
-rw-r--r--previewer/ev-previewer.c34
-rw-r--r--shell/main.c35
-rw-r--r--thumbnailer/evince-thumbnailer.c10
3 files changed, 79 insertions, 0 deletions
diff --git a/previewer/ev-previewer.c b/previewer/ev-previewer.c
index afe2127..5c1980a 100644
--- a/previewer/ev-previewer.c
+++ b/previewer/ev-previewer.c
@@ -27,6 +27,16 @@
#include "ev-previewer-window.h"
+#ifdef G_OS_WIN32
+#ifdef DATADIR
+#undef DATADIR
+#endif
+#include <io.h>
+#include <conio.h>
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#endif
+
static gboolean unlink_temp_file = FALSE;
static const gchar *print_settings;
static const gchar **filenames;
@@ -93,6 +103,30 @@ main (gint argc, gchar **argv)
const gchar *filename;
GError *error = NULL;
+#ifdef G_OS_WIN32
+ if (fileno (stdout) != -1 &&
+ _get_osfhandle (fileno (stdout)) != -1)
+ {
+ /* stdout is fine, presumably redirected to a file or pipe */
+ }
+ else
+ {
+ typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
+
+ AttachConsole_t p_AttachConsole =
+ (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");
+
+ if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
+ {
+ freopen ("CONOUT$", "w", stdout);
+ dup2 (fileno (stdout), 1);
+ freopen ("CONOUT$", "w", stderr);
+ dup2 (fileno (stderr), 2);
+
+ }
+ }
+#endif
+
/* Init glib threads asap */
if (!g_thread_supported ())
g_thread_init (NULL);
diff --git a/shell/main.c b/shell/main.c
index 2d966af..214e9c0 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -45,6 +45,16 @@
#endif
#endif /* WITH_SMCLIENT */
+#ifdef G_OS_WIN32
+#ifdef DATADIR
+#undef DATADIR
+#endif
+#include <io.h>
+#include <conio.h>
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#endif
+
static gchar *ev_page_label;
static gchar *ev_find_string;
static gboolean preview_mode = FALSE;
@@ -387,6 +397,31 @@ main (int argc, char *argv[])
GHashTable *args;
GError *error = NULL;
+#ifdef G_OS_WIN32
+
+ if (fileno (stdout) != -1 &&
+ _get_osfhandle (fileno (stdout)) != -1)
+ {
+ /* stdout is fine, presumably redirected to a file or pipe */
+ }
+ else
+ {
+ typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
+
+ AttachConsole_t p_AttachConsole =
+ (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");
+
+ if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
+ {
+ freopen ("CONOUT$", "w", stdout);
+ dup2 (fileno (stdout), 1);
+ freopen ("CONOUT$", "w", stderr);
+ dup2 (fileno (stderr), 2);
+
+ }
+ }
+#endif
+
/* Init glib threads asap */
if (!g_thread_supported ())
g_thread_init (NULL);
diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c
index 3598fdf..457ceea 100644
--- a/thumbnailer/evince-thumbnailer.c
+++ b/thumbnailer/evince-thumbnailer.c
@@ -25,6 +25,16 @@
#include <stdlib.h>
#include <string.h>
+#ifdef G_OS_WIN32
+#ifdef DATADIR
+#undef DATADIR
+#endif
+#include <io.h>
+#include <conio.h>
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#endif
+
#define THUMBNAIL_SIZE 128
static gint size = THUMBNAIL_SIZE;