bool MpkManip::cleanupFragment(const char* mpkFilename) { bool bOk = false; HANDLE hMpk = 0; char tempFilename[MAX_PATH]; if(SFileCreateArchiveEx(mpkFilename,OPEN_EXISTING,8000,&hMpk)) { uint nTotal = SFileGetFileInfo(hMpk,SFILE_INFO_NUM_FILES); uint nFiles = 0; char tempPath[MAX_PATH]; getTempPath(MAX_PATH, tempPath); getTempFileName(tempPath,tempFilename); HANDLE hTargetMpk = 0; if(SFileCreateArchiveEx(tempFilename,CREATE_ALWAYS,8000,&hTargetMpk)) { SFILE_FIND_DATA fileFindData; HANDLE hFind = SFileFindFirstFile(hMpk,"*",&fileFindData,0); if(hFind) { do { const char* pFilename = fileFindData.cFileName; char tempFilename[MAX_PATH]; getTempFileName(tempPath,tempFilename); if(SFileExtractFile(hMpk,pFilename,tempFilename)) { if(SFileAddFile(hTargetMpk,tempFilename,pFilename,MPK_FILE_REPLACEEXISTING | MPK_FILE_COMPRESS_PKWARE)) { nFiles++; } } } while(SFileFindNextFile(hFind,&fileFindData)); if(nTotal == nFiles)bOk = true; } SFileCloseArchive(hTargetMpk); } SFileCloseArchive(hMpk); } if(bOk && copyFile(tempFilename,mpkFilename,FALSE)) { bOk = true; } return bOk; }
// return "" or "-CMFN=modNamList_" where modNamList_ is a temp file that // has the list of module names to be extracted by MDFWriter. // requires: cmfn is long enough to hold "-CMFN=modNamList_". char* SQLJFile::getModuleNamesOption(Cmdline_Args &args, char *cmfn) { ExtQualModuleNames* EQMNs = args.getModuleNames(); Int32 count; if (!EQMNs || (count=EQMNs->count()) <= 0) { return ""; // means extract all } else { // create a temporary file char *modNamFil, modNam[L_tmpnam+20], templNam[L_tmpnam+26]; modNamFil = getTempFileName(modNam); if (!modNamFil) { return NULL; } FILE *tFil = createTempFile(modNamFil, templNam); if (!tFil) { return NULL; } // write into temp file the names of modules to be extracted for (Int32 x=0; x<count; x++) { const ThreePartModuleName& modNam = EQMNs->at(x); fprintf(tFil, "%s\n", modNam.catalog.c_str()); fprintf(tFil, "%s\n", modNam.schema.c_str()); fprintf(tFil, "%s\n", modNam.module.c_str()); } fclose(tFil); // return "-CMFN=modNamList_" strcpy(cmfn, "-CMFN="); strcat(cmfn, templNam); strcat(cmfn, " "); modNamList_ = templNam; return cmfn; } }
void output_openOutFile(Project* project) // // Input: none // Output: none // Purpose: opens a project's binary output file. // { // --- close output file if already opened if (project->Fout.file != NULL) fclose(project->Fout.file); // --- else if file name supplied then set file mode to SAVE else if (strlen(project->Fout.name) != 0) project->Fout.mode = SAVE_FILE; // --- otherwise set file mode to SCRATCH & generate a name else { project->Fout.mode = SCRATCH_FILE; getTempFileName(project,project->Fout.name); } // --- try to open the file if ( (project->Fout.file = fopen(project->Fout.name, "w+b")) == NULL) { writecon(FMT14); project->ErrorCode = ERR_OUT_FILE; } }
void device_PRT::CommitData() { timeOutAt = 0; BOOL wait = 0; if (destination == "direct") { DWORD dwBytesWritten = 0; HANDLE lptPort = CreateFile(name, (GENERIC_READ | GENERIC_WRITE), 0, 0, OPEN_EXISTING, 0, 0); BOOL bErrorFlag = WriteFile( lptPort, // open file handle rawdata.c_str(), // start of data to write (DWORD)rawdata.size(), // number of bytes to write &dwBytesWritten, // number of bytes that were written NULL); // no overlapped structure if (FALSE == bErrorFlag) { ErrorDialog("ERROR: Unable open '%s'", name); } rawdata.clear(); CloseHandle(lptPort); return; } if (!destination.empty()) { char* tmpFile = getTempFileName(); if (tmpFile == NULL) { ErrorDialog("ERROR: Unable to get temporary filename."); return; } FILE* fh = fopen(tmpFile, "wb"); if (fh) { if (fwrite(rawdata.c_str(), rawdata.size(), 1, fh)) { fclose(fh); executeCmd((char*)destination.c_str(), tmpFile, wait); if (wait) { remove(tmpFile); } } else { ErrorDialog("ERROR: Unable to write to temporary file '%s'.", tmpFile); } } else { ErrorDialog("ERROR: Unable to create temporary file '%s'.", tmpFile); } free(tmpFile); } else { ErrorDialog("ERROR: Port '%s' is not configured.", name); } rawdata.clear(); }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parse() { UBMetadataDcSubsetAdaptor::persist(mProxy); mIndent = ""; if (!getTempFileName() || !createTempFlashPath()) return false; if (mDOMdoc.isNull()) return false; bool result = parseDoc(); if (result) result = mProxy->pageCount() != 0; if (QFile::exists(mTempFilePath)) QFile::remove(mTempFilePath); // if (mTmpFlashDir.exists()) // UBFileSystemUtils::deleteDir(mTmpFlashDir.path()); return result; }
// open SQLJ file for extraction of embedded module definitions. // return true if all OK. bool SQLJFile::openFile(Cmdline_Args &args) { // put together MDFWriter invocation Lng32 cmdLen; char cmd[1024], *cmdP=cmd, *moduleNamesOption, cmfn[L_tmpnam+40]; char *errFileName,errFileNm[L_tmpnam+20]; char *outputFileName,outputFileNm[L_tmpnam+20]; if ((moduleNamesOption=getModuleNamesOption(args,cmfn)) == NULL || (errFileName=getTempFileName(errFileNm)) == NULL || (outputFileName=getTempFileName(outputFileNm)) == NULL) { return ApplicationFile::openFile(args); } // invoke MDFWriter to extract modules const char mdfWriter[]= "java sqlj.runtime.profile.util.MDFWriter"; cmdLen = strlen(mdfWriter) + strlen(moduleNamesOption) + 2 + strlen("-CerrorFileName=") + strlen(errFileName) + 2 + strlen("-CMDFList=") + strlen(outputFileName) + 1 + args.application().length(); // for efficiency we try to use the stack-allocated cmd variable. // but, no matter how big we declare it, eg: char cmd[12345], // it is always possible for someone like QA try something like // mxCompileUserModule -d CQD1=v1 -d CQD2=v2 ... -d CQDn=vn my.exe // whereby the mxcmp invocation string overflows cmd. We can always // dynamically allocate and use cmdP but "new" is very inefficient // compared to stack allocation. So, we try to get the best of both // by using stack allocation for the 90% case and use "new" only for // the pathological 10% (customer is using a program generator to // invoke us or QA is simply trying to break our code) case. if (cmdLen > 1024) { cmdP = new char[cmdLen]; } strcpy(cmdP, mdfWriter); strcat(cmdP, " "); strcat(cmdP, moduleNamesOption); strcat(cmdP, " -CerrorFileName="); strcat(cmdP, errFileName); strcat(cmdP, " -CMDFList="); strcat(cmdP, outputFileName); strcat(cmdP, " "); strcat(cmdP, args.application().c_str()); cout << cmdP << endl; Int32 rc = system(cmdP); if (cmdP != cmd) { delete cmdP; } // interpret MDFWriter's return code if (rc == 0) { // MDFWriter invocation OK // check MDFWriter output if (ACCESS(outputFileName, READABLE) != 0) { // no extractions *mxCUMptr << FAIL << DgSqlCode(-2217) << DgString0(outputFileName); } // open MDFWriter output else if ((appFile_=fopen(outputFileName, "r")) == NULL) { *mxCUMptr << FAIL << DgSqlCode(-2218) << DgString0(outputFileName); } else { // all OK if (!args.keepMdf()) { // clean up temporary file (names of modules to extract) remove(modNamList_.c_str()); } } } else if (rc == -1 ) { // function fails: cannot create child process // or cannot get child shell's exit status *mxCUMptr << FAIL << DgSqlCode(-2216) << DgInt0(rc); } else { // unsuccessful module extraction *mxCUMptr << FAIL << DgSqlCode(-2216) << DgInt0(rc); } // report any MDFWriter errors/warnings now to avoid confusing the user // with possibly interleaved MDFWriter/mxcmp errors/warnings. printMDFWriterErrors(errFileName); return ApplicationFile::openFile(args); }
void rain_open(Project* project) // // Input: none // Output: none // Purpose: opens binary rain interface file and RDII processor. // { int i; int count; // --- see how many gages get their data from a file count = 0; for (i = 0; i < project->Nobjects[GAGE]; i++) { if ( project->Gage[i].dataSource == RAIN_FILE ) count++; } project->Frain.file = NULL; if ( count == 0 ) { project->Frain.mode = NO_FILE; } // --- see what kind of rain interface file to open else switch ( project->Frain.mode ) { case SCRATCH_FILE: getTempFileName(project,project->Frain.name); if ( (project->Frain.file = fopen(project->Frain.name, "w+b")) == NULL) { report_writeErrorMsg(project,ERR_RAIN_FILE_SCRATCH, ""); return; } break; case USE_FILE: if ( (project->Frain.file = fopen(project->Frain.name, "r+b")) == NULL) { report_writeErrorMsg(project,ERR_RAIN_FILE_OPEN, project->Frain.name); return; } break; case SAVE_FILE: if ( (project->Frain.file = fopen(project->Frain.name, "w+b")) == NULL) { report_writeErrorMsg(project,ERR_RAIN_FILE_OPEN, project->Frain.name); return; } break; } // --- create new rain file if required if ( project->Frain.mode == SCRATCH_FILE || project->Frain.mode == SAVE_FILE ) { createRainFile(project,count); } // --- initialize rain file if ( project->Frain.mode != NO_FILE ) initRainFile(project); // --- open RDII processor (creates/opens a RDII interface file) rdii_openRdii(project); }
String createTempFileName(const String &ext) { String fileName = getTempFileName(_T("cXXXXXX")); _tmktemp(fileName.cstr()); return FileNameSplitter(fileName).setExtension(ext).getAbsolutePath(); }
QString myPixRead(const QString &list) { QString imageInfo; l_int32 d = 0; l_uint32 pxres = 0,pyres = 0; l_float32 scalex = 0.0,scaley = 0.0; PIX *pixs = NULL, *pix1 = NULL, *pixd = NULL; QStringList list2 = list.split(","); if (list2.count() != 2) { return QObject::tr("Failed to read QStringList"); } const QByteArray aux1 = list2.at(0).toUtf8(); //aux1 and aux2 must be not delete or change const char *fileName = aux1.constData(); const QByteArray aux2 = list2.at(1).toUtf8(); int page = aux2.toInt(0,10); if (page == 0) { if ((pixs = pixRead(fileName)) == NULL) { QString msg = QObject::tr("Failed to open image %1").arg(fileName); return msg; } } else { if ((pixs = pixReadTiff(fileName, page)) == NULL) { QString msg = QObject::tr("Failed to open subimage %1 %2") .arg(fileName) .arg(page); return msg; } } d = pixGetDepth(pixs); if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32) { QString msg = QObject::tr("depth image must be 1,2,4,8,16 or 32"); return msg; } pixGetResolution(pixs,&pxres,&pyres); imageInfo = QString("%1,%2,%3,%4,%5").arg(page).arg(pixs->w).arg(pixs->h).arg(pxres) .arg(pyres); if (pxres && pyres) { scalex = 300.0 / pxres; scaley = 300.0 / pyres; pix1 = pixScale(pixs,scalex,scaley); if (pix1->d > 1) { pixd = pixConvertTo8(pix1,FALSE); pixDestroy(&pix1); } else pixd = pix1; } else if (pixs->d > 1) pixd = pixConvertTo8(pixs,FALSE); else pixd = pixClone(pixs); pixDestroy(&pixs); /* ------------------ Image file format types -------------- */ /* * The IFF_UNKNOWN flag is used to write the file out in * a compressed and lossless format; namely, IFF_TIFF_G4 * for d = 1 and IFF_PNG for everything else. */ QByteArray fileOut(getTempFileName(aux1,page)); if (pixWrite(fileOut.constData(),pixd,IFF_DEFAULT)) { QString msg = QObject::tr("pix not written to file"); return msg; } pixDestroy(&pixd); return imageInfo; }
int main(int argc, char *argv[]) { int c, instance = -1; ACE_CString daemonRef; ACE_CString hostName; ACE_CString additional; for (;;) { int option_index = 0; c = getopt_long(argc, argv, "hi:d:H:a:", long_options, &option_index); if (c == -1) break; switch (c) { case 'h': usage(argv[0]); return 0; case 'i': instance = ACE_OS::atoi(optarg); break; case 'd': daemonRef = optarg; break; case 'H': hostName = optarg; break; case 'a': additional = optarg; break; } } if (instance == -1) { ACE_OS::printf("Error: instance is a mandatory option try %s -h\n", argv[0]); return -1; } #define DEFAULT_LOG_FILE_NAME "acs_local_log" ACE_CString daemonsLogFileName = getTempFileName(0, DEFAULT_LOG_FILE_NAME); // replace "ACS_INSTANCE.x" with "acsdaemonStartAcs_" + <timestamp> ACE_CString daemonsDir = "acsdaemonStartAcs_" + getStringifiedTimeStamp(); ACE_CString instancePart("ACS_INSTANCE."); ACE_CString::size_type pos = daemonsLogFileName.find(instancePart); daemonsLogFileName = daemonsLogFileName.substring(0, pos) + daemonsDir + daemonsLogFileName.substring(pos + instancePart.length() + 1); // +1 for skipping instance number ACE_OS::setenv("ACS_LOG_FILE", daemonsLogFileName.c_str(), 1); LoggingProxy *logger = new LoggingProxy(0, 0, 31); if (logger) { LoggingProxy::init(logger); LoggingProxy::ProcessName(argv[0]); LoggingProxy::ThreadName("main"); } else ACS_SHORT_LOG((LM_INFO, "Failed to initialize logging.")); StartCallback* sc = new StartCallback(); try { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "TAO"); // get a reference to the RootPOA CORBA::Object_var pobj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(pobj.in()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // create policies CORBA::PolicyList policy_list; policy_list.length(5); policy_list[0] = root_poa->create_request_processing_policy(PortableServer::USE_DEFAULT_SERVANT); policy_list[1] = root_poa->create_id_uniqueness_policy(PortableServer::MULTIPLE_ID); policy_list[2] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); policy_list[3] = root_poa->create_servant_retention_policy(PortableServer::NON_RETAIN); policy_list[4] = root_poa->create_lifespan_policy(PortableServer::PERSISTENT); // create a ACSDaemon POA with policies PortableServer::POA_var poa = root_poa->create_POA("DaemonCallback", poa_manager.in(), policy_list); // destroy policies for (CORBA::ULong i = 0; i < policy_list.length(); ++i) { CORBA::Policy_ptr policy = policy_list[i]; policy->destroy(); } // set as default servant poa->set_servant(sc); // create reference PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("DaemonCallback"); pobj = poa->create_reference_with_id (oid.in(), sc->_interface_repository_id()); CORBA::String_var m_ior = orb->object_to_string(pobj.in()); // bind to IOR table CORBA::Object_var table_object = orb->resolve_initial_references("IORTable"); IORTable::Table_var adapter = IORTable::Table::_narrow(table_object.in()); if (CORBA::is_nil(adapter.in())) { ACS_SHORT_LOG ((LM_ERROR, "Nil IORTable")); return -1; } else { adapter->bind("DaemonCallback", m_ior.in()); } // activate POA poa_manager->activate(); ACS_SHORT_LOG((LM_INFO, "%s is waiting for incoming requests.", "DaemonCallback")); // construct default one if (daemonRef.length() == 0) { if (hostName.length() == 0) { hostName = ACSPorts::getIP(); } daemonRef = "corbaloc::"; daemonRef = daemonRef + hostName + ":" + ACSPorts::getServicesDaemonPort().c_str() + "/" + ::acsdaemon::servicesDaemonServiceName; ACS_SHORT_LOG((LM_INFO, "Using local ACS Services Daemon reference: '%s'", daemonRef.c_str())); } else { ACS_SHORT_LOG((LM_INFO, "ACS Services Daemon reference obtained via command line: '%s'", daemonRef.c_str())); } CORBA::Object_var obj = orb->string_to_object(daemonRef.c_str()); if (CORBA::is_nil(obj.in())) { ACS_SHORT_LOG((LM_INFO, "Failed to resolve reference '%s'.", daemonRef.c_str())); return -1; } acsdaemon::ServicesDaemon_var daemon = acsdaemon::ServicesDaemon::_narrow(obj.in()); if (CORBA::is_nil(daemon.in())) { ACS_SHORT_LOG((LM_INFO, "Failed to narrow reference '%s'.", daemonRef.c_str())); return -1; } // @todo implement support for callback and wait for completion call acsdaemon::DaemonSequenceCallback_var dummyCallback = sc->_this(); ACS_SHORT_LOG((LM_INFO, "Calling start_acs(%d, %s, dummyCallback).", instance, additional.c_str())); daemon->start_acs(dummyCallback.in(), instance, additional.c_str()); ACS_SHORT_LOG((LM_INFO, "ACS start message issued.")); while(!sc->isComplete()) { if (orb->work_pending()) orb->perform_work(); } } catch(ACSErrTypeCommon::BadParameterEx & ex) { ACSErrTypeCommon::BadParameterExImpl exImpl(ex); exImpl.log(); return -1; } catch(CORBA::Exception & ex) { ACS_SHORT_LOG((LM_INFO, "Failed.")); ex._tao_print_exception("Caught unexpected exception:"); return -1; } return 0; }