int main(int argc, char** argv) { int fin; /* input file handle */ int fout; /* output file handle */ /* too few parameters passed */ if (argc <= 2) { printHelp(); return 1; } fin = initFile(argv[1], INIT_READ); if (fin < 0) { printf("\n !!! Error opening file %s! \n", argv[1]); return 1; } fout = initFile(argv[2], INIT_WRITE); if (fout < 0) { printf("\n !!! Error opening file %s! \n", argv[2]); return 1; } convertData(fin, fout); close(fout); close(fin); return 0; }
// -------------------------------------------------------------------- // main // -------------------------------------------------------------------- int main(int argc, char*argv[]) { parseArgs(argc, argv); struct sigaction a; a.sa_handler = traitementInterrupt; /* fonction à lancer */ sigemptyset(&a.sa_mask); /* rien à masquer */ sigaction(SIGTSTP, &a, NULL); /* pause contrôle-Z */ sigaction(SIGINT, &a, NULL); /* fin contrôle-C */ sigaction(SIGTERM, &a, NULL); /* arrêt */ sigaction(SIGSEGV, &a, NULL); /* segmentation fault ! */ int sock=0; initSocket(sock); sock_=sock; ZFile file; initFile(&file); file_=&file; while(1) { bool close=false; processPacket(sock, &file, false, close); if (close) { file.close(); initFile(&file); file_=&file; } } return(EXIT_SUCCESS); }
int main () { srand (time (NULL)); int numGames, numPlayers; Card deck[NUM_CARDS]; Card hand[MAX_PLAYER][HAND_SIZE]; getGameInfo (&numGames); initFile (numGames); for (int i = 0; i < numGames; i++) { getNumPlayers (&numPlayers); int handScores[numPlayers][1 + HAND_SIZE]; memset(handScores, 0, numPlayers * (1 + HAND_SIZE) * sizeof(int)); int bestHandIndices[numPlayers]; memset (bestHandIndices, 0, numPlayers*sizeof(int)); int *numTied = (int *)malloc(sizeof(int)); *numTied = 0; printfName (i + 1, numPlayers); initDeck (deck); shuffleDeck (deck); dealHands (deck, hand, numPlayers); evaluateWinner (hand, numPlayers, handScores, bestHandIndices, numTied); for (int j = 0; j < numPlayers; j++) { printResults (&hand[j][0], HAND_SIZE, j, handScores); } printWinner (i + 1, hand, numPlayers, handScores, bestHandIndices, *numTied); } }
void SpoutCalgary::generateTuples() { uint32_t counter = 0; initFile(); while(!killGenerateThread) { std::stringstream ss; std::string str = getNextAccess(); if(str.compare("CRANE_FINISH") == 0) { //std::cout<<"SpoutCalgary::generateTuples: get finish string"<<std::endl; ss << str << std::endl; ss << counter++ << std::endl; Tuple finishTuple(ss.str()); //emitAll(finishTuple); emit(finishTuple); return; } ss << str << std::endl; ss << counter++ << std::endl; Tuple imaginary(ss.str()); emit(imaginary); //add tuple to all the subscribing bolts, each bolt select one task } }
local void testScobindConditionMulti(void) { Stab stabGlobal, stabFile, stab; AbSyn ab; initFile(); stabGlobal = stabNewGlobal(); stabFile = stabNewFile(stabGlobal); stab = stabPushLevel(stabFile, sposNone, STAB_LEVEL_LARGE); finiFile(); return; /* ideally, I'd like to test this here, but comsgNote (used for multiple defs) doesn't play nice. */ #if 0 AbSyn ab = abqParse("if A then { f: X == 1; f: X == 1}"); scopeBind(stab, ab); Symbol sym_f = symInternConst("f"); scobindTestCheckUnique(stab, sym_f); #endif }
local void testSymeAddCondition() { String B_imp = "import from Boolean"; String C_txt = "C: Category == with"; String D1_txt = "D1: with == add"; String D2_txt = "D2: with == add"; StringList lines = listList(String)(4, B_imp, C_txt, D1_txt, D2_txt); AbSynList code = listCons(AbSyn)(stdtypes(), abqParseLines(lines)); AbSyn absyn = abNewSequenceL(sposNone, code); initFile(); Stab stab = stabFile(); abPutUse(absyn, AB_Use_NoValue); scopeBind(stab, absyn); typeInfer(stab, absyn); AbSyn D1 = abFrSyme(uniqueMeaning(stabFile(), "D1")); AbSyn D2 = abFrSyme(uniqueMeaning(stabFile(), "D2")); AbSyn C = abFrSyme(uniqueMeaning(stabFile(), "C")); Syme syme1 = symeNewExport(symInternConst("syme2"), tfNewAbSyn(TF_General, id("D")), car(stab)); symeAddCondition(syme1, sefo(has(D1, C)), true); testIntEqual("test1", 1, listLength(Sefo)(symeCondition(syme1))); Syme syme2 = symeNewExport(symInternConst("syme1"),tfNewAbSyn(TF_General, id("D")), car(stab)); symeAddCondition(syme2, sefo(and(has(D1, C), has(D2, C))), true); testIntEqual("test2", 2, listLength(Sefo)(symeCondition(syme2))); finiFile(); }
local void testSymeSExpr() { String aSimpleDomain = "+++Comment\nDom: Category == with {f: () -> () ++ f\n}"; StringList lines = listList(String)(1, aSimpleDomain); AbSynList code = listCons(AbSyn)(stdtypes(), abqParseLines(lines)); AbSyn absyn = abNewSequenceL(sposNone, code); initFile(); Stab stab = stabFile(); abPutUse(absyn, AB_Use_NoValue); scopeBind(stab, absyn); typeInfer(stab, absyn); testTrue("Declare is sefo", abIsSefo(absyn)); testIntEqual("Error Count", 0, comsgErrorCount()); SymeList symes = stabGetMeanings(stab, ablogFalse(), symInternConst("Dom")); testIntEqual("unique meaning", 1, listLength(Syme)(symes)); Syme syme = car(symes); SExpr sx = symeSExprAList(syme); finiFile(); }
/*! * \brief Initializes the node * * Gets server parameters, initializes publishers and subscribers, starts * the log file, and runs the spin loop. */ void CatCreator::init() { is_init_ = false; save_to_file_ = true; getParams(); // Initialize publisher cat_pub_ = n_.advertise<burst_calc::cat>("cats", 1000); ca_pub_ = n_.advertise<burst_calc::ca>("cas", 1000); // Wait for subscribers ROS_INFO("Waiting for subscribers..."); while (cat_pub_.getNumSubscribers() < 1 && ca_pub_.getNumSubscribers() && ros::ok()); // Initialize subscribers burst_sub_ = n_.subscribe("bursts_to_cat_creator", 1000, &CatCreator::callback, this); ranges_sub_ = n_.subscribe("ranges_to_cat_creator", 1, &CatCreator::rangesCallback, this); if (save_to_file_) initFile(file_name_.c_str()); ros::spin(); }
int TAP_Main(void) { char* path = "fileTest.txt"; char line[512]; UFILE *fp; TYPE_File *tf; printf("Starting file tester...\r\n"); PrintMem(); initFile(_INFO); PrintMem(); if (fp = fopen(path, "w")) { if (fputs("This is a test message1\n", fp) == EOF) ShowError(); //TAP_Print("1. File is %d bytes\r\n", TAP_Hdd_Flen(fp->fd)); if (fputs("This is a test message2\n", fp) == EOF) ShowError(); //TAP_Print("2. File is %d bytes\r\n", TAP_Hdd_Flen(fp->fd)); fclose(fp); } PrintMem(); tf = TAP_Hdd_Fopen("fileTest.txt"); TAP_Print("re-opened file is %d bytes\r\n", TAP_Hdd_Flen(tf)); TAP_Hdd_Fclose(tf); printf("Ending file tester...\r\n"); return 0; }
int runServer(int argc, char* argv[]) { QCoreApplication app(argc, argv); Lua _lua; rainback::Rainback rainback(_lua); const QString buildDir(TOP_BUILDDIR); const QString srcDir(TOP_SRCDIR); _lua["Rainback"]["globals"]["srcdir"] = srcDir; _lua["Rainback"]["globals"]["buildDir"] = buildDir; _lua["Rainback"]["globals"]["profile"] = "server"; QFile buildProps(buildDir + "/settings.lua"); QFile srcProps(srcDir + "/settings.lua"); if (srcProps.exists()) { _lua(srcProps); } if (buildProps.exists()) { _lua(buildProps); } if (!srcProps.exists() && !buildProps.exists()) { std::cerr << "settings.lua must be defined in your top build or source directory" << std::endl; std::cerr << "Look at demo/init.lua for guidance on what globals need to be defined" << std::endl; std::cerr << "defined within that file. Build settings will override source settings." << std::endl; QCoreApplication::exit(1); return 1; } QFile initFile(srcDir + "/demo/init.lua"); _lua(initFile); return app.exec(); }
void readF(void){ int i = 0, j = 0; char tempFileName[127] = "!"; if (parametrs[i] == '"') { i++; } while (fileName[j] != '\0') { fileName[j] = '\0'; j++; } j = 0; while (parametrs[i] != '\0') { tempFileName[j] = parametrs[i]; i++; j++; } if(!initFile(tempFileName)){ fprintf(stderr, "Нет такого файла!\n"); return; } }
void FileTarget::Impl::write( const std::string &&message ) { if( m_prevDate.daysTo( QDateTime::currentDateTime() ) != 0 ) { m_stream.flush(); initFile(); } m_stream << message << endl; }
void PropertyConfiguratorImpl::doConfigure(const std::string& initFileName) throw (ConfigureFailure) { std::ifstream initFile(initFileName.c_str()); if (!initFile) { throw ConfigureFailure(std::string("File ") + initFileName + " does not exist"); } doConfigure(initFile); }
bool VideoInput::switchInput(const std::string& resource) { DEBUG("MRL: '%s'", resource.c_str()); if (switchPending_) { ERROR("Video switch already requested"); return false; } // Switch off video input? if (resource.empty()) { clearOptions(); switchPending_ = true; if (!loop_.isRunning()) loop_.start(); return true; } // Supported MRL schemes static const std::string sep = "://"; const auto pos = resource.find(sep); if (pos == std::string::npos) return false; const auto prefix = resource.substr(0, pos); if ((pos + sep.size()) >= resource.size()) return false; const auto suffix = resource.substr(pos + sep.size()); bool valid = false; if (prefix == "v4l2") { /* Video4Linux2 */ valid = initCamera(suffix); } else if (prefix == "display") { /* X11 display name */ valid = initX11(suffix); } else if (prefix == "file") { /* Pathname */ valid = initFile(suffix); } /* Unsupported MRL or failed initialization */ if (valid) { switchPending_ = true; if (!loop_.isRunning()) loop_.start(); } else ERROR("Failed to init input for MRL '%s'\n", resource.c_str()); return valid; }
bool OneBCorpus::read_line(string& line){ bool res = (bool) getline(*file, line); if(!res && current_file < 99){ closeFile(); initFile(++current_file); res = (bool) getline(*file, line); } total_read += line.size() + 1; return res; }
int main(int argc, char *argv[]) { FILE *file = initFile(); init(file); if(argc == 1){ printItems(); } else { if(!strcmp(argv[1],"add")){ if(argc<3){ printf("Usage: todo add [<priority>] <text>\n"); } else { insertItem(argv,argc); } } if(!strcmp(argv[1],"del")){ if(argc<3){ printf("Usage: todo del <id>\n"); } else { deleteItem(atoi(argv[2])); } } if(!strcmp(argv[1],"swap")){ if(argc<4){ printf("Usage: todo swap <id1> <id2>\n"); } else { swapIDs(atoi(argv[2]), atoi(argv[3])); } } /* if(!strcmp(argv[1],"prio")){ if(argc < 4){ printf("Usage: todo prio <id> <new_prio>\n"); } else { changePrio(atoi(argv[2]), atoi(argv[3])); } } */ } cleanUp(); return 0; }
CdfSource::CdfSource(KConfig *cfg, const QString& filename, const QString& type) : KstDataSource(cfg, filename, type) { // kstdDebug() << "Entering CdfSource constructor for " << _filename << endl; _maxFrameCount = 0; if (!type.isEmpty() && type != "CDF") { return; } _valid = initFile(); }
AsciiSource::AsciiSource(const QString& filename, const QString& type) : KstDataSource(filename, type) { if (!type.isEmpty() && type != "ASCII") { return; } _rowIndex = 0L; if (initFile()) { _valid = true; } }
LFIIOSource::LFIIOSource( const QString& filename, const QString& type ) : KstDataSource( filename, type ) { if( type.isEmpty( ) || type == "LFIIO" ) { if( initFile( ) ) { _valid = true; } } }
/* Create a steady state solver, solve the constraints. */ void solveSteadyStates(const string & path_to_model, const Model & model) { // Create the output file and label columns ofstream output_file = initFile(path_to_model, model.name); outputLegend(model.species, output_file); // Create the solver together with the constraints SpaceSolver<SteadySpace> solver(new SteadySpace(model.species.size(), model.max_value)); for (const size_t i : cscope(model.species)) solver->boundSpecie(i, model.species[i].max_val); solver->applyModel(model); // Output the results outputResults(output_file, solver); }
LFIIOSource::LFIIOSource( QSettings *cfg, const QString& filename, const QString& type ) : KstDataSource( cfg, filename, type ) { _first = true; if( type.isEmpty( ) || type == "LFIIO" ) { if( initFile( ) ) { _valid = true; } } }
WMAPSource::WMAPSource( KConfig *cfg, const QString& filename, const QString& type ) : KstDataSource( cfg, filename, type ) { _fields.setAutoDelete( TRUE ); if( type.isEmpty( ) || type == "WMAP" ) { if( initFile( ) ) { _valid = true; } } }
/** * @brief 开始文件下载任务 * @author LuChenQun * @date 2015/07/05 * @return int 任务结果 */ int NetWork::startDownloadFile() { int code = CURLE_OK; QByteArray urlBa = m_url.toLocal8Bit(); char *url = urlBa.data(); // 初始化文件 code = initFile(); if (code != NETWORK_INIT_FILE_SUCCESS) { return code; } curl_easy_reset(m_curl); curl_easy_setopt(m_curl, CURLOPT_URL, url); curl_easy_setopt(m_curl, CURLOPT_LOW_SPEED_LIMIT, 10); curl_easy_setopt(m_curl, CURLOPT_LOW_SPEED_TIME, 300); curl_easy_setopt(m_curl, CURLOPT_HEADER, 1); curl_easy_setopt(m_curl, CURLOPT_NOBODY, 1); // 获取文件大小 code = curl_easy_perform(m_curl); double fileSize = 0; curl_easy_getinfo(m_curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fileSize); emitFileSize(fileSize); if (getDiskFreeSpace("e:/") <= (m_fileSize)) { code = NETWORK_DISK_NO_SPACE; return code; } curl_easy_setopt(m_curl, CURLOPT_HEADER, 0); curl_easy_setopt(m_curl, CURLOPT_NOBODY, 0); curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, writeData); curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, this); curl_easy_setopt(m_curl, CURLOPT_RESUME_FROM_LARGE, m_breakPoint); // 断点续传 curl_easy_setopt(m_curl, CURLOPT_XFERINFOFUNCTION, progress); // 进度 curl_easy_setopt(m_curl, CURLOPT_XFERINFODATA, this); curl_easy_setopt(m_curl, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, 1L); // 多线程需要注意的 curl_easy_setopt(m_curl, CURLOPT_FORBID_REUSE, 1); code = curl_easy_perform(m_curl); m_downloadFile.flush(); m_downloadFile.close(); return code; }
bool DBConfigDialog::writeToFile(const QString &hostname, int port, const QString &database, const QString &user, const QString &password) { QFile initFile( QDir::currentPath()+"/init.bin" ); if(!initFile.open(QIODevice::WriteOnly)) { QMessageBox::critical(this,tr("Błąd!"), tr("Nie można otworzyć pliku z kofiguracją bazy danych.")); setGrayOut(false); return false; } QDataStream out( &initFile ); out << hostname << QString::number(port) << database << user << password; initFile.close(); return true; }
local void testAblog() { initFile(); ablogDebug = 0; String Boolean_imp = "import from Boolean"; String C0_def = "C0: Category == with"; String C1_def = "C1: Category == C0 with"; String D0_def = "D0: C0 with == add"; String D1_def = "D1: C1 with == add"; StringList lines = listList(String)(5, Boolean_imp, C0_def, C1_def, D0_def, D1_def); AbSynList code = listCons(AbSyn)(stdtypes(), abqParseLines(lines)); AbSyn absyn = abNewSequenceL(sposNone, code); abPutUse(absyn, AB_Use_NoValue); Stab file = stabFile(); Stab stab = stabPushLevel(file, sposNone, STAB_LEVEL_LARGE); scopeBind(stab, absyn); typeInfer(stab, absyn); testTrue("Declare is sefo", abIsSefo(absyn)); testIntEqual("Error Count", 0, comsgErrorCount()); Syme C0 = uniqueMeaning(stab, "C0"); Syme C1 = uniqueMeaning(stab, "C1"); Syme D0 = uniqueMeaning(stab, "D0"); Syme D1 = uniqueMeaning(stab, "D1"); AbSyn sefo1 = has(abFrSyme(D1), abFrSyme(C1)); AbSyn sefo0 = has(abFrSyme(D1), abFrSyme(C0)); tiSefo(stab, sefo0); tiSefo(stab, sefo1); AbLogic cond0 = ablogFrSefo(sefo0); AbLogic cond1 = ablogFrSefo(sefo1); afprintf(dbOut, "Implies: %pAbLogic %pAbLogic %d\n", cond1, cond0, ablogImplies(cond1, cond0)); afprintf(dbOut, "Implies: %pAbLogic %pAbLogic %d\n", cond0, cond1, ablogImplies(cond0, cond1)); testTrue("00", ablogImplies(cond0, cond0)); testTrue("10", ablogImplies(cond1, cond0)); testFalse("01",ablogImplies(cond0, cond1)); testTrue("11", ablogImplies(cond1, cond1)); }
bool FileLogger<DataType>::print() { if (dataToWrite_.size() < 1) { std::cout << "No data to write in " << filename_ << std::endl; return false; } if (!createFile()) return false; initFile(); writeToFile(); outFile_->flush(); outFile_->close(); return true; }
/* File handling module. Includes all file open close, read and write utilities */ int initForFile(const char * inputFile) { char infile[100]; strcpy(infile, inputFile); strcpy(fileBaseName, inputFile); initFile("infile"); ifd = fopen(strcat(infile, INP_SUFFIX), "r"); if (!ifd) { char msg[MSG_MAX_SIZE]; sprintf(msg, "couldn't open file <%s>\n", infile); return reportError(msg, FATAL); } }
/** Uncompile model: remove compiled version. * Returns true if it has been successful or if there were no compiled version. */ bool ModPlusOMCtrl::uncompile() { // info InfoSender::instance()->sendNormal("Removing compiled model : "+name()); // first remove initfile QFileInfo initFile(_ModelPlus->mmoFolder(),_initFileXml); LowTools::removeFile(initFile.absoluteFilePath()); // remove exeFile QFileInfo exeFile(_ModelPlus->mmoFolder(),_exeFile); if(!exeFile.exists()) return true; return LowTools::removeFile(exeFile.absoluteFilePath()); }
void QueuesToStorageFiles::operator()() { for (auto& it : valuesToWrite_) { auto q = outputConnectors_.logQueues.find(it); if (q == outputConnectors_.logQueues.end()) { std::cout << it << " queue was not found\n"; exit(EXIT_FAILURE); } else { q->second->subscribe(); addLog(it); } } inputConnectors_.doneWithSubscription.wait(); outputConnectors_.doneWithExecution.wait(); for (auto& currentValue : valuesToWrite_) { auto currentQueue = outputConnectors_.logQueues.find(currentValue); if (currentQueue == outputConnectors_.logQueues.end()) { std::cout << currentValue << " queue was not found\n"; exit(EXIT_FAILURE); } OutputConnectors::FrameType currentFrame; std::vector< OutputConnectors::FrameType > dataToWrite; currentFrame = currentQueue->second->pop(); while (currentFrame.time != outputConnectors_.TimePlaceholderForEndOfData) { dataToWrite.push_back(currentFrame); currentFrame = currentQueue->second->pop(); } initFile(currentValue, dataToWrite); auto q = outFiles_.find(currentValue); auto outFile = (q->second); for (auto& dataIt : dataToWrite) { *outFile << dataIt.time << separator_; for (auto& sampleIt : dataIt.data) *outFile << sampleIt << separator_; *outFile << std::endl; } } }
/** * @brief This function calls WriteSaveSlot using each of the three save slots loaded * from earlier and saves the saveData.xml file. */ void save() { xmlDoc.SaveFile("Backup_SavedData.xml"); xmlDoc.Clear(); initFile(); WriteSaveSlot(*saved_data[0]); WriteSaveSlot(*saved_data[1]); WriteSaveSlot(*saved_data[2]); pRoot->InsertEndChild(saveGame); tinyxml2::XMLError eResult = xmlDoc.SaveFile("Assets/save_data.xml"); if (eResult != NULL) perror("Error saving file a backup will be loaded on restart"); if (remove("Backup_SavedData.xml") != 0) perror("Error deleting backup file"); }