bool gravApp::OnInit() { grav = new gravManager(); // defaults - can be changed by command line windowWidth = 900; windowHeight = 550; startX = 10; startY = 50; // gravManager's windowwidth/height will be set by the glcanvas's resize // callback parser.SetCmdLine( argc, argv ); videoSessionListener = new VideoListener( grav ); audioSessionListener = new AudioManager(); sessionManager = new SessionManager( videoSessionListener, audioSessionListener ); //videoInitialized = false; audioInitialized = false; if ( !handleArgs() ) { delete grav; return false; } // Some weirdness happens if this is called before arg handling, etc. gravUtil::initLogging(); // Set verbosity here, nothing should use gravUtil::logVerbose before this. if ( verbose ) wxLog::SetVerbose( true ); if ( VPMverbose ) vpmlog_set_log_level( VPMLOG_LEVEL_DEBUG ); // GUI setup mainFrame = new Frame( (wxFrame*)NULL, -1, _("grav"), wxPoint( startX, startY ), wxSize( windowWidth, windowHeight ) ); mainFrame->Show( true ); mainFrame->SetName( _("main grav frame") ); mainFrame->setSourceManager( grav ); SetTopWindow( mainFrame ); if ( startFullscreen ) mainFrame->ShowFullScreen( true ); int treeX = 960; int treeY = 50; // forces resize - for some reason it doesn't draw inner contents until // resized int treeWidth = 251; int treeHeight = 501; treeFrame = new SideFrame( mainFrame, -1, _("grav menu"), wxPoint( treeX, treeY ), wxSize( treeWidth, treeHeight ) ); treeFrame->Show( true ); treeFrame->SetSizeHints( 250, 500, 250, 500 ); treePanel = new wxPanel( treeFrame, wxID_ANY, treeFrame->GetPosition(), treeFrame->GetSize() ); treeNotebook = new wxNotebook( treePanel, wxID_ANY, treePanel->GetPosition(), treePanel->GetSize() ); int attribList[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 24, 0 }; canvas = new GLCanvas( mainFrame, grav, attribList, mainFrame->GetClientSize() ); sourceTree = new TreeControl( treeNotebook ); sourceTree->setSourceManager( grav ); sessionTree = new SessionTreeControl( treeNotebook ); treeNotebook->AddPage( sourceTree, _("Videos"), true ); treeNotebook->AddPage( sessionTree, _("Sessions") ); // sizer for the notebook in general wxBoxSizer* treeSizer = new wxBoxSizer( wxVERTICAL ); treePanel->SetSizer( treeSizer ); treeSizer->Fit( treeFrame ); treeSizer->Add( treeNotebook, wxEXPAND ); treeSizer->Show( treeNotebook ); treeSizer->Layout(); // put the main frame on top mainFrame->Raise(); // log here instead of in handleargs, see above/in handleargs // (handleargs is where the timer intervals actually get set) // might be that we can't do logging until main window is created if ( fps > 1000 ) { gravUtil::logVerbose( "grav::warning: invalid fps value %li, " "reset to 60\n", fps ); // note the "fps" variable here is just the input from the command line, // the timer interval - what actually determines the rendering timing - // has already been reset to 16ms in handleArgs } if ( printVersion ) { std::string ver = "grav "; ver += gravUtil::getVersionString(); gravUtil::logMessage( ver.c_str() ); } if ( disablePython ) { PythonTools::disableInit = true; } // since these bools are used in glinit, set them before glinit GLUtil::getInstance()->setShaderEnable( enableShaders ); GLUtil::getInstance()->setBufferFontUsage( bufferFont ); // initialize GL stuff (+ shaders) needs to be done AFTER attriblist is // used in making the canvas if ( !GLUtil::getInstance()->initGL() ) { // bail out if something failed gravUtil::logError( "grav::OnInit(): ERROR: initGL() failed, " "exiting\n" ); delete grav; return false; } if ( headerSet ) grav->setHeaderString( header ); timer = new RenderTimer( canvas, timerInterval ); //timer->Start(); //wxStopWatch* t2 = new wxStopWatch(); //videoSession_listener->setTimer( t2 ); earth = new Earth(); input = new InputHandler( earth, grav, mainFrame ); // frame needs reference to inputhandler to generate help window for // shortcut hotkeys mainFrame->setInputHandler( input ); // add the input handler to the chain of things that can handle // events & give the canvas focus so we don't have to click on it to // start sending key events canvas->PushEventHandler( input ); canvas->SetFocus(); canvas->setTimer( timer ); if ( !disablePython ) { venueClientController = new VenueClientController( 0.0f, 0.0f, grav ); venueClientController->setSessionControl( sessionTree ); } grav->setEarth( earth ); grav->setInput( input ); grav->setTree( sourceTree ); grav->setBorderTex( "border.png" ); grav->setVideoListener( videoSessionListener ); grav->setCanvas( canvas ); grav->setVenueClientController( venueClientController ); // may be null grav->setAudio( audioSessionListener ); // may not necessarily be used mapRTP(); sessionTree->setSessionManager( sessionManager ); for ( unsigned int i = 0; i < initialVideoAddresses.size(); i++ ) { gravUtil::logVerbose ( "grav::initializing video address %s\n", initialVideoAddresses[i].c_str() ); sessionTree->addSession( initialVideoAddresses[i], false, addToAvailableVideoList ); if ( haveVideoKey ) sessionTree->setEncryptionKey( initialVideoAddresses[i], initialVideoKey ); } for ( unsigned int i = 0; i < initialAudioAddresses.size(); i++ ) { gravUtil::logVerbose ( "grav::initializing audio address %s\n", initialAudioAddresses[i].c_str() ); sessionTree->addSession( initialAudioAddresses[i], true, false ); if ( haveAudioKey ) sessionTree->setEncryptionKey( initialAudioAddresses[i], initialAudioKey ); } if ( getAGVenueStreams && !disablePython ) { venueClientController->updateVenueStreams(); venueClientController->addAllVenueStreams(); } if ( autoRotateAvailableVideo ) sessionTree->startTimer( rotateIntervalMS ); gravUtil::logVerbose( "grav::init function complete\n" ); return true; }
// hlavna funkcia int main (int argc, char **argv) { unsigned port; if ((port = handleArgs (argc, argv)) == -1) { handleError (WRONG_PARAMS, "wrong parameters on commandline"); } int listenSocket; if((listenSocket = socket( PF_INET, SOCK_STREAM, 0)) < 0) { handleError(INTERNAL_ERROR, "cannot create socket"); } sockaddr_in s1, s2; socklen_t s2Len = sizeof(s2); memset (&s1, 0, sizeof(s1)); s1.sin_family = AF_INET; s1.sin_port = htons(port); s1.sin_addr.s_addr = INADDR_ANY; int tr = 1; if (setsockopt(listenSocket,SOL_SOCKET,SO_REUSEADDR,&tr,sizeof(int)) == -1) { close(listenSocket); handleError(INTERNAL_ERROR, "setsockopt failed"); } if (bind( listenSocket, reinterpret_cast<sockaddr*>(&s1), sizeof(s1)) != 0) { close(listenSocket); handleError(INTERNAL_ERROR, "bind() failed"); } if (listen(listenSocket, 0) != 0) { close(listenSocket); handleError(CONNECTION_FAILED, "listen() failed"); } // otvorenie suboru s datami std::ifstream infile; infile.open(filename); infile.is_open(); // nacitani suboru do vektoru std::string line; if (infile.is_open()) { while (getline(infile, line)) fileCopy.push_back(line); } infile.close(); // vytvoreni threadu pro signaly a mutexov pthread_t thread; pthread_attr_t attrt; pthread_attr_init (&attrt); pthread_attr_setdetachstate (&attrt, PTHREAD_CREATE_DETACHED); if (pthread_mutex_init (&dataMutex, NULL) != 0) { close (listenSocket); file.close(); handleError(INTERNAL_ERROR, "mutex init failed"); } size_t dataSocket; pthread_t sigThread; sigset_t set; int s; sigemptyset(&set); sigaddset(&set, SIGQUIT); sigaddset(&set, SIGINT); sigaddset(&set, SIGTERM); s = pthread_sigmask(SIG_BLOCK, &set, NULL); if (s != 0) handleError (INTERNAL_ERROR, "pthread_create"); s = pthread_create(&sigThread, NULL, sigThreadCatch, &set); if (s != 0) handleError(INTERNAL_ERROR, "pthread_create"); while (1) { dataSocket = accept(listenSocket, reinterpret_cast<sockaddr*>(&s2), &s2Len); if (dataSocket <= 0) continue; pthread_create (&thread, &attrt, handleConnection, &dataSocket); } }
/** * Main. Creates Application window. * * Cleaning up #defines. */ int main(int argc, char** argv) { RS_DEBUG->setLevel(RS_Debug::D_WARNING); QCoreApplication::setApplicationName(XSTR(QC_APPNAME)); #if QT_VERSION < 0x040400 /* No such property in Qt 4.3 */ #else QCoreApplication::setApplicationVersion(XSTR(QC_VERSION)); #endif QApplication app(argc, argv); #if defined(Q_OS_MAC) && QT_VERSION > 0x050000 //need stylesheet for Qt5 on mac app.setStyleSheet( "QToolButton:checked" "{" " background-color: rgb(160,160,160);" " border-style: inset;" "}" "" "QToolButton" "{" " background-color: transparent;" "}" "" "QToolButton:hover" "{" " background-color: rgb(255,255,255);" " border-style: outset;" "}" ); #endif // for image mime resources from png files // TODO: kinda dirty to call that explicitly // QINITIMAGES_LIBRECAD(); #ifdef RS_SCRIPTING // qInitImages_librecad(); #endif const QString lpDebugSwitch0("-d"),lpDebugSwitch1("--debug") ; const QString help0("-h"), help1("--help"); bool allowOptions=true; QList<int> argClean; for (int i=0; i<argc; i++) { QString argstr(argv[i]); if(allowOptions&&QString::compare("--", argstr)==0){ allowOptions=false; continue; } if (allowOptions&&( help0.compare(argstr, Qt::CaseInsensitive)==0 || help1.compare(argstr, Qt::CaseInsensitive)==0 ) ){//hep information qDebug()<<"librecad::usage: <options> <dxf file>"; qDebug()<<"-h, --help\tdisplay this message"; qDebug()<<""; qDebug()<<" --help\tdisplay this message"; qDebug()<<"-d, --debug <level>"; RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:"); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Nothing", RS_Debug::D_NOTHING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Critical", RS_Debug::D_CRITICAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Error", RS_Debug::D_ERROR); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Warning", RS_Debug::D_WARNING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Notice", RS_Debug::D_NOTICE); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Informational", RS_Debug::D_INFORMATIONAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Debugging", RS_Debug::D_DEBUGGING); exit(0); } if ( allowOptions&& ( argstr.startsWith(lpDebugSwitch0, Qt::CaseInsensitive)|| argstr.startsWith(lpDebugSwitch1, Qt::CaseInsensitive) ) ){ argClean<<i; // to control the level of debugging output use --debug with level 0-6, e.g. --debug3 // for a list of debug levels use --debug? // if no level follows, the debugging level is set argstr.remove(QRegExp("^"+lpDebugSwitch0)); argstr.remove(QRegExp("^"+lpDebugSwitch1)); char level; if(argstr.size()==0){ if(i+1<argc) { if(QRegExp("\\d*").exactMatch(argv[i+1])){ ++i; qDebug()<<"reading "<<argv[i]<<" as debugging level"; level=argv[i][0]; argClean<<i; }else level='3'; }else level='3'; //default to D_WARNING }else level=argstr.toStdString()[0]; // if( strlen( argv[i]) > iDebugSwitchLen) { switch(level) { case '?' : RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:"); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Nothing", RS_Debug::D_NOTHING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Critical", RS_Debug::D_CRITICAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Error", RS_Debug::D_ERROR); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Warning", RS_Debug::D_WARNING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Notice", RS_Debug::D_NOTICE); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Informational", RS_Debug::D_INFORMATIONAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Debugging", RS_Debug::D_DEBUGGING); return 0; case '0' + RS_Debug::D_NOTHING : RS_DEBUG->setLevel( RS_Debug::D_NOTHING); ++i; break; case '0' + RS_Debug::D_CRITICAL : RS_DEBUG->setLevel( RS_Debug::D_CRITICAL); ++i; break; case '0' + RS_Debug::D_ERROR : RS_DEBUG->setLevel( RS_Debug::D_ERROR); ++i; break; case '0' + RS_Debug::D_WARNING : RS_DEBUG->setLevel( RS_Debug::D_WARNING); ++i; break; case '0' + RS_Debug::D_NOTICE : RS_DEBUG->setLevel( RS_Debug::D_NOTICE); ++i; break; case '0' + RS_Debug::D_INFORMATIONAL : RS_DEBUG->setLevel( RS_Debug::D_INFORMATIONAL); ++i; break; case '0' + RS_Debug::D_DEBUGGING : RS_DEBUG->setLevel( RS_Debug::D_DEBUGGING); ++i; break; default : RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING); break; } // } // else { // RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING); // } } } RS_DEBUG->print("param 0: %s", argv[0]); QFileInfo prgInfo( QFile::decodeName(argv[0]) ); QString prgDir(prgInfo.absolutePath()); RS_SETTINGS->init(XSTR(QC_COMPANYKEY), XSTR(QC_APPKEY)); RS_SYSTEM->init(XSTR(QC_APPNAME), XSTR(QC_VERSION), XSTR(QC_APPDIR), prgDir); // parse command line arguments that might not need a launched program: QStringList fileList = handleArgs(argc, argv, argClean); QString lang; QString langCmd; QString unit; RS_SETTINGS->beginGroup("/Defaults"); #ifndef QC_PREDEFINED_UNIT unit = RS_SETTINGS->readEntry("/Unit", "Invalid"); #else unit = RS_SETTINGS->readEntry("/Unit", QC_PREDEFINED_UNIT); #endif RS_SETTINGS->endGroup(); // show initial config dialog: if (unit=="Invalid") { RS_DEBUG->print("main: show initial config dialog.."); QG_DlgInitial di(NULL); di.setText("<font size=\"+1\"><b>Welcome to " XSTR(QC_APPNAME) "</b></font>" "<br>" "Please choose the unit you want to use for new drawings and your " "preferred language.<br>" "You can changes these settings later in the " "Options Dialog of " XSTR(QC_APPNAME) "."); QPixmap pxm(":/main/intro_librecad.png"); di.setPixmap(pxm); if (di.exec()) { RS_SETTINGS->beginGroup("/Defaults"); unit = RS_SETTINGS->readEntry("/Unit", "None"); RS_SETTINGS->endGroup(); } RS_DEBUG->print("main: show initial config dialog: OK"); } #ifdef QSPLASHSCREEN_H // RS_DEBUG->print("main: splashscreen.."); QPixmap* pixmap = new QPixmap(":/main/splash_librecad.png"); #endif RS_DEBUG->print("main: init fontlist.."); RS_FONTLIST->init(); RS_DEBUG->print("main: init fontlist: OK"); RS_DEBUG->print("main: init patternlist.."); RS_PATTERNLIST->init(); RS_DEBUG->print("main: init patternlist: OK"); RS_DEBUG->print("main: init scriptlist.."); RS_SCRIPTLIST->init(); RS_DEBUG->print("main: init scriptlist: OK"); RS_DEBUG->print("main: loading translation.."); RS_SETTINGS->beginGroup("/Appearance"); #ifdef QC_PREDEFINED_LOCALE lang = RS_SETTINGS->readEntry("/Language", ""); if (lang.isEmpty()) { lang=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/Language", lang); } langCmd = RS_SETTINGS->readEntry("/LanguageCmd", ""); if (langCmd.isEmpty()) { langCmd=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/LanguageCmd", langCmd); } #else lang = RS_SETTINGS->readEntry("/Language", "en"); langCmd = RS_SETTINGS->readEntry("/LanguageCmd", "en"); #endif RS_SETTINGS->endGroup(); RS_SYSTEM->loadTranslation(lang, langCmd); RS_DEBUG->print("main: loading translation: OK"); #ifdef QSPLASHSCREEN_H RS_SETTINGS->beginGroup("Appearance"); { bool showSplash=RS_SETTINGS->readNumEntry("/ShowSplash",1)==1; if(showSplash){ splash = new QSplashScreen(*pixmap); splash->show(); splash->showMessage(QObject::tr("Loading.."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); RS_DEBUG->print("main: splashscreen: OK"); } } RS_SETTINGS->endGroup(); #endif //QApplication::setStyle(new QWindowsStyle()); //QApplication::setStyle(new QPlatinumStyle()); #ifdef QC_BUILTIN_STYLE //js: RS_DEBUG->print("main: applying built in style.."); applyBuiltinStyle(); #endif RS_DEBUG->print("main: creating main window.."); QC_ApplicationWindow * appWin = new QC_ApplicationWindow(); RS_DEBUG->print("main: setting caption"); appWin->setWindowTitle(XSTR(QC_APPNAME)); RS_DEBUG->print("main: show main window"); appWin->show(); RS_DEBUG->print("main: set focus"); appWin->setFocus(); RS_DEBUG->print("main: creating main window: OK"); #ifdef QSPLASHSCREEN_H if (splash) { RS_DEBUG->print("main: updating splash.."); splash->showMessage(QObject::tr("Loading..."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); RS_DEBUG->print("main: processing events"); qApp->processEvents(); RS_DEBUG->print("main: updating splash: OK"); } #endif // Set LC_NUMERIC so that enetring numeric values uses . as teh decimal seperator setlocale(LC_NUMERIC, "C"); RS_DEBUG->print("main: loading files.."); bool files_loaded = false; for (QStringList::Iterator it = fileList.begin(); it != fileList.end(); ++it ) { #ifdef QSPLASHSCREEN_H if (splash) { splash->showMessage(QObject::tr("Loading File %1..") .arg(QDir::toNativeSeparators(*it)), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); qApp->processEvents(); } #endif appWin->slotFileOpen(*it, RS2::FormatUnknown); files_loaded = true; } RS_DEBUG->print("main: loading files: OK"); #ifdef QSPLASHSCREEN_H # ifndef QC_DELAYED_SPLASH_SCREEN if (splash) { splash->finish(appWin); delete splash; splash = nullptr; } # endif delete pixmap; #endif //app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); RS_DEBUG->print("main: app.exec()"); if (!files_loaded) { appWin->slotFileNewNew(); } appWin->slotRunStartScript(); int r = app.exec(); RS_DEBUG->print("main: Temporary disabled delete appWin"); // delete appWin; RS_DEBUG->print("main: finished"); return r; }
/** * Main. Creates Application window. * * Cleaning up #defines. */ int main(int argc, char** argv) { RS_DEBUG->setLevel(RS_Debug::D_WARNING); QCoreApplication::setApplicationName(XSTR(QC_APPNAME)); #if QT_VERSION < 0x040400 /* No such property in Qt 4.3 */ #else QCoreApplication::setApplicationVersion(XSTR(QC_VERSION)); #endif QApplication app(argc, argv); // for image mime resources from png files // TODO: kinda dirty to call that explicitly // QINITIMAGES_LIBRECAD(); #ifdef RS_SCRIPTING // qInitImages_librecad(); #endif const char *lpDebugSwitch = "--debug"; size_t iDebugSwitchLen = strlen(lpDebugSwitch); for (int i=0; i<argc; i++) { if ( ! strncmp( lpDebugSwitch, argv[i], iDebugSwitchLen)) { // to control the level of debugging output use --debug with level 0-6, e.g. --debug3 // for a list of debug levels use --debug? // if no level follows, the debugging level is set if( strlen( argv[i]) > iDebugSwitchLen) { switch( argv[i][iDebugSwitchLen]) { case '?' : RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:"); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Nothing", RS_Debug::D_NOTHING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Critical", RS_Debug::D_CRITICAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Error", RS_Debug::D_ERROR); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Warning", RS_Debug::D_WARNING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Notice", RS_Debug::D_NOTICE); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Informational", RS_Debug::D_INFORMATIONAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Debugging", RS_Debug::D_DEBUGGING); return 0; case '0' + RS_Debug::D_NOTHING : RS_DEBUG->setLevel( RS_Debug::D_NOTHING); ++i; break; case '0' + RS_Debug::D_CRITICAL : RS_DEBUG->setLevel( RS_Debug::D_CRITICAL); ++i; break; case '0' + RS_Debug::D_ERROR : RS_DEBUG->setLevel( RS_Debug::D_ERROR); ++i; break; case '0' + RS_Debug::D_WARNING : RS_DEBUG->setLevel( RS_Debug::D_WARNING); ++i; break; case '0' + RS_Debug::D_NOTICE : RS_DEBUG->setLevel( RS_Debug::D_NOTICE); ++i; break; case '0' + RS_Debug::D_INFORMATIONAL : RS_DEBUG->setLevel( RS_Debug::D_INFORMATIONAL); ++i; break; case '0' + RS_Debug::D_DEBUGGING : RS_DEBUG->setLevel( RS_Debug::D_DEBUGGING); ++i; break; default : RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING); break; } } else { RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING); } } } RS_DEBUG->print("param 0: %s", argv[0]); QFileInfo prgInfo( QFile::decodeName(argv[0]) ); QString prgDir(prgInfo.absolutePath()); RS_SETTINGS->init(XSTR(QC_COMPANYKEY), XSTR(QC_APPKEY)); RS_SYSTEM->init(XSTR(QC_APPNAME), XSTR(QC_VERSION), XSTR(QC_APPDIR), prgDir); RS_FileIO::instance()->registerFilter(&( RS_FilterLFF::createFilter)); RS_FileIO::instance()->registerFilter( &(RS_FilterDXFRW::createFilter)); RS_FileIO::instance()->registerFilter( &(RS_FilterCXF::createFilter)); RS_FileIO::instance()->registerFilter( &(RS_FilterJWW::createFilter)); RS_FileIO::instance()->registerFilter( &(RS_FilterDXF1::createFilter)); // parse command line arguments that might not need a launched program: QStringList fileList = handleArgs(argc, argv); QString lang; QString langCmd; QString unit; RS_SETTINGS->beginGroup("/Defaults"); #ifndef QC_PREDEFINED_UNIT unit = RS_SETTINGS->readEntry("/Unit", "Invalid"); #else unit = RS_SETTINGS->readEntry("/Unit", QC_PREDEFINED_UNIT); #endif RS_SETTINGS->endGroup(); // show initial config dialog: if (unit=="Invalid") { RS_DEBUG->print("main: show initial config dialog.."); QG_DlgInitial di(NULL); di.setText("<font size=\"+1\"><b>Welcome to " XSTR(QC_APPNAME) "</b></font>" "<br>" "Please choose the unit you want to use for new drawings and your " "preferred language.<br>" "You can changes these settings later in the " "Options Dialog of " XSTR(QC_APPNAME) "."); QPixmap pxm(":/main/intro_librecad.png"); di.setPixmap(pxm); if (di.exec()) { RS_SETTINGS->beginGroup("/Defaults"); unit = RS_SETTINGS->readEntry("/Unit", "None"); RS_SETTINGS->endGroup(); } RS_DEBUG->print("main: show initial config dialog: OK"); } #ifdef QSPLASHSCREEN_H RS_DEBUG->print("main: splashscreen.."); QPixmap* pixmap = new QPixmap(":/main/splash_librecad.png"); # endif RS_DEBUG->print("main: init fontlist.."); RS_FONTLIST->init(); RS_DEBUG->print("main: init fontlist: OK"); RS_DEBUG->print("main: init patternlist.."); RS_PATTERNLIST->init(); RS_DEBUG->print("main: init patternlist: OK"); RS_DEBUG->print("main: init scriptlist.."); RS_SCRIPTLIST->init(); RS_DEBUG->print("main: init scriptlist: OK"); RS_DEBUG->print("main: loading translation.."); RS_SETTINGS->beginGroup("/Appearance"); #ifdef QC_PREDEFINED_LOCALE lang = RS_SETTINGS->readEntry("/Language", ""); if (lang.isEmpty()) { lang=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/Language", lang); } langCmd = RS_SETTINGS->readEntry("/LanguageCmd", ""); if (langCmd.isEmpty()) { langCmd=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/LanguageCmd", langCmd); } #else lang = RS_SETTINGS->readEntry("/Language", "en"); langCmd = RS_SETTINGS->readEntry("/LanguageCmd", "en"); #endif RS_SETTINGS->endGroup(); RS_SYSTEM->loadTranslation(lang, langCmd); RS_DEBUG->print("main: loading translation: OK"); #ifdef QSPLASHSCREEN_H splash = new QSplashScreen(*pixmap); splash->show(); splash->showMessage(QObject::tr("Loading.."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); RS_DEBUG->print("main: splashscreen: OK"); #endif //QApplication::setStyle(new QWindowsStyle()); //QApplication::setStyle(new QPlatinumStyle()); #ifdef QC_BUILTIN_STYLE //js: RS_DEBUG->print("main: applying built in style.."); applyBuiltinStyle(); #endif RS_DEBUG->print("main: creating main window.."); QC_ApplicationWindow * appWin = new QC_ApplicationWindow(); RS_DEBUG->print("main: setting caption"); appWin->setWindowTitle(XSTR(QC_APPNAME)); RS_DEBUG->print("main: show main window"); appWin->show(); RS_DEBUG->print("main: set focus"); appWin->setFocus(); RS_DEBUG->print("main: creating main window: OK"); #ifdef QSPLASHSCREEN_H if (splash) { RS_DEBUG->print("main: updating splash.."); splash->showMessage(QObject::tr("Loading..."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); RS_DEBUG->print("main: processing events"); qApp->processEvents(); RS_DEBUG->print("main: updating splash: OK"); } #endif // Set LC_NUMERIC so that enetring numeric values uses . as teh decimal seperator setlocale(LC_NUMERIC, "C"); RS_DEBUG->print("main: loading files.."); bool files_loaded = false; for (QStringList::Iterator it = fileList.begin(); it != fileList.end(); ++it ) { #ifdef QSPLASHSCREEN_H if (splash) { splash->showMessage(QObject::tr("Loading File %1..") .arg(QDir::toNativeSeparators(*it)), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); qApp->processEvents(); } #endif appWin->slotFileOpen(*it, RS2::FormatUnknown); files_loaded = true; } RS_DEBUG->print("main: loading files: OK"); #ifdef QSPLASHSCREEN_H # ifndef QC_DELAYED_SPLASH_SCREEN if (splash) { splash->finish(appWin); delete splash; splash = 0; } # endif delete pixmap; #endif //app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); RS_DEBUG->print("main: app.exec()"); if (!files_loaded) { appWin->slotFileNewNew(); } appWin->slotRunStartScript(); int r = app.exec(); RS_DEBUG->print("main: Temporary disabled delete appWin"); // delete appWin; RS_DEBUG->print("main: finished"); return r; }
/** * Main. Creates Application window. */ int main(int argc, char** argv) { RS_DEBUG->setLevel(RS_Debug::D_WARNING); QApplication app(argc, argv); QCoreApplication::setOrganizationName("LibreCAD"); QCoreApplication::setApplicationName("/LibreCAD"); QCoreApplication::setApplicationVersion("master"); QSplashScreen* splash = new QSplashScreen; RS_SETTINGS->beginGroup("Appearance"); bool show_splash = RS_SETTINGS->readNumEntry("/ShowSplash", 1); RS_SETTINGS->endGroup(); if (show_splash) { QPixmap pixmap(":/main/splash_librecad.png"); splash->setPixmap(pixmap); splash->setAttribute(Qt::WA_DeleteOnClose); splash->show(); splash->showMessage(QObject::tr("Loading.."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); app.processEvents(); RS_DEBUG->print("main: splashscreen: OK"); } #if defined(Q_OS_MAC) && QT_VERSION > 0x050000 //need stylesheet for Qt5 on mac app.setStyleSheet( "QToolButton:checked" "{" " background-color: rgb(160,160,160);" " border-style: inset;" "}" "" "QToolButton" "{" " background-color: transparent;" "}" "" "QToolButton:hover" "{" " background-color: rgb(255,255,255);" " border-style: outset;" "}" ); #endif const QString lpDebugSwitch0("-d"),lpDebugSwitch1("--debug") ; const QString help0("-h"), help1("--help"); bool allowOptions=true; QList<int> argClean; for (int i=0; i<argc; i++) { QString argstr(argv[i]); if(allowOptions&&QString::compare("--", argstr)==0) { allowOptions=false; continue; } if (allowOptions && (help0.compare(argstr, Qt::CaseInsensitive)==0 || help1.compare(argstr, Qt::CaseInsensitive)==0 )) { qDebug()<<"librecad::usage: <options> <dxf file>"; qDebug()<<"-h, --help\tdisplay this message"; qDebug()<<""; qDebug()<<" --help\tdisplay this message"; qDebug()<<"-d, --debug <level>"; RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:"); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Nothing", RS_Debug::D_NOTHING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Critical", RS_Debug::D_CRITICAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Error", RS_Debug::D_ERROR); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Warning", RS_Debug::D_WARNING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Notice", RS_Debug::D_NOTICE); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Informational", RS_Debug::D_INFORMATIONAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Debugging", RS_Debug::D_DEBUGGING); exit(0); } if ( allowOptions&& (argstr.startsWith(lpDebugSwitch0, Qt::CaseInsensitive) || argstr.startsWith(lpDebugSwitch1, Qt::CaseInsensitive) )) { argClean<<i; // to control the level of debugging output use --debug with level 0-6, e.g. --debug3 // for a list of debug levels use --debug? // if no level follows, the debugging level is set argstr.remove(QRegExp("^"+lpDebugSwitch0)); argstr.remove(QRegExp("^"+lpDebugSwitch1)); char level; if(argstr.size()==0) { if(i+1<argc) { if(QRegExp("\\d*").exactMatch(argv[i+1])) { ++i; qDebug()<<"reading "<<argv[i]<<" as debugging level"; level=argv[i][0]; argClean<<i; } else level='3'; } else level='3'; //default to D_WARNING } else level=argstr.toStdString()[0]; switch(level) { case '?' : RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:"); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Nothing", RS_Debug::D_NOTHING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Critical", RS_Debug::D_CRITICAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Error", RS_Debug::D_ERROR); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Warning", RS_Debug::D_WARNING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Notice", RS_Debug::D_NOTICE); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Informational", RS_Debug::D_INFORMATIONAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Debugging", RS_Debug::D_DEBUGGING); return 0; case '0' + RS_Debug::D_NOTHING : RS_DEBUG->setLevel( RS_Debug::D_NOTHING); ++i; break; case '0' + RS_Debug::D_CRITICAL : RS_DEBUG->setLevel( RS_Debug::D_CRITICAL); ++i; break; case '0' + RS_Debug::D_ERROR : RS_DEBUG->setLevel( RS_Debug::D_ERROR); ++i; break; case '0' + RS_Debug::D_WARNING : RS_DEBUG->setLevel( RS_Debug::D_WARNING); ++i; break; case '0' + RS_Debug::D_NOTICE : RS_DEBUG->setLevel( RS_Debug::D_NOTICE); ++i; break; case '0' + RS_Debug::D_INFORMATIONAL : RS_DEBUG->setLevel( RS_Debug::D_INFORMATIONAL); ++i; break; case '0' + RS_Debug::D_DEBUGGING : RS_DEBUG->setLevel( RS_Debug::D_DEBUGGING); ++i; break; default : RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING); break; } } } RS_DEBUG->print("param 0: %s", argv[0]); QFileInfo prgInfo( QFile::decodeName(argv[0]) ); QString prgDir(prgInfo.absolutePath()); RS_SETTINGS->init(XSTR(QC_COMPANYKEY), XSTR(QC_APPKEY)); RS_SYSTEM->init(XSTR(QC_APPNAME), XSTR(QC_VERSION), XSTR(QC_APPDIR), prgDir); // parse command line arguments that might not need a launched program: QStringList fileList = handleArgs(argc, argv, argClean); QString lang; QString langCmd; QString unit; RS_SETTINGS->beginGroup("/Defaults"); #ifndef QC_PREDEFINED_UNIT unit = RS_SETTINGS->readEntry("/Unit", "Invalid"); #else unit = RS_SETTINGS->readEntry("/Unit", QC_PREDEFINED_UNIT); #endif RS_SETTINGS->endGroup(); // show initial config dialog: if (unit=="Invalid") { RS_DEBUG->print("main: show initial config dialog.."); QG_DlgInitial di(nullptr); QPixmap pxm(":/main/intro_librecad.png"); di.setPixmap(pxm); if (di.exec()) { RS_SETTINGS->beginGroup("/Defaults"); unit = RS_SETTINGS->readEntry("/Unit", "None"); RS_SETTINGS->endGroup(); } RS_DEBUG->print("main: show initial config dialog: OK"); } RS_DEBUG->print("main: init fontlist.."); RS_FONTLIST->init(); RS_DEBUG->print("main: init fontlist: OK"); RS_DEBUG->print("main: init patternlist.."); RS_PATTERNLIST->init(); RS_DEBUG->print("main: init patternlist: OK"); RS_DEBUG->print("main: init scriptlist.."); RS_SCRIPTLIST->init(); RS_DEBUG->print("main: init scriptlist: OK"); RS_DEBUG->print("main: loading translation.."); RS_SETTINGS->beginGroup("/Appearance"); #ifdef QC_PREDEFINED_LOCALE lang = RS_SETTINGS->readEntry("/Language", ""); if (lang.isEmpty()) { lang=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/Language", lang); } langCmd = RS_SETTINGS->readEntry("/LanguageCmd", ""); if (langCmd.isEmpty()) { langCmd=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/LanguageCmd", langCmd); } #else lang = RS_SETTINGS->readEntry("/Language", "en"); langCmd = RS_SETTINGS->readEntry("/LanguageCmd", "en"); #endif RS_SETTINGS->endGroup(); RS_SYSTEM->loadTranslation(lang, langCmd); RS_DEBUG->print("main: loading translation: OK"); RS_DEBUG->print("main: creating main window.."); QC_ApplicationWindow appWin; RS_DEBUG->print("main: setting caption"); appWin.setWindowTitle(XSTR(QC_APPNAME)); RS_DEBUG->print("main: show main window"); RS_SETTINGS->beginGroup("/Geometry"); int windowWidth = RS_SETTINGS->readNumEntry("/WindowWidth", 0); int windowHeight = RS_SETTINGS->readNumEntry("/WindowHeight", 0); int windowX = RS_SETTINGS->readNumEntry("/WindowX", 30); int windowY = RS_SETTINGS->readNumEntry("/WindowY", 30); RS_SETTINGS->endGroup(); if (windowWidth != 0) appWin.resize(windowWidth, windowHeight); appWin.move(windowX, windowY); RS_SETTINGS->beginGroup("Defaults"); bool maximize = RS_SETTINGS->readNumEntry("/Maximize", 0); RS_SETTINGS->endGroup(); if (maximize || windowWidth == 0) appWin.showMaximized(); else appWin.show(); RS_DEBUG->print("main: set focus"); appWin.setFocus(); RS_DEBUG->print("main: creating main window: OK"); if (show_splash) { RS_DEBUG->print("main: updating splash"); splash->raise(); splash->showMessage(QObject::tr("Loading..."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); RS_DEBUG->print("main: processing events"); qApp->processEvents(); RS_DEBUG->print("main: updating splash: OK"); } // Set LC_NUMERIC so that entering numeric values uses . as the decimal seperator setlocale(LC_NUMERIC, "C"); RS_DEBUG->print("main: loading files.."); bool files_loaded = false; for (QStringList::Iterator it = fileList.begin(); it != fileList.end(); ++it ) { if (show_splash) { splash->showMessage(QObject::tr("Loading File %1..") .arg(QDir::toNativeSeparators(*it)), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); qApp->processEvents(); } appWin.slotFileOpen(*it, RS2::FormatUnknown); files_loaded = true; } RS_DEBUG->print("main: loading files: OK"); RS_DEBUG->print("main: app.exec()"); if (!files_loaded) { appWin.slotFileNewNew(); } if (show_splash) splash->finish(&appWin); else delete splash; int return_code = app.exec(); RS_DEBUG->print("main: exited Qt event loop"); return return_code; }
/** * Main. Creates Application window. */ int main(int argc, char** argv) { QT_REQUIRE_VERSION(argc, argv, "5.2.1"); RS_DEBUG->setLevel(RS_Debug::D_WARNING); QApplication app(argc, argv); QCoreApplication::setOrganizationName("LibreCAD"); QCoreApplication::setApplicationName("LibreCAD"); QCoreApplication::setApplicationVersion(XSTR(LC_VERSION)); QSettings settings; bool first_load = settings.value("Startup/FirstLoad", 1).toBool(); const QString lpDebugSwitch0("-d"),lpDebugSwitch1("--debug") ; const QString help0("-h"), help1("--help"); bool allowOptions=true; QList<int> argClean; for (int i=0; i<argc; i++) { QString argstr(argv[i]); if(allowOptions&&QString::compare("--", argstr)==0) { allowOptions=false; continue; } if (allowOptions && (help0.compare(argstr, Qt::CaseInsensitive)==0 || help1.compare(argstr, Qt::CaseInsensitive)==0 )) { qDebug()<<"librecad::usage: <options> <dxf file>"; qDebug()<<"-h, --help\tdisplay this message"; qDebug()<<""; qDebug()<<" --help\tdisplay this message"; qDebug()<<"-d, --debug <level>"; RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:"); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Nothing", RS_Debug::D_NOTHING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Critical", RS_Debug::D_CRITICAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Error", RS_Debug::D_ERROR); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Warning", RS_Debug::D_WARNING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Notice", RS_Debug::D_NOTICE); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Informational", RS_Debug::D_INFORMATIONAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Debugging", RS_Debug::D_DEBUGGING); exit(0); } if ( allowOptions&& (argstr.startsWith(lpDebugSwitch0, Qt::CaseInsensitive) || argstr.startsWith(lpDebugSwitch1, Qt::CaseInsensitive) )) { argClean<<i; // to control the level of debugging output use --debug with level 0-6, e.g. --debug3 // for a list of debug levels use --debug? // if no level follows, the debugging level is set argstr.remove(QRegExp("^"+lpDebugSwitch0)); argstr.remove(QRegExp("^"+lpDebugSwitch1)); char level; if(argstr.size()==0) { if(i+1<argc) { if(QRegExp("\\d*").exactMatch(argv[i+1])) { ++i; qDebug()<<"reading "<<argv[i]<<" as debugging level"; level=argv[i][0]; argClean<<i; } else level='3'; } else level='3'; //default to D_WARNING } else level=argstr.toStdString()[0]; switch(level) { case '?' : RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:"); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Nothing", RS_Debug::D_NOTHING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Critical", RS_Debug::D_CRITICAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Error", RS_Debug::D_ERROR); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Warning", RS_Debug::D_WARNING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Notice", RS_Debug::D_NOTICE); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Informational", RS_Debug::D_INFORMATIONAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Debugging", RS_Debug::D_DEBUGGING); return 0; case '0' + RS_Debug::D_NOTHING : RS_DEBUG->setLevel( RS_Debug::D_NOTHING); ++i; break; case '0' + RS_Debug::D_CRITICAL : RS_DEBUG->setLevel( RS_Debug::D_CRITICAL); ++i; break; case '0' + RS_Debug::D_ERROR : RS_DEBUG->setLevel( RS_Debug::D_ERROR); ++i; break; case '0' + RS_Debug::D_WARNING : RS_DEBUG->setLevel( RS_Debug::D_WARNING); ++i; break; case '0' + RS_Debug::D_NOTICE : RS_DEBUG->setLevel( RS_Debug::D_NOTICE); ++i; break; case '0' + RS_Debug::D_INFORMATIONAL : RS_DEBUG->setLevel( RS_Debug::D_INFORMATIONAL); ++i; break; case '0' + RS_Debug::D_DEBUGGING : RS_DEBUG->setLevel( RS_Debug::D_DEBUGGING); ++i; break; default : RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING); break; } } } RS_DEBUG->print("param 0: %s", argv[0]); QFileInfo prgInfo( QFile::decodeName(argv[0]) ); QString prgDir(prgInfo.absolutePath()); RS_SETTINGS->init(app.organizationName(), app.applicationName()); RS_SYSTEM->init(app.applicationName(), app.applicationVersion(), XSTR(QC_APPDIR), prgDir); // parse command line arguments that might not need a launched program: QStringList fileList = handleArgs(argc, argv, argClean); QString unit = settings.value("Defaults/Unit", "Invalid").toString(); // show initial config dialog: if (first_load) { RS_DEBUG->print("main: show initial config dialog.."); QG_DlgInitial di(nullptr); QPixmap pxm(":/main/intro_librecad.png"); di.setPixmap(pxm); if (di.exec()) { RS_SETTINGS->beginGroup("/Defaults"); unit = RS_SETTINGS->readEntry("/Unit", "None"); RS_SETTINGS->endGroup(); } RS_DEBUG->print("main: show initial config dialog: OK"); } auto splash = new QSplashScreen; bool show_splash = settings.value("Startup/ShowSplash", 1).toBool(); if (show_splash) { QPixmap pixmap(":/main/splash_librecad.png"); splash->setPixmap(pixmap); splash->setAttribute(Qt::WA_DeleteOnClose); splash->show(); splash->showMessage(QObject::tr("Loading.."), Qt::AlignRight|Qt::AlignBottom, Qt::black); app.processEvents(); RS_DEBUG->print("main: splashscreen: OK"); } RS_DEBUG->print("main: init fontlist.."); RS_FONTLIST->init(); RS_DEBUG->print("main: init fontlist: OK"); RS_DEBUG->print("main: init patternlist.."); RS_PATTERNLIST->init(); RS_DEBUG->print("main: init patternlist: OK"); RS_DEBUG->print("main: loading translation.."); settings.beginGroup("Appearance"); QString lang = settings.value("Language", "en").toString(); QString langCmd = settings.value("LanguageCmd", "en").toString(); settings.endGroup(); RS_SYSTEM->loadTranslation(lang, langCmd); RS_DEBUG->print("main: loading translation: OK"); RS_DEBUG->print("main: creating main window.."); QC_ApplicationWindow appWin; RS_DEBUG->print("main: setting caption"); appWin.setWindowTitle(app.applicationName()); RS_DEBUG->print("main: show main window"); settings.beginGroup("Geometry"); int windowWidth = settings.value("WindowWidth", 1024).toInt(); int windowHeight = settings.value("WindowHeight", 1024).toInt(); int windowX = settings.value("WindowX", 32).toInt(); int windowY = settings.value("WindowY", 32).toInt(); settings.endGroup(); if (!first_load) appWin.resize(windowWidth, windowHeight); appWin.move(windowX, windowY); bool maximize = settings.value("Startup/Maximize", 0).toBool(); if (maximize || first_load) appWin.showMaximized(); else appWin.show(); RS_DEBUG->print("main: set focus"); appWin.setFocus(); RS_DEBUG->print("main: creating main window: OK"); if (show_splash) { RS_DEBUG->print("main: updating splash"); splash->raise(); splash->showMessage(QObject::tr("Loading..."), Qt::AlignRight|Qt::AlignBottom, Qt::black); RS_DEBUG->print("main: processing events"); qApp->processEvents(); RS_DEBUG->print("main: updating splash: OK"); } // Set LC_NUMERIC so that entering numeric values uses . as the decimal seperator setlocale(LC_NUMERIC, "C"); RS_DEBUG->print("main: loading files.."); bool files_loaded = false; for (QStringList::Iterator it = fileList.begin(); it != fileList.end(); ++it ) { if (show_splash) { splash->showMessage(QObject::tr("Loading File %1..") .arg(QDir::toNativeSeparators(*it)), Qt::AlignRight|Qt::AlignBottom, Qt::black); qApp->processEvents(); } appWin.slotFileOpen(*it, RS2::FormatUnknown); files_loaded = true; } RS_DEBUG->print("main: loading files: OK"); if (!files_loaded) { appWin.slotFileNewNew(); } if (show_splash) splash->finish(&appWin); else delete splash; if (first_load) settings.setValue("Startup/FirstLoad", 0); RS_DEBUG->print("main: entering Qt event loop"); int return_code = app.exec(); RS_DEBUG->print("main: exited Qt event loop"); return return_code; }
//handle production "Exp -> ...|... " //maybe it waste some time , should modify later SpecialType *handleExp(CSNode *root) { if(isProduction_3(root,MyEXP,MyEXP,MyASSIGNOP,MyEXP) == 1) { CSNode *lexp = root->firstChild; CSNode *rexp = lexp->nextSibling->nextSibling; SpecialType *ltype = NULL; SpecialType *rtype = NULL; ltype = handleExp(lexp); rtype = handleExp(rexp); if(!(isProduction_1(lexp,MyEXP,MyID) == 1 || isProduction_4(lexp,MyEXP,MyEXP,MyLB,MyEXP,MyRB) == 1 || isProduction_3(lexp,MyEXP,MyEXP,MyDOT,MyID) == 1)) { printf("Error type 6 at Line %d: The left-hand side of an assignment must be a variable.\n",lexp->lineNo); semanticFlag = 0; return NULL; } if(ltype == NULL || rtype == NULL) { //printf("left or right has a error, =\n"); semanticFlag = 0; return NULL; } if(compareSpecialType(ltype,rtype) == 0) { printf("Error type 5 at Line %d: Type mismatched for assignment.\n",lexp->nextSibling->lineNo); semanticFlag = 0; return NULL; } return ltype; } else if(isProduction_3(root,MyEXP,MyEXP,MyAND,MyEXP) == 1 || isProduction_3(root,MyEXP,MyEXP,MyOR,MyEXP) == 1) { CSNode *lexp = root->firstChild; CSNode *rexp = lexp->nextSibling->nextSibling; SpecialType *ltype = NULL; SpecialType *rtype = NULL; ltype = handleExp(lexp); rtype = handleExp(rexp); if(ltype == NULL || rtype == NULL) { //printf("left or right type has error, || &&\n"); semanticFlag = 0; return NULL; } if(compareSpecialType(ltype,rtype) == 0) { printf("Error type 7 at Line %d: Type mismatched for operands.\n",lexp->nextSibling->lineNo); semanticFlag = 0; return NULL; } if(!(ltype->kind == BASIC && (ltype->u).basic == 0)) { printf("Error type 7 at Line %d: Type mismatched for operand and operator. The left operand should be an integer.\n",lexp->lineNo); semanticFlag = 0; return NULL; } if(!(rtype->kind == BASIC && (rtype->u).basic == 0)) { printf("Error type 7 at Line %d: Type mismatched for operand and operator. The right operand should be an integer.\n",rexp->lineNo); semanticFlag = 0; return NULL; } return ltype; } else if(isProduction_3(root,MyEXP,MyEXP,MyRELOP,MyEXP) == 1 || isProduction_3(root,MyEXP,MyEXP,MyPLUS,MyEXP) == 1 || isProduction_3(root,MyEXP,MyEXP,MyMINUS,MyEXP) == 1 || isProduction_3(root,MyEXP,MyEXP,MySTAR,MyEXP) == 1 || isProduction_3(root,MyEXP,MyEXP,MyDIV,MyEXP) == 1 ) { CSNode *lexp = root->firstChild; CSNode *rexp = lexp->nextSibling->nextSibling; SpecialType *ltype = NULL; SpecialType *rtype = NULL; ltype = handleExp(lexp); rtype = handleExp(rexp); if(ltype == NULL || rtype == NULL) { //printf("left or right type has error,+-\n"); semanticFlag = 0; return NULL; } if(compareSpecialType(ltype,rtype) == 0) { printf("Error type 7 at Line %d: Type mismatched for operands.\n",lexp->nextSibling->lineNo); semanticFlag = 0; return NULL; } if(ltype->kind != BASIC) { printf("Error type 7 at Line %d: Type mismatched for operand and operator. The left operand should be an interger or float.\n",lexp->lineNo); semanticFlag = 0; return NULL; } if(rtype->kind != BASIC) { printf("Error type 7 at Line %d: Type mismatched for operand and operator. The right operand should be an integer or float.\n",rexp->lineNo); semanticFlag = 0; return NULL; } if((ltype->u).basic == 1 && isProduction_3(root,MyEXP,MyEXP,MyRELOP,MyEXP) == 1) { SpecialType *type = NULL; type = (SpecialType *)malloc(sizeof(SpecialType)); type->kind = BASIC; (type->u).basic = 0; type->size = getSizeOfSpecialType(type); return type; } return ltype; } else if(isProduction_3(root,MyEXP,MyLP,MyEXP,MyRP) == 1) { SpecialType *type = NULL; type = handleExp(root->firstChild->nextSibling); return type; } else if(isProduction_2(root,MyEXP,MyMINUS,MyEXP) == 1) { SpecialType *type = NULL; CSNode *expNode = root->firstChild->nextSibling; type = handleExp(expNode); if(type == NULL) { //printf("type has error after -\n"); semanticFlag = 0; return NULL; } if(type->kind != BASIC) { printf("Error type 7 at Line %d: Type mismatched for operand and operator. The operand should be an integer or float.\n",expNode->lineNo); semanticFlag = 0; return NULL; } return type; } else if(isProduction_2(root,MyEXP,MyNOT,MyEXP) == 1) { SpecialType *type = NULL; CSNode *expNode = root->firstChild->nextSibling; type = handleExp(expNode); if(type == NULL) { //printf("type has a error after !\n"); semanticFlag = 0; return NULL; } if(!(type->kind == BASIC && (type->u).basic == 0)) { printf("Error type 7 at Line %d: Type mismatched for operand and operator. The operand should be an integer.\n",expNode->lineNo); semanticFlag = 0; return NULL; } return type; } else if(isProduction_4(root,MyEXP,MyID,MyLP,MyARGS,MyRP) == 1) { char *name = (root->firstChild->type_union).type_id.p_str; SYNode *checkFlag = NULL; checkFlag = checkSymbolName(0,name); if(checkFlag == NULL) { printf("Error type 2 at Line %d: Undefined function \"%s\".\n",root->firstChild->lineNo,name); semanticFlag = 0; return NULL; } if(checkFlag->type != MyFUNCNAME) { printf("Error type 11 at Line %d: \"%s\" is not a function.\n",root->firstChild->lineNo,name); semanticFlag = 0; return NULL; } SYMBOL_FUNC *fc = (SYMBOL_FUNC *)(checkFlag->content); CSNode *argsNode = root->firstChild->nextSibling->nextSibling; int countOfArgs = getCountOfArgs(argsNode); if(fc->param_num != countOfArgs) { printf("Error type 9 at Line %d: The number of arguments and the number of parameters are not equal for function \"%s\".\n",root->firstChild->lineNo,name); semanticFlag = 0; return NULL; } FieldList *fd_param = handleArgs(argsNode); if(compareFieldList(fc->param,fd_param) == 0) { printf("Error type 9 at Line %d: The type of arguments and the type of parameters are not equal for function \"%s\".\n",root->firstChild->lineNo,name); semanticFlag = 0; return NULL; } return fc->rel; } else if(isProduction_3(root,MyEXP,MyID,MyLP,MyRP) == 1) { char *name = (root->firstChild->type_union).type_id.p_str; SYNode *checkFlag = NULL; checkFlag = checkSymbolName(0,name); if(checkFlag == NULL) { printf("Error type 2 at Line %d: Undefined function \"%s\".\n",root->firstChild->lineNo,name); semanticFlag = 0; return NULL; } if(checkFlag->type != MyFUNCNAME) { printf("Error type 11 at Line %d: \"%s\" is not a function.\n",root->firstChild->lineNo,name); semanticFlag = 0; return NULL; } SYMBOL_FUNC *fc = (SYMBOL_FUNC *)(checkFlag->content); if(!(fc->param == NULL && fc->param_num == 0)) { printf("Error type 9 at Line %d: The number of arguments and the number of parameters are not equal for function \"%s\".\n",root->firstChild->lineNo,name); semanticFlag = 0; return NULL; } return fc->rel; } else if(isProduction_4(root,MyEXP,MyEXP,MyLB,MyEXP,MyRB) == 1) { CSNode *exp1 = root->firstChild; CSNode *exp2 = exp1->nextSibling->nextSibling; SpecialType *type1 = handleExp(exp1); SpecialType *type2 = handleExp(exp2); if(type1 == NULL || type2 == NULL) { //printf("type has a error , []\n"); semanticFlag = 0; return NULL; } if(type1->kind != ARRAY) { printf("Error type 10 at Line %d: Variable is not an array or the element of the array is not an array.\n",exp1->lineNo); semanticFlag = 0; return NULL; } if(!(type2->kind == BASIC && (type2->u).basic == 0)) { printf("Error type 12 at Line %d: The value between \"[\" and \"]\" is not an interger.\n",exp2->lineNo); semanticFlag = 0; return NULL; } return (type1->u).array.elem; } else if(isProduction_3(root,MyEXP,MyEXP,MyDOT,MyID) == 1) { SpecialType *type = NULL; type = handleExp(root->firstChild); CSNode *idNode = root->firstChild->nextSibling->nextSibling; char *name = (idNode->type_union).type_id.p_str; if(type == NULL) { //printf("type has a error, .id\n"); semanticFlag = 0; return NULL; } if(type->kind != STRUCTURE) { printf("Error type 13 at Line %d: Illegal use of \".\".\n",root->firstChild->nextSibling->lineNo); semanticFlag = 0; return NULL; } FieldList *fd = (type->u).structure; FieldList *checkFlag = NULL; checkFlag = checkSameNameFL(name,fd); if(checkFlag == NULL) { printf("Error type 14 at Line %d: Non-existent field \"%s\".\n",idNode->lineNo,name); semanticFlag = 0; return NULL; } return checkFlag->type; } else if(isProduction_1(root,MyEXP,MyID) == 1) { char *name = (root->firstChild->type_union).type_id.p_str; SYNode *checkFlag = NULL; checkFlag = checkSymbolName(0,name); if(checkFlag == NULL) { printf("Error type 1 at Line %d: Undefined variable \"%s\".\n",root->firstChild->lineNo,name); semanticFlag = 0; return NULL; } if(checkFlag->type == MySTRUCTNAME || checkFlag->type == MyFUNCNAME) { printf("Error type 1 at Line %d: Undefined variable \"%s\",it is a name of a struct or a function, not a variable.\n",root->firstChild->lineNo,name); semanticFlag = 0; return NULL; } if(checkFlag->type == MyINTVAR) { return ((SYMBOL_INT *)(checkFlag->content))->type; } if(checkFlag->type == MyFLOATVAR) { return ((SYMBOL_FLOAT *)(checkFlag->content))->type; } if(checkFlag->type == MyARRAYVAR) { return ((SYMBOL_ARRAY *)(checkFlag->content))->type; } if(checkFlag->type == MySTRUCTVAR) { return ((SYMBOL_STRUCTVAR *)(checkFlag->content))->type; } else { printf("error type id\n"); semanticFlag = 0; return NULL; } } else if(isProduction_1(root,MyEXP,MyINT) == 1) { SpecialType *type = NULL; type = (SpecialType *)malloc(sizeof(SpecialType)); type->kind = BASIC; (type->u).basic = 0; type->size = getSizeOfSpecialType(type); return type; } else if(isProduction_1(root,MyEXP,MyFLOAT) == 1) { SpecialType *type = NULL; type = (SpecialType *)malloc(sizeof(SpecialType)); type->kind = BASIC; (type->u).basic = 1; type->size = getSizeOfSpecialType(type); return type; } else { printf("error Exp production\n"); semanticFlag = 0; return NULL; } }
int main(int argc, char* argv[]) { date_t tempDate; long startAbs, endAbs; char *envStr; int envArgc; char *envArgv[40]; /* this should be big enough */ progname = argv[0]; set_default_city(); if ((envStr = getenv(ENV_OPTS)) && strcmp(envStr, "")) { int i; tokenize(envStr, &envArgc, envArgv); for (i = 1; i < argc; i++) /* append argv onto envArgv */ envArgv[envArgc++] = argv[i]; handleArgs(envArgc, envArgv); } else handleArgs(argc, argv); tempDate.yy = theYear; if (theYear < (hebrewDates_sw ? 3761 : 1)) die("Sorry, hebcal can only handle dates in the common era.", ""); switch (rangeType) { case TODAY: printHebDates_sw = 1; tempDate.dd = theDay; tempDate.mm = theMonth; tempDate.yy = theYear; startAbs = endAbs = greg2abs(tempDate); break; case DAY: printHebDates_sw = 1; tempDate.dd = theDay; tempDate.mm = theMonth; tempDate.yy = theYear; if (hebrewDates_sw) startAbs = endAbs = hebrew2abs(tempDate); else startAbs = endAbs = greg2abs(tempDate); break; case MONTH: tempDate.dd = 1; tempDate.mm = theMonth; tempDate.yy = theYear; if (hebrewDates_sw) { startAbs = hebrew2abs(tempDate); tempDate.dd = max_days_in_heb_month(tempDate.mm, tempDate.yy); endAbs = hebrew2abs(tempDate); } else { startAbs = greg2abs(tempDate); tempDate.dd = MonthLengths[LEAP(theYear)][theMonth]; endAbs = greg2abs(tempDate); } break; case YEAR: if (hebrewDates_sw) { tempDate.dd = 1; tempDate.mm = TISHREI; tempDate.yy = theYear; startAbs = hebrew2abs(tempDate); /* start yearly calendar with the day before RH (i.e. Erev * Rosh Hashanah) */ startAbs--; tempDate.yy++; endAbs = hebrew2abs(tempDate) - 1; } else { tempDate.dd = 1; tempDate.mm = JAN; tempDate.yy = theYear; startAbs = greg2abs(tempDate); tempDate.yy++; endAbs = greg2abs(tempDate) - 1; } break; default: die("Oh, NO! internal error #17q!", ""); /* this is dead code, but it silences some uninitialized variable warnings in gcc */ startAbs = endAbs =0; } tempDate = abs2hebrew(startAbs); if (ok_to_run) { init_holidays(tempDate.yy); /* load the holiday array */ main_calendar(startAbs, endAbs); return 0; /* success! Kol hakavod to thorough programmers */ } else return 1; }