Changeset 173 for trunk


Ignore:
Timestamp:
Nov 6, 2007, 11:00:00 PM (18 years ago)
Author:
dmik
Message:

Tools: Added the new printing procedure for qDebug(), qWarning() etc. that is capable of redirecting output to a file (set by the QT_PM_DEBUG_FILE=<file_name> environment variable), to the PmPrintf queue (set by the QT_PM_DEBUG_QUEUE environment variable), or to the standard error stream as usual (by default).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tools/qglobal.cpp

    r133 r173  
    5151#if defined(Q_OS_OS2)
    5252#include "qt_os2.h"
     53#include <time.h>
    5354#endif
    5455
     
    448449
    449450
    450 #ifdef Q_CC_MWERKS
     451#if defined(Q_CC_MWERKS)
    451452
    452453#include "qt_mac.h"
     
    464465}
    465466
    466 #endif
    467 
     467#elif defined(Q_OS_OS2)
     468
     469// OS/2 PmPrintf debug output function
     470
     471static
     472void qPmPrint( const char *buf )
     473{
     474    // recognized environment variables:
     475    // QT_PM_DEBUG_FILE=<filename>   output to file
     476    // QT_PM_DEBUG_QUEUE             output to queue \QUEUES\PRINTF32
     477    //                               that can be read e.g. by PmPrintf
     478    // <nothing>                     output to stderr
     479
     480    char const *queue_env = ::getenv( "QT_PM_DEBUG_QUEUE" ),
     481               *file_env = ::getenv( "QT_PM_DEBUG_FILE" );
     482
     483    if ( queue_env != 0 ) {
     484        PID srvPid;
     485        HQUEUE queue;
     486        if ( ::DosOpenQueue( &srvPid, &queue, "\\QUEUES\\PRINTF32" ) == NO_ERROR ) {
     487            char* shrBuf;
     488            unsigned long bufSize = ::strlen(buf) + 1;
     489            if ( ::DosAllocSharedMem( (PPVOID) &shrBuf, NULL, bufSize,
     490                                      OBJ_GIVEABLE | PAG_WRITE |
     491                                      PAG_COMMIT ) != NO_ERROR ) {
     492                ::DosSleep( 200 ); // give it a second chance...
     493                if ( ::DosAllocSharedMem( (PPVOID) &shrBuf, NULL, bufSize,
     494                                          OBJ_GIVEABLE | PAG_WRITE |
     495                                          PAG_COMMIT ) != NO_ERROR ) {
     496                    ::DosCloseQueue( queue );
     497                    return; // give up...
     498                }
     499            }
     500            ::strcpy( shrBuf, buf );
     501
     502            if ( ::DosGiveSharedMem( shrBuf, srvPid, PAG_READ ) == NO_ERROR ) {
     503                time_t tt;
     504                ::time(&tt);
     505                ::DosWriteQueue( queue, (ULONG)tt, bufSize, shrBuf, 0 );
     506            }
     507
     508            ::DosFreeMem( shrBuf );
     509            ::DosCloseQueue( queue );
     510
     511            return;
     512        }
     513    } else if ( file_env != 0 ) {
     514        FILE* f = ::fopen( file_env, "a" );
     515        if( f != 0 )
     516        {
     517            ::fprintf( f, "%s\n", buf );
     518            ::fclose( f );
     519            return;
     520        }
     521    } else {
     522        ::fprintf( stderr, "%s\n", buf );
     523    }
     524}
     525
     526#endif
    468527
    469528void qDebug( const char *msg, ... )
     
    488547        QString fstr( buf );
    489548        OutputDebugString( (fstr + "\n").ucs2() );
     549#elif defined(Q_OS_OS2)
     550        qPmPrint( buf );
    490551#else
    491552        fprintf( stderr, "%s\n", buf );         // add newline
     
    516577        QString fstr( buf );
    517578        OutputDebugString( (fstr + "\n").ucs2() );
     579#elif defined(Q_OS_OS2)
     580        qPmPrint( buf );
    518581#else
    519582        fprintf( stderr, "%s\n", buf );         // add newline
     
    543606        QString fstr( buf );
    544607        OutputDebugString( (fstr + "\n").ucs2() );
     608#elif defined(Q_OS_OS2)
     609        qPmPrint( buf );
    545610#else
    546611        fprintf( stderr, "%s\n", buf );         // add newline
     
    572637        QString fstr( buf );
    573638        OutputDebugString( (fstr + "\n").ucs2() );
     639#elif defined(Q_OS_OS2)
     640        qPmPrint( buf );
    574641#else
    575642        fprintf( stderr, "%s\n", buf );         // add newline
     
    596663#if defined(Q_CC_MWERKS)
    597664        mac_default_handler(buf);
     665#elif defined(Q_OS_OS2)
     666        qPmPrint( buf );
    598667#else
    599668        fprintf( stderr, "%s\n", buf );         // add newline
     
    632701#if defined(Q_CC_MWERKS)
    633702        mac_default_handler(buf);
     703#elif defined(Q_OS_OS2)
     704        qPmPrint( buf );
    634705#else
    635706        fprintf( stderr, "%s\n", buf );         // add newline
     
    656727  error code will be used if possible. Use this method to handle
    657728  failures in platform specific API calls.
    658  
     729
    659730  Under OS/2, the value -1 for \a code should only be used after Presentation
    660731  Manager calls.
Note: See TracChangeset for help on using the changeset viewer.