void find_target() { clear_screen(); print_string("Targg"); motor_spin_left(); left_count = 0; while (get_range() > MAX_RANGE && left_count < 5 * NINETY_DEGREES) { clear_screen(); print_num(get_range()); _delay_ms(20); } motor_stop(); if (left_count >= 5 * NINETY_DEGREES) { motor_forward(); left_count = 0; while (left_count < 90); motor_stop(); } else { motor_spin_right(); _delay_ms(20); motor_stop(); state = &attack; } }
static void map_cmd(const char **s) { if ( **s == '*' ) { range_from = 32; range_to = 255; map_to = 32; is_exclude = 0; (*s)++; skip_space(s); } else if ( **s == '~' ) { is_exclude = 1; map_to = 0; /*will be ignored */ (*s)++; skip_space(s); get_range(s); } else { is_exclude = 0; get_range(s); map_to = range_from; if ( **s == '>') { (*s)++; skip_space(s); map_to = get_add(s); } } }
void progress_indicator_subindicator::refresh() { stream_size_type val = get_current(); if (val > get_range()) val = get_range(); if (get_range() == 0) return; stream_size_type value= val* m_outerRange / get_range(); if (m_parent) { m_parent->raw_step(value - m_oldValue); m_oldValue = value; } }
int main() { get_range(0,5); get_range(5,0); get_range2(0,5); get_range2(5,0); range_divisible_by(0,10,2); median(10, 100, 50); char string[] = "HELLO"; print_backwards(string); return 0; }
void worksheet::merge_cells(const range_reference &reference) { d_->merged_cells_.push_back(reference); bool first = true; for (auto row : get_range(reference)) { for (auto cell : row) { cell.set_merged(true); if (!first) { if (cell.get_data_type() == cell::type::string) { cell.set_value(""); } else { cell.clear_value(); } } first = false; } } }
char *get_options(const char *str, int nints, int *ints) { int res, i = 1; while (i < nints) { res = get_option((char **)&str, ints + i); if (res == 0) break; if (res == 3) { int range_nums; range_nums = get_range((char **)&str, ints + i, nints - i); if (range_nums < 0) break; /* * Decrement the result by one to leave out the * last number in the range. The next iteration * will handle the upper number in the range */ i += (range_nums - 1); } i++; if (res == 1) break; } ints[0] = i - 1; return (char *)str; }
cmpl disp_table_n_value (const disp_t *disp, double lam) { const struct disp_table *table = & disp->disp.table; int ni, nb; double lami; cmpl a, b, n; double lmin, lmax; double dlam; get_range (table, &lmin, &lmax, &nb); dlam = (lmax - lmin) / (nb - 1); ni = (int) ((lam - lmin) / dlam); ni = (ni < 0 ? 0 : (ni >= nb-1 ? nb-2 : ni)); lami = lmin + ni * dlam; a = get_value_at_index (table, ni); b = get_value_at_index (table, ni+1); n = a + (b - a) * (lam - lami) / dlam; return n; }
/* * where <seg-name> [<offset>[kmgp] <length>[kmgp]] - show node location * of specified range of segment. * * NOTE: if neither <offset> nor <length> specified, <offset> defaults * to 0 [start of segment], as usual, and length defaults to 64 pages * rather than the entire segment. Suitable for a "quick look" at where * segment resides. */ static int where_seg(char *args) { glctx_t *gcp = &glctx; char *segname, *nextarg; range_t range = { 0L, 0L }; int ret; if (!numa_supported()) return CMD_ERROR; args += strspn(args, whitespace); if (!required_arg(args, "<seg-name>")) return CMD_ERROR; segname = strtok_r(args, whitespace, &nextarg); args = nextarg + strspn(nextarg, whitespace); /* * offset, length are optional */ if (get_range(args, &range, &nextarg) == CMD_ERROR) return CMD_ERROR; if (args == nextarg) range.length = 64 * gcp->pagesize; /* default length */ if (!segment_location(segname, &range)) return CMD_ERROR; return CMD_SUCCESS; }
/* * touch_seg: <seg-name> [<offset> <length>] [read|write] */ static int touch_seg(char *args) { glctx_t *gcp = &glctx; char *segname, *nextarg; range_t range = { 0L, 0L }; int axcs; args += strspn(args, whitespace); if (!required_arg(args, "<seg-name>")) return CMD_ERROR; segname = strtok_r(args, whitespace, &nextarg); args = nextarg + strspn(nextarg, whitespace); /* * offset, length are optional */ if (get_range(args, &range, &nextarg) == CMD_ERROR) return CMD_ERROR; args = nextarg; axcs = get_access(args); if (axcs == 0) return CMD_ERROR; if (!segment_touch(segname, &range, axcs - 1)) return CMD_ERROR; return CMD_SUCCESS; }
int main ( int argc, char** argv ) { mi::VolumeInfo info ( mi::Point3i (128, 128, 128) , mi::Point3d ( 0.4, 0.4, 1) ); const mi::Point3i p0 (3, 0, 0); const mi::Point3i p1 (0, 3, 0); const double r = 10; // range mi::Range range; get_range( info, p0, p1, r, range); std::cerr<<range.getMin().transpose()<<" " <<range.getMax().transpose()<<std::endl; double d = 1; for ( auto&& p : info ) { if ( range.isValid(p)) continue; const double dist0 = info.getLength(p0-p); const double dist1 = info.getLength(p1-p); double dist = dist0 + dist1; if ( dist < r ) { std::cerr<<"error "<<dist0<<" "<<dist1<<" "<<p.transpose()<<" "<<dist<<std::endl; return -1; } } std::cerr<<"ok"<<std::endl; return 0; }
utree operator()(A0 const& _0, A1 const& _1) const { boost::array<utree, 2> elements; elements[0] = _0; elements[1] = _1; return derived().eval(get_range(elements)); }
int get_list(bitstr_t *bits, int low, int high, const char **names, const char **pp) { /* clear the bit string, since the default is 'off'. */ bit_nclear(bits, 0, (high-low+1)); /* list = range {"," range} */ /* process all ranges */ while(1) { if(get_range(bits, low, high, names, pp) == ERR) return ERR; if(**pp == ',') ++(*pp); else break; } /* exiting. skip to some blanks, then skip over the blanks. */ while(**pp != 0 && !isspace(**pp)) ++(*pp); while(isspace(**pp)) ++(*pp); return OK; }
bool check(R r1) const { range_type r2 = get_range(); for ( ;r1 && r2 && *r1==*r2; ++r1, ++r2 ); return !r1 && !r2; }
tree texmacs_invarianted (tree t, tree p, int c, string src, hashmap<tree,tree> corr, hashmap<tree,tree> pred, hashmap<tree,tree> succ) { if (corr->contains (t)) { tree oids= corr[t], ids (TUPLE); for (int i=0; i<N(oids); i++) { int b, e; if (get_range (oids[i], b, e, src)) ids << oids[i]; } if (N(ids) >= 1) { tree id= texmacs_best_match (ids, p, c, corr, pred, succ); if (id != tree (UNINIT)) return compound ("ilx", id); } } if (is_atomic (t)) return t; else { int i, n= N(t); tree r (t, n); for (i=0; i<n; i++) r[i]= texmacs_invarianted (t[i], t, i, src, corr, pred, succ); return r; } }
static int init(const struct motion_sensor_t *s) { int ret = 0, tmp; ret = raw_read8(s->addr, LSM6DS0_WHO_AM_I_REG, &tmp); if (ret) return EC_ERROR_UNKNOWN; if (tmp != LSM6DS0_WHO_AM_I) return EC_ERROR_ACCESS_DENIED; /* * This sensor can be powered through an EC reboot, so the state of * the sensor is unknown here. Initiate software reset to restore * sensor to default. * [6] BDU Enable Block Data Update. * [0] SW_RESET software reset * * lsm6ds0 supports both accel & gyro features * Board will see two virtual sensor devices: accel & gyro. * Requirement: Accel need be init before gyro. * SW_RESET is down for accel only! */ if (MOTIONSENSE_TYPE_ACCEL == s->type) { mutex_lock(s->mutex); ret = raw_read8(s->addr, LSM6DS0_CTRL_REG8, &tmp); if (ret) { mutex_unlock(s->mutex); return EC_ERROR_UNKNOWN; } tmp |= (1 | LSM6DS0_BDU_ENABLE); ret = raw_write8(s->addr, LSM6DS0_CTRL_REG8, tmp); mutex_unlock(s->mutex); if (ret) return EC_ERROR_UNKNOWN; /* Power Down Gyro */ ret = raw_write8(s->addr, LSM6DS0_CTRL_REG1_G, 0x0); if (ret) return EC_ERROR_UNKNOWN; ret = set_range(s, s->default_range, 1); if (ret) return EC_ERROR_UNKNOWN; } if (MOTIONSENSE_TYPE_GYRO == s->type) { /* Config GYRO Range */ ret = set_range(s, s->default_range, 1); if (ret) return EC_ERROR_UNKNOWN; } CPRINTF("[%T %s: MS Done Init type:0x%X range:%d]\n", s->name, s->type, get_range(s)); return ret; }
static int init(const struct motion_sensor_t *s) { int ret, resol; struct si114x_drv_data_t *data = SI114X_GET_DATA(s); /* initialize only once: light must be declared first. */ if (s->type == MOTIONSENSE_TYPE_LIGHT) { #ifdef CONFIG_ALS_SI114X_CHECK_REVISION ret = si114x_revisions(s); if (ret != EC_SUCCESS) return ret; #endif ret = si114x_initialize(s); if (ret != EC_SUCCESS) return ret; data->state = SI114X_IDLE; resol = 7; } else { if (data->state == SI114X_NOT_READY) return EC_ERROR_ACCESS_DENIED; resol = 5; } set_range(s, s->default_range, 0); /* * Sensor is most likely behind a glass. * Max out the gain to get correct measurement */ set_resolution(s, resol, 0); CPRINTF("[%T %s: MS Done Init type:0x%X range:%d]\n", s->name, s->type, get_range(s)); return EC_SUCCESS; }
/* * file_seg: <path-name> [<offset>[kmgp] <length>[kmgp] [private|shared]] */ static int file_seg(char *args) { glctx_t *gcp = &glctx; char *pathname, *nextarg; range_t range = { 0L, 0L }; int segflag = MAP_PRIVATE; args += strspn(args, whitespace); if (!required_arg(args, "<path-name>")) return CMD_ERROR; pathname = strtok_r(args, whitespace, &nextarg); args = nextarg + strspn(nextarg, whitespace); /* * offset, length are optional */ if (get_range(args, &range, &nextarg) == CMD_ERROR) return CMD_ERROR; args = nextarg; if (*args != '\0') { segflag = get_shared(args); if (segflag == -1) return CMD_ERROR; } if (!segment_register(SEGT_FILE, pathname, &range, segflag)) return CMD_ERROR; return CMD_SUCCESS; }
void TerrainObject::place_unchecked(std::shared_ptr<Terrain> t, coord::phys3 &position) { // storing the position: this->pos = get_range(position); this->terrain = t; this->occupied_chunk_count = 0; bool chunk_known = false; // set pointers to this object on each terrain tile // where the building will stand and block the ground for (coord::tile temp_pos : tile_list(this->pos)) { TerrainChunk *chunk = this->get_terrain()->get_chunk(temp_pos); if (chunk == nullptr) { continue; } for (int c = 0; c < this->occupied_chunk_count; c++) { if (this->occupied_chunk[c] == chunk) { chunk_known = true; } } if (not chunk_known) { this->occupied_chunk[this->occupied_chunk_count] = chunk; this->occupied_chunk_count += 1; } else { chunk_known = false; } int tile_pos = chunk->tile_position_neigh(temp_pos); chunk->get_data(tile_pos)->obj.push_back(this); } }
static idn_result_t read_file(const char *file, FILE *fp, idn_ucsset_t set) { char line[256]; idn_result_t r; int lineno = 0; while (fgets(line, sizeof(line), fp) != NULL) { char *p = line; unsigned long ucs1, ucs2; lineno++; while (isspace((unsigned char)*p)) p++; if (*p == '\0' || *p == '#') continue; #ifdef SUPPORT_VERSIONING /* Skip version tag. */ if (lineno == 1 && strncmp("version=", line, 8) == 0) continue; #endif if (!get_range(p, &ucs1, &ucs2)) { WARNING(("syntax error in file \"%-.100s\" line %d: " "%-.100s", file, lineno, line)); return (idn_invalid_syntax); } if ((r = idn_ucsset_addrange(set, ucs1, ucs2)) != idn_success) return (r); } return (idn_success); }
void ScintillaEditor::unindentSelection() { int lineFrom, lineTo; get_range(&lineFrom, &lineTo); for (int line = lineFrom;line <= lineTo;line++) { qsci->unindent(line); } }
void ScintillaEditor::commentSelection() { int lineFrom, lineTo; get_range(&lineFrom, &lineTo); for (int line = lineFrom;line <= lineTo;line++) { qsci->insertAt("//", line, 0); } }
range worksheet::operator[](const std::string &name) { if (has_named_range(name)) { return get_named_range(name); } return get_range(range_reference(name)); }
/*===========================================================================* * action_pre_error * *===========================================================================*/ static void action_pre_error(struct fbd_rule *rule, iovec_t *iov, unsigned *count, size_t *size, u64_t *pos) { /* Limit the request to the part that precedes the matched range. */ *size = get_range(rule, *pos, size, NULL); limit_range(iov, count, *size); }
t_stat sim_load(FILE *fileref, CONST char *cptr, CONST char *fname, int flag) { t_addr lo, hi; if (flag == 0) return SCPE_ARG; /* * We want to write the memory in some device-dependent format. sim_switches * contains the command switches which will be used to determine the * format: * * -p Paper tape format * * Command syntax is: * * dump <file> -p <loaddr>-<hiaddr> */ if ((sim_switches & SWMASK('P')) != 0) { const char *tptr; t_addr addr; int temp, count = 0; tptr = get_range(NULL, cptr, &lo, &hi, cpu_dev.aradix, cpu_unit.capac - 1, 0); if (tptr != NULL) { /* * Output a couple of NULL frames to start the dump */ fputc(0, fileref); fputc(0, fileref); for (addr = lo; addr <= hi; addr++) { temp = M[addr]; /* * If the data is 0, map it to -0 (0xFFFF) since 0 terminates the * sequence. We also count the number of times this happens and * report it at the end. */ if (temp == 0) { temp =0xFFFF; count++; } fputc((temp >> 8) & 0xFF, fileref); fputc(temp & 0xFF, fileref); } /* * Terminate the dump with 2 more NULL frames */ fputc(0, fileref); fputc(0, fileref); if (count != 0) printf("%d zero word translated to 0xFFFF\n", count); return SCPE_OK; } }
/* * mbind <seg-name> [<offset>[kmgp] <length>[kmgp]] <policy> <node-list> */ static int mbind_seg(char *args) { glctx_t *gcp = &glctx; char *segname, *nextarg; range_t range = { 0L, 0L }; nodemask_t *nodemask = NULL; int policy, flags = 0; int ret; if (!numa_supported()) return CMD_ERROR; args += strspn(args, whitespace); if (!required_arg(args, "<seg-name>")) return CMD_ERROR; segname = strtok_r(args, whitespace, &nextarg); args = nextarg + strspn(nextarg, whitespace); /* * offset, length are optional */ if (get_range(args, &range, &nextarg) == CMD_ERROR) return CMD_ERROR; args = nextarg; if (!required_arg(args, "<policy>")) return CMD_ERROR; policy = get_mbind_policy(args, &nextarg); if (policy < 0) return CMD_ERROR; args = nextarg + strspn(nextarg, whitespace); if (*args == '+') { flags = get_mbind_flags(++args, &nextarg); if (flags == -1) return CMD_ERROR; } args = nextarg + strspn(nextarg, whitespace); if (policy != MPOL_DEFAULT) { if (!required_arg(args, "<node/list>")) return CMD_ERROR; nodemask = get_nodemask(args); if (nodemask == NULL) return CMD_ERROR; } ret = CMD_SUCCESS; #if 1 // for testing if (!segment_mbind(segname, &range, policy, nodemask, flags)) ret = CMD_ERROR; #endif if (nodemask != NULL) free(nodemask); return ret; }
range worksheet::get_named_range(const std::string &name) { if (!has_named_range(name)) { throw named_range_exception(); } return get_range(d_->named_ranges_[name].get_targets()[0].second); }
static int new_pref(lua_State* L, pref_type_t type) { const gchar* label = luaL_optstring(L,1,NULL); const gchar* descr = luaL_optstring(L,3,""); Pref pref = (wslua_pref_t *)g_malloc(sizeof(wslua_pref_t)); pref->name = NULL; pref->label = label ? g_strdup(label) : NULL; pref->desc = g_strdup(descr); pref->type = type; pref->next = NULL; pref->proto = NULL; switch(type) { case PREF_BOOL: { gboolean def = wslua_toboolean(L,2); pref->value.b = def; break; } case PREF_UINT: { guint32 def = wslua_optgint32(L,2,0); pref->value.u = def; break; } case PREF_STRING: { gchar* def = g_strdup(luaL_optstring(L,2,"")); pref->value.s = def; break; } case PREF_ENUM: { guint32 def = wslua_optgint32(L,2,0); enum_val_t *enum_val = get_enum(L,4); gboolean radio = wslua_toboolean(L,5); pref->value.e = def; pref->info.enum_info.enumvals = enum_val; pref->info.enum_info.radio_buttons = radio; break; } case PREF_RANGE: { range_t *range = get_range(L,2,4); guint32 max = wslua_optgint32(L,4,0); pref->value.r = range; pref->info.max_value = max; break; } case PREF_STATIC_TEXT: { /* This is just a static text. */ break; } default: g_assert_not_reached(); break; } pushPref(L,pref); return 1; }
SLVAL sl_make_range_exclusive(sl_vm_t* vm, SLVAL lower, SLVAL upper) { SLVAL rangev = sl_allocate(vm, vm->lib.Range); sl_range_t* range = get_range(vm, rangev); range->left = lower; range->right = upper; range->exclusive = 1; return rangev; }
ContainerOut tails(const ContainerIn& xs) { ContainerOut result; std::size_t xs_size = size_of_cont(xs); internal::prepare_container(result, xs_size + 1); auto it_out = internal::get_back_inserter(result); for (std::size_t i = 0; i <= xs_size; ++i) *it_out = get_range(i, xs_size, xs); return result; }
/* ATTAQUE */ int create_action(t_engine *e, t_entity *t, t_entity *attaked) { int id; s_do_action *a; char *w; // int pop; // pop = 0; // if (t->action == ACTION_MOVE) // { // // raccourci le chemin // finish_move(e, t); // pop = 1; // // rajoute l'action dans la queue // } // else if (t->action != ACTION_NONE) reset_actions(e, t); if (!attack_is_valid(e, t, attaked)) return (-1); w = get_weapon(e, t, attaked); if (!w) return (-1); printf("ATTACKKKKKEE :p\n");fflush(stdout); // if (!pop) // { t->action = ACTION_ATTACK; fw_send_action(e, t); // } id = e->id_action++; a = (s_do_action*)xmalloc(sizeof(*a)); a->id = id; a->tag = ACTION_ATTACK; a->entity = t; a->entity->action_fail = 0; t->direction = get_direction(t->direction, &(t->pos), &(attaked->pos)); fw_send_dir(e, a->entity); a->attaked = attaked; a->cpt_time = 0; a->range = get_range(e, t, w); a->damages = get_damages(e, t, w); // <-- a revoir plus tard a->time_take = get_rof(e, t, w); // <-- a revoir plus tard // if (pop) // { // pop_action(e, t, a); // printf("\t\t\t\t\t\tje pop :)\n");fflush(stdout); // } // else // { a->next = e->actions; e->actions = a; // } fflush(stderr); return (id); }