Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Defines | Functions | Variables
main_win32.cpp File Reference
#include <iostream>
#include <signal.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <qapplication.h>
#include <exception>
#include "scribusapp.h"
#include "scribuscore.h"
#include "scribus.h"
#include "scconfig.h"
#include <wincon.h>
#include <windows.h>

Go to the source code of this file.

Defines

#define BASE_QM   "scribus"
#define MAX_LINES   500

Functions

int mainApp (ScribusQApp &app)
 Launches the Gui.
static LONG exceptionFilter (DWORD exceptionCode)
 describe the behavior to be adopted against specific exception
static QString exceptionDescription (DWORD exceptionCode)
 return a string describing a specific exception
static void defaultCrashHandler (DWORD exceptionCode)
void messageHandler (QtMsgType type, const char *msg)
bool consoleOptionEnabled (int argc, char *argv[])
void redirectIOToConsole (void)
int main (int argc, char *argv[])

Variables

const char ARG_CONSOLE []
const char ARG_CONSOLE_SHORT []
ScribusCore SCRIBUS_APIScCore
ScribusMainWindow SCRIBUS_APIScMW
ScribusQApp SCRIBUS_APIScQApp
bool emergencyActivated

Define Documentation

#define BASE_QM   "scribus"

Definition at line 43 of file main_win32.cpp.

#define MAX_LINES   500

Definition at line 44 of file main_win32.cpp.


Function Documentation

bool consoleOptionEnabled ( int  argc,
char *  argv[] 
)

Definition at line 261 of file main_win32.cpp.

{
 bool value = false;
       for( int i = 0; i < argc; i++ )
       {
              if( strcmp(argv[i], ARG_CONSOLE) == 0 ||
                     strcmp(argv[i], ARG_CONSOLE_SHORT) == 0 )
              {
                     value = true;
                     break;
              }
       }
       return value;
}

Here is the caller graph for this function:

void defaultCrashHandler ( DWORD  exceptionCode) [static]

Definition at line 217 of file main_win32.cpp.

{
       static int crashRecursionCounter = 0;
       crashRecursionCounter++;
       if (crashRecursionCounter < 2)
       {
              emergencyActivated=true;
              crashRecursionCounter++;
              QString expDesc = exceptionDescription(exceptionCode);
              QString expHdr  = QObject::tr("Scribus Crash");
              QString expLine = "-------------";
              QString expMsg  = QObject::tr("Scribus crashes due to the following exception : %1").arg(expDesc);
              std::cout << (const char*) expHdr << std::endl;
              std::cout << (const char*) expLine << std::endl;
              std::cout << (const char*) expMsg << std::endl;
              if (ScribusQApp::useGUI)
              {
                     ScCore->closeSplash();
                     QMessageBox::critical(ScMW, expHdr, expMsg, QObject::tr("&OK"));
                     ScMW->emergencySave();
                     ScMW->close();
              }
       }
       ExitProcess(255);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static QString exceptionDescription ( DWORD  exceptionCode) [static]

return a string describing a specific exception

Author:
Jean Ghali
Date:
Sun Oct 30 14:30:30 CET 2005
Parameters:
DWORDexceptionCode the value returned by GetExceptionCode()
Return values:
stringdescribing the specified exception

Definition at line 177 of file main_win32.cpp.

{
 QString description;
       if ( exceptionCode == EXCEPTION_ACCESS_VIOLATION )
              description = "EXCEPTION_ACCESS_VIOLATION";
       else if ( exceptionCode == EXCEPTION_DATATYPE_MISALIGNMENT )
              description = "EXCEPTION_DATATYPE_MISALIGNMENT";
       else if ( exceptionCode == EXCEPTION_ARRAY_BOUNDS_EXCEEDED )
              description = "EXCEPTION_ARRAY_BOUNDS_EXCEEDED";
       else if ( exceptionCode == EXCEPTION_FLT_DENORMAL_OPERAND )
              description = "EXCEPTION_FLT_DENORMAL_OPERAND";
       else if ( exceptionCode == EXCEPTION_FLT_DIVIDE_BY_ZERO )
              description = "EXCEPTION_FLT_DIVIDE_BY_ZERO";
       else if ( exceptionCode == EXCEPTION_FLT_INEXACT_RESULT )
              description = "EXCEPTION_FLT_INEXACT_RESULT";
       else if ( exceptionCode == EXCEPTION_FLT_INVALID_OPERATION )
              description = "EXCEPTION_FLT_INVALID_OPERATION";
       else if ( exceptionCode == EXCEPTION_FLT_OVERFLOW )
              description = "EXCEPTION_FLT_OVERFLOW";
       else if ( exceptionCode == EXCEPTION_FLT_STACK_CHECK )
              description = "EXCEPTION_FLT_STACK_CHECK";
       else if ( exceptionCode == EXCEPTION_FLT_UNDERFLOW )
              description = "EXCEPTION_FLT_UNDERFLOW";
       else if ( exceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION )
              description = "EXCEPTION_ILLEGAL_INSTRUCTION";
       else if ( exceptionCode == EXCEPTION_INT_DIVIDE_BY_ZERO )
              description = "EXCEPTION_INT_DIVIDE_BY_ZERO";
       else if ( exceptionCode == EXCEPTION_INT_OVERFLOW )
              description = "EXCEPTION_INT_OVERFLOW";
       else if ( exceptionCode == EXCEPTION_INVALID_HANDLE )
              description = "EXCEPTION_INVALID_HANDLE";
       else if ( exceptionCode == EXCEPTION_NONCONTINUABLE_EXCEPTION )
              description = "EXCEPTION_NONCONTINUABLE_EXCEPTION";
       else if ( exceptionCode == EXCEPTION_STACK_OVERFLOW )
              description = "EXCEPTION_STACK_OVERFLOW";
       else
              description = "UNKNOWN EXCEPTION";
       return description;
}

Here is the caller graph for this function:

LONG exceptionFilter ( DWORD  exceptionCode) [static]

describe the behavior to be adopted against specific exception

Author:
Jean Ghali
Date:
Sun Oct 30 14:30:30 CET 2005
Parameters:
DWORDexceptionCode the value returned by GetExceptionCode()
Return values:
EXCEPTION_EXECUTE_HANDLERif handler is to be executed or EXCEPTION_CONTINUE_EXECUTION if not

Definition at line 135 of file main_win32.cpp.

{
 LONG result;
       switch( exceptionCode )
       {
       case EXCEPTION_ACCESS_VIOLATION:
       case EXCEPTION_DATATYPE_MISALIGNMENT:
       case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
       case EXCEPTION_FLT_DENORMAL_OPERAND:
       case EXCEPTION_FLT_DIVIDE_BY_ZERO:
       case EXCEPTION_FLT_INEXACT_RESULT:
       case EXCEPTION_FLT_INVALID_OPERATION:
       case EXCEPTION_FLT_OVERFLOW:
       case EXCEPTION_FLT_STACK_CHECK:
       case EXCEPTION_FLT_UNDERFLOW:
       case EXCEPTION_ILLEGAL_INSTRUCTION:
       case EXCEPTION_INT_DIVIDE_BY_ZERO:
       case EXCEPTION_INT_OVERFLOW:
       case EXCEPTION_INVALID_HANDLE:
       case EXCEPTION_NONCONTINUABLE_EXCEPTION:
       case EXCEPTION_STACK_OVERFLOW:
              result = EXCEPTION_EXECUTE_HANDLER;
              break;
       case EXCEPTION_BREAKPOINT:
       case EXCEPTION_SINGLE_STEP:
              result = EXCEPTION_CONTINUE_EXECUTION;
              break;
       default:
              result = EXCEPTION_EXECUTE_HANDLER;
              break;
       }
       return result;
}

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 76 of file main_win32.cpp.

{
       int result;
       emergencyActivated = false;
#if !defined(_CONSOLE)
       if (consoleOptionEnabled(argc, argv))
       {
              redirectIOToConsole();
              qInstallMsgHandler( messageHandler );
       }
#endif
       ScribusQApp app(argc, argv);
       result =  mainApp(app);
       return result;
}

Here is the call graph for this function:

int mainApp ( ScribusQApp &  app)

Launches the Gui.

Author:
Franz Schmid
Alessandro Rimoldi
Craig Bradney
Jean Ghali
Date:
Mon Feb 9 14:07:46 CET 2004
Parameters:
appa Scribus QApplication object
Return values:
intError code from the execution of Scribus

Definition at line 103 of file main_win32.cpp.

{
       int appRetVal;
#ifndef _DEBUG
       __try
       {
#endif
              app.parseCommandLine();
              if (app.useGUI)
              {
                     appRetVal = app.init();
                     if (appRetVal != EXIT_FAILURE)
                            appRetVal = app.exec();
              }
#ifndef _DEBUG
       }
       __except( exceptionFilter(GetExceptionCode()) )
       {
              defaultCrashHandler( GetExceptionCode() );
       }
#endif
       return appRetVal;
}

Here is the call graph for this function:

void messageHandler ( QtMsgType  type,
const char *  msg 
)

Definition at line 243 of file main_win32.cpp.

{
       cerr << msg << endl;
       if( type == QtFatalMsg )
       {
              if (ScribusQApp::useGUI)
              {
                     ScCore->closeSplash();
                     QString expHdr = QObject::tr("Scribus Crash");
                     QString expMsg = msg;
                     QMessageBox::critical(ScMW, expHdr, expMsg, QObject::tr("&OK"));
                     ScMW->emergencySave();
                     ScMW->close();
              }
              ExitProcess(255);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void redirectIOToConsole ( void  )

Definition at line 276 of file main_win32.cpp.

{
       int hConHandle;
       HANDLE lStdHandle;
       CONSOLE_SCREEN_BUFFER_INFO coninfo;
       FILE *fp;

       // allocate console
       if( GetStdHandle(STD_OUTPUT_HANDLE) != INVALID_HANDLE_VALUE )
              AllocConsole();
       // set the screen buffer to be big enough to let us scroll text
       GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
       coninfo.dwSize.Y = MAX_LINES;
       SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
       //redirect unbuffered STDOUT to the console
       lStdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
       hConHandle = _open_osfhandle((intptr_t) lStdHandle, _O_TEXT);
       fp = _fdopen( hConHandle, "w" );
       *stdout = *fp;
       setvbuf( stdout, NULL, _IONBF, 0 );
       // redirect unbuffered STDIN to the console
       lStdHandle = GetStdHandle(STD_INPUT_HANDLE);
       hConHandle = _open_osfhandle((intptr_t) lStdHandle, _O_TEXT);
       fp = _fdopen( hConHandle, "r" );
       *stdin = *fp;
       setvbuf( stdin, NULL, _IONBF, 0 );
       // redirect unbuffered STDERR to the console
       lStdHandle = GetStdHandle(STD_ERROR_HANDLE);
       hConHandle = _open_osfhandle((intptr_t) lStdHandle, _O_TEXT);
       fp = _fdopen( hConHandle, "w" );
       *stderr = *fp;
       setvbuf( stderr, NULL, _IONBF, 0 );
       // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog 
       // point to console as well
       ios::sync_with_stdio();
}

Here is the caller graph for this function:


Variable Documentation

const char ARG_CONSOLE[]
const char ARG_CONSOLE_SHORT[]

Definition at line 74 of file main_win32.cpp.

ScribusCore SCRIBUS_API* ScCore

Definition at line 71 of file main_win32.cpp.

ScribusMainWindow SCRIBUS_API* ScMW

Definition at line 72 of file main_win32.cpp.

ScribusQApp SCRIBUS_API* ScQApp

Definition at line 73 of file main_win32.cpp.