[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kdecore/kernel
From:       Ralf Habacker <Ralf.Habacker () freenet ! de>
Date:       2009-03-31 20:08:32
Message-ID: 1238530112.278172.20583.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 947583 by habacker:

reverted last patch as it breaks kdecore for normal applications

 M  +88 -99    kkernel_win.cpp  


--- trunk/KDE/kdelibs/kdecore/kernel/kkernel_win.cpp #947582:947583
@@ -89,70 +89,6 @@
   return kde4Prefix ? *kde4Prefix : QString::fromUtf16((ushort*) kde4prefixUtf16);
 }
 
-#include <streambuf>
-
-/** 
-  ios related debug message printer for win32
-*/
-class debug_streambuf: public std::streambuf
-{
-    public:
-        debug_streambuf(char *prefix)
-        {
-            strcpy(buf,prefix);
-            index = rindex = strlen(buf);
-        }
-
-    protected:
-        virtual int overflow(int c = EOF)
-        {
-            if (c != EOF)
-            {
-                char cc = traits_type::to_char_type(c);
-                // @TODO: buffer size checking
-                buf[index++] = cc;
-                if (cc == '\n')
-                {
-                    buf[index] = '\0';
-                    OutputDebugStringA((LPCSTR)buf);
-                    index = rindex;
-                }
-            }
-            return traits_type::not_eof(c);
-        }
-    private:
-        char buf[4096];
-        int index, rindex;
-};
-
-static class kMessageOutputInstaller {
-    public:
-        kMessageOutputInstaller() 
-            : stdoutBuffer("stdout:")
-            , stderrBuffer("stderr:")
-            , oldStdoutBuffer(0)
-            , oldStderrBuffer(0)
-        {
-        }
-
-        ~kMessageOutputInstaller()
-        {
-            if (oldStdoutBuffer) 
-                std::cout.rdbuf(oldStdoutBuffer);
-            if (oldStderrBuffer) 
-                std::cerr.rdbuf(oldStderrBuffer);
-        }
-    
-        void registerHandler(HINSTANCE hInst);
-
-    private:
-        debug_streambuf stdoutBuffer;
-        debug_streambuf stderrBuffer;
-        std::streambuf* oldStdoutBuffer;
-        std::streambuf* oldStderrBuffer;
-
-} kMessageOutputInstallerInstance;
-
 /**
  * The dll entry point - get the instance handle for GetModuleFleNameW
  * Maybe also some special initialization / cleanup can be done here
@@ -162,7 +98,6 @@
 {
     switch ( fdwReason ) {
     case DLL_PROCESS_ATTACH:
-        kMessageOutputInstallerInstance.registerHandler(hinstDLL);
         kdecoreDllInstance = hinstDLL;
         initKde4prefixUtf16();
         kde4Prefix = new QString( QString::fromUtf16((ushort*) kde4prefixUtf16) );
@@ -378,17 +313,53 @@
     ios::sync_with_stdio();
 }
 
+#include <streambuf>
+
+/** 
+  ios related debug message printer for win32
+*/
+class debug_streambuf: public std::streambuf
+{
+    public:
+        debug_streambuf(char *prefix)
+        {
+            strcpy(buf,prefix);
+            index = rindex = strlen(buf);
+        }
+
+    protected:
+        virtual int overflow(int c = EOF)
+        {
+            if (c != EOF)
+            {
+                char cc = traits_type::to_char_type(c);
+                // @TODO: buffer size checking
+                buf[index++] = cc;
+                if (cc == '\n')
+                {
+                    buf[index] = '\0';
+                    OutputDebugStringA((LPCSTR)buf);
+                    index = rindex;
+                }
+            }
+            return traits_type::not_eof(c);
+        }
+    private:
+        char buf[4096];
+        int index, rindex;
+};
+
 /**
   retrieve type of win32 subsystem from the executable header 
   \return type of win32 subsystem - the subsystem types are defined at \
                http://msdn.microsoft.com/en-us/library/ms680339(VS.85).aspx 
 */
-static int subSystem(HINSTANCE hInst)
+static int subSystem()
 {
     static int subSystem = -1;
     if (subSystem > -1)
         return subSystem; 
 
-    PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)hInst;
+    PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)0x00400000;
     PIMAGE_NT_HEADERS ntHeader = (PIMAGE_NT_HEADERS) ((char *)dosHeader + \
dosHeader->e_lfanew);  if (ntHeader->Signature != 0x00004550) 
     {
@@ -425,41 +396,59 @@
 /**
  setup up debug output 
 */ 
-void kMessageOutputInstaller::registerHandler(HINSTANCE hInst)
-{
-    if (subSystem(hInst) == IMAGE_SUBSYSTEM_WINDOWS_CUI) {
-        if (attachToConsole()) {
-            // setup kde and qt level 
-            qInstallMsgHandler(kMessageOutputFileIO);
-            // redirect ios and file io to console
-            redirectToConsole();
+static class kMessageOutputInstaller {
+    public:
+        kMessageOutputInstaller() : stdoutBuffer("stdout:"), \
stderrBuffer("stderr:"), oldStdoutBuffer(0), oldStderrBuffer(0) +        {
+            if (subSystem() == IMAGE_SUBSYSTEM_WINDOWS_CUI) {
+                if (attachToConsole()) {
+                    // setup kde and qt level 
+                    qInstallMsgHandler(kMessageOutputFileIO);
+                    // redirect ios and file io to console
+                    redirectToConsole();
+                }
+                else {
+                    // setup kde and qt level 
+                    qInstallMsgHandler(kMessageOutputDebugString);
+                    // redirect ios to debug message port 
+                    oldStdoutBuffer = std::cout.rdbuf(&stdoutBuffer);
+                    oldStderrBuffer = std::cerr.rdbuf(&stderrBuffer);
+                }
+            }
+            else if (subSystem() == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
+                // setup kde and qt level 
+                qInstallMsgHandler(kMessageOutputDebugString);
+                // try to get a console
+                if (attachToConsole()) {
+                    redirectToConsole();
+                }
+                else {
+                    // redirect ios to debug message port
+                    oldStdoutBuffer = std::cout.rdbuf(&stdoutBuffer);
+                    oldStderrBuffer = std::cerr.rdbuf(&stderrBuffer);
+                    // TODO: redirect FILE * level to console, no idea how to do yet
+                }
+            }
+            else
+                qWarning("unknown subsystem %d detected, could not setup qt message \
handler",subSystem());  }
-        else {
-            // setup kde and qt level 
-            qInstallMsgHandler(kMessageOutputDebugString);
-            // redirect ios to debug message port 
-            oldStdoutBuffer = std::cout.rdbuf(&stdoutBuffer);
-            oldStderrBuffer = std::cerr.rdbuf(&stderrBuffer);
+        ~kMessageOutputInstaller()
+        {
+            if (oldStdoutBuffer) 
+                std::cout.rdbuf(oldStdoutBuffer);
+            if (oldStderrBuffer) 
+                std::cerr.rdbuf(oldStderrBuffer);
         }
-    }
-    else if (subSystem(hInst) == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
-        // setup kde and qt level 
-        qInstallMsgHandler(kMessageOutputDebugString);
-        // try to get a console
-        if (attachToConsole()) {
-            redirectToConsole();
-        }
-        else {
-            // redirect ios to debug message port
-            oldStdoutBuffer = std::cout.rdbuf(&stdoutBuffer);
-            oldStderrBuffer = std::cerr.rdbuf(&stderrBuffer);
-            // TODO: redirect FILE * level to console, no idea how to do yet
-        }
-    }
-    else
-        qWarning("unknown subsystem %d detected, could not setup qt message \
                handler",subSystem(hInst));
-}
+    
+    private:
+        debug_streambuf stdoutBuffer;
+        debug_streambuf stderrBuffer;
+        std::streambuf* oldStdoutBuffer;
+        std::streambuf* oldStderrBuffer;
 
+} kMessageOutputInstallerInstance;
+
+
 bool isExecutable(const QString &file)
 {
   return ( file.endsWith( QLatin1String( ".exe" ) ) ||


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic