Blame synfig-studio/src/gui/main_win32.cpp

0d86cb
/*
0d86cb
For general Scribus (>=1.3.2) copyright and licensing information please refer
0d86cb
to the COPYING file provided with the program. Following this notice may exist
0d86cb
a copyright and/or license notice that predates the release of Scribus 1.3.2
0d86cb
for which a new license (GPL+exception) is in place.
0d86cb
*/
0d86cb
/***************************************************************************
0d86cb
						main.cpp  -  description
0d86cb
							-------------------
0d86cb
	begin                : Fre Apr  6 21:47:55 CEST 2001
0d86cb
	copyright            : (C) 2001 by Franz Schmid
0d86cb
	email                : Franz.Schmid@altmuehlnet.de
0d86cb
	copyright            : (C) 2004 by Alessandro Rimoldi
0d86cb
	email                : http://ideale.ch/contact
0d86cb
	copyright            : (C) 2005 by Craig Bradney
0d86cb
	email                : cbradney@zip.com.au
0d86cb
***************************************************************************/
0d86cb
0d86cb
/***************************************************************************
0d86cb
*                                                                         *
0d86cb
*   This program is free software; you can redistribute it and/or modify  *
0d86cb
*   it under the terms of the GNU General Public License as published by  *
0d86cb
*   the Free Software Foundation; either version 2 of the License, or     *
0d86cb
*   (at your option) any later version.                                   *
0d86cb
*                                                                         *
0d86cb
***************************************************************************/
0d86cb
10a93e
#ifdef _WIN32
650c7f
0d86cb
#include <iostream></iostream>
0d86cb
#include <signal.h></signal.h>
0d86cb
#include <stdio.h></stdio.h>
0d86cb
#include <fcntl.h></fcntl.h>
0d86cb
#include <io.h></io.h>
0d86cb
using namespace std;
0d86cb
0d86cb
#define MAX_LINES 500
0d86cb
0d86cb
#include <windows.h></windows.h>
0d86cb
#include <wincon.h></wincon.h>
0d86cb
0d86cb
bool consoleOptionEnabled(int argc, char* argv[])
0d86cb
{
0d86cb
	bool value = false;
0d86cb
	for (int i = 0; i < argc; i++)
0d86cb
	{
da71a8
		if (strcmp(argv[i], "--console") == 0 ||
da71a8
			strcmp(argv[i], "-c") == 0)
0d86cb
		{
0d86cb
			value = true;
0d86cb
			break;
0d86cb
		}
0d86cb
	}
0d86cb
	return value;
0d86cb
}
0d86cb
da71a8
void redirectIOToConsole()
0d86cb
{
0d86cb
	int hConHandle;
0d86cb
	HANDLE lStdHandle;
0d86cb
	CONSOLE_SCREEN_BUFFER_INFO coninfo;
0d86cb
	FILE *fp;
0d86cb
0d86cb
	// allocate console
0d86cb
	if( GetStdHandle(STD_OUTPUT_HANDLE) != INVALID_HANDLE_VALUE )
0d86cb
		AllocConsole();
0d86cb
	// set the screen buffer to be big enough to let us scroll text
0d86cb
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
0d86cb
	coninfo.dwSize.Y = MAX_LINES;
0d86cb
	SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
0d86cb
	//redirect unbuffered STDOUT to the console
0d86cb
	lStdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
0d86cb
	hConHandle = _open_osfhandle((intptr_t) lStdHandle, _O_TEXT);
0d86cb
	fp = _fdopen( hConHandle, "w" );
0d86cb
	*stdout = *fp;
0d86cb
	setvbuf( stdout, NULL, _IONBF, 0 );
0d86cb
	// redirect unbuffered STDIN to the console
0d86cb
	lStdHandle = GetStdHandle(STD_INPUT_HANDLE);
0d86cb
	hConHandle = _open_osfhandle((intptr_t) lStdHandle, _O_TEXT);
0d86cb
	fp = _fdopen( hConHandle, "r" );
0d86cb
	*stdin = *fp;
0d86cb
	setvbuf( stdin, NULL, _IONBF, 0 );
0d86cb
	// redirect unbuffered STDERR to the console
0d86cb
	lStdHandle = GetStdHandle(STD_ERROR_HANDLE);
0d86cb
	hConHandle = _open_osfhandle((intptr_t) lStdHandle, _O_TEXT);
0d86cb
	fp = _fdopen( hConHandle, "w" );
0d86cb
	*stderr = *fp;
0d86cb
	setvbuf( stderr, NULL, _IONBF, 0 );
0d86cb
	// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog 
0d86cb
	// point to console as well
0d86cb
	ios::sync_with_stdio();
0d86cb
}
650c7f
650c7f
#endif /* WIN32 */