[Scummvm-cvs-logs] CVS: scummvm/base main.cpp,1.6,1.7

Travis Howell kirben at users.sourceforge.net
Thu Sep 25 17:10:12 CEST 2003


Update of /cvsroot/scummvm/scummvm/base
In directory sc8-pr-cvs1:/tmp/cvs-serv32173/base

Modified Files:
	main.cpp 
Log Message:

Add optional define for no console


Index: main.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/base/main.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- main.cpp	21 Sep 2003 09:06:13 -0000	1.6
+++ main.cpp	26 Sep 2003 00:09:09 -0000	1.7
@@ -85,6 +85,12 @@
 Config	*g_config = 0;
 NewGui	*g_gui = 0;
 
+#if defined(WIN32) && defined(NO_CONSOLE)
+#include <cstdio>
+#define STDOUT_FILE	TEXT("stdout.txt")
+#define STDERR_FILE	TEXT("stderr.txt")
+#endif
+
 #if defined(QTOPIA)
 // FIXME - why exactly is this needed?
 extern "C" int main(int argc, char *argv[]);
@@ -221,6 +227,41 @@
 		strcpy(scummhome, DEFAULT_CONFIG_FILE);
 	#endif
 #endif
+
+// Code copied from SDL_main
+#if defined(WIN32) && defined(NO_CONSOLE)
+
+	/* Flush the output in case anything is queued */
+	fclose(stdout);
+	fclose(stderr);
+
+	/* Redirect standard input and standard output */
+	FILE *newfp = freopen(STDOUT_FILE, "w", stdout);
+	if ( newfp == NULL ) {	/* This happens on NT */
+#if !defined(stdout)
+		stdout = fopen(STDOUT_FILE, "w");
+#else
+		newfp = fopen(STDOUT_FILE, "w");
+		if ( newfp ) {
+			*stdout = *newfp;
+		}
+#endif
+	}
+	newfp = freopen(STDERR_FILE, "w", stderr);
+	if ( newfp == NULL ) {	/* This happens on NT */
+#if !defined(stderr)
+		stderr = fopen(STDERR_FILE, "w");
+#else
+		newfp = fopen(STDERR_FILE, "w");
+		if ( newfp ) {
+			*stderr = *newfp;
+		}
+#endif
+	}
+	setvbuf(stdout, NULL, _IOLBF, BUFSIZ);	/* Line buffered */
+	setbuf(stderr, NULL);			/* No buffering */
+
+#endif //defined(WIN32) && defined(USE_CONSOLE)
 
 	// Read the config file
 	g_config = new Config(scummhome, "scummvm");





More information about the Scummvm-git-logs mailing list