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

kjsembed

  • sources
  • kde-4.12
  • kdelibs
  • kjsembed
  • kjsembed
kjseglobal.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2004, 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
3  Copyright (C) 2004, 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
4  Copyright (C) 2004, 2005, 2006 Richard J. Moore <rich@kde.org>
5  Copyright (C) 2004, 2005, 2006 Erik L. Bunce <kde@bunce.us>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "kjseglobal.h"
24 
25 #ifdef QT_ONLY
26 # include <QObject>
27 # include <cstdio>
28 #endif
29 
30 #if defined(_WIN32) || defined(_WIN64)
31 # include <windows.h>
32 # include <fcntl.h>
33 # include <io.h>
34 # include <ios>
35 # include <QFile>
36 # include <QTextStream>
37 #endif
38 
39 static QTextStream *kjsembed_err = 0L;
40 static QTextStream *kjsembed_in = 0L;
41 static QTextStream *kjsembed_out = 0L;
42 
43 #if defined(_WIN32) || defined(_WIN64)
44 static QFile win32_stdin;
45 static QFile win32_stdout;
46 static QFile win32_stderr;
47 
48 static const WORD MAX_CONSOLE_LINES = 500;
49 
50 void RedirectIOToConsole() {
51  int hConHandle;
52  intptr_t lStdHandle;
53  CONSOLE_SCREEN_BUFFER_INFO coninfo;
54  AllocConsole();
55  GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
56  coninfo.dwSize.Y = MAX_CONSOLE_LINES;
57  SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
58 
59  lStdHandle = (intptr_t)GetStdHandle(STD_INPUT_HANDLE);
60  hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
61  win32_stdin.open(hConHandle,QIODevice::ReadOnly);
62 
63  lStdHandle = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE);
64  hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
65  win32_stdout.open(hConHandle,QIODevice::WriteOnly);
66 
67  lStdHandle = (intptr_t)GetStdHandle(STD_ERROR_HANDLE);
68  hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
69  win32_stderr.open(hConHandle, QIODevice::WriteOnly);
70 
71  std::ios::sync_with_stdio();
72 
73 }
74 
75 
76 
77 #endif
78 
79 
80 QTextStream &consoleOut( )
81 {
82  return *KJSEmbed::conout();
83 }
84 
85 QTextStream &consoleError( )
86 {
87  return *KJSEmbed::conerr();
88 }
89 
90 QTextStream &consoleIn( )
91 {
92  return *KJSEmbed::conin();
93 }
94 
95 #ifdef QT_ONLY
96 QTextStream &kdDebug( int area )
97 {
98 #ifndef QT_DEBUG
99  return consoleError() << "DEBUG: (" << area << ") ";
100 #else
101  return consoleOut();
102 #endif
103 
104 }
105 
106 QTextStream &kdWarning( int area )
107 {
108  return consoleOut() << "WARNING: (" << area << ") ";
109 }
110 
111 QString i18n( const char *string )
112 {
113  return QObject::tr( string, "qjsembed string");
114 }
115 
116 #endif
117 
118 QTextStream *KJSEmbed::conin()
119 {
120  if ( !kjsembed_in ) {
121 #ifdef _WIN32
122  kjsembed_in = new QTextStream( &win32_stdin );
123 #else
124  kjsembed_in = new QTextStream( stdin, QIODevice::ReadOnly );
125 #endif
126  }
127  return kjsembed_in;
128 }
129 
130 QTextStream *KJSEmbed::conout()
131 {
132  if ( !kjsembed_out ) {
133 #ifdef _WIN32
134  kjsembed_out = new QTextStream( &win32_stdout );
135 #else
136  kjsembed_out = new QTextStream( stdout, QIODevice::WriteOnly );
137 #endif
138  }
139  return kjsembed_out;
140 
141 }
142 
143 QTextStream *KJSEmbed::conerr()
144 {
145  if ( !kjsembed_err ) {
146 #ifdef _WIN32
147  kjsembed_err = new QTextStream( &win32_stderr );
148 #else
149  kjsembed_err = new QTextStream( stderr, QIODevice::WriteOnly );
150 #endif
151  }
152  return kjsembed_err;
153 }
154 
155 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;
consoleError
QTextStream & consoleError()
Definition: kjseglobal.cpp:85
KJSEmbed::conin
KJSEMBED_EXPORT QTextStream * conin()
Definition: kjseglobal.cpp:118
kjsembed_err
static QTextStream * kjsembed_err
Definition: kjseglobal.cpp:39
KJSEmbed::conout
KJSEMBED_EXPORT QTextStream * conout()
Definition: kjseglobal.cpp:130
consoleOut
QTextStream & consoleOut()
Definition: kjseglobal.cpp:80
consoleIn
QTextStream & consoleIn()
Definition: kjseglobal.cpp:90
kjseglobal.h
kjsembed_in
static QTextStream * kjsembed_in
Definition: kjseglobal.cpp:40
kjsembed_out
static QTextStream * kjsembed_out
Definition: kjseglobal.cpp:41
KJSEmbed::conerr
KJSEMBED_EXPORT QTextStream * conerr()
Definition: kjseglobal.cpp:143
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kjsembed

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal