]> www.fi.muni.cz Git - evince.git/blobdiff - shell/main.c
[print] Fixes segmentation violation when format is empty
[evince.git] / shell / main.c
index 2d966afdb8181eb4057fc06f676abc039a0c3c5c..214e9c0e2ea77625e246411488cc946adac31d5e 100644 (file)
 #endif
 #endif /* WITH_SMCLIENT */
 
 #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;
 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;
 
        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);
        /* Init glib threads asap */
        if (!g_thread_supported ())
                g_thread_init (NULL);