diff options
author | 2016-03-06 18:02:37 +1100 | |
---|---|---|
committer | 2016-03-06 21:49:56 +1100 | |
commit | 73b44c94291c4d086477167a76fd7db239936c3b (patch) | |
tree | 9af214e443878f4b1e6452d63393ca9f9f8a0884 /src/lib/util/xmlfile.cpp | |
parent | 00941faaab99d937a32bce4d225ec56951d21020 (diff) |
Turn core_file into a proper class that gets cleaned up safely using unique_ptr
Subverted somewhat by chd_file class
Diffstat (limited to 'src/lib/util/xmlfile.cpp')
-rw-r--r-- | src/lib/util/xmlfile.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/lib/util/xmlfile.cpp b/src/lib/util/xmlfile.cpp index 620f12a66b3..db288b0a807 100644 --- a/src/lib/util/xmlfile.cpp +++ b/src/lib/util/xmlfile.cpp @@ -52,7 +52,7 @@ static xml_data_node *add_child(xml_data_node *parent, const char *name, const c static xml_attribute_node *add_attribute(xml_data_node *node, const char *name, const char *value); /* recursive tree operations */ -static void write_node_recursive(xml_data_node *node, int indent, core_file *file); +static void write_node_recursive(xml_data_node *node, int indent, util::core_file &file); static void free_node_recursive(xml_data_node *node); @@ -139,7 +139,7 @@ xml_data_node *xml_file_create(void) nodes -------------------------------------------------*/ -xml_data_node *xml_file_read(core_file *file, xml_parse_options *opts) +xml_data_node *xml_file_read(util::core_file &file, xml_parse_options *opts) { xml_parse_info parse_info; int done; @@ -154,8 +154,8 @@ xml_data_node *xml_file_read(core_file *file, xml_parse_options *opts) char tempbuf[TEMP_BUFFER_SIZE]; /* read as much as we can */ - int bytes = core_fread(file, tempbuf, sizeof(tempbuf)); - done = core_feof(file); + int bytes = file.read(tempbuf, sizeof(tempbuf)); + done = file.eof(); /* parse the data */ if (XML_Parse(parse_info.parser, tempbuf, bytes, done) == XML_STATUS_ERROR) @@ -223,15 +223,15 @@ xml_data_node *xml_string_read(const char *string, xml_parse_options *opts) xml_file_write - write an XML tree to a file -------------------------------------------------*/ -void xml_file_write(xml_data_node *node, core_file *file) +void xml_file_write(xml_data_node *node, util::core_file &file) { /* ensure this is a root node */ if (node->name != nullptr) return; /* output a simple header */ - core_fprintf(file, "<?xml version=\"1.0\"?>\n"); - core_fprintf(file, "<!-- This file is autogenerated; comments and unknown tags will be stripped -->\n"); + file.printf("<?xml version=\"1.0\"?>\n"); + file.printf("<!-- 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) @@ -1002,7 +1002,7 @@ static xml_attribute_node *add_attribute(xml_data_node *node, const char *name, -------------------------------------------------*/ /** - * @fn static void write_node_recursive(xml_data_node *node, int indent, core_file *file) + * @fn static void write_node_recursive(xml_data_node *node, int indent, util::core_file &file) * * @brief Writes a node recursive. * @@ -1011,30 +1011,30 @@ static xml_attribute_node *add_attribute(xml_data_node *node, const char *name, * @param [in,out] file If non-null, the file. */ -static void write_node_recursive(xml_data_node *node, int indent, core_file *file) +static void write_node_recursive(xml_data_node *node, int indent, util::core_file &file) { xml_attribute_node *anode; xml_data_node *child; /* output this tag */ - core_fprintf(file, "%*s<%s", indent, "", node->name); + file.printf("%*s<%s", indent, "", node->name); /* output any attributes */ for (anode = node->attribute; anode; anode = anode->next) - core_fprintf(file, " %s=\"%s\"", anode->name, anode->value); + file.printf(" %s=\"%s\"", anode->name, anode->value); /* if there are no children and no value, end the tag here */ if (node->child == nullptr && node->value == nullptr) - core_fprintf(file, " />\n"); + file.printf(" />\n"); /* otherwise, close this tag and output more stuff */ else { - core_fprintf(file, ">\n"); + file.printf(">\n"); /* if there is a value, output that here */ if (node->value != nullptr) - core_fprintf(file, "%*s%s\n", indent + 4, "", node->value); + file.printf("%*s%s\n", indent + 4, "", node->value); /* loop over children and output them as well */ if (node->child != nullptr) @@ -1044,7 +1044,7 @@ static void write_node_recursive(xml_data_node *node, int indent, core_file *fil } /* write a closing tag */ - core_fprintf(file, "%*s</%s>\n", indent, "", node->name); + file.printf("%*s</%s>\n", indent, "", node->name); } } |