GString * format_ipv (guint id, guint pos, guint val) { GString *buf = g_string_sized_new(1); GString *vec_buf = g_string_sized_new(1); XmlSettings *xml = get_xml_settings(id, pos); GString *val_buf; if (!xml) { g_warning("Failed to find xml settings for position %d id %d.", id, pos); g_string_printf(buf, "%s", "error"); return buf; } val_buf = format_value(xml, val); g_string_printf(vec_buf, "(%d, %d, %d)", pos, id, val); g_string_printf(buf, "%-16s %s: %s: %s", vec_buf->str, get_position(pos), xml->label, val_buf->str); g_string_free(vec_buf, TRUE); g_string_free(val_buf, TRUE); return buf; }
void write_preset_to_xml(Preset *preset, gchar *filename) { int rc; xmlTextWriterPtr writer; GList *iter_params = preset->params; guint last_id = 0; guint last_position = 0; printf("Creating a new xml doc\n"); /* Create a new XmlWriter for uri, with no compression. */ writer = xmlNewTextWriterFilename(filename, 0); if (writer == NULL) { printf("testXmlwriterFilename: Error creating the xml writer\n"); return; } /* * Start the document with the xml default for the version, * encoding and the default for the standalone declaration. */ rc = xmlTextWriterStartDocument(writer, NULL, GDIGI_ENCODING, NULL); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterStartDocument\n"); return; } rc = xmlTextWriterSetIndent(writer, 1); rc = xmlTextWriterSetIndentString(writer, BAD_CAST " "); /* Write the tag identifying type of prefix, schema version and ns. */ rc = xmlTextWriterStartElement(writer, BAD_CAST get_preset_filename(product_id)); rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SchemaVersion", BAD_CAST "1.2"); rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns", BAD_CAST "http://www.digitech.com/xml/preset"); /* Write the Name tag. */ rc = xmlTextWriterWriteElement(writer, BAD_CAST "Name", BAD_CAST preset->name); rc = xmlTextWriterStartElement(writer, BAD_CAST "Params"); while (iter_params) { XmlSettings *xml; SettingParam *param = (SettingParam *) iter_params->data; if (param->id == last_id && param->position == last_position) { g_warning("Skipping duplicate parameter id %d position %d", last_id, last_position); iter_params = iter_params->next; continue; } rc = xmlTextWriterStartElement(writer, BAD_CAST "Param"); rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ID", "%d", param->id); rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "Position", "%d", param->position); rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "Value", "%d", param->value); last_id = param->id; last_position = param->position; xml = get_xml_settings(param->id, param->position); if (!xml) { printf("Failed to get xml settings for id %d position %d\n", param->id, param->position); } else { ValueType type; gchar *suffix = ""; gdouble step = 1.0; gint offset = 0; gboolean decimal = FALSE; EffectValues *values = NULL; rc = xmlTextWriterWriteElement(writer, BAD_CAST "Name", BAD_CAST xml->label); values = xml->values; type = values->type; while ((type & VALUE_TYPE_EXTRA) && value_is_extra(values, param->value)) { values = values->extra; type = values->type; } type &= ~VALUE_TYPE_EXTRA; if (type & VALUE_TYPE_OFFSET) { offset = values->offset; type &= ~VALUE_TYPE_OFFSET; } if (type & VALUE_TYPE_STEP) { step = values->step; type &= ~VALUE_TYPE_STEP; } if (type & VALUE_TYPE_SUFFIX) { suffix = values->suffix; type &= ~VALUE_TYPE_SUFFIX; } if (type & VALUE_TYPE_DECIMAL) { decimal = TRUE; type &= ~VALUE_TYPE_DECIMAL; } switch (type) { case VALUE_TYPE_LABEL: { char *textp = map_xml_value(xml, param->value); if (!textp) { g_warning("Unable to map %s value %d for id %d position %d", xml->label, param->value, param->id, param->position); textp = ""; } rc = xmlTextWriterWriteElement(writer, BAD_CAST "Text", BAD_CAST textp); break; } case VALUE_TYPE_PLAIN: { if (decimal) { double value = (param->value + offset) * step; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "Text", "%0.2f%s", value, suffix); } else { gint value = (param->value + offset) * step; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "Text", "%d%s", value, suffix); } break; } case VALUE_TYPE_NONE: rc = xmlTextWriterStartElement(writer, BAD_CAST "Text"); rc = xmlTextWriterEndElement(writer); break; default: g_warning("Unhandled value type %d", type); break; } } rc = xmlTextWriterEndElement(writer); iter_params = iter_params->next; } rc = xmlTextWriterEndDocument(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndDocument\n"); return; } xmlFreeTextWriter(writer); }