void xml_file_write(xml_data_node *node, mame_file *file) { /* ensure this is a root node */ assert_always(node->name == NULL, "xml_file_write called with a non-root node"); /* output a simple header */ mame_fprintf(file, "<?xml version=\"1.0\"?>\n"); mame_fprintf(file, "<!-- This file is autogenerated; comments and unknown tags will be stripped -->\n"); /* loop over children of the root and output */ for (node = node->child; node; node = node->next) xml_write_node_recursive(node, 0, file); }
void options_output_ini_mame_file(mame_file *inifile) { options_data *data; /* loop over all items */ for (data = datalist; data != NULL; data = data->next) { /* header: just print */ if ((data->flags & OPTION_HEADER) != 0) mame_fprintf(inifile, "\n#\n# %s\n#\n", data->description); /* otherwise, output entries for all non-deprecated and non-command items */ else if ((data->flags & (OPTION_DEPRECATED | OPTION_INTERNAL | OPTION_COMMAND)) == 0 && data->names[0][0] != 0) { if (data->data == NULL) mame_fprintf(inifile, "# %-23s <NULL> (not set)\n", data->names[0]); else if (strchr(data->data, ' ') != NULL) mame_fprintf(inifile, "%-25s \"%s\"\n", data->names[0], data->data); else mame_fprintf(inifile, "%-25s %s\n", data->names[0], data->data); } } }
static void xml_write_node_recursive(xml_data_node *node, int indent, mame_file *file) { xml_attribute_node *anode; xml_data_node *child; /* output this tag */ mame_fprintf(file, "%*s<%s", indent, "", node->name); /* output any attributes */ for (anode = node->attribute; anode; anode = anode->next) mame_fprintf(file, " %s=\"%s\"", anode->name, anode->value); /* if there are no children and no value, end the tag here */ if (!node->child && !node->value) mame_fprintf(file, " />\n"); /* otherwise, close this tag and output more stuff */ else { mame_fprintf(file, ">\n"); /* if there is a value, output that here */ if (node->value) mame_fprintf(file, "%*s%s\n", indent + 4, "", node->value); /* loop over children and output them as well */ if (node->child) { for (child = node->child; child; child = child->next) xml_write_node_recursive(child, indent + 4, file); } /* write a closing tag */ mame_fprintf(file, "%*s</%s>\n", indent, "", node->name); } }