QList<QChar> StrokesMatcher::doMatching() { int strokeCount = inputCharacter.getStrokeCount(); QStringList list=strokesData.values(strokeCount); for (int i=0; i<list.count(); i++) { compareTo=loadNextCharacterStrokeData(list.at(i)); QPair<QChar,double> match = compareToNext(); if (match.second>=0) addMatch(match); } return getMatches(); }
foreach (const QString &activity, activities) { if (current == activity) { continue; } KActivities::Info info(activity); if (info.name().startsWith(name, Qt::CaseInsensitive)) { addMatch(info, matches); } if (!context.isValid()) { return; } }
foreach (const QString &activity, activities) { if (currentActivity == activity) { continue; } KActivities::Info info(activity); if (info.name().startsWith(name, Qt::CaseInsensitive)) { bool exact = info.name().compare(name, Qt::CaseInsensitive) == 0; addMatch(info, triggerWord ? (exact ? Sprinter::QuerySession::ExactMatch : Sprinter::QuerySession::CloseMatch) : (exact ? Sprinter::QuerySession::CloseMatch : Sprinter::QuerySession::FuzzyMatch), matchData); } if (!matchData.isValid()) { return; } }
bool MyMoneySplit::replaceId(const QString& newId, const QString& oldId) { bool changed = false; if (m_payee == oldId) { m_payee = newId; changed = true; } else if (m_account == oldId) { m_account = newId; changed = true; } if (isMatched()) { MyMoneyTransaction t = matchedTransaction(); if (t.replaceId(newId, oldId)) { removeMatch(); addMatch(t); changed = true; } } return changed; }
// processes the MEMBLOCK by finding matches to SCANVALUE (if specified) of specified size; adds matches to MATCHES // args: MEMBLOCK: array of read memory values; MEMBLOCK_SIZE: size of memory block; BASE_ADDRESS: address where first value in MEMBLOCK was read void Memscan::processMemblock(DWORD64* memblock, DWORD64 memblock_size, HMODULE base_address) { for (int i = 0; i < memblock_size; i++) { DWORD64 value = memblock[i]; DWORD64 initial = value; HMODULE matchBaseAddress = base_address + (i * 2); // +(i*2) because HMODULE values are incremented in sizeof(int) units; DWORD64 = 2 * sizeof(int) for (SIZE_T size : sizes) { DWORD64 mask = 0; if (size == 8) { // necessary because left shift is undefined if right operand equals to number of bits in left operand mask = 0xffffffffffffffff; } else { mask = ~(0xffffffffffffffff << (size * 8)); // masks last SIZE*8 bits } // Windows NT is little-endian for (int i = 0; i < (sizeof(DWORD64)/size); i++) { if ((SCAN_ATTRIBUTE::NONE == scanAttribute) || ((SCAN_ATTRIBUTE::VALUE == scanAttribute) && ((value & mask) == scanValue))) { addMatch(matchBaseAddress, (value & mask), size, i); } if (size < 8) { value >>= (size * 8); // shifts right by SIZE*8 bits } } value = initial; } }
void hitMatrix::filter(encodedQuery *query, bool isReverse) { if (_hitsLen == 0) return; // Decide on the minimum quality values; we pick the larger of // the fixed lengths, and the sequence length * coverage. // uint32 minLengthSingle = (uint32)(config._minCoverageSingle * _qsLen); uint32 minLengthMultiple = (uint32)(config._minCoverageMultiple * _qsLen); if (minLengthSingle < config._minLengthSingle) minLengthSingle = config._minLengthSingle; if (minLengthMultiple < config._minLengthMultiple) minLengthMultiple = config._minLengthMultiple; // First, sort by the dsPos. This is done so that we can find all the hits for // a specific scaffold. // sort_dsPos(); // Now, while there are hits left.... // uint32 firstHit = 0; uint32 lastHit = 0; uint32 currentSeq = 0; while (firstHit < _hitsLen) { // Move the currentSeq until the firstHit is below it. // while ((currentSeq < config._dbSTREAM->numberOfSequences()) && (config._dbSTREAM->startOf(currentSeq) <= _hits[firstHit]._dsPos)) currentSeq++; // // currentSeq is now the sequence AFTER the one that we want hits in. // // Find the first hit that is in currentSeq. If this is the last sequence, // then, of course, all remaining hits are in it. // if (currentSeq < config._dbSTREAM->numberOfSequences()) { lastHit = firstHit + 1; while ((lastHit < _hitsLen) && (_hits[lastHit]._dsPos < config._dbSTREAM->startOf(currentSeq))) lastHit++; } else { lastHit = _hitsLen; } // Drop back one sequence; this is the sequence the hits are in. // currentSeq--; #if TRACE fprintf(stdout, "Hits are in sequence %d\n", config._dbSTREAM->IIDOf(currentSeq)); fprintf(stdout, "filtering %u hits -- first = %u last = %u.\n", _hitsLen, firstHit, lastHit); #if 0 fprintf(stdout, "UNSORTED\n"); for (uint32 i=firstHit; i<lastHit; i++) fprintf(stdout, "hit at qs=%4u ds=%6u diag=%6u\n", _hits[i]._qsPos, _hits[i]._dsPos, _hits[i]._diagonalID); #endif #endif // Adjust the hits to be relative to the start of this sequence // for (uint32 i=firstHit; i<lastHit; i++) _hits[i]._dsPos -= config._dbSTREAM->startOf(currentSeq); // Sort them, if needed. // if (lastHit - firstHit > 1) { // We cheat; heapsort isn't too friendly to sorting the middle of // an array, so we make a new array in the middle! // diagonalLine *hitsToSort = _hits + firstHit; // Build the heap. I initially thought this could be done at the // same time as the scan for the last hit, but it can't (easily) // for (int32 i=(lastHit - firstHit)/2 - 1; i>=0; i--) #ifdef WITHOUT_DIAGONALID adjustHeap(hitsToSort, i, lastHit - firstHit, _qsLen); #else adjustHeap(hitsToSort, i, lastHit - firstHit); #endif // Sort the hits be diagonal. This is the second part of // heap sort -- Interchange the new maximum with the element // at the end of the tree // for (uint32 i=lastHit - firstHit - 1; i>0; i--) { uint32 q = hitsToSort[i]._qsPos; uint32 d = hitsToSort[i]._dsPos; #ifndef WITHOUT_DIAGONALID uint32 l = hitsToSort[i]._diagonalID; #endif hitsToSort[i]._qsPos = hitsToSort[0]._qsPos; hitsToSort[i]._dsPos = hitsToSort[0]._dsPos; #ifndef WITHOUT_DIAGONALID hitsToSort[i]._diagonalID = hitsToSort[0]._diagonalID; #endif hitsToSort[0]._qsPos = q; hitsToSort[0]._dsPos = d; #ifndef WITHOUT_DIAGONALID hitsToSort[0]._diagonalID = l; #endif #ifdef WITHOUT_DIAGONALID adjustHeap(hitsToSort, 0, i, _qsLen); #else adjustHeap(hitsToSort, 0, i); #endif } } // Check the sorting // #if 0 #if 0 fprintf(stderr, "sort by diagonal:\n"); for (uint32 i=firstHit; i<lastHit; i++) fprintf(stderr, "%8u %8u %8u\n", _hits[i]._diagonalID, _hits[i]._qsPos, _hits[i]._dsPos); #endif for (uint32 i=firstHit; i<lastHit-1; i++) { if (_hits[i]._diagonalID > _hits[i+1]._diagonalID) { fprintf(stderr, "sort by diagonal failed.\n"); exit(1); } } #endif #if TRACE #if 0 fprintf(stdout, "SORTED\n"); for (uint32 i=firstHit; i<lastHit; i++) fprintf(stdout, "hit at qs=%4u ds=%6u diag=%6u\n", _hits[i]._qsPos, _hits[i]._dsPos, _hits[i]._diagonalID); #endif fprintf(stdout, "FILTERED\n"); #endif // Filter them // #ifdef WITHOUT_DIAGONALID uint32 frstDiagonal = _qsLen - _hits[firstHit]._qsPos - 1 + _hits[firstHit]._dsPos; uint32 lastDiagonal = frstDiagonal; #else uint32 frstDiagonal = _hits[firstHit]._diagonalID; uint32 lastDiagonal = _hits[firstHit]._diagonalID; #endif uint32 qsLow = _hits[firstHit]._qsPos; uint32 qsHigh = _hits[firstHit]._qsPos; uint32 dsLow = _hits[firstHit]._dsPos; uint32 dsHigh = _hits[firstHit]._dsPos; // Create a new merCovering, and space to count the number of mers in a match // merCovering *IL = new merCovering(config._merSize); for (uint32 i=firstHit; i<lastHit; i++) { #ifdef WITHOUT_DIAGONALID uint32 thisDiagonalID = _qsLen - _hits[i]._qsPos - 1 + _hits[i]._dsPos; #else uint32 thisDiagonalID = _hits[i]._diagonalID; #endif #if TRACE fprintf(stdout, "hit[qs=%6u ds=%7u d=%7u] box[qs=%6u-%6u ds=%7u-%7u d=%7u-%7u] ", _hits[i]._qsPos, _hits[i]._dsPos, thisDiagonalID, qsLow, qsHigh, dsLow, dsHigh, frstDiagonal, lastDiagonal); #endif // Unconditionally extend if the diagonal difference is small. // if (lastDiagonal + config._maxDiagonal >= thisDiagonalID) { lastDiagonal = thisDiagonalID; if (qsLow > _hits[i]._qsPos) qsLow = _hits[i]._qsPos; if (qsHigh < _hits[i]._qsPos) qsHigh = _hits[i]._qsPos; if (dsLow > _hits[i]._dsPos) dsLow = _hits[i]._dsPos; if (dsHigh < _hits[i]._dsPos) dsHigh = _hits[i]._dsPos; IL->addMer(_hits[i]._qsPos); #if TRACE fprintf(stdout, "extend qs=%9u-%9u ds=%9u-%9u diag=%9u-%9u (diagonal)\n", qsLow, qsHigh, dsLow, dsHigh, frstDiagonal, lastDiagonal); #endif continue; } // XXX: Prototype for extending only if the next hit is near // the last hit. // if (((dsHigh <= _hits[i]._dsPos) && (_hits[i]._dsPos - dsHigh <= config._maxIntronLength)) || ((dsHigh >= _hits[i]._dsPos) && (dsHigh - _hits[i]._dsPos <= config._maxIntronLength))) { // Extend into multiple-exon like things only if the input // sequence is long. // if (_qsLen > config._smallSequenceCutoff) { // Extend if the qsOverlap is small (or nonexistant) // if ((qsHigh + config._merSize) < (_hits[i]._qsPos + config._qsOverlap)) { lastDiagonal = thisDiagonalID; if (qsLow > _hits[i]._qsPos) qsLow = _hits[i]._qsPos; if (qsHigh < _hits[i]._qsPos) qsHigh = _hits[i]._qsPos; if (dsLow > _hits[i]._dsPos) dsLow = _hits[i]._dsPos; if (dsHigh < _hits[i]._dsPos) dsHigh = _hits[i]._dsPos; IL->addMer(_hits[i]._qsPos); #if TRACE fprintf(stdout, "extend qs=%9u-%9u ds=%9u-%9u diag=%9u-%9u (qsOverlap)\n", qsLow, qsHigh, dsLow, dsHigh, frstDiagonal, lastDiagonal); #endif continue; } // Extend if the dsOverlap is small (or nonexistant) // if (_hits[i]._dsPos < (dsLow + config._dsOverlap)) { lastDiagonal = thisDiagonalID; if (qsLow > _hits[i]._qsPos) qsLow = _hits[i]._qsPos; if (qsHigh < _hits[i]._qsPos) qsHigh = _hits[i]._qsPos; if (dsLow > _hits[i]._dsPos) dsLow = _hits[i]._dsPos; if (dsHigh < _hits[i]._dsPos) dsHigh = _hits[i]._dsPos; IL->addMer(_hits[i]._qsPos); #if TRACE fprintf(stdout, "extend qs=%9u-%9u ds=%9u-%9u diag=%9u-%9u (dsOverlap)\n", qsLow, qsHigh, dsLow, dsHigh, frstDiagonal, lastDiagonal); #endif continue; } } } // XXX: End prototype #if TRACE fprintf(stdout, "close current cluster.\nGOOD? qsCov=%u; >= %u or %u? diag: %u < 25?\n", qsHigh - qsLow, minLengthSingle, minLengthMultiple, lastDiagonal - frstDiagonal); #endif // Save the current cluster and start a new one? // uint32 qCov = IL->sumOfLengths(); if ((qCov >= minLengthMultiple) || ((lastDiagonal - frstDiagonal < 25) && (qCov >= minLengthSingle))) { #if TRACE fprintf(stdout, "add match!\n"); #endif addMatch(qsLow, qsHigh + config._merSize, dsLow, dsHigh + config._merSize, IL); IL = new merCovering(config._merSize); } if (IL) IL->clear(); #if TRACE fprintf(stdout, "reset!\n"); #endif frstDiagonal = thisDiagonalID; lastDiagonal = thisDiagonalID; qsLow = _hits[i]._qsPos; qsHigh = _hits[i]._qsPos; dsLow = _hits[i]._dsPos; dsHigh = _hits[i]._dsPos; #if TRACE fprintf(stdout, "hit[qs=%6u ds=%7u d=%7u] box[qs=%6u-%6u ds=%7u-%7u d=%7u-%7u] (initial hit)\n", _hits[i]._qsPos, _hits[i]._dsPos, _qsLen - _hits[i]._qsPos - 1 + _hits[i]._dsPos, qsLow, qsHigh, dsLow, dsHigh, frstDiagonal, lastDiagonal); #endif IL->addMer(_hits[i]._qsPos); } // Save the final cluster? // uint32 qCov = IL->sumOfLengths(); if ((qCov >= minLengthMultiple) || ((lastDiagonal - frstDiagonal < 21) && (qCov >= minLengthSingle))) { addMatch(qsLow, qsHigh + config._merSize, dsLow, dsHigh + config._merSize, IL); IL = 0; } // Delete any remaining IL // delete IL; // Merge and print the matches // trapMatch *n = 0L; uint32 ML = 0; while (_matches) { // Save the current match, then delete it. // dsLow = _matches->_dsLo; dsHigh = _matches->_dsHi; IL = _matches->_IL; ML = IL->sumOfLengths(); n = _matches; _matches = _matches->_next; delete n; #if TRACE fprintf(stdout, "Merge: %8u %8u\n", dsLow, dsHigh); #endif // Assimilate as many of the remaining matches as possible. // // Think of this as first reversing the list, then merging as // long as (dsHigh + 1000 > _matches->_dsLo). But since we // don't reverse the list, we can map: // dsHigh --> _matches->dsHi // _matches->_dsLo --> dsLow // where dsHigh and dsLow are the values for the extended match. // while (_matches && (dsLow < _matches->_dsHi + 5000)) { // Combine the two merCoverings // IL->merge(_matches->_IL); ML += _matches->_IL->sumOfLengths(); // The start of the new match might be after the start of the // merged region. (Only rarely is it before) // if (dsLow > _matches->_dsLo) dsLow = _matches->_dsLo; // The end of current match is always greater than the end of the // new match! // //dsHigh = _matches->_dsHi; #if TRACE fprintf(stdout, "Merge: %8u %8u -> %8u %8u\n", _matches->_dsLo, _matches->_dsHi, dsLow, dsHigh); #endif n = _matches; _matches = _matches->_next; delete n->_IL; delete n; } if (config._binaryOutput) { aHit a; a._forward = !isReverse; a._merged = false; a._qsIdx = _qsIdx; a._dsIdx = config._dbSTREAM->IIDOf(currentSeq); a._dsLo = dsLow; a._dsHi = dsHigh; a._covered = IL->sumOfLengths(); a._matched = ML; a._numMers = _qsMers; query->addOutput(&a, sizeof(aHit)); } else { char line[128]; sprintf(line, "-%c -e "uint32FMT" -D "uint32FMT" "uint32FMT" "uint32FMT" -M "uint32FMT" "uint32FMT" "uint32FMT"\n", isReverse ? 'r' : 'f', _qsIdx, config._dbSTREAM->IIDOf(currentSeq), dsLow, dsHigh, IL->sumOfLengths(), ML, _qsMers); query->addOutput(line, 0); } delete IL; } // All done with these hits. Move to the next set. // firstHit = lastHit; } }
void DirectoryListThread::run() { // Thread safety notes: // // There very possibly may be thread safety issues here, but I've done a check // of all of the things that would seem to be problematic. Here are a few // things that I have checked to be safe here (some used indirectly): // // QDir::currentDirPath(), QDir::setCurrent(), QFile::decodeName(), QFile::encodeName() // QString::fromLocal8Bit(), QString::local8Bit(), QTextCodec::codecForLocale() // // Also see (for POSIX functions): // http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html DIR *dir = 0; for(QStringList::ConstIterator it = m_dirList.begin(); it != m_dirList.end() && !terminationRequested(); ++it) { // Open the next directory if(!dir) { dir = ::opendir(QFile::encodeName(*it)); if(!dir) { kdDebug() << "Failed to open dir: " << *it << endl; done(); return; } } // A trick from KIO that helps performance by a little bit: // chdir to the directroy so we won't have to deal with full paths // with stat() QString path = QDir::currentDirPath(); QDir::setCurrent(*it); // Loop through all directory entries // Solaris and IRIX dirent structures do not allocate space for d_name. On // systems that do (HP-UX, Linux, Tru64 UNIX), we overallocate space but // that's ok. #ifndef HAVE_READDIR_R struct dirent *dirEntry = 0; while(!terminationRequested() && (dirEntry = ::readdir(dir))) #else struct dirent *dirPosition = (struct dirent *)malloc(sizeof(struct dirent) + MAXPATHLEN + 1); struct dirent *dirEntry = 0; while(!terminationRequested() && ::readdir_r(dir, dirPosition, &dirEntry) == 0 && dirEntry) #endif { // Skip hidden files if m_noHidden is true if(dirEntry->d_name[0] == '.' && m_noHidden) continue; // Skip "." if(dirEntry->d_name[0] == '.' && dirEntry->d_name[1] == '\0') continue; // Skip ".." if(dirEntry->d_name[0] == '.' && dirEntry->d_name[1] == '.' && dirEntry->d_name[2] == '\0') continue; QString file = QFile::decodeName(dirEntry->d_name); if(m_filter.isEmpty() || file.startsWith(m_filter)) { if(m_onlyExe || m_onlyDir || m_appendSlashToDir) { KDE_struct_stat sbuff; if(KDE_stat(dirEntry->d_name, &sbuff) == 0) { // Verify executable if(m_onlyExe && (sbuff.st_mode & MODE_EXE) == 0) continue; // Verify directory if(m_onlyDir && !S_ISDIR(sbuff.st_mode)) continue; // Add '/' to directories if(m_appendSlashToDir && S_ISDIR(sbuff.st_mode)) file.append('/'); } else { kdDebug() << "Could not stat file " << file << endl; continue; } } addMatch(file); } } // chdir to the original directory QDir::setCurrent(path); ::closedir(dir); dir = 0; #ifdef HAVE_READDIR_R free(dirPosition); #endif } done(); }
void PowerDevilRunner::match(Sprinter::MatchData &matchData) { const QString term = matchData.queryContext().query(); PowerDevilWord word = NoWord; for (auto it = m_words.cbegin(); it != m_words.cend(); ++it) { if (term.startsWith(it.value(), Qt::CaseInsensitive)) { word = it.key(); break; } } // extracts the parameters from the given term auto getParameters = [&term](const QString &word) -> QStringList { QString adjustedTerm = term; adjustedTerm.remove(0, word.length()); return adjustedTerm.trimmed().split(' ', QString::SkipEmptyParts); }; switch (word) { case SuspendWord: { const QSet<Solid::PowerManagement::SleepState> states = Solid::PowerManagement::supportedSleepStates(); if (states.contains(Solid::PowerManagement::SuspendState)) { addMatch(SuspendAction, matchData); } if (states.contains(Solid::PowerManagement::HibernateState)) { addMatch(HibernateAction, matchData); } } break; case SleepWord: case ToRamWord: addMatch(SuspendAction, matchData); break; case HibernateWord: case ToDiskWord: addMatch(HibernateAction, matchData); break; case ScreenBrightnessWord: case DimScreenWord: { const QStringList parameters = getParameters(m_words.value(word)); int brightness; bool brightnessValid = false; if (!parameters.isEmpty()) { brightness = parameters.first().toInt(&brightnessValid); } if (brightnessValid) { addBrightnessMatch(brightness, matchData); } else { addMatch(DimTotalAction, matchData); addMatch(DimHalfAction, matchData); addMatch(DimNotAction, matchData); } } break; default: // No match found break; } }