const cEvent* cConflictCheckTimerObj::SetEventFromSchedule() { cSchedulesLock SchedulesLock; const cSchedules* Schedules = NULL; if (!(Schedules = cSchedules::Schedules(SchedulesLock))) return NULL; const cSchedule *Schedule = Schedules->GetSchedule(timer->Channel()); if (Schedule && Schedule->Events()->First()) { const cEvent *Event = NULL; if (timer->HasFlags(tfVps) && Schedule->Events()->First()->Vps()) { // VPS timers only match if their start time exactly matches the event's VPS time: for (const cEvent *e = Schedule->Events()->First(); e; e = Schedule->Events()->Next(e)) { if (e->StartTime() && e->RunningStatus() != SI::RunningStatusNotRunning) { // skip outdated events int overlap = 0; Matches(e, &overlap); if (overlap > FULLMATCH) { Event = e; break; // take the first matching event } } } } else { // Normal timers match the event they have the most overlap with: int Overlap = 0; // Set up the time frame within which to check events: timer->Matches(0, true); time_t TimeFrameBegin = start - EPGLIMITBEFORE; time_t TimeFrameEnd = stop + EPGLIMITAFTER; for (const cEvent *e = Schedule->Events()->First(); e; e = Schedule->Events()->Next(e)) { if (e->EndTime() < TimeFrameBegin) continue; // skip events way before the timer starts if (e->StartTime() > TimeFrameEnd) break; // the rest is way after the timer ends int overlap = 0; Matches(e, &overlap); if (overlap && overlap >= Overlap) { if (Event && overlap == Overlap && e->Duration() <= Event->Duration()) continue; // if overlap is the same, we take the longer event Overlap = overlap; Event = e; } } } return Event; } return NULL; }
bool wxSimpleHtmlParser::ParseComment() { // Eat the comment tag start Matches(wxT("<!--"), TRUE); while (!Eof() && !Matches(wxT("-->"), TRUE)) { m_pos ++; } return TRUE; }
void MonkeyBinding::Callback(const ValueList &args, SharedValue result) { SharedKObject event = args.at(1)->ToObject(); std::string url_value = event->Get("url")->ToString(); std::vector< std::pair< std::pair< VectorOfPatterns,VectorOfPatterns >,std::string> >::iterator iter = scripts.begin(); while(iter!=scripts.end()) { std::pair< std::pair< VectorOfPatterns,VectorOfPatterns >, std::string> e = (*iter++); VectorOfPatterns include = e.first.first; VectorOfPatterns exclude = e.first.second; if (Matches(exclude,url_value)) { continue; } if (Matches(include,url_value)) { // I got a castle in brooklyn, that's where i dwell try { SharedKMethod eval = event->Get("scope")->ToObject()->Get("window")->ToObject()->Get("eval")->ToMethod(); #ifdef DEBUG std::cout << ">>> loading user script for " << url_value << std::endl; #endif eval->Call(Value::NewString(e.second)); } catch (ValueException &ex) { Logger* logger = Logger::Get("Monkey"); SharedString ss = ex.DisplayString(); int line = -1; if (ex.GetValue()->IsObject() && ex.GetValue()->ToObject()->Get("line")->IsNumber()) { line = ex.GetValue()->ToObject()->Get("line")->ToInt(); } logger->Error( "Exception generated evaluating user script for %s " "(line %i): %s", url_value.c_str(), line, ss->c_str()); } catch (std::exception &ex) { Logger* logger = Logger::Get("Monkey"); logger->Error("Exception generated evaluating user script for %s, Exception: %s",url_value.c_str(),ex.what()); } } } }
void FlashOnClickWhitelist::AddImpl (QString str, const QModelIndex& old) { bool ok = false; str = QInputDialog::getText (this, tr ("Add URL to whitelist"), tr ("Please enter the URL to add to the FlashOnClick's whitelist"), QLineEdit::Normal, str, &ok); if (str.isEmpty () || !ok) return; if (old.isValid ()) Model_->removeRow (old.row ()); if (Matches (str)) { QMessageBox::warning (this, "LeechCraft", tr ("This URL is already matched by another whitelist entry.")); return; } Model_->appendRow (new QStandardItem (str)); }
void CDebugger::FindEeFunctions() { if(m_virtualMachine.m_ee->m_os->GetELF() == nullptr) return; auto executableRange = m_virtualMachine.m_ee->m_os->GetExecutableRange(); uint32 minAddr = executableRange.first; uint32 maxAddr = executableRange.second & ~0x03; { Framework::CStdStream patternStream("ee_functions.xml", "rb"); boost::scoped_ptr<Framework::Xml::CNode> document(Framework::Xml::CParser::ParseDocument(patternStream)); CMipsFunctionPatternDb patternDb(document.get()); for(auto patternIterator(std::begin(patternDb.GetPatterns())); patternIterator != std::end(patternDb.GetPatterns()); ++patternIterator) { auto pattern = *patternIterator; for(uint32 address = minAddr; address <= maxAddr; address += 4) { uint32* text = reinterpret_cast<uint32*>(m_virtualMachine.m_ee->m_ram + address); uint32 textSize = (maxAddr - address); if(pattern.Matches(text, textSize)) { m_virtualMachine.m_ee->m_EE.m_Functions.InsertTag(address, pattern.name.c_str()); break; } } } m_virtualMachine.m_ee->m_EE.m_Functions.OnTagListChange(); } }
TMatchResults T2DSingleTemplateMatcher::MatchTable(const std::vector<string> &texttable){ string text; std::vector<size_t> equivalence_class(templateheight, -1); equivalence_class.push_back(-2); textheight = texttable.size(); if (!texttable.empty()) textlength = texttable.back().size(); for (size_t row_number = 0; row_number < texttable.size(); ++row_number) { if (texttable[row_number].size()!=textlength) throw std::logic_error("row lengths don't match"); text+=texttable[row_number]; } TStringStream stream(text); TMatchResults RowsMatch = Matcher.MatchStream(stream); std::vector<std::vector<size_t>> Matches(textlength, std::vector<size_t>(textheight,-1)); for (size_t Match_number = 0; Match_number < RowsMatch.size(); ++Match_number) { size_t x = RowsMatch[Match_number].first / textlength; size_t y = RowsMatch[Match_number].first % textlength; if (Matches[y][x] + 1 == 0) Matches[y][x]= RowsMatch[Match_number].second; if (equivalence_class[RowsMatch[Match_number].second] + 1 == 0) equivalence_class[RowsMatch[Match_number].second] = Matches[y][x]; } TMatchResults Res; for (size_t columntocheck = templatelength - 1;columntocheck < textlength ;++columntocheck) { FindRowMatchSequence(Matches[columntocheck], columntocheck, Res, equivalence_class); } return Res; }
// finish deferred counting of submitted jobs. void ScheddOtherStatsMgr::CountJobsSubmitted() { if ( ! deferred_jobs_submitted.empty() && pools.getNumElements() > 0) { time_t now = time(NULL); for (std::map<int, int>::iterator it = deferred_jobs_submitted.begin(); it != deferred_jobs_submitted.end(); ++it) { int cluster = it->first; int last_proc = it->second; for (int proc = 0; proc <= last_proc; ++proc) { ClassAd * job_ad = GetJobAd(cluster, proc); if (job_ad) { ScheddOtherStats *po = Matches(*job_ad, now); while (po) { po->stats.JobsSubmitted += 1; po = po->next; } FreeJobAd(job_ad); } } } } deferred_jobs_submitted.clear(); }
virtual EModRet OnChanNotice(CNick& nick, CChan& channel, CString& sMessage) { if (Matches(sMessage)) { Attach(channel); } return CONTINUE; }
static bool MatchesWithConditionalCast(const std::shared_ptr<const OtherPhysicalClass> &physical, std::shared_ptr<const PhysicalClass> *cast_physical) { bool is_match = Matches(physical); if (is_match) { *cast_physical = std::static_pointer_cast<const PhysicalClass>(physical); } return is_match; }
bool Sequence::Matches(const SeqIdList& others) const { SeqIdList::const_iterator o, oe = others.end(); for (o=others.begin(); o!=oe; ++o) if (Matches(**o)) return true; return false; }
bool Script::Matches(const char* pattern, const char* target) { // exact match returns immediately if (!strcmp(pattern, target)) return true; switch (*pattern) { case '\0': return *target == '\0'; case '*': return Matches(pattern+1, target) || (*target && Matches(pattern, target+1)); default: return *pattern == *target && Matches(pattern+1, target+1); } }
static bool MatchesWithConditionalCast( const std::shared_ptr<const OtherExpressionClass> &expression, std::shared_ptr<const ExpressionClass> *cast_expression) { bool is_match = Matches(expression); if (is_match) { *cast_expression = std::static_pointer_cast<const ExpressionClass>(expression); } return is_match; }
void NetEditorBase::SlotLoadedData() { QDomDocument doc; doc.setContent(m_reply->readAll()); QDomElement root = doc.documentElement(); QDomElement content = root.firstChildElement("InternetContent"); QDomElement grabber = content.firstChildElement("grabber"); while (!grabber.isNull()) { QString title, author, image, description, type, commandline; double version; bool search = false; bool tree = false; title = grabber.firstChildElement("name").text(); commandline = grabber.firstChildElement("command").text(); author = grabber.firstChildElement("author").text(); image = grabber.firstChildElement("thumbnail").text(); type = grabber.firstChildElement("type").text(); description = grabber.firstChildElement("description").text(); version = grabber.firstChildElement("version").text().toDouble(); QString searchstring = grabber.firstChildElement("search").text(); if (!searchstring.isEmpty() && (searchstring.toLower() == "true" || searchstring.toLower() == "yes" || searchstring == "1")) search = true; QString treestring = grabber.firstChildElement("tree").text(); if (!treestring.isEmpty() && (treestring.toLower() == "true" || treestring.toLower() == "yes" || treestring == "1")) tree = true; if (type.toLower() == "video" && Matches(search, tree)) { LOG(VB_GENERAL, LOG_INFO, QString("Found Source %1...").arg(title)); m_grabberList.append(new GrabberScript(title, image, VIDEO_FILE, author, search, tree, description, commandline, version)); } grabber = grabber.nextSiblingElement("grabber"); } ParsedData(); }
NS_IMETHODIMP nsPermission::MatchesURI(nsIURI* aURI, bool aExactHost, bool* aMatches) { NS_ENSURE_ARG_POINTER(aURI); mozilla::OriginAttributes attrs; nsCOMPtr<nsIPrincipal> principal = mozilla::BasePrincipal::CreateCodebasePrincipal(aURI, attrs); NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE); return Matches(principal, aExactHost, aMatches); }
//--------------------------------------------------------------------------- bool TFileMasks::Matches(const UnicodeString & FileName, bool Local, bool Directory, const TParams * Params, bool & ImplicitMatch) const { bool Result; if (Local) { UnicodeString Path = ExtractFilePath(FileName); if (!Path.IsEmpty()) { Path = ToUnixPath(ExcludeTrailingBackslash(Path)); } Result = Matches(ExtractFileName(FileName, false), Directory, Path, Params, ImplicitMatch); } else { Result = Matches(UnixExtractFileName(FileName), Directory, UnixExcludeTrailingBackslash(::UnixExtractFilePath(FileName)), Params, ImplicitMatch); } return Result; }
bool Script::Matches(vector<string>& patterns, string& url) { vector<string>::iterator iter = patterns.begin(); while (iter != patterns.end()) { string& pattern = (*iter++); if (Matches(pattern.c_str(), url.c_str())) { return true; } } return false; }
wxSimpleHtmlTag* wxSimpleHtmlParser::ParseTagClose() { Matches(wxT("</"), TRUE); EatWhitespace(); wxString word; ReadWord(word, TRUE); EatWhitespace(); m_pos ++; wxSimpleHtmlTag* tag = new wxSimpleHtmlTag(word, wxSimpleHtmlTag_Close); return tag; }
error_t LiteralSpecifier:: Run(char const * & input, Environment & env) { if (!m_literal) return OK; char const * end = input + strlen(input) - m_length; while (input <= end) { if (Matches(input, m_literal, m_length)) { input += m_length; return OK; } ++input; } return ERROR_NO_STRING_MATCH; }
// e.g. <!DOCTYPE ....> wxSimpleHtmlTag* wxSimpleHtmlParser::ParseDirective() { Matches(wxT("<!"), TRUE); EatWhitespace(); wxString word; ReadWord(word, TRUE); EatWhitespace(); wxSimpleHtmlTag* tag = new wxSimpleHtmlTag(word, wxSimpleHtmlTag_Directive); ParseAttributes(tag); EatWhitespace(); if (IsTagEndBracket(GetChar(m_pos))) m_pos ++; return tag; }
void KeyAction::CheckSDLEventAndDispatch(const SDL_Event *event) { switch (event->type) { case SDL_KEYDOWN: case SDL_KEYUP: { if (Matches(&event->key.keysym)) { if (event->key.state == SDL_PRESSED) onPress.emit(); else if (event->key.state == SDL_RELEASED) onRelease.emit(); } break; } case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: { if (binding1.Matches(&event->jbutton) || binding2.Matches(&event->jbutton)) { if (event->jbutton.state == SDL_PRESSED) onPress.emit(); else if (event->jbutton.state == SDL_RELEASED) onRelease.emit(); } break; } case SDL_JOYHATMOTION: { if (binding1.Matches(&event->jhat) || binding2.Matches(&event->jhat)) { onPress.emit(); // XXX to emit onRelease, we need to have access to the state of the joystick hat prior to this event, // so that we can detect the case of switching from a direction that matches the binding to some other direction } break; } default: break; } }
bool ProcessOptions::IsFalse(const char *value) { return (Matches("off",value) || Matches("false",value) || Matches("no",value) || Matches("0",value)); }
bool ProcessOptions::IsTrue(const char *value) { return (Matches("on",value) || Matches("true",value) || Matches("yes",value) || Matches("1",value)); }
//--------------------------------------------------------------------------- bool TFileMasks::Matches(const UnicodeString & FileName, bool Local, bool Directory, const TParams * Params) const { bool ImplicitMatch; return Matches(FileName, Local, Directory, Params, ImplicitMatch); }
bool IsFalse(const char *value) { return (Matches("off",value) || Matches("false",value) || Matches("no",value) || Matches("0",value)); }
bool IsTrue(const char *value) { return (Matches("on",value) || Matches("true",value) || Matches("yes",value) || Matches("1",value)); }
bool wxSimpleHtmlParser::IsTagClose() { return Matches(wxT("</")); }
int wxRegExImpl::Replace(wxString *text, const wxString& replacement, size_t maxMatches) const { wxCHECK_MSG( text, wxNOT_FOUND, wxT("NULL text in wxRegEx::Replace") ); wxCHECK_MSG( IsValid(), wxNOT_FOUND, wxT("must successfully Compile() first") ); // the input string #ifndef WXREGEX_CONVERT_TO_MB const wxChar *textstr = text->c_str(); size_t textlen = text->length(); #else const wxWX2MBbuf textstr = WXREGEX_CHAR(*text); if (!textstr) { wxLogError(_("Failed to find match for regular expression: %s"), GetErrorMsg(0, true).c_str()); return 0; } size_t textlen = strlen(textstr); text->clear(); #endif // the replacement text wxString textNew; // the result, allow 25% extra wxString result; result.reserve(5 * textlen / 4); // attempt at optimization: don't iterate over the string if it doesn't // contain back references at all bool mayHaveBackrefs = replacement.find_first_of(wxT("\\&")) != wxString::npos; if ( !mayHaveBackrefs ) { textNew = replacement; } // the position where we start looking for the match size_t matchStart = 0; // number of replacement made: we won't make more than maxMatches of them // (unless maxMatches is 0 which doesn't limit the number of replacements) size_t countRepl = 0; // note that "^" shouldn't match after the first call to Matches() so we // use wxRE_NOTBOL to prevent it from happening while ( (!maxMatches || countRepl < maxMatches) && Matches( #ifndef WXREGEX_CONVERT_TO_MB textstr + matchStart, #else textstr.data() + matchStart, #endif countRepl ? wxRE_NOTBOL : 0 WXREGEX_IF_NEED_LEN(textlen - matchStart)) ) { // the string possibly contains back references: we need to calculate // the replacement text anew after each match if ( mayHaveBackrefs ) { mayHaveBackrefs = false; textNew.clear(); textNew.reserve(replacement.length()); for ( const wxChar *p = replacement.c_str(); *p; p++ ) { size_t index = (size_t)-1; if ( *p == wxT('\\') ) { if ( wxIsdigit(*++p) ) { // back reference wxChar *end; index = (size_t)wxStrtoul(p, &end, 10); p = end - 1; // -1 to compensate for p++ in the loop } //else: backslash used as escape character } else if ( *p == wxT('&') ) { // treat this as "\0" for compatbility with ed and such index = 0; } // do we have a back reference? if ( index != (size_t)-1 ) { // yes, get its text size_t start, len; if ( !GetMatch(&start, &len, index) ) { wxFAIL_MSG( wxT("invalid back reference") ); // just eat it... } else { textNew += wxString( #ifndef WXREGEX_CONVERT_TO_MB textstr #else textstr.data() #endif + matchStart + start, *wxConvCurrent, len); mayHaveBackrefs = true; } } else // ordinary character { textNew += *p; } } } size_t start, len; if ( !GetMatch(&start, &len) ) { // we did have match as Matches() returned true above! wxFAIL_MSG( wxT("internal logic error in wxRegEx::Replace") ); return wxNOT_FOUND; } // an insurance against implementations that don't grow exponentially // to ensure building the result takes linear time if (result.capacity() < result.length() + start + textNew.length()) result.reserve(2 * result.length()); #ifndef WXREGEX_CONVERT_TO_MB result.append(*text, matchStart, start); #else result.append(wxString(textstr.data() + matchStart, *wxConvCurrent, start)); #endif matchStart += start; result.append(textNew); countRepl++; matchStart += len; } #ifndef WXREGEX_CONVERT_TO_MB result.append(*text, matchStart, wxString::npos); #else result.append(wxString(textstr.data() + matchStart, *wxConvCurrent)); #endif *text = result; return countRepl; }
bool wxSimpleHtmlParser::IsComment() { return Matches(wxT("<!--")); }
void CDebugger::FindEeFunctions() { if(m_virtualMachine.m_ee->m_os->GetELF() == nullptr) return; auto executableRange = m_virtualMachine.m_ee->m_os->GetExecutableRange(); uint32 minAddr = executableRange.first; uint32 maxAddr = executableRange.second & ~0x03; { Framework::CStdStream patternStream("ee_functions.xml", "rb"); boost::scoped_ptr<Framework::Xml::CNode> document(Framework::Xml::CParser::ParseDocument(patternStream)); CMipsFunctionPatternDb patternDb(document.get()); for(auto patternIterator(std::begin(patternDb.GetPatterns())); patternIterator != std::end(patternDb.GetPatterns()); ++patternIterator) { auto pattern = *patternIterator; for(uint32 address = minAddr; address <= maxAddr; address += 4) { uint32* text = reinterpret_cast<uint32*>(m_virtualMachine.m_ee->m_ram + address); uint32 textSize = (maxAddr - address); if(pattern.Matches(text, textSize)) { m_virtualMachine.m_ee->m_EE.m_Functions.InsertTag(address, pattern.name.c_str()); break; } } } } { //Identify functions that reference special string literals (TODO: Move that inside a file) static const std::map<std::string, std::string> stringFuncs = { { "SceSifrpcBind", "SifBindRpc" }, { "SceSifrpcCall", "SifCallRpc" }, { "call cdread cmd\n", "CdRead" }, { "sceGsPutDrawEnv: DMA Ch.2 does not terminate\r\n", "GsPutDrawEnv" }, { "sceGsSyncPath: DMA Ch.1 does not terminate\r\n", "GsSyncPath" }, { "sceDbcReceiveData: rpc error\n", "DbcReceiveData" } }; { auto& eeFunctions = m_virtualMachine.m_ee->m_EE.m_Functions; const auto& eeComments = m_virtualMachine.m_ee->m_EE.m_Comments; const auto& eeAnalysis = m_virtualMachine.m_ee->m_EE.m_analysis; for(auto tagIterator = eeComments.GetTagsBegin(); tagIterator != eeComments.GetTagsEnd(); tagIterator++) { const auto& tag = *tagIterator; auto subroutine = eeAnalysis->FindSubroutine(tag.first); if(subroutine == nullptr) continue; auto stringFunc = stringFuncs.find(tag.second); if(stringFunc == std::end(stringFuncs)) continue; eeFunctions.InsertTag(subroutine->start, stringFunc->second.c_str()); } } } m_virtualMachine.m_ee->m_EE.m_Functions.OnTagListChange(); }
bool wxSimpleHtmlParser::IsDirective() { return Matches(wxT("<!")); }