void cheat_manager::load_cheats(const char *filename) { std::string searchstr(machine().options().cheat_path()); std::string curpath; for (path_iterator path(searchstr); path.next(curpath); ) { searchstr.append(";").append(curpath).append(PATH_SEPARATOR).append("cheat"); } emu_file cheatfile(std::move(searchstr), OPEN_FLAG_READ); try { // loop over all instrances of the files found in our search paths for (osd_file::error filerr = cheatfile.open(filename, ".xml"); filerr == osd_file::error::NONE; filerr = cheatfile.open_next()) { osd_printf_verbose("Loading cheats file from %s\n", cheatfile.fullpath()); // read the XML file into internal data structures xml_parse_options options = { nullptr }; xml_parse_error error; options.error = &error; std::unique_ptr<xml_data_node, void (*)(xml_data_node *)> rootnode(xml_data_node::file_read(cheatfile, &options), [] (xml_data_node *node) { node->file_free(); }); // if unable to parse the file, just bail if (rootnode == nullptr) throw emu_fatalerror("%s.xml(%d): error parsing XML (%s)\n", filename, error.error_line, error.error_message); // find the layout node xml_data_node *mamecheatnode = rootnode->get_child("mamecheat"); if (mamecheatnode == nullptr) throw emu_fatalerror("%s.xml: missing mamecheatnode node", filename); // validate the config data version int version = mamecheatnode->get_attribute_int("version", 0); if (version != CHEAT_VERSION) throw emu_fatalerror("%s.xml(%d): Invalid cheat XML file: unsupported version", filename, mamecheatnode->line); // parse all the elements for (xml_data_node const *cheatnode = mamecheatnode->get_child("cheat"); cheatnode != nullptr; cheatnode = cheatnode->get_next_sibling("cheat")) { // load this entry auto curcheat = std::make_unique<cheat_entry>(*this, m_symtable, filename, *cheatnode); // make sure we're not a duplicate if (REMOVE_DUPLICATE_CHEATS && curcheat->is_duplicate()) { osd_printf_verbose("Ignoring duplicate cheat '%s' from file %s\n", curcheat->description(), cheatfile.fullpath()); } else // add to the end of the list m_cheatlist.push_back(std::move(curcheat)); } } } // handle errors cleanly catch (emu_fatalerror &err) { osd_printf_error("%s\n", err.string()); m_cheatlist.clear(); } }
bool BTree::open(const char *filename, bool destruct) { if(!db.open(filename, destruct)) return false; if(destruct) { BTreeNode rootnode(numElements, elementSize); BTreeNode leafnode(numElements, elementSize); rootnode.insertElement(MAXKEY, 1); leafnode.insertElement(MAXKEY, 0); rootnode.makeIndex(); leafnode.makeLeaf(0); db.writeRecord(0, rootnode.getbuf()); db.writeRecord(1, leafnode.getbuf()); blockman.setnextblock(2); } else { int j = 2; char *buf = new char[elementSize]; while(db.readRecord(j, buf)) j++; blockman.setnextblock(j); } return true; }
svgtiny_code svgtiny_parse(svgInfo &info,struct svgtiny_diagram *diagram, const char *buffer,int viewport_width, int viewport_height){ Poco::XML::Document *document; Poco::XML::Element *svg; struct svgtiny_parse_state state; float x, y, width, height; svgtiny_code code; assert(diagram); assert(buffer); string rawXMLstring(buffer); //info.rawXML = rawXMLstring; //parser is statically allocated Poco::XML::DOMParser parser; /* Why does this upset the internal SVG parser? */ //parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false); document = parser.parseString(rawXMLstring); svg = document->documentElement(); //std::cout << svg->localName() << std::endl; if (!svg){ code = svgtiny_NOT_SVG; return code; }else if(svg->localName().compare("svg") != 0){ code= svgtiny_NOT_SVG; return code; }else{ /* get graphic dimensions */ state.diagram = diagram; state.document = document; state.viewport_width = viewport_width; state.viewport_height = viewport_height; svgtiny_parse_position_attributes(svg, state, &x, &y, &width, &height); diagram->width = width; diagram->height = height; /* set up parsing state */ state.viewport_width = width; state.viewport_height = height; state.ctm.a = 1; /*(float) viewport_width / (float) width;*/ state.ctm.b = 0; state.ctm.c = 0; state.ctm.d = 1; /*(float) viewport_height / (float) height;*/ state.ctm.e = 0; /*x;*/ state.ctm.f = 0; /*y;*/ /*state.style = css_base_style; state.style.font_size.value.length.value = option_font_size * 0.1;*/ state.fill = 0x000000; state.stroke = svgtiny_TRANSPARENT; state.stroke_width = 1; state.linear_gradient_stop_count = 0; //borg state.info = &info; /* parse tree */ ofPtr<svgNode> rootnode(new svgNode()); rootnode->type = SVG_TAG_TYPE_DOCUMENT; info.rootnode = rootnode; //store root svg info info.width = ofToString(svg->getAttribute("width").c_str()); info.height = ofToString(svg->getAttribute("height").c_str()); info.x = ofToString(svg->getAttribute("x").c_str()); info.y = ofToString(svg->getAttribute("y").c_str()); info.viewbox = ofToString(svg->getAttribute("viewBox").c_str()); info.id = ofToString(svg->getAttribute("id").c_str()); info.xmlns = ofToString(svg->getAttribute("xmlns").c_str()); info.version = ofToString(svg->getAttribute("version").c_str()); info.preserveAspectRatio = ofToString(svg->getAttribute("preserveAspectRatio").c_str()); code = svgtiny_parse_svg(info,svg, state,rootnode); } /* free XML tree */ //xmlFreeDoc(document); //return without namespace //parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false); //document = parser.parseString(rawXMLstring); return code; }