bool Inliner::inline_primitive(Class* klass, CompiledMethod* cm, executor prim) { const char* inlined_prim = 0; if(prim == Primitives::tuple_at && count_ == 1) { inlined_prim = "tuple_at"; call_tuple_at(ops_, *this); } else if(prim == Primitives::tuple_put && count_ == 2) { inlined_prim = "tuple_put"; call_tuple_put(ops_, *this); } else if(prim == Primitives::fixnum_and && count_ == 1) { inlined_prim = "fixnum_and"; fixnum_and(ops_, *this); } else if(prim == Primitives::fixnum_or && count_ == 1) { inlined_prim = "fixnum_or"; fixnum_or(ops_, *this); } else if(prim == Primitives::fixnum_neg && count_ == 0) { inlined_prim = "fixnum_neg"; fixnum_neg(ops_, *this); } else if(prim == Primitives::object_equal && count_ == 1) { inlined_prim = "object_equal"; object_equal(klass, ops_, *this); } else if(prim == Primitives::float_add && count_ == 1) { inlined_prim = "float_add"; float_op(cAdd, klass, ops_, *this); } else if(prim == Primitives::float_sub && count_ == 1) { inlined_prim = "float_sub"; float_op(cSub, klass, ops_, *this); } else if(prim == Primitives::float_mul && count_ == 1) { inlined_prim = "float_mul"; float_op(cMultiply, klass, ops_, *this); } else if(prim == Primitives::float_div && count_ == 1) { inlined_prim = "float_div"; float_op(cDivide, klass, ops_, *this); } else if(prim == Primitives::float_mod && count_ == 1) { inlined_prim = "float_mod"; float_op(cMod, klass, ops_, *this); /* } else if(prim == Primitives::object_class && count_ == 0) { inlined_prim = "object_class"; object_class(klass, ops_, *this); */ } else { JITStubResults stub_res; if(Primitives::get_jit_stub(cm->prim_index(), stub_res)) { if(stub_res.arg_count() == count_) { Value* self = recv(); ops_.check_class(self, klass, failure()); std::vector<Value*> call_args; Signature sig(ops_.state(), "Object"); sig << "VM"; call_args.push_back(ops_.vm()); if(stub_res.pass_callframe()) { sig << "CallFrame"; call_args.push_back(ops_.call_frame()); } sig << "Object"; call_args.push_back(self); for(int i = 0; i < stub_res.arg_count(); i++) { sig << "Object"; call_args.push_back(arg(i)); } Function* func = sig.function(stub_res.name()); func->setDoesNotCapture(1, true); if(stub_res.pass_callframe()) { func->setDoesNotCapture(2, true); } Value* res = sig.call(stub_res.name(), call_args, "prim_value", ops_.b()); // Only doing this when stub_res.can_fail() causes an exception // to be thrown when running the ci specs, need to investigate. BasicBlock* cont = ops_.new_block("continue"); Value* as_i = ops_.ptrtoint(res); Value* icmp = ops_.b().CreateICmpEQ(as_i, ConstantInt::get(ops_.state()->IntPtrTy, reinterpret_cast<intptr_t>(Qundef))); ops_.b().CreateCondBr(icmp, failure(), cont); ops_.set_block(cont); set_result(res); if(ops_.state()->config().jit_inline_debug) { std::cerr << "inlining: " << ops_.state()->symbol_cstr(cm->scope()->module()->name()) << "#" << ops_.state()->symbol_cstr(cm->name()) << " into " << ops_.state()->symbol_cstr(ops_.vmmethod()->original->name()) << ". generic primitive: " << stub_res.name() << "\n"; } return true; } } } if(inlined_prim) { if(ops_.state()->config().jit_inline_debug) { std::cerr << "inlining: " << ops_.state()->symbol_cstr(cm->scope()->module()->name()) << "#" << ops_.state()->symbol_cstr(cm->name()) << " into " << ops_.state()->symbol_cstr(ops_.vmmethod()->original->name()) << ". primitive " << inlined_prim << "\n"; } return true; } // Add more primitive inlining! if(ops_.state()->config().jit_inline_debug) { std::cerr << "NOT inlining: " << ops_.state()->symbol_cstr(cm->scope()->module()->name()) << "#" << ops_.state()->symbol_cstr(cm->name()) << " into " << ops_.state()->symbol_cstr(ops_.vmmethod()->original->name()) << ". primitive: " << ops_.state()->symbol_cstr(cm->primitive()) << "\n"; } return false; }
/* * Implement the hdu list subcommand: * * <path> hdu list * * see comments for hduCmd() for details. */ int RtdImage::hduCmdList(int argc, char** argv, FitsIO* fits) { // return a list of HDUs int numHDUs = fits->getNumHDUs(); if (numHDUs <= 0) return TCL_OK; // empty return list // save current HDU, then loop through all HDUs to get info int curHDU = fits->getHDUNum(); ostringstream os; int status = 0; int count = 0; for (int i = 1; i <= numHDUs; i++) { if (fits->setHDU(i) != 0) { status++; break; } const char* type = fits->getHDUType(); if (!type) { status++; break; } // get these keyword values and default to "" char extName[80], naxis[32], naxis1[32], naxis2[32], naxis3[32]; char crpix1[32], crpix2[32]; fits->get("EXTNAME", extName, sizeof(extName)); fits->get("NAXIS", naxis, sizeof(naxis)); fits->get("NAXIS1", naxis1, sizeof(naxis1)); fits->get("NAXIS2", naxis2, sizeof(naxis2)); fits->get("NAXIS3", naxis3, sizeof(naxis3)); fits->get("CRPIX1", crpix1, sizeof(crpix1)); fits->get("CRPIX2", crpix2, sizeof(crpix2)); // Try avoiding long fractional strings if (strlen(crpix1) != 0 && strlen(crpix2) != 0) { double dcrpix1, dcrpix2; fits->get("CRPIX1", dcrpix1); fits->get("CRPIX2", dcrpix2); os << "{" << i << " " << type << " {" << extName << "}" << " {" << naxis << "}" << " {" << naxis1 << "}" << " {" << naxis2 << "}" << " {" << naxis3 << "}" << " {" << dcrpix1 << "}" << " {" << dcrpix2 << "}" << "} "; } else { os << "{" << i << " " << type << " {" << extName << "}" << " {" << naxis << "}" << " {" << naxis1 << "}" << " {" << naxis2 << "}" << " {" << naxis3 << "}" << " {" << crpix1 << "}" << " {" << crpix2 << "}" << "} "; } count++; } if (count) { if (status == TCL_OK) { set_result(os.str().c_str()); } fits->setHDU(curHDU); } return status; }
void template_matching(int frameID, unsigned char *image, int width, int height, int search_range, const bounding_box *box0) { // 別メモリ領域に確保した画像データをMISTの画像コンテナにマッピングする // 第1引数:画像の幅 // 第2引数:画像の高さ // 第3引数:メモリ領域を指すポインタ // 第4引数:メモリ領域のサイズ image_type img(width, height, (pixel_type *) image, width * height * 3 * sizeof(unsigned char)); // 画像をBMP形式で保存する場合は次の様に記述する // mist::write_bmp( img, "ファイル名.bmp" ); if (frameID == 0) { // 最初のフレームは追跡開始位置を記憶 obox = *box0; // 参照画像を切り出す img.trim(rimg, obox.x, obox.y, obox.w, obox.h); // 移動物体を囲む矩形を設定 set_result(frameID, obox); } else { // 前回の物体位置を基準にして現在の物体位置を探索 int i0 = obox.x - search_range; int j0 = obox.y - search_range; double merr = 1.0e100; // 参照画像とのテンプレートマッチング for (int j = obox.y - search_range; j <= obox.y + search_range; j++) { if (j < 0 || height <= j + obox.h) { continue; } for (int i = obox.x - search_range; i <= obox.x + search_range; i++) { if (i < 0 || width <= i + obox.w) { continue; } double err = 0.0; // 参照画像との2乗誤差を計算 for (int n = 0; n < obox.h; n++) { for (int m = 0; m < obox.w; m++) { // 参照画像と入力画像それぞれの画素への参照 const pixel_type &p1 = rimg(m, n); const pixel_type &p2 = img(m + i, n + j); double r = p1.r - p2.r; double g = p1.g - p2.g; double b = p1.b - p2.b; err += r * r; err += g * g; err += b * b; } if (err >= merr) { break; } } // 2乗誤差が最小の位置を記憶 if (err < merr) { i0 = i; j0 = j; merr = err; } } } obox.x = i0; obox.y = j0; // 移動物体を囲む矩形を記録 set_result(frameID, obox); } }
virtual void run() { auto boundfn = []() -> typename res<Fn>::type{}; set_result(boundfn); }
void configure::process_event() { int mousex, mousey; SDL_GetMouseState(&mousex,&mousey); tooltips::process(mousex, mousey); if(cancel_game_.pressed()) { set_result(QUIT); return; } if(launch_game_.pressed()) { // check if the map is valid if (name_entry_.text() == "") { gui2::show_transient_message(disp_.video(), "", _("You must enter a name.")); } else { set_result(CREATE); return; } } if(password_button_.pressed()) { gui2::tmp_create_game_set_password::execute( parameters_.password , disp_.video()); } if (entry_points_combo_.changed()) { const config& scenario = *entry_points_[entry_points_combo_.selected()]; parameters_.hash = scenario.hash(); state_.set_scenario(scenario); force_use_map_settings_check_ = true; } // Turns per game const int cur_turns = turns_slider_.value(); std::stringstream buf; if(cur_turns < 100) { buf << _("Turns: ") << cur_turns; } else { buf << _("Unlimited turns"); } turns_label_.set_text(buf.str()); countdown_init_time_label_.enable(countdown_game_.checked()); countdown_init_time_slider_.enable(countdown_game_.checked()); countdown_turn_bonus_label_.enable(countdown_game_.checked()); countdown_turn_bonus_slider_.enable(countdown_game_.checked()); countdown_reservoir_time_label_.enable(countdown_game_.checked()); countdown_reservoir_time_slider_.enable(countdown_game_.checked()); countdown_action_bonus_label_.enable(countdown_game_.checked()); countdown_action_bonus_slider_.enable(countdown_game_.checked()); if(mp_countdown_init_time_ != countdown_init_time_slider_.value() && countdown_init_time_slider_.value() > countdown_reservoir_time_slider_.value()) { countdown_reservoir_time_slider_.set_value(countdown_init_time_slider_.value()); } if(mp_countdown_reservoir_time_ != countdown_reservoir_time_slider_.value() && countdown_reservoir_time_slider_.value() < countdown_init_time_slider_.value()) { countdown_init_time_slider_.set_value(countdown_reservoir_time_slider_.value()); } mp_countdown_init_time_ = countdown_init_time_slider_.value(); mp_countdown_reservoir_time_ = countdown_reservoir_time_slider_.value(); buf.str(""); buf << _("Init. limit: ") << mp_countdown_init_time_; // << _(" sec."); countdown_init_time_label_.set_text(buf.str()); const int mp_countdown_turn_bonus_val = countdown_turn_bonus_slider_.value(); buf.str(""); buf << _("Turn bonus: ") << mp_countdown_turn_bonus_val; // << _(" sec."); countdown_turn_bonus_label_.set_text(buf.str()); buf.str(""); buf << _("Reservoir: ") << mp_countdown_reservoir_time_; // << _(" sec."); countdown_reservoir_time_label_.set_text(buf.str()); const int mp_countdown_action_bonus_val = countdown_action_bonus_slider_.value(); buf.str(""); buf << _("Action bonus: ") << mp_countdown_action_bonus_val; // << _(" sec."); countdown_action_bonus_label_.set_text(buf.str()); // Villages can produce between 1 and 5 gold a turn const int village_gold = village_gold_slider_.value(); buf.str(""); buf << _("Village gold: ") << village_gold; village_gold_label_.set_text(buf.str()); // Unit levels supported per village const int village_support = village_support_slider_.value(); buf.str(""); buf << _("Village support: ") << village_support; village_support_label_.set_text(buf.str()); // Experience modifier const int xpmod = xp_modifier_slider_.value(); buf.str(""); buf << _("Experience modifier: ") << xpmod << "%"; xp_modifier_label_.set_text(buf.str()); if(use_map_settings_.pressed() || force_use_map_settings_check_) { force_use_map_settings_check_ = false; const bool map_settings = use_map_settings_.checked(); // If the map settings are wanted use them, // if not properly defined fall back to the default settings turns_slider_.set_value(map_settings ? settings::get_turns(state_.get_starting_pos()["turns"]) : preferences::turns()); xp_modifier_slider_.set_value(map_settings ? settings::get_xp_modifier(state_.get_starting_pos()["experience_modifier"]) : preferences::xp_modifier()); random_start_time_.set_check(map_settings ? state_.get_starting_pos()["random_start_time"].to_bool(true) : preferences::random_start_time()); // These are per player, always show values of player 1. /** * @todo This might not be 100% correct, but at the moment * it is not possible to show the fog and shroud per player. * This might change in the future. * NOTE when 'load game' is selected there are no sides. */ config::const_child_itors sides = state_.get_starting_pos().child_range("side"); if (sides.first != sides.second) { const config &cfg = *sides.first; village_gold_slider_.set_value(map_settings ? settings::get_village_gold(cfg["village_gold"]) : preferences::village_gold()); village_support_slider_.set_value(map_settings ? settings::get_village_support(cfg["village_support"]) : preferences::village_support()); fog_game_.set_check(map_settings ? cfg["fog"].to_bool(true) : preferences::fog()); shroud_game_.set_check(map_settings ? cfg["shroud"].to_bool(false) : preferences::shroud()); } // Set the widget states turns_slider_.enable(!map_settings); village_gold_slider_.enable(!map_settings); village_support_slider_.enable(!map_settings); xp_modifier_slider_.enable(!map_settings); random_start_time_.enable(!map_settings); fog_game_.enable(!map_settings); shroud_game_.enable(!map_settings); } options_manager_.process_event(); }
void wait::process_event() { if (cancel_button_.pressed()) set_result(QUIT); }
void create::process_event() { int mousex, mousey; SDL_GetMouseState(&mousex,&mousey); tooltips::process(mousex, mousey); if (cancel_game_.pressed()) { set_result(QUIT); return; } if (launch_game_.pressed() || levels_menu_.double_clicked()) { if (engine_.current_level().can_launch_game()) { if (engine_.current_level_type() == level::CAMPAIGN || engine_.current_level_type() == level::SP_CAMPAIGN) { std::string difficulty = select_campaign_difficulty(); if (difficulty == "CANCEL") { return; } engine_.prepare_for_campaign(difficulty); } engine_.prepare_for_new_level(); set_result(CREATE); return; } else { gui2::show_transient_message(disp_.video(), "", _("The level is invalid.")); } } if (level_type_combo_.changed()) { init_level_type_changed(0); } if (load_game_.pressed()) { engine_.prepare_for_saved_game(); set_result(LOAD_GAME); return; } bool update_mod_button_label = mod_selection_ != mods_menu_.selection(); if (select_mod_.pressed() || mods_menu_.double_clicked()) { int index = mods_menu_.selection(); engine_.set_current_mod_index(index); engine_.toggle_current_mod(); update_mod_button_label = true; synchronize_selections(); } if (update_mod_button_label) { mod_selection_ = mods_menu_.selection(); engine_.set_current_mod_index(mod_selection_); set_description(engine_.current_extra(create_engine::MOD).description); if (engine_.dependency_manager().is_modification_active(mod_selection_)) { select_mod_.set_label(_("Deactivate")); } else { select_mod_.set_label(_("Activate")); } } bool era_changed = era_selection_ != eras_menu_.selection(); era_selection_ = eras_menu_.selection(); if (era_changed) { engine_.set_current_era_index(era_selection_); set_description(engine_.current_extra(create_engine::ERA).description); synchronize_selections(); } if (filter_name_.text() != engine_.level_name_filter()) { engine_.apply_level_filter(filter_name_.text()); init_level_type_changed(0); } bool level_changed = level_selection_ != levels_menu_.selection(); level_selection_ = levels_menu_.selection(); if (level_changed && level_selection_ >= 0) { init_level_changed(level_selection_); synchronize_selections(); } if (engine_.generator_assigned() && generator_settings_.pressed()) { engine_.generator_user_config(disp_); level_changed = true; } if(engine_.generator_assigned() && (level_changed || regenerate_map_.pressed())) { const cursor::setter cursor_setter(cursor::WAIT); cursor::setter cur(cursor::WAIT); engine_.init_generated_level_data(); if (!engine_.current_level().data()["error_message"].empty()) gui2::show_message(disp().video(), "map generation error", engine_.current_level().data()["error_message"]); level_changed = true; } if(level_changed) { std::stringstream players; std::stringstream map_size; players << _("Players: "); engine_.current_level().set_metadata(); draw_level_image(); set_description(engine_.current_level().description()); switch (engine_.current_level_type()) { case level::SCENARIO: case level::USER_MAP: case level::USER_SCENARIO: case level::RANDOM_MAP: { scenario* current_scenario = dynamic_cast<scenario*>(&engine_.current_level()); players << current_scenario->num_players(); map_size << _("Size: ") << current_scenario->map_size(); break; } case level::CAMPAIGN: case level::SP_CAMPAIGN: { campaign* current_campaign = dynamic_cast<campaign*>(&engine_.current_level()); players << current_campaign->min_players(); if (current_campaign->max_players() != current_campaign->min_players()) { players << " to " << current_campaign->max_players(); } break; } } // end switch map_size_label_.set_text(map_size.str()); num_players_label_.set_text(players.str()); launch_game_.enable(engine_.current_level().can_launch_game()); generator_settings_.enable(engine_.generator_assigned()); regenerate_map_.enable(engine_.generator_assigned()); } if (filter_num_players_slider_.value() != engine_.player_num_filter()) { const int val = filter_num_players_slider_.value(); engine_.apply_level_filter(val); std::stringstream ss; if (val == 1) { ss << _("Number of players: any"); } else { ss << _("Number of players: ") << val; } filter_num_players_label_.set_text(ss.str()); init_level_type_changed(0); } }
// sampler commands static void cmd_sampler(void) { u08 cmd, res; u08 exit = 0; while((cmd = get_char()) != 0) { switch(cmd) { case 'm': // read track to spi ram { u08 sel = floppy_select_on(); u08 mot = floppy_motor_on(); track_init(); res = trk_read_to_spiram(parse_hex_byte(1)); if(mot) floppy_motor_off(); if(sel) floppy_select_off(); set_result(res); } break; case 'f': // fake read track (only to spi ram) res = trk_read_sim(parse_hex_byte(1)); set_result(res); break; case 'v': // verify track with spi ram res = trk_check_spiram(parse_hex_byte(1)); set_result(res); break; // ----- checks ----- case 'i': // index check { u08 sel = floppy_select_on(); u08 mot = floppy_motor_on(); track_init(); res = trk_read_count_index(); if(mot) floppy_motor_off(); if(sel) floppy_select_off(); set_result(res); } break; case 'd': // read data check { u08 sel = floppy_select_on(); u08 mot = floppy_motor_on(); track_init(); res = trk_read_count_data(); if(mot) floppy_motor_off(); if(sel) floppy_select_off(); set_result(res); } break; case 's': // read data spectrum { u08 sel = floppy_select_on(); u08 mot = floppy_motor_on(); track_init(); res = trk_read_data_spectrum(parse_hex_byte(0)); if(mot) floppy_motor_off(); if(sel) floppy_select_off(); set_result(res); } break; default: set_result(ERROR_SYNTAX); case '.': exit = 1; break; } if(exit) break; } }
void wait::join_game(bool observe) { const bool download_res = download_level_data(); if (!download_res) { DBG_MP << "mp wait: could not download level data, quitting..."; set_result(QUIT); return; } else if (!get_scenario()["allow_new_game"].to_bool(true) && !level_.child_or_empty("multiplayer")["savegame"].to_bool(false)) { set_result(PLAY); return; } if (first_scenario_) { state_ = saved_game(); state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER; const config* campaign = &game_config_manager::get()-> game_config().find_child("campaign", "id", level_.child("multiplayer")["mp_campaign"]); const config* scenario = &game_config_manager::get()-> game_config().find_child("multiplayer", "id", level_.child(lexical_cast<std::string>(game_classification::CAMPAIGN_TYPE::MULTIPLAYER))["id"]); const config* era = &game_config_manager::get()-> game_config().find_child("era", "id", level_.child("era")["id"]); if (*campaign) { state_.classification().difficulty = level_.child("multiplayer")["difficulty_define"].str(); state_.classification().campaign_define = (*campaign)["define"].str(); state_.classification().campaign_xtra_defines = utils::split((*campaign)["extra_defines"]); } if (*scenario) state_.classification().scenario_define = (*scenario)["define"].str(); if (*era) state_.classification().era_define = (*era)["define"].str(); BOOST_FOREACH(const config& mod, level_.child_range("modification")) { const config* modification = &game_config_manager::get()-> game_config().find_child("modification", "id", mod["id"]); if (*modification) { state_.classification().mod_defines.push_back( (*modification)["define"].str()); } } // Make sure that we have the same config as host, if possible. game_config_manager::get()-> load_game_config_for_game(state_.classification()); } // Add the map name to the title. append_to_title(": " + get_scenario()["name"].t_str()); if (!observe) { //search for an appropriate vacant slot. If a description is set //(i.e. we're loading from a saved game), then prefer to get the side //with the same description as our login. Otherwise just choose the first //available side. const config *side_choice = NULL; int side_num = -1, nb_sides = 0; BOOST_FOREACH(const config &sd, get_scenario().child_range("side")) { DBG_MP << "*** side " << nb_sides << "***\n" << sd.debug() << "***\n"; if (sd["controller"] == "reserved" && sd["current_player"] == preferences::login()) { side_choice = &sd; side_num = nb_sides; break; } if (sd["controller"] == "network" && sd["player_id"].empty()) { if (!side_choice) { // found the first empty side side_choice = &sd; side_num = nb_sides; } if (sd["current_player"] == preferences::login()) { side_choice = &sd; side_num = nb_sides; break; // found the preferred one } } ++nb_sides; } if (!side_choice) { size_t count = 0; for(config::child_itors its = get_scenario().child_range("side"); its.second != its.first; ++its.first) { ++count; } DBG_MP << "could not find a side, all " << count << " sides were unsuitable\n"; set_result(QUIT); return; } bool allow_changes = (*side_choice)["allow_changes"].to_bool(true); //if the client is allowed to choose their team, instead of having //it set by the server, do that here. if(allow_changes) { events::event_context context; const config &era = level_.child("era"); /** @todo Check whether we have the era. If we don't inform the user. */ if (!era) throw config::error(_("No era information found.")); config::const_child_itors possible_sides = era.child_range("multiplayer_side"); if (possible_sides.first == possible_sides.second) { set_result(QUIT); throw config::error(_("No multiplayer sides found")); } int color = side_num; const std::string color_str = (*side_choice)["color"]; if (!color_str.empty()) color = game_config::color_info(color_str).index() - 1; std::vector<const config*> era_factions; BOOST_FOREACH(const config &side, possible_sides) { era_factions.push_back(&side); } const bool lock_settings = get_scenario()["force_lock_settings"].to_bool(); const bool use_map_settings = level_.child("multiplayer")["mp_use_map_settings"].to_bool(); const bool saved_game = level_.child("multiplayer")["savegame"].to_bool(); ng::flg_manager flg(era_factions, *side_choice, lock_settings, use_map_settings, saved_game, color); std::vector<std::string> choices; BOOST_FOREACH(const config *s, flg.choosable_factions()) { const config &side = *s; const std::string &name = side["name"]; const std::string &icon = side["image"]; if (!icon.empty()) { std::string rgb = side["flag_rgb"]; if (rgb.empty()) rgb = "magenta"; choices.push_back(IMAGE_PREFIX + icon + "~RC(" + rgb + ">" + lexical_cast<std::string>(color+1) + ")" + COLUMN_SEPARATOR + name); } else { choices.push_back(name); } } std::vector<gui::preview_pane* > preview_panes; leader_preview_pane leader_selector(disp(), flg, color); preview_panes.push_back(&leader_selector); const int faction_choice = gui::show_dialog(disp(), NULL, _("Choose your faction:"), _("Starting position: ") + lexical_cast<std::string>(side_num + 1), gui::OK_CANCEL, &choices, &preview_panes); if(faction_choice < 0) { set_result(QUIT); return; } config faction; config& change = faction.add_child("change_faction"); change["change_faction"] = true; change["name"] = preferences::login(); change["faction"] = flg.current_faction()["id"]; change["leader"] = flg.current_leader(); change["gender"] = flg.current_gender(); network::send_data(faction, 0); } }
int svr4_shmsys(struct pt_regs * regs) { int command = get_syscall_parameter (regs, 0); int arg1, arg2, arg3; mm_segment_t old_fs; long retval = 0; char *addr = 0; arg1 = arg2 = arg3 = 0; switch (command) { case U_SHMAT: case U_SHMCTL: case U_SHMGET: arg1 = get_syscall_parameter (regs, 1); arg2 = get_syscall_parameter (regs, 2); arg3 = get_syscall_parameter (regs, 3); break; case U_SHMDT: addr = (char *) get_syscall_parameter (regs, 1); break; default: printk(KERN_ERR "%d iBCS: bad SHM command %d\n", current->pid, command); retval = -EINVAL; goto test_exit; } switch (command) { case U_SHMAT: { #ifdef IPCCALL unsigned long raddr; #endif #ifdef CONFIG_ABI_TRACE if ((ibcs_trace & TRACE_API) || ibcs_func_p->trace) printk(KERN_DEBUG "%d iBCS: ibcs_shmat: args: %d %x %o \n", current->pid, arg1, arg2, arg3); #endif /* * raddr = 0 tells sys_shmat to limit to 2G * and we are IBCS, no raddr value to return */ #ifdef IPCCALL old_fs = get_fs(); set_fs(get_ds()); retval = SYS (ipc) (IPCCALL(1,SHMAT), arg1, arg3, &raddr, (char *) arg2); set_fs(old_fs); if (retval >= 0) retval = raddr; #else retval = SYS (ipc) (SHMAT, arg1, arg3, 0, (char *) arg2); #endif #ifdef CONFIG_ABI_TRACE if ((ibcs_trace & TRACE_API) || ibcs_func_p->trace) printk(KERN_DEBUG "%d iBCS: ibcs_shmat: return val is %lx\n", current->pid, retval); #endif goto test_exit; } case U_SHMGET: #ifdef CONFIG_ABI_TRACE if ((ibcs_trace & TRACE_API) || ibcs_func_p->trace) printk(KERN_DEBUG "%d iBCS: ibcs_shmget: args: %d %x %o \n", current->pid, arg1, arg2, arg3); #endif retval = SYS (ipc) (SHMGET, arg1, arg2, arg3, 0); goto test_exit; case U_SHMDT: #ifdef CONFIG_ABI_TRACE if ((ibcs_trace & TRACE_API) || ibcs_func_p->trace) printk(KERN_DEBUG "%d iBCS: ibcs_shmdt: arg: %lx\n", current->pid, (unsigned long)addr); #endif retval = SYS (ipc) (SHMDT, 0, 0, 0, addr); goto test_exit; case U_SHMCTL: #ifdef CONFIG_ABI_TRACE if ((ibcs_trace & TRACE_API) || ibcs_func_p->trace) printk(KERN_DEBUG "%d iBCS: ibcs_shmctl: args: %d %x %o %d %x\n", current->pid, arg1, arg2, arg3, arg3, arg3); #endif switch (arg2) { case U_SHMLOCK: retval = SYS (ipc) (SHMCTL, arg1, SHM_LOCK, 0, arg3); goto test_exit; case U_SHMUNLOCK: retval = SYS (ipc) (SHMCTL, arg1, SHM_UNLOCK, 0, arg3); goto test_exit; case U_IPC_SET: { struct ibcs_shmid_ds is; struct shmid_ds ls; retval = verify_area(VERIFY_WRITE, (char *)arg3, sizeof(is)); if (retval) goto test_exit; copy_from_user(&is, (char *)arg3, sizeof(is)); ishm_to_lshm(&is, &ls); old_fs = get_fs(); set_fs (get_ds()); retval = SYS (ipc) (SHMCTL, arg1, IPC_SET, 0, &ls); set_fs(old_fs); if (retval < 0) goto test_exit; lshm_to_ishm(&ls, &is); copy_to_user((char *)arg3, &is, sizeof(is)); goto test_exit; } case U_IPC_SET_L: { struct ibcs_shmid_ds_l is; struct shmid_ds ls; retval = verify_area(VERIFY_WRITE, (char *)arg3, sizeof(is)); if (retval) goto test_exit; copy_from_user(&is, (char *)arg3, sizeof(is)); ishm_to_lshm_l(&is, &ls); old_fs = get_fs(); set_fs (get_ds()); retval = SYS (ipc) (SHMCTL, arg1, IPC_SET, 0, &ls); set_fs(old_fs); if (retval < 0) goto test_exit; lshm_to_ishm_l(&ls, &is); copy_to_user((char *)arg3, &is, sizeof(is)); goto test_exit; } case U_IPC_RMID: case U_IPC_RMID_L: retval = SYS (ipc) (SHMCTL, arg1, IPC_RMID, arg3); goto test_exit; case U_IPC_STAT: { struct ibcs_shmid_ds is; struct shmid_ds ls; old_fs = get_fs(); set_fs (get_ds()); retval = SYS (ipc) (SHMCTL, arg1, IPC_STAT, 0, &ls); set_fs(old_fs); if (retval < 0) goto test_exit; lshm_to_ishm(&ls, &is); retval = copy_to_user((char *)arg3, &is, sizeof(is)) ? -EFAULT : 0; goto test_exit; } case U_IPC_STAT_L: { struct ibcs_shmid_ds_l is; struct shmid_ds ls; old_fs = get_fs(); set_fs (get_ds()); retval = SYS (ipc) (SHMCTL, arg1, IPC_STAT, 0, &ls); set_fs(old_fs); if (retval < 0) goto test_exit; lshm_to_ishm_l(&ls, &is); retval = copy_to_user((char *)arg3, &is, sizeof(is)) ? -EFAULT : 0; goto test_exit; } default: printk(KERN_ERR "%d iBCS: ibcs_shmctl: unsupported command %d\n", current->pid, arg2); } retval = -EINVAL; goto test_exit; default: #ifdef CONFIG_ABI_TRACE printk(KERN_DEBUG "%d iBCS: ibcs_shm: command: %x\n", current->pid, command); #endif retval = -EINVAL; goto test_exit; } test_exit:; if ((retval < 0) && (retval > -255)) { set_error (regs, iABI_errors (-retval)); #ifdef CONFIG_ABI_TRACE if ((ibcs_trace & TRACE_API) || ibcs_func_p->trace) printk(KERN_DEBUG "%d iBCS: Error %ld\n", current->pid, get_result (regs)); #endif } else { clear_error (regs); set_result (regs, retval); } return 0; }
void wait::process_event_impl(bool quit) { if (quit) { set_result(QUIT); } }
int main (int argc, const char* argv[]) { char *line, *cmd, *args; ChessGame* game; ChessGameIterator iter; int quit = 0; chess_generate_init(); game = chess_game_new(); chess_game_iterator_init(&iter, game); print_board(&iter); line = 0; for (;;) { if (line) free(line); if (quit) break; line = read_line("> "); if (!parse_line(line, &cmd, &args)) continue; if (!strcmp(cmd, "quit") || !strcmp(cmd, "q")) { quit = 1; } else if (!strcmp(cmd, "new")) { chess_game_iterator_cleanup(&iter); chess_game_reset(game); chess_game_iterator_init(&iter, game); print_board(&iter); } else if (!strcmp(cmd, "fen")) { load_fen(game, args); } else if (!strcmp(cmd, "pgn")) { save_pgn(game); } else if (!strcmp(cmd, "ls")) { list_moves(&iter); } else if (!strcmp(cmd, "moves")) { game_moves(game); } else if (!strcmp(cmd, "bd")) { print_board(&iter); } else if (!strcmp(cmd, "undo")) { undo_move(&iter); } else if (!strcmp(cmd, "event")) { set_event(game, args); } else if (!strcmp(cmd, "site")) { set_site(game, args); } else if (!strcmp(cmd, "date")) { set_date(game, args); } else if (!strcmp(cmd, "round")) { set_round(game, args); } else if (!strcmp(cmd, "white")) { set_white(game, args); } else if (!strcmp(cmd, "black")) { set_black(game, args); } else if (!strcmp(cmd, "result")) { set_result(game, args); } else { handle_move(&iter, cmd); } } chess_game_iterator_cleanup(&iter); chess_game_destroy(game); return 0; }
static nog_instruction_t *run(nog_closure_t *c, construction current, nog_instruction_t *ip_next, tree *result_tree) { nog_instruction_t *ip; /*printf("run pc=%ld i=%ld c->sp=%ld c->fail=%d c->memo=%d\n", ip_next - pg->np_program, c->head - c->bof, c->sp - c->cx->cx_stack, c->fail, c->memo);*/ if(!ip_next) return 0; for(;;) { ip = ip_next; assert(c->pg->np_program <= ip && ip < c->pg->np_program + c->pg->np_count); assert(c->bof <= c->head && c->head <= c->eof); /*printf("pc=%ld i=%ld c->sp=%ld c->fail=%d c->memo=%d\n", ip - c->pg->np_program, c->head - c->bof, c->sp - c->cx->cx_stack, c->fail, c->memo);*/ DEBUGIF(NOG_DEBUG,"%ld %ld %d\n", (long) (ip - c->pg->np_program), (long) (c->head - c->bof), c->fail); ip_next = ip + 1; switch(ip->ni_opcode) { case NOG_BRA: jump(); break; case NOG_BEOF: if(c->head == c->eof) jump(); break; case NOG_BNEOF: if(c->head < c->eof) jump(); break; case NOG_BFC: if(!c->fail) jump(); break; case NOG_BFS: if(c->fail) jump(); break; case NOG_BMB: if(c->memo == R_BUSY) jump(); break; case NOG_BMBF: if(c->memo == R_BUSY || c->memo == R_FAIL) jump(); break; case NOG_BMK: if(c->memo != R_UNKNOWN) jump(); break; case NOG_BMUK: if(c->memo == R_UNKNOWN) jump(); break; case NOG_BMF: if(c->memo == R_FAIL) jump(); break; case NOG_BBRC: if(!boolean_pop(c)) jump(); break; case NOG_BBRS: if(boolean_pop(c)) jump(); break; case NOG_JSR: (void) run(c, current, c->pg->np_program + arg0(), result_tree); break; case NOG_SBNS: if(c->head < c->eof && *c->head == arg1()) { c->head ++; } else { jump(); } break; case NOG_BSLLT: if(c->eof - c->head < arg1()) jump(); /* XXX */ break; case NOG_BNBOF: if(c->head != c->bof) jump(); break; case NOG_SSEQ: boolean_push(c, c->head < c->eof && *c->head == arg0()); break; case NOG_TSSEQ: boolean_push(c, c->head < c->eof && c->pg->np_tables[arg0()].nt_entries[*c->head] == (letter_t) arg1()); break; case NOG_SSIR: boolean_push(c, c->head < c->eof && arg0() <= *c->head && *c->head <= arg1()); break; case NOG_BTRUE: boolean_push(c, true); break; case NOG_BFALSE: boolean_push(c, false); break; case NOG_BAND: { bool b1, b2; b1 = boolean_pop(c); b2 = boolean_pop(c); boolean_push(c, b1 && b2); } break; case NOG_BOR: { bool b1, b2; b1 = boolean_pop(c); b2 = boolean_pop(c); boolean_push(c, b1 || b2); } break; case NOG_BNOT: boolean_push(c, !boolean_pop(c)); break; case NOG_SETF: c->fail = true; break; case NOG_CLRF: c->fail = false; break; case NOG_RIGHT: c->head += arg0(); break; case NOG_PUSHP: stack_push(c, c->head - c->bof); break; case NOG_POPP: c->head = c->bof + stack_pop(c); break; case NOG_RESTP: c->head = c->bof + stack_top(c); break; case NOG_DROPP: (void) stack_pop(c); break; case NOG_LDMEM: assert(0 <= arg0() && arg0() < c->cx->cx_num_productions); c->memo = get_result(c->cx, c->head - c->bof, arg0()); break; case NOG_LDCH: assert(0 <= arg0() && arg0() < c->cx->cx_num_alternatives); c->choice = get_choice(c->cx, c->head - c->bof, arg0()); break; case NOG_POPSTMEMJ: { int position; position = stack_pop(c); assert(0 <= arg0() && arg0() < c->cx->cx_num_productions); set_result(c->cx, position, arg0(), c->head - c->bof); } break; case NOG_STMEMB: assert(0 <= arg0() && arg0() < c->cx->cx_num_productions); set_result(c->cx, c->head - c->bof, arg0(), R_BUSY); break; case NOG_STMEMF: assert(0 <= arg0() && arg0() < c->cx->cx_num_productions); set_result(c->cx, c->head - c->bof, arg0(), R_FAIL); break; case NOG_TOPSTCH: { int position; position = stack_top(c); assert(0 <= arg0() && arg0() < c->cx->cx_num_alternatives); set_choice(c->cx, position, arg0(), arg1()); } break; case NOG_JMEM: c->head = c->bof + c->memo; break; case NOG_RTS: return ip_next; case NOG_SWCH: assert(c->choice < ip->ni_arg[0].na_table.nt_length); jump_to(ip->ni_arg[0].na_table.nt_elements[c->choice]); break; case NOG_LABEL: break; /* Construction */ case NOG_SNODE: { int id; unsigned char *name; construction new_cons; tree new_tree; id = arg0(); name = c->pg->np_constructors[id].ns_chars; new_cons = c->bd->pb_start_construction(c->bi, id, name, c->head - c->bof); ip_next = run(c, new_cons, ip_next, &new_tree); if(!ip_next) { return 0; } /* new_tree = c->bd->pb_finish_construction(c->bi, new_cons); */ if(!c->bd->pb_add_children(c->bi, current, new_tree)) return 0; } break; case NOG_FNODE: if(result_tree) { *result_tree = c->bd->pb_finish_construction(c->bi, current, c->head - c->bof); } return ip_next; case NOG_ATTR: { int id; unsigned char *name; id = arg0(); name = c->pg->np_attributes[id].ns_chars; if(!c->bd->pb_add_attribute(c->bi, current, id, name, c->head - c->bof, c->memo)) return 0; } break; case NOG_STRATTR: { int id; unsigned char *name; id = arg0(); name = c->pg->np_attributes[id].ns_chars; if(!c->bd->pb_add_constant_attribute(c->bi, current, id, name, ip->ni_arg[1].na_string.ns_chars, ip->ni_arg[1].na_string.ns_length)) return 0; } break; case NOG_POSATTR: { int id; unsigned char *name; id = arg0(); name = c->pg->np_attributes[id].ns_chars; if(!c->bd->pb_add_attribute(c->bi, current, id, name, c->head - c->bof, c->head - c->bof - 1)) return 0; } break; case NOG_TOKEN: if(!c->bd->pb_add_token(c->bi, current, c->head - c->bof, c->memo)) return 0; break; } } }
// for: _iadd, _imul, _isub, _idiv, _irem void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) { if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) { // The requirements for division and modulo // input : eax: dividend min_int // reg: divisor (may not be eax/edx) -1 // // output: eax: quotient (= eax idiv reg) min_int // edx: remainder (= eax irem reg) 0 // eax and edx will be destroyed // Note: does this invalidate the spec ??? LIRItem right(x->y(), this); LIRItem left(x->x() , this); // visit left second, so that the is_register test is valid left.set_destroys_register(); right.set_destroys_register(); left.load_item(); right.load_item(); if (x->op() == Bytecodes::_idiv) { set_result(x, divOutRInfo()); } else { set_result(x, remOutRInfo()); } if (!ImplicitDiv0Checks) { CodeEmitInfo* info = state_for(x); emit()->explicit_div_by_zero_check(right.result(), info); } CodeEmitInfo* info = state_for(x); RInfo tmp = FrameMap::_edxRInfo; // idiv and irem use edx in their implementation emit()->arithmetic_idiv(x->op(), x->operand(), left.result(), right.result(), tmp, info); } else { // missing test if instr is commutative and if we should swap LIRItem left(x->x(), this); LIRItem right(x->y(), this); LIRItem* left_arg = &left; LIRItem* right_arg = &right; if (x->is_commutative() && left.is_stack() && right.is_register()) { // swap them if left is real stack (or cached) and right is real register(not cached) left_arg = &right; right_arg = &left; } left_arg->set_destroys_register(); left_arg->load_item(); // do not need to load right, as we can handle stack and constants if (x->op() == Bytecodes::_imul ) { // check if we can use shift instead RInfo tmp; bool use_constant = false; bool use_tmp = false; if (right_arg->is_constant()) { int iconst = right_arg->get_jint_constant(); if (iconst > 0) { if (is_power_of_2(iconst)) { use_constant = true; } else if (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1)) { use_constant = true; use_tmp = true; } } } if (use_constant) { right_arg->dont_load_item(); } else { right_arg->load_item(); } if (use_tmp) { tmp = new_register(T_INT)->rinfo(); } RInfo reg = rlock_result(x)->rinfo(); emit()->arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp); } else { right_arg->dont_load_item(); RInfo reg = rlock_result(x)->rinfo(); RInfo tmp; emit()->arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp); } } }
void file_dialog::action(gui::dialog_process_info &dp_info) { if(result() == gui::CLOSE_DIALOG) return; //handle "delete item" requests if(result() == gui::DELETE_ITEM) { if(!chosen_file_.empty()) { if(files_list_->delete_chosen_file() == -1) { gui2::show_transient_error_message(get_video() , _("Deletion of the file failed.")); dp_info.clear_buttons(); } else { dp_info.first_time = true; } } set_result(gui::CONTINUE_DIALOG); } //handle "create item" requests else if(result() == gui::CREATE_ITEM) { std::string new_dir_name = ""; if(gui2::tfolder_create::execute(new_dir_name, get_video())) { if( !files_list_->make_directory(new_dir_name) ) { gui2::show_transient_error_message(get_video() , _("Creation of the directory failed.")); } else { dp_info.first_time = true; } } dp_info.clear_buttons(); set_result(gui::CONTINUE_DIALOG); } //update the chosen file if((dp_info.selection != last_selection_ || dp_info.first_time || dp_info.double_clicked) && (!files_list_->type_a_head() || dp_info.new_left_button)) { files_list_->reset_type_a_head(); chosen_file_ = files_list_->get_choice(); set_save_text(chosen_file_); last_selection_ = (dp_info.double_clicked) ? -1 : dp_info.selection; last_textbox_text_ = textbox_text(); } else if(textbox_text() != last_textbox_text_) { chosen_file_ = unformat_filename(textbox_text()); last_textbox_text_ = textbox_text(); // Do type-a-head search in listbox if (autocomplete_) { files_list_->select_file(textbox_text()); } } if(result() >=0) { //if a directory has been chosen, enter it if(files_list_->is_directory(chosen_file_)) { files_list_->change_directory(chosen_file_); get_message().set_text(format_dirname(files_list_->get_directory())); //reset the chosen file chosen_file_ = ".."; get_textbox().set_text(format_filename(chosen_file_)); set_result(gui::CONTINUE_DIALOG); } //if a file has been chosen, return button index "Ok" else { set_result(0); } } }
// track commands static void cmd_track(void) { // ensure floppy is selected u08 did_sel = floppy_select_on(); u08 cmd,res; u08 exit = 0; while((cmd = get_char()) != 0) { switch(cmd) { case 'i': track_init(); set_result(STATUS_OK); break; case 'c': res = track_check_max(); set_result(res); break; case 'z': track_zero(); set_result(STATUS_OK); break; case '?': set_result(track_num()); break; case '+': track_step_next(parse_hex_byte(1)); set_result(track_num()); break; case '-': track_step_prev(parse_hex_byte(1)); set_result(track_num()); break; case 'n': track_next(parse_hex_byte(1)); set_result(track_num()); break; case 'p': track_prev(parse_hex_byte(1)); set_result(track_num()); break; case 's': track_side_toggle(); set_result(track_num()); break; case 't': track_side_top(); set_result(track_num()); break; case 'b': track_side_bot(); set_result(track_num()); break; case 'm': track_set_max(parse_hex_byte(79)); set_result(track_get_max()); break; default: set_result(ERROR_SYNTAX); case '.': exit = 1; break; } if(exit) break; } if(did_sel) { floppy_select_off(); } }
/** * Check all referenced array elements are present. * * @param pOi pointer to oi_fits struct to check * @param pResult pointer to oi_check_result struct to store result in * * @return oi_breach level indicating overall test result */ oi_breach_level check_elements_present(oi_fits *pOi, oi_check_result *pResult) { GList *link; int i, j; oi_vis *pVis; oi_vis2 *pVis2; oi_t3 *pT3; const char desc[] = "Reference to missing array element"; char location[FLEN_VALUE]; init_check_result(pResult); /* Check OI_VIS tables */ link = pOi->visList; while(link != NULL) { pVis = link->data; if(strlen(pVis->arrname) > 0) { for(i=0; i<pVis->numrec; i++) { for(j=0; j<2; j++) { if(oi_fits_lookup_element(pOi, pVis->arrname, pVis->record[i].sta_index[j]) == NULL) { g_snprintf(location, FLEN_VALUE, "OI_VIS #%d record %d", g_list_position(pOi->visList, link)+1, i+1); set_result(pResult, OI_BREACH_NOT_OIFITS, desc, location); } } } } link = link->next; } /* Check OI_VIS2 tables */ link = pOi->vis2List; while(link != NULL) { pVis2 = link->data; if(strlen(pVis2->arrname) > 0) { for(i=0; i<pVis2->numrec; i++) { for(j=0; j<2; j++) { if(oi_fits_lookup_element(pOi, pVis2->arrname, pVis2->record[i].sta_index[j]) == NULL) { g_snprintf(location, FLEN_VALUE, "OI_VIS2 #%d record %d", g_list_position(pOi->vis2List, link)+1, i+1); set_result(pResult, OI_BREACH_NOT_OIFITS, desc, location); } } } } link = link->next; } /* Check OI_T3 tables */ link = pOi->t3List; while(link != NULL) { pT3 = link->data; if(strlen(pT3->arrname) > 0) { for(i=0; i<pT3->numrec; i++) { for(j=0; j<3; j++) { if(oi_fits_lookup_element(pOi, pT3->arrname, pT3->record[i].sta_index[j]) == NULL) { g_snprintf(location, FLEN_VALUE, "OI_T3 #%d record %d", g_list_position(pOi->t3List, link)+1, i+1); set_result(pResult, OI_BREACH_NOT_OIFITS, desc, location); } } } } link = link->next; } return pResult->level; }
// wiznet commands static void cmd_wiznet(void) { u08 cmd, res, val; u16 addr, wval; u08 exit = 0; while((cmd = get_char()) != 0) { switch(cmd) { // ---------- low level/debug ---------- case 'r': // low level: read byte <addr/16> addr = parse_hex_byte(0) << 8 | parse_hex_byte(0); wiz_low_begin(); res = wiz_low_read(addr); wiz_low_end(); set_result(res); uart_send_hex_word_space(addr); uart_send_hex_byte_crlf(res); break; case 'w': // low level: write byte <addr/16><val/8> addr = parse_hex_byte(0) << 8 | parse_hex_byte(0); val = parse_hex_byte(0); wiz_low_begin(); wiz_low_write(addr,val); wiz_low_end(); set_result(val); uart_send_hex_word_space(addr); uart_send_hex_byte_crlf(val); break; case 'R': // low level: read word <addr/16> addr = parse_hex_byte(0) << 8 | parse_hex_byte(0); wiz_low_begin(); res = wiz_low_read_word(addr); wiz_low_end(); set_result(res); uart_send_hex_word_space(addr); uart_send_hex_word_crlf(res); break; case 'W': // low level: write byte <addr/16><val/8> addr = parse_hex_byte(0) << 8 | parse_hex_byte(0); wval = parse_hex_byte(0) << 8 | parse_hex_byte(0); wiz_low_begin(); wiz_low_write_word(addr,wval); wiz_low_end(); set_result(wval); uart_send_hex_word_space(addr); uart_send_hex_word_crlf(wval); break; // ---------- config ---------- case '?': net_info(); break; case 'm': // set mac addr 6*<8> { wiz_cfg_t *wc = wiz_get_cfg(); for(int i=0;i<6;i++) { wc->mac_addr[i] = parse_hex_byte(0); } wiz_realize_cfg(); } break; case 's': // set src ip 4*<8> { wiz_cfg_t *wc = wiz_get_cfg(); for(int i=0;i<4;i++) { wc->src_ip[i] = parse_hex_byte(0); } wiz_realize_cfg(); } break; case 't': // set tgt ip 4*<8> { wiz_cfg_t *wc = wiz_get_cfg(); for(int i=0;i<4;i++) { wc->tgt_ip[i] = parse_hex_byte(0); } wiz_realize_cfg(); } break; case 'n': // set netmask 4*<8> { wiz_cfg_t *wc = wiz_get_cfg(); for(int i=0;i<4;i++) { wc->net_msk[i] = parse_hex_byte(0); } wiz_realize_cfg(); } break; case 'g': // set gateway 4*<8> { wiz_cfg_t *wc = wiz_get_cfg(); for(int i=0;i<4;i++) { wc->gw_ip[i] = parse_hex_byte(0); } wiz_realize_cfg(); } break; case 'o': // src port { wiz_cfg_t *wc = wiz_get_cfg(); wc->src_port = parse_hex_word(1234); } break; case 'p': // tgt port { wiz_cfg_t *wc = wiz_get_cfg(); wc->tgt_port = parse_hex_word(6800); } break; // ----- load/save config ----- case 'S': // save to sram wiz_save_cfg(); break; case 'L': // load from sram wiz_load_cfg(); wiz_realize_cfg(); break; case 'c': // connect test { int result = wiz_begin_tcp_client(); if(result == 0) { uart_send_string((u08 *)"connected"); const char *hw = "hello world!\r\n"; wiz_write_tcp((u08 *)hw, 14); uart_send_string((u08 *)"disconnect"); wiz_end_tcp_client(); } set_result(result); } break; case 'i': net_init(); break; default: set_result(ERROR_SYNTAX); case '.': exit = 1; break; } if(exit) break; } }
/** * Check for negative error bars. * * @param pOi pointer to oi_fits struct to check * @param pResult pointer to oi_check_result struct to store result in * * @return oi_breach level indicating overall test result */ oi_breach_level check_flagging(oi_fits *pOi, oi_check_result *pResult) { GList *link; int i, j; oi_vis *pVis; oi_vis2 *pVis2; oi_t3 *pT3; const char desc[] = "Data table contains negative error bar"; char location[FLEN_VALUE]; init_check_result(pResult); /* Check OI_VIS tables */ link = pOi->visList; while(link != NULL) { pVis = link->data; for(i=0; i<pVis->numrec; i++) { if(pVis->record[i].flag) continue; for(j=0; j<pVis->nwave; j++) { if(pVis->record[i].visamperr[j] < 0. || pVis->record[i].visphierr[j] < 0.) { g_snprintf(location, FLEN_VALUE, "OI_VIS #%d record %d channel %d", g_list_position(pOi->visList, link)+1, i+1, j+1); set_result(pResult, OI_BREACH_NOT_OIFITS, desc, location); } } } link = link->next; } /* Check OI_VIS2 tables */ link = pOi->vis2List; while(link != NULL) { pVis2 = link->data; for(i=0; i<pVis2->numrec; i++) { if(pVis2->record[i].flag) continue; for(j=0; j<pVis2->nwave; j++) { if(pVis2->record[i].vis2err[j] < 0.) { g_snprintf(location, FLEN_VALUE, "OI_VIS2 #%d record %d channel %d", g_list_position(pOi->vis2List, link)+1, i+1, j+1); set_result(pResult, OI_BREACH_NOT_OIFITS, desc, location); } } } link = link->next; } /* Check OI_T3 tables */ link = pOi->t3List; while(link != NULL) { pT3 = link->data; for(i=0; i<pT3->numrec; i++) { if(pT3->record[i].flag) continue; for(j=0; j<pT3->nwave; j++) { if(pT3->record[i].t3amperr[j] < 0. || pT3->record[i].t3phierr[j] < 0.) { g_snprintf(location, FLEN_VALUE, "OI_T3 #%d record %d channel %d", g_list_position(pOi->t3List, link)+1, i+1, j+1); set_result(pResult, OI_BREACH_NOT_OIFITS, desc, location); } } } link = link->next; } return pResult->level; }
void statistics_dialog::action(gui::dialog_process_info &dp_info) { int sel = get_menu().selection(); bool has_details = sel < 5 && sel >= 0 && unit_count_[sel] > 0; detail_btn_->enable(has_details); if(dp_info.double_clicked && has_details) { set_result(sel); } else if(dp_info.new_key_down && !dp_info.key_down) { set_result(gui::CLOSE_DIALOG); } // Prepare the sub-dialog for Statistic Details std::string title; std::vector<std::string> items_sub; switch(result()) { case gui::CLOSE_DIALOG: break; case 0: items_sub = create_unit_table(current_stats().recruits, team_num_); title = _("Recruits"); break; case 1: items_sub = create_unit_table(current_stats().recalls, team_num_); title = _("Recalls"); break; case 2: items_sub = create_unit_table(current_stats().advanced_to, team_num_); title = _("Advancements"); break; case 3: items_sub = create_unit_table(current_stats().deaths, team_num_); title = _("Losses"); break; case 4: // Give kills a (probably) different team color. items_sub = create_unit_table(current_stats().killed, team_num_ == 1 ? 2 : 1); title = _("Kills"); break; case BUTTON_SCENE: // Scenario selection. do_scene_selection(); set_result(gui::CONTINUE_DIALOG); break; case BUTTON_TOGGLE: // Toggle between campaign and scenario stats. display_stats(!use_campaign_); set_result(gui::CONTINUE_DIALOG); break; default: break; } if (items_sub.empty() == false) { gui::dialog d(get_display(), title + " (" + player_name_ + ")", "", gui::CLOSE_ONLY); d.set_menu(items_sub); d.show(); dp_info.clear_buttons(); set_result(gui::CONTINUE_DIALOG); } }
// Aborts and returns 1 if an error is encountered. int PackageRenderer::render_package(RenderPackage *package) { int audio_done = 0; int video_done = 0; int samples_rendered = 0; result = 0; this->package = package; // printf( // "PackageRenderer::render_package: audio s=%lld l=%lld video s=%lld l=%lld\n", // package->audio_start, // package->audio_end - package->audio_start, // package->video_start, // package->video_end - package->video_start); // FIXME: The design that we only get EDL once does not give us neccessary flexiblity to do things the way they should be donek default_asset->video_data = package->video_do; default_asset->audio_data = package->audio_do; Render::check_asset(edl, *default_asset); create_output(); if(!asset->video_data) video_done = 1; if(!asset->audio_data) audio_done = 1; // Create render engine if(!result) { create_engine(); //printf("PackageRenderer::render_package 5 %d\n", result); // Main loop while((!audio_done || !video_done) && !result) { int need_audio = 0, need_video = 0; // Calculate lengths to process. Audio fragment is constant. if(!audio_done) { if(audio_position + audio_read_length >= package->audio_end) { audio_done = 1; audio_read_length = package->audio_end - audio_position; } samples_rendered = audio_read_length; need_audio = 1; } //printf("PackageRenderer::render_package 6 %d\n", samples_rendered); if(!video_done) { if(audio_done) { video_read_length = package->video_end - video_position; // Packetize video length so progress gets updated video_read_length = (int)MIN(asset->frame_rate, video_read_length); video_read_length = MAX(video_read_length, 30); } else // Guide video with audio { video_read_length = Units::to_int64( (double)(audio_position + audio_read_length) / asset->sample_rate * asset->frame_rate) - video_position; } // Clamp length if(video_position + video_read_length >= package->video_end) { video_done = 1; video_read_length = package->video_end - video_position; } // Calculate samples rendered for progress bar. if(audio_done) samples_rendered = Units::round((double)video_read_length / asset->frame_rate * asset->sample_rate); need_video = 1; } //printf("PackageRenderer::render_package 1 %d %lld %lld\n", result, audio_read_length, video_read_length); if(need_video && !result) do_video(); //printf("PackageRenderer::render_package 7 %d %d\n", result, samples_rendered); if(need_audio && !result) do_audio(); if(!result) set_progress(samples_rendered); if(!result && progress_cancelled()) result = 1; // printf("PackageRenderer::render_package 10 %d %d %d %d\n", // audio_read_length, video_read_length, samples_rendered, result); if(result) set_result(result); else result = get_result(); } //printf("PackageRenderer::render_package 20\n"); stop_engine(); //printf("PackageRenderer::render_package 30\n"); stop_output(); //printf("PackageRenderer::render_package 40\n"); } //printf("PackageRenderer::render_package 50\n"); close_output(); //printf("PackageRenderer::render_package 60\n"); set_result(result); //printf("PackageRenderer::render_package 70\n"); return result; }
void wait::join_game(bool observe) { //if we have got valid side data //the first condition is to make sure that we don't have another //WML message with a side-tag in it while (!level_.has_attribute("version") || !level_.child("side")) { network::connection data_res = dialogs::network_receive_dialog(disp(), _("Getting game data..."), level_); if (!data_res) { set_result(QUIT); return; } check_response(data_res, level_); if(level_.child("leave_game")) { set_result(QUIT); return; } } // Add the map name to the title. append_to_title(": " + level_["name"].t_str()); if (!observe) { //search for an appropriate vacant slot. If a description is set //(i.e. we're loading from a saved game), then prefer to get the side //with the same description as our login. Otherwise just choose the first //available side. const config *side_choice = NULL; int side_num = -1, nb_sides = 0; BOOST_FOREACH(const config &sd, level_.child_range("side")) { if (sd["controller"] == "reserved" && sd["current_player"] == preferences::login()) { side_choice = &sd; side_num = nb_sides; break; } if (sd["controller"] == "network" && sd["player_id"].empty()) { if (!side_choice) { // found the first empty side side_choice = &sd; side_num = nb_sides; } if (sd["current_player"] == preferences::login()) { side_choice = &sd; side_num = nb_sides; break; // found the preferred one } } ++nb_sides; } if (!side_choice) { set_result(QUIT); return; } bool allow_changes = (*side_choice)["allow_changes"].to_bool(true); //if the client is allowed to choose their team, instead of having //it set by the server, do that here. std::string leader_choice, gender_choice; if(allow_changes) { events::event_context context; const config &era = level_.child("era"); /** @todo Check whether we have the era. If we don't inform the user. */ if (!era) throw config::error(_("No era information found.")); config::const_child_itors possible_sides = era.child_range("multiplayer_side"); if (possible_sides.first == possible_sides.second) { set_result(QUIT); throw config::error(_("No multiplayer sides found")); } int color = side_num; const std::string color_str = (*side_choice)["color"]; if (!color_str.empty()) color = game_config::color_info(color_str).index() - 1; std::vector<const config *> leader_sides; BOOST_FOREACH(const config &side, possible_sides) { leader_sides.push_back(&side); } int forced_faction = find_suitable_faction(leader_sides, *side_choice); if (forced_faction >= 0) { const config *f = leader_sides[forced_faction]; leader_sides.clear(); leader_sides.push_back(f); } std::vector<std::string> choices; BOOST_FOREACH(const config *s, leader_sides) { const config &side = *s; const std::string &name = side["name"]; const std::string &icon = side["image"]; if (!icon.empty()) { std::string rgb = side["flag_rgb"]; if (rgb.empty()) rgb = "magenta"; choices.push_back(IMAGE_PREFIX + icon + "~RC(" + rgb + ">" + lexical_cast<std::string>(color+1) + ")" + COLUMN_SEPARATOR + name); } else { choices.push_back(name); } } std::vector<gui::preview_pane* > preview_panes; leader_preview_pane leader_selector(disp(), leader_sides, color); preview_panes.push_back(&leader_selector); const int res = gui::show_dialog(disp(), NULL, _("Choose your faction:"), _("Starting position: ") + lexical_cast<std::string>(side_num + 1), gui::OK_CANCEL, &choices, &preview_panes); if(res < 0) { set_result(QUIT); return; } const int faction_choice = res; leader_choice = leader_selector.get_selected_leader(); gender_choice = leader_selector.get_selected_gender(); assert(static_cast<unsigned>(faction_choice) < leader_sides.size()); config faction; config& change = faction.add_child("change_faction"); change["name"] = preferences::login(); change["faction"] = forced_faction >= 0 ? forced_faction : faction_choice; change["leader"] = leader_choice; change["gender"] = gender_choice; network::send_data(faction, 0); } }
void file_dialog::action(gui::dialog_process_info &dp_info) { if(result() == gui::CLOSE_DIALOG) return; //handle "delete item" requests if(result() == gui::DELETE_ITEM) { if(!chosen_file_.empty()) { if(files_list_->delete_chosen_file() == -1) { gui::message_dialog d(get_display(), _("Deletion of the file failed.")); d.show(); dp_info.clear_buttons(); } else { dp_info.first_time = true; } } set_result(gui::CONTINUE_DIALOG); } //handle "create item" requests else if(result() == gui::CREATE_ITEM) { gui::dialog d(get_display(), _("New Folder"), "", gui::OK_CANCEL); d.set_textbox(_("Name: ")); d.show(); if(d.result() != gui::CLOSE_DIALOG && !d.textbox_text().empty()) { if( !files_list_->make_directory(d.textbox_text()) ) { gui::message_dialog d2(get_display(), _("Creation of the directory failed.")); d2.show(); } else { dp_info.first_time = true; } } dp_info.clear_buttons(); set_result(gui::CONTINUE_DIALOG); } //update the chosen file if((dp_info.selection != last_selection_ || dp_info.first_time || dp_info.double_clicked) && (!files_list_->type_a_head() || dp_info.new_left_button)) { files_list_->reset_type_a_head(); chosen_file_ = files_list_->get_choice(); get_textbox().set_text(format_filename(chosen_file_)); last_selection_ = (dp_info.double_clicked) ? -1 : dp_info.selection; last_textbox_text_ = textbox_text(); } else if(textbox_text() != last_textbox_text_) { chosen_file_ = unformat_filename(textbox_text()); last_textbox_text_ = textbox_text(); // Do type-a-head search in listbox if (autocomplete_) { files_list_->select_file(textbox_text()); } } if(result() >=0) { //if a directory has been chosen, enter it if(files_list_->is_directory(chosen_file_)) { files_list_->change_directory(chosen_file_); get_message().set_text(format_dirname(files_list_->get_directory())); //reset the chosen file chosen_file_ = ".."; get_textbox().set_text(format_filename(chosen_file_)); set_result(gui::CONTINUE_DIALOG); } //if a file has been chosen, return button index "Ok" else { set_result(0); } } }