int peepfinal(ins_t *code) { while (code->op != OP_EOF) { if (code->op == OP_SHIFT) { // *A += X // shift A //-> // shift A // *0 += X int off = code->b; ins_t* prev = find_ref(code, -1); if (prev) { for (ins_t *dst = code; dst != prev; --dst) { *dst = *(dst - 1); dst->b -= off; } *prev = (ins_t){OP_SHIFT, 0, off}; } } if (code->op == OP_SKIPZ) { ins_t *prev = find_ref(code, -1); if (prev) { if (prev->op == OP_ADD && prev->a) { ins_t *prev2 = find_ref(prev, -1); if (prev2 && prev2->op == OP_LOOPNZ) { // ] // *0 += X // [ // -> // ] // *0 += X // { (where { is just a label) code->a = 1; } } else if (prev->op == OP_SET && prev->a) { // *0 = X // [ // -> // *0 = X // { code->a = 1; } } } else if (code->op == OP_LOOPNZ) { ins_t *prev = find_ref(code, -1); if (prev && prev->op == OP_LOOPNZ) { // ] // ] // -> // ] // } code->a = 1; } } ++code; } }
static void do_resolve_rects(const config& cfg, config& resolved_config, config* resol_cfg = nullptr) { // recursively resolve children for(const config::any_child& value : cfg.all_children_range()) { config& childcfg = resolved_config.add_child(value.key); do_resolve_rects(value.cfg, childcfg, value.key == "resolution" ? &childcfg : resol_cfg); } // copy all key/values resolved_config.merge_attributes(cfg); // override default reference rect with "ref" parameter if any if(!cfg["ref"].empty()) { if(resol_cfg == nullptr) { ERR_DP << "Use of ref= outside a [resolution] block" << std::endl; } else { // DBG_DP << ">> Looking for " << cfg["ref"] << "\n"; const config& ref = find_ref(cfg["ref"], *resol_cfg); if(ref["id"].empty()) { ERR_DP << "Reference to non-existent rect id \"" << cfg["ref"] << "\"" << std::endl; } else if(ref["rect"].empty()) { ERR_DP << "Reference to id \"" << cfg["ref"] << "\" which does not have a \"rect\"\n"; } else { ref_rect = read_rect(ref); } } } // resolve the rect value to absolute coordinates if(!cfg["rect"].empty()) { resolved_config["rect"] = resolve_rect(cfg["rect"]); } }
static config& find_ref(const std::string& id, config& cfg, bool remove = false) { static config empty_config; config::all_children_itors itors = cfg.all_children_range(); for(config::all_children_iterator i = itors.begin(); i != itors.end(); ++i) { config& icfg = i->cfg; if(i->cfg["id"] == id) { if(remove) { cfg.erase(i); return empty_config; } else { return icfg; } } // Recursively look in children. config& c = find_ref(id, icfg, remove); if(&c != &empty_config) { return c; } } // Not found. return empty_config; }
static config& find_ref(const std::string& id, config& cfg, bool remove = false) { for(config::child_map::const_iterator i = cfg.all_children().begin(); i != cfg.all_children().end(); i++) { for (config::child_list::const_iterator j = i->second.begin(); j != i->second.end(); j++) { if ((**j)["id"] == id) { //DBG_DP << "Found a " << *(*i).first << "\n"; if (remove) { const config* const res = cfg.find_child((*i).first,"id",id); const size_t index = std::find((*i).second.begin(), (*i).second.end(), res) - (*i).second.begin(); cfg.remove_child((*i).first,index); return empty_config; } else { return **j; } } // recursively look in children config& c = find_ref(id, **j, remove); if (!c["id"].empty()) { return c; } } } // not found return empty_config; }
/** * Returns a config with all partial resolutions of a theme expanded. * * @param theme The original object, whose objects need to be * expanded. * * @returns A new object with the expanded resolutions in * a theme. This object no longer contains * partial resolutions. */ static config expand_partialresolution(const config& theme) { config result; // Add all the resolutions for(const auto& resolution : theme.child_range("resolution")) { result.add_child("resolution", resolution); } // Resolve all the partialresolutions for(const auto& part : theme.child_range("partialresolution")) { config resolution = get_resolution(result, part["inherits"]); resolution.merge_attributes(part); for(const auto& remove : part.child_range("remove")) { VALIDATE(!remove["id"].empty() , missing_mandatory_wml_key( "[theme][partialresolution][remove]" , "id")); find_ref(remove["id"], resolution, true); } for(const auto& change : part.child_range("change")) { VALIDATE(!change["id"].empty() , missing_mandatory_wml_key( "[theme][partialresolution][change]" , "id")); config& target = find_ref(change["id"], resolution, false); target.merge_attributes(change); } // cannot add [status] sub-elements, but who cares for(const auto& add : part.child_range("add")) { for(const auto& child : add.all_children_range()) { resolution.add_child(child.key, child.cfg); } } result.add_child("resolution", resolution); } return result; }
theme::object* theme::refresh_title2(const std::string& id, const std::string& title_tag){ std::string new_title; const config &cfg = find_ref(id, cfg_, false); if (! cfg[title_tag].empty()) new_title = cfg[title_tag].str(); return refresh_title(id, new_title); }
void CSearchFileDlg::OnGetdispinfoList(NMHDR* pNMHDR, LRESULT* pResult) { LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR; int id = pDispInfo->item.lParam; const t_map_entry& e = find_ref(m_map, id); string& buffer = m_list.get_buffer(); buffer = e.name; pDispInfo->item.pszText = const_cast<char*>(buffer.c_str()); *pResult = 0; }
int Cxse::extract(string fname, Cvirtual_file& f) { int error = 0; const t_map_entry& e = find_ref(m_map, fname); int c_channels = e.flags & 1 ? 2 : 1; m_bag_f.seek(e.offset); if (e.flags & 2) { assert(!e.chunk_size); int cb_d = sizeof(t_wav_header) + e.size; byte* d = new byte[cb_d]; byte* w = d; int c_channels = e.flags & 1 ? 2 : 1; int c_samples = e.size / c_channels >> 1; w += wav_file_write_header(w, c_samples, e.samplerate, 2, c_channels); error = m_bag_f.read(w, e.size); if (!error) f.write(d, cb_d); delete[] d; }
config& fill_rect_cfg(std::map<std::string, config>& cache, config& main_res, const std::string& id, const config& chg) { config chg2; std::map<std::string, config>::iterator it = cache.find(id); if (it == cache.end()) { // has been no data, fill data from main_res. const config& target = find_ref(id, main_res); if (!target.empty()) { full_rect_cfg(target, chg2); chg2["id"] = id; } cache.insert(std::make_pair(id, chg2)); it = cache.find(id); } if (!it->second.empty()) { // verlay with current cfg it->second.merge_attributes(chg); } return it->second; }
void CSearchFileDlg::OnFind() { if (UpdateData(true)) { CWaitCursor wait; m_list.DeleteAllItems(); m_map.clear(); for (auto& i : m_main_frame->mix_map_list()) { if (i.second.fname.empty()) continue; Cmix_file f; if (!f.open(i.second.fname)) { const t_mix_map_list_entry& e = find_ref(m_main_frame->mix_map_list(), i.second.parent); find(f, get_filename(), e.name + " - " + i.second.name, i.first); } } m_list.SetItemCount(m_map.size()); for (auto& i : m_map) m_list.InsertItemData(i.first); } }
static void do_resolve_rects(const config& cfg, config& resolved_config, config* resol_cfg = NULL) { // recursively resolve children for(config::all_children_iterator i = cfg.ordered_begin(); i != cfg.ordered_end(); ++i) { const config::all_children_iterator::value_type& value = *i; config& childcfg = resolved_config.add_child(value.first); do_resolve_rects(*value.second, childcfg, (value.first == "resolution") ? &childcfg : resol_cfg); } // copy all key/values for(string_map::const_iterator j = cfg.values.begin(); j != cfg.values.end(); ++j) { resolved_config.values[j->first] = j->second; } // override default reference rect with "ref" parameter if any if (!cfg["ref"].empty()) { if (resol_cfg == NULL) { ERR_DP << "Use of ref= outside a [resolution] block\n"; } else { //DBG_DP << ">> Looking for " << cfg["ref"] << "\n"; const config ref = find_ref (cfg["ref"], *resol_cfg); if (ref["id"].empty()) { ERR_DP << "Reference to non-existent rect id \"" << cfg["ref"] << "\"\n"; } else if (ref["rect"].empty()) { ERR_DP << "Reference to id \"" << cfg["ref"] << "\" which does not have a \"rect\"\n"; } else { ref_rect = read_rect(ref); } } } // resolve the rect value to absolute coordinates if (!cfg["rect"].empty()) { resolved_config.values["rect"] = resolve_rect(cfg["rect"]); } }
// to be called from gdb static config& find_ref(const char* id, config& cfg) { return find_ref(std::string(id), cfg); }
static void expand_partialresolution(config& dst_cfg, const config& top_cfg) { std::vector<config> res_cfgs_; // resolve all the partialresolutions const config::child_list& parts_list = top_cfg.get_children("partialresolution"); for(config::child_list::const_iterator i = parts_list.begin(); i != parts_list.end(); ++i) { // follow the inheritance hierarchy and push all the nodes on the stack std::vector<const config*> parent_stack(1, (*i)); const config* parent; //const t_string* parent_id = &((**i)["inherits"]); t_string parent_id = ((**i)["inherits"]); //const shared_string* parent_id = &((**i)["inherits"]); //while((parent = top_cfg.find_child("resolution", "id", (*parent_id))) == NULL) { while((parent = top_cfg.find_child("resolution", "id", (parent_id))) == NULL) { //parent = top_cfg.find_child("partialresolution", "id", (*parent_id)); parent = top_cfg.find_child("partialresolution", "id", (parent_id)); if(parent == NULL) //throw config::error("[partialresolution] refers to non-existant [resolution] " + (*parent_id)); throw config::error("[partialresolution] refers to non-existant [resolution] " + (parent_id)); parent_stack.push_back(parent); //parent_id = &((*parent)["inherits"]); parent_id = ((*parent)["inherits"]); } // Add the parent resolution and apply all the modifications of its children res_cfgs_.push_back(*parent); while(!parent_stack.empty()) { //override attributes for(string_map::const_iterator j = parent_stack.back()->values.begin(); j != parent_stack.back()->values.end(); ++j) { res_cfgs_.back().values[j->first] = j->second; } { const config::child_list& c = parent_stack.back()->get_children("remove"); for(config::child_list::const_iterator j = c.begin(); j != c.end(); ++j) { find_ref ((**j)["id"], res_cfgs_.back(), true); } } { const config::child_list& c = parent_stack.back()->get_children("change"); for(config::child_list::const_iterator j = c.begin(); j != c.end(); ++j) { config& target = find_ref ((**j)["id"], res_cfgs_.back()); for(string_map::iterator k = (**j).values.begin(); k != (**j).values.end(); ++k) { target.values[k->first] = k->second; } } } { // cannot add [status] sub-elements, but who cares const config* c = parent_stack.back()->child("add"); if (c != NULL) { const config::child_map m = c->all_children(); for(config::child_map::const_iterator j = m.begin(); j != m.end(); ++j) { for(config::child_list::const_iterator k = j->second.begin(); k != j->second.end(); ++k) { res_cfgs_.back().add_child(j->first, **k); } } } } parent_stack.pop_back(); } } // Add all the resolutions const config::child_list& res_list = top_cfg.get_children("resolution"); for(config::child_list::const_iterator j = res_list.begin(); j != res_list.end(); ++j) { dst_cfg.add_child("resolution", (**j)); } // Add all the resolved resolutions for(std::vector<config>::const_iterator k = res_cfgs_.begin(); k != res_cfgs_.end(); ++k) { dst_cfg.add_child("resolution", (*k)); } return; }
int peep(ins_t *code) { int changed = 0; while (code->op != OP_EOF) { if (code->op == OP_LOAD) { ins_t *prev = find_ref(code, -1); ins_t *next = find_ref(code, 1); if (prev && prev->op == OP_ADDT && (prev->a == 1 || prev->a == -1) && next && next->op == OP_SET) { // *A += tmp / *A -= tmp // tmp = *A // *A = B // -> // tmp += *A // *A = B prev->op = OP_NOP; code->op = OP_TADD; code->a = prev->a == 1 ? 0 : 0x80; changed = 1; } else if (prev && prev->op == OP_ADD && next && (next->op == OP_SET || next->op == OP_SETT)) { // *A += C // tmp = *A + D // *A = B / *A = tmp // -> // tmp = *A + C + D // *A = B / *A = tmp prev->op = OP_NOP; code->a += prev->a; changed = 1; } } else if (code->op == OP_SET) { ins_t *next = find_ref(code, 1); if (next && next->op == OP_ADD) { // *A = B // *A += C // -> // *A = B + C changed = 1; code->a += next->a; next->op = OP_NOP; } else if (next && next->op == OP_ADDT && code->a == 0 && next->a == 1) { // *A = 0 // *A += tmp // -> // *A = tmp changed = 1; code->op = OP_NOP; next->op = OP_SETT; } } else if (code->op == OP_TADD) { ins_t *prev = find_ref(code, -1); ins_t *next = find_ref(code, 1); if ((code->a & 0x7f) == 0 && prev && prev->op == OP_ADD && next && next->op == OP_SET && prev->a <= 63 && prev->a >= -64) { // *A += X // tmp = *A + tmp * (a>>8) // *A = Y // -> // tmp = *A + tmp + (a>>8) + X // *A = Y changed = 1; prev->op = OP_NOP; // 1bit: negate tmp, 7bit: offset code->a = (code->a & 0x80) | (prev->a & 0x7f); } } ++code; } return changed; }
void CSearchFileDlg::open_mix(int id) { const t_map_entry& e = find_ref(m_map, id); m_main_frame->left_mix_pane()->open_location_mix(m_main_frame->mix_map_list().find(e.parent), e.id); EndDialog(IDCANCEL); }
static int find_optional_attributes(xmlNodePtr curr_node, int in_block, struct ldap_object_node *curr_obj, struct ldap_attr_node **attrs, struct idinfo *ids) { xmlNodePtr node; struct ldap_attr_node *attr; struct ldap_attr_meta_node *n; if (!curr_node || (curr_node->type == XML_ELEMENT_NODE && (curr_node->name && !strcasecmp((char *)curr_node->name, "element")))) { return 0; } dbg_printf("lookin for optionals\n"); for (node = curr_node; node; node = node->next) { if (node->type != XML_ELEMENT_NODE) continue; if (!strcasecmp((char *)node->name, "ref")) { find_optional_attributes( find_ref(node), 1, curr_obj, attrs, ids); } if (!strcasecmp((char *)node->name, "choice")) { find_optional_attributes(node->xmlChildrenNode, 1, curr_obj, attrs, ids); continue; } if (!strcasecmp((char *)node->name, "group")) { find_optional_attributes(node->xmlChildrenNode, 1, curr_obj, attrs, ids); continue; } if (!strcasecmp((char *)node->name, "optional")) { find_optional_attributes(node->xmlChildrenNode, 1, curr_obj, attrs, ids); continue; } if (!node->name || strcmp((char *)node->name, "attribute")) { continue; } if (!in_block) continue; attr = get_attr(node, attrs, ids); n = zalloc(sizeof(*n)); dbg_printf("opt attr '%s'\n", attr->idval->name); if (find_meta_attr(curr_obj->required_attrs, attr)) { dbg_printf("skipping dup attr\n"); continue; } if (find_meta_attr(curr_obj->optional_attrs, attr)) { dbg_printf("skipping dup attr on optional list\n"); continue; } n->node = attr; n->next = curr_obj->optional_attrs; curr_obj->optional_attrs = n; } return 0; }
const Cbvalue& Cbvalue::d(const std::string& v) const { static Cbvalue z; return m_value_type == vt_dictionary ? find_ref(*m_map, v, z) : z; }
static const config& modify_top_cfg_according_to_mode(const std::string& patch, const config& top_cfg, config& tmp) { if (patch.empty()) { return top_cfg; } const config& sub = top_cfg.child(patch); if (!sub) { return top_cfg; } std::map<std::string, config> change_cache; std::vector<std::string> res_ids; res_ids.push_back("1024x768"); res_ids.push_back("640x480"); res_ids.push_back("480x320"); config* main_res = NULL; tmp = top_cfg; for (std::vector<std::string>::const_iterator it = res_ids.begin(); it != res_ids.end(); ++ it) { const std::string& key = *it; const config& cfg = sub.child(key); bool is_resolution = it == res_ids.begin(); config* find = NULL; if (is_resolution) { find = &tmp.find_child("resolution", "id", key); main_res = find; } else { find = &tmp.find_child("partialresolution", "id", key); } if (!*find) { VALIDATE(!is_resolution, "Theme must define 1024x768!"); continue; } if (cfg) { BOOST_FOREACH (const config &rm, cfg.child_range("remove")) { if (is_resolution) { find_ref(rm["id"], *find, true); } else { config& find2 = find->find_child("remove", "id", rm["id"]); if (!find2) { find->add_child("remove", rm); } } } BOOST_FOREACH (const config &chg, cfg.child_range("change")) { const std::string& id = chg["id"]; const config& chg2 = fill_rect_cfg(change_cache, *main_res, id, chg); if (is_resolution) { config& target = find_ref(id, *find); if (!target.empty()) { target.merge_attributes(chg2); } } else { config& find2 = find->find_child("change", "id", id); if (find2) { find2.merge_attributes(chg2); } else { find->add_child("change", chg2); } } } BOOST_FOREACH (const config &add, cfg.child_range("add")) { if (!is_resolution) { continue; } const std::string parent = add["id"].str(); config& target = parent.empty()? *find: find_ref(parent, *find); BOOST_FOREACH (const config::any_child &j, add.all_children_range()) { target.add_child(j.key, j.cfg); } } } else { for (std::map<std::string, config>::const_iterator it2 = change_cache.begin(); it2 != change_cache.end(); ++ it2) { config& find2 = find->find_child("change", "id", it2->first); if (find2) { find2.merge_attributes(it2->second); } else { find->add_child("change", it2->second); } } } }