static inline int pf_print(t_modifier *m, t_array *d, va_list ap) { int ans; int i; char const *c = "diouxXcCsSpbn"; void *const t[] = {&pf_cv_di, &pf_cv_di, &pf_cv_o, &pf_cv_u, &pf_cv_x, &pf_cv_cx, &pf_cv_c, &pf_cv_wc, &pf_cv_s, &pf_cv_ws, &pf_cv_p, &pf_cv_b, &pf_cv_n}; ans = 0; if (m->length == 'l' && is_in(m->conversion, "cs") >= 0) m->conversion -= 32; if (is_in(m->conversion, "DOU") >= 0) { m->conversion += 32; m->length = 'l'; } i = 0; while (c[i] != '\0' && m->conversion != c[i]) i++; if (c[i] != '\0') ans += ((int (*)())t[i])(m, d, ap); return (ans); }
bool CUIWindow::AlignHintWndPos( Frect const& vis_rect, float border, float dx16pos ) //this = hint wnd { float const cursor_height = 43.0f; Fvector2 cursor_pos = GetUICursor()->GetCursorPosition(); if ( UI()->is_16_9_mode() ) { cursor_pos.x -= dx16pos; } if ( !vis_rect.in(cursor_pos) ) { return false; } Frect rect; rect.set( -border, -border, GetWidth() - 2.0f*border, GetHeight() - 2.0f*border ); rect.add( cursor_pos.x, cursor_pos.y ); rect.sub( 0.0f, rect.height() - border ); if ( !is_in( vis_rect, rect ) ) { rect.sub( rect.width() - border, 0.0f ); } if ( !is_in( vis_rect, rect ) ) { rect.add( 0.0f , rect.height() - border ); } if ( !is_in( vis_rect, rect ) ) { rect.add( rect.width() - border, cursor_height ); } float yn = rect.top - vis_rect.height() + rect.height( ) - border + cursor_height; if ( !is_in( vis_rect, rect ) ) { rect.sub( 0.0f , yn ); } if ( !is_in( vis_rect, rect ) ) { rect.sub( rect.width() - border, 0.0f ); } SetWndPos( rect.lt ); return true; }
int fehn2board (char str[]) { char *fstring; int z=0; int i=0; int j=0; int number=0; int PL=0; fstring = strtok(str, " "); fstring = strtok(NULL, " "); //read boardmap section. setup_board(0); printf("%s /%i\n",fstring, strlen(fstring)); for (z=0;z<strlen(fstring);z++) { number = fstring[z]-'0'; if (is_in(fstring[z],pieces[0],6)||is_in(fstring[z],pieces[1],6)) { board.squares[i][j] = fstring[z]; j++; } if (fstring[z]=='/') { i++; j=0; } if (0<number && number<9) j=j+number; } fstring = strtok(NULL, " "); //read active player section. //if (fstring == 'b') fstring = strtok(NULL, " "); //read castling righst section. for (i=0;i<2;i++) for (j=0;j<3;j++) { board.castle[i][j]=0; board.castle[i][1]=1; } for (z=0;z<strlen(fstring);z++) { if (fstring[z] == 'Q') board.castle[0][0]=1; if (fstring[z] == 'K') board.castle[0][1]=1; if (fstring[z] == 'q') board.castle[1][0]=1; if (fstring[z] == 'k') board.castle[1][1]=1; } return PL; }
// Finding an get_value() bool IntervallTree_bed::is_in(long position, Leaf * &p) { if (p == NULL) { return false; } else { long score = p->overlap(position); if (score > 0) { is_in(position, p->left); } else if (score < 0) { is_in(position, p->right); } else { return true; } } }
void sus(char *roomname, user_data *ud) { list subs_rooms = ud->subscribed_rooms; if (get_room(rooms, roomname) == NULL) { write(get_socket(ud), "Sorry, this room does not exist", MAX_PACK_SIZE); return; } if (is_in(get_room(rooms, roomname), subs_rooms)) { write(get_socket(ud), "You are already subscribed to this room", MAX_PACK_SIZE); return; } add_user(rooms, roomname, ud); add(subs_rooms, get_room(rooms, roomname)); char *buffer; if ((buffer = malloc(sizeof(char)*256)) == NULL) { perror("Malloc failed"); write(get_socket(ud), "You are now subscribed to the room!", 256); return; } memset(buffer, 0, 256); strcat(buffer, "You are now subscribed to the room '"); strcat(buffer, roomname); strcat(buffer,"'!"); write(get_socket(ud), buffer, 256); free(buffer); }
static short get_prio(char **cmd, int in, short i, short prio) { while ((*cmd)[++i]) { if (!(in = is_in((i > 0) ? (*cmd)[i - 1] : 0, (*cmd)[i], in)) && (*cmd)[i - 1] && (*cmd)[i - 1] != '\\') { if (is_double(*cmd, i, 1) && ((*cmd)[i] = ' ')) prio = (*cmd)[i++]; if (((*cmd)[i] == PIPE && (*cmd)[i + 1] == PIPE) || ((*cmd)[i] == '&' && (*cmd)[i + 1] == '&')) { i += 2; break ; } else if (((*cmd)[i] == PIPE)\ || ((*cmd)[i] == CHEVRON_R && (*cmd)[i + 1] != '&')\ || ((*cmd)[i] == CHEVRON_L && (*cmd)[i + 1] != '&')) { get_current_id_prio(prio != 0 ? CHEVRON_DOUBLE : (*cmd)[i]); break ; } } } (*cmd)[i] = '\0'; return (i + 1); }
static short get_total_node(char *cmd, int on, short i, short n_node) { short in; in = 0; while (cmd[++i]) { if (!(on = is_in((i > 1) ? cmd[i - 1] : 0, cmd[i], on))) if (i == 0 || (cmd[i - 1] && cmd[i - 1] != '\\')) { if (is_double(cmd, i, 2)) i++; if (cmd[i] == PIPE && cmd[i + 1] == PIPE) i++; if (cmd[i] == '&' && cmd[i + 1] == '&') n_node++; if (cmd[i] == PIPE || cmd[i] == CHEVRON_R \ || cmd[i] == CHEVRON_L) in = 0; else if (in == 0) { n_node++; in = 1; } } } return (n_node); }
ExprNode Parser::parse_identifier_(std::string const* fn_name, Function* fn) { auto id = lex_->identifier(); cur_tok_ = lex_->next(); if (cur_tok_ == '(') { cur_tok_ = lex_->next(); std::vector<ExprNode> fn_params; while (cur_tok_ != ')') { auto param = parse_expr_(fn_name, fn); fn_params.emplace_back(std::move(param)); if (cur_tok_ != ',' && cur_tok_ != ')') throw InvalidInput{"Ill-formed expression"}; if (cur_tok_ == ',') { cur_tok_ = lex_->next(); if (cur_tok_ == ')') throw InvalidInput{"Ill-formed expression"}; } } cur_tok_ = lex_->next(); auto fun_it = funs_.find(id); if (fn_name && fun_it != std::end(funs_) && *fn_name == id) throw InvalidInput{"Recursive function calls are not allowed"}; return std::make_unique<FunctionCallTree>(std::move(id), std::move(fn_params), funs_, vars_); } if (fn) { if (is_in(id, fn->param_names)) return std::make_unique<FunctionParamTree>(std::move(id), fn); } return std::make_unique<IdentifierTree>(std::move(id), vars_, funs_); }
int MainWindow::getRandomStep(QPoint p) { int m[MAX_SIZE][MAX_SIZE]; memcpy(m,map,sizeof(m)); QPoint p_a[4]; p_a[to_left] = QPoint(p.x() - 1, p.y()); p_a[to_right] = QPoint(p.x() + 1, p.y()); p_a[to_up] = QPoint(p.x(), p.y() - 1); p_a[to_down] = QPoint(p.x(), p.y() + 1); int p_l[4]; int i = 0; int p_mn = -1; int p_max = -1; for(; i < 4; i++) { if(is_in(p_a[i]) && m[p_a[i].x()][p_a[i].y()] == none) { p_l[i] = calcH(point(getHead().x(),getHead().y()), food_pos); if(p_l[i] > p_max) { p_max = p_l[i]; p_mn = i; } } } return p_mn; }
unsigned int BaseEntityParser::readNumber(bool hex) { const char* start = text.current; int length = 0; std::istringstream conversor; unsigned int number; // Default is to read decimal numbers std::string ALLOWED_CHARS = DIGITS; // base setup if ( hex ) { conversor >> std::hex; ALLOWED_CHARS = HEXDIGITS; } // Find the end of this number while ( (not text.eof()) && is_in(*text, ALLOWED_CHARS) ){ ++text; ++length; } // Empty number? if ( length == 0 ){ throw InvalidCharError("Invalid char while reading a number in " "a character reference."); } // Setup conversor with the value read; conversor.str( std::string(start, length) ); conversor >> number; // No error checking.. let's assume it works... return number; }
int parse_braces(t_cmds *cmd, int in, int quotee, int quotef) { int i; char *tmp; i = 0; while (cmd->cmd[i]) { if (in && cmd->cmd[(i > 1) ? i - 1 : 0] != '\\' && cmd->cmd[i] == in) in = 0; else if (!in && is_in(in, i, cmd)) in = cmd->cmd[i]; if (!in && cmd->cmd[(i > 1) ? i - 1 : 0] != '\\' && cmd->cmd[i] == '{') quotee++; else if (!in && quotee % 2 && cmd->cmd[(i > 1) ? i - 1 : 0] != '\\' && cmd->cmd[i] == '}') quotef++; i++; } if (quotee != quotef) { tmp = ft_strnew(1); tmp[0] = '\n'; ft_strcat(cmd->cmd, tmp); } return (quotee - quotef); }
void DetectWithOF5::Motion::hlp_make_of_brc(size_t idx, cv::Mat &x, cv::Mat &y) { assert(idx >= 0 && idx < dense_of_poss.size()); //assert(dense_of_poss.size() == desnse_of_xs.size()); //assert(dense_of_poss.size() == desnse_of_ys.size()); x = cv::Mat::zeros(cv::Size(brc.width, brc.height), CV_32F); y = cv::Mat::zeros(cv::Size(brc.width, brc.height), CV_32F); cv::Rect rc = dense_of_poss[idx]; if (!is_in(brc, rc)) { rc &= brc; if (rc.width == 0 || rc.height == 0) { //__asm int 3; } } rc.x -= brc.x; rc.y -= brc.y; cv::Mat t = x(rc); dense_of_xs[idx].copyTo(t); t = y(rc); dense_of_ys[idx].copyTo(t); }
void MainWindow::moveOne(QPoint p) { if(is_in(p) == false){ gameover(); return; } bool flag = false; if(map[p.x()][p.y()] == food) flag = true; map[p.x()][p.y()] = snake_body; que.push_back(QPoint(p.x(), p.y())); if(flag == false){ p = que.front(); map[p.x()][p.y()] = none; que.pop_front(); }else{ createfood(); } auto iter = que.begin() + 1; for(; iter != que.end(); ++iter) { map[iter -> x()][iter -> y()] = snake_body; } iter = que.end() - 1; map[iter -> x()][iter -> y()] = snake_head; iter = que.begin(); map[iter -> x()][iter -> y()] = snake_foot; }
void StructuredGrid::get_region(const Geometry& geometry, std::vector<int>& indices) const { indices.clear(); for (int i = 0; i < num_cells; ++i) { if (is_in(geometry,i)) { indices.push_back(i); } } }
void mapHM::set(string key, int value){ int hash_value = myhash(&*key.begin(), key.length(), size_of_table); if (!(is_in(key))){ Pairs p; p.setPairs(key, value); arrayOfPairs[hash_value].add(p); } }
int check(Point p1,Point p2,Point p3,Point p4,Point start,Point end) { if(is_in(p1,p3,start,end)) return 1; return intersect(p1,p2,start,end) || intersect(p2,p3,start,end) || intersect(p3,p4,start,end) || intersect(p4,p1,start,end); }
ExprNode Parser::parse_unary_(std::string const* fn_name, Function* fn) { if (!is_in(cur_tok_, unary_operators)) return parse_top_(fn_name, fn); auto un_op = cur_tok_; cur_tok_ = lex_->next(); return std::make_unique<UnaryExprTree>(un_op, parse_unary_(fn_name, fn)); }
int range_match(char *str1, char *str2) { char *range; int end; end = 0; while (str2[end] && (str2[end] != CLOSE_BRACKET)) end++; if (!str2[end]) return (0); range = char_list(str2, end); if (is_in(range, *str1)) { xsfree(range); return (match(str1 + 1, is_in(str2, CLOSE_BRACKET) + 1)); } xsfree(range); return (0); }
void parser_base::skip_to_or_blank(const char*&p, size_t& len, const char* chars) { p = mp_char; len = 0; for (; has_char(); next(), ++len) { if (is_blank(*mp_char) || is_in(*mp_char, chars)) return; } }
// check if circle c is within the polygon. // INVALID if the polygon is not convex. bool is_in(const circle& c){ if(!is_in(c.c)) return false; _vertices[_num_vertices] = _vertices[0]; for(int i=0; i<_num_vertices; ++i){ if(lt(distance_p2l(c.c, _vertices[i], _vertices[i+1]), c.r)){ return false; } } return true; }
/** * Release a segment by putting it on the list of "freed" segments. We keep the * memory instead of deallocating it each time, so that's it's fast to "allocate" * a new segment next time. * * Assumes outSynapses has already been updated. * TODO: a call to releaseSegment should delete any pending * update for that segment in the update list. The * cheapest way to do this is to maintain segment updates on a * per cell basis. Currently there is a check in * Cells4::adaptSegment for this case but that may be insufficient. */ void releaseSegment(UInt segIdx) { NTA_ASSERT(segIdx < _segments.size()); // TODO: check this if (is_in(segIdx, _freeSegments)) { return; } // TODO: check this NTA_ASSERT(not_in(segIdx, _freeSegments)); _segments[segIdx].clear(); // important in case we push_back later _freeSegments.push_back(segIdx); _segments[segIdx]._totalActivations = 0; _segments[segIdx]._positiveActivations = 0; NTA_ASSERT(_segments[segIdx].empty()); NTA_ASSERT(is_in(segIdx, _freeSegments)); }
void Space::object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl) { assert(!mr.is_empty(), "Should be non-empty"); // We use MemRegion(bottom(), end()) rather than used_region() below // because the two are not necessarily equal for some kinds of // spaces, in particular, certain kinds of free list spaces. // We could use the more complicated but more precise: // MemRegion(used_region().start(), round_to(used_region().end(), CardSize)) // but the slight imprecision seems acceptable in the assertion check. assert(MemRegion(bottom(), end()).contains(mr), "Should be within used space"); HeapWord* prev = cl->previous(); // max address from last time if (prev >= mr.end()) { // nothing to do return; } // This assert will not work when we go from cms space to perm // space, and use same closure. Easy fix deferred for later. XXX YSR // assert(prev == NULL || contains(prev), "Should be within space"); bool last_was_obj_array = false; HeapWord *blk_start_addr, *region_start_addr; if (prev > mr.start()) { region_start_addr = prev; blk_start_addr = prev; // The previous invocation may have pushed "prev" beyond the // last allocated block yet there may be still be blocks // in this region due to a particular coalescing policy. // Relax the assertion so that the case where the unallocated // block is maintained and "prev" is beyond the unallocated // block does not cause the assertion to fire. assert((BlockOffsetArrayUseUnallocatedBlock && (!is_in(prev))) || (blk_start_addr == block_start(region_start_addr)), "invariant"); } else { region_start_addr = mr.start(); blk_start_addr = block_start(region_start_addr); } HeapWord* region_end_addr = mr.end(); MemRegion derived_mr(region_start_addr, region_end_addr); while (blk_start_addr < region_end_addr) { const size_t size = block_size(blk_start_addr); if (block_is_obj(blk_start_addr)) { last_was_obj_array = cl->do_object_bm(oop(blk_start_addr), derived_mr); } else { last_was_obj_array = false; } blk_start_addr += size; } if (!last_was_obj_array) { assert((bottom() <= blk_start_addr) && (blk_start_addr <= end()), "Should be within (closed) used space"); assert(blk_start_addr > prev, "Invariant"); cl->set_previous(blk_start_addr); // min address for next time } }
int brace_parse(char **string, t_cmd *cmd, int iarg, t_vector *new_args) { if (is_in(string[0], OPEN_BRACE)) { new_args = find_all_pattern(string); vector_rev(new_args); add_files_to_arg_tab(cmd, iarg, new_args); vector_free(new_args); return (1); } return (0); }
int my_is_num(char *str) { int i; i = 0; while (str[i] != '\0') { if ( ! is_in(str[i], "0123456789+-")) return (0); i++; } return (1); }
void term(){ if(look == '*'){ match("*"); term(); emitln("xor ebx, ebx"); settype(reduceptr(current_type)); STRSWITCH(current_type) STRCASE("short") emitln("mov bx, word [eax]"); STRCASE("char") emitln("mov bl, byte [eax]"); STRDEFAULT emitln("mov ebx, dword [eax]"); STRSWITCHEND emitln("xchg eax, ebx"); } else if(look == '('){ match("("); emitln("push eax"); expression(); match(")"); } else if(look == '"'){ emitln("mov eax, %s", add_string(getstring('"'))); current_type = "char*"; } else if(look == '\''){ match("'"); emitln("mov eax, %d", look); getcharacter(); match("'"); current_type = "char"; } else if(is_in(dynstring("%c", look), "+", "-", NULL)){ emitln("push dword 0"); operator(); } else if(isalpha(look)){ identifier(); } else if(isdigit(look)){ emitln("mov eax, %s", getnumber()); } else expected("Number or variable"); }
static inline const char *pf_match(char const *s, t_modifier *m) { int n; while (*s != '\0') { if (*s == '.') s = pf_update_value(s + 1, &(m->precision)) - 1; else if ('1' <= *s && *s <= '9') s = pf_update_value(s, &(m->size)) - 1; else if ((n = is_in(*s, "0+- #")) >= 0) m->booleans.t[n] = 1; else if (is_in(*s, FTPF_LM) >= 0) pf_set_length(*s, &(m->length)); else if (is_in(*s, FTPF_CV) >= 0 && (m->conversion = *s)) return (s + 1); else break ; s++; } return (s); }
/* 合法手かどうかの判定 */ int is_legal_move(const int side, const XY sq) { assert(is_in(sq.x, sq.y)); int i; if (board[sq.x][sq.y] != 0)// すでにおいてある時は置けない return FALSE; for (i = 0; i < 8; i++) { if (can_flip(side, sq, directions[i]))// ひっくり返せるなら return TRUE; } return FALSE; // 置けない }
/* return a token from the input stream */ void get_token(void) { char *p; p = token; /* skip spaces */ while (*p_pos == ' ') p_pos++; if (*p_pos == '\0') { /*is end of input*/ *p++ = '\0'; return; } if (is_in(*p_pos, ".!?")) { *p = *p_pos; p++, p_pos++; *p = '\0'; return; } /*read word until*/ while (*p_pos != ' ' && !is_in(*p_pos, ".,;?!")&&*p_pos) { *p = tolower(*p_pos++); p++; } *p = '\0'; }
int main (int argc, char **argv) { unsigned int i, newline = 1, as_int = 0, as_double = 0; char *arg, *opt, *nl, *yesnl = "\n", *nonl = ""; for (i=1; i<argc; i++) { arg = argv[i]; if (!starts_with(arg,"-")) die("Unknown argument %s\n",arg); opt = arg; while (*opt && opt[0] == '-') opt++; if (is_in(opt,"int","i",(char*)NULL)) { as_int = 1; } else if (is_in(opt,"double","d",(char*)NULL)) { as_double = 1; } else if (is_in(opt,"b","bare","nonl","no-newline",(char*)NULL)) { newline = 0; } else { die("Unknown option %s\n",opt); } } nl = newline ? yesnl : nonl; if (!as_int) as_double++; if (as_double) printf("%f%s",NOW(),nl); if (as_int) printf("%.0f%s",NOW(),nl); return 0; }
int my_is_alphanum(char *str) { int i; char *data; data = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-"; i = 0; while (str[i] != '\0') { if ( ! is_in(str[i], data)) return (0); i++; } return (1); }