kjsembed
kjseglobal.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2004, 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org> 00003 Copyright (C) 2004, 2005, 2006 Matt Broadstone <mbroadst@gmail.com> 00004 Copyright (C) 2004, 2005, 2006 Richard J. Moore <rich@kde.org> 00005 Copyright (C) 2004, 2005, 2006 Erik L. Bunce <kde@bunce.us> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include "kjseglobal.h" 00024 00025 #ifdef QT_ONLY 00026 # include <QObject> 00027 # include <cstdio> 00028 #endif 00029 00030 #if defined(_WIN32) || defined(_WIN64) 00031 # include <windows.h> 00032 # include <fcntl.h> 00033 # include <io.h> 00034 # include <ios> 00035 # include <QFile> 00036 # include <QTextStream> 00037 #endif 00038 00039 static QTextStream *kjsembed_err = 0L; 00040 static QTextStream *kjsembed_in = 0L; 00041 static QTextStream *kjsembed_out = 0L; 00042 00043 #if defined(_WIN32) || defined(_WIN64) 00044 static QFile win32_stdin; 00045 static QFile win32_stdout; 00046 static QFile win32_stderr; 00047 00048 static const WORD MAX_CONSOLE_LINES = 500; 00049 00050 void RedirectIOToConsole() { 00051 int hConHandle; 00052 intptr_t lStdHandle; 00053 CONSOLE_SCREEN_BUFFER_INFO coninfo; 00054 AllocConsole(); 00055 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo); 00056 coninfo.dwSize.Y = MAX_CONSOLE_LINES; 00057 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize); 00058 00059 lStdHandle = (intptr_t)GetStdHandle(STD_INPUT_HANDLE); 00060 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); 00061 win32_stdin.open(hConHandle,QIODevice::ReadOnly); 00062 00063 lStdHandle = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE); 00064 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); 00065 win32_stdout.open(hConHandle,QIODevice::WriteOnly); 00066 00067 lStdHandle = (intptr_t)GetStdHandle(STD_ERROR_HANDLE); 00068 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); 00069 win32_stderr.open(hConHandle, QIODevice::WriteOnly); 00070 00071 std::ios::sync_with_stdio(); 00072 00073 } 00074 00075 00076 00077 #endif 00078 00079 00080 QTextStream &consoleOut( ) 00081 { 00082 return *KJSEmbed::conout(); 00083 } 00084 00085 QTextStream &consoleError( ) 00086 { 00087 return *KJSEmbed::conerr(); 00088 } 00089 00090 QTextStream &consoleIn( ) 00091 { 00092 return *KJSEmbed::conin(); 00093 } 00094 00095 #ifdef QT_ONLY 00096 QTextStream &kdDebug( int area ) 00097 { 00098 #ifndef QT_DEBUG 00099 return consoleError() << "DEBUG: (" << area << ") "; 00100 #else 00101 return consoleOut(); 00102 #endif 00103 00104 } 00105 00106 QTextStream &kdWarning( int area ) 00107 { 00108 return consoleOut() << "WARNING: (" << area << ") "; 00109 } 00110 00111 QString i18n( const char *string ) 00112 { 00113 return QObject::tr( string, "qjsembed string"); 00114 } 00115 00116 #endif 00117 00118 QTextStream *KJSEmbed::conin() 00119 { 00120 if ( !kjsembed_in ) { 00121 #ifdef _WIN32 00122 kjsembed_in = new QTextStream( &win32_stdin ); 00123 #else 00124 kjsembed_in = new QTextStream( stdin, QIODevice::ReadOnly ); 00125 #endif 00126 } 00127 return kjsembed_in; 00128 } 00129 00130 QTextStream *KJSEmbed::conout() 00131 { 00132 if ( !kjsembed_out ) { 00133 #ifdef _WIN32 00134 kjsembed_out = new QTextStream( &win32_stdout ); 00135 #else 00136 kjsembed_out = new QTextStream( stdout, QIODevice::WriteOnly ); 00137 #endif 00138 } 00139 return kjsembed_out; 00140 00141 } 00142 00143 QTextStream *KJSEmbed::conerr() 00144 { 00145 if ( !kjsembed_err ) { 00146 #ifdef _WIN32 00147 kjsembed_err = new QTextStream( &win32_stderr ); 00148 #else 00149 kjsembed_err = new QTextStream( stderr, QIODevice::WriteOnly ); 00150 #endif 00151 } 00152 return kjsembed_err; 00153 } 00154 00155 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;
KDE 4.6 API Reference