[gedit] When opeing gedit from console on win32 visualize the stdout.



commit d4ead5e444d38775157b9e49b0d58f6e1e7e9f3a
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Jun 17 22:49:30 2009 +0200

    When opeing gedit from console on win32 visualize the stdout.

 gedit/gedit.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/gedit/gedit.c b/gedit/gedit.c
index d9633d5..6a5b33a 100644
--- a/gedit/gedit.c
+++ b/gedit/gedit.c
@@ -63,6 +63,9 @@
 #ifdef G_OS_WIN32
 #define SAVE_DATADIR DATADIR
 #undef DATADIR
+#include <io.h>
+#include <conio.h>
+#define _WIN32_WINNT 0x0500
 #include <windows.h>
 #define DATADIR SAVE_DATADIR
 #undef SAVE_DATADIR
@@ -563,6 +566,29 @@ main (int argc, char *argv[])
 
 #ifdef G_OS_WIN32
 	setup_path ();
+
+	/* If we open gedit from a console get the stdout printing */
+	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
 
 	gtk_init (&argc, &argv);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]