//config file processing int rpc::read_config(std::string sparams) { sconfig=sparams; std::replace( sparams.begin(), sparams.end(),';', '\n' ); std::istrstream fconfig(sparams.c_str()); //assure(fconfig,fname_config.c_str()); char buf[200]; while (fconfig.getline(buf,200)) { std::string nstr(buf); if ((nstr.size()>0) and (nstr.at(0)!='/')) { int ind1=nstr.find('='); int ind2=nstr.length()-1; std::string pname=nstr.substr(0,ind1); std::string pvalue=nstr.substr(ind1+1,ind2-ind1-2); std::string ptype=nstr.substr(ind2); if (ptype.length()>0){ switch (ptype.at(0)){ case 'd':case 'f': set_param(pname,atof(pvalue.c_str())); break; case 'c': set_param(pname,pvalue.at(0)); break; case 'i': set_param(pname,atoi(pvalue.c_str())); break; case 's': set_param(pname,pvalue); break; };}; }; }; return 0; }
/** * Constructs a WORHP algorithm */ worhp::worhp(int iter, double feas, double opt, bool screen_output) { // We construct the map between parameters and integers used to set and get them define_param_map(); // We set the screen output member from algorithm::base set_screen_output(screen_output); // We deactivate WORHP keyboard handler as it does introduce funny problems setenv("WORHP_DISABLE_KEYBOARD_HANDLER", "1", 0); // We deal with screen output (this is buggy in lworhp 1.8.0, hopefully future releases can fix the problem // and we will be able to restore the screen output upon request if (m_screen_output) { SetWorhpPrint(default_output); } else { SetWorhpPrint(no_screen_output); } // We read the algorithm parameters from the xml file, if this is not found // we set default values and ignore the issue. int status; m_params.initialised = false; ReadParams(&status, const_cast<char*>("param.xml"), &m_params); status = OK; m_params.MatrixCC = false; // Not sure what this deas exactly // We set some of the parameters exposed in the constructor set_param("TolFeas", feas); set_param("TolOpti", opt); set_param("MaxIter", iter); }
int set_param_option(char *option) { Str tmp = Strnew(); char *p = option, *q; while (*p && !IS_SPACE(*p) && *p != '=') Strcat_char(tmp, *p++); while (*p && IS_SPACE(*p)) p++; if (*p == '=') { p++; while (*p && IS_SPACE(*p)) p++; } Strlower(tmp); if (set_param(tmp->ptr, p)) goto option_assigned; q = tmp->ptr; if (!strncmp(q, "no", 2)) { /* -o noxxx, -o no-xxx, -o no_xxx */ q += 2; if (*q == '-' || *q == '_') q++; } else if (tmp->ptr[0] == '-') /* -o -xxx */ q++; else return 0; if (set_param(q, "0")) goto option_assigned; return 0; option_assigned: return 1; }
void checkAndPushRanges(CamData& cd, string param_name, dc1394feature_t feature) { uint32_t min; uint32_t max; cd.cam->getFeatureBoundaries(feature, min, max); set_param(cd.name + string("/") + param_name + string("_min"), (int)(min)); set_param(cd.name + string("/") + param_name + string("_max"), (int)(max)); }
static void test_param_int(CuTest * tc) { struct param *par = 0; test_cleanup(); CuAssertIntEquals(tc, 13, get_param_int(par, "foo", 13)); set_param(&par, "foo", "23"); set_param(&par, "bar", "42"); CuAssertIntEquals(tc, 23, get_param_int(par, "foo", 0)); CuAssertIntEquals(tc, 42, get_param_int(par, "bar", 0)); }
static void test_param_flt(CuTest * tc) { struct param *par = 0; test_cleanup(); CuAssertDblEquals(tc, 13, get_param_flt(par, "foo", 13), 0.01); set_param(&par, "foo", "23.0"); set_param(&par, "bar", "42.0"); CuAssertDblEquals(tc, 23.0, get_param_flt(par, "foo", 0.0), 0.01); CuAssertDblEquals(tc, 42.0, get_param_flt(par, "bar", 0.0), 0.01); }
static void test_get_set_param(CuTest * tc) { struct param *par = 0; test_cleanup(); CuAssertStrEquals(tc, 0, get_param(par, "foo")); set_param(&par, "foo", "bar"); set_param(&par, "bar", "foo"); CuAssertStrEquals(tc, "bar", get_param(par, "foo")); CuAssertStrEquals(tc, "foo", get_param(par, "bar")); }
void eq_value_changed (DdbEqualizer *widget) { ddb_dsp_context_t *eq = get_supereq (); if (eq) { for (int i = 0; i < 18; i++) { set_param (eq, i+1, ddb_equalizer_get_band (widget, i)); } set_param (eq, 0, ddb_equalizer_get_preamp (widget)); deadbeef->streamer_dsp_chain_save (); } }
static void test_unit_limit(CuTest * tc) { set_param(&global.parameters, "rules.limit.faction", "250"); CuAssertIntEquals(tc, 250, rule_faction_limit()); set_param(&global.parameters, "rules.limit.faction", "200"); CuAssertIntEquals(tc, 200, rule_faction_limit()); set_param(&global.parameters, "rules.limit.alliance", "250"); CuAssertIntEquals(tc, 250, rule_alliance_limit()); }
void LCD_init() { int i; for (i = 0; i < 50*1000*15; i++); // wait 15msec set_param(3); for (i = 0; i < 50*1000*5; i++); // wait 5msec set_param(3); for (i = 0; i < 50*1000*1; i++); // wait 1msec set_param(3); for (i = 0; i < 50*1000*1; i++); // wait 1msec set_param(2); for (i = 0; i < 50*1000*1; i++); // wait 1msec }
static void test_cannot_create_unit_above_limit(CuTest * tc) { faction *f; test_cleanup(); test_create_world(); f = test_create_faction(rc_find("human")); set_param(&global.parameters, "rules.limit.faction", "4"); CuAssertIntEquals(tc, 0, checkunitnumber(f, 4)); CuAssertIntEquals(tc, 2, checkunitnumber(f, 5)); set_param(&global.parameters, "rules.limit.alliance", "3"); CuAssertIntEquals(tc, 0, checkunitnumber(f, 3)); CuAssertIntEquals(tc, 1, checkunitnumber(f, 4)); }
void test_upkeep_hunger_damage(CuTest * tc) { region *r; unit *u1; faction *f1; const item_type *i_silver; test_cleanup(); test_create_world(); i_silver = it_find("money"); assert(i_silver); r = findregion(0, 0); f1 = test_create_faction(test_create_race("human")); u1 = test_create_unit(f1, r); assert(r && u1); set_param(&global.parameters, "rules.food.flags", "0"); u1->hp = 100; get_food(r); // since u1 and u2 are not allied, u1 should not help u2 with upkeep CuAssertTrue(tc, u1->hp < 100); test_cleanup(); }
void test_upkeep_from_pool(CuTest * tc) { region *r; unit *u1, *u2; const item_type *i_silver; test_cleanup(); test_create_world(); i_silver = it_find("money"); assert(i_silver); r = findregion(0, 0); u1 = test_create_unit(test_create_faction(test_create_race("human")), r); assert(u1); u2 = test_create_unit(u1->faction, r); assert(r && u1 && u2); set_param(&global.parameters, "rules.food.flags", "0"); i_change(&u1->items, i_silver, 30); get_food(r); CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER)); CuAssertIntEquals(tc, 0, fval(u2, UFL_HUNGER)); get_food(r); CuAssertIntEquals(tc, 0, i_get(u1->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER)); CuAssertIntEquals(tc, UFL_HUNGER, fval(u2, UFL_HUNGER)); test_cleanup(); }
ZibaseTemp::ZibaseTemp(Params &p): InputTemp(p), port(0) { // Define IO documentation ioDoc->friendlyNameSet("ZibaseTemp"); ioDoc->descriptionSet(_("Zibase temperature sensor")); ioDoc->paramAdd("host", _("Zibase IP address on the network"), IODoc::TYPE_STRING, true); ioDoc->paramAddInt("port", _("Zibase ethernet port, default to 17100"), 0, 65535, false, 17100); ioDoc->paramAdd("zibase_id", _("Zibase device ID (ABC)"), IODoc::TYPE_STRING, true); Params devList = {{ "temp", _("Temperature sensor") }}; ioDoc->paramAddList("zibase_sensor", "Type of sensor", true, devList, "temp"); if (!param_exists("port")) set_param("port", "17100"); host = get_param("host"); Utils::from_string(get_param("port"), port); id = get_param("zibase_id"); sensor_type = ZibaseInfoSensor::eTEMP; Zibase::Instance(host, port).sig_newframe.connect(sigc::mem_fun(*this, &ZibaseTemp::valueUpdated)); cDebugDom("input") << get_param("id"); }
static void test_shipspeed_max_range(CuTest *tc) { ship *sh; ship_type *stype; region *r; struct faction *f; unit *cap, *crew; test_cleanup(); sh = setup_ship(); setup_crew(sh, 0, &cap, &crew); set_param(&global.parameters, "movement.shipspeed.skillbonus", "5"); r = sh->region; f = test_create_faction(0); assert(r && f); stype = st_get_or_create(sh->type->_name); set_level(cap, SK_SAILING, stype->cptskill + 4); set_level(crew, SK_SAILING, (stype->sumskill - stype->cptskill) * 4); CuAssertIntEquals_Msg(tc, "skill bonus requires at least movement.shipspeed.skillbonus points", 2, shipspeed(sh, cap)); set_level(cap, SK_SAILING, stype->cptskill + 5); set_level(crew, SK_SAILING, (stype->sumskill - stype->cptskill) * 5); CuAssertIntEquals_Msg(tc, "skill bonus from movement.shipspeed.skillbonus", 3, shipspeed(sh, cap)); set_level(cap, SK_SAILING, stype->cptskill + 15); set_level(crew, SK_SAILING, (stype->sumskill - stype->cptskill) * 15); CuAssertIntEquals_Msg(tc, "skill-bonus cannot exceed max_range", 4, shipspeed(sh, cap)); test_cleanup(); }
/* **************************************************************** * Abre a conexão (parte do servidor) * **************************************************************** */ int tcp_open (int port) { int fd; T_BIND req; INADDR req_addr; if ((fd = t_open (tcpdevname, O_RDWR, (T_INFO *)NULL)) < 0) return (-1); /* * Preenche a estrutura T_BIND */ FILL_INADDR (req_addr, 0, port); FILL_NETBUF (req.addr, &req_addr, sizeof (req_addr)); req.qlen = MAX_LISTEN_QLEN; if (t_bind (fd, &req, (T_BIND *)NULL) < 0) goto bad; if (set_param (fd) < 0) goto bad; listen_port = port; return (fd); bad: t_close (fd); return (-1); } /* end tcp_open */
/* **************************************************************** * Inicia um cliente * **************************************************************** */ int tcp_connect (int port, const char *name) { int fd; T_BIND bind; T_CALL call; INADDR bind_addr, addr; IPADDR remote_ip_addr; if ((fd = t_open (tcpdevname, O_RDWR, (T_INFO *)NULL)) < 0) return (-1); /* * Associa um endereço local. */ FILL_INADDR (bind_addr, 0, 0); FILL_NETBUF (bind.addr, &bind_addr, sizeof (bind_addr)); bind.qlen = 0; /* Não vamos dar "t_listen" nesta conexão */ if (t_bind (fd, &bind, (T_BIND *)NULL) < 0) goto bad; if (set_param (fd) < 0) goto bad; /* * Converte o nome da estação remota em um endereço IP. */ if (name != NOSTR && name[0] != '\0') { remote_ip_addr = t_node_to_addr (fd, name, NULL); if (remote_ip_addr == -1) goto bad; } else { remote_ip_addr = LOCAL_IP_ADDR; } /* * Preenche a estrutura T_CALL: só o membro addr é relevante. */ FILL_INADDR (addr, remote_ip_addr, port); FILL_NETBUF (call.addr, &addr, sizeof (addr)); FILL_NETBUF (call.opt, NULL, 0); FILL_NETBUF (call.udata, NULL, 0); /* * Tenta estabeler a conexão com a estação remota. */ if (t_connect (fd, &call, (T_CALL *)NULL) < 0) goto bad; return (fd); bad: t_close (fd); return (-1); } /* end tcp_connect */
void panel_set_option(struct parsed_tagarg *arg) { FILE *f = NULL; char *p; if (no_rc_dir) { disp_message("There's no ~/.w3m directory... config not saved", FALSE); } else { f = fopen(config_file, "wt"); if (f == NULL) { disp_message("Can't write option!", FALSE); } } while (arg) { /* InnerCharset -> SystemCharset */ if (arg->value) { p = conv_to_system(arg->value); if (set_param(arg->arg, p)) { if (f) fprintf(f, "%s %s\n", arg->arg, p); } } arg = arg->next; } if (f) fclose(f); sync_with_option(); backBf(); }
/** * Parse the name=value pairs in the query string and set parameters * @param params The fastphoto parameters to set * @param query The query string */ static void parse_query (fastphoto_t * params, char * query) { char * key, * val, * end; if (!query) return; key = query; do { val = strchr (key, '='); end = strchr (key, '&'); if (end) { if (val) { if (val < end) { *val++ = '\0'; } else { val = NULL; } } *end++ = '\0'; } else { if (val) *val++ = '\0'; } /* fprintf (stderr, "%s = %s\n", key, val);*/ set_param (params, key, val); key = end; } while (end != NULL); return; }
static void interpret_rc(FILE * f) { Str line; Str tmp; char *p; for (;;) { line = Strfgets(f); Strchop(line); if (line->length == 0) break; Strremovefirstspaces(line); if (line->ptr[0] == '#') /* comment */ continue; tmp = Strnew(); p = line->ptr; while (*p && !IS_SPACE(*p)) Strcat_char(tmp, *p++); while (*p && IS_SPACE(*p)) p++; Strlower(tmp); set_param(tmp->ptr, p); } }
/*---------------------------------------------------------------------------*/ static void test_rx_modes(void) { int i; printf("====================================\n"); printf("RX Modes Test: [0 , 3]\n"); for(i = 0; i <= 3; i++) { value = i; printf("Switch to: %d, Now: ", value); set_param(RADIO_PARAM_RX_MODE, value); if(get_param(RADIO_PARAM_RX_MODE, &value) == RADIO_RESULT_OK) { printf("Address Filtering is "); if(value & RADIO_RX_MODE_ADDRESS_FILTER) { printf("On, "); } else { printf("Off, "); } printf("Auto ACK is "); if(value & RADIO_RX_MODE_AUTOACK) { printf("On, "); } else { printf("Off, "); } printf("(value=%d)\n", value); } } }
generic_diode::generic_diode() { m_Vd = 0.7; set_param(1e-15, 1, 1e-15); m_G = m_gmin; m_Id = 0.0; }
void SoundPlayer2D::_notification(int p_what) { switch(p_what) { case NOTIFICATION_ENTER_TREE: { //find the sound space source_rid = SpatialSound2DServer::get_singleton()->source_create(get_world_2d()->get_sound_space()); for(int i=0;i<PARAM_MAX;i++) set_param(Param(i),params[i]); SpatialSound2DServer::get_singleton()->source_set_transform(source_rid,get_global_transform()); } break; case NOTIFICATION_TRANSFORM_CHANGED: { SpatialSound2DServer::get_singleton()->source_set_transform(source_rid,get_global_transform()); } break; case NOTIFICATION_EXIT_TREE: { if (source_rid.is_valid()) SpatialSound2DServer::get_singleton()->free(source_rid); } break; } }
void test_upkeep_default(CuTest * tc) { region *r; unit *u1, *u2; faction *f1, *f2; const item_type *i_silver; test_cleanup(); test_create_world(); i_silver = it_find("money"); assert(i_silver); r = findregion(0, 0); f1 = test_create_faction(test_create_race("human")); f2 = test_create_faction(test_create_race("human")); assert(f1 && f2); u1 = test_create_unit(f1, r); u2 = test_create_unit(f2, r); assert(r && u1 && u2); set_param(&global.parameters, "rules.food.flags", "0"); i_change(&u1->items, i_silver, 20); get_food(r); // since u1 and u2 are not allied, u1 should not help u2 with upkeep CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER)); CuAssertIntEquals(tc, UFL_HUNGER, fval(u2, UFL_HUNGER)); test_cleanup(); }
static void test_get_set_param(CuTest * tc) { struct param *par = 0; test_cleanup(); CuAssertStrEquals(tc, 0, get_param(par, "foo")); set_param(&par, "foo", "bar"); set_param(&par, "bar", "foo"); CuAssertStrEquals(tc, "bar", get_param(par, "foo")); CuAssertStrEquals(tc, "foo", get_param(par, "bar")); set_param(&par, "bar", "bar"); CuAssertStrEquals(tc, "bar", get_param(par, "bar")); set_param(&par, "bar", NULL); CuAssertPtrEquals(tc, NULL, (void *)get_param(par, "bar")); free_params(&par); test_cleanup(); }
bool CurveGradient::set_param(const String & param, const ValueBase &value) { IMPORT_VALUE(param_origin); IMPORT_VALUE(param_width); if(param=="bline" && value.get_type()==ValueBase::TYPE_LIST) { param_bline=value; bline_loop=value.get_loop(); sync(); return true; } IMPORT_VALUE(param_gradient); IMPORT_VALUE(param_loop); IMPORT_VALUE(param_zigzag); IMPORT_VALUE(param_perpendicular); IMPORT_VALUE(param_fast); if(param=="offset") return set_param("origin", value); return Layer_Composite::set_param(param,value); }
int iKXPlugin::set_all_params(kxparam_t *values) // at least [count] { int ret=0; for(int i=0;i<get_param_count();i++) ret+=set_param(i,values[i]); return ret; }
Particles2D::Particles2D() { for(int i=0;i<PARAM_MAX;i++) { param[i]=0; randomness[i]=0; } set_param(PARAM_SPREAD,10); set_param(PARAM_LINEAR_VELOCITY,20); set_param(PARAM_GRAVITY_STRENGTH,9.8); set_param(PARAM_RADIAL_ACCEL,0); set_param(PARAM_TANGENTIAL_ACCEL,0); set_param(PARAM_INITIAL_ANGLE,0.0); set_param(PARAM_INITIAL_SIZE,1.0); set_param(PARAM_FINAL_SIZE,1.0); set_param(PARAM_ANIM_SPEED_SCALE,1.0); time=0; lifetime=2; emitting=false; particles.resize(32); active_count=-1; set_emitting(true); local_space=true; preprocess=0; time_scale=1.0; color_phase_count=1; set_color_phase_pos(0,0.0); set_color_phase_pos(1,1.0); set_color_phase_pos(2,1.0); set_color_phase_pos(3,1.0); set_color_phase_color(0,Color(1,1,1)); set_color_phase_color(1,Color(0,0,0)); set_color_phase_color(2,Color(0,0,0)); set_color_phase_color(3,Color(0,0,0)); flip_h=false; flip_v=false; v_frames=1; h_frames=1; emit_timeout = 0; time_to_live = 0; explosiveness=1.0; }
int iAPSExpPlusPlugin::set_all_params(kxparam_t* values) { for (int i = 0; i < APSEXP_PLUS_PARAMS_COUNT; i++) set_param(i, values[i]); /* you can perform parameters calculations right here (as i did in Reverb/Chorus), or just call set_param for every parameter (like above) */ return 0; }
int main_loop(t_map *m) { set_param(m); calculus(m); mlx_key_hook(m->win, &get_loop_key, m); mlx_mouse_hook(m->win, &get_loop_scroll, m); mlx_hook(m->win, 6, (1l << 6), &get_loop_mouse, m); mlx_loop(m->mlx); return (0); }