static int config_save_xml(running_machine &machine, emu_file &file, int which_type) { xml_data_node *root = xml_file_create(); xml_data_node *confignode, *systemnode; config_type *type; /* if we don't have a root, bail */ if (!root) return 0; /* create a config node */ confignode = xml_add_child(root, "mameconfig", NULL); if (!confignode) goto error; xml_set_attribute_int(confignode, "version", CONFIG_VERSION); /* create a system node */ systemnode = xml_add_child(confignode, "system", NULL); if (!systemnode) goto error; xml_set_attribute(systemnode, "name", (which_type == CONFIG_TYPE_DEFAULT) ? "default" : machine.system().name); /* create the input node and write it out */ /* loop over all registrants and call their save function */ for (type = typelist; type; type = type->next) { xml_data_node *curnode = xml_add_child(systemnode, type->name, NULL); if (!curnode) goto error; type->save(which_type, curnode); /* if nothing was added, just nuke the node */ if (!curnode->value && !curnode->child) xml_delete_node(curnode); } /* flush the file */ xml_file_write(root, file); /* free and get out of here */ xml_file_free(root); return 1; error: xml_file_free(root); return 0; }
static int expat_setup_parser(xml_parse_info *parse_info, xml_parse_options *opts) { XML_Memory_Handling_Suite memcallbacks; /* setup parse_info structure */ memset(parse_info, 0, sizeof(*parse_info)); if (opts != nullptr) { parse_info->flags = opts->flags; if (opts->error != nullptr) { opts->error->error_message = nullptr; opts->error->error_line = 0; opts->error->error_column = 0; } } /* create a root node */ parse_info->rootnode = xml_file_create(); if (parse_info->rootnode == nullptr) return FALSE; parse_info->curnode = parse_info->rootnode; /* create the XML parser */ memcallbacks.malloc_fcn = expat_malloc; memcallbacks.realloc_fcn = expat_realloc; memcallbacks.free_fcn = expat_free; parse_info->parser = XML_ParserCreate_MM(nullptr, &memcallbacks, nullptr); if (parse_info->parser == nullptr) { free(parse_info->rootnode); return FALSE; } /* configure the parser */ XML_SetElementHandler(parse_info->parser, expat_element_start, expat_element_end); XML_SetCharacterDataHandler(parse_info->parser, expat_data); XML_SetUserData(parse_info->parser, parse_info); /* optional parser initialization step */ if (opts != nullptr && opts->init_parser != nullptr) (*opts->init_parser)(parse_info->parser); return TRUE; }
static int setup_parser(xml_parse_info *parse_info, xml_parse_options *opts) { /* setup parse_info structure */ memset(parse_info, 0, sizeof(*parse_info)); if (opts) { parse_info->flags = opts->flags; if (opts->error) { opts->error->error_message = NULL; opts->error->error_line = 0; opts->error->error_column = 0; } } /* create a root node */ parse_info->rootnode = xml_file_create(); if (!parse_info->rootnode) return FALSE; parse_info->curnode = parse_info->rootnode; /* create the XML parser */ parse_info->parser = XML_ParserCreate(NULL); if (!parse_info->parser) { free(parse_info->rootnode); return FALSE; } /* configure the parser */ XML_SetElementHandler(parse_info->parser, xml_element_start, xml_element_end); XML_SetCharacterDataHandler(parse_info->parser, xml_data); XML_SetUserData(parse_info->parser, parse_info); /* optional parser initialization step */ if (opts && opts->init_parser) opts->init_parser(parse_info->parser); return TRUE; }
int debug_comment_save(void) { int i, j; char crc_buf[20]; xml_data_node *root = xml_file_create(); xml_data_node *commentnode, *systemnode; int total_comments = 0; /* if we don't have a root, bail */ if (!root) return 0; /* create a comment node */ commentnode = xml_add_child(root, "mamecommentfile", NULL); if (!commentnode) goto error; xml_set_attribute_int(commentnode, "version", COMMENT_VERSION); /* create a system node */ systemnode = xml_add_child(commentnode, "system", NULL); if (!systemnode) goto error; xml_set_attribute(systemnode, "name", Machine->gamedrv->name); /* for each cpu */ for (i = 0; i < cpu_gettotalcpu(); i++) { xml_data_node *curnode = xml_add_child(systemnode, "cpu", NULL); if (!curnode) goto error; xml_set_attribute_int(curnode, "num", i); for (j = 0; j < debug_comments[i].comment_count; j++) { xml_data_node *datanode = xml_add_child(curnode, "comment", debug_comments[i].comment_info[j]->text); if (!datanode) goto error; xml_set_attribute_int(datanode, "address", debug_comments[i].comment_info[j]->address); xml_set_attribute_int(datanode, "color", debug_comments[i].comment_info[j]->color); sprintf(crc_buf, "%08X", debug_comments[i].comment_info[j]->crc); xml_set_attribute(datanode, "crc", crc_buf); total_comments++; } } /* flush the file */ if (total_comments > 0) { mame_file *fp = mame_fopen(Machine->gamedrv->name, 0, FILETYPE_COMMENT, 1); xml_file_write(root, fp); mame_fclose(fp); } /* free and get out of here */ xml_file_free(root); return 1; error: xml_file_free(root); return 0; }