void XPathMatcher::endElement(const XMLElementDecl& elemDecl, const XMLCh* const elemContent) { for(int i = 0; i < (int) fLocationPathSize; i++) { // go back a step fCurrentStep[i] = fStepIndexes->elementAt(i)->pop(); // don't do anything, if not matching if (fNoMatchDepth[i] > 0) { fNoMatchDepth[i]--; } // signal match, if appropriate else { int j=0; for(; j<i && ((fMatched[j] & XP_MATCHED) != XP_MATCHED); j++) ; if (j < i || (fMatched[j] == 0) || ((fMatched[j] & XP_MATCHED_A) == XP_MATCHED_A)) continue; DatatypeValidator* dv = ((SchemaElementDecl*) &elemDecl)->getDatatypeValidator(); bool isNillable = (((SchemaElementDecl *) &elemDecl)->getMiscFlags() & SchemaSymbols::XSD_NILLABLE) != 0; matched(elemContent, dv, isNillable); fMatched[i] = 0; } } }
/* Insert a packet to the carrier sense or hidden teriminal list */ void update_list( unsigned char mac1[6], unsigned char mac2[6],struct timespec value,int t){ struct timespec tmp1 = {0}; if(timespec_compare(&value,&tmp1)<0){ printk(KERN_DEBUG "[warning]There exists negtive dmac!\n"); } int i; struct inf_info * tmp; for(i=0;i<CS_NUMBER;i++){ tmp = (struct inf_info *)&cs[t][i]; if( (tmp->value.tv_nsec != 0) && (matched(ether_sprintf_test3(tmp->wlan_src),ether_sprintf_test4(tmp->wlan_dst),ether_sprintf_test(mac1),ether_sprintf_test2(mac2),t) == true) ){ tmp->value = timespec_add(tmp->value,value); return; } } // there is no match!! for(i=0;i<CS_NUMBER;i++) { tmp = (struct inf_info *)&cs[t][i]; if( (cs[t][i].value.tv_nsec == 0 ) && (control_address(ether_sprintf_test(mac1))== 0)&& (control_address(ether_sprintf_test2(mac2))== 0)) { memcpy(cs[t][i].wlan_src,mac1,MAC_LEN); memcpy(cs[t][i].wlan_dst,mac2,MAC_LEN); cs[t][i].value = value; return; } } }
const QString ArgFilePath::error() const { if(isValid()) return QString(); if(empty()) return identifier() + " expected"; if(!matched()) return "filepath must be delimited by quotation marks, and can not contain following charachters: \\*?<>|"; if(m_invalidatedFilePath.isDir()) return "filepath should not point to a directory"; if(m_existingFile && !m_invalidatedFilePath.isFile()) return "filepath does not point to a file (required)"; if(m_existingFile && !m_invalidatedFilePath.exists()) return "filepath does not exist (required)"; if(m_existingFile && !m_invalidatedFilePath.permission(m_permissions)) return "filepath does not yield required permissions (required)"; return "unknown"; }
unsigned int BlanketResolver::findHeadIndex(Genome* blanket) { std::vector<bool> matched(blanket->genomeLength(), false); std::vector<Genome*> blanketGenomes = BlanketResolver::getBlanketGenomes(blanket); std::vector<PopulationNode*> nodes; for (unsigned int i = 0; i < blanket->genomeLength(); i++) { std::set<Locus*> constructiveLoci = blanketGenomes[i]->getConstructiveLoci(); for (auto locus : constructiveLoci) nodes.push_back(((PopulationLocus*)locus)->getNode()); } for (unsigned int i = 0; i < blanketGenomes.size(); i++) for (unsigned int k = 0; k < nodes.size(); k++) if (nodes[k]->contains(blanketGenomes[i])) { matched[i] = true; break; } for (unsigned int i = 0; i < matched.size(); i++) if (!matched[i]) return i; // Strangeness is happening here throw InvalidBlanketException(); }
int main(int argc, char *argv[]) { int i, rank; Arraylist r; assert(argc > 1); rank = atoi(argv[1]); r = allGraphs(rank); if (rank % 2 == 1){ printf("Graphs: %d.\n", r->size); printAsGraphList(rank, r); } else { Arraylist r0, r1; r0 = newArraylist(5); r1 = newArraylist(5); for (i = 0 ; i < r->size ; i++) { if (matched(rank, r->it[i])) putItem(r->it[i], r0); else putItem(r->it[i], r1); } printf("Matched graphs: %d.\n", r0->size); printAsGraphList(rank, r0); printf("Unmatched graphs: %d.\n", r1->size); printAsGraphList(rank, r1); freeArraylist(r0); freeArraylist(r1); } freeArraylist(r); freePerm(); #if 0 reportCnt(); reportACnt(); reportGCnt(); #endif return 0; }
void print_list(const std::vector<Expr> &args) { for (size_t i = 0; i < args.size(); i++) { if (i > 0) { stream << matched(",") << " "; } print(args[i]); } }
static ptrdiff_t findLngID(const wchar_t *fn) { for (size_t i = 0; i < langColl.getCount (); i++) { const TLang *lng = langColl[i]; if (matched (lng->mask, fn)) return (i); } return (-1); }
void Instantiator::ground(Grounder *g) { typedef std::vector<bool> BoolVec; assert(indices_.size() > 0); int numNew = 0; for(IndexPtrVec::size_type i = 0; i < indices_.size(); ++i) { new_[i] = 2 * indices_[i].hasNew(); if(new_[i]) ++numNew; } BoolVec ord(new_.size(), true); int l = 0; std::pair<bool, bool> matched(true, false); while(l >= 0) { if(matched.first) matched = indices_[l].firstMatch(g, l); else matched = indices_[l].nextMatch(g, l); if(matched.first && !matched.second && new_[l] == 2) { new_[l] = 1; --numNew; } assert(ord[l] || !matched.second); if(!matched.second) ord[l] = false; if(matched.first && numNew > 0) { if(l + 1 == static_cast<int>(indices_.size())) { if(!groundable_->grounded(g)) break; matched.first = false; } else ++l; } else { ord[l] = true; matched.first = false; if(new_[l] == 1) { ++numNew; new_[l] = 2; } --l; } } foreach(uint32_t var, groundable_->vars()) g->unbind(var); foreach(Index &idx, indices_) idx.finish(); }
template <typename Traits> inline void branch<Traits>::process(char const *begin, char const *end, Traits &traits) const { if (matched(begin, end)) { for (typename std::list<pointer>::const_iterator i = children_.begin(), list_end = children_.end(); i != list_end; ++i) { (*i)->process(begin, end, traits); } for (typename std::list<definition_pointer>::const_iterator i = definitions_.begin(), list_end = definitions_.end(); i != list_end; ++i) { (*i)->process(begin, end, traits); } } }
Arraylist allMatchedGraphs(int rank) { Arraylist ar = allGraphs(rank); int i; for (i = 0; i < ar->size; i++) { if (! matched(rank, ar->it[i])) { freestack(ar->it[i]); ar->it[i] = NULL; } } removeNulls(ar); return ar; }
const std::string & submatch(int number) { if (!matched(number)) return _subcaching[_subcounter - 1 /* invalid, always empty! */ ]; if (_subcaching[number].empty()) { _subcaching[number].assign(_basestring, _submatches[number].rm_so, _submatches[number].rm_eo - _submatches[number].rm_so); } return _subcaching[number]; }
void _RemoveTransaction(void *id, BOOL (*matched)(void *t1, void *t2)) { int i = 0; for(; i < CountTransaction(); i++) { struct Transaction *tt = GetTransactionByPosition(i); if (matched(tt, id)) { RemoveTransactionByPosition(i); DestroyTransaction(&tt); break; } } }
void CommandMgr::HandleKeres(CommandMessage& recvData) { CNick(recvData); if(recvData.Args.length() <= recvData.firstSpace+1) { sIRCSession.SendChatMessage(PRIVMSG, recvData.GetChannel(), "Nincs paraméter!"); return; } string kiiras = sVezerlo.urlencode(recvData.Args.substr(recvData.firstSpace+1)); m_Curl = curl_easy_init(); if(m_Curl) { string bufferdata; curl_easy_setopt(m_Curl, CURLOPT_URL, format("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=0&rsz=small&q=%s", kiiras.c_str()).c_str()); curl_easy_setopt(m_Curl, CURLOPT_WRITEFUNCTION, CommandMgr::writer); curl_easy_setopt(m_Curl, CURLOPT_WRITEDATA, &bufferdata); CURLcode result = curl_easy_perform(m_Curl); curl_easy_cleanup(m_Curl); if(result == CURLE_OK) { boost::regex re("(\\\"unescapedUrl\\\"):\\\"(?<url>\\S+)\\\",\\\"url\\\""); boost::cmatch matches; boost::regex_search(bufferdata.c_str(), matches, re); string matched(matches[2].first, matches[2].second); boost::regex re1(".titleNoFormatting.:.(.*).,.content.:."); boost::cmatch matches1; boost::regex_search(bufferdata.c_str(), matches1, re1); string matched1(matches1[1].first, matches1[1].second); int szokoz = matched1.find("\",\""); sIRCSession.SendChatMessage(PRIVMSG, recvData.GetChannel(), "2Title: %s", matched1.substr(0, szokoz).c_str()); sIRCSession.SendChatMessage(PRIVMSG, recvData.GetChannel(), "2Link: 9%s", matched.c_str()); } else { Log.Notice("IRCSession", "Keres: Hiba a Http lekerdezesben."); sIRCSession.SendChatMessage(PRIVMSG, recvData.GetChannel(), "Hibás találat"); } } else curl_easy_cleanup(m_Curl); }
int main(){ char *buffer = malloc(buffer_size); char *save = buffer; int is_matched; while(1){ buffer = save; memset(buffer, 0, buffer_size); fgets(buffer, buffer_size, stdin); if(!buffer | *buffer == 0) break; is_matched = matched(&buffer, 0); assert(is_matched); //printf("%d\n", is_matched); } }
int matched(char **string, int level){ while(**string && **string != ')'){ if(**string == '('){ (*string)++; if(!matched(string, level + 1)) return 0; } else (*string)++; } if(!(!!**string ^ !!level)){ (*string)++; return 1; } else return 0; }
void ACAutomation::search(uint8_t *data,uint64_t size) { Node *p = this->root; for(uint64_t i=0;i<size;i++){ uint8_t index=data[i]; while(p->next[index] == NULL && p != this->root){ p = p->fail; } if(p->next[index] == NULL){ p=this->root; }else{ p=p->next[index]; if(p->flag>0){ bool continu=matched(i- p->size+1, p->flag-1); if(continu==false){ return; } } } } }
/** * Scan through a origin file, looking for sections that match * checksums from the generator, and transmit either literal or token * data. * * Also calculates the MD4 checksum of the whole file, using the md * accumulator. This is transmitted with the file as protection * against corruption on the wire. * * @param s Checksums received from the generator. If <tt>s->count == * 0</tt>, then there are actually no checksums for this file. * * @param len Length of the file to send. **/ void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len) { int sum_len; last_match = 0; false_alarms = 0; hash_hits = 0; matches = 0; data_transfer = 0; sum_init(xfersum_type, checksum_seed); if (append_mode > 0) { if (append_mode == 2) { OFF_T j = 0; for (j = CHUNK_SIZE; j < s->flength; j += CHUNK_SIZE) { if (buf && INFO_GTE(PROGRESS, 1)) show_progress(last_match, buf->file_size); sum_update(map_ptr(buf, last_match, CHUNK_SIZE), CHUNK_SIZE); last_match = j; } if (last_match < s->flength) { int32 n = (int32)(s->flength - last_match); if (buf && INFO_GTE(PROGRESS, 1)) show_progress(last_match, buf->file_size); sum_update(map_ptr(buf, last_match, n), n); } } last_match = s->flength; s->count = 0; } if (len > 0 && s->count > 0) { build_hash_table(s); if (DEBUG_GTE(DELTASUM, 2)) rprintf(FINFO,"built hash table\n"); hash_search(f, s, buf, len); if (DEBUG_GTE(DELTASUM, 2)) rprintf(FINFO,"done hash search\n"); } else { OFF_T j; /* by doing this in pieces we avoid too many seeks */ for (j = last_match + CHUNK_SIZE; j < len; j += CHUNK_SIZE) matched(f, s, buf, j, -2); matched(f, s, buf, len, -1); } sum_len = sum_end(sender_file_sum); /* If we had a read error, send a bad checksum. We use all bits * off as long as the checksum doesn't happen to be that, in * which case we turn the last 0 bit into a 1. */ if (buf && buf->status != 0) { int i; for (i = 0; i < sum_len && sender_file_sum[i] == 0; i++) {} memset(sender_file_sum, 0, sum_len); if (i == sum_len) sender_file_sum[i-1]++; } if (DEBUG_GTE(DELTASUM, 2)) rprintf(FINFO,"sending file_sum\n"); write_buf(f, sender_file_sum, sum_len); if (DEBUG_GTE(DELTASUM, 2)) { rprintf(FINFO, "false_alarms=%d hash_hits=%d matches=%d\n", false_alarms, hash_hits, matches); } total_hash_hits += hash_hits; total_false_alarms += false_alarms; total_matches += matches; stats.literal_data += data_transfer; }
static void hash_search(int f,struct sum_struct *s, struct map_struct *buf, OFF_T len) { OFF_T offset, aligned_offset, end; int32 k, want_i, aligned_i, backup; char sum2[SUM_LENGTH]; uint32 s1, s2, sum; int more; schar *map; /* want_i is used to encourage adjacent matches, allowing the RLL * coding of the output to work more efficiently. */ want_i = 0; if (DEBUG_GTE(DELTASUM, 2)) { rprintf(FINFO, "hash search b=%ld len=%s\n", (long)s->blength, big_num(len)); } k = (int32)MIN(len, (OFF_T)s->blength); map = (schar *)map_ptr(buf, 0, k); sum = get_checksum1((char *)map, k); s1 = sum & 0xFFFF; s2 = sum >> 16; if (DEBUG_GTE(DELTASUM, 3)) rprintf(FINFO, "sum=%.8x k=%ld\n", sum, (long)k); offset = aligned_offset = aligned_i = 0; end = len + 1 - s->sums[s->count-1].len; if (DEBUG_GTE(DELTASUM, 3)) { rprintf(FINFO, "hash search s->blength=%ld len=%s count=%s\n", (long)s->blength, big_num(len), big_num(s->count)); } do { int done_csum2 = 0; uint32 hash_entry; int32 i, *prev; if (DEBUG_GTE(DELTASUM, 4)) { rprintf(FINFO, "offset=%s sum=%04x%04x\n", big_num(offset), s2 & 0xFFFF, s1 & 0xFFFF); } if (tablesize == TRADITIONAL_TABLESIZE) { hash_entry = SUM2HASH2(s1,s2); if ((i = hash_table[hash_entry]) < 0) goto null_hash; sum = (s1 & 0xffff) | (s2 << 16); } else { sum = (s1 & 0xffff) | (s2 << 16); hash_entry = BIG_SUM2HASH(sum); if ((i = hash_table[hash_entry]) < 0) goto null_hash; } prev = &hash_table[hash_entry]; hash_hits++; do { int32 l; /* When updating in-place, the chunk's offset must be * either >= our offset or identical data at that offset. * Remove any bypassed entries that we can never use. */ if (updating_basis_file && s->sums[i].offset < offset && !(s->sums[i].flags & SUMFLG_SAME_OFFSET)) { *prev = s->sums[i].chain; continue; } prev = &s->sums[i].chain; if (sum != s->sums[i].sum1) continue; /* also make sure the two blocks are the same length */ l = (int32)MIN((OFF_T)s->blength, len-offset); if (l != s->sums[i].len) continue; if (DEBUG_GTE(DELTASUM, 3)) { rprintf(FINFO, "potential match at %s i=%ld sum=%08x\n", big_num(offset), (long)i, sum); } if (!done_csum2) { map = (schar *)map_ptr(buf,offset,l); get_checksum2((char *)map,l,sum2); done_csum2 = 1; } if (memcmp(sum2,s->sums[i].sum2,s->s2length) != 0) { false_alarms++; continue; } /* When updating in-place, the best possible match is * one with an identical offset, so we prefer that over * the adjacent want_i optimization. */ if (updating_basis_file) { /* All the generator's chunks start at blength boundaries. */ while (aligned_offset < offset) { aligned_offset += s->blength; aligned_i++; } if ((offset == aligned_offset || (sum == 0 && l == s->blength && aligned_offset + l <= len)) && aligned_i < s->count) { if (i != aligned_i) { if (sum != s->sums[aligned_i].sum1 || l != s->sums[aligned_i].len || memcmp(sum2, s->sums[aligned_i].sum2, s->s2length) != 0) goto check_want_i; i = aligned_i; } if (offset != aligned_offset) { /* We've matched some zeros in a spot that is also zeros * further along in the basis file, if we find zeros ahead * in the sender's file, we'll output enough literal data * to re-align with the basis file, and get back to seeking * instead of writing. */ backup = (int32)(aligned_offset - last_match); if (backup < 0) backup = 0; map = (schar *)map_ptr(buf, aligned_offset - backup, l + backup) + backup; sum = get_checksum1((char *)map, l); if (sum != s->sums[i].sum1) goto check_want_i; get_checksum2((char *)map, l, sum2); if (memcmp(sum2, s->sums[i].sum2, s->s2length) != 0) goto check_want_i; /* OK, we have a re-alignment match. Bump the offset * forward to the new match point. */ offset = aligned_offset; } /* This identical chunk is in the same spot in the old and new file. */ s->sums[i].flags |= SUMFLG_SAME_OFFSET; want_i = i; } } check_want_i: /* we've found a match, but now check to see * if want_i can hint at a better match. */ if (i != want_i && want_i < s->count && (!updating_basis_file || s->sums[want_i].offset >= offset || s->sums[want_i].flags & SUMFLG_SAME_OFFSET) && sum == s->sums[want_i].sum1 && memcmp(sum2, s->sums[want_i].sum2, s->s2length) == 0) { /* we've found an adjacent match - the RLL coder * will be happy */ i = want_i; } want_i = i + 1; matched(f,s,buf,offset,i); offset += s->sums[i].len - 1; k = (int32)MIN((OFF_T)s->blength, len-offset); map = (schar *)map_ptr(buf, offset, k); sum = get_checksum1((char *)map, k); s1 = sum & 0xFFFF; s2 = sum >> 16; matches++; break; } while ((i = s->sums[i].chain) >= 0); null_hash: backup = (int32)(offset - last_match); /* We sometimes read 1 byte prior to last_match... */ if (backup < 0) backup = 0; /* Trim off the first byte from the checksum */ more = offset + k < len; map = (schar *)map_ptr(buf, offset - backup, k + more + backup) + backup; s1 -= map[0] + CHAR_OFFSET; s2 -= k * (map[0]+CHAR_OFFSET); /* Add on the next byte (if there is one) to the checksum */ if (more) { s1 += map[k] + CHAR_OFFSET; s2 += s1; } else --k; /* By matching early we avoid re-reading the data 3 times in the case where a token match comes a long way after last match. The 3 reads are caused by the running match, the checksum update and the literal send. */ if (backup >= s->blength+CHUNK_SIZE && end-offset > CHUNK_SIZE) matched(f, s, buf, offset - s->blength, -2); } while (++offset < end); matched(f, s, buf, len, -1); map_ptr(buf, len-1, 1); }
/** * Scan through a origin file, looking for sections that match * checksums from the generator, and transmit either literal or token * data. * * Also calculates the MD4 checksum of the whole file, using the md * accumulator. This is transmitted with the file as protection * against corruption on the wire. * * @param s Checksums received from the generator. If <tt>s->count == * 0</tt>, then there are actually no checksums for this file. * * @param len Length of the file to send. **/ void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len) { char file_sum[MD4_SUM_LENGTH]; last_match = 0; false_alarms = 0; hash_hits = 0; matches = 0; data_transfer = 0; sum_init(checksum_seed); if (append_mode > 0) { OFF_T j = 0; for (j = CHUNK_SIZE; j < s->flength; j += CHUNK_SIZE) { if (buf && do_progress) show_progress(last_match, buf->file_size); sum_update(map_ptr(buf, last_match, CHUNK_SIZE), CHUNK_SIZE); last_match = j; } if (last_match < s->flength) { int32 len = (int32)(s->flength - last_match); if (buf && do_progress) show_progress(last_match, buf->file_size); sum_update(map_ptr(buf, last_match, len), len); last_match = s->flength; } s->count = 0; } if (len > 0 && s->count > 0) { build_hash_table(s); if (verbose > 2) rprintf(FINFO,"built hash table\n"); hash_search(f,s,buf,len); if (verbose > 2) rprintf(FINFO,"done hash search\n"); } else { OFF_T j; /* by doing this in pieces we avoid too many seeks */ for (j = last_match + CHUNK_SIZE; j < len; j += CHUNK_SIZE) matched(f, s, buf, j, -2); matched(f, s, buf, len, -1); } sum_end(file_sum); /* If we had a read error, send a bad checksum. */ if (buf && buf->status != 0) file_sum[0]++; if (verbose > 2) rprintf(FINFO,"sending file_sum\n"); write_buf(f,file_sum,MD4_SUM_LENGTH); if (verbose > 2) rprintf(FINFO, "false_alarms=%d hash_hits=%d matches=%d\n", false_alarms, hash_hits, matches); total_hash_hits += hash_hits; total_false_alarms += false_alarms; total_matches += matches; stats.literal_data += data_transfer; }
static void hash_search(int f,struct sum_struct *s, struct map_struct *buf, OFF_T len) { OFF_T offset, end; int32 k, want_i, backup; char sum2[SUM_LENGTH]; uint32 s1, s2, sum; int more; schar *map; /* want_i is used to encourage adjacent matches, allowing the RLL * coding of the output to work more efficiently. */ want_i = 0; if (verbose > 2) { rprintf(FINFO, "hash search b=%ld len=%.0f\n", (long)s->blength, (double)len); } k = (int32)MIN(len, (OFF_T)s->blength); map = (schar *)map_ptr(buf, 0, k); sum = get_checksum1((char *)map, k); s1 = sum & 0xFFFF; s2 = sum >> 16; if (verbose > 3) rprintf(FINFO, "sum=%.8x k=%ld\n", sum, (long)k); offset = 0; end = len + 1 - s->sums[s->count-1].len; if (verbose > 3) { rprintf(FINFO, "hash search s->blength=%ld len=%.0f count=%.0f\n", (long)s->blength, (double)len, (double)s->count); } do { int done_csum2 = 0; int32 i; if (verbose > 4) { rprintf(FINFO, "offset=%.0f sum=%04x%04x\n", (double)offset, s2 & 0xFFFF, s1 & 0xFFFF); } i = hash_table[SUM2HASH2(s1,s2)]; if (i < 0) goto null_hash; sum = (s1 & 0xffff) | (s2 << 16); hash_hits++; do { int32 l; if (sum != s->sums[i].sum1) continue; /* also make sure the two blocks are the same length */ l = (int32)MIN((OFF_T)s->blength, len-offset); if (l != s->sums[i].len) continue; /* in-place: ensure chunk's offset is either >= our * offset or that the data didn't move. */ if (updating_basis_file && s->sums[i].offset < offset && !(s->sums[i].flags & SUMFLG_SAME_OFFSET)) continue; if (verbose > 3) { rprintf(FINFO, "potential match at %.0f i=%ld sum=%08x\n", (double)offset, (long)i, sum); } if (!done_csum2) { map = (schar *)map_ptr(buf,offset,l); get_checksum2((char *)map,l,sum2); done_csum2 = 1; } if (memcmp(sum2,s->sums[i].sum2,s->s2length) != 0) { false_alarms++; continue; } /* When updating in-place, the best possible match is * one with an identical offset, so we prefer that over * the following want_i optimization. */ if (updating_basis_file) { int32 i2; for (i2 = i; i2 >= 0; i2 = s->sums[i2].chain) { if (s->sums[i2].offset != offset) continue; if (i2 != i) { if (sum != s->sums[i2].sum1) break; if (memcmp(sum2, s->sums[i2].sum2, s->s2length) != 0) break; i = i2; } /* This chunk was at the same offset on * both the sender and the receiver. */ s->sums[i].flags |= SUMFLG_SAME_OFFSET; goto set_want_i; } } /* we've found a match, but now check to see * if want_i can hint at a better match. */ if (i != want_i && want_i < s->count && (!updating_basis_file || s->sums[want_i].offset >= offset || s->sums[want_i].flags & SUMFLG_SAME_OFFSET) && sum == s->sums[want_i].sum1 && memcmp(sum2, s->sums[want_i].sum2, s->s2length) == 0) { /* we've found an adjacent match - the RLL coder * will be happy */ i = want_i; } set_want_i: want_i = i + 1; matched(f,s,buf,offset,i); offset += s->sums[i].len - 1; k = (int32)MIN((OFF_T)s->blength, len-offset); map = (schar *)map_ptr(buf, offset, k); sum = get_checksum1((char *)map, k); s1 = sum & 0xFFFF; s2 = sum >> 16; matches++; break; } while ((i = s->sums[i].chain) >= 0); null_hash: backup = (int32)(offset - last_match); /* We sometimes read 1 byte prior to last_match... */ if (backup < 0) backup = 0; /* Trim off the first byte from the checksum */ more = offset + k < len; map = (schar *)map_ptr(buf, offset - backup, k + more + backup) + backup; s1 -= map[0] + CHAR_OFFSET; s2 -= k * (map[0]+CHAR_OFFSET); /* Add on the next byte (if there is one) to the checksum */ if (more) { s1 += map[k] + CHAR_OFFSET; s2 += s1; } else --k; /* By matching early we avoid re-reading the data 3 times in the case where a token match comes a long way after last match. The 3 reads are caused by the running match, the checksum update and the literal send. */ if (backup >= s->blength+CHUNK_SIZE && end-offset > CHUNK_SIZE) matched(f, s, buf, offset - s->blength, -2); } while (++offset < end); matched(f, s, buf, len, -1); map_ptr(buf, len-1, 1); }
void print_list(const string &l, const std::vector<Expr> &args, const string &r) { stream << matched(l); print_list(args); stream << matched(r); }
void CommandMgr::HandleForditas(CommandMessage& recvData) { CNick(recvData); if(recvData.Args.length() <= recvData.firstSpace+1) { sIRCSession.SendChatMessage(PRIVMSG, recvData.GetChannel(), "Nincs paraméter!"); return; } vector<string> res(1); split(recvData.Args.substr(recvData.firstSpace+1), " ", res); if(res.size() < 2) { res.clear(); return; } if(res.size() < 3) { sIRCSession.SendChatMessage(PRIVMSG, recvData.GetChannel(), "Nincs egy szó se megadva amit lekéne fordítani!"); res.clear(); return; } string nyelv = res[1]; string alomany; int resAdat = res.size(); for(int i = 2; i < resAdat; i++) alomany += " " + res[i]; string iras = sVezerlo.urlencode(alomany.substr(1)); m_Curl = curl_easy_init(); if(m_Curl) { string bufferdata; curl_easy_setopt(m_Curl, CURLOPT_URL, format("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=%s&langpair=%s", iras.c_str(), nyelv.c_str()).c_str()); curl_easy_setopt(m_Curl, CURLOPT_WRITEFUNCTION, CommandMgr::writer); curl_easy_setopt(m_Curl, CURLOPT_WRITEDATA, &bufferdata); CURLcode result = curl_easy_perform(m_Curl); curl_easy_cleanup(m_Curl); if(result == CURLE_OK) { boost::regex re("\\{.translatedText.\\:.(.+).\\},"); boost::cmatch matches; boost::regex_search(bufferdata.c_str(), matches, re); string matched(matches[1].first, matches[1].second); sIRCSession.SendChatMessage(PRIVMSG, recvData.GetChannel(), "%s", matched.c_str()); } else { Log.Notice("IRCSession", "Fordit: Hiba a Http lekerdezesben."); sIRCSession.SendChatMessage(PRIVMSG, recvData.GetChannel(), "Hibás fordítás"); } } else curl_easy_cleanup(m_Curl); res.clear(); }
void XPathMatcher::startElement(const XMLElementDecl& elemDecl, const unsigned int urlId, const XMLCh* const elemPrefix, const RefVectorOf<XMLAttr>& attrList, const unsigned int attrCount) { for (int i = 0; i < (int) fLocationPathSize; i++) { // push context int startStep = fCurrentStep[i]; fStepIndexes->elementAt(i)->push(startStep); // try next xpath, if not matching if ((fMatched[i] & XP_MATCHED_D) == XP_MATCHED || fNoMatchDepth[i] > 0) { fNoMatchDepth[i]++; continue; } if((fMatched[i] & XP_MATCHED_D) == XP_MATCHED_D) { fMatched[i] = XP_MATCHED_DP; } // consume self::node() steps XercesLocationPath* locPath = fLocationPaths->elementAt(i); int stepSize = locPath->getStepSize(); while (fCurrentStep[i] < stepSize && locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::SELF) { fCurrentStep[i]++; } if (fCurrentStep[i] == stepSize) { fMatched[i] = XP_MATCHED; continue; } // now if the current step is a descendant step, we let the next // step do its thing; if it fails, we reset ourselves // to look at this step for next time we're called. // so first consume all descendants: int descendantStep = fCurrentStep[i]; while (fCurrentStep[i] < stepSize && locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::DESCENDANT) { fCurrentStep[i]++; } bool sawDescendant = fCurrentStep[i] > descendantStep; if (fCurrentStep[i] == stepSize) { fNoMatchDepth[i]++; continue; } // match child::... step, if haven't consumed any self::node() if ((fCurrentStep[i] == startStep || fCurrentStep[i] > descendantStep) && locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::CHILD) { XercesStep* step = locPath->getStep(fCurrentStep[i]); XercesNodeTest* nodeTest = step->getNodeTest(); if (nodeTest->getType() == XercesNodeTest::QNAME) { QName elemQName(elemPrefix, elemDecl.getElementName()->getLocalPart(), urlId, fMemoryManager); // if (!(*(nodeTest->getName()) == *(elemDecl.getElementName()))) { if (!(*(nodeTest->getName()) == elemQName)) { if(fCurrentStep[i] > descendantStep) { fCurrentStep[i] = descendantStep; continue; } fNoMatchDepth[i]++; continue; } } fCurrentStep[i]++; } if (fCurrentStep[i] == stepSize) { if (sawDescendant) { fCurrentStep[i] = descendantStep; fMatched[i] = XP_MATCHED_D; } else { fMatched[i] = XP_MATCHED; } continue; } // match attribute::... step if (fCurrentStep[i] < stepSize && locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::ATTRIBUTE) { if (attrCount) { XercesNodeTest* nodeTest = locPath->getStep(fCurrentStep[i])->getNodeTest(); for (unsigned int attrIndex = 0; attrIndex < attrCount; attrIndex++) { const XMLAttr* curDef = attrList.elementAt(attrIndex); if (nodeTest->getType() != XercesNodeTest::QNAME || (*(nodeTest->getName()) == *(curDef->getAttName()))) { fCurrentStep[i]++; if (fCurrentStep[i] == stepSize) { fMatched[i] = XP_MATCHED_A; int j=0; for(; j<i && ((fMatched[j] & XP_MATCHED) != XP_MATCHED); j++) ; if(j == i) { SchemaAttDef* attDef = ((SchemaElementDecl&) elemDecl).getAttDef(curDef->getName(), curDef->getURIId()); DatatypeValidator* dv = (attDef) ? attDef->getDatatypeValidator() : 0; matched(curDef->getValue(), dv, false); } } break; } } } if ((fMatched[i] & XP_MATCHED) != XP_MATCHED) { if(fCurrentStep[i] > descendantStep) { fCurrentStep[i] = descendantStep; continue; } fNoMatchDepth[i]++; } } } }
static int enable_disable(int argc, char **argv, struct mpd_connection *conn, bool (*matched)(struct mpd_connection *conn, unsigned id), bool (*not_matched)(struct mpd_connection *conn, unsigned id)) { char **names = argv, **names_end = argv; bool only = false; if (not_matched != NULL && !strcmp(argv[0], "only")) { only = true; ++argv; if (!--argc) { DIE("No outputs specified."); } } unsigned *ids = malloc(argc * sizeof *ids); unsigned *ids_end = ids; for (int i = argc; i; --i, ++argv) { int arg; if (!parse_int(*argv, &arg)) { *names_end = *argv; ++names_end; } else if (arg <= 0) { fprintf(stderr, "%s: not a positive integer\n", *argv); } else { /* We decrement by 1 to make it natural to the user. */ *ids_end++ = arg - 1; } } unsigned max; if (only || names != names_end) { max = match_outputs(conn, names, names_end, &ids_end); } if (ids == ids_end) { goto done; } if (!mpd_command_list_begin(conn, false)) { printErrorAndExit(conn); } if (only) { for (unsigned i = 0; i <= max; ++i) { bool found = false; for (unsigned *id = ids; !found && id != ids_end; ++id) { found = *id == i; } (found ? matched : not_matched)(conn, i); } } else { for (unsigned *id = ids; id != ids_end; ++id) { matched(conn, *id); } } if (!mpd_command_list_end(conn) || !mpd_response_finish(conn)) { printErrorAndExit(conn); } cmd_outputs(0, NULL, conn); done: free(ids); return 0; }