void serverlist_frame() { int i; for (i = 0; i < server_count; i++) { msg_t *msg = sock_recv(&serverlist[i].sock); if (msg) { serverlist[i].ping_end = millis(); skip_data(msg, strlen("info\n")); read_server(serverlist + i, read_string(msg)); if (partial_match(filter, serverlist[i].name) || partial_match(filter, serverlist[i].map) || partial_match(filter, serverlist[i].mod) || partial_match(filter, serverlist[i].gametype)) ui_output(output_client, "^5%i ^7(%i) %s %s ^5[^7%s^5] [^7%s:%s^5]\n", i, serverlist[i].ping_end - serverlist[i].ping_start, serverlist[i].players, serverlist[i].name, serverlist[i].map, serverlist[i].mod, serverlist[i].gametype); serverlist[i].received = qtrue; } if (serverlist[i].ping_retries > 0 && !serverlist[i].received && millis() >= serverlist[i].ping_start + PING_TIMEOUT) ping_server(serverlist + i); } master_t *master; for (master = masters; master->address; master++) { msg_t *msg = sock_recv(&master->sock); if (!msg) continue; char address_string[32]; qbyte address[4]; unsigned short port; skip_data(msg, strlen("getserversResponse")); while (msg->readcount + 7 <= msg->cursize) { char prefix = read_char(msg); port = 0; if (prefix == '\\') { read_data(msg, address, 4); port = ShortSwap(read_short(msg)); sprintf(address_string, "%u.%u.%u.%u", address[0], address[1], address[2], address[3]); } if (port != 0) { server_t *server = find_server(address_string, port); if (server != NULL) continue; server = serverlist + server_count++; sock_init(&server->sock); strcpy(server->address, address_string); server->port = port; server->received = qfalse; server->ping_retries = MAX_PING_RETRIES + 1; ping_server(server); } } } }
// static Node *Viterbi::filterNode(Node *constrained_node, Node *node) { if (!constrained_node) { return node; } Node *prev = 0; Node *result = 0; for (Node *n = node; n; n = n->bnext) { if (constrained_node->length == n->length && (std::strcmp(constrained_node->feature, "*") == 0 || partial_match(constrained_node->feature, n->feature))) { if (prev) { prev->bnext = n; prev = n; } else { result = n; prev = result; } } } if (!result) { result = constrained_node; } if (prev) { prev->bnext = 0; } return result; }
Node* Viterbi::filterNode(Node *node, size_t pos) { if (!partial_) return node; Node *c = begin_node_list_[pos]; if (!c) return node; Node *prev = 0; Node *result = 0; for (Node *n = node; n; n = n->bnext) { if (c->length == n->length && (std::strcmp(c->feature, "*") == 0 || partial_match(c->feature, n->feature))) { if (prev) { prev->bnext = n; prev = n; } else { result = n; prev = result; } } } if (!result) result = c; if (prev) prev->bnext = 0; return result; }
bool match_(match_state<BidiIter> &state, Next const &next, mpl::false_) const { typedef typename iterator_difference<BidiIter>::type difference_type; BidiIter const tmp = state.cur_; if(!detail::advance_to(state.cur_, -static_cast<difference_type>(this->width_), state.begin_)) { state.cur_ = tmp; return this->not_ ? next.match(state) : false; } // matching xpr could produce side-effects, save state memento<BidiIter> mem = save_sub_matches(state); if(this->not_) { // negative look-ahead assertions do not trigger partial matches. save_restore<bool> partial_match(state.found_partial_match_); detail::ignore_unused(partial_match); if(this->xpr_.match(state)) { restore_action_queue(mem, state); restore_sub_matches(mem, state); BOOST_ASSERT(state.cur_ == tmp); return false; } state.cur_ = tmp; restore_action_queue(mem, state); if(next.match(state)) { reclaim_sub_matches(mem, state, true); return true; } reclaim_sub_matches(mem, state, false); } else { if(!this->xpr_.match(state)) { state.cur_ = tmp; restore_action_queue(mem, state); reclaim_sub_matches(mem, state, false); return false; } BOOST_ASSERT(state.cur_ == tmp); restore_action_queue(mem, state); if(next.match(state)) { reclaim_sub_matches(mem, state, true); return true; } restore_sub_matches(mem, state); } BOOST_ASSERT(state.cur_ == tmp); return false; }
bool match_(match_state<BidiIter> &state, Next const &next, mpl::false_) const { BidiIter const tmp = state.cur_; // matching xpr could produce side-effects, save state memento<BidiIter> mem = save_sub_matches(state); if(this->not_) { // negative look-ahead assertions do not trigger partial matches. save_restore<bool> partial_match(state.found_partial_match_); detail::ignore_unused(partial_match); if(this->xpr_.match(state)) { restore_action_queue(mem, state); restore_sub_matches(mem, state); state.cur_ = tmp; return false; } restore_action_queue(mem, state); if(next.match(state)) { reclaim_sub_matches(mem, state, true); return true; } reclaim_sub_matches(mem, state, false); } else { if(!this->xpr_.match(state)) { restore_action_queue(mem, state); reclaim_sub_matches(mem, state, false); return false; } state.cur_ = tmp; restore_action_queue(mem, state); if(next.match(state)) { reclaim_sub_matches(mem, state, true); return true; } restore_sub_matches(mem, state); } BOOST_ASSERT(state.cur_ == tmp); return false; }
static void cmd_mirror() { char *text = trap->cmd_argv(1); if (partial_match("made a new MGX record", text)) { int c = trap->cmd_client(); cs_t *cs = trap->client_cs(c); sprintf(message, "[%s @ %s] %s", trap->get_level(c), cs_get(cs, CS_HOSTNAME), text); trap->irc_say(NULL, "%s\n", uncolor(message)); } if (query) { if (partial_match("No highscores found yet!", text)) { trap->irc_say(target, "%s\n", uncolor(text)); query = 0; } if (partial_match("Top 3 players on", text)) { char *result = uncolor(text); result = strchr(result, '\n') + 1; char *end = strchr(result, '\n'); if (end) *end = '\0'; trap->irc_say(target, "%s\n", result); query = 0; } } }
bool match_(match_state<BidiIter> &state, Next const &next, mpl::true_) const { BidiIter const tmp = state.cur_; if(this->not_) { // negative look-ahead assertions do not trigger partial matches. save_restore<bool> partial_match(state.found_partial_match_); detail::ignore_unused(partial_match); if(this->xpr_.match(state)) { state.cur_ = tmp; return false; } else if(next.match(state)) { return true; } } else { if(!this->xpr_.match(state)) { return false; } state.cur_ = tmp; if(next.match(state)) { return true; } } BOOST_ASSERT(state.cur_ == tmp); return false; }
bool telnet_console_connection::tabcomplete() { if (inputbuf.empty()) return false; parser_context ctx(inputbuf.c_str()); node *n; bool ro = false; std::string lasttent; int res = transform(&ctx, g_mrd, node::method, n, lasttent); if (ctx.current_column() != (int)inputbuf.size()) { node::content_type ctype; const char *cmatch; res = n->match_property(node::method, ctx.head().value.c_str(), ctype, cmatch); if (res == 1 && ctype == node::method && !strcmp(cmatch, "show")) { res = transform(&ctx, n, node::info_method, n, lasttent); ro = true; } } /* if not all buffer was consumed, we can't really complete */ if (ctx.current_column() != (int)inputbuf.size()) return false; if (res == END_LINE) { /* grunf */ if (!isspace(inputbuf[inputbuf.size()-1])) { inputbuf.resize(inputbuf.size() - lasttent.size()); inputbuf += n->name(); inputbuf += " "; } } else if (res == OK) { node::content_type ctype; const char *cmatch; res = n->match_property(node::child | (ro ? node::info_method : node::method), ctx.head().value.c_str(), ctype, cmatch); if (res == 0) { return false; } else if (res == 1) { int pos = ctx.current_column() - ctx.head().value.size(); /* if end-of-input */ if (ctx.eat() == 0) { inputbuf.resize(pos); inputbuf += cmatch; inputbuf += " "; } return true; } else { res = CONSISTENCY_ERROR; } } if (res == CONSISTENCY_ERROR) { std::string base; int count = 0; writeclient("\r\n"); for (node::properties::const_iterator i = n->get_properties().begin(); i != n->get_properties().end(); ++i) { if (i->second.is_child() || (i->second.is_method() && i->second.is_readonly() == ro)) { if (partial_match(lasttent.c_str(), i->first.c_str())) { _output.xprintf("%s ", i->first.c_str()); count++; if (base.empty()) base = i->first; else { int cn; int alen = base.size(), blen = i->first.size(); /* least common denominator */ for (cn = 0; cn < alen && cn < blen && base[cn] == i->first[cn]; cn++); if (cn < alen) base.resize(cn); } } } } if (count) { _output.newl(); if (!base.empty() && base != lasttent) { inputbuf.resize(inputbuf.size() - lasttent.size()); inputbuf += base; } } } return true; }