summaryrefslogtreecommitdiffstats
path: root/kjsembed/global.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /kjsembed/global.cpp
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kjsembed/global.cpp')
-rw-r--r--kjsembed/global.cpp178
1 files changed, 178 insertions, 0 deletions
diff --git a/kjsembed/global.cpp b/kjsembed/global.cpp
new file mode 100644
index 00000000..1f424dcd
--- /dev/null
+++ b/kjsembed/global.cpp
@@ -0,0 +1,178 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Richard Moore *
+ * rich@kde.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU Library General Public License as *
+ * published by the Free Software Foundation; either version 2 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Library General Public *
+ * License along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+# include "global.h"
+
+#ifdef QT_ONLY
+# include <qobject.h>
+# include <cstdio>
+# ifdef _WIN32
+# include <windows.h>
+# include <fcntl.h>
+# include <io.h>
+# include <iostream.h>
+# include <qfile.h>
+# endif
+#endif
+
+static QTextStream *kjsembed_err = 0L;
+static QTextStream *kjsembed_in = 0L;
+static QTextStream *kjsembed_out = 0L;
+
+#ifndef _WIN32
+char *itoa(int num, char *str, int radix)
+{
+ int k;
+ char c, flag, *ostr;
+
+ if (num < 0) {
+ num = -num;
+ *str++ = '-';
+ }
+ k = 10000;
+ ostr = str;
+ flag = 0;
+ while (k) {
+ c = num / k;
+ if (c || k == 1 || flag) {
+ num %= k;
+ c += '0';
+ *str++ = c;
+ flag = 1;
+ }
+ k /= 10;
+ }
+ *str = '\0';
+ return ostr;
+}
+
+#endif
+
+#ifdef _WIN32
+static QFile win32_stdin;
+static QFile win32_stdout;
+static QFile win32_stderr;
+
+static const WORD MAX_CONSOLE_LINES = 500;
+
+void RedirectIOToConsole() {
+ int hConHandle;
+ long lStdHandle;
+ CONSOLE_SCREEN_BUFFER_INFO coninfo;
+ AllocConsole();
+ GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
+ coninfo.dwSize.Y = MAX_CONSOLE_LINES;
+ SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
+
+ lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
+ hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
+ win32_stdin.open(IO_ReadOnly,hConHandle);
+
+ lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
+ hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
+ win32_stdout.open(IO_WriteOnly,hConHandle );
+
+ lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
+ hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
+ win32_stderr.open(IO_WriteOnly,hConHandle);
+
+ ios::sync_with_stdio();
+
+}
+
+
+
+#endif
+
+
+QTextStream &consoleOut( )
+{
+ return *KJSEmbed::conout();
+}
+
+QTextStream &consoleError( )
+{
+ return *KJSEmbed::conerr();
+}
+
+QTextStream &consoleIn( )
+{
+ return *KJSEmbed::conin();
+}
+
+#ifdef QT_ONLY
+QTextStream &kdDebug( int area )
+{
+#ifndef QT_DEBUG
+ return consoleError() << "DEBUG: (" << area << ") ";
+#else
+ return consoleOut();
+#endif
+
+}
+
+QTextStream &kdWarning( int area )
+{
+ return consoleOut() << "WARNING: (" << area << ") ";
+}
+
+QString i18n( const char *string )
+{
+ return QObject::tr( string, "qjsembed string");
+}
+
+#endif
+
+QTextStream *KJSEmbed::conin()
+{
+ if ( !kjsembed_in ) {
+#ifdef _WIN32
+ kjsembed_in = new QTextStream( &win32_stdin );
+#else
+ kjsembed_in = new QTextStream( stdin, IO_ReadOnly );
+#endif
+ }
+ return kjsembed_in;
+}
+
+QTextStream *KJSEmbed::conout()
+{
+ if ( !kjsembed_out ) {
+#ifdef _WIN32
+ kjsembed_out = new QTextStream( &win32_stdout );
+#else
+ kjsembed_out = new QTextStream( stdout, IO_WriteOnly );
+#endif
+ }
+ return kjsembed_out;
+
+}
+
+QTextStream *KJSEmbed::conerr()
+{
+ if ( !kjsembed_err ) {
+#ifdef _WIN32
+ kjsembed_err = new QTextStream( &win32_stderr );
+#else
+ kjsembed_err = new QTextStream( stderr, IO_WriteOnly );
+#endif
+ }
+ return kjsembed_err;
+}