int fileCallback(const char* pathname, const struct stat* ptr, int flag){ if (flag == 0) { puts(pathname); char* tempPath = malloc(sizeof(char) * (strlen(pathname) + 1)); FILE *file = fopen (pathname, "r"); if (file != NULL) { char* line = malloc(2048); //Buffer where line is stored char* tempWord = malloc(sizeof(char) * 1024); while (fgets (line, 2048, file ) != NULL) /* read a line */ { char* token; int i; for (token=strtok(line, delims); token != NULL; token=strtok(NULL, delims)) { for(i=0; i < strlen(token); i++){ token[i] = tolower(token[i]); } puts(token); strcpy(tempWord, token); strcpy(tempPath, pathname); addCount(tempPath, tempWord); } } free(tempWord); free(line); fclose (file); } free(tempPath); } return 0; }
counts_t * countFile(const char * filename, kvarray_t * kvPairs) { counts_t *c = createCounts(); FILE *f = fopen(filename,"r"); if(f==NULL) { fprintf(stderr,"Couldn't open File!"); return NULL; } char *line=NULL; char *value=NULL; size_t num=0; char *temp=NULL; while(getline(&line,&num,f)!=-1) { temp=strchr(line,'\n'); *temp='\0'; value=lookupValue(kvPairs,line); addCount(c,value); free(line); value=NULL; temp=NULL; // free(temp); num=0; } // free(value); free(line); if(fclose(f)!=0) { fprintf(stderr,"Couldn't close file!"); return NULL; } return c; }
int WSrcDeck::Add(MTGCard * c, int quantity) { if (!c) return 0; if (copies.find(c->getMTGId()) == copies.end()) { cards.push_back(c); } copies[c->getMTGId()] += quantity; addCount(c, quantity); return 1; }
void WSrcDeck::updateCounts() { vector<MTGCard*>::iterator it; map<int, int>::iterator ccount; clearCounts(); for (it = cards.begin(); it != cards.end(); it++) { ccount = copies.find((*it)->getMTGId()); if (ccount == copies.end()) continue; addCount((*it), ccount->second); } }
void RunTimes::stop(Category c) { Element e = category_stack.top(); category_stack.pop(); if (e.first != c) { std::cerr << e.first; std::cerr << c; BEEV::FatalError("Don't match"); } addTime(c, getCurrentTime() - e.second); addCount(c); }
bool BaseClient::linkConnector(BaseConnector *c) { bool ok = true; ok &= (bool)connect(c, SIGNAL(connecting()), this, SLOT(UIConnectingState())); ok &= (bool)connect(c, SIGNAL(connected()), this, SLOT(UIConnectedState())); ok &= (bool)connect(c, SIGNAL(disconnecting()), this, SLOT(UIDisconnectingState())); ok &= (bool)connect(c, SIGNAL(disconnected()), this, SLOT(UIDisconnectedState())); ok &= (bool)connect(c, SIGNAL(outMessage(QString)), this, SLOT(outMessage(QString))); ok &= (bool)connect(c, SIGNAL(newFrame(uint)), this, SLOT(newFrame(uint))); ok &= (bool)connect(c, SIGNAL(newFrame(uint)), this, SLOT(addCount())); ok &= (bool)connect(c, SIGNAL(updateSubject(SubjectData*)), this, SLOT(update(SubjectData*))); return ok; }
/** * \brief Main loop */ void Scanner::loop() { prctl(PR_SET_NAME, "fbitexp:Scanner\0", 0, 0, 0); std::mutex mtx; std::unique_lock<std::mutex> lock(mtx); MSG_DEBUG(msg_module, "started"); while (!_done) { /* * This is before waiting because we want to check size on startup before * any scan or add requests */ if (totalSize() > _max_size) { removeDirs(); } MSG_DEBUG(msg_module, "Total size: %s, Max: %s, Watermark: %s", sizeToStr(totalSize()).c_str(), sizeToStr(_max_size).c_str(), sizeToStr(_watermark).c_str()); _cv.wait(lock, [&]{ return scanCount() > 0 || addCount() > 0 || _done || totalSize() > _max_size; }); if (_done) { break; } /* Add dirs from queue */ if (addCount() > 0) { addNewDirs(); } /* Scan dirs in queue */ if (scanCount() > 0) { rescanDirs(); } } MSG_DEBUG(msg_module, "closing thread"); }
int WSrcDeck::Remove(MTGCard * c, int quantity, bool erase) { if (!c) return 0; map<int, int>::iterator it = copies.find(c->getMTGId()); if (it == copies.end()) return 0; int amt = it->second; if (amt < quantity) return 0; amt -= quantity; it->second = amt; if (erase && amt == 0) { copies.erase(it); vector<MTGCard*>::iterator i = find(cards.begin(), cards.end(), c); if (i != cards.end()) cards.erase(i); } addCount(c, -quantity); return 1; }
Status Chunk::insertXY(ID xId, ID yId, bool flag) { //if(isChunkFull()) // return CHUNK_IS_FULL; //modify xMin xMax yMax yMin //maybe there is useless xMax = xId > xMax ? xId : xMax; yMax = yId > yMax ? yId : yMax; xMin = xId < xMin ? xId : xMin; yMin = yId < yMin ? yId : yMin; writeXId(xId, endPtr); writeYId(yId, endPtr); addCount(); return OK; }
counts_t * countFile(const char * filename, kvarray_t * kvPairs) { //WRITE ME counts_t * c = createCounts(); FILE * f = fopen(filename,"r"); char * line = NULL; size_t sz = 0; while(getline(&line, &sz, f) >= 0) { char * ptr = strchr(line, '\n'); if (ptr != NULL) { *ptr = '\0'; } char * value = lookupValue(kvPairs, line); addCount(c, value); } fclose(f); free(line); return c; }
/** * \brief Add new directories */ void Scanner::addNewDirs() { Directory *dir, *parent; uint64_t newSize; while (addCount() > 0) { std::tie(dir, parent) = getNextAdd(); MSG_DEBUG(msg_module, "Adding %s", dir->getName().c_str()); parent->addChild(dir); /* * If directory is NOT active, it means that it is final tree node (leaf) * and we can count it's size. */ if (dir->isActive()) { continue; } /* Set directory age */ dir->detectAge(); /* Get directory size */ dir->setSize(dir->countSize()); newSize = dir->getSize(); /* Propagate size to predecessors */ while (parent) { if (!parent->isActive()) { /* If parent is inactive, we can count size of files in it */ newSize += parent->countFilesSize(); } parent->setSize(parent->getSize() + newSize); parent = parent->getParent(); } } }
virtual void write(const uint8_t* buf, size_t n) { out_stream_->write(buf, n); addCount(n); }