Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

main_nix.cpp

Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                         main.cpp  -  description
00009                             -------------------
00010     begin                : Fre Apr  6 21:47:55 CEST 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013     copyright            : (C) 2004 by Alessandro Rimoldi
00014     email                : http://ideale.ch/contact
00015     copyright            : (C) 2005 by Craig Bradney
00016     email                : cbradney@zip.com.au
00017 ***************************************************************************/
00018 
00019 /***************************************************************************
00020 *                                                                         *
00021 *   This program is free software; you can redistribute it and/or modify  *
00022 *   it under the terms of the GNU General Public License as published by  *
00023 *   the Free Software Foundation; either version 2 of the License, or     *
00024 *   (at your option) any later version.                                   *
00025 *                                                                         *
00026 ***************************************************************************/
00027 
00028 #include <iostream>
00029 #include <signal.h>
00030 
00031 #include <QApplication>
00032 
00033 #define BASE_QM "scribus"
00034 
00035 #include "scribusapp.h"
00036 #include "scribuscore.h"
00037 #include "scribus.h"
00038 
00039 #include "scconfig.h"
00040 
00041 int mainApp(int argc, char **argv);
00042 void initCrashHandler();
00043 static void defaultCrashHandler(int sig);
00044 
00045 ScribusCore SCRIBUS_API *ScCore;
00046 ScribusMainWindow SCRIBUS_API *ScMW;
00047 ScribusQApp SCRIBUS_API *ScQApp;
00048 bool emergencyActivated;
00049 
00050 int main(int argc, char *argv[])
00051 {
00052     return mainApp(argc, argv);
00053 }
00054 
00065 int mainApp(int argc, char **argv)
00066 {
00067     emergencyActivated=false;
00068     ScribusQApp app(argc, argv);
00069     initCrashHandler();
00070     app.parseCommandLine();
00071     if (app.useGUI)
00072     {
00073         int appRetVal=app.init();
00074         if (appRetVal==EXIT_FAILURE)
00075             return(EXIT_FAILURE);
00076         return app.exec();
00077     }
00078     return EXIT_SUCCESS;    
00079 }
00080 
00081 void initCrashHandler()
00082 {
00083     typedef void (*HandlerType)(int);
00084     HandlerType handler = 0;
00085     handler = defaultCrashHandler;
00086     if (!handler)
00087         handler = SIG_DFL;
00088     sigset_t mask;
00089     sigemptyset(&mask);
00090 #ifdef SIGSEGV
00091     signal (SIGSEGV, handler);
00092     sigaddset(&mask, SIGSEGV);
00093 #endif
00094 #ifdef SIGFPE
00095     signal (SIGFPE, handler);
00096     sigaddset(&mask, SIGFPE);
00097 #endif
00098 #ifdef SIGILL
00099     signal (SIGILL, handler);
00100     sigaddset(&mask, SIGILL);
00101 #endif
00102 #ifdef SIGABRT
00103     signal (SIGABRT, handler);
00104     sigaddset(&mask, SIGABRT);
00105 #endif
00106     sigprocmask(SIG_UNBLOCK, &mask, 0);
00107 }
00108 
00109 void defaultCrashHandler(int sig)
00110 {
00111     static int crashRecursionCounter = 0;
00112     crashRecursionCounter++;
00113     signal(SIGALRM, SIG_DFL);
00114     if (crashRecursionCounter < 2)
00115     {
00116         emergencyActivated=true;
00117         crashRecursionCounter++;
00118         QString sigHdr=QObject::tr("Scribus Crash");
00119         QString sigLine="-------------";
00120         QString sigMsg=QObject::tr("Scribus crashes due to Signal #%1").arg(sig);
00121         std::cout << sigHdr.toStdString() << std::endl;
00122         std::cout << sigLine.toStdString() << std::endl;
00123         std::cout << sigMsg.toStdString() << std::endl;
00124         if (ScribusQApp::useGUI)
00125         {
00126             ScCore->closeSplash();
00127             QMessageBox::critical(ScMW, sigHdr, sigMsg, QObject::tr("&OK"));
00128             ScMW->emergencySave();
00129             ScMW->close();
00130         }
00131         alarm(300);
00132     }
00133     exit(255);
00134 }
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.