• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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 char *itoa(int num, char *str, int /*radix*/)
00045 {
00046    int k;
00047    char c, flag, *ostr;
00048 
00049    if (num < 0) {
00050       num = -num;
00051       *str++ = '-';
00052    }
00053    k = 10000;
00054    ostr = str;
00055    flag = 0;
00056    while (k) {
00057       c = num / k;
00058       if (c || k == 1 || flag) {
00059          num %= k;
00060          c += '0';
00061          *str++ = c;
00062          flag = 1;
00063       }
00064       k /= 10;
00065    }
00066    *str = '\0';
00067    return ostr;
00068 }
00069 
00070 #endif
00071 
00072 #if defined(_WIN32) || defined(_WIN64)
00073 static QFile win32_stdin;
00074 static QFile win32_stdout;
00075 static QFile win32_stderr;
00076 
00077 static const WORD MAX_CONSOLE_LINES = 500;
00078 
00079 void RedirectIOToConsole() {
00080    int hConHandle;
00081    long lStdHandle;
00082    CONSOLE_SCREEN_BUFFER_INFO coninfo;
00083    AllocConsole();
00084    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
00085    coninfo.dwSize.Y = MAX_CONSOLE_LINES;
00086    SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
00087 
00088    lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
00089    hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
00090    win32_stdin.open(hConHandle,QIODevice::ReadOnly);
00091 
00092    lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
00093    hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
00094    win32_stdout.open(hConHandle,QIODevice::WriteOnly);
00095 
00096    lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
00097    hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
00098    win32_stderr.open(hConHandle, QIODevice::WriteOnly);
00099 
00100    std::ios::sync_with_stdio();
00101 
00102 }
00103 
00104 
00105 
00106 #endif
00107 
00108 
00109 QTextStream &consoleOut(  )
00110 {
00111    return *KJSEmbed::conout();
00112 }
00113 
00114 QTextStream &consoleError( )
00115 {
00116    return *KJSEmbed::conerr();
00117 }
00118 
00119 QTextStream &consoleIn( )
00120 {
00121    return *KJSEmbed::conin();
00122 }
00123 
00124 #ifdef QT_ONLY
00125 QTextStream &kdDebug( int area )
00126 {
00127 #ifndef QT_DEBUG
00128    return consoleError() << "DEBUG: (" << area << ") ";
00129 #else
00130    return consoleOut();
00131 #endif
00132 
00133 }
00134 
00135 QTextStream &kdWarning( int area )
00136 {
00137    return consoleOut() << "WARNING: (" << area << ") ";
00138 }
00139 
00140 QString i18n( const char *string )
00141 {
00142     return QObject::tr( string, "qjsembed string");
00143 }
00144 
00145 #endif
00146 
00147 QTextStream *KJSEmbed::conin()
00148 {
00149    if ( !kjsembed_in ) {
00150 #ifdef _WIN32
00151        kjsembed_in = new QTextStream( &win32_stdin );
00152 #else
00153        kjsembed_in = new QTextStream( stdin, QIODevice::ReadOnly );
00154 #endif
00155    }
00156    return kjsembed_in;
00157 }
00158 
00159 QTextStream *KJSEmbed::conout()
00160 {
00161    if ( !kjsembed_out ) {
00162 #ifdef _WIN32
00163        kjsembed_out = new QTextStream( &win32_stdout  );
00164 #else
00165        kjsembed_out = new QTextStream( stdout, QIODevice::WriteOnly );
00166 #endif
00167    }
00168    return kjsembed_out;
00169 
00170 }
00171 
00172 QTextStream *KJSEmbed::conerr()
00173 {
00174    if ( !kjsembed_err ) {
00175 #ifdef _WIN32
00176        kjsembed_err = new QTextStream( &win32_stderr  );
00177 #else
00178        kjsembed_err = new QTextStream( stderr, QIODevice::WriteOnly );
00179 #endif
00180    }
00181    return kjsembed_err;
00182 }
00183 
00184 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;

kjsembed

Skip menu "kjsembed"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal