int temporary_files_creation(){ #if defined(__linux) || defined(__APPLE__) if (mkstemp(TRIVIAL_ENCODING_FILE) == -1){ fprintf(stderr,"Error on opening trivial temporary file: %s.\n", TRIVIAL_ENCODING_FILE); removeTempFiles(); return -1; } if (mkstemp(CONSTRAINTS_FILE) == -1){ fprintf(stderr,"Error on opening constraint temporary file: %s.\n", CONSTRAINTS_FILE); removeTempFiles(); return -1; } if (mkstemp(TMP_FILE) == -1){ fprintf(stderr,"Error on opening temporary file: %s.\n", TMP_FILE); removeTempFiles(); return -1; } if (mkstemp(SCRIPT_PATH) == -1){ fprintf(stderr,"Error on opening temporary file: %s.\n", SCRIPT_PATH); removeTempFiles(); return -1; } #else TRIVIAL_ENCODING_FILE = tmpnam (NULL); CONSTRAINTS_FILE = tmpnam (NULL); TMP_FILE = tmpnam (NULL); SCRIPT_PATH = tmpnam (NULL); #endif return 0; }
void BtInstallThread::slotStopInstall() { qDebug() << "*************************************\nBtInstallThread::slotStopInstall" << m_module << "\n********************************"; if (!done) { done = true; qDebug() << "*********************************\nBtInstallThread::slotStopInstall, installing" << m_module << "was cancelled\n**************************************"; m_iMgr->terminate(); //this->terminate(); // It's dangerous to forcibly stop, but we will clean up the files qDebug() << "BtInstallThread::slotStopInstall 2"; //qApp->processEvents(); // wait to terminate for some secs. We rather let the execution go on and cleaning up to fail than the app to freeze int notRun = this->wait(200); if (notRun) { this->terminate(); this->wait(2); qDebug() << "installthread ("<< m_module << ") terminated, delete m_iMgr"; delete m_iMgr; // this makes sure the ftp library will be cleaned up in the destroyer m_iMgr = 0; } qDebug() << "BtInstallThread::slotStopInstall 3"; // cleanup: remove the module, remove the temp files if (true) { qDebug() << "BtInstallThread::slotStopInstall 4"; // remove the installed module, just to be sure because mgr may // have been terminated when copying files removeModule(); removeTempFiles(); qDebug() << "BtInstallThread::slotStopInstall will emit installStopped..."; emit installStopped(m_module, m_source); } } }
void BtInstallThread::slotStopInstall() { qDebug() << "BtInstallThread::slotStopInstall, installing" << m_module << "was cancelled"; if (!done) { done = true; qDebug() << "BtInstallThread::slotStopInstall 1"; m_iMgr.terminate(); this->terminate(); // It's dangerous to forcibly stop, but we will clean up the files qDebug() << "BtInstallThread::slotStopInstall 2"; //qApp->processEvents(); // wait to terminate for some secs. We rather let the execution go on and cleaning up to fail than the app to freeze this->wait(3000); qDebug() << "BtInstallThread::slotStopInstall 3"; qApp->processEvents(); // cleanup: remove the module, remove the temp files // Actually m_iMgr is unnecessary, it could be local in the run(). if (true) { qDebug() << "BtInstallThread::slotStopInstall 4"; // remove the installed module, just to be sure because mgr may // have been terminated when copying files removeModule(); qApp->processEvents(); removeTempFiles(); qApp->processEvents(); qDebug() << "BtInstallThread::slotStopInstall will emit installStopped..."; emit installStopped(m_module, m_source); qApp->processEvents(); } } qDebug() << "BtInstallThread::slotStopInstall end"; }
static int error(int status) { removeTempFiles(); fprintf(stderr, "*** %s exit status %d\n", plld, status); exit(status); return 1; /* not reached */ }
void Package::saveAs(const String& name, bool remove_unused) { // type of package if (wxDirExists(name)) { saveToDirectory(name, remove_unused, false); } else { saveToZipfile (name, remove_unused, false); } filename = name; removeTempFiles(remove_unused); reopen(); }
int main(int argc, char *argv[]) { //define qapplication class QApplication app(argc, argv); //make string variable char str[STRLEN]; //make file object FILE *file; //quit if it is not the only Yellowcot instance memset(str, 0, STRLEN); sprintf(str, "%s", TMPDIR); if ((file = fopen(str, "r"))) { memset(str, 0, STRLEN); sprintf(str, "Multiple, simultaneous instances of Yellowcot is not yet a supported feature. If you are certain another instance is not running, you may execute \"sudo rm -r %s\".", TMPDIR); QMessageBox::critical(0, QString("Fatal Error"), QString(str)); return 1; fclose (file); } //create temporary directory for yellowcot quiz sysprintf("mkdir %s", TMPDIR); //create config file if it doesn't already exist sysprintf("cp ~/.yellowcot/config %s/config > /dev/null 2>&1", TMPDIR); memset(str, 0, STRLEN); sprintf(str, "%s/config", TMPDIR); if ((file = fopen(str, "r"))) { fclose(file); remove(str); } else { sysprintf("echo -e \"# Yellowcot configuration file\n#\n# If you'd like to use a font other than the default, specify\n# its path (e.g. /usr/local/share/fonts/c/code2000.ttf) here.\n#font=\n# Specify the font size here.\nfontsize=24\" > %s/config", TMPDIR); sysprintf("mkdir ~/.yellowcot"); sysprintf("mv %s/config ~/.yellowcot/config", TMPDIR); } //start translator QTranslator translator; translator.load(QString("yellowcot_") + QLocale::system().name()); app.installTranslator(&translator); //create and show main window MainWindow mainWindow; mainWindow.show(); //delete temporary file when yellowcot is about to quit QObject::connect(&app, SIGNAL(aboutToQuit()), &mainWindow, SLOT(removeTempFiles())); //pass control to qt return app.exec(); }
void OcrEngine::finishedOCRVisible(bool success) { if (m_ocrDialog!=NULL) m_ocrDialog->enableGUI(false); if (success) { emit newOCRResultText(); if (m_imgCanvas!=NULL) { if (m_resultImage!=NULL) delete m_resultImage; m_resultImage = new QImage(m_ocrResultFile); kDebug() << "Result image" << m_ocrResultFile << "size" << m_resultImage->size(); /* The image canvas is present. Set it to our image */ m_imgCanvas->newImage(m_resultImage, true); m_imgCanvas->setReadOnly(true); /* now handle double clicks to jump to the word */ m_trackingActive = true; } /* now it is time to invoke the dictionary if required */ // TODO: readOnlyEditor needed here? Also done in finishResultDocument() emit readOnlyEditor(false); // user can now edit if (m_ocrDialog!=NULL) { emit setSpellCheckConfig(m_ocrDialog->customSpellConfigFile()); bool doSpellcheck = m_ocrDialog->wantInteractiveSpellCheck(); bool bgSpellcheck = m_ocrDialog->wantBackgroundSpellCheck(); emit startSpellCheck(doSpellcheck, bgSpellcheck); } } if (m_ocrDialog!=NULL) m_ocrDialog->hide(); // close the dialogue m_ocrRunning = false; removeTempFiles(); kDebug() << "OCR finished"; }
static void cleanup() { removeTempFiles(); removeTempDirectories(); removeSemaphores(); }
int main(int argc, char **argv) { int special; plld = argv[0]; argc--; argv++; catchSignals(); if ( argc == 0 ) { fprintf(stderr, "No input files. Use %s -help.\n", plld); exit(0); } putenv("PLLD=true"); /* for subprograms */ verbose = FALSE; if ( argc > 2 && streq(argv[0], "-pl") ) special = 2; else special = 0; /* swipl-ld [-pl x] -v: verbose */ if ( argc-special == 1 && streq(argv[special], "-v") ) { arglist coptions; int i; memset(&coptions, 0, sizeof(coptions)); for(i=special; i < argc; i++) appendArgList(&coptions, argv[i]); callprog(PROG_CC, &coptions); return 0; } parseOptions(argc, argv); defaultProgram(&pl, PROG_PL); if ( build_defaults ) { nostate = TRUE; /* not needed and Prolog won't run */ defaultProgram(&cc, C_CC); #ifdef PLBASE defaultPath(&plbase, PLBASE); #else defaultPath(&plbase, PLHOME); #endif defaultPath(&plarch, PLARCH); defaultProgram(&pllib, C_PLLIB); addOptionString(C_LIBS); appendArgList(&ldoptions, C_LDFLAGS); appendArgList(&coptions, C_CFLAGS); appendArgList(&cppoptions, C_CFLAGS); #ifdef SO_EXT soext = strdup(SO_EXT); #endif #ifdef O_PLMT ensureOption(&coptions, "-D_REENTRANT"); ensureOption(&cppoptions, "-D_REENTRANT"); #ifdef _THREAD_SAFE /* FreeBSD */ ensureOption(&coptions, "-D_THREAD_SAFE"); ensureOption(&cppoptions, "-D_THREAD_SAFE"); #endif #endif } else { getPrologOptions(); } fillDefaultOptions(); if ( show_version ) { callprog(cc, &coptions); exit(0); } compileObjectFiles(); if ( !nolink ) { if ( shared ) linkSharedObject(); else { linkBaseExecutable(); if ( !nostate ) { createSavedState(); createOutput(); } } } removeTempFiles(); return 0; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { atexit(dumpLeaks); // _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); if (strstr(lpCmdLine, "-s") != 0) { Setup(true, false); exit(0); } lang.init(); StringCache::getInstance().init(); GetCurrentDirectory(MAX_PATH, programPath); getUserFile(settings, "meospref.xml"); Parser::test(); int rInit = (GetTickCount() / 100); InitRanom(rInit, rInit/379); tabList=new list<TabObject>; MSG msg; HACCEL hAccelTable; gdi_main = new gdioutput("main", 1.0, ANSI); gdi_extra.push_back(gdi_main); try { gEvent = new oEvent(*gdi_main); } catch (std::exception &ex) { gdi_main->alert(string("Failed to create base event: ") + ex.what()); return 0; } gEvent->loadProperties(settings); lang.get().addLangResource("English", "104"); lang.get().addLangResource("Svenska", "103"); lang.get().addLangResource("Deutsch", "105"); lang.get().addLangResource("Dansk", "106"); lang.get().addLangResource("Russian (ISO 8859-5)", "107"); lang.get().addLangResource("English (ISO 8859-2)", "108"); if (fileExist("extra.lng")) { lang.get().addLangResource("Extraspråk", "extra.lng"); } else { char lpath[260]; getUserFile(lpath, "extra.lng"); if (fileExist(lpath)) lang.get().addLangResource("Extraspråk", lpath); } string defLang = gEvent->getPropertyString("Language", "Svenska"); // Backward compatibility if (defLang=="103") defLang = "Svenska"; else if (defLang=="104") defLang = "English"; gEvent->setProperty("Language", defLang); try { lang.get().loadLangResource(defLang); } catch (std::exception &) { lang.get().loadLangResource("Svenska"); } try { char listpath[MAX_PATH]; getUserFile(listpath, ""); vector<string> res; expandDirectory(listpath, "*.lxml", res); expandDirectory(listpath, "*.listdef", res); # #ifdef _DEBUG expandDirectory(".\\Lists\\", "*.lxml", res); expandDirectory(".\\Lists\\", "*.listdef", res); #endif string err; for (size_t k = 0; k<res.size(); k++) { try { xmlparser xml(0); strcpy_s(listpath, res[k].c_str()); xml.read(listpath); xmlobject xlist = xml.getObject(0); gEvent->getListContainer().load(MetaListContainer::InternalList, xlist, true); } catch (std::exception &ex) { string errLoc = "Kunde inte ladda X\n\n(Y)#" + string(listpath) + "#" + lang.tl(ex.what()); if (err.empty()) err = errLoc; else err += "\n" + errLoc; } } if (!err.empty()) gdi_main->alert(err); } catch (std::exception &ex) { gdi_main->alert(ex.what()); //exit(1); } gEvent->openRunnerDatabase("database"); strcpy_s(szTitle, "MeOS"); strcpy_s(szWindowClass, "MeosMainClass"); strcpy_s(szWorkSpaceClass, "MeosWorkSpace"); MyRegisterClass(hInstance); registerToolbar(hInstance); string encoding = lang.tl("encoding"); gdi_main->setFont(gEvent->getPropertyInt("TextSize", 0), gEvent->getPropertyString("TextFont", "Arial"), interpetEncoding(encoding)); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } RECT rc; GetClientRect(hWndMain, &rc); SendMessage(hWndMain, WM_SIZE, 0, MAKELONG(rc.right, rc.bottom)); gdi_main->init(hWndWorkspace, hWndMain, hMainTab); gdi_main->getTabs().get(TCmpTab)->loadPage(*gdi_main); autoTask = new AutoTask(hWndMain, *gEvent, *gdi_main); autoTask->setTimers(); // Install a hook procedure to monitor the message stream for mouse // messages intended for the controls in the dialog box. g_hhk = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, (HINSTANCE) NULL, GetCurrentThreadId()); hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MEOS); initMySQLCriticalSection(true); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } tabAutoRegister(0); tabList->clear(); delete tabList; tabList=0; delete autoTask; autoTask = 0; for (size_t k = 0; k<gdi_extra.size(); k++) { if (gdi_extra[k]) { DestroyWindow(gdi_extra[k]->getHWND()); if (k < gdi_extra.size()) { delete gdi_extra[k]; gdi_extra[k] = 0; } } } gdi_extra.clear(); if (gEvent) gEvent->saveProperties(settings); delete gEvent; gEvent = 0; initMySQLCriticalSection(false); removeTempFiles(); #ifdef _DEBUG lang.get().debugDump("untranslated.txt", "translated.txt"); #endif StringCache::getInstance().clear(); lang.unload(); return msg.wParam; }